renusify 2.2.0 → 2.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,500 +1,501 @@
1
1
  <template>
2
- <div :class="`${$r.prefix}table-manage`">
3
- <r-modal bottom full-width v-model="showForm">
4
- <slot name="form" :autoSend="autoSend"
5
- :method="method"
6
- :options="table.option"
7
- :title="title"
8
- :url="url"
9
- :modelValue="editedItem"
10
- :ok="ok">
11
- <r-form-creator :autoSend="autoSend"
12
- :method="method"
13
- :options="table.option"
14
- :title="title"
15
- :url="url"
16
- :modelValue="editedItem"
17
- @ok="ok"
18
- ></r-form-creator>
19
- </slot>
20
- </r-modal>
21
- <r-modal v-model="showCopy" bottom full-width>
22
- <div class="pa-3">
23
- <div :key="key" class="mb-5"
24
- v-for="(item,key) in table.option">
25
- <template v-if="item['formInput']!==false">
2
+ <div :class="`${$r.prefix}table-manage`">
3
+ <r-modal v-model="showForm" bottom full-width>
4
+ <slot :autoSend="autoSend" :method="method"
5
+ :modelValue="editedItem"
6
+ :ok="ok"
7
+ :options="table.option"
8
+ :title="title"
9
+ :url="url"
10
+ name="form">
11
+ <r-form-creator :autoSend="autoSend"
12
+ :method="method"
13
+ :modelValue="editedItem"
14
+ :options="table.option"
15
+ :title="title"
16
+ :url="url"
17
+ @ok="ok"
18
+ ></r-form-creator>
19
+ </slot>
20
+ </r-modal>
21
+ <r-modal v-model="showCopy" bottom full-width>
22
+ <div class="pa-3">
23
+ <div v-for="(item,key) in table.option" :key="key"
24
+ class="mb-5">
25
+ <template v-if="item['formInput']!==false">
26
26
 
27
- <r-json-input v-if="item['type']==='file-uploader'" baseArray :label="$t(key,'renusify')"
28
- v-model="copyItem['d'][key]"></r-json-input>
29
- <component
30
- v-else
31
- :is="item['type']"
32
- :label="$t(key,'renusify')"
33
- v-model="copyItem['d'][key]"
34
- v-bind="getAttr(table.option[key],copyItem['t'])['props']"
35
- ></component>
36
- </template>
37
- </div>
27
+ <r-json-input v-if="item['type']==='file-uploader'" v-model="copyItem['d'][key]" :label="$t(key,'renusify')"
28
+ baseArray></r-json-input>
29
+ <component
30
+ :is="item['type']"
31
+ v-else
32
+ v-model="copyItem['d'][key]"
33
+ :label="$t(key,'renusify')"
34
+ v-bind="getAttr(table.option[key],copyItem['t'])['props']"
35
+ ></component>
36
+ </template>
37
+ </div>
38
38
 
39
- <r-divider class="my-5"></r-divider>
40
- <div class="d-flex h-space-between v-baseline">
39
+ <r-divider class="my-5"></r-divider>
40
+ <div class="d-flex h-space-between v-baseline">
41
41
  <span>
42
42
  <r-number-input v-if="copyItem['t']==='copy'" :label="$t('count_copy','renusify')"
43
43
  v-model="copyItem['c']"></r-number-input>
44
44
  </span>
