Skip to content

Commit a32fdfc

Browse files
committed
更新[chavy.box.js]: 可以单独清空当前会话的某项目数据
1 parent 7ee9520 commit a32fdfc

1 file changed

Lines changed: 37 additions & 5 deletions

File tree

chavy.box.js

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,31 @@ function handleApi() {
228228
$.msg($.name, $.subt, $.desc.join('\n'))
229229
}
230230
}
231+
// 保存当前会话
232+
if (data.cmd === 'saveCurAppSession') {
233+
const app = data.val
234+
const isExistsApp = getSystemApps().find((_app) => _app.id === app.id)
235+
if (isExistsApp) {
236+
let isAllSaveSuc = true
237+
app.datas.forEach((data) => {
238+
const oldval = $.getdata(data.key)
239+
const newval = data.val
240+
const savesuc = $.setdata(`${newval}`, data.key)
241+
isAllSaveSuc = !savesuc ? false : isAllSaveSuc
242+
$.log('', `❕ ${app.name}, 保存设置: ${data.key} ${savesuc ? '成功' : '失败'}!`, `旧值: ${oldval}`, `新值: ${newval}`)
243+
})
244+
$.subt = `保存会话: ${isAllSaveSuc ? '成功' : '失败'} (${app.name})`
245+
$.msg($.name, $.subt, '')
246+
// sessions.push(session)
247+
// const savesuc = $.setdata(JSON.stringify(sessions), $.KEY_sessions)
248+
// $.subt = `保存会话: ${savesuc ? '成功' : '失败'} (${session.appName})`
249+
// $.desc = []
250+
// $.desc.push(`会话名称: ${session.name}`, `应用名称: ${session.appName}`, `会话编号: ${session.id}`, `应用编号: ${session.appId}`, `数据: ${JSON.stringify(session)}`)
251+
// $.msg($.name, $.subt, $.desc.join('\n'))
252+
}
253+
}
231254
// 保存设置
232-
else if (data.cmd === 'savePops') {
255+
else if (data.cmd === 'saveSettings') {
233256
$.log(`❕ ${$.name}, 保存设置!`)
234257
const settings = data.val
235258
if (Array.isArray(settings)) {
@@ -402,7 +425,7 @@ function printHtml(data, curapp = null) {
402425
<v-divider></v-divider>
403426
<v-card-actions>
404427
<v-spacer></v-spacer>
405-
<v-btn small text color="success" @click="onSavePops">保存设置</v-btn>
428+
<v-btn small text color="success" @click="onSaveSettings">保存设置</v-btn>
406429
</v-card-actions>
407430
</template>
408431
</v-card>
@@ -429,6 +452,11 @@ function printHtml(data, curapp = null) {
429452
<v-list-item-title>{{ data.key }}</v-list-item-title>
430453
<v-list-item-subtitle>{{ data.val ? data.val : '无数据!' }}</v-list-item-subtitle>
431454
</v-list-item-content>
455+
<v-list-item-action>
456+
<v-btn icon @click.stop="onClearCurAppSessionData(ui.curapp, ui.curapp.datas, data)">
457+
<v-icon color="grey darken-1">mdi-close</v-icon>
458+
</v-btn>
459+
</v-list-item-action>
432460
</v-list-item>
433461
<v-divider></v-divider>
434462
<v-card-actions>
@@ -549,6 +577,10 @@ function printHtml(data, curapp = null) {
549577
history.pushState(state, '', '/app/' + this.ui.curapp.id)
550578
document.title = state.title
551579
},
580+
onClearCurAppSessionData(app, datas, data) {
581+
data.val = ''
582+
axios.post('/api', JSON.stringify({ cmd: 'saveCurAppSession', val: app }))
583+
},
552584
onSaveSession() {
553585
const session = {
554586
id: uuidv4(),
@@ -563,8 +595,8 @@ function printHtml(data, curapp = null) {
563595
this.ui.curappSessions.push(session)
564596
axios.post('/api', JSON.stringify({ cmd: 'saveSession', val: session }))
565597
},
566-
onSavePops() {
567-
axios.post('/api', JSON.stringify({ cmd: 'savePops', val: this.ui.curapp.settings }))
598+
onSaveSettings() {
599+
axios.post('/api', JSON.stringify({ cmd: 'saveSettings', val: this.ui.curapp.settings }))
568600
},
569601
onImpSession() {
570602
const impjson = this.ui.impSessionDialog.impval
@@ -601,7 +633,7 @@ function printHtml(data, curapp = null) {
601633
},
602634
onUseSession(session) {
603635
axios.post('/api', JSON.stringify({ cmd: 'useSession', val: session }))
604-
this.ui.curapp.datas = session.datas
636+
this.ui.curapp.datas = JSON.parse(JSON.stringify(session.datas))
605637
},
606638
onCopy(e) {
607639
this.ui.snackbar.show = true

0 commit comments

Comments
 (0)