UNPKG

sohelp-ele

Version:

SohelpEle Library

362 lines (361 loc) 11.9 kB
"use strict"; var TableConfigurationMixin = { data() { return { tableConfiguration: { requestValue: "", primaryKey: "", url: "/engine/service/crud/page", namespace: "", toolbars: [], defaultValues: {}, colors: [], more: [], requestParams: "", extendEntity: "", operationToolbars: [], properties: [] }, columns: [], original: [], filters: { data: {}, type: {} } }; }, methods: { saveConfiguration() { }, _getGroupColumns() { var _a, _b; let _columns = []; let arr = []; for (let i = 0; i < ((_b = (_a = this.tableConfiguration) == null ? void 0 : _a.properties) == null ? void 0 : _b.length); i++) { let recordData = this.tableConfiguration.properties[i]; let data = {}; if (recordData.groupHeader) { data = { label: recordData.groupHeader, type: "header", children: [this._switchToColumn(recordData, true)] }; } else { data = this._switchToColumn(recordData); } let group = false; arr.forEach((e) => { if (data.label === e.label) { e.children.push(data.children[0]); group = true; } }); if (!group) { arr.push(data); } } _columns = arr; return _columns; }, _switchToColumn(recordData, group) { if (group) { let data = { "name": recordData.name, label: recordData.header, i18n: recordData.i18n, prop: recordData.name, editor: recordData.editor, editable: recordData.editable, width: parseInt(recordData.width), align: recordData.align ? recordData.align : "", customFilterDropdown: recordData.filter, slot: recordData.name, resizable: true, type: recordData.type, show: parseInt(recordData.hidden) ? false : true, not_null: recordData.not_null ? recordData.not_null : "", length: recordData.length, fixed: recordData.lock === "1" ? "right" : false, render: recordData.render, multiline: recordData.multiline, editorParam: recordData.editor_param, summaryRender: recordData.summaryRender, dict: recordData.dict, digits: recordData.digits }; if (recordData.sort) { data.sortable = "custom"; } return data; } else { let data = { "name": recordData.name, digits: recordData.digits, label: recordData.header, i18n: recordData.i18n, prop: recordData.name, editor: recordData.editor, editable: recordData.editable, width: parseInt(recordData.width), align: recordData.align ? recordData.align : "", customFilterDropdown: recordData.filter, slot: recordData.name, headerSlot: recordData.name + "Header", resizable: true, type: recordData.type, show: parseInt(recordData.hidden) ? false : true, not_null: recordData.not_null ? recordData.not_null : "", length: recordData.length, fixed: recordData.lock === "1" ? "right" : false, render: recordData.render, multiline: recordData.multiline, editorParam: recordData.editor_param, summaryRender: recordData.summaryRender, dict: recordData.dict }; if (recordData.sort) { data.sortable = "custom"; } return data; } }, _getColumns() { let _columns = []; for (let i = 0; i < this.tableConfiguration.properties.length; i++) { let recordData = this.tableConfiguration.properties[i]; _columns.push(this._switchToColumn(recordData)); } return _columns; }, getBatchDeleteButton() { }, getMoreActionButton() { var _a, _b; (_b = (_a = this.tableConfiguration) == null ? void 0 : _a.operationToolbars) == null ? void 0 : _b.forEach((e) => { if (e.buttonType === "more") { this.tableConfiguration.more.push(e); this.judge = true; } }); }, tableSearch(filterType, filters) { this.filters = { data: filters, type: filterType }; this.reload(); }, async _initTableConfiguration(config) { let sum = 0; let cfg = { operationToolbars: config.operationToolbars, extendEntity: config.extendEntity, properties: config.properties, toolbars: config.toolbars, requestParams: config.requestParams, colors: config.colors, requestValue: config.extendEntity }; if (config.requestType === "url") { cfg["url"] = config.requestValue; } else if (config.requestType === "namespace") { cfg["namespace"] = config.requestValue; } cfg.toolbars.forEach((item) => { if (item.buttonType === "common") { item.loading = false; } }); this.tableConfiguration = Object.assign(this.tableConfiguration, cfg); let properties = config.properties; let primaryData = properties.slice(0); let group = false; for (let i = 0; i < properties.length; i++) { let recordData = properties[i]; if (primaryData[i]["primary_key"] === "1") { this.tableConfiguration.primaryKey = primaryData[i].name; } if (primaryData[i]["default_value"]) { this.tableConfiguration.defaultValues[primaryData[i].name] = primaryData[i].default_value; } if (recordData.width) { sum = sum + parseInt(recordData.width); } properties.forEach((e) => { if (e.groupHeader) { group = true; } }); if (recordData.editor === "dictcombo") { let _params = this.getEditorConfig(recordData.editor_param); if (_params.data) { this.dictData[recordData.name] = _params.data; } else { let dictResponse = await this.getDictSelectData(recordData.dict); let _data = dictResponse.data; if (dictResponse.meta.success) { if (_params == null ? void 0 : _params.mappingFields) { const { label, value } = _params.mappingFields; _data.map((item) => { item.label = item[label]; item.value = item[value]; }); } this.dictData[recordData.name] = _data; } else { this.$message.error(dictResponse.meta.message); } } } if (recordData.editor === "dyncombo") { let _params = this.getEditorConfig(recordData.editor_param); if (_params.data) { this.dynSelectData[recordData.name] = _params.data; } else { let res = await this.getDynSelectData(_params); let _data = res.data; if (res.meta.success) { if (_params == null ? void 0 : _params.mappingFields) { const { label, value } = _params.mappingFields; _data.map((item) => { item.label = item[label]; item.value = item[value]; }); } this.dynSelectData[recordData.name] = _data; } else { this.$message.error(res.meta.message); } } } } this.original = this._getColumns(); this.columns = !group ? this._getColumns() : this._getGroupColumns(); this.columns.forEach((r) => { if (r == null ? void 0 : r.i18n) { const i18n = this.$t(r.i18n); if (i18n && i18n != r.i18n) { r.label = i18n; } } }); if (this.rowNumber) { let indexColumn = { columnKey: "index", type: "index", width: 45, align: "center", label: "#", showOverflowTooltip: true }; this.columns.unshift(indexColumn); } if (this.rowCheckbox === true) { let selectionColumn = { columnKey: "selection", type: "selection", width: 50, reserveSelection: true, align: "center" }; this.columns.unshift(selectionColumn); } this.getMoreActionButton(); }, async loadColumns(refid) { this.loading = true; this.done = false; if (!this.refid) { return Promise.reject("\u8BF7\u914D\u7F6ERefid\u53C2\u6570"); } let res = await SohelpHttp.get("/engine/web/ele/grid/read", { refid }); this.done = true; if (res.meta.success) { this._initTableConfiguration(res.data); this.done = true; Promise.resolve(res); } else { this.done = true; Promise.reject(res.meta.message); } return res; }, getFilterParams() { let filters = this.filters.data; let filtersType = this.filters.type; let filtersArray = Object.keys(filters); let filtersTypeArray = Object.keys(filtersType); let filtersVarArray = filtersArray.map(function(i) { return filters[i]; }); let filtersTypeVarArray = filtersTypeArray.map(function(i) { return filtersType[i]; }); let data = { offset: this.start, limit: this.isPaging ? this.limit : null, filters: [] }; for (let i = 0; i < filtersArray.length; i++) { let res = {}; let rec = filtersArray[i].split(","); let figure = this.getColumnConfig(rec[0]); res.field = rec[0]; res.data = { type: figure, value: filtersVarArray[i], comparison: "" }; for (let j = 0; j < filtersTypeArray.length; j++) { if (filtersTypeArray[j] == filtersArray[i]) { res.data.comparison = filtersTypeVarArray[i]; } } data.filters.push(res); } let dataString = encodeURI(JSON.stringify(data)); return Object.assign(this.params, { filters: dataString }); }, getColumnConfig(name) { let column = this.columns; let filtersType = ""; column.forEach((e) => { if (e.slot == name) { filtersType = e.type; } }); return filtersType; }, getDictSelectData(dict) { return SohelpHttp.get("/admin/system/dict/category/getDataList", { dictName: dict }); }, getDynSelectData(editorParams) { let { url, params } = editorParams; return SohelpHttp.get(url, params); }, getEditorConfig(editorParams) { if (!editorParams) { return {}; } return Function('"use strict"; return (' + editorParams + ")")(); }, onColumnRender(value, record, column, index) { var _a, _b, _c, _d; if (column.render) { let func = new Function("value", "record", "column", "index", column.render); return func.call(this, value, record, column, index); } else if (column.editor == "dictcombo") { let _data = (_a = this.dictData[column.name]) == null ? void 0 : _a.find((item) => item.value === value); return (_b = _data == null ? void 0 : _data.label) != null ? _b : value; } else if (column.editor == "dyncombo") { let _data = (_c = this.dynSelectData[column.name]) == null ? void 0 : _c.find((item) => item.value === value); return (_d = _data == null ? void 0 : _data.label) != null ? _d : value; } else { return value; } } } }; module.exports = TableConfigurationMixin;