11<template >
2- <div >GM_setValue GM_getValue</div >
2+ <v-card >
3+ <v-card-title >
4+ <v-text-field
5+ v-model =" search"
6+ :append-icon =" icons.mdiMagnify"
7+ label =" 搜索键"
8+ single-line
9+ hide-details
10+ ></v-text-field >
11+ <v-spacer ></v-spacer >
12+ <v-dialog v-model =" dialog" max-width =" 500px" >
13+ <template v-slot :activator =" { on , attrs } " >
14+ <v-btn color =" primary" dark class =" mb-2" v-bind =" attrs" v-on =" on" >
15+ 添加新值
16+ </v-btn >
17+ </template >
18+ <v-card >
19+ <v-card-title >
20+ <span class =" text-h5" >添加新值</span >
21+ </v-card-title >
22+ <v-card-text >
23+ <v-container >
24+ <v-row >
25+ <v-col >
26+ <v-text-field
27+ v-model =" editedItem.key"
28+ label =" 储存键"
29+ ></v-text-field >
30+ </v-col >
31+ <v-col >
32+ <v-text-field
33+ v-model =" editedItem.value"
34+ label =" 储存值"
35+ ></v-text-field >
36+ </v-col >
37+ </v-row >
38+ </v-container >
39+ </v-card-text >
40+
41+ <v-card-actions >
42+ <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 >
45+ </v-card-actions >
46+ </v-card >
47+ </v-dialog >
48+ </v-card-title >
49+ <v-data-table
50+ :headers =" headers"
51+ :items =" values"
52+ :search =" search"
53+ :footer-props =" {
54+ itemsPerPageAllText: '显示全部',
55+ itemsPerPageText: '每行页数',
56+ }"
57+ >
58+ <template v-slot :top >
59+ <v-toolbar flat >
60+ <p >
61+ 储存空间:
62+ {{
63+ (script.metadata["storagename"] &&
64+ script.metadata["storagename"][0]) ||
65+ "匿名空间"
66+ }}
67+ </p >
68+ <v-spacer ></v-spacer >
69+ <v-dialog v-model =" dialogDelete" max-width =" 500px" >
70+ <v-card >
71+ <v-card-title class =" text-h5" >请确定是否删除储存项?</v-card-title >
72+ <v-card-actions >
73+ <v-spacer ></v-spacer >
74+ <v-btn color =" blue darken-1" text @click =" closeDelete"
75+ >取消</v-btn
76+ >
77+ <v-btn color =" blue darken-1" text @click =" deleteItemConfirm"
78+ >确定</v-btn
79+ >
80+ <v-spacer ></v-spacer >
81+ </v-card-actions >
82+ </v-card >
83+ </v-dialog >
84+ </v-toolbar >
85+ </template >
86+ <template v-slot :[` item.value ` ]=" { item } " >
87+ {{ toStorageValueStr(item.value) }}
88+ </template >
89+ <template v-slot :[` item.actions ` ]=" { item } " >
90+ <v-icon small class =" mr-2" @click =" editItem(item)" >
91+ {{ icons.mdiPencil }}
92+ </v-icon >
93+ <v-icon small @click =" deleteItem(item)" >
94+ {{ icons.mdiDelete }}
95+ </v-icon >
96+ </template >
97+ <template v-slot :no-data > 没有储存数据 </template >
98+ </v-data-table >
99+ <v-card-subtitle >
100+ 值的第一个字符表示该值的类型,在编辑值时请也按照此规则进行编辑,否则默认识别为文本.
101+ s:文本 n:数字 b:布尔值 o:对象
102+ </v-card-subtitle >
103+ </v-card >
3104</template >
4105
5106<script lang="ts">
6- import { Component , Prop , Vue } from " vue-property-decorator" ;
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" ;
7113
8114@Component ({})
9- export default class CloseButton extends Vue {}
115+ export default class CloseButton extends Vue {
116+ icons = {
117+ mdiMagnify: mdiMagnify ,
118+ mdiPencil: mdiPencil ,
119+ mdiDelete: mdiDelete ,
120+ };
121+ scriptCtrl = new ScriptController ();
122+ values: Array <Value > = new Array ();
123+ dialog = false ;
124+ dialogDelete = false ;
125+ editedIndex = - 1 ;
126+ editedItem = { key: " " , value: " " };
127+
128+ @Prop () script! : Script ;
129+
130+ async created() {
131+ let values = await this .scriptCtrl .getValues (this .script );
132+ console .log (this .script , values );
133+ for (const key in values ) {
134+ this .values .push (values [key ]);
135+ }
136+ }
137+
138+ data() {
139+ return {
140+ search: " " ,
141+ headers: [
142+ { text: " 储存键" , value: " key" },
143+ { text: " 储存值" , value: " value" },
144+ { text: " 操作" , value: " actions" },
145+ ],
146+ };
147+ }
148+ toStorageValueStr = toStorageValueStr ;
149+
150+ @Watch (" dialog" )
151+ watchDialog(val : any ) {
152+ val || this .close ();
153+ }
154+
155+ @Watch (" dialogDelete" )
156+ watchDialogDelete(val : any ) {
157+ val || this .closeDelete ();
158+ }
159+
160+ close() {
161+ this .dialog = false ;
162+ this .$nextTick (() => {
163+ this .editedItem = { key: " " , value: " " };
164+ this .editedIndex = - 1 ;
165+ });
166+ }
167+
168+ closeDelete() {
169+ this .dialogDelete = false ;
170+ this .$nextTick (() => {
171+ this .editedItem = { key: " " , value: " " };
172+ this .editedIndex = - 1 ;
173+ });
174+ }
175+
176+ async save() {
177+ let value = await this .scriptCtrl .saveValue (
178+ this .script ,
179+ this .editedItem .key ,
180+ parseStorageValue (this .editedItem .value )
181+ );
182+ if (! value ) {
183+ alert (" 保存失败" );
184+ return ;
185+ }
186+ if (this .editedIndex > - 1 ) {
187+ this .values [this .editedIndex ].value = value .value ;
188+ } else {
189+ this .values .unshift (value );
190+ }
191+ this .close ();
192+ }
193+
194+ editItem(item : Value ) {
195+ this .editedIndex = this .values .indexOf (item );
196+ this .editedItem = Object .assign ({}, item );
197+ this .editedItem .value = toStorageValueStr (item .value );
198+ this .dialog = true ;
199+ }
200+
201+ deleteItem(item : Value ) {
202+ this .editedIndex = this .values .indexOf (item );
203+ this .editedItem = Object .assign ({}, item );
204+ this .editedItem .value = toStorageValueStr (item .value );
205+ this .dialogDelete = true ;
206+ }
207+
208+ deleteItemConfirm() {
209+ this .values .splice (this .editedIndex , 1 );
210+ this .scriptCtrl .deleteValue (this .script , this .editedItem .key );
211+ this .closeDelete ();
212+ }
213+ }
10214 </script >
11215
12- <style >
13- </style >
216+ <style ></style >
0 commit comments