cloud-web-corejs 1.0.281 → 1.1.0-dev.4
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/package.json +6 -2
- package/src/components/VabUpload/image-viewer.vue +442 -442
- package/src/components/VabUpload/index.vue +44 -2
- package/src/components/VabUpload/mixins.js +126 -19
- package/src/components/VabUpload/view.vue +247 -209
- package/src/components/baseTabs/mixins.js +181 -181
- package/src/components/bizTab/BizBillActions.vue +129 -0
- package/src/components/bizTab/BizTabListPage.vue +391 -0
- package/src/components/bizTab/README.md +378 -0
- package/src/components/bizTab/billTableUtil.js +48 -0
- package/src/components/bizTab/billValidators.js +136 -0
- package/src/components/bizTab/bizBillDetailMixin.js +705 -0
- package/src/components/bizTab/index.js +24 -0
- package/src/components/excelExport/exportFieldDialog.vue +23 -12
- package/src/components/excelExport/exportItemConfigUtil.js +30 -0
- package/src/components/excelExport/mixins.js +3 -3
- package/src/components/mobile/statusTag/mixins.js +1 -61
- package/src/components/mobile/wf/content.vue +1662 -1556
- package/src/components/mobile/wf/mixins/wfModifyDialogMixin.js +8 -6
- package/src/components/table/config.js +78 -78
- package/src/components/table/index.js +1276 -1276
- package/src/components/table/plugins/cell-area/index.js +1055 -0
- package/src/components/table/plugins/cell-area/index.scss +77 -0
- package/src/components/table/plugins/cell-area/util.js +224 -0
- package/src/components/table/tableForm.vue +330 -330
- package/src/components/table/tableFormMixin.js +318 -318
- package/src/components/table/vxeFilter/index.js +163 -163
- package/src/components/table/vxeFilter/mixin.js +316 -316
- package/src/components/wf/content.vue +1188 -1188
- package/src/components/wf/wf.js +40 -20
- package/src/components/wf/wfActionDropdown.vue +1 -1
- package/src/components/wf/wfActionItems.js +1 -1
- package/src/components/xform/docs/2026-08 xform H5 P0 /345/256/236/347/216/260/350/247/204/346/240/274.md" +528 -0
- package/src/components/xform/docs/2026-08 xform H5 P1 /345/256/236/347/216/260/350/247/204/346/240/274.md" +412 -0
- package/src/components/xform/docs/2026-08 xform H5 P2 /345/256/236/347/216/260/350/247/204/346/240/274.md" +287 -0
- package/src/components/xform/docs/2026-08 xform /347/247/273/345/212/250/347/253/257/345/270/203/345/261/200/345/257/271/351/275/220 bill_setting /346/226/271/346/241/210.md" +400 -0
- package/src/components/xform/form-designer/designer.js +15 -0
- package/src/components/xform/form-designer/form-widget/container-widget/data-table-widget.vue +269 -269
- package/src/components/xform/form-designer/form-widget/container-widget/detail-temp-widget.vue +132 -0
- package/src/components/xform/form-designer/form-widget/container-widget/detail-widget.vue +250 -250
- package/src/components/xform/form-designer/form-widget/dialog/fileReferenceDialog.vue +319 -320
- package/src/components/xform/form-designer/form-widget/dialog/formDialog.vue +365 -365
- package/src/components/xform/form-designer/form-widget/dialog/searchFormDialog.vue +554 -555
- package/src/components/xform/form-designer/form-widget/dialog/vabSearchDialog.vue +409 -409
- package/src/components/xform/form-designer/form-widget/field-widget/a-link-widget.vue +150 -132
- package/src/components/xform/form-designer/form-widget/field-widget/date-range-widget.vue +114 -114
- package/src/components/xform/form-designer/form-widget/field-widget/date-widget.vue +154 -154
- package/src/components/xform/form-designer/form-widget/field-widget/form-item-wrapper.vue +47 -1
- package/src/components/xform/form-designer/form-widget/field-widget/mixins/date-limit-mixin.js +178 -178
- package/src/components/xform/form-designer/form-widget/field-widget/mixins/time-limit-mixin.js +77 -77
- package/src/components/xform/form-designer/form-widget/field-widget/select-export-item-button-widget.vue +6 -0
- package/src/components/xform/form-designer/form-widget/field-widget/select-widget.vue +139 -139
- package/src/components/xform/form-designer/form-widget/field-widget/time-range-widget.vue +106 -106
- package/src/components/xform/form-designer/form-widget/field-widget/time-widget.vue +134 -134
- package/src/components/xform/form-designer/form-widget/field-widget/vabUpload-widget.vue +1 -0
- package/src/components/xform/form-designer/setting-panel/form-setting.vue +39 -39
- package/src/components/xform/form-designer/setting-panel/property-editor/container-data-table/data-table-editor.vue +10 -10
- package/src/components/xform/form-designer/setting-panel/property-editor/container-data-table/exportItemColumns-dialog.vue +438 -432
- package/src/components/xform/form-designer/setting-panel/property-editor/container-data-table/table-column-dialog.vue +2103 -2103
- package/src/components/xform/form-designer/setting-panel/property-editor/container-detail/detail-temp-edito.vue +90 -0
- package/src/components/xform/form-designer/setting-panel/property-editor/container-grid/gutter-editor.vue +82 -82
- package/src/components/xform/form-designer/setting-panel/property-editor/container-list-h5/list-h5-editor.vue +19 -5
- package/src/components/xform/form-designer/setting-panel/property-editor/container-table/table-dynamicField-editor.vue +8 -8
- package/src/components/xform/form-designer/setting-panel/property-editor/dropdownFlag-editor.vue +137 -137
- package/src/components/xform/form-designer/setting-panel/property-editor/field-button/search-dialog-event-editor.vue +237 -237
- package/src/components/xform/form-designer/setting-panel/property-editor/field-date/date-defaultValue-editor.vue +43 -43
- package/src/components/xform/form-designer/setting-panel/property-editor/field-date-range/date-range-defaultValue-editor.vue +43 -43
- package/src/components/xform/form-designer/setting-panel/property-editor/field-import-button/import2-button-editor.vue +96 -96
- package/src/components/xform/form-designer/setting-panel/property-editor/field-table-export-button/select-export-item-button-editor.vue +51 -0
- package/src/components/xform/form-designer/setting-panel/property-editor/field-time/time-defaultValue-editor.vue +42 -42
- package/src/components/xform/form-designer/setting-panel/property-editor/field-time-range/time-range-defaultValue-editor.vue +43 -43
- package/src/components/xform/form-designer/setting-panel/property-editor/formScriptEnabled-editor.vue +158 -158
- package/src/components/xform/form-designer/setting-panel/property-editor/h5Span-editor.vue +51 -0
- package/src/components/xform/form-designer/setting-panel/property-editor/itemStyle-editor.vue +39 -0
- package/src/components/xform/form-designer/setting-panel/property-editor/name-editor.vue +188 -188
- package/src/components/xform/form-designer/setting-panel/property-editor/styleTempClass-editor.vue +51 -0
- package/src/components/xform/form-designer/setting-panel/property-editor/textFlag-editor.vue +347 -347
- package/src/components/xform/form-designer/setting-panel/propertyRegister.js +4 -0
- package/src/components/xform/form-designer/widget-panel/widgetsConfig.js +59 -3
- package/src/components/xform/form-render/container-item/data-table-mixin.js +151 -93
- package/src/components/xform/form-render/container-item/detail-h5-item.vue +183 -32
- package/src/components/xform/form-render/container-item/detail-temp-item.vue +110 -0
- package/src/components/xform/form-render/container-item/h5-card-pane-item.vue +160 -140
- package/src/components/xform/form-render/container-item/list-h5-item.vue +1688 -1700
- package/src/components/xform/form-render/index.vue +153 -147
- package/src/components/xform/form-render/indexMixin.js +12 -0
- package/src/components/xform/lang/en-US.js +10 -0
- package/src/components/xform/lang/zh-CN.js +12 -0
- package/src/components/xform/mixins/defaultHandle.js +707 -707
- package/src/components/xform/styles/h5.scss +1992 -0
- package/src/components/xform/utils/textMaskUtil.js +182 -179
- package/src/components/xform/utils/treeTableUtil.js +1292 -1265
- package/src/components/xform/utils/util.js +56 -11
- package/src/index.js +9 -4
- package/src/layout/components/extractedCode/viewDialog.vue +7 -7
- package/src/router/index.js +21 -0
- package/src/router/modules/customer.js +71 -14
- package/src/store/modules/permission.js +17 -18
- package/src/utils/pdfUtil.js +429 -429
- package/src/utils/resolveViewComponent.js +142 -16
- package/src/views/bd/project/branch/bd_branch/edit.vue +145 -0
- package/src/views/bd/project/branch/bd_branch/list.vue +72 -0
- package/src/views/bd/project/branch/bd_branch/menuKindDialog.vue +106 -0
- package/src/views/bd/project/branch/bd_branch/mixins/edit.js +189 -0
- package/src/views/bd/project/branch/bd_branch/mixins/list.js +124 -0
- package/src/views/bd/project/branch/bd_branch/mixins/menuKindDialog.js +85 -0
- package/src/views/bd/project/branch/form_script/list.vue +31 -0
- package/src/views/bd/project/branch/form_template/list.vue +30 -0
- package/src/views/bd/project/branch/menu_kind/list.vue +31 -0
- package/src/views/bd/project/common/form_script/list.vue +16 -0
- package/src/views/bd/project/common/form_template/list.vue +15 -0
- package/src/views/bd/project/common/menu_kind/list.vue +15 -0
- package/src/views/bd/project/core/branchContext.js +100 -0
- package/src/views/bd/project/core/branchPage.js +78 -0
- package/src/views/bd/project/core/branchPageWrap.vue +225 -0
- package/src/views/bd/project/core/branchScope.js +44 -0
- package/src/views/bd/project/core/branchSearchPage.js +285 -0
- package/src/views/bd/project/core/branchSelect.vue +85 -0
- package/src/views/bd/project/core/branchTreeBar.vue +81 -0
- package/src/views/bd/project/core/httpBranchPatch.js +58 -0
- package/src/views/bd/project/datatable/menu_kind/list.vue +15 -0
- package/src/views/bd/project/datatable/table_model/list.vue +15 -0
- package/src/views/bd/setting/bd_company_env/dialog.vue +174 -174
- package/src/views/bd/setting/table_model/edit.vue +1066 -1066
- package/src/views/bd/setting/table_model/mixins/edit.js +1455 -1455
- package/src/views/bd/setting/table_model/mixins/zdDialog.js +148 -148
- package/src/views/demo/bizTab/bill/billConfig.js +41 -0
- package/src/views/demo/bizTab/bill/detail.vue +436 -0
- package/src/views/demo/bizTab/bill/list.vue +288 -0
- package/src/views/demo/bizTab/bill/productDialog.vue +176 -0
- package/src/views/demo/bizTab/simple/billApi.js +123 -0
- package/src/views/demo/bizTab/simple/detail.vue +407 -0
- package/src/views/demo/bizTab/simple/list.vue +217 -0
- package/src/views/demo/bizTab/standalone/index.vue +121 -0
- package/src/views/demo/bizTab/wf/billConfig.js +44 -0
- package/src/views/demo/bizTab/wf/detail.vue +661 -0
- package/src/views/demo/bizTab/wf/list.vue +242 -0
- package/src/views/support/form-dialog-demo/demoPickerDialog.vue +72 -0
- package/src/views/support/form-dialog-demo/index.vue +537 -0
- package/src/views/user/file_view_ins/list.vue +3 -3
- package/src/views/user/home/index.vue +8 -6
- package/src/views/user/home/wjl/content.vue +1569 -0
- package/src/views/user/notify_message/dialog.vue +7 -5
- package/src/views/user/outLink/cc_form_view.vue +188 -0
- package/src/views/user/outLink/form_view.vue +2 -2
- package/src/views/user/outLink/index.vue +4 -4
- package/src/views/user/outLink/view.vue +3 -3
- package/src/views/user/role/edit.vue +632 -632
- package/src/views/user/role/list.vue +260 -260
- package/src/views/user/wf/iframe/index.vue +3 -3
- package/src/views/user/wf/iframe/index2.vue +3 -3
- package/src/views/user/wf/wf_manage/list.vue +1112 -1116
- package/src/views/user/wf/wf_manage/list2.vue +9 -13
- package/src/views/user/wf/wf_manage/wfContentDialog.vue +8 -5
- package/src/components/xform/form-designer/form-widget/field-widget/dropdown-menu-widget.vue +0 -106
- package/src/components/xform/form-designer/form-widget/field-widget/tableexportbuttonwidget.vue +0 -99
- package/src/components/xform/form-render/container-item/list-h5-item2.vue +0 -1340
- package/src/utils/wf.js +0 -766
|
@@ -1,1276 +1,1276 @@
|
|
|
1
|
-
/**version-1.0*/
|
|
2
|
-
let modules = {};
|
|
3
|
-
import Sortable from "sortablejs";
|
|
4
|
-
import tableConfig from "./config.js";
|
|
5
|
-
import customConfig from "./customConfig.js";
|
|
6
|
-
import Vue from "vue";
|
|
7
|
-
import { extendDeeply } from "../../utils/index.js";
|
|
8
|
-
import corejsConfig from "@/corejsConfig";
|
|
9
|
-
import settingConfig from "@/settings.js";
|
|
10
|
-
import { getCellValue, createParams } from "./util/index";
|
|
11
|
-
import { getTableStateValue, setTableState } from "./state";
|
|
12
|
-
|
|
13
|
-
let configUtil = {
|
|
14
|
-
Sortable,
|
|
15
|
-
extendDeeply,
|
|
16
|
-
tableConfig,
|
|
17
|
-
Vue,
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
function getGrid(that, tableRef) {
|
|
21
|
-
let $grid;
|
|
22
|
-
if (Array.isArray(that.$refs[tableRef])) {
|
|
23
|
-
$grid = that.$refs[tableRef][0];
|
|
24
|
-
} else {
|
|
25
|
-
$grid = that.$refs[tableRef];
|
|
26
|
-
}
|
|
27
|
-
return $grid;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** 是否在列子树中包含目标叶子列(同级 ref 优先,兜底 id) */
|
|
31
|
-
function columnSubtreeContainsLeaf(node, leaf) {
|
|
32
|
-
if (!node || !leaf) return false;
|
|
33
|
-
if (node === leaf) return true;
|
|
34
|
-
if (leaf.id && node.id && String(node.id) === String(leaf.id)) return true;
|
|
35
|
-
if (node.children && node.children.length) {
|
|
36
|
-
return node.children.some((child) =>
|
|
37
|
-
columnSubtreeContainsLeaf(child, leaf)
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/** leaf 所属的 collectColumn 最顶层节点的下标(-1 表示未找到) */
|
|
44
|
-
function collectTopRootIndex(collectColumn, leaf) {
|
|
45
|
-
if (!collectColumn || !collectColumn.length || !leaf) return -1;
|
|
46
|
-
return collectColumn.findIndex((root) =>
|
|
47
|
-
columnSubtreeContainsLeaf(root, leaf)
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async function initVxeTable(option) {
|
|
52
|
-
let tableName = option.tableName;
|
|
53
|
-
if (
|
|
54
|
-
!configUtil.tableConfig.disableTableName &&
|
|
55
|
-
option.tableNameRequired !== false &&
|
|
56
|
-
!tableName &&
|
|
57
|
-
settingConfig.tableStorageDisabled !== true
|
|
58
|
-
) {
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
let that = option.vue;
|
|
63
|
-
if (!that.$refs[option.tableRef]) {
|
|
64
|
-
await that.$nextTick();
|
|
65
|
-
}
|
|
66
|
-
let $grid = getGrid(that, option.tableRef);
|
|
67
|
-
if (!$grid) {
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
delete option.vue;
|
|
71
|
-
|
|
72
|
-
//操作列自动补全
|
|
73
|
-
handleCustomAlign(option);
|
|
74
|
-
|
|
75
|
-
initColumnIndex(option.columns);
|
|
76
|
-
|
|
77
|
-
let originOption = that.$baseLodash.cloneDeep(option);
|
|
78
|
-
originOption.vue = that;
|
|
79
|
-
$grid.originOption = originOption;
|
|
80
|
-
option.vue = that;
|
|
81
|
-
|
|
82
|
-
// 运行时状态先收集到局部对象,末尾并入 nOption.params 随 vxeOption 传给表格实例,
|
|
83
|
-
// 保证页面 v-if 销毁重建 grid 后状态不丢(详见 ./state.js)
|
|
84
|
-
let tableState = {
|
|
85
|
-
tableName: tableName || null,
|
|
86
|
-
isQueryAllPage: true,
|
|
87
|
-
exportColumns: null,
|
|
88
|
-
exportItemColumns: null,
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
let isQueryAllPage = true;
|
|
92
|
-
if (option.isQueryAllPage !== null && option.isQueryAllPage !== undefined) {
|
|
93
|
-
isQueryAllPage = option.isQueryAllPage;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
let searchColumns = null;
|
|
97
|
-
if (tableName) {
|
|
98
|
-
setTableState($grid, "tableName", tableName);
|
|
99
|
-
if (option.path) {
|
|
100
|
-
await getTableData(that, option.tableRef, "isQueryAllPage", (res1) => {
|
|
101
|
-
let result = res1.objx ? res1.objx.data : null;
|
|
102
|
-
if (result !== null && result !== undefined) {
|
|
103
|
-
if (result === "false" || result === false) {
|
|
104
|
-
isQueryAllPage = false;
|
|
105
|
-
} else {
|
|
106
|
-
isQueryAllPage = true;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
await getTableJson(tableName, that, (resultMsg) => {
|
|
112
|
-
let objx = resultMsg.objx;
|
|
113
|
-
if (objx !== null && objx !== undefined) {
|
|
114
|
-
let jsonStr = objx.data;
|
|
115
|
-
if (jsonStr) {
|
|
116
|
-
let json = JSON.parse(decodeURIComponent(jsonStr));
|
|
117
|
-
let columnData = json.columns ? json.columns : json;
|
|
118
|
-
if (columnData) {
|
|
119
|
-
option.columns = initColumn(option, columnData);
|
|
120
|
-
}
|
|
121
|
-
searchColumns = initSearchColumns(
|
|
122
|
-
option.searchColumns,
|
|
123
|
-
json.searchColumns
|
|
124
|
-
);
|
|
125
|
-
$grid.searchColumns = searchColumns;
|
|
126
|
-
initExportColumns($grid, tableState, json);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
if (!searchColumns || !searchColumns.length) {
|
|
130
|
-
searchColumns = initSearchColumns(option.searchColumns);
|
|
131
|
-
$grid.searchColumns = searchColumns;
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
} else {
|
|
135
|
-
searchColumns = initSearchColumns(option.searchColumns);
|
|
136
|
-
$grid.searchColumns = searchColumns;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (!!$grid?.$refs?.xTable) {
|
|
140
|
-
$grid.$refs.xTable.getCellValue = getCellValue;
|
|
141
|
-
$grid.$refs.xTable.createParams = createParams;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// $grid.getCellValue = getCellValue;
|
|
145
|
-
// $grid.createParams = createParams;
|
|
146
|
-
|
|
147
|
-
option.isQueryAllPage = isQueryAllPage;
|
|
148
|
-
let nOption = initOption(option);
|
|
149
|
-
|
|
150
|
-
// isQueryAllPage 的事实源是 $grid.params(checkQueryTotal 也写这里),
|
|
151
|
-
// pager 插槽与代理 ajax.query 均读它,初始化必须回写,
|
|
152
|
-
// 否则首屏恒为 undefined:既丢用户存的偏好,也让页面配置的 false 不生效。
|
|
153
|
-
tableState.isQueryAllPage = isQueryAllPage;
|
|
154
|
-
setTableState($grid, "isQueryAllPage", isQueryAllPage);
|
|
155
|
-
|
|
156
|
-
if (tableName) {
|
|
157
|
-
nOption.tableName = tableName;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
nOption.vue = that;
|
|
161
|
-
//绑定列位置拖拽
|
|
162
|
-
columnDrop(that, tableName, option.tableRef);
|
|
163
|
-
|
|
164
|
-
//自动绑定toobar
|
|
165
|
-
handleToolbar($grid, option);
|
|
166
|
-
|
|
167
|
-
// nOption.originOption = originOption;
|
|
168
|
-
// nOption.getCellValue = getCellValue;
|
|
169
|
-
// nOption.createParams = createParams;
|
|
170
|
-
// nOption.searchColumns = searchColumns;
|
|
171
|
-
// 运行时可变状态(tableName / isQueryAllPage / exportColumns / exportItemColumns)
|
|
172
|
-
// 一并放进 params:params 随 vxeOption 由页面持有,grid 被 v-if 销毁重建后依然带着这些值
|
|
173
|
-
let params = {
|
|
174
|
-
originOption,
|
|
175
|
-
getCellValue,
|
|
176
|
-
createParams,
|
|
177
|
-
searchColumns,
|
|
178
|
-
...tableState,
|
|
179
|
-
};
|
|
180
|
-
if (!nOption.params) nOption.params = {};
|
|
181
|
-
Object.assign(nOption.params, params);
|
|
182
|
-
return nOption;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
//自动绑定toobar
|
|
186
|
-
function handleToolbar($grid, option) {
|
|
187
|
-
let selfConfig = getSelfConfig();
|
|
188
|
-
if (
|
|
189
|
-
option.bindToolbar ||
|
|
190
|
-
(option.bindToolbar !== false && selfConfig.bindToolbar)
|
|
191
|
-
) {
|
|
192
|
-
let loopDo = function (children) {
|
|
193
|
-
if (children && children.length) {
|
|
194
|
-
children.forEach((item) => {
|
|
195
|
-
if (item.$options.name === "VxeToolbar") {
|
|
196
|
-
$grid.connect(item);
|
|
197
|
-
} else {
|
|
198
|
-
loopDo(item.$children);
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
$grid.$nextTick(() => {
|
|
204
|
-
loopDo($grid.$children);
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* grid 被 v-if 销毁重建后调用(页面把 showTable 从 false 切回 true 之类)。
|
|
211
|
-
*
|
|
212
|
-
* 状态类(tableName / isQueryAllPage / exportColumns…)已经随 params 跨重建存活,
|
|
213
|
-
* 这里只重做「绑在实例或 DOM 上、params 带不走」的那部分:
|
|
214
|
-
* - columnDrop:Sortable 绑的是旧表头 DOM,重建后新表头上什么都没有,列拖拽会静默失效;
|
|
215
|
-
* - handleToolbar:$grid.connect(toolbar) 是实例间的连接,重建后失联。
|
|
216
|
-
* 必须等新 grid 渲染出表头再绑,所以整体放在 $nextTick 里。
|
|
217
|
-
*/
|
|
218
|
-
function rebindGrid(that, tableRef) {
|
|
219
|
-
let $grid = getGrid(that, tableRef);
|
|
220
|
-
let originOption = $grid && $grid.params && $grid.params.originOption;
|
|
221
|
-
if (!originOption) {
|
|
222
|
-
// 没走过 initVxeTable 的表格没有 params.originOption,无从重绑
|
|
223
|
-
return Promise.resolve(false);
|
|
224
|
-
}
|
|
225
|
-
$grid.originOption = originOption;
|
|
226
|
-
// vxeFilter 已改为直接 import 工具函数,这里补挂只为兼容直接读 $table.getCellValue 的业务代码
|
|
227
|
-
if ($grid.$refs && $grid.$refs.xTable) {
|
|
228
|
-
$grid.$refs.xTable.getCellValue = getCellValue;
|
|
229
|
-
$grid.$refs.xTable.createParams = createParams;
|
|
230
|
-
}
|
|
231
|
-
return $grid.$nextTick().then(() => {
|
|
232
|
-
columnDrop(that, originOption.tableName, tableRef);
|
|
233
|
-
handleToolbar($grid, originOption);
|
|
234
|
-
return true;
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
//操作列自动补全
|
|
239
|
-
function handleCustomAlign(option) {
|
|
240
|
-
let selfConfig = getSelfConfig();
|
|
241
|
-
// let customAlign = option.customAlign || selfConfig.customAlign || "right";
|
|
242
|
-
let customAlign =
|
|
243
|
-
selfConfig.customAlign === false
|
|
244
|
-
? false
|
|
245
|
-
: selfConfig.customAlign || "right";
|
|
246
|
-
customAlign =
|
|
247
|
-
option.customAlign === false ? false : option.customAlign || customAlign;
|
|
248
|
-
|
|
249
|
-
let customColumnWidth =
|
|
250
|
-
option.customColumnWidth || selfConfig.customColumnWidth || 47;
|
|
251
|
-
let checkBoxColumnWidth =
|
|
252
|
-
option.checkBoxColumnWidth || selfConfig.checkBoxColumnWidth || 48;
|
|
253
|
-
|
|
254
|
-
let checkBoxRequired = selfConfig.checkBoxRequired !== false;
|
|
255
|
-
if (option.checkBoxRequired === false) {
|
|
256
|
-
checkBoxRequired = false;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
let columnSize = option.columns.length;
|
|
260
|
-
if (columnSize > 0) {
|
|
261
|
-
if (checkBoxRequired) {
|
|
262
|
-
let firstColumn = option.columns[0];
|
|
263
|
-
if (firstColumn.type !== "checkbox") {
|
|
264
|
-
option.columns.splice(0, 0, {
|
|
265
|
-
type: "checkbox",
|
|
266
|
-
width: checkBoxColumnWidth,
|
|
267
|
-
resizable: false,
|
|
268
|
-
fixed: "left",
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
if (customAlign !== false) {
|
|
273
|
-
let lastColumn = option.columns[columnSize - 1];
|
|
274
|
-
if (customAlign === "left") {
|
|
275
|
-
if (!lastColumn.field && lastColumn.fixed === "right") {
|
|
276
|
-
option.columns.splice(columnSize - 1, 1);
|
|
277
|
-
lastColumn.fixed = "left";
|
|
278
|
-
option.columns.splice(1, 0, lastColumn);
|
|
279
|
-
} else if (columnSize > 1) {
|
|
280
|
-
if (option.columns[1].field) {
|
|
281
|
-
option.columns.splice(1, 0, {
|
|
282
|
-
width: customColumnWidth,
|
|
283
|
-
fixed: "left",
|
|
284
|
-
title: "",
|
|
285
|
-
sortable: false,
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
} else if (customAlign === "right") {
|
|
290
|
-
let column1 = option.columns[1];
|
|
291
|
-
if (!column1.field && column1.fixed === "left") {
|
|
292
|
-
option.columns.splice(1, 1);
|
|
293
|
-
column1.fixed = "right";
|
|
294
|
-
option.columns.push(column1);
|
|
295
|
-
} else if (lastColumn.field || lastColumn.fixed !== "right") {
|
|
296
|
-
option.columns.push({
|
|
297
|
-
width: customColumnWidth,
|
|
298
|
-
fixed: "right",
|
|
299
|
-
title: "",
|
|
300
|
-
sortable: false,
|
|
301
|
-
});
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
//列位置拖拽
|
|
309
|
-
function columnDrop(t, tableName, tableRef) {
|
|
310
|
-
let that = t;
|
|
311
|
-
const $table = getGrid(that, tableRef);
|
|
312
|
-
if (!$table) {
|
|
313
|
-
return;
|
|
314
|
-
}
|
|
315
|
-
// 表头尚未渲染(grid 刚被 v-if 重建、DOM 还没就绪)时 querySelector 返回 null,
|
|
316
|
-
// Sortable.create(null) 会直接抛错,这里降级为不绑定,由调用方在 $nextTick 后重试
|
|
317
|
-
const headerElem =
|
|
318
|
-
$table.$el &&
|
|
319
|
-
$table.$el.querySelector(
|
|
320
|
-
".body--wrapper>.vxe-table--header .vxe-header--row"
|
|
321
|
-
);
|
|
322
|
-
if (!headerElem) {
|
|
323
|
-
return;
|
|
324
|
-
}
|
|
325
|
-
// if (!$table.params) $table.params = {};
|
|
326
|
-
if ($table.sortable) {
|
|
327
|
-
$table.sortable.destroy();
|
|
328
|
-
$table.sortable = null;
|
|
329
|
-
}
|
|
330
|
-
let dragStartIndex = -1;
|
|
331
|
-
let dragEndIndex = -1;
|
|
332
|
-
$table.sortable = configUtil.Sortable.create(
|
|
333
|
-
headerElem,
|
|
334
|
-
{
|
|
335
|
-
handle: ".vxe-header--column:not(.col--fixed)",
|
|
336
|
-
onMove: (a, b, c) => {
|
|
337
|
-
let { dragged, related } = a;
|
|
338
|
-
// dragStartIndex = getElementIndex(dragged);
|
|
339
|
-
// dragEndIndex = getElementIndex(related);
|
|
340
|
-
|
|
341
|
-
let tableColumn = $table.getTableColumn().tableColumn;
|
|
342
|
-
let draggedColId = dragged.getAttribute("colid");
|
|
343
|
-
let relatedColId = related.getAttribute("colid");
|
|
344
|
-
dragStartIndex = tableColumn.findIndex(
|
|
345
|
-
(item) => item.id === draggedColId
|
|
346
|
-
);
|
|
347
|
-
dragEndIndex = tableColumn.findIndex(
|
|
348
|
-
(item) => item.id === relatedColId
|
|
349
|
-
);
|
|
350
|
-
},
|
|
351
|
-
onEnd: (dropParam) => {
|
|
352
|
-
let { item } = dropParam;
|
|
353
|
-
let oldIndex = dragStartIndex;
|
|
354
|
-
let newIndex = dragEndIndex;
|
|
355
|
-
|
|
356
|
-
// Sortable 原地放下时可能不触发 onMove,索引需从 dropParam 兜底
|
|
357
|
-
if (oldIndex < 0) oldIndex = dropParam.oldIndex;
|
|
358
|
-
if (newIndex < 0) newIndex = dropParam.newIndex;
|
|
359
|
-
const { fullColumn, tableColumn, collectColumn } =
|
|
360
|
-
$table.getTableColumn();
|
|
361
|
-
const targetThElem = item;
|
|
362
|
-
const wrapperElem = targetThElem.parentNode;
|
|
363
|
-
let oldColumn = tableColumn[oldIndex];
|
|
364
|
-
const newColumn = tableColumn[newIndex];
|
|
365
|
-
if (!oldColumn || !newColumn) return;
|
|
366
|
-
if (newColumn.fixed) {
|
|
367
|
-
// 错误的移动
|
|
368
|
-
if (newIndex > oldIndex) {
|
|
369
|
-
wrapperElem.insertBefore(
|
|
370
|
-
targetThElem,
|
|
371
|
-
wrapperElem.children[oldIndex]
|
|
372
|
-
);
|
|
373
|
-
} else {
|
|
374
|
-
wrapperElem.insertBefore(
|
|
375
|
-
wrapperElem.children[oldIndex],
|
|
376
|
-
targetThElem
|
|
377
|
-
);
|
|
378
|
-
}
|
|
379
|
-
return;
|
|
380
|
-
/* return that.$XModal.message({
|
|
381
|
-
content: '固定列不允许拖动!',
|
|
382
|
-
status: 'error'
|
|
383
|
-
}) */
|
|
384
|
-
}
|
|
385
|
-
// 叶子在 fullColumn 中的下标,与 collectColumn 顶层结构的下标不能直接混用
|
|
386
|
-
const oldColumnIndex = fullColumn.findIndex(
|
|
387
|
-
(item) => item.id === oldColumn.id
|
|
388
|
-
);
|
|
389
|
-
const newColumnIndex = fullColumn.findIndex(
|
|
390
|
-
(item) => item.id === newColumn.id
|
|
391
|
-
);
|
|
392
|
-
const oldLeafColumn = fullColumn[oldColumnIndex];
|
|
393
|
-
const newLeafColumn = fullColumn[newColumnIndex];
|
|
394
|
-
if (oldColumnIndex === newColumnIndex) {
|
|
395
|
-
return;
|
|
396
|
-
}
|
|
397
|
-
const oldTopIdx = collectTopRootIndex(collectColumn, oldLeafColumn);
|
|
398
|
-
const newTopIdx = collectTopRootIndex(collectColumn, newLeafColumn);
|
|
399
|
-
if (oldTopIdx === -1 || newTopIdx === -1) {
|
|
400
|
-
return;
|
|
401
|
-
}
|
|
402
|
-
if (oldTopIdx !== newTopIdx) {
|
|
403
|
-
const currRow = collectColumn.splice(oldTopIdx, 1)[0];
|
|
404
|
-
collectColumn.splice(newTopIdx, 0, currRow);
|
|
405
|
-
$table.loadColumn(collectColumn);
|
|
406
|
-
addTableJson(that, $table, tableName, collectColumn);
|
|
407
|
-
}
|
|
408
|
-
},
|
|
409
|
-
}
|
|
410
|
-
);
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
function getSelfConfig() {
|
|
414
|
-
let tableConfig = configUtil.tableConfig || {};
|
|
415
|
-
let selfConfig = tableConfig.selfConfig || {};
|
|
416
|
-
return selfConfig;
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
function applyTableFeatureDisabled(result, that) {
|
|
420
|
-
let userState = that?.$store?.state?.user || {};
|
|
421
|
-
let sortDisabled = userState.tableSortDisabled === true;
|
|
422
|
-
let filterDisabled = userState.tableFilterDisabled === true;
|
|
423
|
-
if (!sortDisabled && !filterDisabled) return;
|
|
424
|
-
|
|
425
|
-
let handleColumns = (columns) => {
|
|
426
|
-
(columns || []).forEach((column) => {
|
|
427
|
-
if (sortDisabled) {
|
|
428
|
-
column.sortable = false;
|
|
429
|
-
}
|
|
430
|
-
if (filterDisabled) {
|
|
431
|
-
column.filterType = false;
|
|
432
|
-
delete column.filters;
|
|
433
|
-
delete column.filterRender;
|
|
434
|
-
delete column.filterMethod;
|
|
435
|
-
}
|
|
436
|
-
if (column.children && column.children.length) {
|
|
437
|
-
handleColumns(column.children);
|
|
438
|
-
}
|
|
439
|
-
});
|
|
440
|
-
};
|
|
441
|
-
|
|
442
|
-
handleColumns(result.columns);
|
|
443
|
-
if (sortDisabled) {
|
|
444
|
-
if (result.proxyConfig) result.proxyConfig.sort = false;
|
|
445
|
-
if (result.sortConfig) {
|
|
446
|
-
result.sortConfig.showIcon = false;
|
|
447
|
-
delete result.sortConfig.defaultSort;
|
|
448
|
-
delete result.sortConfig.sortMethod;
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
if (filterDisabled) {
|
|
452
|
-
if (result.proxyConfig) result.proxyConfig.filter = false;
|
|
453
|
-
if (result.filterConfig) result.filterConfig.showIcon = false;
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
function initColumnDefaulAttrs(columns, opts) {
|
|
458
|
-
let tableConfig = configUtil.tableConfig || {};
|
|
459
|
-
let selfConfig = getSelfConfig();
|
|
460
|
-
let lockCheckboxWidth =
|
|
461
|
-
opts.lockCheckboxWidth !== false
|
|
462
|
-
? opts.lockCheckboxWidth || selfConfig.lockCheckboxWidth
|
|
463
|
-
: null;
|
|
464
|
-
let filterType =
|
|
465
|
-
opts.filterType !== false && !opts.treeNodeUrl
|
|
466
|
-
? opts.filterType || selfConfig.filterType || "filterContent"
|
|
467
|
-
: null;
|
|
468
|
-
let sortAll =
|
|
469
|
-
opts.sortAll === true || (opts.sortAll !== false && !opts.treeNodeUrl);
|
|
470
|
-
|
|
471
|
-
columns.forEach((column) => {
|
|
472
|
-
// 只有最底层的列(没有 children)才设置默认属性
|
|
473
|
-
if (!column.children || column.children.length === 0) {
|
|
474
|
-
// 设置 sortable
|
|
475
|
-
if (
|
|
476
|
-
sortAll &&
|
|
477
|
-
column.title &&
|
|
478
|
-
(column.sortable === null || column.sortable === undefined)
|
|
479
|
-
) {
|
|
480
|
-
column.sortable = true;
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
// 设置过滤器
|
|
484
|
-
if (filterType && column.title && column.field) {
|
|
485
|
-
if (
|
|
486
|
-
column.filterType === "filterContent" ||
|
|
487
|
-
((column.filterType === null || column.filterType === undefined) &&
|
|
488
|
-
filterType === "filterContent")
|
|
489
|
-
) {
|
|
490
|
-
if (!column.filters) {
|
|
491
|
-
column.filters = [
|
|
492
|
-
{
|
|
493
|
-
data: {},
|
|
494
|
-
},
|
|
495
|
-
];
|
|
496
|
-
}
|
|
497
|
-
if (!column.filterRender) {
|
|
498
|
-
column.filterRender = {
|
|
499
|
-
name: "FilterContent",
|
|
500
|
-
};
|
|
501
|
-
}
|
|
502
|
-
} else if (
|
|
503
|
-
column.filterType === "filterInput" ||
|
|
504
|
-
((column.filterType === null || column.filterType === undefined) &&
|
|
505
|
-
filterType === "filterInput")
|
|
506
|
-
) {
|
|
507
|
-
if (!column.filters) {
|
|
508
|
-
column.filters = [
|
|
509
|
-
{
|
|
510
|
-
data: "",
|
|
511
|
-
},
|
|
512
|
-
];
|
|
513
|
-
}
|
|
514
|
-
if (!column.filterRender) {
|
|
515
|
-
column.filterRender = {
|
|
516
|
-
name: "FilterInput",
|
|
517
|
-
};
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
// 设置复选框列宽度
|
|
523
|
-
if (lockCheckboxWidth && column.type === "checkbox") {
|
|
524
|
-
column.width = lockCheckboxWidth;
|
|
525
|
-
}
|
|
526
|
-
} else {
|
|
527
|
-
column.sortable = false;
|
|
528
|
-
column.filterType = false;
|
|
529
|
-
column.align = "center";
|
|
530
|
-
column.resizable = false;
|
|
531
|
-
// 递归处理 children
|
|
532
|
-
initColumnDefaulAttrs(column.children, opts);
|
|
533
|
-
}
|
|
534
|
-
});
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
function initOption(opts) {
|
|
538
|
-
let result = {};
|
|
539
|
-
let that = opts.vue;
|
|
540
|
-
let $grid = getGrid(that, opts.tableRef);
|
|
541
|
-
|
|
542
|
-
let path = opts.path || "";
|
|
543
|
-
// let columns = JSON.parse(JSON.stringify(opts.columns || []));
|
|
544
|
-
let columns = opts.columns || [];
|
|
545
|
-
let pagerLayouts = getPagerConfigLayouts(opts);
|
|
546
|
-
|
|
547
|
-
let config = opts.config || {};
|
|
548
|
-
|
|
549
|
-
initColumnDefaulAttrs(columns, opts);
|
|
550
|
-
|
|
551
|
-
let defaultOptions = {
|
|
552
|
-
columnKey: true,
|
|
553
|
-
resizable: true,
|
|
554
|
-
showOverflow: true,
|
|
555
|
-
showHeaderOverflow: true,
|
|
556
|
-
showFooterOverflow: true,
|
|
557
|
-
highlightHoverRow: true,
|
|
558
|
-
border: "inner",
|
|
559
|
-
height: "auto",
|
|
560
|
-
// maxHeight:"1000px",
|
|
561
|
-
// rowId: 'id',
|
|
562
|
-
emptyText: " ",
|
|
563
|
-
sortConfig: {
|
|
564
|
-
trigger: "cell",
|
|
565
|
-
remote: false,
|
|
566
|
-
},
|
|
567
|
-
filterConfig: {
|
|
568
|
-
remote: false,
|
|
569
|
-
},
|
|
570
|
-
pagerConfig: {
|
|
571
|
-
autoHidden: true,
|
|
572
|
-
perfect: true,
|
|
573
|
-
pageSize: 200,
|
|
574
|
-
pageSizes: [50, 100, 200, 500],
|
|
575
|
-
layouts: pagerLayouts,
|
|
576
|
-
slots: {
|
|
577
|
-
left: (obj, b, c) => {
|
|
578
|
-
let $grid = obj.$grid;
|
|
579
|
-
let k = $grid.$data;
|
|
580
|
-
let tableDataInfo = $grid.getTableData();
|
|
581
|
-
let data = tableDataInfo.fullData;
|
|
582
|
-
let h = $grid.$createElement;
|
|
583
|
-
|
|
584
|
-
let proxyInfo = $grid.getProxyInfo();
|
|
585
|
-
let pager = proxyInfo ? proxyInfo.pager : null;
|
|
586
|
-
|
|
587
|
-
let celems = [
|
|
588
|
-
h("span", $grid.$t2("本页记录数", "components.table.currentNum")),
|
|
589
|
-
h(
|
|
590
|
-
"span",
|
|
591
|
-
{
|
|
592
|
-
attrs: {
|
|
593
|
-
class: "f-red",
|
|
594
|
-
},
|
|
595
|
-
},
|
|
596
|
-
" " + tableDataInfo.visibleData.length + " "
|
|
597
|
-
),
|
|
598
|
-
];
|
|
599
|
-
if (pager && getTableStateValue($grid, "isQueryAllPage")) {
|
|
600
|
-
celems.push(
|
|
601
|
-
h(
|
|
602
|
-
"span",
|
|
603
|
-
"," + $grid.$t2("总记录数", "components.table.totalNum")
|
|
604
|
-
)
|
|
605
|
-
);
|
|
606
|
-
celems.push(
|
|
607
|
-
h(
|
|
608
|
-
"span",
|
|
609
|
-
{
|
|
610
|
-
attrs: {
|
|
611
|
-
class: "f-red",
|
|
612
|
-
},
|
|
613
|
-
},
|
|
614
|
-
" " + pager.total + " "
|
|
615
|
-
)
|
|
616
|
-
);
|
|
617
|
-
}
|
|
618
|
-
let elem = h("span", {}, celems);
|
|
619
|
-
return [elem];
|
|
620
|
-
},
|
|
621
|
-
},
|
|
622
|
-
},
|
|
623
|
-
exportConfig: {
|
|
624
|
-
// 默认选中类型
|
|
625
|
-
type: "xlsx",
|
|
626
|
-
// 局部自定义类型
|
|
627
|
-
types: ["xlsx", "csv", "html", "xml", "txt"],
|
|
628
|
-
// 仅保留当前页:mode=all 依赖的 queryAll 无鉴权实现,从未可用;全量导出请走 $excelExport
|
|
629
|
-
modes: ["current"],
|
|
630
|
-
// 与 $excelExport 一致地剔除非数据列与脱敏列,避免绕开 $excelExport 导出明文
|
|
631
|
-
columnFilterMethod({ column }) {
|
|
632
|
-
return !column.params?.exportDisabled;
|
|
633
|
-
},
|
|
634
|
-
},
|
|
635
|
-
radioConfig: {
|
|
636
|
-
labelField: "id",
|
|
637
|
-
reserve: true,
|
|
638
|
-
highlight: true,
|
|
639
|
-
},
|
|
640
|
-
checkboxConfig: {
|
|
641
|
-
highlight: true,
|
|
642
|
-
},
|
|
643
|
-
customConfig: {
|
|
644
|
-
storage: false,
|
|
645
|
-
},
|
|
646
|
-
scrollX: {
|
|
647
|
-
// enabled: true,
|
|
648
|
-
gt: 10,
|
|
649
|
-
// oSize: 5
|
|
650
|
-
},
|
|
651
|
-
/*loadingConfig: {
|
|
652
|
-
icon: "vxe-loading--spinner",
|
|
653
|
-
text: ' '
|
|
654
|
-
},*/
|
|
655
|
-
columns: columns,
|
|
656
|
-
};
|
|
657
|
-
let tableDefaultConfig =
|
|
658
|
-
corejsConfig?.componentConfig?.table?.defaultConfig || {};
|
|
659
|
-
defaultOptions = configUtil.extendDeeply(defaultOptions, tableConfig);
|
|
660
|
-
defaultOptions = configUtil.extendDeeply(defaultOptions, customConfig);
|
|
661
|
-
defaultOptions = configUtil.extendDeeply(defaultOptions, tableDefaultConfig);
|
|
662
|
-
|
|
663
|
-
if (opts.path) {
|
|
664
|
-
// defaultOptions.filterInput = true;
|
|
665
|
-
defaultOptions.pagerConfig.autoHidden = false;
|
|
666
|
-
defaultOptions.proxyConfig = {
|
|
667
|
-
seq: true, // 启用动态序号代理
|
|
668
|
-
sort: true, // 启用排序代理
|
|
669
|
-
filter: true, // 启用筛选代理
|
|
670
|
-
props: {
|
|
671
|
-
result: "objx.records", // 配置响应结果列表字段
|
|
672
|
-
total: "objx.total", // 配置响应结果总页数字段
|
|
673
|
-
},
|
|
674
|
-
ajax: {
|
|
675
|
-
// 接收 Promise 对象
|
|
676
|
-
query: ({ page, sorts, filters, form }) => {
|
|
677
|
-
if (!opts.path) {
|
|
678
|
-
return;
|
|
679
|
-
}
|
|
680
|
-
return new Promise((resolve, reject) => {
|
|
681
|
-
let toDo = () => {
|
|
682
|
-
let formData = opts.param ? opts.param() || {} : {};
|
|
683
|
-
const queryParams = Object.assign({}, formData);
|
|
684
|
-
|
|
685
|
-
// 处理排序条件
|
|
686
|
-
/*const firstSort = sorts[0];
|
|
687
|
-
if (firstSort) {
|
|
688
|
-
queryParams.sort = firstSort.property;
|
|
689
|
-
queryParams.order = firstSort.order;
|
|
690
|
-
}*/
|
|
691
|
-
// 处理筛选条件
|
|
692
|
-
filters.forEach(({ property, values }) => {
|
|
693
|
-
queryParams[property] = values.join(",");
|
|
694
|
-
});
|
|
695
|
-
if (page.pageSize !== undefined) {
|
|
696
|
-
queryParams["size"] = page.pageSize;
|
|
697
|
-
queryParams["current"] = page.currentPage;
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
let $grid = getGrid(that, opts.tableRef);
|
|
701
|
-
let isQueryAllPage = getTableStateValue($grid, "isQueryAllPage");
|
|
702
|
-
let pathStr1 = "";
|
|
703
|
-
if (isQueryAllPage === false) {
|
|
704
|
-
queryParams.searchCount = false;
|
|
705
|
-
}
|
|
706
|
-
|
|
707
|
-
let reqPath = typeof path === "function" ? path() : path;
|
|
708
|
-
let addUserForTableEnabled =
|
|
709
|
-
settingConfig.addUserForTableDisabled !== true;
|
|
710
|
-
let addCreateInfo =
|
|
711
|
-
opts.addCreateInfo === true || addUserForTableEnabled;
|
|
712
|
-
let queryCreateInfo =
|
|
713
|
-
opts.queryCreateInfo === true || addUserForTableEnabled;
|
|
714
|
-
let reqData = queryParams;
|
|
715
|
-
if (opts.paramHandle) {
|
|
716
|
-
reqData = opts.paramHandle
|
|
717
|
-
? opts.paramHandle(queryParams) || {}
|
|
718
|
-
: {};
|
|
719
|
-
}
|
|
720
|
-
that.$commonHttp({
|
|
721
|
-
aes: opts.aes || false,
|
|
722
|
-
url: reqPath,
|
|
723
|
-
method: "post",
|
|
724
|
-
data: reqData,
|
|
725
|
-
addCreateInfo: addCreateInfo,
|
|
726
|
-
queryCreateInfo: queryCreateInfo,
|
|
727
|
-
callback: (res) => {
|
|
728
|
-
resolve(res);
|
|
729
|
-
if (res.type === "success") {
|
|
730
|
-
let rows = res.objx
|
|
731
|
-
? res.objx.records || res.objx || []
|
|
732
|
-
: [];
|
|
733
|
-
if (opts.treeNodeUrl) {
|
|
734
|
-
if (rows.length > 0) {
|
|
735
|
-
let $t = getGrid(that, opts.tableRef);
|
|
736
|
-
let treeConditions = $t.params.originOption
|
|
737
|
-
.treeConditions || ["enabled"];
|
|
738
|
-
let treeFiled = Object.keys(formData).some((key) => {
|
|
739
|
-
return (
|
|
740
|
-
!treeConditions.includes(key) &&
|
|
741
|
-
formData[key] !== null &&
|
|
742
|
-
formData[key] !== undefined &&
|
|
743
|
-
formData[key] !== ""
|
|
744
|
-
);
|
|
745
|
-
});
|
|
746
|
-
if (treeFiled) {
|
|
747
|
-
that.$nextTick(() => {
|
|
748
|
-
setTimeout(function () {
|
|
749
|
-
let isLazy = $t.treeConfig.lazy;
|
|
750
|
-
$t.treeConfig.lazy = false;
|
|
751
|
-
$t.setAllTreeExpand(true).then(() => {
|
|
752
|
-
let fullAllDataRowMap =
|
|
753
|
-
$t.$refs.xTable.fullAllDataRowMap;
|
|
754
|
-
let fullData = $t.getTableData().fullData;
|
|
755
|
-
fullData.forEach((lineData) => {
|
|
756
|
-
if (
|
|
757
|
-
$t.$refs.xTable.isTreeExpandByRow(lineData)
|
|
758
|
-
) {
|
|
759
|
-
let rest = fullAllDataRowMap.get(lineData);
|
|
760
|
-
rest.treeLoaded = true;
|
|
761
|
-
}
|
|
762
|
-
});
|
|
763
|
-
$t.treeConfig.lazy = isLazy;
|
|
764
|
-
});
|
|
765
|
-
}, 0);
|
|
766
|
-
});
|
|
767
|
-
} else {
|
|
768
|
-
let row = rows[0];
|
|
769
|
-
if (row[$t.treeConfig.hasChild]) {
|
|
770
|
-
that.$nextTick(() => {
|
|
771
|
-
setTimeout(function () {
|
|
772
|
-
$t.setTreeExpand(row, true);
|
|
773
|
-
}, 0);
|
|
774
|
-
});
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
}
|
|
779
|
-
if (opts.callback) {
|
|
780
|
-
that.$nextTick(() => {
|
|
781
|
-
setTimeout(function () {
|
|
782
|
-
opts.callback(rows, res);
|
|
783
|
-
}, 0);
|
|
784
|
-
});
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
},
|
|
788
|
-
error: (error) => {
|
|
789
|
-
reject(error);
|
|
790
|
-
},
|
|
791
|
-
});
|
|
792
|
-
};
|
|
793
|
-
let index = 0;
|
|
794
|
-
let loopHandle = () => {
|
|
795
|
-
if (index < 500 && $grid.tableFormStop === true) {
|
|
796
|
-
//阻塞列表查询,或者次数达到500时,自动释放
|
|
797
|
-
index++;
|
|
798
|
-
setTimeout(() => {
|
|
799
|
-
loopHandle();
|
|
800
|
-
}, 10);
|
|
801
|
-
} else {
|
|
802
|
-
if ($grid.tableFormStop) $grid.tableFormStop = false;
|
|
803
|
-
toDo();
|
|
804
|
-
}
|
|
805
|
-
};
|
|
806
|
-
loopHandle();
|
|
807
|
-
});
|
|
808
|
-
},
|
|
809
|
-
},
|
|
810
|
-
};
|
|
811
|
-
/*defaultOptions.scrollX = {
|
|
812
|
-
enabled: true,
|
|
813
|
-
gt: 20
|
|
814
|
-
};*/
|
|
815
|
-
defaultOptions.scrollY = {
|
|
816
|
-
// enabled: false,
|
|
817
|
-
gt: 20,
|
|
818
|
-
oSize: 20,
|
|
819
|
-
};
|
|
820
|
-
} else {
|
|
821
|
-
if (!$grid.height && (!opts.config || !opts.config.height)) {
|
|
822
|
-
defaultOptions.maxHeight = "528px";
|
|
823
|
-
}
|
|
824
|
-
defaultOptions.scrollY = {
|
|
825
|
-
// enabled: false,
|
|
826
|
-
gt: 20,
|
|
827
|
-
oSize: 20,
|
|
828
|
-
};
|
|
829
|
-
}
|
|
830
|
-
|
|
831
|
-
if (opts.editSaveUrl) {
|
|
832
|
-
(defaultOptions.keepSource = true),
|
|
833
|
-
(defaultOptions.editConfig = {
|
|
834
|
-
trigger: "manual",
|
|
835
|
-
mode: "row",
|
|
836
|
-
showStatus: true,
|
|
837
|
-
autoClear: false,
|
|
838
|
-
});
|
|
839
|
-
}
|
|
840
|
-
if (opts.treeNodeUrl) {
|
|
841
|
-
defaultOptions.proxyConfig.props.result = "objx";
|
|
842
|
-
defaultOptions.pagerConfig.autoHidden = true;
|
|
843
|
-
defaultOptions.treeConfig = {
|
|
844
|
-
lazy: true,
|
|
845
|
-
children: "children",
|
|
846
|
-
hasChild: "hasChild", // 设置是否有子节点标识
|
|
847
|
-
parentField: "parent",
|
|
848
|
-
transform: true,
|
|
849
|
-
loadMethod({ $table, row }) {
|
|
850
|
-
// 模拟后台接口
|
|
851
|
-
return new Promise((resolve, reject) => {
|
|
852
|
-
let treeNodeParam = opts.treeNodeParam
|
|
853
|
-
? opts.treeNodeParam(row) || {}
|
|
854
|
-
: {
|
|
855
|
-
parent: row.id,
|
|
856
|
-
};
|
|
857
|
-
that.$http({
|
|
858
|
-
aes: opts.aes || false,
|
|
859
|
-
url: opts.treeNodeUrl,
|
|
860
|
-
method: "post",
|
|
861
|
-
data: treeNodeParam,
|
|
862
|
-
callback: (res) => {
|
|
863
|
-
if (res.type === "success") {
|
|
864
|
-
// let rows = res.objx || [];
|
|
865
|
-
let rows = res.objx ? res.objx.records || res.objx || [] : [];
|
|
866
|
-
let hasChildField = $grid.treeConfig.hasChild;
|
|
867
|
-
if (row[hasChildField] && !rows.length) {
|
|
868
|
-
row[hasChildField] = false;
|
|
869
|
-
}
|
|
870
|
-
resolve(rows);
|
|
871
|
-
if (opts.treeCallback) {
|
|
872
|
-
that.$nextTick(() => {
|
|
873
|
-
setTimeout(function () {
|
|
874
|
-
opts.treeCallback(rows, res);
|
|
875
|
-
}, 0);
|
|
876
|
-
});
|
|
877
|
-
}
|
|
878
|
-
} else {
|
|
879
|
-
reject(res);
|
|
880
|
-
}
|
|
881
|
-
},
|
|
882
|
-
});
|
|
883
|
-
});
|
|
884
|
-
},
|
|
885
|
-
};
|
|
886
|
-
}
|
|
887
|
-
|
|
888
|
-
result = configUtil.extendDeeply(defaultOptions, config);
|
|
889
|
-
applyTableFeatureDisabled(result, that);
|
|
890
|
-
|
|
891
|
-
let pageSize = result.pagerConfig.pageSize;
|
|
892
|
-
let pageSizes = result.pagerConfig.pageSizes;
|
|
893
|
-
if (pageSizes && !pageSizes.includes(pageSize)) {
|
|
894
|
-
for (let i = 0; i < pageSizes.length; i++) {
|
|
895
|
-
let item = pageSizes[i];
|
|
896
|
-
if (item > pageSize) {
|
|
897
|
-
pageSizes.splice(i, 0, pageSize);
|
|
898
|
-
break;
|
|
899
|
-
}
|
|
900
|
-
}
|
|
901
|
-
}
|
|
902
|
-
|
|
903
|
-
return result;
|
|
904
|
-
}
|
|
905
|
-
|
|
906
|
-
function getTableJson(tableName, that, success) {
|
|
907
|
-
if (
|
|
908
|
-
configUtil.tableConfig.disableTableName ||
|
|
909
|
-
settingConfig.tableStorageDisabled
|
|
910
|
-
)
|
|
911
|
-
return false;
|
|
912
|
-
if (!tableName) return;
|
|
913
|
-
let url = USER_PREFIX + "/table_column/getTableJson";
|
|
914
|
-
let data = {
|
|
915
|
-
tableName: tableName,
|
|
916
|
-
};
|
|
917
|
-
let json = null;
|
|
918
|
-
return that.$http({
|
|
919
|
-
url: url,
|
|
920
|
-
method: "post",
|
|
921
|
-
data: data,
|
|
922
|
-
success: success,
|
|
923
|
-
});
|
|
924
|
-
}
|
|
925
|
-
|
|
926
|
-
function addTableJson(that, $grid, tableName, columns, success) {
|
|
927
|
-
if (
|
|
928
|
-
configUtil.tableConfig.disableTableName ||
|
|
929
|
-
settingConfig.tableStorageDisabled
|
|
930
|
-
)
|
|
931
|
-
return false;
|
|
932
|
-
if (!tableName) return;
|
|
933
|
-
if (!columns) {
|
|
934
|
-
columns = $grid.getTableColumn().collectColumn;
|
|
935
|
-
}
|
|
936
|
-
let saveColumn = [];
|
|
937
|
-
columns.forEach(function (item, index) {
|
|
938
|
-
let columnData = {
|
|
939
|
-
field: item.field || item.property,
|
|
940
|
-
title: item.title,
|
|
941
|
-
visible: item.visible,
|
|
942
|
-
width: item.renderWidth || item.width,
|
|
943
|
-
};
|
|
944
|
-
|
|
945
|
-
// 如果有 children,递归处理
|
|
946
|
-
if (item.children && item.children.length > 0) {
|
|
947
|
-
columnData.children = processChildren(item.children);
|
|
948
|
-
}
|
|
949
|
-
|
|
950
|
-
saveColumn.push(columnData);
|
|
951
|
-
});
|
|
952
|
-
|
|
953
|
-
// 处理 children 的递归函数
|
|
954
|
-
function processChildren(children) {
|
|
955
|
-
let result = [];
|
|
956
|
-
children.forEach(function (childItem) {
|
|
957
|
-
let childData = {
|
|
958
|
-
field: childItem.field || childItem.property,
|
|
959
|
-
title: childItem.title,
|
|
960
|
-
visible: childItem.visible,
|
|
961
|
-
width: childItem.renderWidth || childItem.width,
|
|
962
|
-
};
|
|
963
|
-
|
|
964
|
-
// 递归处理嵌套的 children
|
|
965
|
-
if (childItem.children && childItem.children.length > 0) {
|
|
966
|
-
childData.children = processChildren(childItem.children);
|
|
967
|
-
}
|
|
968
|
-
|
|
969
|
-
result.push(childData);
|
|
970
|
-
});
|
|
971
|
-
return result;
|
|
972
|
-
}
|
|
973
|
-
|
|
974
|
-
let searchColumns = $grid.params.searchColumns || [];
|
|
975
|
-
let jsonData = {
|
|
976
|
-
columns: saveColumn,
|
|
977
|
-
searchColumns: searchColumns,
|
|
978
|
-
};
|
|
979
|
-
let exportColumns = getTableStateValue($grid, "exportColumns");
|
|
980
|
-
let exportItemColumns = getTableStateValue($grid, "exportItemColumns");
|
|
981
|
-
if (exportColumns && exportColumns.length) {
|
|
982
|
-
jsonData.exportColumns = exportColumns;
|
|
983
|
-
}
|
|
984
|
-
if (exportItemColumns && exportItemColumns.length) {
|
|
985
|
-
jsonData.exportItemColumns = exportItemColumns;
|
|
986
|
-
}
|
|
987
|
-
let json = encodeURIComponent(JSON.stringify(jsonData));
|
|
988
|
-
|
|
989
|
-
let url = USER_PREFIX + "/table_column/addTableJson";
|
|
990
|
-
let data = {
|
|
991
|
-
tableName: tableName,
|
|
992
|
-
// json: encodeURIComponent(JSON.stringify(saveColumn)),
|
|
993
|
-
json: json,
|
|
994
|
-
};
|
|
995
|
-
that.$http({
|
|
996
|
-
url: url,
|
|
997
|
-
method: "post",
|
|
998
|
-
data: data,
|
|
999
|
-
success: success,
|
|
1000
|
-
});
|
|
1001
|
-
}
|
|
1002
|
-
|
|
1003
|
-
function initColumnIndex(columns) {
|
|
1004
|
-
columns.forEach(function (column, index) {
|
|
1005
|
-
if (!column.params) column.params = {};
|
|
1006
|
-
if (column.params) {
|
|
1007
|
-
column.params._index = index;
|
|
1008
|
-
column.params._visible = column.visible ?? true;
|
|
1009
|
-
}
|
|
1010
|
-
if (column.children && column.children.length > 0) {
|
|
1011
|
-
initColumnIndex(column.children);
|
|
1012
|
-
}
|
|
1013
|
-
});
|
|
1014
|
-
}
|
|
1015
|
-
|
|
1016
|
-
function initColumn(option, syncColumns) {
|
|
1017
|
-
let oldColumns = option.columns;
|
|
1018
|
-
let newColumns = [];
|
|
1019
|
-
if (syncColumns) {
|
|
1020
|
-
// 按列对象配对:DB 里同 field 多行时不得反复匹配同一 oldColumn;old 删了重复列时多余 sync 行应丢弃
|
|
1021
|
-
const matchedOld = new Set();
|
|
1022
|
-
syncColumns.forEach(function (syncColumn) {
|
|
1023
|
-
const field = syncColumn.field;
|
|
1024
|
-
if (!field) return;
|
|
1025
|
-
const oldColumn = oldColumns.find(function (oc) {
|
|
1026
|
-
return oc.field === field && !matchedOld.has(oc);
|
|
1027
|
-
});
|
|
1028
|
-
if (!oldColumn) return;
|
|
1029
|
-
matchedOld.add(oldColumn);
|
|
1030
|
-
if (!oldColumn.params) oldColumn.params = {};
|
|
1031
|
-
const visibleSync =
|
|
1032
|
-
option.visibleSync !== false && oldColumn.visibleSync !== false;
|
|
1033
|
-
if (visibleSync) {
|
|
1034
|
-
oldColumn.visible = syncColumn.visible;
|
|
1035
|
-
}
|
|
1036
|
-
if (oldColumn.width !== undefined) {
|
|
1037
|
-
oldColumn.params._width = oldColumn.width;
|
|
1038
|
-
}
|
|
1039
|
-
if (syncColumn.width) oldColumn.width = syncColumn.width;
|
|
1040
|
-
newColumns.push(oldColumn);
|
|
1041
|
-
});
|
|
1042
|
-
oldColumns.forEach(function (oldColumn, index) {
|
|
1043
|
-
if (matchedOld.has(oldColumn)) return;
|
|
1044
|
-
newColumns.splice(index, 0, oldColumn);
|
|
1045
|
-
});
|
|
1046
|
-
|
|
1047
|
-
// 处理 children 中的列
|
|
1048
|
-
if (syncColumns.length > 0) {
|
|
1049
|
-
newColumns.forEach(function (newColumn) {
|
|
1050
|
-
if (newColumn.children && newColumn.children.length > 0) {
|
|
1051
|
-
// 在 syncColumns 中查找对应的父列
|
|
1052
|
-
let syncParentColumn = syncColumns.find(function (syncCol) {
|
|
1053
|
-
return syncCol.field === newColumn.field;
|
|
1054
|
-
});
|
|
1055
|
-
if (
|
|
1056
|
-
syncParentColumn &&
|
|
1057
|
-
syncParentColumn.children &&
|
|
1058
|
-
syncParentColumn.children.length > 0
|
|
1059
|
-
) {
|
|
1060
|
-
// 递归处理 children
|
|
1061
|
-
newColumn.children = initColumn(
|
|
1062
|
-
{ columns: newColumn.children },
|
|
1063
|
-
syncParentColumn.children
|
|
1064
|
-
);
|
|
1065
|
-
}
|
|
1066
|
-
}
|
|
1067
|
-
});
|
|
1068
|
-
}
|
|
1069
|
-
} else {
|
|
1070
|
-
newColumns = oldColumns;
|
|
1071
|
-
}
|
|
1072
|
-
return newColumns;
|
|
1073
|
-
}
|
|
1074
|
-
|
|
1075
|
-
function initExportColumns($grid, tableState, json) {
|
|
1076
|
-
if (json?.exportColumns?.length) {
|
|
1077
|
-
tableState.exportColumns = json.exportColumns;
|
|
1078
|
-
setTableState($grid, "exportColumns", json.exportColumns);
|
|
1079
|
-
}
|
|
1080
|
-
if (json?.exportItemColumns?.length) {
|
|
1081
|
-
tableState.exportItemColumns = json.exportItemColumns;
|
|
1082
|
-
setTableState($grid, "exportItemColumns", json.exportItemColumns);
|
|
1083
|
-
}
|
|
1084
|
-
}
|
|
1085
|
-
|
|
1086
|
-
function initSearchColumns(oriColumns, syncColumns) {
|
|
1087
|
-
let oldColumns = oriColumns || [];
|
|
1088
|
-
let newColumns = [];
|
|
1089
|
-
if (syncColumns) {
|
|
1090
|
-
const matchedOld = new Set();
|
|
1091
|
-
syncColumns.forEach(function (syncColumn) {
|
|
1092
|
-
const field = syncColumn.field;
|
|
1093
|
-
if (!field) return;
|
|
1094
|
-
const oldColumn = oldColumns.find(function (oc) {
|
|
1095
|
-
return oc.field === field && !oc.fixed && !matchedOld.has(oc);
|
|
1096
|
-
});
|
|
1097
|
-
if (!oldColumn) return;
|
|
1098
|
-
matchedOld.add(oldColumn);
|
|
1099
|
-
oldColumn.common = syncColumn.common || false;
|
|
1100
|
-
if (syncColumn.defaultValue !== undefined) {
|
|
1101
|
-
oldColumn.defaultValue = syncColumn.defaultValue;
|
|
1102
|
-
}
|
|
1103
|
-
newColumns.push(oldColumn);
|
|
1104
|
-
});
|
|
1105
|
-
oldColumns.forEach(function (oldColumn, index) {
|
|
1106
|
-
if (oldColumn.fixed) {
|
|
1107
|
-
newColumns.splice(index, 0, oldColumn);
|
|
1108
|
-
return;
|
|
1109
|
-
}
|
|
1110
|
-
if (matchedOld.has(oldColumn)) return;
|
|
1111
|
-
newColumns.splice(index, 0, oldColumn);
|
|
1112
|
-
});
|
|
1113
|
-
} else {
|
|
1114
|
-
newColumns = oldColumns;
|
|
1115
|
-
}
|
|
1116
|
-
return newColumns.length ? newColumns : oldColumns;
|
|
1117
|
-
}
|
|
1118
|
-
|
|
1119
|
-
function onColumnWitchChange(option) {
|
|
1120
|
-
let that = option.$grid.$parent;
|
|
1121
|
-
let $grid = option.$grid;
|
|
1122
|
-
let originOption = $grid.params.originOption;
|
|
1123
|
-
let tableName = originOption.tableName;
|
|
1124
|
-
if (tableName) {
|
|
1125
|
-
// let columns = $grid.columns;
|
|
1126
|
-
const { fullColumn, tableColumn } = $grid.getTableColumn();
|
|
1127
|
-
addTableJson(that, $grid, tableName);
|
|
1128
|
-
}
|
|
1129
|
-
}
|
|
1130
|
-
|
|
1131
|
-
function restoreColumnPosition(currentColumns) {
|
|
1132
|
-
// 根据 params._index 排序 currentColumns
|
|
1133
|
-
let sortedColumns = [...currentColumns].sort((a, b) => {
|
|
1134
|
-
let indexA = a.params?._index ?? 0;
|
|
1135
|
-
let indexB = b.params?._index ?? 0;
|
|
1136
|
-
return indexA - indexB;
|
|
1137
|
-
});
|
|
1138
|
-
|
|
1139
|
-
// 递归处理 children
|
|
1140
|
-
sortedColumns.forEach((column) => {
|
|
1141
|
-
if (column.children && column.children.length > 0) {
|
|
1142
|
-
column.children = restoreColumnPosition(column.children);
|
|
1143
|
-
} else {
|
|
1144
|
-
column.visible = column.params?._visible ?? true;
|
|
1145
|
-
if (column.params?._width !== undefined) {
|
|
1146
|
-
column.width = column.params?._width;
|
|
1147
|
-
} else {
|
|
1148
|
-
// delete column.width;
|
|
1149
|
-
}
|
|
1150
|
-
}
|
|
1151
|
-
});
|
|
1152
|
-
|
|
1153
|
-
return sortedColumns;
|
|
1154
|
-
}
|
|
1155
|
-
|
|
1156
|
-
function customHandle(option) {
|
|
1157
|
-
let that = option.$grid.$parent;
|
|
1158
|
-
let $grid = option.$grid;
|
|
1159
|
-
let originOption = $grid.params.originOption;
|
|
1160
|
-
if (option.type === "confirm" || option.type === "reset") {
|
|
1161
|
-
let tableName = originOption.tableName;
|
|
1162
|
-
if (option.type === "reset") {
|
|
1163
|
-
const { collectColumn } = $grid.getTableColumn();
|
|
1164
|
-
|
|
1165
|
-
// 还原列的位置
|
|
1166
|
-
let oldColumns = originOption.columns || [];
|
|
1167
|
-
if (oldColumns.length > 0) {
|
|
1168
|
-
const restoredColumns = restoreColumnPosition(collectColumn);
|
|
1169
|
-
$grid.loadColumn(restoredColumns);
|
|
1170
|
-
} else {
|
|
1171
|
-
$grid.loadColumn(collectColumn);
|
|
1172
|
-
}
|
|
1173
|
-
}
|
|
1174
|
-
if (tableName) {
|
|
1175
|
-
setTimeout(() => {
|
|
1176
|
-
addTableJson(that, $grid, tableName);
|
|
1177
|
-
}, 200);
|
|
1178
|
-
}
|
|
1179
|
-
|
|
1180
|
-
if (option && option.$event && option.$event.preventDefault) {
|
|
1181
|
-
option.$event.preventDefault(); // 取消事件的默认行为
|
|
1182
|
-
}
|
|
1183
|
-
}
|
|
1184
|
-
originOption.customCallback && originOption.customCallback(option);
|
|
1185
|
-
}
|
|
1186
|
-
|
|
1187
|
-
function changeSelectCount(checked) {
|
|
1188
|
-
let checkedLength = checked.records.length;
|
|
1189
|
-
}
|
|
1190
|
-
|
|
1191
|
-
function getTableData(that, tableRef, type, success) {
|
|
1192
|
-
if (
|
|
1193
|
-
configUtil.tableConfig.disableTableName ||
|
|
1194
|
-
settingConfig.tableStorageDisabled
|
|
1195
|
-
)
|
|
1196
|
-
return false;
|
|
1197
|
-
let $grid = getGrid(that, tableRef);
|
|
1198
|
-
let tableName = getTableStateValue($grid, "tableName");
|
|
1199
|
-
let url = USER_PREFIX + "/table_column/getTableData";
|
|
1200
|
-
let param = {
|
|
1201
|
-
tableName: tableName,
|
|
1202
|
-
type: type,
|
|
1203
|
-
};
|
|
1204
|
-
let data = null;
|
|
1205
|
-
return that.$http({
|
|
1206
|
-
url: url,
|
|
1207
|
-
method: "post",
|
|
1208
|
-
data: param,
|
|
1209
|
-
success: success,
|
|
1210
|
-
});
|
|
1211
|
-
}
|
|
1212
|
-
|
|
1213
|
-
function addTableData(that, tableRef, value, success) {
|
|
1214
|
-
if (
|
|
1215
|
-
configUtil.tableConfig.disableTableName ||
|
|
1216
|
-
settingConfig.tableStorageDisabled
|
|
1217
|
-
)
|
|
1218
|
-
return false;
|
|
1219
|
-
let $grid = getGrid(that, tableRef);
|
|
1220
|
-
let tableName = getTableStateValue($grid, "tableName");
|
|
1221
|
-
if (tableName) {
|
|
1222
|
-
that.$http({
|
|
1223
|
-
method: "post",
|
|
1224
|
-
url: USER_PREFIX + "/table_column/addTableData",
|
|
1225
|
-
data: {
|
|
1226
|
-
tableName: tableName,
|
|
1227
|
-
type: "isQueryAllPage",
|
|
1228
|
-
data: value,
|
|
1229
|
-
},
|
|
1230
|
-
success: success,
|
|
1231
|
-
});
|
|
1232
|
-
}
|
|
1233
|
-
}
|
|
1234
|
-
|
|
1235
|
-
function checkQueryTotal(that, tableRef, value) {
|
|
1236
|
-
let $grid = getGrid(that, tableRef);
|
|
1237
|
-
setTableState($grid, "isQueryAllPage", value);
|
|
1238
|
-
let option = $grid.getProxyInfo();
|
|
1239
|
-
let pagerConfig = $grid.pagerConfig;
|
|
1240
|
-
|
|
1241
|
-
$grid.pagerConfig.layouts = pagerConfig.layouts || [];
|
|
1242
|
-
addTableData(that, tableRef, value);
|
|
1243
|
-
$grid.commitProxy("query");
|
|
1244
|
-
}
|
|
1245
|
-
|
|
1246
|
-
function getPagerConfigLayouts(opts) {
|
|
1247
|
-
if (opts.showPageSizes !== false) {
|
|
1248
|
-
return ["Sizes", "PrevPage", "JumpNumber", "NextPage"];
|
|
1249
|
-
} else {
|
|
1250
|
-
return ["PrevPage", "JumpNumber", "NextPage"];
|
|
1251
|
-
}
|
|
1252
|
-
}
|
|
1253
|
-
|
|
1254
|
-
modules = {
|
|
1255
|
-
initVxeTable,
|
|
1256
|
-
columnDrop,
|
|
1257
|
-
rebindGrid,
|
|
1258
|
-
initOption,
|
|
1259
|
-
getTableJson,
|
|
1260
|
-
addTableJson,
|
|
1261
|
-
onColumnWitchChange,
|
|
1262
|
-
customHandle,
|
|
1263
|
-
changeSelectCount,
|
|
1264
|
-
getTableData,
|
|
1265
|
-
addTableData,
|
|
1266
|
-
checkQueryTotal,
|
|
1267
|
-
getCellValue,
|
|
1268
|
-
createParams,
|
|
1269
|
-
getTableStateValue,
|
|
1270
|
-
setTableState,
|
|
1271
|
-
};
|
|
1272
|
-
|
|
1273
|
-
if (!configUtil.Vue.prototype.$vxeTableUtil)
|
|
1274
|
-
configUtil.Vue.prototype.$vxeTableUtil = modules;
|
|
1275
|
-
|
|
1276
|
-
export default modules;
|
|
1
|
+
/**version-1.0*/
|
|
2
|
+
let modules = {};
|
|
3
|
+
import Sortable from "sortablejs";
|
|
4
|
+
import tableConfig from "./config.js";
|
|
5
|
+
import customConfig from "./customConfig.js";
|
|
6
|
+
import Vue from "vue";
|
|
7
|
+
import { extendDeeply } from "../../utils/index.js";
|
|
8
|
+
import corejsConfig from "@/corejsConfig";
|
|
9
|
+
import settingConfig from "@/settings.js";
|
|
10
|
+
import { getCellValue, createParams } from "./util/index";
|
|
11
|
+
import { getTableStateValue, setTableState } from "./state";
|
|
12
|
+
|
|
13
|
+
let configUtil = {
|
|
14
|
+
Sortable,
|
|
15
|
+
extendDeeply,
|
|
16
|
+
tableConfig,
|
|
17
|
+
Vue,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
function getGrid(that, tableRef) {
|
|
21
|
+
let $grid;
|
|
22
|
+
if (Array.isArray(that.$refs[tableRef])) {
|
|
23
|
+
$grid = that.$refs[tableRef][0];
|
|
24
|
+
} else {
|
|
25
|
+
$grid = that.$refs[tableRef];
|
|
26
|
+
}
|
|
27
|
+
return $grid;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** 是否在列子树中包含目标叶子列(同级 ref 优先,兜底 id) */
|
|
31
|
+
function columnSubtreeContainsLeaf(node, leaf) {
|
|
32
|
+
if (!node || !leaf) return false;
|
|
33
|
+
if (node === leaf) return true;
|
|
34
|
+
if (leaf.id && node.id && String(node.id) === String(leaf.id)) return true;
|
|
35
|
+
if (node.children && node.children.length) {
|
|
36
|
+
return node.children.some((child) =>
|
|
37
|
+
columnSubtreeContainsLeaf(child, leaf)
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** leaf 所属的 collectColumn 最顶层节点的下标(-1 表示未找到) */
|
|
44
|
+
function collectTopRootIndex(collectColumn, leaf) {
|
|
45
|
+
if (!collectColumn || !collectColumn.length || !leaf) return -1;
|
|
46
|
+
return collectColumn.findIndex((root) =>
|
|
47
|
+
columnSubtreeContainsLeaf(root, leaf)
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function initVxeTable(option) {
|
|
52
|
+
let tableName = option.tableName;
|
|
53
|
+
if (
|
|
54
|
+
!configUtil.tableConfig.disableTableName &&
|
|
55
|
+
option.tableNameRequired !== false &&
|
|
56
|
+
!tableName &&
|
|
57
|
+
settingConfig.tableStorageDisabled !== true
|
|
58
|
+
) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
let that = option.vue;
|
|
63
|
+
if (!that.$refs[option.tableRef]) {
|
|
64
|
+
await that.$nextTick();
|
|
65
|
+
}
|
|
66
|
+
let $grid = getGrid(that, option.tableRef);
|
|
67
|
+
if (!$grid) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
delete option.vue;
|
|
71
|
+
|
|
72
|
+
//操作列自动补全
|
|
73
|
+
handleCustomAlign(option);
|
|
74
|
+
|
|
75
|
+
initColumnIndex(option.columns);
|
|
76
|
+
|
|
77
|
+
let originOption = that.$baseLodash.cloneDeep(option);
|
|
78
|
+
originOption.vue = that;
|
|
79
|
+
$grid.originOption = originOption;
|
|
80
|
+
option.vue = that;
|
|
81
|
+
|
|
82
|
+
// 运行时状态先收集到局部对象,末尾并入 nOption.params 随 vxeOption 传给表格实例,
|
|
83
|
+
// 保证页面 v-if 销毁重建 grid 后状态不丢(详见 ./state.js)
|
|
84
|
+
let tableState = {
|
|
85
|
+
tableName: tableName || null,
|
|
86
|
+
isQueryAllPage: true,
|
|
87
|
+
exportColumns: null,
|
|
88
|
+
exportItemColumns: null,
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
let isQueryAllPage = true;
|
|
92
|
+
if (option.isQueryAllPage !== null && option.isQueryAllPage !== undefined) {
|
|
93
|
+
isQueryAllPage = option.isQueryAllPage;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
let searchColumns = null;
|
|
97
|
+
if (tableName) {
|
|
98
|
+
setTableState($grid, "tableName", tableName);
|
|
99
|
+
if (option.path) {
|
|
100
|
+
await getTableData(that, option.tableRef, "isQueryAllPage", (res1) => {
|
|
101
|
+
let result = res1.objx ? res1.objx.data : null;
|
|
102
|
+
if (result !== null && result !== undefined) {
|
|
103
|
+
if (result === "false" || result === false) {
|
|
104
|
+
isQueryAllPage = false;
|
|
105
|
+
} else {
|
|
106
|
+
isQueryAllPage = true;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
await getTableJson(tableName, that, (resultMsg) => {
|
|
112
|
+
let objx = resultMsg.objx;
|
|
113
|
+
if (objx !== null && objx !== undefined) {
|
|
114
|
+
let jsonStr = objx.data;
|
|
115
|
+
if (jsonStr) {
|
|
116
|
+
let json = JSON.parse(decodeURIComponent(jsonStr));
|
|
117
|
+
let columnData = json.columns ? json.columns : json;
|
|
118
|
+
if (columnData) {
|
|
119
|
+
option.columns = initColumn(option, columnData);
|
|
120
|
+
}
|
|
121
|
+
searchColumns = initSearchColumns(
|
|
122
|
+
option.searchColumns,
|
|
123
|
+
json.searchColumns
|
|
124
|
+
);
|
|
125
|
+
$grid.searchColumns = searchColumns;
|
|
126
|
+
initExportColumns($grid, tableState, json);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (!searchColumns || !searchColumns.length) {
|
|
130
|
+
searchColumns = initSearchColumns(option.searchColumns);
|
|
131
|
+
$grid.searchColumns = searchColumns;
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
} else {
|
|
135
|
+
searchColumns = initSearchColumns(option.searchColumns);
|
|
136
|
+
$grid.searchColumns = searchColumns;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (!!$grid?.$refs?.xTable) {
|
|
140
|
+
$grid.$refs.xTable.getCellValue = getCellValue;
|
|
141
|
+
$grid.$refs.xTable.createParams = createParams;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// $grid.getCellValue = getCellValue;
|
|
145
|
+
// $grid.createParams = createParams;
|
|
146
|
+
|
|
147
|
+
option.isQueryAllPage = isQueryAllPage;
|
|
148
|
+
let nOption = initOption(option);
|
|
149
|
+
|
|
150
|
+
// isQueryAllPage 的事实源是 $grid.params(checkQueryTotal 也写这里),
|
|
151
|
+
// pager 插槽与代理 ajax.query 均读它,初始化必须回写,
|
|
152
|
+
// 否则首屏恒为 undefined:既丢用户存的偏好,也让页面配置的 false 不生效。
|
|
153
|
+
tableState.isQueryAllPage = isQueryAllPage;
|
|
154
|
+
setTableState($grid, "isQueryAllPage", isQueryAllPage);
|
|
155
|
+
|
|
156
|
+
if (tableName) {
|
|
157
|
+
nOption.tableName = tableName;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
nOption.vue = that;
|
|
161
|
+
//绑定列位置拖拽
|
|
162
|
+
columnDrop(that, tableName, option.tableRef);
|
|
163
|
+
|
|
164
|
+
//自动绑定toobar
|
|
165
|
+
handleToolbar($grid, option);
|
|
166
|
+
|
|
167
|
+
// nOption.originOption = originOption;
|
|
168
|
+
// nOption.getCellValue = getCellValue;
|
|
169
|
+
// nOption.createParams = createParams;
|
|
170
|
+
// nOption.searchColumns = searchColumns;
|
|
171
|
+
// 运行时可变状态(tableName / isQueryAllPage / exportColumns / exportItemColumns)
|
|
172
|
+
// 一并放进 params:params 随 vxeOption 由页面持有,grid 被 v-if 销毁重建后依然带着这些值
|
|
173
|
+
let params = {
|
|
174
|
+
originOption,
|
|
175
|
+
getCellValue,
|
|
176
|
+
createParams,
|
|
177
|
+
searchColumns,
|
|
178
|
+
...tableState,
|
|
179
|
+
};
|
|
180
|
+
if (!nOption.params) nOption.params = {};
|
|
181
|
+
Object.assign(nOption.params, params);
|
|
182
|
+
return nOption;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
//自动绑定toobar
|
|
186
|
+
function handleToolbar($grid, option) {
|
|
187
|
+
let selfConfig = getSelfConfig();
|
|
188
|
+
if (
|
|
189
|
+
option.bindToolbar ||
|
|
190
|
+
(option.bindToolbar !== false && selfConfig.bindToolbar)
|
|
191
|
+
) {
|
|
192
|
+
let loopDo = function (children) {
|
|
193
|
+
if (children && children.length) {
|
|
194
|
+
children.forEach((item) => {
|
|
195
|
+
if (item.$options.name === "VxeToolbar") {
|
|
196
|
+
$grid.connect(item);
|
|
197
|
+
} else {
|
|
198
|
+
loopDo(item.$children);
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
$grid.$nextTick(() => {
|
|
204
|
+
loopDo($grid.$children);
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* grid 被 v-if 销毁重建后调用(页面把 showTable 从 false 切回 true 之类)。
|
|
211
|
+
*
|
|
212
|
+
* 状态类(tableName / isQueryAllPage / exportColumns…)已经随 params 跨重建存活,
|
|
213
|
+
* 这里只重做「绑在实例或 DOM 上、params 带不走」的那部分:
|
|
214
|
+
* - columnDrop:Sortable 绑的是旧表头 DOM,重建后新表头上什么都没有,列拖拽会静默失效;
|
|
215
|
+
* - handleToolbar:$grid.connect(toolbar) 是实例间的连接,重建后失联。
|
|
216
|
+
* 必须等新 grid 渲染出表头再绑,所以整体放在 $nextTick 里。
|
|
217
|
+
*/
|
|
218
|
+
function rebindGrid(that, tableRef) {
|
|
219
|
+
let $grid = getGrid(that, tableRef);
|
|
220
|
+
let originOption = $grid && $grid.params && $grid.params.originOption;
|
|
221
|
+
if (!originOption) {
|
|
222
|
+
// 没走过 initVxeTable 的表格没有 params.originOption,无从重绑
|
|
223
|
+
return Promise.resolve(false);
|
|
224
|
+
}
|
|
225
|
+
$grid.originOption = originOption;
|
|
226
|
+
// vxeFilter 已改为直接 import 工具函数,这里补挂只为兼容直接读 $table.getCellValue 的业务代码
|
|
227
|
+
if ($grid.$refs && $grid.$refs.xTable) {
|
|
228
|
+
$grid.$refs.xTable.getCellValue = getCellValue;
|
|
229
|
+
$grid.$refs.xTable.createParams = createParams;
|
|
230
|
+
}
|
|
231
|
+
return $grid.$nextTick().then(() => {
|
|
232
|
+
columnDrop(that, originOption.tableName, tableRef);
|
|
233
|
+
handleToolbar($grid, originOption);
|
|
234
|
+
return true;
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
//操作列自动补全
|
|
239
|
+
function handleCustomAlign(option) {
|
|
240
|
+
let selfConfig = getSelfConfig();
|
|
241
|
+
// let customAlign = option.customAlign || selfConfig.customAlign || "right";
|
|
242
|
+
let customAlign =
|
|
243
|
+
selfConfig.customAlign === false
|
|
244
|
+
? false
|
|
245
|
+
: selfConfig.customAlign || "right";
|
|
246
|
+
customAlign =
|
|
247
|
+
option.customAlign === false ? false : option.customAlign || customAlign;
|
|
248
|
+
|
|
249
|
+
let customColumnWidth =
|
|
250
|
+
option.customColumnWidth || selfConfig.customColumnWidth || 47;
|
|
251
|
+
let checkBoxColumnWidth =
|
|
252
|
+
option.checkBoxColumnWidth || selfConfig.checkBoxColumnWidth || 48;
|
|
253
|
+
|
|
254
|
+
let checkBoxRequired = selfConfig.checkBoxRequired !== false;
|
|
255
|
+
if (option.checkBoxRequired === false) {
|
|
256
|
+
checkBoxRequired = false;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
let columnSize = option.columns.length;
|
|
260
|
+
if (columnSize > 0) {
|
|
261
|
+
if (checkBoxRequired) {
|
|
262
|
+
let firstColumn = option.columns[0];
|
|
263
|
+
if (firstColumn.type !== "checkbox") {
|
|
264
|
+
option.columns.splice(0, 0, {
|
|
265
|
+
type: "checkbox",
|
|
266
|
+
width: checkBoxColumnWidth,
|
|
267
|
+
resizable: false,
|
|
268
|
+
fixed: "left",
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
if (customAlign !== false) {
|
|
273
|
+
let lastColumn = option.columns[columnSize - 1];
|
|
274
|
+
if (customAlign === "left") {
|
|
275
|
+
if (!lastColumn.field && lastColumn.fixed === "right") {
|
|
276
|
+
option.columns.splice(columnSize - 1, 1);
|
|
277
|
+
lastColumn.fixed = "left";
|
|
278
|
+
option.columns.splice(1, 0, lastColumn);
|
|
279
|
+
} else if (columnSize > 1) {
|
|
280
|
+
if (option.columns[1].field) {
|
|
281
|
+
option.columns.splice(1, 0, {
|
|
282
|
+
width: customColumnWidth,
|
|
283
|
+
fixed: "left",
|
|
284
|
+
title: "",
|
|
285
|
+
sortable: false,
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
} else if (customAlign === "right") {
|
|
290
|
+
let column1 = option.columns[1];
|
|
291
|
+
if (!column1.field && column1.fixed === "left") {
|
|
292
|
+
option.columns.splice(1, 1);
|
|
293
|
+
column1.fixed = "right";
|
|
294
|
+
option.columns.push(column1);
|
|
295
|
+
} else if (lastColumn.field || lastColumn.fixed !== "right") {
|
|
296
|
+
option.columns.push({
|
|
297
|
+
width: customColumnWidth,
|
|
298
|
+
fixed: "right",
|
|
299
|
+
title: "",
|
|
300
|
+
sortable: false,
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
//列位置拖拽
|
|
309
|
+
function columnDrop(t, tableName, tableRef) {
|
|
310
|
+
let that = t;
|
|
311
|
+
const $table = getGrid(that, tableRef);
|
|
312
|
+
if (!$table) {
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
// 表头尚未渲染(grid 刚被 v-if 重建、DOM 还没就绪)时 querySelector 返回 null,
|
|
316
|
+
// Sortable.create(null) 会直接抛错,这里降级为不绑定,由调用方在 $nextTick 后重试
|
|
317
|
+
const headerElem =
|
|
318
|
+
$table.$el &&
|
|
319
|
+
$table.$el.querySelector(
|
|
320
|
+
".body--wrapper>.vxe-table--header .vxe-header--row"
|
|
321
|
+
);
|
|
322
|
+
if (!headerElem) {
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
// if (!$table.params) $table.params = {};
|
|
326
|
+
if ($table.sortable) {
|
|
327
|
+
$table.sortable.destroy();
|
|
328
|
+
$table.sortable = null;
|
|
329
|
+
}
|
|
330
|
+
let dragStartIndex = -1;
|
|
331
|
+
let dragEndIndex = -1;
|
|
332
|
+
$table.sortable = configUtil.Sortable.create(
|
|
333
|
+
headerElem,
|
|
334
|
+
{
|
|
335
|
+
handle: ".vxe-header--column:not(.col--fixed)",
|
|
336
|
+
onMove: (a, b, c) => {
|
|
337
|
+
let { dragged, related } = a;
|
|
338
|
+
// dragStartIndex = getElementIndex(dragged);
|
|
339
|
+
// dragEndIndex = getElementIndex(related);
|
|
340
|
+
|
|
341
|
+
let tableColumn = $table.getTableColumn().tableColumn;
|
|
342
|
+
let draggedColId = dragged.getAttribute("colid");
|
|
343
|
+
let relatedColId = related.getAttribute("colid");
|
|
344
|
+
dragStartIndex = tableColumn.findIndex(
|
|
345
|
+
(item) => item.id === draggedColId
|
|
346
|
+
);
|
|
347
|
+
dragEndIndex = tableColumn.findIndex(
|
|
348
|
+
(item) => item.id === relatedColId
|
|
349
|
+
);
|
|
350
|
+
},
|
|
351
|
+
onEnd: (dropParam) => {
|
|
352
|
+
let { item } = dropParam;
|
|
353
|
+
let oldIndex = dragStartIndex;
|
|
354
|
+
let newIndex = dragEndIndex;
|
|
355
|
+
|
|
356
|
+
// Sortable 原地放下时可能不触发 onMove,索引需从 dropParam 兜底
|
|
357
|
+
if (oldIndex < 0) oldIndex = dropParam.oldIndex;
|
|
358
|
+
if (newIndex < 0) newIndex = dropParam.newIndex;
|
|
359
|
+
const { fullColumn, tableColumn, collectColumn } =
|
|
360
|
+
$table.getTableColumn();
|
|
361
|
+
const targetThElem = item;
|
|
362
|
+
const wrapperElem = targetThElem.parentNode;
|
|
363
|
+
let oldColumn = tableColumn[oldIndex];
|
|
364
|
+
const newColumn = tableColumn[newIndex];
|
|
365
|
+
if (!oldColumn || !newColumn) return;
|
|
366
|
+
if (newColumn.fixed) {
|
|
367
|
+
// 错误的移动
|
|
368
|
+
if (newIndex > oldIndex) {
|
|
369
|
+
wrapperElem.insertBefore(
|
|
370
|
+
targetThElem,
|
|
371
|
+
wrapperElem.children[oldIndex]
|
|
372
|
+
);
|
|
373
|
+
} else {
|
|
374
|
+
wrapperElem.insertBefore(
|
|
375
|
+
wrapperElem.children[oldIndex],
|
|
376
|
+
targetThElem
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
return;
|
|
380
|
+
/* return that.$XModal.message({
|
|
381
|
+
content: '固定列不允许拖动!',
|
|
382
|
+
status: 'error'
|
|
383
|
+
}) */
|
|
384
|
+
}
|
|
385
|
+
// 叶子在 fullColumn 中的下标,与 collectColumn 顶层结构的下标不能直接混用
|
|
386
|
+
const oldColumnIndex = fullColumn.findIndex(
|
|
387
|
+
(item) => item.id === oldColumn.id
|
|
388
|
+
);
|
|
389
|
+
const newColumnIndex = fullColumn.findIndex(
|
|
390
|
+
(item) => item.id === newColumn.id
|
|
391
|
+
);
|
|
392
|
+
const oldLeafColumn = fullColumn[oldColumnIndex];
|
|
393
|
+
const newLeafColumn = fullColumn[newColumnIndex];
|
|
394
|
+
if (oldColumnIndex === newColumnIndex) {
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
const oldTopIdx = collectTopRootIndex(collectColumn, oldLeafColumn);
|
|
398
|
+
const newTopIdx = collectTopRootIndex(collectColumn, newLeafColumn);
|
|
399
|
+
if (oldTopIdx === -1 || newTopIdx === -1) {
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
if (oldTopIdx !== newTopIdx) {
|
|
403
|
+
const currRow = collectColumn.splice(oldTopIdx, 1)[0];
|
|
404
|
+
collectColumn.splice(newTopIdx, 0, currRow);
|
|
405
|
+
$table.loadColumn(collectColumn);
|
|
406
|
+
addTableJson(that, $table, tableName, collectColumn);
|
|
407
|
+
}
|
|
408
|
+
},
|
|
409
|
+
}
|
|
410
|
+
);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
function getSelfConfig() {
|
|
414
|
+
let tableConfig = configUtil.tableConfig || {};
|
|
415
|
+
let selfConfig = tableConfig.selfConfig || {};
|
|
416
|
+
return selfConfig;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
function applyTableFeatureDisabled(result, that) {
|
|
420
|
+
let userState = that?.$store?.state?.user || {};
|
|
421
|
+
let sortDisabled = userState.tableSortDisabled === true;
|
|
422
|
+
let filterDisabled = userState.tableFilterDisabled === true;
|
|
423
|
+
if (!sortDisabled && !filterDisabled) return;
|
|
424
|
+
|
|
425
|
+
let handleColumns = (columns) => {
|
|
426
|
+
(columns || []).forEach((column) => {
|
|
427
|
+
if (sortDisabled) {
|
|
428
|
+
column.sortable = false;
|
|
429
|
+
}
|
|
430
|
+
if (filterDisabled) {
|
|
431
|
+
column.filterType = false;
|
|
432
|
+
delete column.filters;
|
|
433
|
+
delete column.filterRender;
|
|
434
|
+
delete column.filterMethod;
|
|
435
|
+
}
|
|
436
|
+
if (column.children && column.children.length) {
|
|
437
|
+
handleColumns(column.children);
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
handleColumns(result.columns);
|
|
443
|
+
if (sortDisabled) {
|
|
444
|
+
if (result.proxyConfig) result.proxyConfig.sort = false;
|
|
445
|
+
if (result.sortConfig) {
|
|
446
|
+
result.sortConfig.showIcon = false;
|
|
447
|
+
delete result.sortConfig.defaultSort;
|
|
448
|
+
delete result.sortConfig.sortMethod;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
if (filterDisabled) {
|
|
452
|
+
if (result.proxyConfig) result.proxyConfig.filter = false;
|
|
453
|
+
if (result.filterConfig) result.filterConfig.showIcon = false;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
function initColumnDefaulAttrs(columns, opts) {
|
|
458
|
+
let tableConfig = configUtil.tableConfig || {};
|
|
459
|
+
let selfConfig = getSelfConfig();
|
|
460
|
+
let lockCheckboxWidth =
|
|
461
|
+
opts.lockCheckboxWidth !== false
|
|
462
|
+
? opts.lockCheckboxWidth || selfConfig.lockCheckboxWidth
|
|
463
|
+
: null;
|
|
464
|
+
let filterType =
|
|
465
|
+
opts.filterType !== false && !opts.treeNodeUrl
|
|
466
|
+
? opts.filterType || selfConfig.filterType || "filterContent"
|
|
467
|
+
: null;
|
|
468
|
+
let sortAll =
|
|
469
|
+
opts.sortAll === true || (opts.sortAll !== false && !opts.treeNodeUrl);
|
|
470
|
+
|
|
471
|
+
columns.forEach((column) => {
|
|
472
|
+
// 只有最底层的列(没有 children)才设置默认属性
|
|
473
|
+
if (!column.children || column.children.length === 0) {
|
|
474
|
+
// 设置 sortable
|
|
475
|
+
if (
|
|
476
|
+
sortAll &&
|
|
477
|
+
column.title &&
|
|
478
|
+
(column.sortable === null || column.sortable === undefined)
|
|
479
|
+
) {
|
|
480
|
+
column.sortable = true;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
// 设置过滤器
|
|
484
|
+
if (filterType && column.title && column.field) {
|
|
485
|
+
if (
|
|
486
|
+
column.filterType === "filterContent" ||
|
|
487
|
+
((column.filterType === null || column.filterType === undefined) &&
|
|
488
|
+
filterType === "filterContent")
|
|
489
|
+
) {
|
|
490
|
+
if (!column.filters) {
|
|
491
|
+
column.filters = [
|
|
492
|
+
{
|
|
493
|
+
data: {},
|
|
494
|
+
},
|
|
495
|
+
];
|
|
496
|
+
}
|
|
497
|
+
if (!column.filterRender) {
|
|
498
|
+
column.filterRender = {
|
|
499
|
+
name: "FilterContent",
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
} else if (
|
|
503
|
+
column.filterType === "filterInput" ||
|
|
504
|
+
((column.filterType === null || column.filterType === undefined) &&
|
|
505
|
+
filterType === "filterInput")
|
|
506
|
+
) {
|
|
507
|
+
if (!column.filters) {
|
|
508
|
+
column.filters = [
|
|
509
|
+
{
|
|
510
|
+
data: "",
|
|
511
|
+
},
|
|
512
|
+
];
|
|
513
|
+
}
|
|
514
|
+
if (!column.filterRender) {
|
|
515
|
+
column.filterRender = {
|
|
516
|
+
name: "FilterInput",
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
// 设置复选框列宽度
|
|
523
|
+
if (lockCheckboxWidth && column.type === "checkbox") {
|
|
524
|
+
column.width = lockCheckboxWidth;
|
|
525
|
+
}
|
|
526
|
+
} else {
|
|
527
|
+
column.sortable = false;
|
|
528
|
+
column.filterType = false;
|
|
529
|
+
column.align = "center";
|
|
530
|
+
column.resizable = false;
|
|
531
|
+
// 递归处理 children
|
|
532
|
+
initColumnDefaulAttrs(column.children, opts);
|
|
533
|
+
}
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
function initOption(opts) {
|
|
538
|
+
let result = {};
|
|
539
|
+
let that = opts.vue;
|
|
540
|
+
let $grid = getGrid(that, opts.tableRef);
|
|
541
|
+
|
|
542
|
+
let path = opts.path || "";
|
|
543
|
+
// let columns = JSON.parse(JSON.stringify(opts.columns || []));
|
|
544
|
+
let columns = opts.columns || [];
|
|
545
|
+
let pagerLayouts = getPagerConfigLayouts(opts);
|
|
546
|
+
|
|
547
|
+
let config = opts.config || {};
|
|
548
|
+
|
|
549
|
+
initColumnDefaulAttrs(columns, opts);
|
|
550
|
+
|
|
551
|
+
let defaultOptions = {
|
|
552
|
+
columnKey: true,
|
|
553
|
+
resizable: true,
|
|
554
|
+
showOverflow: true,
|
|
555
|
+
showHeaderOverflow: true,
|
|
556
|
+
showFooterOverflow: true,
|
|
557
|
+
highlightHoverRow: true,
|
|
558
|
+
border: "inner",
|
|
559
|
+
height: "auto",
|
|
560
|
+
// maxHeight:"1000px",
|
|
561
|
+
// rowId: 'id',
|
|
562
|
+
emptyText: " ",
|
|
563
|
+
sortConfig: {
|
|
564
|
+
trigger: "cell",
|
|
565
|
+
remote: false,
|
|
566
|
+
},
|
|
567
|
+
filterConfig: {
|
|
568
|
+
remote: false,
|
|
569
|
+
},
|
|
570
|
+
pagerConfig: {
|
|
571
|
+
autoHidden: true,
|
|
572
|
+
perfect: true,
|
|
573
|
+
pageSize: 200,
|
|
574
|
+
pageSizes: [50, 100, 200, 500],
|
|
575
|
+
layouts: pagerLayouts,
|
|
576
|
+
slots: {
|
|
577
|
+
left: (obj, b, c) => {
|
|
578
|
+
let $grid = obj.$grid;
|
|
579
|
+
let k = $grid.$data;
|
|
580
|
+
let tableDataInfo = $grid.getTableData();
|
|
581
|
+
let data = tableDataInfo.fullData;
|
|
582
|
+
let h = $grid.$createElement;
|
|
583
|
+
|
|
584
|
+
let proxyInfo = $grid.getProxyInfo();
|
|
585
|
+
let pager = proxyInfo ? proxyInfo.pager : null;
|
|
586
|
+
|
|
587
|
+
let celems = [
|
|
588
|
+
h("span", $grid.$t2("本页记录数", "components.table.currentNum")),
|
|
589
|
+
h(
|
|
590
|
+
"span",
|
|
591
|
+
{
|
|
592
|
+
attrs: {
|
|
593
|
+
class: "f-red",
|
|
594
|
+
},
|
|
595
|
+
},
|
|
596
|
+
" " + tableDataInfo.visibleData.length + " "
|
|
597
|
+
),
|
|
598
|
+
];
|
|
599
|
+
if (pager && getTableStateValue($grid, "isQueryAllPage")) {
|
|
600
|
+
celems.push(
|
|
601
|
+
h(
|
|
602
|
+
"span",
|
|
603
|
+
"," + $grid.$t2("总记录数", "components.table.totalNum")
|
|
604
|
+
)
|
|
605
|
+
);
|
|
606
|
+
celems.push(
|
|
607
|
+
h(
|
|
608
|
+
"span",
|
|
609
|
+
{
|
|
610
|
+
attrs: {
|
|
611
|
+
class: "f-red",
|
|
612
|
+
},
|
|
613
|
+
},
|
|
614
|
+
" " + pager.total + " "
|
|
615
|
+
)
|
|
616
|
+
);
|
|
617
|
+
}
|
|
618
|
+
let elem = h("span", {}, celems);
|
|
619
|
+
return [elem];
|
|
620
|
+
},
|
|
621
|
+
},
|
|
622
|
+
},
|
|
623
|
+
exportConfig: {
|
|
624
|
+
// 默认选中类型
|
|
625
|
+
type: "xlsx",
|
|
626
|
+
// 局部自定义类型
|
|
627
|
+
types: ["xlsx", "csv", "html", "xml", "txt"],
|
|
628
|
+
// 仅保留当前页:mode=all 依赖的 queryAll 无鉴权实现,从未可用;全量导出请走 $excelExport
|
|
629
|
+
modes: ["current"],
|
|
630
|
+
// 与 $excelExport 一致地剔除非数据列与脱敏列,避免绕开 $excelExport 导出明文
|
|
631
|
+
columnFilterMethod({ column }) {
|
|
632
|
+
return !column.params?.exportDisabled;
|
|
633
|
+
},
|
|
634
|
+
},
|
|
635
|
+
radioConfig: {
|
|
636
|
+
labelField: "id",
|
|
637
|
+
reserve: true,
|
|
638
|
+
highlight: true,
|
|
639
|
+
},
|
|
640
|
+
checkboxConfig: {
|
|
641
|
+
highlight: true,
|
|
642
|
+
},
|
|
643
|
+
customConfig: {
|
|
644
|
+
storage: false,
|
|
645
|
+
},
|
|
646
|
+
scrollX: {
|
|
647
|
+
// enabled: true,
|
|
648
|
+
gt: 10,
|
|
649
|
+
// oSize: 5
|
|
650
|
+
},
|
|
651
|
+
/*loadingConfig: {
|
|
652
|
+
icon: "vxe-loading--spinner",
|
|
653
|
+
text: ' '
|
|
654
|
+
},*/
|
|
655
|
+
columns: columns,
|
|
656
|
+
};
|
|
657
|
+
let tableDefaultConfig =
|
|
658
|
+
corejsConfig?.componentConfig?.table?.defaultConfig || {};
|
|
659
|
+
defaultOptions = configUtil.extendDeeply(defaultOptions, tableConfig);
|
|
660
|
+
defaultOptions = configUtil.extendDeeply(defaultOptions, customConfig);
|
|
661
|
+
defaultOptions = configUtil.extendDeeply(defaultOptions, tableDefaultConfig);
|
|
662
|
+
|
|
663
|
+
if (opts.path) {
|
|
664
|
+
// defaultOptions.filterInput = true;
|
|
665
|
+
defaultOptions.pagerConfig.autoHidden = false;
|
|
666
|
+
defaultOptions.proxyConfig = {
|
|
667
|
+
seq: true, // 启用动态序号代理
|
|
668
|
+
sort: true, // 启用排序代理
|
|
669
|
+
filter: true, // 启用筛选代理
|
|
670
|
+
props: {
|
|
671
|
+
result: "objx.records", // 配置响应结果列表字段
|
|
672
|
+
total: "objx.total", // 配置响应结果总页数字段
|
|
673
|
+
},
|
|
674
|
+
ajax: {
|
|
675
|
+
// 接收 Promise 对象
|
|
676
|
+
query: ({ page, sorts, filters, form }) => {
|
|
677
|
+
if (!opts.path) {
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
680
|
+
return new Promise((resolve, reject) => {
|
|
681
|
+
let toDo = () => {
|
|
682
|
+
let formData = opts.param ? opts.param() || {} : {};
|
|
683
|
+
const queryParams = Object.assign({}, formData);
|
|
684
|
+
|
|
685
|
+
// 处理排序条件
|
|
686
|
+
/*const firstSort = sorts[0];
|
|
687
|
+
if (firstSort) {
|
|
688
|
+
queryParams.sort = firstSort.property;
|
|
689
|
+
queryParams.order = firstSort.order;
|
|
690
|
+
}*/
|
|
691
|
+
// 处理筛选条件
|
|
692
|
+
filters.forEach(({ property, values }) => {
|
|
693
|
+
queryParams[property] = values.join(",");
|
|
694
|
+
});
|
|
695
|
+
if (page.pageSize !== undefined) {
|
|
696
|
+
queryParams["size"] = page.pageSize;
|
|
697
|
+
queryParams["current"] = page.currentPage;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
let $grid = getGrid(that, opts.tableRef);
|
|
701
|
+
let isQueryAllPage = getTableStateValue($grid, "isQueryAllPage");
|
|
702
|
+
let pathStr1 = "";
|
|
703
|
+
if (isQueryAllPage === false) {
|
|
704
|
+
queryParams.searchCount = false;
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
let reqPath = typeof path === "function" ? path() : path;
|
|
708
|
+
let addUserForTableEnabled =
|
|
709
|
+
settingConfig.addUserForTableDisabled !== true;
|
|
710
|
+
let addCreateInfo =
|
|
711
|
+
opts.addCreateInfo === true || addUserForTableEnabled;
|
|
712
|
+
let queryCreateInfo =
|
|
713
|
+
opts.queryCreateInfo === true || addUserForTableEnabled;
|
|
714
|
+
let reqData = queryParams;
|
|
715
|
+
if (opts.paramHandle) {
|
|
716
|
+
reqData = opts.paramHandle
|
|
717
|
+
? opts.paramHandle(queryParams) || {}
|
|
718
|
+
: {};
|
|
719
|
+
}
|
|
720
|
+
that.$commonHttp({
|
|
721
|
+
aes: opts.aes || false,
|
|
722
|
+
url: reqPath,
|
|
723
|
+
method: "post",
|
|
724
|
+
data: reqData,
|
|
725
|
+
addCreateInfo: addCreateInfo,
|
|
726
|
+
queryCreateInfo: queryCreateInfo,
|
|
727
|
+
callback: (res) => {
|
|
728
|
+
resolve(res);
|
|
729
|
+
if (res.type === "success") {
|
|
730
|
+
let rows = res.objx
|
|
731
|
+
? res.objx.records || res.objx || []
|
|
732
|
+
: [];
|
|
733
|
+
if (opts.treeNodeUrl) {
|
|
734
|
+
if (rows.length > 0) {
|
|
735
|
+
let $t = getGrid(that, opts.tableRef);
|
|
736
|
+
let treeConditions = $t.params.originOption
|
|
737
|
+
.treeConditions || ["enabled"];
|
|
738
|
+
let treeFiled = Object.keys(formData).some((key) => {
|
|
739
|
+
return (
|
|
740
|
+
!treeConditions.includes(key) &&
|
|
741
|
+
formData[key] !== null &&
|
|
742
|
+
formData[key] !== undefined &&
|
|
743
|
+
formData[key] !== ""
|
|
744
|
+
);
|
|
745
|
+
});
|
|
746
|
+
if (treeFiled) {
|
|
747
|
+
that.$nextTick(() => {
|
|
748
|
+
setTimeout(function () {
|
|
749
|
+
let isLazy = $t.treeConfig.lazy;
|
|
750
|
+
$t.treeConfig.lazy = false;
|
|
751
|
+
$t.setAllTreeExpand(true).then(() => {
|
|
752
|
+
let fullAllDataRowMap =
|
|
753
|
+
$t.$refs.xTable.fullAllDataRowMap;
|
|
754
|
+
let fullData = $t.getTableData().fullData;
|
|
755
|
+
fullData.forEach((lineData) => {
|
|
756
|
+
if (
|
|
757
|
+
$t.$refs.xTable.isTreeExpandByRow(lineData)
|
|
758
|
+
) {
|
|
759
|
+
let rest = fullAllDataRowMap.get(lineData);
|
|
760
|
+
rest.treeLoaded = true;
|
|
761
|
+
}
|
|
762
|
+
});
|
|
763
|
+
$t.treeConfig.lazy = isLazy;
|
|
764
|
+
});
|
|
765
|
+
}, 0);
|
|
766
|
+
});
|
|
767
|
+
} else {
|
|
768
|
+
let row = rows[0];
|
|
769
|
+
if (row[$t.treeConfig.hasChild]) {
|
|
770
|
+
that.$nextTick(() => {
|
|
771
|
+
setTimeout(function () {
|
|
772
|
+
$t.setTreeExpand(row, true);
|
|
773
|
+
}, 0);
|
|
774
|
+
});
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
if (opts.callback) {
|
|
780
|
+
that.$nextTick(() => {
|
|
781
|
+
setTimeout(function () {
|
|
782
|
+
opts.callback(rows, res);
|
|
783
|
+
}, 0);
|
|
784
|
+
});
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
},
|
|
788
|
+
error: (error) => {
|
|
789
|
+
reject(error);
|
|
790
|
+
},
|
|
791
|
+
});
|
|
792
|
+
};
|
|
793
|
+
let index = 0;
|
|
794
|
+
let loopHandle = () => {
|
|
795
|
+
if (index < 500 && $grid.tableFormStop === true) {
|
|
796
|
+
//阻塞列表查询,或者次数达到500时,自动释放
|
|
797
|
+
index++;
|
|
798
|
+
setTimeout(() => {
|
|
799
|
+
loopHandle();
|
|
800
|
+
}, 10);
|
|
801
|
+
} else {
|
|
802
|
+
if ($grid.tableFormStop) $grid.tableFormStop = false;
|
|
803
|
+
toDo();
|
|
804
|
+
}
|
|
805
|
+
};
|
|
806
|
+
loopHandle();
|
|
807
|
+
});
|
|
808
|
+
},
|
|
809
|
+
},
|
|
810
|
+
};
|
|
811
|
+
/*defaultOptions.scrollX = {
|
|
812
|
+
enabled: true,
|
|
813
|
+
gt: 20
|
|
814
|
+
};*/
|
|
815
|
+
defaultOptions.scrollY = {
|
|
816
|
+
// enabled: false,
|
|
817
|
+
gt: 20,
|
|
818
|
+
oSize: 20,
|
|
819
|
+
};
|
|
820
|
+
} else {
|
|
821
|
+
if (!$grid.height && (!opts.config || !opts.config.height)) {
|
|
822
|
+
defaultOptions.maxHeight = "528px";
|
|
823
|
+
}
|
|
824
|
+
defaultOptions.scrollY = {
|
|
825
|
+
// enabled: false,
|
|
826
|
+
gt: 20,
|
|
827
|
+
oSize: 20,
|
|
828
|
+
};
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
if (opts.editSaveUrl) {
|
|
832
|
+
(defaultOptions.keepSource = true),
|
|
833
|
+
(defaultOptions.editConfig = {
|
|
834
|
+
trigger: "manual",
|
|
835
|
+
mode: "row",
|
|
836
|
+
showStatus: true,
|
|
837
|
+
autoClear: false,
|
|
838
|
+
});
|
|
839
|
+
}
|
|
840
|
+
if (opts.treeNodeUrl) {
|
|
841
|
+
defaultOptions.proxyConfig.props.result = "objx";
|
|
842
|
+
defaultOptions.pagerConfig.autoHidden = true;
|
|
843
|
+
defaultOptions.treeConfig = {
|
|
844
|
+
lazy: true,
|
|
845
|
+
children: "children",
|
|
846
|
+
hasChild: "hasChild", // 设置是否有子节点标识
|
|
847
|
+
parentField: "parent",
|
|
848
|
+
transform: true,
|
|
849
|
+
loadMethod({ $table, row }) {
|
|
850
|
+
// 模拟后台接口
|
|
851
|
+
return new Promise((resolve, reject) => {
|
|
852
|
+
let treeNodeParam = opts.treeNodeParam
|
|
853
|
+
? opts.treeNodeParam(row) || {}
|
|
854
|
+
: {
|
|
855
|
+
parent: row.id,
|
|
856
|
+
};
|
|
857
|
+
that.$http({
|
|
858
|
+
aes: opts.aes || false,
|
|
859
|
+
url: opts.treeNodeUrl,
|
|
860
|
+
method: "post",
|
|
861
|
+
data: treeNodeParam,
|
|
862
|
+
callback: (res) => {
|
|
863
|
+
if (res.type === "success") {
|
|
864
|
+
// let rows = res.objx || [];
|
|
865
|
+
let rows = res.objx ? res.objx.records || res.objx || [] : [];
|
|
866
|
+
let hasChildField = $grid.treeConfig.hasChild;
|
|
867
|
+
if (row[hasChildField] && !rows.length) {
|
|
868
|
+
row[hasChildField] = false;
|
|
869
|
+
}
|
|
870
|
+
resolve(rows);
|
|
871
|
+
if (opts.treeCallback) {
|
|
872
|
+
that.$nextTick(() => {
|
|
873
|
+
setTimeout(function () {
|
|
874
|
+
opts.treeCallback(rows, res);
|
|
875
|
+
}, 0);
|
|
876
|
+
});
|
|
877
|
+
}
|
|
878
|
+
} else {
|
|
879
|
+
reject(res);
|
|
880
|
+
}
|
|
881
|
+
},
|
|
882
|
+
});
|
|
883
|
+
});
|
|
884
|
+
},
|
|
885
|
+
};
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
result = configUtil.extendDeeply(defaultOptions, config);
|
|
889
|
+
applyTableFeatureDisabled(result, that);
|
|
890
|
+
|
|
891
|
+
let pageSize = result.pagerConfig.pageSize;
|
|
892
|
+
let pageSizes = result.pagerConfig.pageSizes;
|
|
893
|
+
if (pageSizes && !pageSizes.includes(pageSize)) {
|
|
894
|
+
for (let i = 0; i < pageSizes.length; i++) {
|
|
895
|
+
let item = pageSizes[i];
|
|
896
|
+
if (item > pageSize) {
|
|
897
|
+
pageSizes.splice(i, 0, pageSize);
|
|
898
|
+
break;
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
return result;
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
function getTableJson(tableName, that, success) {
|
|
907
|
+
if (
|
|
908
|
+
configUtil.tableConfig.disableTableName ||
|
|
909
|
+
settingConfig.tableStorageDisabled
|
|
910
|
+
)
|
|
911
|
+
return false;
|
|
912
|
+
if (!tableName) return;
|
|
913
|
+
let url = USER_PREFIX + "/table_column/getTableJson";
|
|
914
|
+
let data = {
|
|
915
|
+
tableName: tableName,
|
|
916
|
+
};
|
|
917
|
+
let json = null;
|
|
918
|
+
return that.$http({
|
|
919
|
+
url: url,
|
|
920
|
+
method: "post",
|
|
921
|
+
data: data,
|
|
922
|
+
success: success,
|
|
923
|
+
});
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
function addTableJson(that, $grid, tableName, columns, success) {
|
|
927
|
+
if (
|
|
928
|
+
configUtil.tableConfig.disableTableName ||
|
|
929
|
+
settingConfig.tableStorageDisabled
|
|
930
|
+
)
|
|
931
|
+
return false;
|
|
932
|
+
if (!tableName) return;
|
|
933
|
+
if (!columns) {
|
|
934
|
+
columns = $grid.getTableColumn().collectColumn;
|
|
935
|
+
}
|
|
936
|
+
let saveColumn = [];
|
|
937
|
+
columns.forEach(function (item, index) {
|
|
938
|
+
let columnData = {
|
|
939
|
+
field: item.field || item.property,
|
|
940
|
+
title: item.title,
|
|
941
|
+
visible: item.visible,
|
|
942
|
+
width: item.renderWidth || item.width,
|
|
943
|
+
};
|
|
944
|
+
|
|
945
|
+
// 如果有 children,递归处理
|
|
946
|
+
if (item.children && item.children.length > 0) {
|
|
947
|
+
columnData.children = processChildren(item.children);
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
saveColumn.push(columnData);
|
|
951
|
+
});
|
|
952
|
+
|
|
953
|
+
// 处理 children 的递归函数
|
|
954
|
+
function processChildren(children) {
|
|
955
|
+
let result = [];
|
|
956
|
+
children.forEach(function (childItem) {
|
|
957
|
+
let childData = {
|
|
958
|
+
field: childItem.field || childItem.property,
|
|
959
|
+
title: childItem.title,
|
|
960
|
+
visible: childItem.visible,
|
|
961
|
+
width: childItem.renderWidth || childItem.width,
|
|
962
|
+
};
|
|
963
|
+
|
|
964
|
+
// 递归处理嵌套的 children
|
|
965
|
+
if (childItem.children && childItem.children.length > 0) {
|
|
966
|
+
childData.children = processChildren(childItem.children);
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
result.push(childData);
|
|
970
|
+
});
|
|
971
|
+
return result;
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
let searchColumns = $grid.params.searchColumns || [];
|
|
975
|
+
let jsonData = {
|
|
976
|
+
columns: saveColumn,
|
|
977
|
+
searchColumns: searchColumns,
|
|
978
|
+
};
|
|
979
|
+
let exportColumns = getTableStateValue($grid, "exportColumns");
|
|
980
|
+
let exportItemColumns = getTableStateValue($grid, "exportItemColumns");
|
|
981
|
+
if (exportColumns && exportColumns.length) {
|
|
982
|
+
jsonData.exportColumns = exportColumns;
|
|
983
|
+
}
|
|
984
|
+
if (exportItemColumns && exportItemColumns.length) {
|
|
985
|
+
jsonData.exportItemColumns = exportItemColumns;
|
|
986
|
+
}
|
|
987
|
+
let json = encodeURIComponent(JSON.stringify(jsonData));
|
|
988
|
+
|
|
989
|
+
let url = USER_PREFIX + "/table_column/addTableJson";
|
|
990
|
+
let data = {
|
|
991
|
+
tableName: tableName,
|
|
992
|
+
// json: encodeURIComponent(JSON.stringify(saveColumn)),
|
|
993
|
+
json: json,
|
|
994
|
+
};
|
|
995
|
+
that.$http({
|
|
996
|
+
url: url,
|
|
997
|
+
method: "post",
|
|
998
|
+
data: data,
|
|
999
|
+
success: success,
|
|
1000
|
+
});
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
function initColumnIndex(columns) {
|
|
1004
|
+
columns.forEach(function (column, index) {
|
|
1005
|
+
if (!column.params) column.params = {};
|
|
1006
|
+
if (column.params) {
|
|
1007
|
+
column.params._index = index;
|
|
1008
|
+
column.params._visible = column.visible ?? true;
|
|
1009
|
+
}
|
|
1010
|
+
if (column.children && column.children.length > 0) {
|
|
1011
|
+
initColumnIndex(column.children);
|
|
1012
|
+
}
|
|
1013
|
+
});
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
function initColumn(option, syncColumns) {
|
|
1017
|
+
let oldColumns = option.columns;
|
|
1018
|
+
let newColumns = [];
|
|
1019
|
+
if (syncColumns) {
|
|
1020
|
+
// 按列对象配对:DB 里同 field 多行时不得反复匹配同一 oldColumn;old 删了重复列时多余 sync 行应丢弃
|
|
1021
|
+
const matchedOld = new Set();
|
|
1022
|
+
syncColumns.forEach(function (syncColumn) {
|
|
1023
|
+
const field = syncColumn.field;
|
|
1024
|
+
if (!field) return;
|
|
1025
|
+
const oldColumn = oldColumns.find(function (oc) {
|
|
1026
|
+
return oc.field === field && !matchedOld.has(oc);
|
|
1027
|
+
});
|
|
1028
|
+
if (!oldColumn) return;
|
|
1029
|
+
matchedOld.add(oldColumn);
|
|
1030
|
+
if (!oldColumn.params) oldColumn.params = {};
|
|
1031
|
+
const visibleSync =
|
|
1032
|
+
option.visibleSync !== false && oldColumn.visibleSync !== false;
|
|
1033
|
+
if (visibleSync) {
|
|
1034
|
+
oldColumn.visible = syncColumn.visible;
|
|
1035
|
+
}
|
|
1036
|
+
if (oldColumn.width !== undefined) {
|
|
1037
|
+
oldColumn.params._width = oldColumn.width;
|
|
1038
|
+
}
|
|
1039
|
+
if (syncColumn.width) oldColumn.width = syncColumn.width;
|
|
1040
|
+
newColumns.push(oldColumn);
|
|
1041
|
+
});
|
|
1042
|
+
oldColumns.forEach(function (oldColumn, index) {
|
|
1043
|
+
if (matchedOld.has(oldColumn)) return;
|
|
1044
|
+
newColumns.splice(index, 0, oldColumn);
|
|
1045
|
+
});
|
|
1046
|
+
|
|
1047
|
+
// 处理 children 中的列
|
|
1048
|
+
if (syncColumns.length > 0) {
|
|
1049
|
+
newColumns.forEach(function (newColumn) {
|
|
1050
|
+
if (newColumn.children && newColumn.children.length > 0) {
|
|
1051
|
+
// 在 syncColumns 中查找对应的父列
|
|
1052
|
+
let syncParentColumn = syncColumns.find(function (syncCol) {
|
|
1053
|
+
return syncCol.field === newColumn.field;
|
|
1054
|
+
});
|
|
1055
|
+
if (
|
|
1056
|
+
syncParentColumn &&
|
|
1057
|
+
syncParentColumn.children &&
|
|
1058
|
+
syncParentColumn.children.length > 0
|
|
1059
|
+
) {
|
|
1060
|
+
// 递归处理 children
|
|
1061
|
+
newColumn.children = initColumn(
|
|
1062
|
+
{ columns: newColumn.children },
|
|
1063
|
+
syncParentColumn.children
|
|
1064
|
+
);
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
});
|
|
1068
|
+
}
|
|
1069
|
+
} else {
|
|
1070
|
+
newColumns = oldColumns;
|
|
1071
|
+
}
|
|
1072
|
+
return newColumns;
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
function initExportColumns($grid, tableState, json) {
|
|
1076
|
+
if (json?.exportColumns?.length) {
|
|
1077
|
+
tableState.exportColumns = json.exportColumns;
|
|
1078
|
+
setTableState($grid, "exportColumns", json.exportColumns);
|
|
1079
|
+
}
|
|
1080
|
+
if (json?.exportItemColumns?.length) {
|
|
1081
|
+
tableState.exportItemColumns = json.exportItemColumns;
|
|
1082
|
+
setTableState($grid, "exportItemColumns", json.exportItemColumns);
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
function initSearchColumns(oriColumns, syncColumns) {
|
|
1087
|
+
let oldColumns = oriColumns || [];
|
|
1088
|
+
let newColumns = [];
|
|
1089
|
+
if (syncColumns) {
|
|
1090
|
+
const matchedOld = new Set();
|
|
1091
|
+
syncColumns.forEach(function (syncColumn) {
|
|
1092
|
+
const field = syncColumn.field;
|
|
1093
|
+
if (!field) return;
|
|
1094
|
+
const oldColumn = oldColumns.find(function (oc) {
|
|
1095
|
+
return oc.field === field && !oc.fixed && !matchedOld.has(oc);
|
|
1096
|
+
});
|
|
1097
|
+
if (!oldColumn) return;
|
|
1098
|
+
matchedOld.add(oldColumn);
|
|
1099
|
+
oldColumn.common = syncColumn.common || false;
|
|
1100
|
+
if (syncColumn.defaultValue !== undefined) {
|
|
1101
|
+
oldColumn.defaultValue = syncColumn.defaultValue;
|
|
1102
|
+
}
|
|
1103
|
+
newColumns.push(oldColumn);
|
|
1104
|
+
});
|
|
1105
|
+
oldColumns.forEach(function (oldColumn, index) {
|
|
1106
|
+
if (oldColumn.fixed) {
|
|
1107
|
+
newColumns.splice(index, 0, oldColumn);
|
|
1108
|
+
return;
|
|
1109
|
+
}
|
|
1110
|
+
if (matchedOld.has(oldColumn)) return;
|
|
1111
|
+
newColumns.splice(index, 0, oldColumn);
|
|
1112
|
+
});
|
|
1113
|
+
} else {
|
|
1114
|
+
newColumns = oldColumns;
|
|
1115
|
+
}
|
|
1116
|
+
return newColumns.length ? newColumns : oldColumns;
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
function onColumnWitchChange(option) {
|
|
1120
|
+
let that = option.$grid.$parent;
|
|
1121
|
+
let $grid = option.$grid;
|
|
1122
|
+
let originOption = $grid.params.originOption;
|
|
1123
|
+
let tableName = originOption.tableName;
|
|
1124
|
+
if (tableName) {
|
|
1125
|
+
// let columns = $grid.columns;
|
|
1126
|
+
const { fullColumn, tableColumn } = $grid.getTableColumn();
|
|
1127
|
+
addTableJson(that, $grid, tableName);
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
function restoreColumnPosition(currentColumns) {
|
|
1132
|
+
// 根据 params._index 排序 currentColumns
|
|
1133
|
+
let sortedColumns = [...currentColumns].sort((a, b) => {
|
|
1134
|
+
let indexA = a.params?._index ?? 0;
|
|
1135
|
+
let indexB = b.params?._index ?? 0;
|
|
1136
|
+
return indexA - indexB;
|
|
1137
|
+
});
|
|
1138
|
+
|
|
1139
|
+
// 递归处理 children
|
|
1140
|
+
sortedColumns.forEach((column) => {
|
|
1141
|
+
if (column.children && column.children.length > 0) {
|
|
1142
|
+
column.children = restoreColumnPosition(column.children);
|
|
1143
|
+
} else {
|
|
1144
|
+
column.visible = column.params?._visible ?? true;
|
|
1145
|
+
if (column.params?._width !== undefined) {
|
|
1146
|
+
column.width = column.params?._width;
|
|
1147
|
+
} else {
|
|
1148
|
+
// delete column.width;
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
});
|
|
1152
|
+
|
|
1153
|
+
return sortedColumns;
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
function customHandle(option) {
|
|
1157
|
+
let that = option.$grid.$parent;
|
|
1158
|
+
let $grid = option.$grid;
|
|
1159
|
+
let originOption = $grid.params.originOption;
|
|
1160
|
+
if (option.type === "confirm" || option.type === "reset") {
|
|
1161
|
+
let tableName = originOption.tableName;
|
|
1162
|
+
if (option.type === "reset") {
|
|
1163
|
+
const { collectColumn } = $grid.getTableColumn();
|
|
1164
|
+
|
|
1165
|
+
// 还原列的位置
|
|
1166
|
+
let oldColumns = originOption.columns || [];
|
|
1167
|
+
if (oldColumns.length > 0) {
|
|
1168
|
+
const restoredColumns = restoreColumnPosition(collectColumn);
|
|
1169
|
+
$grid.loadColumn(restoredColumns);
|
|
1170
|
+
} else {
|
|
1171
|
+
$grid.loadColumn(collectColumn);
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
if (tableName) {
|
|
1175
|
+
setTimeout(() => {
|
|
1176
|
+
addTableJson(that, $grid, tableName);
|
|
1177
|
+
}, 200);
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
if (option && option.$event && option.$event.preventDefault) {
|
|
1181
|
+
option.$event.preventDefault(); // 取消事件的默认行为
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
originOption.customCallback && originOption.customCallback(option);
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
function changeSelectCount(checked) {
|
|
1188
|
+
let checkedLength = checked.records.length;
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
function getTableData(that, tableRef, type, success) {
|
|
1192
|
+
if (
|
|
1193
|
+
configUtil.tableConfig.disableTableName ||
|
|
1194
|
+
settingConfig.tableStorageDisabled
|
|
1195
|
+
)
|
|
1196
|
+
return false;
|
|
1197
|
+
let $grid = getGrid(that, tableRef);
|
|
1198
|
+
let tableName = getTableStateValue($grid, "tableName");
|
|
1199
|
+
let url = USER_PREFIX + "/table_column/getTableData";
|
|
1200
|
+
let param = {
|
|
1201
|
+
tableName: tableName,
|
|
1202
|
+
type: type,
|
|
1203
|
+
};
|
|
1204
|
+
let data = null;
|
|
1205
|
+
return that.$http({
|
|
1206
|
+
url: url,
|
|
1207
|
+
method: "post",
|
|
1208
|
+
data: param,
|
|
1209
|
+
success: success,
|
|
1210
|
+
});
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1213
|
+
function addTableData(that, tableRef, value, success) {
|
|
1214
|
+
if (
|
|
1215
|
+
configUtil.tableConfig.disableTableName ||
|
|
1216
|
+
settingConfig.tableStorageDisabled
|
|
1217
|
+
)
|
|
1218
|
+
return false;
|
|
1219
|
+
let $grid = getGrid(that, tableRef);
|
|
1220
|
+
let tableName = getTableStateValue($grid, "tableName");
|
|
1221
|
+
if (tableName) {
|
|
1222
|
+
that.$http({
|
|
1223
|
+
method: "post",
|
|
1224
|
+
url: USER_PREFIX + "/table_column/addTableData",
|
|
1225
|
+
data: {
|
|
1226
|
+
tableName: tableName,
|
|
1227
|
+
type: "isQueryAllPage",
|
|
1228
|
+
data: value,
|
|
1229
|
+
},
|
|
1230
|
+
success: success,
|
|
1231
|
+
});
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
function checkQueryTotal(that, tableRef, value) {
|
|
1236
|
+
let $grid = getGrid(that, tableRef);
|
|
1237
|
+
setTableState($grid, "isQueryAllPage", value);
|
|
1238
|
+
let option = $grid.getProxyInfo();
|
|
1239
|
+
let pagerConfig = $grid.pagerConfig;
|
|
1240
|
+
|
|
1241
|
+
$grid.pagerConfig.layouts = pagerConfig.layouts || [];
|
|
1242
|
+
addTableData(that, tableRef, value);
|
|
1243
|
+
$grid.commitProxy("query");
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
function getPagerConfigLayouts(opts) {
|
|
1247
|
+
if (opts.showPageSizes !== false) {
|
|
1248
|
+
return ["Sizes", "PrevPage", "JumpNumber", "NextPage"];
|
|
1249
|
+
} else {
|
|
1250
|
+
return ["PrevPage", "JumpNumber", "NextPage"];
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
modules = {
|
|
1255
|
+
initVxeTable,
|
|
1256
|
+
columnDrop,
|
|
1257
|
+
rebindGrid,
|
|
1258
|
+
initOption,
|
|
1259
|
+
getTableJson,
|
|
1260
|
+
addTableJson,
|
|
1261
|
+
onColumnWitchChange,
|
|
1262
|
+
customHandle,
|
|
1263
|
+
changeSelectCount,
|
|
1264
|
+
getTableData,
|
|
1265
|
+
addTableData,
|
|
1266
|
+
checkQueryTotal,
|
|
1267
|
+
getCellValue,
|
|
1268
|
+
createParams,
|
|
1269
|
+
getTableStateValue,
|
|
1270
|
+
setTableState,
|
|
1271
|
+
};
|
|
1272
|
+
|
|
1273
|
+
if (!configUtil.Vue.prototype.$vxeTableUtil)
|
|
1274
|
+
configUtil.Vue.prototype.$vxeTableUtil = modules;
|
|
1275
|
+
|
|
1276
|
+
export default modules;
|