@utogether/udp-core 1.0.1-beta.22 → 1.0.1-beta.23

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.
Files changed (67) hide show
  1. package/dist/{403-B87JSuhn.js → 403-CVk0Zv7-.js} +1 -1
  2. package/dist/{404-BhiUKT1b.js → 404-ndDOUJxF.js} +1 -1
  3. package/dist/{500-2G6eyDeT.js → 500-CBFigQjv.js} +1 -1
  4. package/dist/{AuthorityInfo-Bl4_zDot.js → AuthorityInfo-BDf4I8In.js} +1 -1
  5. package/dist/{AuthorityInfo.vue_vue_type_style_index_0_lang-92i5Oriz.js → AuthorityInfo.vue_vue_type_style_index_0_lang-cEIXuHBK.js} +1 -1
  6. package/dist/{Company-CbTh7_bX.js → Company-DYDDIDa5.js} +3 -3
  7. package/dist/{CompanyPanel-BVEYMQKM.js → CompanyPanel-DggYD4kC.js} +1 -1
  8. package/dist/{Department-Cu83Buy8.js → Department-DqrAvwmT.js} +3 -3
  9. package/dist/{DepartmentPanel-CO76buwO.js → DepartmentPanel-BjhhDlhw.js} +1 -1
  10. package/dist/{DesignPanel-DDgVNzYW.js → DesignPanel-DAR2pcpF.js} +1 -1
  11. package/dist/{DesignPanel.vue_vue_type_style_index_0_lang-Bwernx0s.js → DesignPanel.vue_vue_type_style_index_0_lang-B8GPGq0h.js} +2 -2
  12. package/dist/{DictView-DJDg_Oem.js → DictView-BcLgE6q2.js} +1 -1
  13. package/dist/{InvOrganization-D9BMWweK.js → InvOrganization-B61NWug9.js} +1 -1
  14. package/dist/{Org-CcfRkpBY.js → Org-9tL7q4mS.js} +1 -1
  15. package/dist/{Preview-DGP1uIZU.js → Preview-Bn4QDJ6s.js} +1 -1
  16. package/dist/{ReportDefine-u7r-IVPD.js → ReportDefine-BMGU8p3z.js} +1 -1
  17. package/dist/{ReportDesign-CLQRMIy3.js → ReportDesign-DkwxPGCT.js} +2 -2
  18. package/dist/{ReportQuery-BNTCTpqI.js → ReportQuery-DOFFL8Nn.js} +1 -1
  19. package/dist/{ReportQueryFrom-G7X1Fyf5.js → ReportQueryFrom-BDDlluNb.js} +1 -1
  20. package/dist/{ReportQueryFrom.vue_vue_type_style_index_0_lang-D5lDZFPM.js → ReportQueryFrom.vue_vue_type_style_index_0_lang-Yqw26YrX.js} +1 -1
  21. package/dist/{ReportTemplate-QWAuFjaB.js → ReportTemplate-DmFqn7ji.js} +1 -1
  22. package/dist/{Role-Ba1OVGG0.js → Role-DGw_eao_.js} +3 -3
  23. package/dist/{RoleAssign-DFiMYll8.js → RoleAssign-BJ32jpGq.js} +3 -3
  24. package/dist/{RolePanel-c-xitljX.js → RolePanel-B2O0mFtr.js} +1 -1
  25. package/dist/{RolePanel-D6xKrLlM.js → RolePanel-DHS9C-hf.js} +1 -1
  26. package/dist/{RolePanel.vue_vue_type_script_setup_true_lang-BeZ1xNXU.js → RolePanel.vue_vue_type_script_setup_true_lang-CEYM_zn7.js} +1 -1
  27. package/dist/{RolePanel.vue_vue_type_script_setup_true_lang-DrBiLlBb.js → RolePanel.vue_vue_type_script_setup_true_lang-T5FN19eF.js} +3 -3
  28. package/dist/{ScrollPanel.vue_vue_type_style_index_0_lang-D4eReGaK.js → ScrollPanel.vue_vue_type_style_index_0_lang-CeYU2NrW.js} +1 -1
  29. package/dist/{Staff-C-5TE1Yn.js → Staff-3Rejxejf.js} +3 -3
  30. package/dist/{StaffInfo-CwJlL_Nr.js → StaffInfo-C94C3Gj7.js} +1 -1
  31. package/dist/{StaffInfo.vue_vue_type_script_setup_true_lang-C2BsoQlr.js → StaffInfo.vue_vue_type_script_setup_true_lang-Bm76KXps.js} +1 -1
  32. package/dist/{StaffPanel-QOv1pq2Z.js → StaffPanel-ClhiNL5a.js} +1 -1
  33. package/dist/{StaffPanel.vue_vue_type_script_setup_true_lang-BGQSHjaQ.js → StaffPanel.vue_vue_type_script_setup_true_lang-DjUOMmMr.js} +2 -2
  34. package/dist/{SysUser-Byug_VNY.js → SysUser-DUXK1KbY.js} +2 -2
  35. package/dist/{SysUserPanel-B-M2Yxjj.js → SysUserPanel-3HThXZFZ.js} +1 -1
  36. package/dist/SysUserPanel.vue_vue_type_script_setup_true_lang-DjbpSAOd.js +340 -0
  37. package/dist/{SystemMenu-Bs9a4BE0.js → SystemMenu-C1CrBLIy.js} +2 -2
  38. package/dist/{UserInfo-Ipp00UAF.js → UserInfo-C1tgO95t.js} +1 -1
  39. package/dist/{UserInfo.vue_vue_type_style_index_0_lang-DIcWs6vj.js → UserInfo.vue_vue_type_style_index_0_lang-CNLWkLRN.js} +1 -1
  40. package/dist/{childView-N1PkzqQK.js → childView-CCr-NwqZ.js} +1 -1
  41. package/dist/{childView-O-5baerB.js → childView-CeYGykew.js} +1 -1
  42. package/dist/{childView.vue_vue_type_style_index_0_lang--yGHgWVq.js → childView.vue_vue_type_style_index_0_lang-D9PsELsS.js} +1 -1
  43. package/dist/{childView.vue_vue_type_style_index_0_lang-srudWvXc.js → childView.vue_vue_type_style_index_0_lang-IhbVX2Xa.js} +1 -1
  44. package/dist/{code-rule-CRunTGXH.js → code-rule-BVjue1Qj.js} +1 -1
  45. package/dist/core.es.js +1 -1
  46. package/dist/{cron-task-IEuaI4Nt.js → cron-task-BfVSQIgT.js} +1 -1
  47. package/dist/{frameView-vGVXV1ZG.js → frameView-D_YJavxB.js} +1 -1
  48. package/dist/index-ZaDSQxcf.js +6495 -0
  49. package/dist/{layoutView-BJO8Hm5d.js → layoutView-DpxwrEJd.js} +1 -1
  50. package/dist/{login-CZyenjQX.js → login-8muEJPMg.js} +1 -1
  51. package/dist/{lov-view-6He1ZxGX.js → lov-view-DEp2h_qy.js} +2 -2
  52. package/dist/{menuInfo-CE5Cae2u.js → menuInfo-rPb4Ed8Q.js} +1 -1
  53. package/dist/{menuInfo.vue_vue_type_style_index_0_lang-BjshFg3S.js → menuInfo.vue_vue_type_style_index_0_lang-mtPuZDRn.js} +1 -1
  54. package/dist/{pda-app-DOiT57m1.js → pda-app-CSrTwUo7.js} +1 -1
  55. package/dist/{resource-BdlOJOcz.js → resource-B4Fsud2G.js} +1 -1
  56. package/dist/{su-welcome-BxRhJD8X.js → su-welcome-DkwJ8pW8.js} +1 -1
  57. package/dist/{sys-config-Csy-234G.js → sys-config-CnMkBejC.js} +1 -1
  58. package/dist/udp-core.css +1 -1
  59. package/package.json +1 -1
  60. package/src/components/udp/grid/index.vue +514 -513
  61. package/src/plugins/i18n/zh.ts +3 -2
  62. package/src/utils/udp/http/index.ts +294 -0
  63. package/src/utils/udp/http/types.d.ts +42 -0
  64. package/src/views/system/cron/cron-task.vue +2 -12
  65. package/src/views/system/sysUser/SysUserPanel.vue +346 -279
  66. package/dist/SysUserPanel.vue_vue_type_script_setup_true_lang-Dm1YyUXX.js +0 -298
  67. package/dist/index-D_tU_u2l.js +0 -4640
