diff --git a/src/views/business/common-route.vue b/src/views/business/common-route.vue index 9840ca8..b1c7b14 100644 --- a/src/views/business/common-route.vue +++ b/src/views/business/common-route.vue @@ -436,7 +436,25 @@ export default { return result; }, defaultDeptId() { - return (this.userInfo && (this.userInfo.deptId || this.userInfo.dept_id)) || ''; + const raw = (this.userInfo && (this.userInfo.deptId || this.userInfo.dept_id)) || ''; + return ( + String(raw) + .split(',') + .map(item => item.trim()) + .filter(Boolean)[0] || '' + ); + }, + normalizeListQuery(params = {}) { + const query = { ...params, ...this.query }; + const rawDeptId = query.deptId ?? query.searchDeptId; + delete query.searchDeptId; + if (rawDeptId !== undefined && rawDeptId !== null && String(rawDeptId).trim() !== '') { + query.deptId = String(rawDeptId).split(',')[0].trim(); + } else { + delete query.deptId; + } + query.allDept = this.isAdmin ? 1 : 0; + return query; }, applyDefaultDeptSearch() { const deptId = this.defaultDeptId(); @@ -999,9 +1017,9 @@ export default { this.onLoad(this.page, this.query); }, searchChange(params, done) { - this.query = params; + this.query = this.normalizeListQuery(params); this.page.currentPage = 1; - this.onLoad(this.page, params); + this.onLoad(this.page, this.query); done(); }, selectionChange(list) { @@ -1024,12 +1042,10 @@ export default { }, onLoad(page, params = {}) { this.loading = true; + const query = this.normalizeListQuery(params); + this.query = query; api - .getList(page.currentPage, page.pageSize, { - ...params, - ...this.query, - allDept: this.isAdmin ? 1 : 0, - }) + .getList(page.currentPage, page.pageSize, query) .then(res => { const result = res.data.data; this.page.total = result.total; @@ -1042,8 +1058,7 @@ export default { }, buildExportParams() { return { - ...this.query, - allDept: this.isAdmin ? 1 : 0, + ...this.normalizeListQuery(this.query), ids: this.ids, [this.website.tokenHeader]: getToken(), }; diff --git a/src/views/business/process-config.vue b/src/views/business/process-config.vue index 05ef0be..4495ce5 100644 --- a/src/views/business/process-config.vue +++ b/src/views/business/process-config.vue @@ -565,7 +565,13 @@ export default { }); }, defaultDeptId() { - return (this.userInfo && (this.userInfo.deptId || this.userInfo.dept_id)) || ''; + const raw = (this.userInfo && (this.userInfo.deptId || this.userInfo.dept_id)) || ''; + return ( + String(raw) + .split(',') + .map(item => item.trim()) + .filter(Boolean)[0] || '' + ); }, applyDefaultDeptSearch() { const deptId = this.defaultDeptId(); @@ -580,15 +586,32 @@ export default { }); }, flattenDept(tree, level = 0) { - return tree.flatMap(item => [ - { - label: `${' '.repeat(level)}${item.title || item.deptName || item.name}`, - value: item.id, - }, - ...(item.children && item.children.length - ? this.flattenDept(item.children, level + 1) - : []), - ]); + return tree.flatMap(item => { + const id = + item.id === undefined || item.id === null || item.id === '' ? '' : String(item.id); + if (!id) return []; + return [ + { + label: `${' '.repeat(level)}${item.title || item.deptName || item.name}`, + value: id, + }, + ...(item.children && item.children.length + ? this.flattenDept(item.children, level + 1) + : []), + ]; + }); + }, + normalizeListQuery(params = {}) { + const query = { ...params, ...this.query }; + const rawDeptId = query.deptId ?? query.searchDeptId; + delete query.searchDeptId; + if (rawDeptId !== undefined && rawDeptId !== null && String(rawDeptId).trim() !== '') { + query.deptId = String(rawDeptId).split(',')[0].trim(); + } else { + delete query.deptId; + } + query.allDept = this.isAdmin ? 1 : 0; + return query; }, displayStatus(status) { const statusMap = { @@ -1074,9 +1097,9 @@ export default { this.onLoad(this.page, this.query); }, searchChange(params, done) { - this.query = params; + this.query = this.normalizeListQuery(params); this.page.currentPage = 1; - this.onLoad(this.page, params); + this.onLoad(this.page, this.query); done(); }, selectionChange(list) { @@ -1099,12 +1122,10 @@ export default { }, onLoad(page, params = {}) { this.loading = true; + const query = this.normalizeListQuery(params); + this.query = query; api - .getList(page.currentPage, page.pageSize, { - ...params, - ...this.query, - allDept: this.isAdmin ? 1 : 0, - }) + .getList(page.currentPage, page.pageSize, query) .then(res => { const result = res.data.data || {}; this.page.total = result.total || 0; @@ -1117,8 +1138,7 @@ export default { }, buildExportParams() { return { - ...this.query, - allDept: this.isAdmin ? 1 : 0, + ...this.normalizeListQuery(this.query), ids: this.ids, [this.website.tokenHeader]: getToken(), };