1+ <template >
2+ <div >
3+ <v-container class =" grey lighten-5" >
4+ <v-row no-gutters >
5+ <v-col
6+ cols =" 12"
7+ sm =" 2"
8+ >
9+ <v-card
10+ class =" pa-2"
11+ outlined
12+ tile
13+ >
14+ <v-spacer ></v-spacer >
15+ <v-text-field
16+ dense
17+ @change =" fetchTags"
18+ v-model =" searchTag"
19+ append-icon =" mdi-magnify"
20+ label =" Search Tag"
21+ hide-details
22+ ></v-text-field >
23+ </v-card >
24+ </v-col >
25+ <v-col
26+ cols =" 12"
27+ sm =" 2"
28+ >
29+ <v-card
30+ class =" pa-2"
31+ outlined
32+ tile
33+ >
34+ <v-spacer ></v-spacer >
35+ <v-text-field
36+ dense
37+ @change =" fetchTags"
38+ v-model =" searchDescription"
39+ append-icon =" mdi-magnify"
40+ label =" Description"
41+ hide-details
42+ ></v-text-field >
43+ </v-card >
44+ </v-col >
45+ </v-row >
46+ </v-container >
47+
48+ <v-data-table
49+ :headers =" headers"
50+ :items =" tags"
51+ :options.sync =" options"
52+ :server-items-length =" totalTags"
53+ :loading =" loading"
54+ :search =" search"
55+ multi-sort
56+ class =" elevation-1"
57+ dense
58+ :items-per-page =" 15"
59+ >
60+ </v-data-table >
61+ </div >
62+ </template >
63+ <script >
64+ // const pause = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
65+
66+ export default {
67+ name: " Tags" ,
68+
69+ data : () => ({
70+ dialog: false ,
71+ active: [],
72+ open: [],
73+ tags: [],
74+ totalTags: 0 ,
75+ searchTag: " " ,
76+ searchDescription: " " ,
77+ loading: true ,
78+ options: {},
79+ headers: [
80+ {
81+ text: " Tag" ,
82+ align: " start" ,
83+ sortable: true ,
84+ value: " tag" ,
85+ },
86+ { text: " Id" , sortable: true , value: " _id" },
87+ { text: " Group1" , sortable: true , value: " group1" },
88+ { text: " Description" , sortable: true , value: " description" },
89+ { text: " Value" , value: " value" },
90+ ],
91+ }),
92+
93+ computed: {
94+ items () {
95+ return [
96+ {
97+ name: " Tags" ,
98+ children: this .tags ,
99+ },
100+ ];
101+ },
102+ selected () {
103+ if (! this .active .length ) return undefined ;
104+
105+ // const id = this.active[0];
106+
107+ return this .tags .find ((tag ) => tag .tag === tag);
108+ },
109+ },
110+
111+ watch: {
112+ options: {
113+ handler () {
114+ this .fetchTags ();
115+ },
116+ deep: true ,
117+ },
118+ },
119+
120+ mounted () {
121+ this .fetchTags ();
122+ },
123+
124+ methods: {
125+ async fetchTags () {
126+ const { sortBy , sortDesc , page , itemsPerPage } = this .options ;
127+ let filter = {}
128+
129+ if (this .searchTag .trim ()!= " " )
130+ filter .tag = {' $regex' : this .searchTag , ' $options' : ' i' }
131+ if (this .searchDescription .trim ()!= " " )
132+ filter .description = {' $regex' : this .searchDescription , ' $options' : ' i' }
133+
134+ this .loading = true ;
135+ return await fetch (" /Invoke/auth/listTags" , {
136+ method: " post" ,
137+ headers: {
138+ Accept: " application/json" ,
139+ " Content-Type" : " application/json" ,
140+ },
141+ body: JSON .stringify ({
142+ itemsPerPage: itemsPerPage,
143+ sortBy: sortBy,
144+ sortDesc: sortDesc,
145+ page: page,
146+ filter: filter
147+ }),
148+ })
149+ .then ((res ) => res .json ())
150+ .then ((json ) => {
151+ // for (let i = 0; i < json.length; i++) {
152+ // json[i].id = (page-1)*itemsPerPage + i + 1;
153+ // }
154+ this .tags .length = 0 ;
155+ this .tags .push (... json .tags );
156+ this .totalTags = json .countTotal ;
157+ this .loading = false ;
158+ })
159+ .catch ((err ) => {
160+ console .warn (err);
161+ this .loading = false ;
162+ });
163+ },
164+ },
165+ };
166+ </script >
0 commit comments