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" >
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 >
6280 {{
6381 (script.metadata["storagename"] &&
6482 script.metadata["storagename"][0]) ||
65- "匿名空间"
83+ "匿名空间"
6684 }}
6785 </p >
6886 <v-spacer ></v-spacer >
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 >
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 值的第一个字符表示该值的类型,在编辑值时请也按照此规则进行编辑,否则默认识别为文本.
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 ({})
115133export 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