@utogether/udp-core 1.0.1-beta.27 → 1.0.1-beta.30

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 (95) hide show
  1. package/build/plugins.ts +37 -37
  2. package/dist/{403-A9aD_bZN.js → 403-DdjDWbkf.js} +1 -1
  3. package/dist/{404-DREd70aQ.js → 404-D9vF2gFz.js} +1 -1
  4. package/dist/{500-C5qVXkGt.js → 500-mVaDmUjL.js} +1 -1
  5. package/dist/{AuthorityInfo-CYO2IVau.js → AuthorityInfo-DOUJ_Zrj.js} +1 -1
  6. package/dist/{AuthorityInfo.vue_vue_type_style_index_0_lang-V7e_KwWp.js → AuthorityInfo.vue_vue_type_style_index_0_lang-B12sAzqt.js} +1 -1
  7. package/dist/{Company-CaottHQO.js → Company-DY__kM9F.js} +3 -3
  8. package/dist/{CompanyPanel-B3hOiXqj.js → CompanyPanel-C5N8QcMA.js} +1 -1
  9. package/dist/{Department-CHkuRvJN.js → Department-DsuDZdy5.js} +3 -3
  10. package/dist/{DepartmentPanel-DieWfIxW.js → DepartmentPanel-CdwI7Rzu.js} +2 -2
  11. package/dist/{DesignPanel-REWXp3x4.js → DesignPanel-B50-g0TL.js} +1 -1
  12. package/dist/{DesignPanel.vue_vue_type_style_index_0_lang-Df0xc5XP.js → DesignPanel.vue_vue_type_style_index_0_lang-KV8JOZ6v.js} +2 -2
  13. package/dist/{DictView-DnpDHskG.js → DictView-Be2Z5Obk.js} +1 -1
  14. package/dist/{InvOrganization-DoIsDrAx.js → InvOrganization-Lui1q3Ou.js} +1 -1
  15. package/dist/{Org-C4P5Cwia.js → Org-qO5ExsPN.js} +1 -1
  16. package/dist/{Preview-d90pQdFJ.js → Preview-Dq4dfV2D.js} +1 -1
  17. package/dist/{ReportDefine-DNrp4lFP.js → ReportDefine-DH3FvbS1.js} +1 -1
  18. package/dist/{ReportDesign-Ch8x6_mW.js → ReportDesign-Bou01Jbr.js} +2 -2
  19. package/dist/{ReportQuery-C1yR0ULS.js → ReportQuery-BBkmPPSw.js} +1 -1
  20. package/dist/{ReportQueryFrom-BKwf61CL.js → ReportQueryFrom-BCY8lTJ7.js} +1 -1
  21. package/dist/{ReportQueryFrom.vue_vue_type_style_index_0_lang-D2ddteNz.js → ReportQueryFrom.vue_vue_type_style_index_0_lang-CpktcM8J.js} +1 -1
  22. package/dist/{ReportTemplate-HLHli4Cc.js → ReportTemplate-C_yJXxQ-.js} +1 -1
  23. package/dist/{Role-4GbuIhk6.js → Role-CTatYsrC.js} +3 -3
  24. package/dist/{RoleAssign-FGrSCg5R.js → RoleAssign-Cqt3CelK.js} +3 -3
  25. package/dist/{RolePanel-Ce1eKsM8.js → RolePanel-C3JMpNu8.js} +1 -1
  26. package/dist/{RolePanel-BcCozGfv.js → RolePanel-brKRJIhD.js} +1 -1
  27. package/dist/{RolePanel.vue_vue_type_script_setup_true_lang-BiOcU5GE.js → RolePanel.vue_vue_type_script_setup_true_lang-DD8u9pq8.js} +1 -1
  28. package/dist/{RolePanel.vue_vue_type_script_setup_true_lang-CqER1M9Y.js → RolePanel.vue_vue_type_script_setup_true_lang-i6Gq4r5B.js} +3 -3
  29. package/dist/{ScrollPanel.vue_vue_type_style_index_0_lang-BbgS5f79.js → ScrollPanel.vue_vue_type_style_index_0_lang-CiWKyjm3.js} +1 -1
  30. package/dist/{Staff-CBt_0rqg.js → Staff-Cd3twQ6Y.js} +3 -3
  31. package/dist/{StaffInfo-RCdWZr1r.js → StaffInfo-DJp0a0qd.js} +1 -1
  32. package/dist/{StaffInfo.vue_vue_type_script_setup_true_lang-Dm8Yin3r.js → StaffInfo.vue_vue_type_script_setup_true_lang-Dp2AhJ4I.js} +1 -1
  33. package/dist/{StaffPanel-2ka-H3IV.js → StaffPanel-B93hClzs.js} +1 -1
  34. package/dist/{StaffPanel.vue_vue_type_script_setup_true_lang-B0u-PqTe.js → StaffPanel.vue_vue_type_script_setup_true_lang-CXjUzq7n.js} +2 -2
  35. package/dist/{SysUser-Cs7uN3HU.js → SysUser-BvI6vaqI.js} +2 -2
  36. package/dist/{SysUserPanel-Df3qGMep.js → SysUserPanel-C9V8X-Ek.js} +1 -1
  37. package/dist/{SysUserPanel.vue_vue_type_script_setup_true_lang-ClwozbZE.js → SysUserPanel.vue_vue_type_script_setup_true_lang-bMqTui07.js} +1 -1
  38. package/dist/{SystemMenu-BMYVQd-E.js → SystemMenu-D4WME5d0.js} +2 -2
  39. package/dist/{UserInfo-DDk2iOqY.js → UserInfo-D-AfdfJs.js} +1 -1
  40. package/dist/{UserInfo.vue_vue_type_style_index_0_lang-CEccCnDi.js → UserInfo.vue_vue_type_style_index_0_lang-C-JQYIxe.js} +1 -1
  41. package/dist/{childView-C7u4Budn.js → childView--WMSo-wH.js} +1 -1
  42. package/dist/{childView-DFPGu0W-.js → childView-1MTl6Kaj.js} +1 -1
  43. package/dist/childView.vue_vue_type_style_index_0_lang-B8Losc4Y.js +170 -0
  44. package/dist/{childView.vue_vue_type_style_index_0_lang-B3fNaibG.js → childView.vue_vue_type_style_index_0_lang-BAVKNIXs.js} +1 -1
  45. package/dist/{code-rule-BcaRQ1zV.js → code-rule-D-RqrQB6.js} +40 -37
  46. package/dist/core.es.js +1 -1
  47. package/dist/{cron-task-DJQLZCsO.js → cron-task-D-X-KFZm.js} +1 -1
  48. package/dist/{frameView-uPEaJRC7.js → frameView-MAW_-GHJ.js} +1 -1
  49. package/dist/{index-D7BXpJPu.js → index-Bc9vCX7z.js} +45 -45
  50. package/dist/{layoutView-zw1-fplL.js → layoutView-De2QIEr2.js} +3 -3
  51. package/dist/{login-M-rLGYIn.js → login-rdZ0GPYc.js} +1 -1
  52. package/dist/{lov-view-BVfIna0M.js → lov-view-Ao7LMspL.js} +2 -2
  53. package/dist/{menuInfo-BTqoNOuZ.js → menuInfo-DmOcK6An.js} +1 -1
  54. package/dist/{menuInfo.vue_vue_type_style_index_0_lang-CHco0XcS.js → menuInfo.vue_vue_type_style_index_0_lang-Ln-zFWV7.js} +1 -1
  55. package/dist/{pda-app-BzzynCVk.js → pda-app-DY63mQ2T.js} +1 -1
  56. package/dist/{resource-CJQV7_75.js → resource-B21uV58T.js} +1 -1
  57. package/dist/{su-welcome-BxQYF4Ou.js → su-welcome-DgjzJeDF.js} +22 -19
  58. package/dist/{sys-config-DNFqTmvL.js → sys-config-DOtK2I32.js} +1 -1
  59. package/dist/udp-core.css +1 -1
  60. package/index.ts +49 -49
  61. package/package.json +3 -3
  62. package/src/components/SuScrollTree/ScrollPanel.vue +170 -170
  63. package/src/components/udp/content/index.vue +89 -0
  64. package/src/components/udp/form/form.vue +109 -109
  65. package/src/components/udp/grid/index.vue +524 -524
  66. package/src/components/udp/index.ts +2 -1
  67. package/src/components/udp/ut-stamp-badge/index.vue +272 -0
  68. package/src/components/udp/utils.ts +408 -408
  69. package/src/layout/components/lay-sidebar/sidebar-logo.vue +94 -94
  70. package/src/layout/components/lay-tag/index.vue +596 -596
  71. package/src/layout/hooks/useTag.ts +227 -227
  72. package/src/main.ts +1 -1
  73. package/src/plugins/i18n/module/u-workflow.ts +71 -71
  74. package/src/plugins/vxe-table/index.ts +116 -116
  75. package/src/plugins/vxe-table/render.tsx +945 -945
  76. package/src/router/index.ts +187 -187
  77. package/src/router/modules/flow.ts +35 -35
  78. package/src/router/utils.ts +420 -420
  79. package/src/store/modules/multiTags.ts +110 -110
  80. package/src/store/modules/permission.ts +113 -113
  81. package/src/style/button.scss +85 -85
  82. package/src/style/vxetable.scss +348 -348
  83. package/src/views/organization/department/DepartmentPanel.vue +269 -269
  84. package/src/views/system/menu/SystemMenu.vue +185 -185
  85. package/src/views/system/menu/menuInfo.vue +384 -384
  86. package/src/views/system/sysUser/SysUserPanel.vue +348 -348
  87. package/src/views/udev/coderule/code-rule.vue +17 -5
  88. package/src/views/udev/dict/DictView.vue +118 -118
  89. package/src/views/udev/dict/childView.vue +69 -109
  90. package/src/views/udev/lov/childView.vue +174 -174
  91. package/src/views/uhome/components/menu-favorite.vue +1 -1
  92. package/src/views/upms/interface/log-in.vue +100 -100
  93. package/src/views/upms/user/login-log.vue +54 -54
  94. package/src/views/utask/flow-task.vue +18 -18
  95. package/dist/childView.vue_vue_type_style_index_0_lang-BUMcbqzM.js +0 -187
