Skip to content

Commit db0559e

Browse files
committed
✨ 储存增加重新加载与清空选项
1 parent d920c5d commit db0559e

File tree

2 files changed

+90
-30
lines changed

2 files changed

+90
-30
lines changed

src/apps/script/controller.ts

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,34 @@
11
import { v5 as uuidv5 } from 'uuid';
2-
import { SCRIPT_STATUS_ENABLE, SCRIPT_STATUS_DISABLE, Script, SCRIPT_RUN_STATUS_COMPLETE, SCRIPT_TYPE_BACKGROUND, SCRIPT_TYPE_CRONTAB, SCRIPT_TYPE_NORMAL, ScriptCache } from '@App/model/do/script';
2+
import {
3+
SCRIPT_STATUS_ENABLE,
4+
SCRIPT_STATUS_DISABLE,
5+
Script,
6+
SCRIPT_RUN_STATUS_COMPLETE,
7+
SCRIPT_TYPE_BACKGROUND,
8+
SCRIPT_TYPE_CRONTAB,
9+
SCRIPT_TYPE_NORMAL,
10+
ScriptCache
11+
} from '@App/model/do/script';
312
import { ScriptModel } from '@App/model/script';
413
import { get, Page, randomString } from '@App/pkg/utils/utils';
5-
import { ScriptExec, ScriptStatusChange, ScriptStop, ScriptUninstall, ScriptReinstall, ScriptInstall, RequestInstallInfo, ScriptCheckUpdate, RequestConfirmInfo, SubscribeUpdate, Unsubscribe, SubscribeCheckUpdate, ImportFile, OpenImportFileWindow, RequestImportFile, ScriptValueChange } from '../msg-center/event';
14+
import {
15+
ScriptExec,
16+
ScriptStatusChange,
17+
ScriptStop,
18+
ScriptUninstall,
19+
ScriptReinstall,
20+
ScriptInstall,
21+
RequestInstallInfo,
22+
ScriptCheckUpdate,
23+
RequestConfirmInfo,
24+
SubscribeUpdate,
25+
Unsubscribe,
26+
SubscribeCheckUpdate,
27+
ImportFile,
28+
OpenImportFileWindow,
29+
RequestImportFile,
30+
ScriptValueChange
31+
} from '../msg-center/event';
632
import { MsgCenter } from '../msg-center/msg-center';
733
import { parseMetadata, parseUserConfig, copyScript, copySubscribe } from './utils';
834
import { ScriptUrlInfo } from '../msg-center/structs';
@@ -369,7 +395,8 @@ export class ScriptController {
369395
});
370396
}
371397
if (model) {
372-
void this.valueModel.delete(model.id);
398+
model.value = undefined;
399+
void await this.valueModel.delete(model.id);
373400
MsgCenter.connect(ScriptValueChange, { model: model, tabid: undefined });
374401
}
375402
resolve(undefined);

src/views/pages/Option/tabs/ScriptTab/Storage.vue

Lines changed: 60 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,24 @@
99
hide-details
1010
></v-text-field>
1111
<v-spacer></v-spacer>
12+
<v-btn
13+
color="blue-grey"
14+
dark
15+
class="mb-2"
16+
@click="reload"
17+
style="margin-right: 10px"
18+
>
19+
重新加载
20+
</v-btn>
21+
<v-btn
22+
color="error"
23+
dark
24+
class="mb-2"
25+
@click="clearAll"
26+
style="margin-right: 10px"
27+
>
28+
清空
29+
</v-btn>
1230
<v-dialog v-model="dialog" max-width="500px">
1331
<template v-slot:activator="{ on, attrs }">
1432
<v-btn color="primary" dark class="mb-2" v-bind="attrs" v-on="on">
@@ -40,8 +58,8 @@
4058

4159
<v-card-actions>
4260
<v-spacer></v-spacer>
43-
<v-btn color="blue darken-1" text @click="close"> 取消 </v-btn>
44-
<v-btn color="blue darken-1" text @click="save"> 保存 </v-btn>
61+
<v-btn color="blue darken-1" text @click="close"> 取消</v-btn>
62+
<v-btn color="blue darken-1" text @click="save"> 保存</v-btn>
4563
</v-card-actions>
4664
</v-card>
4765
</v-dialog>
@@ -62,7 +80,7 @@
6280
{{
6381
(script.metadata["storagename"] &&
6482
script.metadata["storagename"][0]) ||
65-
"匿名空间"
83+
"匿名空间"
6684
}}
6785
</p>
6886
<v-spacer></v-spacer>
@@ -72,11 +90,11 @@
7290
<v-card-actions>
7391
<v-spacer></v-spacer>
7492
<v-btn color="blue darken-1" text @click="closeDelete"
75-
>取消</v-btn
76-
>
93+
>取消
94+
</v-btn>
7795
<v-btn color="blue darken-1" text @click="deleteItemConfirm"
78-
>确定</v-btn
79-
>
96+
>确定
97+
</v-btn>
8098
<v-spacer></v-spacer>
8199
</v-card-actions>
82100
</v-card>
@@ -94,7 +112,7 @@
94112
{{ icons.mdiDelete }}
95113
</v-icon>
96114
</template>
97-
<template v-slot:no-data> 没有储存数据 </template>
115+
<template v-slot:no-data> 没有储存数据</template>
98116
</v-data-table>
99117
<v-card-subtitle>
100118
值的第一个字符表示该值的类型,在编辑值时请也按照此规则进行编辑,否则默认识别为文本.
@@ -104,12 +122,12 @@
104122
</template>
105123