45
- <r-btn :loading="loading" class="color-success" @click.prevent="copyAll()">{{
46
- $t('send', 'renusify')
47
- }}
48
- </r-btn>
49
- </div>
50
- </div>
51
- </r-modal>
52
- <manage-header v-model="search" @update:modelValue="searching()"
53
- :header-table="table.headers"
54
- :mcud="showMCUD"
55
- :advance-search="advanceSearch" :disable-add="disableAdd" :new-item="newItem"
56
- :loading="loading"
57
- @delete="deleteAll()"
58
- @copy="copyHandle('copy')"
59
- @edit="copyHandle('edit')"
60
- @a-search="(a_search=$event),(searching())"></manage-header>
61
- <r-table :responsive="responsive" transition="table-row" :headers="headerTable" :items="table.data"
62
- key-item="_id">
63
- <template v-slot:header="{header}">
64
- <th :class="{
45
+ <r-btn :loading="loading" class="color-success" @click.prevent="copyAll()">{{
46
+ $t('send', 'renusify')
47
+ }}
48
+ </r-btn>
49
+ </div>
50
+ </div>
51
+ </r-modal>
52
+ <manage-header v-model="search" :advance-search="advanceSearch"
53
+ :disable-add="disableAdd"
54
+ :header-table="table.headers"
55
+ :loading="loading" :mcud="showMCUD" :new-item="newItem"
56
+ @copy="copyHandle('copy')"
57
+ @delete="deleteAll()"
58
+ @edit="copyHandle('edit')"
59
+ @update:modelValue="searching()"
60
+ @a-search="(a_search=$event),(searching())"></manage-header>
61
+ <r-table :headers="headerTable" :items="table.data" :key-item="itemId" :responsive="responsive"
62
+ transition="table-row">
63
+ <template v-slot:header="{header}">
64
+ <th v-for="(item,key) in header"
65
+ :key="`th-${key}`"
66
+ :class="{
65
67
  'header-sortable':$helper.ifHas(item, true, 'option', 'sortable')
66
68
  }"
67
- :key="`th-${key}`"
68
- @click.stop="sortSetup(item)"
69
- v-for="(item,key) in header">
70
- <div v-if="item.option.type==='mcud'">
71
- <input
72
- class="table-checkbox"
73
- v-model="check_all"
74
- type="checkbox">
75
- </div>
76
- <div v-else class="d-flex v-end">
77
- <div class="w-90"><span>{{ item.text }}</span></div>
78
- <div class="w-10 icon-holder" :class="{
69
+ @click.stop="sortSetup(item)">
70
+ <div v-if="item.option.type==='mcud'">
71
+ <input
72
+ v-model="check_all"
73
+ class="table-checkbox"
74
+ type="checkbox">
75
+ </div>
76
+ <div v-else class="d-flex v-end">
77
+ <div class="w-90"><span>{{ item.text }}</span></div>
78
+ <div :class="{
79
79
  'icon-hidden': !(sortBy === item.value && sortType !== 0)
80
- }"
81
- >
82
- <r-icon v-if="(sortType === 2 && sortBy === item.value)"
83
- v-html="this.$r.icons.arrow_down"></r-icon>
84
- <r-icon v-if="(sortType !== 2 || sortBy !== item.value)"
85
- v-html="this.$r.icons.arrow_up"></r-icon>
80
+ }" class="w-10 icon-holder"
81
+ >
82
+ <r-icon v-if="(sortType === 2 && sortBy === item.value)"
83
+ v-html="this.$r.icons.arrow_down"></r-icon>
84
+ <r-icon v-if="(sortType !== 2 || sortBy !== item.value)"
85
+ v-html="this.$r.icons.arrow_up"></r-icon>
86
86
 
87
- </div>
87
+ </div>
88
88
 
89
- </div>
90
- </th>
91
- </template>
89
+ </div>
90
+ </th>
91
+ </template>
92
92
 
