Skip to content

Commit 8157e60

Browse files
committed
更新[box.switcher.js]: 如果在同一批切换会话中,对同一个属性设置不同值时,会提示冲突
1 parent 4153ac9 commit 8157e60

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

box/switcher/box.switcher.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ function execSwitch() {
2626
const app = apps[appId]
2727
app.sessions.push(session)
2828
})
29+
const switchkeys = {}
2930
Object.keys(apps).forEach((appId) => {
3031
const app = apps[appId]
3132
if (app.sessions.length <= 1) {
@@ -40,9 +41,27 @@ function execSwitch() {
4041
const isNewRound = curSessionIdx + 1 === app.sessions.length
4142
const nextSessionIdx = isNewRound ? 0 : curSessionIdx + 1
4243
const nextSession = app.sessions[nextSessionIdx]
43-
nextSession.datas.forEach((_data) => $.setdata([undefined, null, 'undefined', 'null', ''].includes(_data.val) ? '' : _data.val, _data.key))
44+
nextSession.datas.forEach((_data) => {
45+
const key = _data.key
46+
const val = [undefined, null, 'undefined', 'null', ''].includes(_data.val) ? '' : _data.val
47+
if (switchkeys[key]) {
48+
const swData = switchkeys[key]
49+
const isClash = swData.val !== val ? true : false
50+
if (isClash) {
51+
nextSession.isClash = true
52+
$.log('', `⚠️【${key}】冲突: `, ` ${nextSession.appName}.${nextSession.name} => ${swData.session.appName}.${swData.session.name}`)
53+
}
54+
} else {
55+
switchkeys[key] = {}
56+
const swData = switchkeys[key]
57+
swData.val = val
58+
swData.session = nextSession
59+
}
60+
$.setdata(val, key)
61+
})
4462
curSessions[appId] = nextSession.id
45-
$.desc.push(`${curSession.appName}: ${curSession.name} => #${nextSessionIdx + 1} ${nextSession.name} ${isNewRound ? '(新一轮)' : ''}`)
63+
const clashstr = nextSession.isClash === true ? ' (冲突)' : ''
64+
$.desc.push(`${curSession.appName}: ${curSession.name} => #${nextSessionIdx + 1} ${nextSession.name}${clashstr} ${isNewRound ? '(新一轮)' : ''}`)
4665
})
4766
$.setdata(JSON.stringify(curSessions), $.KEY_curSessions)
4867
resove()

0 commit comments

Comments
 (0)