@netang/quasar 0.0.20
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.
- package/LICENSE +21 -0
- package/README.md +17 -0
- package/components/column-title/index.vue +32 -0
- package/components/dialog/components/index.js +6 -0
- package/components/dialog/components/move-to-tree/index.vue +150 -0
- package/components/dialog/index.vue +330 -0
- package/components/dialog-table/index.vue +92 -0
- package/components/dragger/index.vue +202 -0
- package/components/drawer/index.vue +262 -0
- package/components/field-date/index.vue +844 -0
- package/components/field-date/methods.js +100 -0
- package/components/field-table/index.vue +468 -0
- package/components/field-text/index.vue +167 -0
- package/components/field-tree/index.vue +435 -0
- package/components/input-number/index.vue +324 -0
- package/components/input-number/number.js +67 -0
- package/components/input-price-cent/index.vue +213 -0
- package/components/input-price-yuan/index.vue +179 -0
- package/components/layout/index.vue +119 -0
- package/components/list-menu/index.vue +137 -0
- package/components/list-menu-item/index.vue +79 -0
- package/components/power-data/index.vue +667 -0
- package/components/search/index.vue +176 -0
- package/components/search-item/index.vue +219 -0
- package/components/select/index.vue +71 -0
- package/components/select-filter/index.vue +75 -0
- package/components/table/index.vue +347 -0
- package/components/table-column-fixed/index.vue +68 -0
- package/components/table-pagination/index.vue +83 -0
- package/components/table-summary/index.vue +91 -0
- package/components/thumbnail/index.vue +87 -0
- package/components/toolbar/container.vue +31 -0
- package/components/toolbar/index.vue +405 -0
- package/components/uploader/index.vue +157 -0
- package/components/uploader-query/index.vue +731 -0
- package/package.json +21 -0
- package/sass/common.scss +165 -0
- package/sass/index.scss +14 -0
- package/sass/line.scss +39 -0
- package/sass/quasar/btn.scss +46 -0
- package/sass/quasar/common.scss +3 -0
- package/sass/quasar/dialog.scss +7 -0
- package/sass/quasar/drawer.scss +6 -0
- package/sass/quasar/field.scss +210 -0
- package/sass/quasar/loading.scss +6 -0
- package/sass/quasar/menu.scss +8 -0
- package/sass/quasar/table.scss +112 -0
- package/sass/quasar/toolbar.scss +22 -0
- package/store/index.js +32 -0
- package/utils/$area.js +387 -0
- package/utils/$auth.js +135 -0
- package/utils/$dialog.js +43 -0
- package/utils/$role.js +807 -0
- package/utils/$rule.js +17 -0
- package/utils/$search.js +336 -0
- package/utils/$table.js +802 -0
- package/utils/$tree.js +620 -0
- package/utils/$uploader.js +1029 -0
- package/utils/alert.js +10 -0
- package/utils/bus.js +6 -0
- package/utils/config.js +22 -0
- package/utils/confrim.js +11 -0
- package/utils/dict.js +44 -0
- package/utils/getData.js +61 -0
- package/utils/getFile.js +30 -0
- package/utils/getImage.js +136 -0
- package/utils/getTime.js +94 -0
- package/utils/http.js +251 -0
- package/utils/loading.js +13 -0
- package/utils/notify.js +13 -0
- package/utils/previewImage.js +8 -0
- package/utils/symbols.js +3 -0
- package/utils/timestamp.js +18 -0
- package/utils/toast.js +13 -0
- package/utils/uploader/aliyun.js +6 -0
- package/utils/uploader/local.js +8 -0
- package/utils/uploader/qiniu.js +311 -0
- package/utils/useAuth.js +26 -0
- package/utils/useRouter.js +36 -0
- package/utils/useUploader.js +58 -0
package/utils/$table.js
ADDED
|
@@ -0,0 +1,802 @@
|
|
|
1
|
+
import { ref, computed, watch } from 'vue'
|
|
2
|
+
import { useRoute } from 'vue-router'
|
|
3
|
+
import { date, useQuasar } from 'quasar'
|
|
4
|
+
import { parse } from 'qs'
|
|
5
|
+
|
|
6
|
+
// 表格配置
|
|
7
|
+
import tablesConfig from '@/tables'
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
// 设置单个搜索值
|
|
11
|
+
setItemValue,
|
|
12
|
+
} from './$search'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 获取 url 参数
|
|
16
|
+
*/
|
|
17
|
+
function getUrlQuery(url) {
|
|
18
|
+
|
|
19
|
+
const query = {}
|
|
20
|
+
|
|
21
|
+
if (utils.indexOf(url, '?') > -1) {
|
|
22
|
+
|
|
23
|
+
const arr = url.split('?')
|
|
24
|
+
|
|
25
|
+
url = arr[0]
|
|
26
|
+
const urlQuery = parse(arr[1])
|
|
27
|
+
if (utils.isValidObject(urlQuery)) {
|
|
28
|
+
utils.forIn(urlQuery, function (val, key) {
|
|
29
|
+
|
|
30
|
+
key = utils.trimString(key)
|
|
31
|
+
val = utils.trimString(val)
|
|
32
|
+
|
|
33
|
+
if (key && val) {
|
|
34
|
+
if (val.indexOf(',') > -1) {
|
|
35
|
+
val = val.split(',')
|
|
36
|
+
}
|
|
37
|
+
query[key] = utils.numberDeep(val)
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
url,
|
|
45
|
+
query,
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 对话框设置
|
|
51
|
+
*/
|
|
52
|
+
function dialogSetting($dialog, o) {
|
|
53
|
+
|
|
54
|
+
const {
|
|
55
|
+
dialogProps,
|
|
56
|
+
props,
|
|
57
|
+
} = $dialog
|
|
58
|
+
|
|
59
|
+
const {
|
|
60
|
+
route
|
|
61
|
+
} = dialogProps
|
|
62
|
+
|
|
63
|
+
// 如果是路由组件地址
|
|
64
|
+
if (utils.isValidString(route)) {
|
|
65
|
+
o.url = utils.slash(route, 'start', false)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const {
|
|
69
|
+
// 是否多选
|
|
70
|
+
multiple,
|
|
71
|
+
query,
|
|
72
|
+
} = props
|
|
73
|
+
|
|
74
|
+
// 是否多选
|
|
75
|
+
o.selection = multiple ? 'multiple' : 'single'
|
|
76
|
+
|
|
77
|
+
// 合并参数
|
|
78
|
+
Object.assign(o.query, query)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 创建表格
|
|
83
|
+
*/
|
|
84
|
+
function create(params) {
|
|
85
|
+
|
|
86
|
+
// ==========【注入】=================================================================================================
|
|
87
|
+
|
|
88
|
+
// 获取对话框注入
|
|
89
|
+
const $dialog = utils.$dialog.inject()
|
|
90
|
+
const inDialog = !! $dialog
|
|
91
|
+
|
|
92
|
+
// ==========【数据】=================================================================================================
|
|
93
|
+
|
|
94
|
+
// quasar 对象
|
|
95
|
+
const $q = useQuasar()
|
|
96
|
+
|
|
97
|
+
// 每页显示行数选项
|
|
98
|
+
// const rowsPerPageOptions = [30, 40, 50, 100, 200, 500, 1000]
|
|
99
|
+
const rowsPerPageOptions = [4, 40, 50, 100, 200, 500, 1000]
|
|
100
|
+
|
|
101
|
+
// 获取参数
|
|
102
|
+
const o = _.merge({
|
|
103
|
+
// 请求地址
|
|
104
|
+
url: '',
|
|
105
|
+
// 参数
|
|
106
|
+
query: {},
|
|
107
|
+
// 表格节点
|
|
108
|
+
ref: null,
|
|
109
|
+
// 表格行唯一键值
|
|
110
|
+
rowKey: 'id',
|
|
111
|
+
// 选择类型, 可选值 single multiple none
|
|
112
|
+
selection: 'multiple',
|
|
113
|
+
// 表格加载状态
|
|
114
|
+
loading: false,
|
|
115
|
+
// 表格列数据(对象数组)
|
|
116
|
+
columns: [],
|
|
117
|
+
// 可见列
|
|
118
|
+
visibleColumns: [],
|
|
119
|
+
// 表格行数据
|
|
120
|
+
rows: [],
|
|
121
|
+
// 表格翻页参数
|
|
122
|
+
pagination: {
|
|
123
|
+
// 页码
|
|
124
|
+
page: 1,
|
|
125
|
+
// 每页的数据条数
|
|
126
|
+
rowsPerPage: rowsPerPageOptions[0],
|
|
127
|
+
// 数据总数(服务器返回)
|
|
128
|
+
rowsNumber: 1,
|
|
129
|
+
// 排序字段
|
|
130
|
+
sortBy: null,
|
|
131
|
+
// sortBy: 'id',
|
|
132
|
+
// 是否降序排列
|
|
133
|
+
descending: true,
|
|
134
|
+
},
|
|
135
|
+
// 已选数据
|
|
136
|
+
selected: [],
|
|
137
|
+
// 每页显示行数选项
|
|
138
|
+
rowsPerPageOptions,
|
|
139
|
+
// 请求方法
|
|
140
|
+
request: null,
|
|
141
|
+
// 格式化单条数据
|
|
142
|
+
formatRow: null,
|
|
143
|
+
// 格式化参数
|
|
144
|
+
// formatQuery: null,
|
|
145
|
+
// http 设置
|
|
146
|
+
httpSettings: {},
|
|
147
|
+
// 是否开启初始搜素
|
|
148
|
+
search: true,
|
|
149
|
+
// 是否开启合计
|
|
150
|
+
summary: false,
|
|
151
|
+
// 权限按钮列表
|
|
152
|
+
roleBtnLists: null,
|
|
153
|
+
// 从参数中获取搜索值
|
|
154
|
+
searchFromQuery: true,
|
|
155
|
+
// 显示宫格
|
|
156
|
+
showGrid: true,
|
|
157
|
+
// 显示可见列
|
|
158
|
+
showVisibleColumns: true,
|
|
159
|
+
}, params)
|
|
160
|
+
|
|
161
|
+
// 如果是对话框注入
|
|
162
|
+
if (inDialog) {
|
|
163
|
+
// 对话框设置
|
|
164
|
+
dialogSetting($dialog, o)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// 如果没有地址, 则使用当前路由地址
|
|
168
|
+
if (! o.url) {
|
|
169
|
+
// 当前路由
|
|
170
|
+
o.url = useRoute().fullPath
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// 是否显示权限按钮
|
|
174
|
+
const showRoleBtn = o.roleBtnLists !== null
|
|
175
|
+
|
|
176
|
+
// 宫格模式缓存名
|
|
177
|
+
const gridCacheName = 'table_grid_' + o.url
|
|
178
|
+
|
|
179
|
+
// 可见列缓存名
|
|
180
|
+
const visibleColumnsCacheName = 'table_visible_columns_' + o.url
|
|
181
|
+
|
|
182
|
+
// 表格列
|
|
183
|
+
const tableColumns = []
|
|
184
|
+
|
|
185
|
+
// 添加操作列
|
|
186
|
+
if (showRoleBtn) {
|
|
187
|
+
o.columns.push({
|
|
188
|
+
label: '操作',
|
|
189
|
+
name: 'settings',
|
|
190
|
+
})
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// 表格图片标识数组
|
|
194
|
+
const tableImgNames = ref([])
|
|
195
|
+
|
|
196
|
+
// 设置列参数
|
|
197
|
+
utils.forEach(o.columns, function(item) {
|
|
198
|
+
|
|
199
|
+
if (
|
|
200
|
+
! _.has(item, 'field')
|
|
201
|
+
&& _.has(item, 'name')
|
|
202
|
+
) {
|
|
203
|
+
item.field = item.name
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (! _.has(item, 'align')) {
|
|
207
|
+
item.align = 'left'
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// 如果有显示项
|
|
211
|
+
if (_.get(item, 'visible') !== false) {
|
|
212
|
+
o.visibleColumns.push(item.field)
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// 如果有时间戳
|
|
216
|
+
if (_.has(item, 'time')) {
|
|
217
|
+
item.format = val => date.formatDate(utils.toDate(val), item.time === true ? `YYYY-MM-DD HH:mm` : item.time)
|
|
218
|
+
|
|
219
|
+
// 如果有数据字典
|
|
220
|
+
} else if (_.has(item, 'dict')) {
|
|
221
|
+
item.format = val => utils.dict(item.dict, val)
|
|
222
|
+
|
|
223
|
+
// 如果有图片
|
|
224
|
+
} else if (_.has(item, 'img') && item.img === true) {
|
|
225
|
+
tableImgNames.value.push(item.name)
|
|
226
|
+
|
|
227
|
+
// 如果有价格
|
|
228
|
+
} else if (_.has(item, 'price')) {
|
|
229
|
+
item.format = val => utils.price(val)
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// 如果有路由
|
|
233
|
+
if (_.get(item, 'router')) {
|
|
234
|
+
// 如果该值在当前路由路径中, 则显示
|
|
235
|
+
if (utils.indexOf(o.url, item.router) > -1) {
|
|
236
|
+
tableColumns.push(item)
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
} else {
|
|
240
|
+
tableColumns.push(item)
|
|
241
|
+
}
|
|
242
|
+
})
|
|
243
|
+
|
|
244
|
+
// 获取可见列缓存
|
|
245
|
+
const visibleColumnsCache = o.showVisibleColumns ? utils.storage.get(visibleColumnsCacheName) : []
|
|
246
|
+
|
|
247
|
+
// 表格可见列
|
|
248
|
+
const tableVisibleColumns = ref(Array.isArray(visibleColumnsCache) ? visibleColumnsCache : _.uniq([...o.visibleColumns]))
|
|
249
|
+
|
|
250
|
+
// 表格工具栏节点
|
|
251
|
+
const tableToolbarRef = ref(null)
|
|
252
|
+
|
|
253
|
+
// 表格节点
|
|
254
|
+
const tableRef = ref(o.ref)
|
|
255
|
+
|
|
256
|
+
// 表格加载状态
|
|
257
|
+
const tableLoading = ref(o.loading)
|
|
258
|
+
|
|
259
|
+
// 表格行数据
|
|
260
|
+
const tableRows = ref(o.rows)
|
|
261
|
+
|
|
262
|
+
// 表格翻页参数
|
|
263
|
+
const tablePagination = ref(o.pagination)
|
|
264
|
+
|
|
265
|
+
// 表格已选数据
|
|
266
|
+
const tableSelected = ref(o.selected)
|
|
267
|
+
|
|
268
|
+
// 表格宫格
|
|
269
|
+
const tableGrid = ref(o.showGrid ? utils.storage.get(gridCacheName) === true : false)
|
|
270
|
+
|
|
271
|
+
// 表格传参
|
|
272
|
+
const tableQuery = ref({})
|
|
273
|
+
|
|
274
|
+
// 表格请求参数(将表格传参中的搜索参数剥离掉, 剩下的直接当做参数传递给服务器)
|
|
275
|
+
let tableRequestQuery = {}
|
|
276
|
+
|
|
277
|
+
// 是否请求表格合计
|
|
278
|
+
let isRequestSummary = false
|
|
279
|
+
|
|
280
|
+
// 表格合计
|
|
281
|
+
const tableSummary = ref(null)
|
|
282
|
+
|
|
283
|
+
// 获取 url 参数
|
|
284
|
+
const resUrl = getUrlQuery(o.url)
|
|
285
|
+
o.url = resUrl.url
|
|
286
|
+
|
|
287
|
+
// 如果在表格内部
|
|
288
|
+
if (inDialog) {
|
|
289
|
+
// 提交表格已选数据给对话框
|
|
290
|
+
$dialog.submit(function() {
|
|
291
|
+
return tableSelected.value
|
|
292
|
+
})
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
const {
|
|
296
|
+
// 原始参数
|
|
297
|
+
rawQuery,
|
|
298
|
+
// 原始表格搜索参数
|
|
299
|
+
rawSearchOptions,
|
|
300
|
+
// 原始表格搜索值(空表格搜索值, 用于搜索重置)
|
|
301
|
+
rawTableSearchValue,
|
|
302
|
+
// 首次表格搜索值(如果表格搜索参数中带了初始值, 则设置初始值)
|
|
303
|
+
firstTableSearchValue,
|
|
304
|
+
// 表格搜索值(如果表格搜索参数中带了初始值, 则设置初始值)
|
|
305
|
+
} = utils.$search.getRawData(tableColumns, Object.assign({}, o.query, resUrl.query), o.searchFromQuery)
|
|
306
|
+
|
|
307
|
+
// 表格搜索数据值
|
|
308
|
+
const tableSearchValue = ref(firstTableSearchValue)
|
|
309
|
+
|
|
310
|
+
// 表格搜索参数
|
|
311
|
+
const tableSearchOptions = ref()
|
|
312
|
+
|
|
313
|
+
// ==========【计算属性】=============================================================================================
|
|
314
|
+
|
|
315
|
+
// 固定在右边的权限按钮列表
|
|
316
|
+
const tableFixedRoleBtnLists = showRoleBtn ? computed(function () {
|
|
317
|
+
|
|
318
|
+
const lists = []
|
|
319
|
+
|
|
320
|
+
// 先格式化权限按钮列表
|
|
321
|
+
utils.forEach(utils.$role.formatRoleBtnLists(o.roleBtnLists.value), function(item) {
|
|
322
|
+
// 如果是固定按钮
|
|
323
|
+
if (item.fixed) {
|
|
324
|
+
lists.push(item)
|
|
325
|
+
}
|
|
326
|
+
})
|
|
327
|
+
|
|
328
|
+
return lists
|
|
329
|
+
}) : []
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* 表格双击权限按钮
|
|
333
|
+
*/
|
|
334
|
+
const tableDbClickRoleBtn = o.roleBtnLists ? computed(function () {
|
|
335
|
+
if (
|
|
336
|
+
// 非手机模式
|
|
337
|
+
! $q.platform.is.mobile
|
|
338
|
+
// 有权限列表
|
|
339
|
+
&& utils.isValidArray(o.roleBtnLists.value)
|
|
340
|
+
) {
|
|
341
|
+
for (const item of o.roleBtnLists.value) {
|
|
342
|
+
if (_.has(item, 'data.dbclick') === true) {
|
|
343
|
+
return item
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}) : null
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* 是否显示固定在右边的权限按钮列表
|
|
351
|
+
*/
|
|
352
|
+
const showTableFixed = computed(function () {
|
|
353
|
+
return utils.indexOf(tableVisibleColumns.value, 'settings') > -1
|
|
354
|
+
})
|
|
355
|
+
|
|
356
|
+
// ==========【监听数据】=============================================================================================
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* 监听表格宫格模式
|
|
360
|
+
*/
|
|
361
|
+
if (o.showGrid) {
|
|
362
|
+
watch(tableGrid, function(val) {
|
|
363
|
+
|
|
364
|
+
// 设置宫格模式缓存(永久缓存)
|
|
365
|
+
// #if ! IS_DEV
|
|
366
|
+
utils.storage.set(gridCacheName, val, 0)
|
|
367
|
+
// #endif
|
|
368
|
+
})
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* 监听表格可见列
|
|
373
|
+
*/
|
|
374
|
+
if (o.showVisibleColumns) {
|
|
375
|
+
watch(tableVisibleColumns, function(val) {
|
|
376
|
+
|
|
377
|
+
// 设置可见列缓存(永久缓存)
|
|
378
|
+
// #if ! IS_DEV
|
|
379
|
+
utils.storage.set(visibleColumnsCacheName, val, 0)
|
|
380
|
+
// #endif
|
|
381
|
+
})
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* 监听固定在右边的权限按钮列表
|
|
386
|
+
*/
|
|
387
|
+
if (showRoleBtn) {
|
|
388
|
+
watch(tableFixedRoleBtnLists, function (lists) {
|
|
389
|
+
|
|
390
|
+
const index = utils.indexOf(tableVisibleColumns.value, 'settings')
|
|
391
|
+
|
|
392
|
+
// 如果有固定在右边的权限按钮列表
|
|
393
|
+
if (utils.isValidArray(lists)) {
|
|
394
|
+
|
|
395
|
+
// 如果设置不在可见列中
|
|
396
|
+
if (index === -1) {
|
|
397
|
+
|
|
398
|
+
// 如果非手机模式
|
|
399
|
+
if (! $q.platform.is.mobile) {
|
|
400
|
+
|
|
401
|
+
// 则将设置加入可见列中
|
|
402
|
+
tableVisibleColumns.value.push('settings')
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// 否则在可见列中 && 如果是手机模式
|
|
406
|
+
} else if ($q.platform.is.mobile) {
|
|
407
|
+
|
|
408
|
+
// 则将设置从可见列中删除
|
|
409
|
+
tableVisibleColumns.value.splice(index, 1)
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// 否则如果设置在可见列中
|
|
413
|
+
} else if (index > -1) {
|
|
414
|
+
|
|
415
|
+
// 则将设置从可见列中删除
|
|
416
|
+
tableVisibleColumns.value.splice(index, 1)
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
}, {
|
|
420
|
+
// 立即执行
|
|
421
|
+
immediate: true,
|
|
422
|
+
})
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* 监听表格传参
|
|
427
|
+
*/
|
|
428
|
+
watch(tableQuery, function (query) {
|
|
429
|
+
|
|
430
|
+
// 如果禁止从参数中获取搜索值
|
|
431
|
+
if (! o.searchFromQuery) {
|
|
432
|
+
tableRequestQuery = query
|
|
433
|
+
return
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
const newQuery = {}
|
|
437
|
+
|
|
438
|
+
if (utils.isValidObject(query)) {
|
|
439
|
+
|
|
440
|
+
// 搜索参数键值数组
|
|
441
|
+
const searchQueryKey = []
|
|
442
|
+
|
|
443
|
+
utils.forEach(rawSearchOptions, function (item, index) {
|
|
444
|
+
// 如果传参在搜索参数中
|
|
445
|
+
if (_.has(query, item.name)) {
|
|
446
|
+
// 设置单个搜索值
|
|
447
|
+
setItemValue(tableSearchValue.value[index], utils.isRequired(query[item.name]) ? query[item.name] : '')
|
|
448
|
+
// 设置参数中搜索的 key
|
|
449
|
+
searchQueryKey.push(item.name)
|
|
450
|
+
}
|
|
451
|
+
})
|
|
452
|
+
|
|
453
|
+
if (! searchQueryKey.length) {
|
|
454
|
+
tableRequestQuery = query
|
|
455
|
+
return
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
utils.forIn(query, function(val, key) {
|
|
459
|
+
if (searchQueryKey.indexOf(key) === -1) {
|
|
460
|
+
newQuery[key] = val
|
|
461
|
+
}
|
|
462
|
+
})
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
tableRequestQuery = newQuery
|
|
466
|
+
})
|
|
467
|
+
|
|
468
|
+
// ==========【方法】================================================================================================
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* 表格刷新
|
|
472
|
+
*/
|
|
473
|
+
function tableRefresh() {
|
|
474
|
+
// 请求表格合计
|
|
475
|
+
if (o.summary) {
|
|
476
|
+
isRequestSummary = true
|
|
477
|
+
}
|
|
478
|
+
// 请求表格数据
|
|
479
|
+
tableRef.value.requestServerInteraction()
|
|
480
|
+
// 清空表格已选数据
|
|
481
|
+
tableSelected.value = []
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* 表格重新加载
|
|
486
|
+
*/
|
|
487
|
+
function tableReload() {
|
|
488
|
+
// 请求表格合计
|
|
489
|
+
if (o.summary) {
|
|
490
|
+
isRequestSummary = true
|
|
491
|
+
}
|
|
492
|
+
// 请求表格数据
|
|
493
|
+
tableRef.value.requestServerInteraction({
|
|
494
|
+
pagination: o.pagination,
|
|
495
|
+
})
|
|
496
|
+
// 清空表格已选数据
|
|
497
|
+
tableSelected.value = []
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/**
|
|
501
|
+
* 表格搜索重置
|
|
502
|
+
*/
|
|
503
|
+
function tableSearchReset() {
|
|
504
|
+
|
|
505
|
+
// 还原表格搜索数据
|
|
506
|
+
tableSearchValue.value = _.cloneDeep(rawTableSearchValue)
|
|
507
|
+
|
|
508
|
+
// 表格重新加载
|
|
509
|
+
tableReload()
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* 请求数据
|
|
514
|
+
*/
|
|
515
|
+
async function tableRequest(props) {
|
|
516
|
+
|
|
517
|
+
// 解构数据
|
|
518
|
+
const {
|
|
519
|
+
// filter,
|
|
520
|
+
pagination: {
|
|
521
|
+
page,
|
|
522
|
+
rowsPerPage,
|
|
523
|
+
sortBy,
|
|
524
|
+
descending,
|
|
525
|
+
}
|
|
526
|
+
} = props
|
|
527
|
+
|
|
528
|
+
// 设置加载中
|
|
529
|
+
tableLoading.value = true
|
|
530
|
+
|
|
531
|
+
// 请求数据
|
|
532
|
+
const data = {
|
|
533
|
+
// 页码
|
|
534
|
+
page,
|
|
535
|
+
// 每页的数据条数
|
|
536
|
+
per_page: rowsPerPage,
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
// 如果排序字段是有效值
|
|
540
|
+
if (utils.isValidValue(sortBy)) {
|
|
541
|
+
Object.assign(data, {
|
|
542
|
+
// 排序字段
|
|
543
|
+
order_by: sortBy,
|
|
544
|
+
// 是否降序排列
|
|
545
|
+
is_desc: descending ? 1 : 0,
|
|
546
|
+
})
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
// 合并参数
|
|
550
|
+
utils.forIn(Object.assign({}, rawQuery, tableRequestQuery), function(value, key) {
|
|
551
|
+
// 如果有值
|
|
552
|
+
if (utils.isRequired(value)) {
|
|
553
|
+
data[key] = value
|
|
554
|
+
}
|
|
555
|
+
})
|
|
556
|
+
|
|
557
|
+
// 获取搜索值
|
|
558
|
+
const search = utils.$search.formatValue(rawSearchOptions, tableSearchValue.value)
|
|
559
|
+
if (utils.isValidArray(search)) {
|
|
560
|
+
data.search = _.has(data, 'search') ? _.concat(data.search, search) : search
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
// 如果请求表格合计
|
|
564
|
+
if (isRequestSummary) {
|
|
565
|
+
data.summary = 1
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
// 请求数据
|
|
569
|
+
let result
|
|
570
|
+
|
|
571
|
+
// 如果有自定义请求方法
|
|
572
|
+
if (_.isFunction(o.request)) {
|
|
573
|
+
result = await utils.runAsync(o.request)({
|
|
574
|
+
data,
|
|
575
|
+
props,
|
|
576
|
+
tableRef,
|
|
577
|
+
rows: tableRows,
|
|
578
|
+
selected: tableSelected,
|
|
579
|
+
})
|
|
580
|
+
|
|
581
|
+
// 否则请求服务器
|
|
582
|
+
} else {
|
|
583
|
+
const opts = Object.assign({
|
|
584
|
+
// 请求 - 登录
|
|
585
|
+
url: o.url,
|
|
586
|
+
// 请求数据
|
|
587
|
+
data,
|
|
588
|
+
// ~~~~~~ 先开启防抖, 如果后期遇到表格加载不出来的情况, 再关闭防抖
|
|
589
|
+
// 关闭防抖(允许重复请求)
|
|
590
|
+
// debounce: false,
|
|
591
|
+
}, o.httpSettings)
|
|
592
|
+
|
|
593
|
+
// 如果在对话框内部
|
|
594
|
+
if (inDialog) {
|
|
595
|
+
opts.headers = {
|
|
596
|
+
// 添加头部查看请求
|
|
597
|
+
Rview: 1,
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
result = await utils.http(opts)
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
const { status, data: res } = result
|
|
605
|
+
|
|
606
|
+
// 请求成功
|
|
607
|
+
if (status) {
|
|
608
|
+
|
|
609
|
+
const {
|
|
610
|
+
// 返回数据
|
|
611
|
+
rows,
|
|
612
|
+
// 数据总数
|
|
613
|
+
total,
|
|
614
|
+
} = res
|
|
615
|
+
|
|
616
|
+
// 如果请求表格合计
|
|
617
|
+
if (isRequestSummary) {
|
|
618
|
+
const summary = _.get(res, 'summary')
|
|
619
|
+
tableSummary.value = utils.isValidObject(summary) ? summary : null
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
// 更新页码
|
|
623
|
+
tablePagination.value.page = page
|
|
624
|
+
// 更新每页的数据条数
|
|
625
|
+
tablePagination.value.rowsPerPage = rowsPerPage
|
|
626
|
+
// 更新数据总数
|
|
627
|
+
tablePagination.value.rowsNumber = total
|
|
628
|
+
// 更新排序字段
|
|
629
|
+
tablePagination.value.sortBy = sortBy
|
|
630
|
+
// 更新是否降序排列
|
|
631
|
+
tablePagination.value.descending = descending
|
|
632
|
+
|
|
633
|
+
// 格式化单条数据
|
|
634
|
+
if (_.isFunction(o.formatRow)) {
|
|
635
|
+
utils.forEach(rows, function(row) {
|
|
636
|
+
o.formatRow({
|
|
637
|
+
row,
|
|
638
|
+
tableRef,
|
|
639
|
+
rows: tableRows,
|
|
640
|
+
selected: tableSelected,
|
|
641
|
+
})
|
|
642
|
+
})
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
// 清除现有数据并添加新数据
|
|
646
|
+
tableRows.value.splice(0, tableRows.value.length, ...rows)
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
// 取消请求表格合计
|
|
650
|
+
isRequestSummary = false
|
|
651
|
+
|
|
652
|
+
// 取消加载
|
|
653
|
+
tableLoading.value = false
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
/**
|
|
657
|
+
* 单击表格行
|
|
658
|
+
*/
|
|
659
|
+
function tableRowClick(e, row, index) {
|
|
660
|
+
// 如果选择类型为无
|
|
661
|
+
if (o.selection === 'none') {
|
|
662
|
+
// 则无任何操作
|
|
663
|
+
return
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
const opt = {}
|
|
667
|
+
opt[o.rowKey] = row[o.rowKey]
|
|
668
|
+
|
|
669
|
+
// 获取当前数据索引
|
|
670
|
+
const itemIndex = _.findIndex(tableSelected.value, opt)
|
|
671
|
+
|
|
672
|
+
// 如果不存在, 则添加
|
|
673
|
+
if (itemIndex === -1) {
|
|
674
|
+
|
|
675
|
+
// 如果选择类型为单选
|
|
676
|
+
if (o.selection === 'single') {
|
|
677
|
+
tableSelected.value = [row]
|
|
678
|
+
// 否则为多选
|
|
679
|
+
} else {
|
|
680
|
+
tableSelected.value.push(row)
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
// 否则删除
|
|
684
|
+
} else {
|
|
685
|
+
tableSelected.value.splice(itemIndex, 1)
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
/**
|
|
690
|
+
* 双击表格行
|
|
691
|
+
*/
|
|
692
|
+
function tableRowDblclick(e, row) {
|
|
693
|
+
|
|
694
|
+
// 如果选择类型为无
|
|
695
|
+
if (o.selection === 'none') {
|
|
696
|
+
// 则无任何操作
|
|
697
|
+
return
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
// 如果在对话框内部 && 如果是单选
|
|
701
|
+
if (inDialog && o.selection === 'single') {
|
|
702
|
+
tableSelected.value = [ row ]
|
|
703
|
+
$dialog.confirm()
|
|
704
|
+
return
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
// 有双击的权限按钮
|
|
708
|
+
if (tableDbClickRoleBtn && tableDbClickRoleBtn.value) {
|
|
709
|
+
tableToolbarRef.value?.onClick(tableDbClickRoleBtn.value, [ row ])
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
/**
|
|
714
|
+
* 设置表格搜索参数
|
|
715
|
+
*/
|
|
716
|
+
async function setTableSearchOptions(format) {
|
|
717
|
+
tableSearchOptions.value = await utils.$search.getOptions(rawSearchOptions, format)
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
// 如果开启搜索
|
|
721
|
+
if (o.search) {
|
|
722
|
+
// 设置表格搜索参数
|
|
723
|
+
setTableSearchOptions()
|
|
724
|
+
.finally()
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
// ==========【返回】=================================================================================================
|
|
728
|
+
|
|
729
|
+
return {
|
|
730
|
+
// 表格工具栏节点
|
|
731
|
+
tableToolbarRef,
|
|
732
|
+
// 表格节点
|
|
733
|
+
tableRef,
|
|
734
|
+
// 表格加载状态
|
|
735
|
+
tableLoading,
|
|
736
|
+
// 表格 id key
|
|
737
|
+
tableRowKey: o.rowKey,
|
|
738
|
+
// 表格选择类型
|
|
739
|
+
tableSelection: o.selection,
|
|
740
|
+
// 表格每页显示行数选项
|
|
741
|
+
tableRowsPerPageOptions: rowsPerPageOptions,
|
|
742
|
+
// 表格列数据(对象数组)
|
|
743
|
+
tableColumns,
|
|
744
|
+
// 表格可见列
|
|
745
|
+
tableVisibleColumns,
|
|
746
|
+
// 表格行数据
|
|
747
|
+
tableRows,
|
|
748
|
+
// 表格翻页参数
|
|
749
|
+
tablePagination,
|
|
750
|
+
// 表格已选数据
|
|
751
|
+
tableSelected,
|
|
752
|
+
// 固定在右边的权限按钮列表
|
|
753
|
+
tableFixedRoleBtnLists,
|
|
754
|
+
// 是否显示固定在右边的权限按钮列表
|
|
755
|
+
showTableFixed,
|
|
756
|
+
// 表格图片标识
|
|
757
|
+
tableImgNames,
|
|
758
|
+
|
|
759
|
+
// 表格宫格
|
|
760
|
+
tableGrid,
|
|
761
|
+
// 表格传参
|
|
762
|
+
tableQuery,
|
|
763
|
+
// 表格合计
|
|
764
|
+
tableSummary,
|
|
765
|
+
// 表格搜索数据
|
|
766
|
+
tableSearchValue,
|
|
767
|
+
// 表格搜索参数
|
|
768
|
+
tableSearchOptions,
|
|
769
|
+
|
|
770
|
+
// 表格刷新
|
|
771
|
+
tableRefresh,
|
|
772
|
+
// 表格重新加载
|
|
773
|
+
tableReload,
|
|
774
|
+
// 表格请求数据
|
|
775
|
+
tableRequest,
|
|
776
|
+
// 表格单击表格行
|
|
777
|
+
tableRowClick,
|
|
778
|
+
// 表格双击表格行
|
|
779
|
+
tableRowDblclick,
|
|
780
|
+
// 表格搜索重置
|
|
781
|
+
tableSearchReset,
|
|
782
|
+
// 设置表格搜索参数
|
|
783
|
+
setTableSearchOptions,
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
/**
|
|
788
|
+
* 获取配置
|
|
789
|
+
*/
|
|
790
|
+
function config(routePath, path, defaultValue) {
|
|
791
|
+
return _.get(tablesConfig, utils.slash(routePath, 'start', false) + (path ? '.' + path : ''), defaultValue)
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
/**
|
|
795
|
+
* 业务表格
|
|
796
|
+
*/
|
|
797
|
+
utils.$table = {
|
|
798
|
+
// 创建表格
|
|
799
|
+
create,
|
|
800
|
+
// 获取配置
|
|
801
|
+
config,
|
|
802
|
+
}
|