@@ -1,513 +1,514 @@
1
- <!--
2
- * @Author: wei.li
3
- * @Date: 2021-11-17 16:33:37
4
- * @LastEditors: levi7754 levi7754@163.com
5
- * @LastEditTime: 2025-11-06 18:56:12
6
- * @Description: file content
7
- -->
8
- <template>
9
- <div style="width: 100%; height: 100%">
10
- <vxe-grid
11
- ref="xgrid"
12
- v-bind="data"
13
- class="ut-grid-wrapper"
14
- v-on="attrs.events || {}"
15
- @toolbarButtonClick="toolbarButtonClick"
16
- @toolbarToolClick="toolbarButtonClick"
17
- @cell-click="cellClick"
18
- @cell-dblclick="cellDbclick"
19
- @edit-activated="editEctivated"
20
- @form-reset="onReset"
21
- />
22
- <!-- <SearchScheme
23
- v-if="showModal && props.url"
24
- :items="items"
25
- :view="viewCode"
26
- @search="onSearch"
27
- @close="showModal = false"
28
- /> -->
29
- </div>
30
- </template>
31
-
32
- <script lang="ts" setup>
33
- // @ts-nocheck
34
- import { useI18n } from 'vue-i18n';
35
- import { ref, onBeforeMount, reactive, getCurrentInstance, toRaw, useAttrs, onUnmounted, nextTick } from 'vue';
36
- import { VxeGridProps } from 'vxe-table';
37
- import Sortable from 'sortablejs';
38
- import { clone } from 'xe-utils';
39
- import { formatGridItems, i18nColums, formatRules, errorMessage, dbstorage, warnMessage } from '@utogether/utils';
40
- import {
41
- queryAll,
42
- query,
43
- del,
44
- save,
45
- footerSumMethod,
46
- getToolBarConfig,
47
- defaultColums,
48
- onCheckMethod,
49
- getAttrs
50
- } from '../utils';
51
- // import SearchScheme from '../components/SuSearch.vue';
52
-
53
- defineOptions({
54
- name: 'UtGrid'
55
- });
56
-
57
- export interface IProps {
58
- checkMethod?: Function;
59
- serviceCode?: IRecord;
60
- defaultValue?: IRecord;
61
- defaultParams?: IRecord;
62
- url?: string;
63
- columns: Array<ITableColProps>;
64
- items?: Array<IFormItemProps>;
65
- editable?: boolean;
66
- needExport?: boolean; // 是否需要导出
67
- autoLoad?: boolean; // 自动加载查询数据
68
- }
69
-
70
- const attrs: IRecord = getAttrs(useAttrs());
71
-
72
- const kSTORECOLUM = 'U_TABLE_COLUMNN_SORT';
73
- let storeColums;
74
- const cacheColumns = {};
75
-
76
- // console.log(attrs);
77
- const instance = getCurrentInstance()!;
78
- const hasAuthority = instance.appContext.config.globalProperties.$hasAuthority;
79
- const serviceApi = instance.appContext.config.globalProperties.$serviceApi;
80
- const viewCode = instance.parent.type.name;
81
- const $mode = instance.appContext.config.globalProperties.$mode;
82
-
83
- const props = withDefaults(defineProps<IProps>(), {
84
- /**
85
- * @deprecated 2.10.0版本失效,
86
- * */
87
- serviceCode: (): IRecord => {
88
- return {};
89
- },
90
- items: () => [],
91
- columns: () => [],
92
- editable: true,
93
- autoLoad: true,
94
- needExport: true
95
- });
96
-
97
- const { t } = useI18n();
98
-
99
- const xgrid = ref(null);
100
- const showModal = ref(false);
101
-
102
- const favorite = {
103
- icon: 'vxe-icon-setting',
104
- name: 'favorite',
105
- events: {
106
- click: (e, option) => {
107
- if (option.name === 'favorite') {
108
- showModal.value = true;
109
- }
110
- }
111
- }
112
- };
113
-
114
- /**
115
- * @description: 根据items 获取必填选
116
- */
117
- const getRules = () => {
118
- if (!props.columns.length) return {};
119
- return formatRules(props.columns, t);
120
- };
121
- /**
122
- * @description: colum 统一添加国家化
123
- */
124
- const getColumns = () => {
125
- const columns = props.columns;
126
- if (attrs.gridId) {
127
- const cols = defaultColums
128
- .filter(f => !columns.some(s => s.field === f.field))
129
- .map(col => {
130
- if (attrs.format && ['lastUpdateDate', 'creationDate'].includes(col.field)) {
131
- col.formatter = attrs.format;
132
- col.width = 90;
133
- }
134
- return col;
135
- });
136
- const idx = columns.findIndex(s => s.field === 'operate');
137
- if (idx !== -1) {
138
- columns.splice(idx, 0, ...cols);
139
- } else {
140
- columns.push(...cols);
141
- }
142
- }
143
- const act_columns = attrs.gridId ? formatColums(columns) : columns;
144
-
145
- return i18nColums(act_columns, attrs.sortable);
146
- };
147
-
148
- dbstorage.getItem(kSTORECOLUM).then(value => {
149
- storeColums = value;
150
- data.columns = getColumns();
151
- });
152
-
153
- const data = reactive<VxeGridProps>({
154
- border: true,
155
- pagerConfig: { pageSize: attrs.pageSize || 20 },
156
- editConfig: {},
157
- editRules: getRules(),
158
- formConfig: {},
159
- columnConfig: { useKey: true },
160
- toolbarConfig: { enabled: false },
161
- sortConfig: { multiple: true, trigger: 'cell' },
162
- height: $mode ? undefined : window.innerHeight - 92,
163
-
164
- checkboxConfig: {
165
- checkMethod: ({ row }) => onCheckMethod(row, props),
166
- checkRowKeys: props.checkRowKeys
167
- },
168
- loading: false,
169
- footerRowClassName: 'ut-grid-footer',
170
- proxyConfig: {
171
- form: true, // 查询是需要启用表单代理
172
- autoLoad: props.autoLoad,
173
- showResponseMsgvxe: false,
174
- showActionMsgvxe: false,
175
- // 接收 Promise
176
- ajax: {
177
- queryAll: ({ form }) => queryAll(props, serviceApi, form),
178
- query: ({ page, form, code }) => query(props, form, page, serviceApi, code, $mode),
179
- delete: ({ body: { removeRecords } }) => del(serviceApi, removeRecords, props),
180
- save: ({ body }) => Promise.all(save(serviceApi, body, props)),
181
- querySuccess: ({ response }) => callback('querySuccess', response),
182
- queryError: ({ response }) => callback('queryError', response),
183
- deleteSuccess: ({ response }) => callback('deleteSuccess', response),
184
- deleteError: ({ response }) => callback('deleteError', response),
185
- saveSuccess: ({ response }) => callback('saveSuccess', response),
186
- saveError: ({ response }) => callback('saveError', response)
187
- }
188
- },
189
- columns: !attrs.gridId ? getColumns() : [],
190
- ...attrs
191
- });
192
-
193
- /**
194
- * @description: 预处理查询form
195
- * @return {*} items
196
- */
197
- const getItems = () => {
198
- if (!props.items.length) return props.items;
199
- return formatGridItems(clone(props.items, true), viewCode && props.url ? favorite : viewCode);
200
- };
201
-
202
- /**
203
- * @description 格式化column
204
- * @return {*} columns
205
- */
206
- function formatColums(columns) {
207
- const customSort = storeColums ? storeColums[attrs.gridId] : {};
208
- if (!customSort) return columns;
209
- return columns
210
- .map((col, idx) => {
211
- const sort = (idx + 1) * 10;
212
- col._sort = customSort[col.field] || sort;
213
- // 缓存列索引数据
214
- cacheColumns[col.field] = col._sort;
215
- return col;
216
- })
217
- .sort((a, b) => a._sort - b._sort);
218
- }
219
-
220
- /**
221
- * @description: 设置grid参数
222
- */
223
- const setGridConfig = () => {
224
- // 查询
225
- if (props.items.length) {
226
- // data.formConfig = {};
227
- data.formConfig = {
228
- titleWidth: 100,
229
- titleAlign: 'right',
230
- items: getItems(),
231
- rules: formatRules(props.items, t),
232
- validConfig: { showMessage: false }
233
- };
234
- }
235
- // tool bar
236
- const obj = getToolBarConfig(data, props, attrs, hasAuthority);
237
- Object.assign(data, obj);
238
- // 表格id,用于自定义列
239
- if (attrs.gridId) {
240
- data.id = attrs.gridId;
241
- data.customConfig = {
242
- storage: true,
243
- mode: 'popup',
244
- checkMethod({ column }) {
245
- return column.field === 'operate' || ['checkbox', 'radio'].includes(column.type) ? false : true;
246
- },
247
- modalOptions: {
248
- width: 750,
249
- height: '75%'
250
- }
251
- };
252
- }
253
- if (attrs.mergeFooter) {
254
- // 合计方法
255
- data.showFooter = true;
256
- data.footerMethod = ({ columns, data }) => footerSumMethod({ columns, data }, attrs.mergeFooter);
257
- }
258
- };
259
- /**
260
- * @description 手动调用查询方法
261
- */
262
- const refreshData = () => {
263
- xgrid.value.commitProxy('query');
264
- };
265
- /**
266
- * @description 刷新列数据
267
- */
268
- const refreshColumn = () => {
269
- data.editRules = getRules();
270
- return xgrid.value.refreshColumn();
271
- };
272
- /**
273
- * @description 显示加载框
274
- */
275
- const showLoading = () => {
276
- data.loading = true;
277
- };
278
- /**
279
- * @description 隐藏加载框
280
- */
281
- const hiddenLoading = () => {
282
- data.loading = false;
283
- };
284
- /**
285
- * @description 获取实例方法
286
- * @return vxe-grid实例的方法
287
- */
288
- const getInstance = () => {
289
- return toRaw(xgrid.value);
290
- };
291
- /**
292
- * @description 获取表格全量数据方法
293
- * @return vxe-grid表格全量数据
294
- */
295
- const getTableData = () => {
296
- return xgrid.value.getTableData().fullData;
297
- };
298
- /**
299
- * @description 获取表格选中的行
300
- * @return vxe-grid表格勾选行
301
- */
302
- const getSelectRecords = (isFull = false) => {
303
- const columnType = props.columns[0].type;
304
- const checkRecords =
305
- columnType === 'radio' ? xgrid.value.getRadioRecord(isFull) : xgrid.value.getCheckboxRecords(isFull);
306
- if (columnType === 'checkbox' && !checkRecords.length) {
307
- warnMessage(t('message.tip_selectedRecord'));
308
- return [];
309
- } else if (columnType === 'radio' && !checkRecords) {
310
- warnMessage(t('message.tip_selectedRecord'));
311
- return null;
312
- }
313
- return checkRecords;
314
- };
315
-
316
- const callback = (cb, response) => {
317
- attrs?.callback && attrs?.callback[cb] && attrs?.callback[cb](response);
318
- };
319
-
320
- const onReset = e => {
321
- console.log(e);
322
- const data = e.data;
323
- const items = props.items.filter(f => f.itemRender?.props?.multiple);
324
- console.log(items);
325
- items.forEach(item => {
326
- if (item.itemRender.props.defaultValue) {
327
- data[`_${item.field}`] = item.itemRender.props.defaultValue.split(',');
328
- } else {
329
- data[`_${item.field}`] = [];
330
- }
331
- });
332
- };
333
-
334
- let sortable2: any;
335
- const columnDrop = () => {
336
- const $grid = xgrid.value;
337
- sortable2 = Sortable.create($grid.$el.querySelector('.vxe-table--header .vxe-header--row'), {
338
- disabled: !attrs.gridId,
339
- handle: '.vxe-header--column',
340
- onEnd: async sortableEvent => {
341
- const targetThElem = sortableEvent.item;
342
- const newIndex = sortableEvent.newIndex as number;
343
- const oldIndex = sortableEvent.oldIndex as number;
344
- const { fullColumn, tableColumn } = $grid.getTableColumn();
345
- const wrapperElem = targetThElem.parentNode as HTMLElement;
346
- const newColumn = fullColumn[newIndex];
347
- const item = fullColumn[oldIndex];
348
- let nodrag = false;
349
- let msg = '固定列';
350
- if (newColumn.fixed) {
351
- nodrag = false;
352
- } else if (newIndex === 0 || ['checkbox', 'radio'].includes(item.type)) {
353
- msg = '勾选列';
354
- nodrag = true;
355
- } else if (item.field === 'operate' || newIndex === fullColumn.length - 1) {
356
- nodrag = true;
357
- msg = '操作列';
358
- }
359
- if (nodrag) {
360
- // 错误的移动
361
- const oldThElem = wrapperElem.children[oldIndex] as HTMLElement;
362
- if (newIndex > oldIndex) {
363
- wrapperElem.insertBefore(targetThElem, oldThElem);
364
- } else {
365
- wrapperElem.insertBefore(targetThElem, oldThElem ? oldThElem.nextElementSibling : oldThElem);
366
- }
367
- return errorMessage(msg + '不允许拖动!');
368
- }
369
- // 获取列索引 columnIndex > fullColumn
370
- const oldColumnIndex = $grid.getColumnIndex(tableColumn[oldIndex]);
371
- const newColumnIndex = $grid.getColumnIndex(tableColumn[newIndex]);
372
- // 移动到目标列
373
- const currRow = fullColumn.splice(oldColumnIndex, 1)[0];
374
- fullColumn.splice(newColumnIndex, 0, currRow);
375
-
376
- // 拖拽方向 1: 右 -1: 左
377
- const direction = newColumnIndex - oldColumnIndex > 0 ? 1 : -1;
378
-
379
- // 获取新列
380
- const newSort = (newColumnIndex + 1) * 10;
381
- const oldSort = (oldColumnIndex + 1) * 10;
382
- // 目标列索引+1,方便后续计算
383
- const comparisonVal = newSort + 1 * direction;
384
- for (const key in cacheColumns) {
385
- const cacheValue = cacheColumns[key];
386
- if (direction > 0 && cacheValue < comparisonVal && cacheValue > oldSort) {
387
- // 大于拖拽列且小于目标列的索引,均向前移动一个单位
388
- cacheColumns[key] = cacheValue - 10 * direction;
389
- } else if (direction < 0 && cacheValue > comparisonVal && cacheValue < oldSort) {
390
- // 小于拖拽列且大于目标列的索引, 均向后移动一个单位
391
- cacheColumns[key] = cacheValue - 10 * direction;
392
- }
393
- }
394
-
395
- cacheColumns[currRow.field] = newSort;
396
-
397
- dbstorage.setItem(kSTORECOLUM, { [attrs.gridId]: cacheColumns });
398
- $grid.loadColumn(fullColumn);
399
- }
400
- });
401
- };
402
-
403
- /**
404
- * @description 常用查询面板确认查询
405
- * @param data 常用查询条件
406
- */
407
- // const onSearch = data => {
408
- // showModal.value = false;
409
- // const { form } = xgrid.value.getProxyInfo();
410
- // Object.assign(form, data);
411
- // refreshData();
412
- // };
413
-
414
- const reloadGrid = () => {
415
- setGridConfig();
416
- };
417
-
418
- /**
419
- * @description Vue实例对外暴露的相关方法或属性
420
- */
421
- defineExpose({
422
- getTableData,
423
- getSelectRecords,
424
- refreshData,
425
- refreshColumn,
426
- getInstance,
427
- showLoading,
428
- hiddenLoading,
429
- reloadGrid
430
- });
431
-
432
- const toolbarButtonClick = ({ code }) => {
433
- emit('buttonClick', code);
434
- };
435
- const cellClick = e => {
436
- emit('cellClick', e);
437
- };
438
- const cellDbclick = e => {
439
- emit('cellDbclick', e);
440
- };
441
- const editEctivated = e => {
442
- emit('editEctivated', e);
443
- };
444
-
445
- /**
446
- * @description: 监听窗口变化,动态改变表格的高度
447
- */
448
- const addResizeListener = () => {
449
- window.onresize = () => {
450
- return (() => {
451
- let height = attrs?.height || window.innerHeight - 90;
452
- if (attrs.mode !== 'inline' && !attrs?.height) {
453
- height = window.innerHeight - 180;
454
- }
455
- data.height = height < 240 ? 240 : height;
456
- })();
457
- };
458
- };
459
-
460
- let initTime: any;
461
- nextTick(() => {
462
- // 加载完成之后在绑定拖动事件
463
- initTime = setTimeout(() => {
464
- columnDrop();
465
- }, 500);
466
- });
467
- /**
468
- * @description Vue实例卸载
469
- */
470
- onUnmounted(() => {
471
- clearTimeout(initTime);
472
- sortable2 && sortable2.destroy();
473
- });
474
- /**
475
- * @description Vue实例挂载
476
- */
477
- onBeforeMount(() => {
478
- setGridConfig();
479
- addResizeListener();
480
- });
481
-
482
- const emit = defineEmits<{
483
- (e: 'buttonClick', code: string): void;
484
- (e: 'cellClick', data: any): void;
485
- (e: 'cellDbclick', data: any): void;
486
- (e: 'editEctivated', data: any): void;
487
- }>();
488
- </script>
489
-
490
- <style lang="scss">
491
- .ut-grid-wrapper {
492
- padding: 5px;
493
- background-color: #fff;
494
-
495
- .vxe-form--item {
496
- padding: 0.1em 0.8em 0.1em 0 !important;
497
-
498
- .el-select {
499
- .el-input {
500
- height: 26px;
501
- }
502
-
503
- .el-select__tags-text {
504
- color: #000;
505
- }
506
- }
507
- }
508
-
509
- .vxe-grid--layout-body-content-wrapper {
510
- overflow: hidden;
511
- }
512
- }
513
- </style>
1
+ <!--
2
+ * @Author: wei.li
3
+ * @Date: 2021-11-17 16:33:37
4
+ * @LastEditors: levi7754 levi7754@163.com
5
+ * @LastEditTime: 2025-11-06 18:56:12
6
+ * @Description: file content
7
+ -->
8
+ <template>
9
+ <div style="width: 100%; height: 100%">
10
+ <vxe-grid
11
+ ref="xgrid"
12
+ v-bind="data"
13
+ class="ut-grid-wrapper"
14
+ v-on="attrs.events || {}"
15
+ @toolbarButtonClick="toolbarButtonClick"
16
+ @toolbarToolClick="toolbarButtonClick"
17
+ @cell-click="cellClick"
18
+ @cell-dblclick="cellDbclick"
19
+ @edit-activated="editEctivated"
20
+ @form-reset="onReset"
21
+ />
22
+ <!-- <SearchScheme
23
+ v-if="showModal && props.url"
24
+ :items="items"
25
+ :view="viewCode"
26
+ @search="onSearch"
27
+ @close="showModal = false"
28
+ /> -->
29
+ </div>
30
+ </template>
31
+
32
+ <script lang="ts" setup>
33
+ // @ts-nocheck
34
+ import { useI18n } from 'vue-i18n';
35
+ import { ref, onBeforeMount, reactive, getCurrentInstance, toRaw, useAttrs, onUnmounted, nextTick } from 'vue';
36
+ import { VxeGridProps } from 'vxe-table';
37
+ import Sortable from 'sortablejs';
38
+ import { clone } from 'xe-utils';
39
+ import { formatGridItems, i18nColums, formatRules, errorMessage, dbstorage, warnMessage } from '@utogether/utils';
40
+ import { http } from '../../../utils/udp/http';
41
+ import {
42
+ queryAll,
43
+ query,
44
+ del,
45
+ save,
46
+ footerSumMethod,
47
+ getToolBarConfig,
48
+ defaultColums,
49
+ onCheckMethod,
50
+ getAttrs
51
+ } from '../utils';
52
+ // import SearchScheme from '../components/SuSearch.vue';
53
+
54
+ defineOptions({
55
+ name: 'UtGrid'
56
+ });
57
+
58
+ export interface IProps {
59
+ checkMethod?: Function;
60
+ serviceCode?: IRecord;
61
+ defaultValue?: IRecord;
62
+ defaultParams?: IRecord;
63
+ url?: string | IRecord;
64
+ columns: Array<ITableColProps>;
65
+ items?: Array<IFormItemProps>;
66
+ editable?: boolean;
67
+ needExport?: boolean; // 是否需要导出
68
+ autoLoad?: boolean; // 自动加载查询数据
69
+ }
70
+
71
+ const attrs: IRecord = getAttrs(useAttrs());
72
+
73
+ const kSTORECOLUM = 'U_TABLE_COLUMNN_SORT';
74
+ let storeColums;
75
+ const cacheColumns = {};
76
+
77
+ // console.log(attrs);
78
+ const instance = getCurrentInstance()!;
79
+ const hasAuthority = instance.appContext.config.globalProperties.$hasAuthority;
80
+ const serviceApi = instance.appContext.config.globalProperties.$serviceApi;
81
+ const viewCode = instance.parent.type.name;
82
+ const $mode = instance.appContext.config.globalProperties.$mode;
83
+
84
+ const props = withDefaults(defineProps<IProps>(), {
85
+ /**
86
+ * @deprecated 2.10.0版本失效,
87
+ * */
88
+ serviceCode: (): IRecord => {
89
+ return {};
90
+ },
91
+ items: () => [],
92
+ columns: () => [],
93
+ editable: true,
94
+ autoLoad: true,
95
+ needExport: true
96
+ });
97
+
98
+ const { t } = useI18n();
99
+
100
+ const xgrid = ref(null);
101
+ const showModal = ref(false);
102
+
103
+ const favorite = {
104
+ icon: 'vxe-icon-setting',
105
+ name: 'favorite',
106
+ events: {
107
+ click: (e, option) => {
108
+ if (option.name === 'favorite') {
109
+ showModal.value = true;
110
+ }
111
+ }
112
+ }
113
+ };
114
+
115
+ /**
116
+ * @description: 根据items 获取必填选
117
+ */
118
+ const getRules = () => {
119
+ if (!props.columns.length) return {};
120
+ return formatRules(props.columns, t);
121
+ };
122
+ /**
123
+ * @description: colum 统一添加国家化
124
+ */
125
+ const getColumns = () => {
126
+ const columns = props.columns;
127
+ if (attrs.gridId) {
128
+ const cols = defaultColums
129
+ .filter(f => !columns.some(s => s.field === f.field))
130
+ .map(col => {
131
+ if (attrs.format && ['lastUpdateDate', 'creationDate'].includes(col.field)) {
132
+ col.formatter = attrs.format;
133
+ col.width = 90;
134
+ }
135
+ return col;
136
+ });
137
+ const idx = columns.findIndex(s => s.field === 'operate');
138
+ if (idx !== -1) {
139
+ columns.splice(idx, 0, ...cols);
140
+ } else {
141
+ columns.push(...cols);
142
+ }
143
+ }
144
+ const act_columns = attrs.gridId ? formatColums(columns) : columns;
145
+
146
+ return i18nColums(act_columns, attrs.sortable);
147
+ };
148
+
149
+ dbstorage.getItem(kSTORECOLUM).then(value => {
150
+ storeColums = value;
151
+ data.columns = getColumns();
152
+ });
153
+
154
+ const data = reactive<VxeGridProps>({
155
+ border: true,
156
+ pagerConfig: { pageSize: attrs.pageSize || 20 },
157
+ editConfig: {},
158
+ editRules: getRules(),
159
+ formConfig: {},
160
+ columnConfig: { useKey: true },
161
+ toolbarConfig: { enabled: false },
162
+ sortConfig: { multiple: true, trigger: 'cell' },
163
+ height: $mode ? undefined : window.innerHeight - 92,
164
+
165
+ checkboxConfig: {
166
+ checkMethod: ({ row }) => onCheckMethod(row, props),
167
+ checkRowKeys: props.checkRowKeys
168
+ },
169
+ loading: false,
170
+ footerRowClassName: 'ut-grid-footer',
171
+ proxyConfig: {
172
+ form: true, // 查询是需要启用表单代理
173
+ autoLoad: props.autoLoad,
174
+ showResponseMsgvxe: false,
175
+ showActionMsgvxe: false,
176
+ // 接收 Promise
177
+ ajax: {
178
+ queryAll: ({ form }) => queryAll(props, serviceApi, form),
179
+ query: ({ page, form, code }) => query(props, form, page, http, code, $mode),
180
+ delete: ({ body: { removeRecords } }) => del(serviceApi, removeRecords, props),
181
+ save: ({ body }) => Promise.all(save(serviceApi, body, props)),
182
+ querySuccess: ({ response }) => callback('querySuccess', response),
183
+ queryError: ({ response }) => callback('queryError', response),
184
+ deleteSuccess: ({ response }) => callback('deleteSuccess', response),
185
+ deleteError: ({ response }) => callback('deleteError', response),
186
+ saveSuccess: ({ response }) => callback('saveSuccess', response),
187
+ saveError: ({ response }) => callback('saveError', response)
188
+ }
189
+ },
190
+ columns: !attrs.gridId ? getColumns() : [],
191
+ ...attrs
192
+ });
193
+
194
+ /**
195
+ * @description: 预处理查询form
196
+ * @return {*} items
197
+ */
198
+ const getItems = () => {
199
+ if (!props.items.length) return props.items;
200
+ return formatGridItems(clone(props.items, true), viewCode && props.url ? favorite : viewCode);
201
+ };
202
+
203
+ /**
204
+ * @description 格式化column
205
+ * @return {*} columns
206
+ */
207
+ function formatColums(columns) {
208
+ const customSort = storeColums ? storeColums[attrs.gridId] : {};
209
+ if (!customSort) return columns;
210
+ return columns
211
+ .map((col, idx) => {
212
+ const sort = (idx + 1) * 10;
213
+ col._sort = customSort[col.field] || sort;
214
+ // 缓存列索引数据
215
+ cacheColumns[col.field] = col._sort;
216
+ return col;
217
+ })
218
+ .sort((a, b) => a._sort - b._sort);
219
+ }
220
+
221
+ /**
222
+ * @description: 设置grid参数
223
+ */
224
+ const setGridConfig = () => {
225
+ // 查询
226
+ if (props.items.length) {
227
+ // data.formConfig = {};
228
+ data.formConfig = {
229
+ titleWidth: 100,
230
+ titleAlign: 'right',
231
+ items: getItems(),
232
+ rules: formatRules(props.items, t),
233
+ validConfig: { showMessage: false }
234
+ };
235
+ }
236
+ // tool bar
237
+ const obj = getToolBarConfig(data, props, attrs, hasAuthority);
238
+ Object.assign(data, obj);
239
+ // 表格id,用于自定义列
240
+ if (attrs.gridId) {
241
+ data.id = attrs.gridId;
242
+ data.customConfig = {
243
+ storage: true,
244
+ mode: 'popup',
245
+ checkMethod({ column }) {
246
+ return column.field === 'operate' || ['checkbox', 'radio'].includes(column.type) ? false : true;
247
+ },
248
+ modalOptions: {
249
+ width: 750,
250
+ height: '75%'
251
+ }
252
+ };
253
+ }
254
+ if (attrs.mergeFooter) {
255
+ // 合计方法
256
+ data.showFooter = true;
257
+ data.footerMethod = ({ columns, data }) => footerSumMethod({ columns, data }, attrs.mergeFooter);
258
+ }
259
+ };
260
+ /**
261
+ * @description 手动调用查询方法
262
+ */
263
+ const refreshData = () => {
264
+ xgrid.value.commitProxy('query');
265
+ };
266
+ /**
267
+ * @description 刷新列数据
268
+ */
269
+ const refreshColumn = () => {
270
+ data.editRules = getRules();
271
+ return xgrid.value.refreshColumn();
272
+ };
273
+ /**
274
+ * @description 显示加载框
275
+ */
276
+ const showLoading = () => {
277
+ data.loading = true;
278
+ };
279
+ /**
280
+ * @description 隐藏加载框
281
+ */
282
+ const hiddenLoading = () => {
283
+ data.loading = false;
284
+ };
285
+ /**
286
+ * @description 获取实例方法
287
+ * @return vxe-grid实例的方法
288
+ */
289
+ const getInstance = () => {
290
+ return toRaw(xgrid.value);
291
+ };
292
+ /**
293
+ * @description 获取表格全量数据方法
294
+ * @return vxe-grid表格全量数据
295
+ */
296
+ const getTableData = () => {
297
+ return xgrid.value.getTableData().fullData;
298
+ };
299
+ /**
300
+ * @description 获取表格选中的行
301
+ * @return vxe-grid表格勾选行
302
+ */
303
+ const getSelectRecords = (isFull = false) => {
304
+ const columnType = props.columns[0].type;
305
+ const checkRecords =
306
+ columnType === 'radio' ? xgrid.value.getRadioRecord(isFull) : xgrid.value.getCheckboxRecords(isFull);
307
+ if (columnType === 'checkbox' && !checkRecords.length) {
308
+ warnMessage(t('message.tip_selectedRecord'));
309
+ return [];
310
+ } else if (columnType === 'radio' && !checkRecords) {
311
+ warnMessage(t('message.tip_selectedRecord'));
312
+ return null;
313
+ }
314
+ return checkRecords;
315
+ };
316
+
317
+ const callback = (cb, response) => {
318
+ attrs?.callback && attrs?.callback[cb] && attrs?.callback[cb](response);
319
+ };
320
+
321
+ const onReset = e => {
322
+ console.log(e);
323
+ const data = e.data;
324
+ const items = props.items.filter(f => f.itemRender?.props?.multiple);
325
+ console.log(items);
326
+ items.forEach(item => {
327
+ if (item.itemRender.props.defaultValue) {
328
+ data[`_${item.field}`] = item.itemRender.props.defaultValue.split(',');
329
+ } else {
330
+ data[`_${item.field}`] = [];
331
+ }
332
+ });
333
+ };
334
+
335
+ let sortable2: any;
336
+ const columnDrop = () => {
337
+ const $grid = xgrid.value;
338
+ sortable2 = Sortable.create($grid.$el.querySelector('.vxe-table--header .vxe-header--row'), {
339
+ disabled: !attrs.gridId,
340
+ handle: '.vxe-header--column',
341
+ onEnd: async sortableEvent => {
342
+ const targetThElem = sortableEvent.item;
343
+ const newIndex = sortableEvent.newIndex as number;
344
+ const oldIndex = sortableEvent.oldIndex as number;
345
+ const { fullColumn, tableColumn } = $grid.getTableColumn();
346
+ const wrapperElem = targetThElem.parentNode as HTMLElement;
347
+ const newColumn = fullColumn[newIndex];
348
+ const item = fullColumn[oldIndex];
349
+ let nodrag = false;
350
+ let msg = '固定列';
351
+ if (newColumn.fixed) {
352
+ nodrag = false;
353
+ } else if (newIndex === 0 || ['checkbox', 'radio'].includes(item.type)) {
354
+ msg = '勾选列';
355
+ nodrag = true;
356
+ } else if (item.field === 'operate' || newIndex === fullColumn.length - 1) {
357
+ nodrag = true;
358
+ msg = '操作列';
359
+ }
360
+ if (nodrag) {
361
+ // 错误的移动
362
+ const oldThElem = wrapperElem.children[oldIndex] as HTMLElement;
363
+ if (newIndex > oldIndex) {
364
+ wrapperElem.insertBefore(targetThElem, oldThElem);
365
+ } else {
366
+ wrapperElem.insertBefore(targetThElem, oldThElem ? oldThElem.nextElementSibling : oldThElem);
367
+ }
368
+ return errorMessage(msg + '不允许拖动!');
369
+ }
370
+ // 获取列索引 columnIndex > fullColumn
371
+ const oldColumnIndex = $grid.getColumnIndex(tableColumn[oldIndex]);
372
+ const newColumnIndex = $grid.getColumnIndex(tableColumn[newIndex]);
373
+ // 移动到目标列
374
+ const currRow = fullColumn.splice(oldColumnIndex, 1)[0];
375
+ fullColumn.splice(newColumnIndex, 0, currRow);
376
+
377
+ // 拖拽方向 1: -1:
378
+ const direction = newColumnIndex - oldColumnIndex > 0 ? 1 : -1;
379
+
380
+ // 获取新列
381
+ const newSort = (newColumnIndex + 1) * 10;
382
+ const oldSort = (oldColumnIndex + 1) * 10;
383
+ // 目标列索引+1,方便后续计算
384
+ const comparisonVal = newSort + 1 * direction;
385
+ for (const key in cacheColumns) {
386
+ const cacheValue = cacheColumns[key];
387
+ if (direction > 0 && cacheValue < comparisonVal && cacheValue > oldSort) {
388
+ // 大于拖拽列且小于目标列的索引,均向前移动一个单位
389
+ cacheColumns[key] = cacheValue - 10 * direction;
390
+ } else if (direction < 0 && cacheValue > comparisonVal && cacheValue < oldSort) {
391
+ // 小于拖拽列且大于目标列的索引, 均向后移动一个单位
392
+ cacheColumns[key] = cacheValue - 10 * direction;
393
+ }
394
+ }
395
+
396
+ cacheColumns[currRow.field] = newSort;
397
+
398
+ dbstorage.setItem(kSTORECOLUM, { [attrs.gridId]: cacheColumns });
399
+ $grid.loadColumn(fullColumn);
400
+ }
401
+ });
402
+ };
403
+
404
+ /**
405
+ * @description 常用查询面板确认查询
406
+ * @param data 常用查询条件
407
+ */
408
+ // const onSearch = data => {
409
+ // showModal.value = false;
410
+ // const { form } = xgrid.value.getProxyInfo();
411
+ // Object.assign(form, data);
412
+ // refreshData();
413
+ // };
414
+
415
+ const reloadGrid = () => {
416
+ setGridConfig();
417
+ };
418
+
419
+ /**
420
+ * @description Vue实例对外暴露的相关方法或属性
421
+ */
422
+ defineExpose({
423
+ getTableData,
424
+ getSelectRecords,
425
+ refreshData,
426
+ refreshColumn,
427
+ getInstance,
428
+ showLoading,
429
+ hiddenLoading,
430
+ reloadGrid
431
+ });
432
+
433
+ const toolbarButtonClick = ({ code }) => {
434
+ emit('buttonClick', code);
435
+ };
436
+ const cellClick = e => {
437
+ emit('cellClick', e);
438
+ };
439
+ const cellDbclick = e => {
440
+ emit('cellDbclick', e);
441
+ };
442
+ const editEctivated = e => {
443
+ emit('editEctivated', e);
444
+ };
445
+
446
+ /**
447
+ * @description: 监听窗口变化,动态改变表格的高度
448
+ */
449
+ const addResizeListener = () => {
450
+ window.onresize = () => {
451
+ return (() => {
452
+ let height = attrs?.height || window.innerHeight - 90;
453
+ if (attrs.mode !== 'inline' && !attrs?.height) {
454
+ height = window.innerHeight - 180;
455
+ }
456
+ data.height = height < 240 ? 240 : height;
457
+ })();
458
+ };
459
+ };
460
+
461
+ let initTime: any;
462
+ nextTick(() => {
463
+ // 加载完成之后在绑定拖动事件
464
+ initTime = setTimeout(() => {
465
+ columnDrop();
466
+ }, 500);
467
+ });
468
+ /**
469
+ * @description Vue实例卸载
470
+ */
471
+ onUnmounted(() => {
472
+ clearTimeout(initTime);
473
+ sortable2 && sortable2.destroy();
474
+ });
475
+ /**
476
+ * @description Vue实例挂载
477
+ */
478
+ onBeforeMount(() => {
479
+ setGridConfig();
480
+ addResizeListener();
481
+ });
482
+
483
+ const emit = defineEmits<{
484
+ (e: 'buttonClick', code: string): void;
485
+ (e: 'cellClick', data: any): void;
486
+ (e: 'cellDbclick', data: any): void;
487
+ (e: 'editEctivated', data: any): void;
488
+ }>();
489
+ </script>
490
+
491
+ <style lang="scss">
492
+ .ut-grid-wrapper {
493
+ padding: 5px;
494
+ background-color: #fff;
495
+
496
+ .vxe-form--item {
497
+ padding: 0.1em 0.8em 0.1em 0 !important;
498
+
499
+ .el-select {
500
+ .el-input {
501
+ height: 26px;
502
+ }
503
+
504
+ .el-select__tags-text {
505
+ color: #000;
506
+ }
507
+ }
508
+ }
509
+
510
+ .vxe-grid--layout-body-content-wrapper {
511
+ overflow: hidden;
512
+ }
513
+ }
514
+ </style>