93
- <template v-slot:row="props">
94
- <slot name="row" :table="props" :editItem="editItem" :deleteItem="deleteItem">
95
- <td :key="`td-${key2}`"
96
- v-for="(value,key2) in props.th">
97
- <input v-if="value['option']['type']==='mcud'"
98
- class="table-checkbox"
99
- v-model="checked[props.item['_id']]"
100
- @update:model-value="$event===false?check_all=false:''"
101
- :checked="check_all"
102
- type="checkbox">
103
- <r-btn @click.prevent="props.open(props.key)"
104
- icon text v-if="props.show(key2)">
105
- <r-icon v-html="props.opened!==props.key?$r.icons.plus:$r.icons.minus"></r-icon>
106
- </r-btn>
107
- <slot name="cell" :value="value" :item="props.item" :editItem="editItem">
108
- <div
109
- v-if="value['option']['type']==='r-date-input' && props.item[value['value']]!==undefined">
110
- {{ $d(new Date(props.item[value['value']]), value['option']['format'] || 'short') }}
111
- </div>
112
- <div
113
- v-else-if="value['option']['type']==='r-time-ago' && props.item[value['value']]!==undefined">
114
- <r-time-ago :time="props.item[value['value']]"></r-time-ago>
115
- </div>
116
- <div v-else-if="value['option']['type']==='r-switch-input'">
117
- <r-switch-input
118
- :readonly="value['option']['formInput']===false"
119
- :modelValue="props.item[value['value']]"
120
- @update:modelValue="value['option']['formInput']!==false?editItem(props.item,true,value['value']):''"
121
- class="mt-0"
122
- ></r-switch-input>
123
- </div>
124
- <div v-else-if="value['option']['type'] === 'r-number-input'">
125
- {{ $n(props.item[value["value"]]) }}
126
- </div>
127
- <div v-else-if="value['option']['type']!=='action'">
128
- {{
129
- value['value'] in cast ?
130
- $helper.ifHas(props.item, '', value['value'], cast[value['value']])
131
- : props.item[value['value']]
132
- }}
133
- </div>
134
- </slot>
135
- <div v-if="value['option']['type']==='action'">
136
- <r-btn v-if="!disableUpdate" @click.prevent="editItem(props.item)"
137
- class="mx-0 color-success-text" icon text>
138
- <r-icon exact v-html="$r.icons.edit"></r-icon>
139
- </r-btn>
140
- <r-btn v-if="!disableDelete" @click.prevent="deleteItem(props.item)"
141
- class="mx-0 color-error-text" icon text>
142
- <r-icon v-html="$r.icons.delete"></r-icon>
143
- </r-btn>
144
- <r-btn :key="index" @click.prevent="$emit(val.name,props.item)" class="mx-0" icon text
145
- v-for="(val,index) in actions" :class="`color-${val.color}-text`">
146
- <r-icon exact v-html="val.icon"></r-icon>
147
- </r-btn>
148
- </div>
149
- </td>
150
- </slot>
151
- </template>
93
+ <template v-slot:row="props">
94
+ <slot :deleteItem="deleteItem" :editItem="editItem" :table="props" name="row">
95
+ <td v-for="(value,key2) in props.th"
96
+ :key="`td-${key2}`">
97
+ <input v-if="value['option']['type']==='mcud'"
98
+ v-model="checked[props.item[itemId]]"
99
+ :checked="check_all"
100
+ class="table-checkbox"
101
+ type="checkbox"
102
+ @update:model-value="$event===false?check_all=false:''">
103
+ <r-btn v-if="props.show(key2)"
104
+ icon text @click.prevent="props.open(props.key)">
105
+ <r-icon v-html="props.opened!==props.key?$r.icons.plus:$r.icons.minus"></r-icon>
106
+ </r-btn>
107
+ <slot :editItem="editItem" :item="props.item" :value="value" name="cell">
108
+ <div
109
+ v-if="value['option']['type']==='r-date-input' && props.item[value['value']]!==undefined">
110
+ {{ $d(new Date(props.item[value['value']]), value['option']['format'] || 'short') }}
111
+ </div>
112
+ <div
113
+ v-else-if="value['option']['type']==='r-time-ago' && props.item[value['value']]!==undefined">
114
+ <r-time-ago :time="props.item[value['value']]"></r-time-ago>
115
+ </div>
116
+ <div v-else-if="value['option']['type']==='r-switch-input'">
117
+ <r-switch-input
118
+ :modelValue="props.item[value['value']]"
119
+ :readonly="value['option']['formInput']===false"
120
+ class="mt-0"
121
+ @update:modelValue="value['option']['formInput']!==false?editItem(props.item,true,value['value']):''"
122
+ ></r-switch-input>
123
+ </div>
124
+ <div v-else-if="value['option']['type'] === 'r-number-input'">
125
+ {{ $n(props.item[value["value"]]) }}
126
+ </div>
127
+ <div v-else-if="value['option']['type']!=='action'">
128
+ {{
129
+ value['value'] in cast ?
130
+ $helper.ifHas(props.item, '', value['value'], cast[value['value']])
131
+ : props.item[value['value']]
132
+ }}
133
+ </div>
134
+ </slot>
135
+ <div v-if="value['option']['type']==='action'">
136
+ <r-btn v-if="!disableUpdate" class="mx-0 color-success-text"
137
+ icon text @click.prevent="editItem(props.item)">
138
+ <r-icon exact v-html="$r.icons.edit"></r-icon>
139
+ </r-btn>
140
+ <r-btn v-if="!disableDelete" class="mx-0 color-error-text"
141
+ icon text @click.prevent="deleteItem(props.item)">
142
+ <r-icon v-html="$r.icons.delete"></r-icon>
143
+ </r-btn>
144
+ <r-btn v-for="(val,index) in actions" :key="index" :class="`color-${val.color}-text`" class="mx-0" icon
145
+ text @click.prevent="$emit(val.name,props.item)">
146
+ <r-icon exact v-html="val.icon"></r-icon>
147
+ </r-btn>
148
+ </div>
149
+ </td>
150
+ </slot>
151
+ </template>
152
152
 