106124
<script lang="ts">
107-
import { ScriptController } from "@App/apps/script/controller";
108-
import { Script } from "@App/model/do/script";
109-
import { Value } from "@App/model/do/value";
110-
import { parseStorageValue, toStorageValueStr } from "@App/views/pages/utils";
111-
import { Component, Prop, Vue, Watch } from "vue-property-decorator";
112-
import { mdiMagnify, mdiPencil, mdiDelete } from "@mdi/js";
125+
import { ScriptController } from '@App/apps/script/controller';
126+
import { Script } from '@App/model/do/script';
127+
import { Value } from '@App/model/do/value';
128+
import { parseStorageValue, toStorageValueStr } from '@App/views/pages/utils';
129+
import { Component, Prop, Vue, Watch } from 'vue-property-decorator';
130+
import { mdiMagnify, mdiPencil, mdiDelete } from '@mdi/js';
113131
114132
@Component({})
115133
export default class CloseButton extends Vue {
@@ -119,56 +137,56 @@ export default class CloseButton extends Vue {
119137
mdiDelete: mdiDelete,
120138
};
121139
scriptCtrl = new ScriptController();
122-
values: Array<Value> = new Array();
140+
values: Array<Value> = [];
123141
dialog = false;
124142
dialogDelete = false;
125143
editedIndex = -1;
126-
editedItem = { key: "", value: "" };
144+
editedItem = { key: '', value: '' };
127145
128146
@Prop() script!: Script;
129147
130148
async created() {
131149
let values = await this.scriptCtrl.getValues(this.script);
132-
console.log(this.script, values);
133150
for (const key in values) {
134151
this.values.push(values[key]);
135152
}
136153
}
137154
138155
data() {
139156
return {
140-
search: "",
157+
search: '',
141158
headers: [
142-
{ text: "储存键", value: "key" },
143-
{ text: "储存值", value: "value" },
144-
{ text: "操作", value: "actions" },
159+
{ text: '储存键', value: 'key' },
160+
{ text: '储存值', value: 'value' },
161+
{ text: '操作', value: 'actions' },
145162
],
146163
};
147164
}
165+
148166
toStorageValueStr = toStorageValueStr;
149167
150-
@Watch("dialog")
168+
@Watch('dialog')
151169
watchDialog(val: any) {
152170
val || this.close();
153171
}
154172
155-
@Watch("dialogDelete")
173+
@Watch('dialogDelete')
156174
watchDialogDelete(val: any) {
157175
val || this.closeDelete();
158176
}
159177
160178
close() {
161179
this.dialog = false;
162180
this.$nextTick(() => {
163-
this.editedItem = { key: "", value: "" };
181+
this.editedItem = { key: '', value: '' };
164182
this.editedIndex = -1;
165183
});
166184
}
167185
168186
closeDelete() {
169187
this.dialogDelete = false;
170188
this.$nextTick(() => {
171-
this.editedItem = { key: "", value: "" };
189+
this.editedItem = { key: '', value: '' };
172190
this.editedIndex = -1;
173191
});
174192
}
@@ -180,7 +198,7 @@ export default class CloseButton extends Vue {
180198
parseStorageValue(this.editedItem.value)
181199
);
182200
if (!value) {
183-
alert("保存失败");
201+
alert('保存失败');
184202
return;
185203
}
186204
if (this.editedIndex > -1) {
@@ -207,9 +225,24 @@ export default class CloseButton extends Vue {
207225
208226
deleteItemConfirm() {
209227
this.values.splice(this.editedIndex, 1);
210-
this.scriptCtrl.deleteValue(this.script, this.editedItem.key);
228+
void this.scriptCtrl.deleteValue(this.script, this.editedItem.key);
211229
this.closeDelete();
212230
}
231+
232+
async reload() {
233+
this.values = [];
234+
let values = await this.scriptCtrl.getValues(this.script);
235+
for (const key in values) {
236+
this.values.push(values[key]);
237+
}
238+
}
239+
240+
async clearAll() {
241+
for (let i = 0; i < this.values.length; i++) {
242+
await this.scriptCtrl.deleteValue(this.script, this.values[i].key);
243+
}
244+
void (await this.reload());
245+
}
213246
}
214247
</script>
215248

0 commit comments

Comments
 (0)