From b51d4ded90955772c81d3959e48f306e47b833e7 Mon Sep 17 00:00:00 2001 From: xuhuajiao <13476289682@163.com> Date: Fri, 2 Jun 2023 17:34:36 +0800 Subject: [PATCH] =?UTF-8?q?=E9=83=A8=E9=97=A8=E7=AE=A1=E7=90=86api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/system/dept.js | 30 ++- src/components/Crud/crud.js | 2 +- src/views/system/dept/index.vue | 290 +++++++++++++++++-------- src/views/system/groupManage/index.vue | 2 +- 4 files changed, 221 insertions(+), 103 deletions(-) diff --git a/src/api/system/dept.js b/src/api/system/dept.js index 636ce1d..c02dd1b 100644 --- a/src/api/system/dept.js +++ b/src/api/system/dept.js @@ -1,13 +1,5 @@ import request from '@/utils/request' -export function getDeptsList(params) { - return request({ - url: 'api/depts/initDeptsList', - method: 'get', - params - }) -} - export function getDepts(params) { return request({ url: 'api/depts/initDeptsList', @@ -33,11 +25,11 @@ export function add(data) { }) } -export function del(ids) { +export function del(data) { return request({ url: 'api/depts/delDepts', method: 'post', - data: ids + data }) } @@ -49,4 +41,20 @@ export function edit(data) { }) } -export default { add, edit, del, getDepts, getDeptSuperior, getDeptsList } +export function FetchUpdateDeptsStatus(data) { + return request({ + url: '/api/depts/updateDeptsStatus', + method: 'post', + data + }) +} + +export function FetchSonDepts(params) { + return request({ + url: '/api/depts/getSonDepts', + method: 'get', + params + }) +} + +export default { add, edit, del, getDepts, getDeptSuperior, FetchUpdateDeptsStatus, FetchSonDepts } diff --git a/src/components/Crud/crud.js b/src/components/Crud/crud.js index 011f878..3807871 100644 --- a/src/components/Crud/crud.js +++ b/src/components/Crud/crud.js @@ -32,7 +32,7 @@ function CRUD(options) { // 重置表单 defaultForm: () => {}, // 排序规则,默认 id 降序, 支持多字段排序 ['id,desc', 'createTime,asc'] - sort: ['update_time,desc'], + sort: [], // 等待时间 time: 50, // CRUD Method diff --git a/src/views/system/dept/index.vue b/src/views/system/dept/index.vue index d0f792d..48d7acb 100644 --- a/src/views/system/dept/index.vue +++ b/src/views/system/dept/index.vue @@ -4,10 +4,9 @@
- +
- - +
@@ -15,22 +14,35 @@
- + + + +
- + - 启用 停用 @@ -99,23 +111,39 @@ @select="crud.selectChange" @select-all="crud.selectAllChange" @selection-change="crud.selectionChangeHandler" + @expand-change="expandChange" > - + + + + - @@ -143,17 +171,26 @@ import { LOAD_CHILDREN_OPTIONS } from '@riophae/vue-treeselect' import CRUD, { presenter, header, form, crud } from '@crud/crud' import rrOperation from '@crud/RR.operation' import crudOperation from '@crud/CRUD.operation' -// import udOperation from '@crud/UD.operation' import DateRangePicker from '@/components/DateRangePicker' import pagination from '@crud/Pagination' import Vue from 'vue' +import { exportFile } from '@/utils/index' +import qs from 'qs' +import { mapGetters } from 'vuex' const defaultForm = { id: null, fondsId: null, deptsCode: '', deptsName: '', deptsAbbr: '', isTop: '1', deptsParentsId: null, deptsOrders: 999, deptsStatus: null } export default { name: 'Dept', components: { Treeselect, crudOperation, rrOperation, DateRangePicker, pagination }, cruds() { - return CRUD({ title: '部门', url: 'api/depts/initDeptsList', crudMethod: { ...crudDept }}) + return CRUD({ title: '部门', idField: 'deptsId', url: 'api/depts/initDeptsList', crudMethod: { ...crudDept }, optShow: { + add: true, + edit: true, + del: false, + reset: true, + download: false, + group: false + }}) }, mixins: [presenter(), header(), form(defaultForm), crud()], // 设置数据字典 @@ -187,11 +224,14 @@ export default { { required: true, message: '请选择状态', trigger: 'change' } ] }, - deptName: '', deptDatas: [], jobs: [], level: 3, roles: [], + fondsName: '', deptDatas: [], jobs: [], level: 3, roles: [], jobDatas: [], roleDatas: [], // 多选时使用 fondsDatas: [], + filterText: '', defaultExpandedKeys: [], fondsOptions: [], + blurryTime: null, + deleteData: [], defaultProps: { children: 'children', label: 'fondsName' }, permission: { add: ['admin', 'dept:add'], @@ -199,15 +239,54 @@ export default { del: ['admin', 'dept:del'] }, enabledTypeOptions: [ - { key: 'true', display_name: '正常' }, - { key: 'false', display_name: '禁用' } - ] + { key: '1', display_name: '激活' }, + { key: '0', display_name: '锁定' } + ], + expandData: [] + } + }, + computed: { + ...mapGetters([ + 'baseApi' + ]) + }, + watch: { + filterText(val) { + this.$refs.tree.filter(val) } }, mounted() { this.getFondsDatas() }, methods: { + expandChange(row, expandRow) { + crudDept.FetchSonDepts({ deptsId: row.deptsId }).then(res => { + console.log(res) + this.expandData = res + }) + }, + tableRowInserted({ row, parentRow, $index }) { + if (parentRow) { + crudDept.FetchSonDepts({ deptsId: row.deptsId }).then(res => { + console.log(res) + parentRow.children.splice(1, 0, 1) + }) + + parentRow.children.splice(1) + // const data = crud.FetchSonDepts(row.id) // 使用异步请求获取数据 + // data.then((result) => { + // result.forEach((item, index) => { + // parentRow.children.splice($index + index + 1, 0, item) // 将新数据插入到父行的children属性中 + // }) + // }) + } + }, + [CRUD.HOOK.beforeRefresh]() { + if (this.blurryTime) { + this.crud.query.startTime = this.blurryTime[0] + this.crud.query.endTime = this.blurryTime[1] + } + }, getDeptDatas(tree, treeNode, resolve) { const params = { pid: tree.id } setTimeout(() => { @@ -227,60 +306,48 @@ export default { this.$nextTick(() => { Vue.set(this.defaultExpandedKeys, 0, this.fondsDatas[0].children[0].id) this.$refs.tree.setCurrentKey(this.fondsDatas[0].children[0].id) + this.handleNodeClick(this.fondsDatas[0].children[0]) }) }) }, + filterNode(value, data) { + if (!value) return true + return data.fondsName.indexOf(value) !== -1 + }, handleNodeClick(val) { if (val) { - console.log(val) - const params = { - fondsName: val.fondsName, - fondsNo: val.fondsNo + if (val.id !== 0) { + this.query.fondsName = val.fondsName + this.query.fondsNo = val.fondsNo + this.crud.toQuery() } - crudDept.getDeptsList(params).then(res => { - console.log(res) - }) } }, + changeValue(value) { + var obj = {} + obj = this.fondsOptions.find(function(item) { + return item.id === value + }) + this.form.deptsParentsId = null + const params = { + 'fondsId': obj.id, + 'fondsName': obj.fondsName, + 'status': 1 + } + this.getDepts(params) + }, // 新增与编辑前做的操作 [CRUD.HOOK.afterToCU](crud, form) { - // if (form.isTop === '1') { - // form.deptsParentsId = 0 - // } else { - // form.deptsParentsId = '' - // } - // console.log(form) - // if (form.pid !== null) { - // form.isTop = '0' - // } else if (form.id !== null) { - // form.isTop = '1' - // } - // form.enabled = `${form.enabled}` - // if (form.id != null) { - // this.getSupDepts(form.id) - // } else { - // this.getDepts() - // } - }, - getSupDepts(id) { - crudDept.getDeptSuperior(id).then(res => { - const date = res.content - this.buildDepts(date) - this.depts = date - }) + if (form.fondsId !== null) { + this.getDepts() + } }, - buildDepts(depts) { - depts.forEach(data => { - if (data.children) { - this.buildDepts(data.children) - } - if (data.hasChildren && !data.children) { - data.children = null - } - }) + // 编辑前 + [CRUD.HOOK.beforeToEdit](crud, form) { + crud.form.id = form.deptsId }, - getDepts() { - crudDept.getDepts({ enabled: true }).then(res => { + getDepts(params) { + crudDept.getDepts(params).then(res => { this.depts = res.content.map(function(obj) { if (obj.hasChildren) { obj.children = null @@ -292,7 +359,7 @@ export default { // 获取弹窗内部门数据 loadDepts({ action, parentNode, callback }) { if (action === LOAD_CHILDREN_OPTIONS) { - crudDept.getDepts({ enabled: true, pid: parentNode.id }).then(res => { + crudDept.getDepts({ status: 1, pid: parentNode.id }).then(res => { parentNode.children = res.content.map(function(obj) { if (obj.hasChildren) { obj.children = null @@ -306,41 +373,84 @@ export default { } }, // 提交前的验证 - [CRUD.HOOK.afterValidateCU]() { - if (this.form.pid !== null && this.form.pid === this.form.id) { - this.$message({ - message: '上级部门不能为空', - type: 'warning' - }) - return false + [CRUD.HOOK.afterValidateCU](crud) { + if (crud.form.isTop === '1') { + crud.form.deptsParentsId = null } - if (this.form.isTop === '1') { - this.form.deptsParentsId = null - } - delete this.form.isTop - console.log(form) + delete crud.form.isTop return true }, + toDelete(datas) { + this.deleteData = datas + this.$confirm('此操作将删除当前所选' + this.crud.title + '你是否还要继续?', '提示', { + confirmButtonText: '继续', + cancelButtonText: '取消', + type: 'warning', + dangerouslyUseHTMLString: true + }).then(() => { + this.crud.delAllLoading = true + const ids = [] + this.deleteData.forEach(val => { + ids.push(val.deptsId) + }) + crudDept.del(ids).then(() => { + this.crud.notify('删除成功', CRUD.NOTIFICATION_TYPE.SUCCESS) + this.crud.delAllLoading = false + this.crud.refresh() + }).catch(err => { + this.crud.delAllLoading = false + console.log(err) + }) + }).catch(() => { + }) + }, // 改变状态 changeStatus(data, val) { + data.id = data.deptsId this.$confirm('此操作将禁用 / 启用部门 “' + data.deptsName + '”' + '你是否还要继续?', '提示', { confirmButtonText: '继续', cancelButtonText: '取消', type: 'warning', dangerouslyUseHTMLString: true }).then(() => { - crudDept.edit(data).then(res => { - this.crud.notify(this.dict.label.dept_status[val] + '成功', CRUD.NOTIFICATION_TYPE.SUCCESS) - }).catch(err => { - data.enabled = !data.enabled - console.log(err.response.data.message) + crudDept.FetchUpdateDeptsStatus(data).then(res => { + this.crud.notify('修改成功', CRUD.NOTIFICATION_TYPE.SUCCESS) + }).catch(() => { + data.deptsStatus = !data.deptsStatus + }) + }).catch(() => { + this.crud.notify('已取消修改', CRUD.NOTIFICATION_TYPE.INFO) + data.deptsStatus = data.deptsStatus ? 0 : 1 + }) + }, + doExport(data) { + crud.downloadLoading = true + this.$confirm('此操作将导出所选数据' + '你是否还要继续?', '提示', { + confirmButtonText: '继续', + cancelButtonText: '取消', + type: 'warning', + dangerouslyUseHTMLString: true + }).then(() => { + const ids = [] + data.forEach(val => { + ids.push(val.deptsId) }) + const params = { + 'deptsIds': ids + } + exportFile(this.baseApi + '/api/depts/download?' + qs.stringify(params, { indices: false })) }).catch(() => { - data.enabled = !data.enabled }) }, - checkboxT(row, rowIndex) { - return row.id !== 1 + normalizer(node) { + if (node.children && !node.children.length) { + delete node.children + } + return { + id: node.deptsId, + label: node.deptsName, + children: node.children + } } } } diff --git a/src/views/system/groupManage/index.vue b/src/views/system/groupManage/index.vue index a4841d7..52743ad 100644 --- a/src/views/system/groupManage/index.vue +++ b/src/views/system/groupManage/index.vue @@ -285,7 +285,7 @@ export default { }) }).catch(() => { this.crud.notify('已取消修改', CRUD.NOTIFICATION_TYPE.INFO) - data.fondsStatus = !data.fondsStatus + data.fondsStatus = data.fondsStatus ? 0 : 1 }) }, doExport(data) {