153
- </r-table>
154
- <manage-footer v-model:page="page" v-model:per-page="itemsPerPage" :total="table.total"></manage-footer>
155
- <r-confirm
156
- hard
157
- v-model="showConfirm"
158
- v-on:accept="accept"
159
- v-on:cancel="showConfirm = false"
160
- />
161
- </div>
153
+ </r-table>
154
+ <manage-footer v-model:page="page" v-model:per-page="itemsPerPage" :total="table.total"></manage-footer>
155
+ <r-confirm
156
+ v-model="showConfirm"
157
+ hard
158
+ v-on:accept="accept"
159
+ v-on:cancel="showConfirm = false"
160
+ />
161
+ </div>
162
162
  </template>
163
163
 
164
164
  <script>
165
165
  import {defineAsyncComponent} from 'vue'
166
166
 
167
167
  export default {
168
- name: 'r-table-crud',
169
- components: {
170
- ManageHeader: defineAsyncComponent(() =>
171
- import("./header")
172
- ), ManageFooter: defineAsyncComponent(() =>
173
- import("./footer")
174
- )
168
+ name: 'r-table-crud',
169
+ components: {
170
+ ManageHeader: defineAsyncComponent(() =>
171
+ import("./header")
172
+ ), ManageFooter: defineAsyncComponent(() =>
173
+ import("./footer")
174
+ )
175
+ },
176
+ props: {
177
+ link: {
178
+ required: true,
179
+ type: String
180
+ },
181
+ actions: {
182
+ default: function () {
183
+ return []
184
+ },
185
+ type: Array
186
+ },
187
+ cast: {
188
+ default: function () {
189
+ return {}
190
+ },
191
+ type: Object
192
+ },
193
+ perPage: {
194
+ type: Object, default: () => {
195
+ return {name: '10', value: 10}
196
+ }
197
+ },
198
+ query: Object,
199
+ responsive: {
200
+ type: Boolean,
201
+ default: true
175
202
  },
176
- props: {
177
- link: {
178
- required: true,
179
- type: String
180
- },
181
- actions: {
182
- default: function () {
183
- return []
184
- },
185
- type: Array
186
- },
187
- cast: {
188
- default: function () {
189
- return {}
190
- },
191
- type: Object
192
- },
193
- perPage: {
194
- type: Object, default: () => {
195
- return {name: '10', value: 10}
196
- }
197
- },
198
- query: Object,
199
- responsive: {
200
- type: Boolean,
201
- default: true
202
- },
203
203
 
204
- disableAdd: Boolean,
205
- advanceSearch: {type: Boolean, default: true},
206
- disableDelete: Boolean,
207
- disableUpdate: Boolean,
208
- mcud: String,
209
- headers: Object
204
+ disableAdd: Boolean,
205
+ advanceSearch: {type: Boolean, default: true},
206
+ disableDelete: Boolean,
207
+ disableUpdate: Boolean,
208
+ mcud: String,
209
+ itemId: {type: String, default: "_id"},
210
+ headers: Object
211
+ },
212
+ emits: ['actions'],
213
+ data() {
214
+ return {
215
+ time_out_id: null,
216
+ loading: false,
217
+ showForm: false,
218
+ showCopy: false,
219
+ showConfirm: false,
220
+ search: '',
221
+ a_search: {},
222
+ copyItem: {'d': {}, 'c': 1},
223
+ editedItem: {},
224
+ deleted: '',
225
+ url: '',
226
+ method: 'post',
227
+ title: '',
228
+ autoSend: false,
229
+ itemsPerPage: this.perPage,
230
+ page: 1,
231
+ sortBy: null,
232
+ sortType: 0,
233
+ table: {
234
+ headers: [],
235
+ option: {},
236
+ data: [],
237
+ startTime: false,
238
+ total: 0
239
+ },
240
+ check_all: false,
241
+ checked: {}
242
+ }
243
+ },
244
+ created() {
245
+ this.refresh()
246
+ },
247
+ watch: {
248
+ page: function (n, o) {
249
+ if (n > 0) {
250
+ this.refresh()
251
+ }
210
252
  },
211
- emits: ['actions'],
212
- data() {
213
- return {
214
- time_out_id: null,
215
- loading: false,
216
- showForm: false,
217
- showCopy: false,
218
- showConfirm: false,
219
- search: '',
220
- a_search: {},
221
- copyItem: {'d': {}, 'c': 1},
222
- editedItem: {},
223
- deleted: '',
224
- url: '',
225
- method: 'post',
226
- title: '',
227
- autoSend: false,
228
- itemsPerPage: this.perPage,
229
- page: 1,
230
- sortBy: null,
231
- sortType: 0,
232
- table: {
233
- headers: [],
234
- option: {},
235
- data: [],
236
- startTime: false,
237
- total: 0
238
- },
239
- check_all: false,
240
- checked: {}
253
+ itemsPerPage: function () {
254
+ this.refresh()
255
+ }
256
+ },
257
+ computed: {
258
+ showMCUD() {
259
+ if (this.check_all) {
260
+ return true
261
+ }
262
+ for (let k in this.checked) {
263
+ if (this.checked[k] === true) {
264
+ return true
265
+ }
266
+ }
267
+ return false
268
+ },
269
+ headerTable() {
270
+ const headers = this.table.headers
271
+ const res = []
272
+ const lng = headers.length
273
+ for (let i = 0; i < lng; i++) {
274
+ if (this.$helper.ifHas(headers[i], true, 'option', 'tableShow') !== false) {
275
+ res.push(headers[i])
276
+ }
277
+ }
278
+ return res
279
+ }
280
+ },
281
+ methods: {
282
+ getAttr(data, typ) {
283
+ let res = {}
284
+ let ls = ['formInput', 'sortable', 'type', 'tableShow', 'priority']
285
+ if (typ === 'edit') {
286
+ ls.push('rules')
287
+ }
288
+ for (let i in data) {
289
+ if (this.$helper.hasKey(data, i) &&
290
+ !ls.includes(i)) {
291
+ res[i] = data[i]
241
292
  }
293
+ }
294
+ return res
242
295
  },
243
- created() {
296
+ copyAll() {
297
+ this.loading = true
298
+ this.$axios[this.copyItem['t'] === 'copy' ? 'post' : 'put'](this.mcud, this.copyItem, {headers: this.headers}).then(() => {
299
+ this.loading = false
300
+ this.showCopy = false
244
301
  this.refresh()
302
+ }, () => {
303
+ this.loading = false
304
+ })
245
305
  },
246
- watch: {
247
- page: function (n, o) {
248
- if (n > 0) {
249
- this.refresh()
250
- }
251
- },
252
- itemsPerPage: function () {
253
- this.refresh()
306
+ copyHandle(typ = 'copy') {
307
+ this.copyItem = {'d': {}, 'c': 1, 't': typ}
308
+ if (typ === 'edit') {
309
+ this.copyItem['ids'] = this.get_ids()
310
+ if (this.copyItem['ids'].length === 0) {
311
+ return
312
+ }
313
+ }
314
+ if (typ === 'copy') {
315
+ if (this.check_all) {
316
+ this.copyItem['d'] = this.table.data[0]
317
+ this.copyItem['c'] = 1
318
+ }
319
+ for (let k in this.checked) {
320
+ if (this.checked[k] === true) {
321
+ this.table.data.forEach((item) => {
322
+ if (item[this.itemId] === k) {
323
+ this.copyItem['d'] = item
324
+ this.copyItem['c'] = 1
325
+ }
326
+ })
327
+ break
328
+ }
254
329
  }
330
+ }
331
+ this.showCopy = true
255
332
  },
256
- computed: {
257
- showMCUD() {
258
- if (this.check_all) {
259
- return true
260
- }
261
- for (let k in this.checked) {
262
- if (this.checked[k] === true) {
263
- return true
264
- }
265
- }
266
- return false
267
- },
268
- headerTable() {
269
- const headers = this.table.headers
270
- const res = []
271
- const lng = headers.length
272
- for (let i = 0; i < lng; i++) {
273
- if (this.$helper.ifHas(headers[i], true, 'option', 'tableShow') !== false) {
274
- res.push(headers[i])
275
- }
276
- }
277
- return res
333
+ get_ids() {
334
+ let res = []
335
+ if (this.check_all) {
336
+ this.table.data.forEach((item) => {
337
+ res.push(item[this.itemId])
338
+ })
339
+ }
340
+ for (let k in this.checked) {
341
+ if (this.checked[k] === true) {
342
+ res.push(k)
278
343
  }
344
+ }
345
+ return res
279
346
  },
280
- methods: {
281
- getAttr(data, typ) {
282
- let res = {}
283
- let ls = ['formInput', 'sortable', 'type', 'tableShow', 'priority']
284
- if (typ === 'edit') {
285
- ls.push('rules')
286
- }
287
- for (let i in data) {
288
- if (this.$helper.hasKey(data, i) &&
289
- !ls.includes(i)) {
290
- res[i] = data[i]
291
- }
292
- }
293
- return res
294
- },
295
- copyAll() {
296
- this.loading = true
297
- this.$axios[this.copyItem['t'] === 'copy' ? 'post' : 'put'](this.mcud, this.copyItem, {headers: this.headers}).then(() => {
298
- this.loading = false
299
- this.showCopy = false
300
- this.refresh()
301
- }, () => {
302
- this.loading = false
347
+ deleteAll() {
348
+ let res = this.get_ids()
349
+ if (res.length > 0) {
350
+ this.$axios.delete(this.mcud, {
351
+ data: {
352
+ ids: res
353
+ },
354
+ headers: this.headers
355
+ })
356
+ .then(() => {
357
+ this.refresh()
303
358
  })
304
- },
305
- copyHandle(typ = 'copy') {
306
- this.copyItem = {'d': {}, 'c': 1, 't': typ}
307
- if (typ === 'edit') {
308
- this.copyItem['ids'] = this.get_ids()
309
- if (this.copyItem['ids'].length === 0) {
310
- return
311
- }
312
- }
313
- if (typ === 'copy') {
314
- if (this.check_all) {
315
- this.copyItem['d'] = this.table.data[0]
316
- this.copyItem['c'] = 1
317
- }
318
- for (let k in this.checked) {
319
- if (this.checked[k] === true) {
320
- this.table.data.forEach((item) => {
321
- if (item._id === k) {
322
- this.copyItem['d'] = item
323
- this.copyItem['c'] = 1
324
- }
325
- })
326
- break
327
- }
328
- }
329
- }
330
- this.showCopy = true
331
- },
332
- get_ids() {
333
- let res = []
334
- if (this.check_all) {
335
- this.table.data.forEach((item) => {
336
- res.push(item._id)
337
- })
338
- }
339
- for (let k in this.checked) {
340
- if (this.checked[k] === true) {
341
- res.push(k)
342
- }
343
- }
344
- return res
345
- },
346
- deleteAll() {
347
- let res = this.get_ids()
348
- if (res.length > 0) {
349
- this.$axios.delete(this.mcud, {
350
- data: {
351
- ids: res
352
- },
353
- headers: this.headers
354
- })
355
- .then(() => {
356
- this.refresh()
357
- })
358
- }
359
- },
360
- sortSetup(item) {
361
- if (!this.$helper.ifHas(item, true, 'option', 'sortable')) {
362
- return
363
- }
364
- if (this.sortBy !== item.value) {
365
- this.sortType = 0
366
- }
367
- this.sortBy = item.value
368
- if (this.sortType >= 2) {
369
- this.sortType = 0
370
- } else {
371
- this.sortType += 1
372
- }
373
- this.refresh()
374
- },
375
- ok() {
376
- this.refresh()
377
- this.autoSend = false
378
- this.showForm = false
379
- },
380
- refresh(e) {
381
- this.loading = true
382
- this.check_all = false
383
- this.checked = {}
384
- const perPage = e !== undefined ? e.value : this.itemsPerPage.value
385
- let params = this.query || {}
386
- params.page = this.page
387
- if (this.table.startTime !== false) {
388
- params.t = this.table.startTime
389
- }
390
- if (this.sortType !== 0) {
391
- const sort = (this.sortType === 2) ? 'desc' : 'asc'
392
- params[sort] = this.sortBy
393
- }
394
- params.per_page = perPage
395
- if (this.search.length >= 1) {
396
- params.search = this.search
397
- }
398
- if (this.$helper.size(this.a_search) > 0) {
399
- params.a_search = JSON.stringify(this.a_search)
400
- }
359
+ }
360
+ },
361
+ sortSetup(item) {
362
+ if (!this.$helper.ifHas(item, true, 'option', 'sortable')) {
363
+ return
364
+ }
365
+ if (this.sortBy !== item.value) {
366
+ this.sortType = 0
367
+ }
368
+ this.sortBy = item.value
369
+ if (this.sortType >= 2) {
370
+ this.sortType = 0
371
+ } else {
372
+ this.sortType += 1
373
+ }
374
+ this.refresh()
375
+ },
376
+ ok() {
377
+ this.refresh()
378
+ this.autoSend = false
379
+ this.showForm = false
380
+ },
381
+ refresh(e) {
382
+ this.loading = true
383
+ this.check_all = false
384
+ this.checked = {}
385
+ const perPage = e !== undefined ? e.value : this.itemsPerPage.value
386
+ let params = this.query || {}
387
+ params.page = this.page
388
+ if (this.table.startTime !== false) {
389
+ params.t = this.table.startTime
390
+ }
391
+ if (this.sortType !== 0) {
392
+ const sort = (this.sortType === 2) ? 'desc' : 'asc'
393
+ params[sort] = this.sortBy
394
+ }
395
+ params.per_page = perPage
396
+ if (this.search.length >= 1) {
397
+ params.search = this.search
398
+ }
399
+ if (this.$helper.size(this.a_search) > 0) {
400
+ params.a_search = JSON.stringify(this.a_search)
401
+ }
401
402
 
402
- this.setup('/' + this.link, params)
403
- },
404
- searching() {
405
- clearTimeout(this.time_out_id)
406
- this.loading = true
407
- this.time_out_id = setTimeout(() => {
408
- this.page = 1
409
- this.refresh()
410
- }, 1000)
403
+ this.setup(this.link, params)
404
+ },
405
+ searching() {
406
+ clearTimeout(this.time_out_id)
407
+ this.loading = true
408
+ this.time_out_id = setTimeout(() => {
409
+ this.page = 1
410
+ this.refresh()
411
+ }, 1000)
411
412
 
412
- },
413
- newItem() {
414
- this.title = this.$t('new', 'renusify')
415
- this.url = this.link
416
- const items = {}
417
- this.table.headers.map((item) => {
418
- if (item.option.formInput !== false) {
419
- if (item.option.type === 'boolean') {
420
- items[item.value] = false
421
- } else {
422
- items[item.value] = null
423
- }
424
- }
425
- })
426
- this.editedItem = items
427
- this.method = 'post'
428
- this.autoSend = false
429
- this.showForm = true
430
- },
431
- editItem(item, autoSend = false, key = null) {
432
- let sw
433
- this.title = this.$t('edit', 'renusify')
434
- this.url = this.link + '/' + item._id
435
- if (key) {
436
- sw = !item[key]
437
- }
438
- const items = {}
439
- this.table.headers.map((header) => {
440
- if (header.option.formInput !== false) {
441
- if (header.option.type === 'boolean') {
442
- items[header.value] = item[header.value] !== undefined ? item[header.value] : false
443
- } else {
444
- items[header.value] = item[header.value] !== undefined ? item[header.value] : null
445
- }
446
- }
447
- })
448
- this.editedItem = Object.assign({}, items)
413
+ },
414
+ newItem() {
415
+ this.title = this.$t('new', 'renusify')
416
+ this.url = this.link
417
+ const items = {}
418
+ this.table.headers.map((item) => {
419
+ if (item.option.formInput !== false) {
420
+ if (item.option.type === 'boolean') {
421
+ items[item.value] = false
422
+ } else {
423
+ items[item.value] = null
424
+ }
425
+ }
426
+ })
427
+ this.editedItem = items
428
+ this.method = 'post'
429
+ this.autoSend = false
430
+ this.showForm = true
431
+ },
432
+ editItem(item, autoSend = false, key = null) {
433
+ let sw
434
+ this.title = this.$t('edit', 'renusify')
435
+ this.url = this.link + '/' + item[this.itemId]
436
+ if (key) {
437
+ sw = !item[key]
438
+ }
439
+ const items = {}
440
+ this.table.headers.map((header) => {
441
+ if (header.option.formInput !== false) {
442
+ if (header.option.type === 'boolean') {
443
+ items[header.value] = item[header.value] !== undefined ? item[header.value] : false
444
+ } else {
445
+ items[header.value] = item[header.value] !== undefined ? item[header.value] : null
446
+ }
447
+ }
448
+ })
449
+ this.editedItem = Object.assign({}, items)
449
450
 
450
- if (key) {
451
- this.editedItem[key] = sw
452
- }
453
- this.method = 'put'
454
- this.autoSend = autoSend
455
- this.showForm = true
456
- },
457
- deleteItem(item) {
458
- this.showConfirm = true
459
- this.deleted = item._id
460
- },
461
- delete(_id) {
462
- this.$axios.delete(this.link + '/' + _id, {headers: this.headers})
463
- .then((res) => {
464
- this.refresh()
465
- })
466
- },
467
- accept() {
468
- this.showConfirm = false
469
- this.delete(this.deleted)
470
- this.deleted = ''
451
+ if (key) {
452
+ this.editedItem[key] = sw
453
+ }
454
+ this.method = 'put'
455
+ this.autoSend = autoSend
456
+ this.showForm = true
457
+ },
458
+ deleteItem(item) {
459
+ this.showConfirm = true
460
+ this.deleted = item[this.itemId]
461
+ },
462
+ delete(_id) {
463
+ this.$axios.delete(this.link + '/' + _id, {headers: this.headers})
464
+ .then((res) => {
471
465
  this.refresh()
472
- },
473
- setup(url, params = null) {
474
- this.loading = true
475
-
476
- this.$axios.get(url, {params: params, headers: this.headers}).then(({data}) => {
477
- let all = []
478
- if (this.mcud) {
479
- all.push({
480
- option: {type: "mcud", sortable: false, formInput: false, priority: 10},
481
- text: "action",
482
- value: "action"
483
- })
484
- }
485
- all = all.concat(data.headers)
466
+ })
467
+ },
468
+ accept() {
469
+ this.showConfirm = false
470
+ this.delete(this.deleted)
471
+ this.deleted = ''
472
+ this.refresh()
473
+ },
474
+ setup(url, params = null) {
475
+ this.loading = true
486
476
 
487
- this.table.headers = all.map((item) => {
488
- this.table.option[item.value] = item.option
489
- item.text = this.$t(item.value)
490
- return item
491
- })
492
- this.table.data = data.data
493
- this.table.total = data.total
494
- this.table.startTime = this.$helper.ifHas(data, false, 't')
495
- this.loading = false
496
- })
477
+ this.$axios.get(url, {params: params, headers: this.headers}).then(({data}) => {
478
+ let all = []
479
+ if (this.mcud) {
480
+ all.push({
481
+ option: {type: "mcud", sortable: false, formInput: false, priority: 10},
482
+ text: "action",
483
+ value: "action"
484
+ })
497
485
  }
486
+ all = all.concat(data.headers)
487
+
488
+ this.table.headers = all.map((item) => {
489
+ this.table.option[item.value] = item.option
490
+ item.text = this.$t(item.value)
491
+ return item
492
+ })
493
+ this.table.data = data.data
494
+ this.table.total = data.total
495
+ this.table.startTime = this.$helper.ifHas(data, false, 't')
496
+ this.loading = false
497
+ })
498
498
  }
499
+ }
499
500
  }
500
501
  </script>