@@ -1,524 +1,524 @@
1
- <!--
2
- * @Author: wei.li
3
- * @Date: 2021-11-17 16:33:37
4
- * @LastEditors: levi7754 levi7754@163.com
5
- * @LastEditTime: 2025-11-18 15:18:53
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 }) => {
180
- debugger;
181
- return query(props, form, page, serviceApi, code, $mode);
182
- },
183
- delete: ({ body: { removeRecords } }) => del(serviceApi, removeRecords, props),
184
- save: ({ body }) => Promise.all(save(serviceApi, body, props)),
185
- querySuccess: ({ response }) => callback('querySuccess', response),
186
- queryError: ({ response }) => callback('queryError', response),
187
- deleteSuccess: ({ response }) => callback('deleteSuccess', response),
188
- deleteError: ({ response }) => callback('deleteError', response),
189
- saveSuccess: ({ response }) => callback('saveSuccess', response),
190
- saveError: ({ response }) => callback('saveError', response)
191
- }
192
- },
193
- columns: !attrs.gridId ? getColumns() : [],
194
- ...attrs
195
- });
196
-
197
- /**
198
- * @description: 预处理查询form
199
- * @return {*} items
200
- */
201
- const getItems = () => {
202
- if (!props.items.length) return props.items;
203
- return formatGridItems(clone(props.items, true), viewCode && props.url ? favorite : viewCode);
204
- };
205
-
206
- /**
207
- * @description 格式化column
208
- * @return {*} columns
209
- */
210
- function formatColums(columns) {
211
- const customSort = storeColums ? storeColums[attrs.gridId] : {};
212
- if (!customSort) return columns;
213
- return columns
214
- .map((col, idx) => {
215
- const sort = (idx + 1) * 10;
216
- col._sort = customSort[col.field] || sort;
217
- // 缓存列索引数据
218
- cacheColumns[col.field] = col._sort;
219
- return col;
220
- })
221
- .sort((a, b) => a._sort - b._sort);
222
- }
223
-
224
- /**
225
- * @description: 设置grid参数
226
- */
227
- const setGridConfig = () => {
228
- // 查询
229
- if (props.items.length) {
230
- // data.formConfig = {};
231
- data.formConfig = {
232
- titleWidth: 100,
233
- titleAlign: 'right',
234
- items: getItems(),
235
- rules: formatRules(props.items, t),
236
- validConfig: { showMessage: false }
237
- };
238
- }
239
- // tool bar
240
- const obj = getToolBarConfig(data, props, attrs, hasAuthority);
241
- Object.assign(data, obj);
242
- // 表格id,用于自定义列
243
- if (attrs.gridId) {
244
- data.id = attrs.gridId;
245
- data.customConfig = {
246
- storage: true,
247
- mode: 'popup',
248
- checkMethod({ column }) {
249
- return column.field === 'operate' || ['checkbox', 'radio'].includes(column.type) ? false : true;
250
- },
251
- modalOptions: {
252
- width: 750,
253
- height: '75%'
254
- }
255
- };
256
- }
257
- if (attrs.mergeFooter) {
258
- // 合计方法
259
- data.showFooter = true;
260
- data.footerMethod = ({ columns, data }) => footerSumMethod({ columns, data }, attrs.mergeFooter);
261
- }
262
- };
263
- /**
264
- * @description 手动调用查询方法
265
- */
266
- const refreshData = () => {
267
- xgrid.value.commitProxy('query');
268
- };
269
- /**
270
- * @description 刷新列数据
271
- */
272
- const refreshColumn = () => {
273
- data.editRules = getRules();
274
- return xgrid.value.refreshColumn();
275
- };
276
- /**
277
- * @description 显示加载框
278
- */
279
- const showLoading = () => {
280
- data.loading = true;
281
- };
282
- /**
283
- * @description 隐藏加载框
284
- */
285
- const hiddenLoading = () => {
286
- data.loading = false;
287
- };
288
- /**
289
- * @description 获取实例方法
290
- * @return vxe-grid实例的方法
291
- */
292
- const getInstance = () => {
293
- return toRaw(xgrid.value);
294
- };
295
- /**
296
- * @description 获取表格全量数据方法
297
- * @return vxe-grid表格全量数据
298
- */
299
- const getTableData = () => {
300
- return xgrid.value.getTableData().fullData;
301
- };
302
- /**
303
- * @description 获取表格选中的行
304
- * @return vxe-grid表格勾选行
305
- */
306
- const getSelectRecords = (isFull = false) => {
307
- const columnType = props.columns[0].type;
308
- const checkRecords =
309
- columnType === 'radio' ? xgrid.value.getRadioRecord(isFull) : xgrid.value.getCheckboxRecords(isFull);
310
- if (columnType === 'checkbox' && !checkRecords.length) {
311
- warnMessage(t('message.tip_selectedRecord'));
312
- return [];
313
- } else if (columnType === 'radio' && !checkRecords) {
314
- warnMessage(t('message.tip_selectedRecord'));
315
- return null;
316
- }
317
- return checkRecords;
318
- };
319
-
320
- const callback = (cb, response) => {
321
- attrs?.callback && attrs?.callback[cb] && attrs?.callback[cb](response);
322
- };
323
-
324
- const onReset = async e => {
325
- console.log(e);
326
- const data = e.data;
327
- const items = props.items.filter(f => f.itemRender?.props?.multiple);
328
- console.log(items);
329
- items.forEach(item => {
330
- if (item.itemRender.props.defaultValue) {
331
- data[`_${item.field}`] = item.itemRender.props.defaultValue.split(',');
332
- data[`${item.field}`] = item.itemRender.props.defaultValue;
333
- } else {
334
- data[`_${item.field}`] = [];
335
- }
336
- });
337
- if (items.length) {
338
- // 多选时,重新查询一次
339
- setTimeout(() => {
340
- refreshData();
341
- }, 200);
342
- }
343
- };
344
-
345
- let sortable2: any;
346
- const columnDrop = () => {
347
- const $grid = xgrid.value;
348
- sortable2 = Sortable.create($grid.$el.querySelector('.vxe-table--header .vxe-header--row'), {
349
- disabled: !attrs.gridId,
350
- handle: '.vxe-header--column',
351
- onEnd: async sortableEvent => {
352
- const targetThElem = sortableEvent.item;
353
- const newIndex = sortableEvent.newIndex as number;
354
- const oldIndex = sortableEvent.oldIndex as number;
355
- const { fullColumn, tableColumn } = $grid.getTableColumn();
356
- const wrapperElem = targetThElem.parentNode as HTMLElement;
357
- const newColumn = fullColumn[newIndex];
358
- const item = fullColumn[oldIndex];
359
- let nodrag = false;
360
- let msg = '固定列';
361
- if (newColumn.fixed) {
362
- nodrag = false;
363
- } else if (newIndex === 0 || ['checkbox', 'radio'].includes(item.type)) {
364
- msg = '勾选列';
365
- nodrag = true;
366
- } else if (item.field === 'operate' || newIndex === fullColumn.length - 1) {
367
- nodrag = true;
368
- msg = '操作列';
369
- }
370
- if (nodrag) {
371
- // 错误的移动
372
- const oldThElem = wrapperElem.children[oldIndex] as HTMLElement;
373
- if (newIndex > oldIndex) {
374
- wrapperElem.insertBefore(targetThElem, oldThElem);
375
- } else {
376
- wrapperElem.insertBefore(targetThElem, oldThElem ? oldThElem.nextElementSibling : oldThElem);
377
- }
378
- return errorMessage(msg + '不允许拖动!');
379
- }
380
- // 获取列索引 columnIndex > fullColumn
381
- const oldColumnIndex = $grid.getColumnIndex(tableColumn[oldIndex]);
382
- const newColumnIndex = $grid.getColumnIndex(tableColumn[newIndex]);
383
- // 移动到目标列
384
- const currRow = fullColumn.splice(oldColumnIndex, 1)[0];
385
- fullColumn.splice(newColumnIndex, 0, currRow);
386
-
387
- // 拖拽方向 1: 右 -1: 左
388
- const direction = newColumnIndex - oldColumnIndex > 0 ? 1 : -1;
389
-
390
- // 获取新列
391
- const newSort = (newColumnIndex + 1) * 10;
392
- const oldSort = (oldColumnIndex + 1) * 10;
393
- // 目标列索引+1,方便后续计算
394
- const comparisonVal = newSort + 1 * direction;
395
- for (const key in cacheColumns) {
396
- const cacheValue = cacheColumns[key];
397
- if (direction > 0 && cacheValue < comparisonVal && cacheValue > oldSort) {
398
- // 大于拖拽列且小于目标列的索引,均向前移动一个单位
399
- cacheColumns[key] = cacheValue - 10 * direction;
400
- } else if (direction < 0 && cacheValue > comparisonVal && cacheValue < oldSort) {
401
- // 小于拖拽列且大于目标列的索引, 均向后移动一个单位
402
- cacheColumns[key] = cacheValue - 10 * direction;
403
- }
404
- }
405
-
406
- cacheColumns[currRow.field] = newSort;
407
-
408
- dbstorage.setItem(kSTORECOLUM, { [attrs.gridId]: cacheColumns });
409
- $grid.loadColumn(fullColumn);
410
- }
411
- });
412
- };
413
-
414
- /**
415
- * @description 常用查询面板确认查询
416
- * @param data 常用查询条件
417
- */
418
- // const onSearch = data => {
419
- // showModal.value = false;
420
- // const { form } = xgrid.value.getProxyInfo();
421
- // Object.assign(form, data);
422
- // refreshData();
423
- // };
424
-
425
- const reloadGrid = () => {
426
- setGridConfig();
427
- };
428
-
429
- /**
430
- * @description Vue实例对外暴露的相关方法或属性
431
- */
432
- defineExpose({
433
- getTableData,
434
- getSelectRecords,
435
- refreshData,
436
- refreshColumn,
437
- getInstance,
438
- showLoading,
439
- hiddenLoading,
440
- reloadGrid
441
- });
442
-
443
- const toolbarButtonClick = ({ code }) => {
444
- emit('buttonClick', code);
445
- };
446
- const cellClick = e => {
447
- emit('cellClick', e);
448
- };
449
- const cellDbclick = e => {
450
- emit('cellDbclick', e);
451
- };
452
- const editEctivated = e => {
453
- emit('editEctivated', e);
454
- };
455
-
456
- /**
457
- * @description: 监听窗口变化,动态改变表格的高度
458
- */
459
- const addResizeListener = () => {
460
- window.onresize = () => {
461
- return (() => {
462
- let height = attrs?.height || window.innerHeight - 90;
463
- if (attrs.mode !== 'inline' && !attrs?.height) {
464
- height = window.innerHeight - 180;
465
- }
466
- data.height = height < 240 ? 240 : height;
467
- })();
468
- };
469
- };
470
-
471
- let initTime: any;
472
- nextTick(() => {
473
- // 加载完成之后在绑定拖动事件
474
- initTime = setTimeout(() => {
475
- columnDrop();
476
- }, 500);
477
- });
478
- /**
479
- * @description Vue实例卸载
480
- */
481
- onUnmounted(() => {
482
- clearTimeout(initTime);
483
- sortable2 && sortable2.destroy();
484
- });
485
- /**
486
- * @description Vue实例挂载
487
- */
488
- onBeforeMount(() => {
489
- setGridConfig();
490
- addResizeListener();
491
- });
492
-
493
- const emit = defineEmits<{
494
- (e: 'buttonClick', code: string): void;
495
- (e: 'cellClick', data: any): void;
496
- (e: 'cellDbclick', data: any): void;
497
- (e: 'editEctivated', data: any): void;
498
- }>();
499
- </script>
500
-
501
- <style lang="scss">
502
- .ut-grid-wrapper {
503
- padding: 5px;
504
- background-color: #fff;
505
-
506
- .vxe-form--item {
507
- padding: 0.1em 0.8em 0.1em 0 !important;
508
-
509
- .el-select {
510
- .el-input {
511
- height: 26px;
512
- }
513
-
514
- .el-select__tags-text {
515
- color: #000;
516
- }
517
- }
518
- }
519
-
520
- .vxe-grid--layout-body-content-wrapper {
521
- overflow: hidden;
522
- }
523
- }
524
- </style>
1
+ <!--
2
+ * @Author: wei.li
3
+ * @Date: 2021-11-17 16:33:37
4
+ * @LastEditors: levi7754 levi7754@163.com
5
+ * @LastEditTime: 2025-11-18 15:18:53
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 }) => {
180
+ debugger;
181
+ return query(props, form, page, serviceApi, code, $mode);
182
+ },
183
+ delete: ({ body: { removeRecords } }) => del(serviceApi, removeRecords, props),
184
+ save: ({ body }) => Promise.all(save(serviceApi, body, props)),
185
+ querySuccess: ({ response }) => callback('querySuccess', response),
186
+ queryError: ({ response }) => callback('queryError', response),
187
+ deleteSuccess: ({ response }) => callback('deleteSuccess', response),
188
+ deleteError: ({ response }) => callback('deleteError', response),
189
+ saveSuccess: ({ response }) => callback('saveSuccess', response),
190
+ saveError: ({ response }) => callback('saveError', response)
191
+ }
192
+ },
193
+ columns: !attrs.gridId ? getColumns() : [],
194
+ ...attrs
195
+ });
196
+
197
+ /**
198
+ * @description: 预处理查询form
199
+ * @return {*} items
200
+ */
201
+ const getItems = () => {
202
+ if (!props.items.length) return props.items;
203
+ return formatGridItems(clone(props.items, true), viewCode && props.url ? favorite : viewCode);
204
+ };
205
+
206
+ /**
207
+ * @description 格式化column
208
+ * @return {*} columns
209
+ */
210
+ function formatColums(columns) {
211
+ const customSort = storeColums ? storeColums[attrs.gridId] : {};
212
+ if (!customSort) return columns;
213
+ return columns
214
+ .map((col, idx) => {
215
+ const sort = (idx + 1) * 10;
216
+ col._sort = customSort[col.field] || sort;
217
+ // 缓存列索引数据
218
+ cacheColumns[col.field] = col._sort;
219
+ return col;
220
+ })
221
+ .sort((a, b) => a._sort - b._sort);
222
+ }
223
+
224
+ /**
225
+ * @description: 设置grid参数
226
+ */
227
+ const setGridConfig = () => {
228
+ // 查询
229
+ if (props.items.length) {
230
+ // data.formConfig = {};
231
+ data.formConfig = {
232
+ titleWidth: 100,
233
+ titleAlign: 'right',
234
+ items: getItems(),
235
+ rules: formatRules(props.items, t),
236
+ validConfig: { showMessage: false }
237
+ };
238
+ }
239
+ // tool bar
240
+ const obj = getToolBarConfig(data, props, attrs, hasAuthority);
241
+ Object.assign(data, obj);
242
+ // 表格id,用于自定义列
243
+ if (attrs.gridId) {
244
+ data.id = attrs.gridId;
245
+ data.customConfig = {
246
+ storage: true,
247
+ mode: 'popup',
248
+ checkMethod({ column }) {
249
+ return column.field === 'operate' || ['checkbox', 'radio'].includes(column.type) ? false : true;
250
+ },
251
+ modalOptions: {
252
+ width: 750,
253
+ height: '75%'
254
+ }
255
+ };
256
+ }
257
+ if (attrs.mergeFooter) {
258
+ // 合计方法
259
+ data.showFooter = true;
260
+ data.footerMethod = ({ columns, data }) => footerSumMethod({ columns, data }, attrs.mergeFooter);
261
+ }
262
+ };
263
+ /**
264
+ * @description 手动调用查询方法
265
+ */
266
+ const refreshData = () => {
267
+ xgrid.value.commitProxy('query');
268
+ };
269
+ /**
270
+ * @description 刷新列数据
271
+ */
272
+ const refreshColumn = () => {
273
+ data.editRules = getRules();
274
+ return xgrid.value.refreshColumn();
275
+ };
276
+ /**
277
+ * @description 显示加载框
278
+ */
279
+ const showLoading = () => {
280
+ data.loading = true;
281
+ };
282
+ /**
283
+ * @description 隐藏加载框
284
+ */
285
+ const hiddenLoading = () => {
286
+ data.loading = false;
287
+ };
288
+ /**
289
+ * @description 获取实例方法
290
+ * @return vxe-grid实例的方法
291
+ */
292
+ const getInstance = () => {
293
+ return toRaw(xgrid.value);
294
+ };
295
+ /**
296
+ * @description 获取表格全量数据方法
297
+ * @return vxe-grid表格全量数据
298
+ */
299
+ const getTableData = () => {
300
+ return xgrid.value.getTableData().fullData;
301
+ };
302
+ /**
303
+ * @description 获取表格选中的行
304
+ * @return vxe-grid表格勾选行
305
+ */
306
+ const getSelectRecords = (isFull = false) => {
307
+ const columnType = props.columns[0].type;
308
+ const checkRecords =
309
+ columnType === 'radio' ? xgrid.value.getRadioRecord(isFull) : xgrid.value.getCheckboxRecords(isFull);
310
+ if (columnType === 'checkbox' && !checkRecords.length) {
311
+ warnMessage(t('message.tip_selectedRecord'));
312
+ return [];
313
+ } else if (columnType === 'radio' && !checkRecords) {
314
+ warnMessage(t('message.tip_selectedRecord'));
315
+ return null;
316
+ }
317
+ return checkRecords;
318
+ };
319
+
320
+ const callback = (cb, response) => {
321
+ attrs?.callback && attrs?.callback[cb] && attrs?.callback[cb](response);
322
+ };
323
+
324
+ const onReset = async e => {
325
+ console.log(e);
326
+ const data = e.data;
327
+ const items = props.items.filter(f => f.itemRender?.props?.multiple);
328
+ console.log(items);
329
+ items.forEach(item => {
330
+ if (item.itemRender.props.defaultValue) {
331
+ data[`_${item.field}`] = item.itemRender.props.defaultValue.split(',');
332
+ data[`${item.field}`] = item.itemRender.props.defaultValue;
333
+ } else {
334
+ data[`_${item.field}`] = [];
335
+ }
336
+ });
337
+ if (items.length) {
338
+ // 多选时,重新查询一次
339
+ setTimeout(() => {
340
+ refreshData();
341
+ }, 200);
342
+ }
343
+ };
344
+
345
+ let sortable2: any;
346
+ const columnDrop = () => {
347
+ const $grid = xgrid.value;
348
+ sortable2 = Sortable.create($grid.$el.querySelector('.vxe-table--header .vxe-header--row'), {
349
+ disabled: !attrs.gridId,
350
+ handle: '.vxe-header--column',
351
+ onEnd: async sortableEvent => {
352
+ const targetThElem = sortableEvent.item;
353
+ const newIndex = sortableEvent.newIndex as number;
354
+ const oldIndex = sortableEvent.oldIndex as number;
355
+ const { fullColumn, tableColumn } = $grid.getTableColumn();
356
+ const wrapperElem = targetThElem.parentNode as HTMLElement;
357
+ const newColumn = fullColumn[newIndex];
358
+ const item = fullColumn[oldIndex];
359
+ let nodrag = false;
360
+ let msg = '固定列';
361
+ if (newColumn.fixed) {
362
+ nodrag = false;
363
+ } else if (newIndex === 0 || ['checkbox', 'radio'].includes(item.type)) {
364
+ msg = '勾选列';
365
+ nodrag = true;
366
+ } else if (item.field === 'operate' || newIndex === fullColumn.length - 1) {
367
+ nodrag = true;
368
+ msg = '操作列';
369
+ }
370
+ if (nodrag) {
371
+ // 错误的移动
372
+ const oldThElem = wrapperElem.children[oldIndex] as HTMLElement;
373
+ if (newIndex > oldIndex) {
374
+ wrapperElem.insertBefore(targetThElem, oldThElem);
375
+ } else {
376
+ wrapperElem.insertBefore(targetThElem, oldThElem ? oldThElem.nextElementSibling : oldThElem);
377
+ }
378
+ return errorMessage(msg + '不允许拖动!');
379
+ }
380
+ // 获取列索引 columnIndex > fullColumn
381
+ const oldColumnIndex = $grid.getColumnIndex(tableColumn[oldIndex]);
382
+ const newColumnIndex = $grid.getColumnIndex(tableColumn[newIndex]);
383
+ // 移动到目标列
384
+ const currRow = fullColumn.splice(oldColumnIndex, 1)[0];
385
+ fullColumn.splice(newColumnIndex, 0, currRow);
386
+
387
+ // 拖拽方向 1: 右 -1: 左
388
+ const direction = newColumnIndex - oldColumnIndex > 0 ? 1 : -1;
389
+
390
+ // 获取新列
391
+ const newSort = (newColumnIndex + 1) * 10;
392
+ const oldSort = (oldColumnIndex + 1) * 10;
393
+ // 目标列索引+1,方便后续计算
394
+ const comparisonVal = newSort + 1 * direction;
395
+ for (const key in cacheColumns) {
396
+ const cacheValue = cacheColumns[key];
397
+ if (direction > 0 && cacheValue < comparisonVal && cacheValue > oldSort) {
398
+ // 大于拖拽列且小于目标列的索引,均向前移动一个单位
399
+ cacheColumns[key] = cacheValue - 10 * direction;
400
+ } else if (direction < 0 && cacheValue > comparisonVal && cacheValue < oldSort) {
401
+ // 小于拖拽列且大于目标列的索引, 均向后移动一个单位
402
+ cacheColumns[key] = cacheValue - 10 * direction;
403
+ }
404
+ }
405
+
406
+ cacheColumns[currRow.field] = newSort;
407
+
408
+ dbstorage.setItem(kSTORECOLUM, { [attrs.gridId]: cacheColumns });
409
+ $grid.loadColumn(fullColumn);
410
+ }
411
+ });
412
+ };
413
+
414
+ /**
415
+ * @description 常用查询面板确认查询
416
+ * @param data 常用查询条件
417
+ */
418
+ // const onSearch = data => {
419
+ // showModal.value = false;
420
+ // const { form } = xgrid.value.getProxyInfo();
421
+ // Object.assign(form, data);
422
+ // refreshData();
423
+ // };
424
+
425
+ const reloadGrid = () => {
426
+ setGridConfig();
427
+ };
428
+
429
+ /**
430
+ * @description Vue实例对外暴露的相关方法或属性
431
+ */
432
+ defineExpose({
433
+ getTableData,
434
+ getSelectRecords,
435
+ refreshData,
436
+ refreshColumn,
437
+ getInstance,
438
+ showLoading,
439
+ hiddenLoading,
440
+ reloadGrid
441
+ });
442
+
443
+ const toolbarButtonClick = ({ code }) => {
444
+ emit('buttonClick', code);
445
+ };
446
+ const cellClick = e => {
447
+ emit('cellClick', e);
448
+ };
449
+ const cellDbclick = e => {
450
+ emit('cellDbclick', e);
451
+ };
452
+ const editEctivated = e => {
453
+ emit('editEctivated', e);
454
+ };
455
+
456
+ /**
457
+ * @description: 监听窗口变化,动态改变表格的高度
458
+ */
459
+ const addResizeListener = () => {
460
+ window.onresize = () => {
461
+ return (() => {
462
+ let height = attrs?.height || window.innerHeight - 90;
463
+ if (attrs.mode !== 'inline' && !attrs?.height) {
464
+ height = window.innerHeight - 180;
465
+ }
466
+ data.height = height < 240 ? 240 : height;
467
+ })();
468
+ };
469
+ };
470
+
471
+ let initTime: any;
472
+ nextTick(() => {
473
+ // 加载完成之后在绑定拖动事件
474
+ initTime = setTimeout(() => {
475
+ columnDrop();
476
+ }, 500);
477
+ });
478
+ /**
479
+ * @description Vue实例卸载
480
+ */
481
+ onUnmounted(() => {
482
+ clearTimeout(initTime);
483
+ sortable2 && sortable2.destroy();
484
+ });
485
+ /**
486
+ * @description Vue实例挂载
487
+ */
488
+ onBeforeMount(() => {
489
+ setGridConfig();
490
+ addResizeListener();
491
+ });
492
+
493
+ const emit = defineEmits<{
494
+ (e: 'buttonClick', code: string): void;
495
+ (e: 'cellClick', data: any): void;
496
+ (e: 'cellDbclick', data: any): void;
497
+ (e: 'editEctivated', data: any): void;
498
+ }>();
499
+ </script>
500
+
501
+ <style lang="scss">
502
+ .ut-grid-wrapper {
503
+ padding: 5px;
504
+ background-color: #fff;
505
+
506
+ .vxe-form--item {
507
+ padding: 0.1em 0.8em 0.1em 0 !important;
508
+
509
+ .el-select {
510
+ .el-input {
511
+ height: 26px;
512
+ }
513
+
514
+ .el-select__tags-text {
515
+ color: #000;
516
+ }
517
+ }
518
+ }
519
+
520
+ .vxe-grid--layout-body-content-wrapper {
521
+ overflow: hidden;
522
+ }
523
+ }
524
+ </style>