From 3c4bc455f767e220199b7c33552e0250357535af Mon Sep 17 00:00:00 2001 From: JINGYJ <1458671527@qq.com> Date: Thu, 17 Aug 2023 16:17:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/api/user.ts | 2 +- src/views/system/dept/form.vue | 21 ++++---- src/views/system/dept/index.vue | 10 ++-- src/views/system/dept/utils/hook.tsx | 71 ++++++++++++++++------------ src/views/system/dept/utils/types.ts | 3 +- src/views/system/user/form.vue | 3 +- src/views/system/user/utils/hook.tsx | 54 +++++++++++++-------- 8 files changed, 95 insertions(+), 71 deletions(-) diff --git a/package.json b/package.json index bca49b0..49090a2 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "tp-admin", + "name": "xznsh-admin", "version": "2.0.0", "private": true, "scripts": { diff --git a/src/api/user.ts b/src/api/user.ts index 28b3f0c..53d987d 100644 --- a/src/api/user.ts +++ b/src/api/user.ts @@ -37,7 +37,7 @@ export type RefreshTokenResult = { // return http.request("post", "/login", { data }); // }; export const getLogin = (data?: object) => { - return http.request("post", baseUrlApi("organization/login"), { + return http.request("post", baseUrlApi("organization/login/"), { data }); }; diff --git a/src/views/system/dept/form.vue b/src/views/system/dept/form.vue index f7f57c1..4c51f8b 100644 --- a/src/views/system/dept/form.vue +++ b/src/views/system/dept/form.vue @@ -8,7 +8,7 @@ import { FormProps } from "./utils/types"; const props = withDefaults(defineProps(), { formInline: () => ({ higherDeptOptions: [], - parentId: 0, + parent_id: "", name: "", principal: "", phone: "", @@ -16,7 +16,8 @@ const props = withDefaults(defineProps(), { sort: 0, status: 1, remark: "", - id: "" + id: "", + is_active: true }) }); @@ -43,7 +44,7 @@ defineExpose({ getRef }); - - + --> + - + ( - - {row.status === 1 ? "启用" : "停用"} - - ) - }, + // { + // label: "状态", + // prop: "is_active", + // minWidth: 100, + // cellRenderer: ({ row, props }) => ( + // + // {row.is_active ? "启用" : "停用"} + // + // ) + // }, { label: "创建时间", minWidth: 200, - prop: "createTime", - formatter: ({ createTime }) => - dayjs(createTime).format("YYYY-MM-DD HH:mm:ss") - }, - { - label: "备注", - prop: "remark", - minWidth: 320 + prop: "insert_time", + formatter: ({ insert_time }) => + dayjs(insert_time).format("YYYY-MM-DD HH:mm:ss") }, + // { + // label: "备注", + // prop: "remark", + // minWidth: 320 + // }, { label: "操作", fixed: "right", @@ -103,11 +103,15 @@ export function useDept() { // newData = newData.filter(item => item.name.includes(form.name)); newData = filterNested(newData, item => item.name.includes(form.name)); } - if (!isAllEmpty(form.status)) { - // 前端搜索状态 - // newData = newData.filter(item => item.status === form.status); - newData = filterNested(newData, item => item.status === form.status); - } + // if (!isAllEmpty(form.is_active)) { + // // 前端搜索状态 + // // newData = newData.filter(item => item.status === form.status); + // // newData = filterNested( + // // newData, + // // item => item.is_active === form.is_active + // // ); + // newData = newData.filter(item => item.is_active === form.is_active); + // } // dataList.value = handleTree(newData); // 处理成树结构 dataList.value = newData; // 处理成树结构 setTimeout(() => { @@ -133,7 +137,7 @@ export function useDept() { props: { formInline: { higherDeptOptions: formatHigherDeptOptions(cloneDeep(dataList.value)), - parentId: row?.id ?? "", + parent_id: row?.parent_id ?? "", name: row?.name ?? "", principal: row?.principal ?? "", phone: row?.phone ?? "", @@ -141,7 +145,8 @@ export function useDept() { sort: row?.sort ?? 0, status: row?.status ?? 1, remark: row?.remark ?? "", - id: row?.id ?? "" + id: row?.id ?? "", + is_active: row?.is_active ?? true } }, width: "40%", @@ -160,8 +165,9 @@ export function useDept() { onSearch(); // 刷新表格数据 } FormRef.validate(valid => { + console.log("curData", curData); + if (valid) { - console.log("curData", curData); // 表单规则校验通过 if (title === "新增") { // 实际开发先调用新增接口,再进行下面操作 @@ -183,7 +189,8 @@ export function useDept() { // deptList.data.push(addItem); const params = { department_name: curData.name, - department_id: curData.parentId + department_id: curData.parent_id, + is_active: curData.is_active }; addDept(params).then(res => { @@ -198,7 +205,9 @@ export function useDept() { } else { const params = { name: curData.name, - id: curData.id + id: curData.id, + department_id: curData.parent_id ? curData.parent_id : null, + is_active: curData.is_active }; updateDept(params) .then(res => { diff --git a/src/views/system/dept/utils/types.ts b/src/views/system/dept/utils/types.ts index 558dcd0..b406587 100644 --- a/src/views/system/dept/utils/types.ts +++ b/src/views/system/dept/utils/types.ts @@ -1,6 +1,6 @@ interface FormItemProps { higherDeptOptions: Record[]; - parentId: number; + parent_id: string | number; name: string; principal: string; phone: string | number; @@ -9,6 +9,7 @@ interface FormItemProps { status: number; remark: string; id: string | number; + is_active: boolean; } interface FormProps { formInline: FormItemProps; diff --git a/src/views/system/user/form.vue b/src/views/system/user/form.vue index 9dd5947..9f583ac 100644 --- a/src/views/system/user/form.vue +++ b/src/views/system/user/form.vue @@ -47,7 +47,7 @@ defineExpose({ getRef }); emitPath: false, checkStrictly: true, disabled: function (data) { - if (!data.parent_id) { + if (!data.is_active) { return true; } else { return false; @@ -99,7 +99,6 @@ defineExpose({ getRef }); - diff --git a/src/views/system/user/utils/hook.tsx b/src/views/system/user/utils/hook.tsx index ea8b81b..53ef5b9 100644 --- a/src/views/system/user/utils/hook.tsx +++ b/src/views/system/user/utils/hook.tsx @@ -134,7 +134,7 @@ export function useUser() { function onChange({ row, index }) { ElMessageBox.confirm( `确认要${ - row.status === 0 ? "停用" : "启用" + row.is_active === false ? "停用" : "启用" }${ row.username }用户吗?`, @@ -148,28 +148,42 @@ export function useUser() { } ) .then(() => { - switchLoadMap.value[index] = Object.assign( - {}, - switchLoadMap.value[index], - { - loading: true + const params = { + department_id: row.department_id, + username: row.username, + phone_number: row.phone_number, + is_active: row.is_active, + gender: row.gender, + id: row.id + }; + updateUser(params).then(res => { + if (res.success) { + setTimeout(() => { + switchLoadMap.value[index] = Object.assign( + {}, + switchLoadMap.value[index], + { + loading: false + } + ); + message("已成功修改用户状态", { + type: "success" + }); + }, 300); + } else { + row.is_active === false + ? (row.is_active = true) + : (row.is_active = false); + message(`${res.msg}`, { + type: "warning" + }); } - ); - setTimeout(() => { - switchLoadMap.value[index] = Object.assign( - {}, - switchLoadMap.value[index], - { - loading: false - } - ); - message("已成功修改用户状态", { - type: "success" - }); - }, 300); + }); }) .catch(() => { - row.status === 0 ? (row.status = 1) : (row.status = 0); + row.is_active === false + ? (row.is_active = true) + : (row.is_active = false); }); }