| | |
| | | </el-table-column> |
| | | <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> |
| | | <template #default="scope"> |
| | | <el-button link type="primary" icon="Top" @click="moveUp(scope.row)" v-hasPermi="['system:dept:edit']">上移</el-button> |
| | | <el-button link type="primary" icon="Bottom" @click="moveDown(scope.row)" v-hasPermi="['system:dept:edit']">下移</el-button> |
| | | <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:dept:edit']">修改</el-button> |
| | | <el-button link type="primary" icon="Plus" @click="handleAdd(scope.row)" v-hasPermi="['system:dept:add']">新增</el-button> |
| | | <el-button v-if="scope.row.parentId != 0" link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['system:dept:remove']">删除</el-button> |
| | |
| | | </template> |
| | | |
| | | <script setup name="Dept"> |
| | | import { listDept, getDept, delDept, addDept, updateDept, listDeptExcludeChild } from "@/api/system/dept" |
| | | import { listDept, getDept, delDept, addDept, updateDept, listDeptExcludeChild, updateDeptSort } from "@/api/system/dept" |
| | | |
| | | const { proxy } = getCurrentInstance() |
| | | const { sys_normal_disable } = proxy.useDict("sys_normal_disable") |
| | |
| | | }).catch(() => {}) |
| | | } |
| | | |
| | | /** 找到部门在同级中的位置 */ |
| | | function findSiblings(targetId, list = deptList.value) { |
| | | for (let i = 0; i < list.length; i++) { |
| | | if (list[i].deptId === targetId) { |
| | | return { list, index: i } |
| | | } |
| | | if (list[i].children && list[i].children.length) { |
| | | const r = findSiblings(targetId, list[i].children) |
| | | if (r) return r |
| | | } |
| | | } |
| | | return null |
| | | } |
| | | |
| | | /** 保存同级排序(重排 0..n-1) */ |
| | | function saveDeptSort(siblings) { |
| | | const payload = siblings.map((d, i) => ({ deptId: d.deptId, orderNum: i })) |
| | | return updateDeptSort(payload).then(() => { |
| | | proxy.$modal.msgSuccess("排序成功") |
| | | getList() |
| | | }) |
| | | } |
| | | |
| | | /** 上移 */ |
| | | function moveUp(row) { |
| | | const s = findSiblings(row.deptId) |
| | | if (!s || s.index <= 0) { |
| | | proxy.$modal.msgWarning("已经是第一个了") |
| | | return |
| | | } |
| | | const { list, index } = s |
| | | const tmp = list[index - 1] |
| | | list[index - 1] = list[index] |
| | | list[index] = tmp |
| | | saveDeptSort(list) |
| | | } |
| | | |
| | | /** 下移 */ |
| | | function moveDown(row) { |
| | | const s = findSiblings(row.deptId) |
| | | if (!s || s.index >= s.list.length - 1) { |
| | | proxy.$modal.msgWarning("已经是最后一个了") |
| | | return |
| | | } |
| | | const { list, index } = s |
| | | const tmp = list[index + 1] |
| | | list[index + 1] = list[index] |
| | | list[index] = tmp |
| | | saveDeptSort(list) |
| | | } |
| | | |
| | | getList() |
| | | </script> |
| | | |