Sfoglia il codice sorgente

feat: v4版本组织管理,添加全局 disabled

qindao 1 anno fa
parent
commit
528f80067b

+ 35 - 5
src/api/auth/dept.ts

@@ -1,6 +1,5 @@
 import { http } from '@/utils/http/axios';
-import { DeptPageRequest } from '@/types/dept/type';
-import { QueryUserGroupListRes } from '@/types/dept/type';
+import { DeptTreeItem , addDeptProps} from '@/types/dept/type';
 
 /**
  * @description: 部门列表
@@ -68,13 +67,44 @@ export function deleteDept(params) {
   });
 }
 
+
 /**
- * @description: V4:组织列表
+ * @description: V4: 添加组织
  */
- export function queryUserGroupList(params:DeptPageRequest):QueryUserGroupListRes {
+export function saveDept(params) {
   return http.request({
-    url: '/userGroup/queryUserGroupList',
+    url: '/admin/dept/saveDept',
     method: 'post',
     params,
   });
+}
+
+/**
+ * @description: V4:编辑组织
+ */
+export function updateDepartments(params:addDeptProps) {
+  return http.request({
+    url: '/admin/dept/updateDept',
+    method: 'post',
+    params,
+  });
+}
+
+// v4: 获取所有组织
+export function getAllDepartments(): Promise<DeptTreeItem[]> {
+  return http.request({
+    url: '/admin/dept/queryAllDeptTree',
+    method: 'post',
+  });
+}
+
+
+/**
+ * @description:V4: 删除部门
+ */
+export function deleteDepartments(deptId:number) {
+  return http.request({
+    url: `/admin/dept/deleteDept?deptId=${deptId}`,
+    method: 'DELETE',
+  });
 }

+ 7 - 1
src/types/common/constants.ts

@@ -1 +1,7 @@
-export const DEFAULT_PAGE_SIZE = 10;
+export const DEFAULT_PAGE_SIZE = 10;
+
+// 状态: 0-启用, 1-禁用
+export enum IS_DISABLED {
+  NO = 0,
+  YES = 1
+}

+ 19 - 17
src/types/dept/type.ts

@@ -1,20 +1,22 @@
-import { PaginationRequest, PaginationResponse } from '@/types/common/type';
+import { id } from "element-plus/es/locale"
 
-export type DeptPageRequest = PaginationRequest & {
-  queryStr: string;
+/* V4: 部门树结构 */
+export interface DeptTreeItem {
+  id: number | null,
+  deptName: string, // 部门名称
+  parentId: number | null, // 上级部门 id
+  orderNum: number | undefined, // 排序
+  isDisabled: boolean | number, // 状态: 0-启用, 1-禁用
+  createdBy: number, // 创建人
+  updatedBy: number, // 更新人
+  createdAt: string, // 创建时间
+  updatedAt: string, // 更新时间
+  isDeleted: number, // 0-未删除。 大于 0-已删除
+  tenantId: number, // 租户 ID
 }
 
-export interface DeptListItem {
-  /*用户组id */
-  id: number;
-  /*用户组名称 */
-  name: string;
-  /*分组描述 */
-  description: string;
-  /*人数 */
-  total: number;
-  /*操作人姓名 */
-  operatorName: string;
-  /*操作时间 */
-  operationTime: string;
-}
+export type DeptTree = DeptTreeItem & { children: DeptTreeItem[] }
+
+export type addDeptProps = Pick<DeptTreeItem, 'isDisabled' | 'parentId' | 'deptName' | 'orderNum'>
+
+export type editDeptProps = addDeptProps & {id: DeptTreeItem['id']}

+ 51 - 38
src/views/auth/dept/CreateDrawer.vue

@@ -10,20 +10,20 @@
       <el-form-item label="部门名称" prop="deptName">
         <el-input placeholder="请输入部门名称" v-model="formParams.deptName" />
       </el-form-item>
-      <el-form-item label="上级部门" prop="parent">
+      <el-form-item label="上级部门" prop="parentId">
         <el-tree-select
           :data="getTreeList"
           clearable
           check-strictly
-          v-model="formParams.parent"
+          v-model="formParams.parentId"
           placeholder="请选择上级部门"
         />
       </el-form-item>
       <el-form-item label="排序" prop="orderNum">
         <el-input-number placeholder="请输入排序" v-model="formParams.orderNum" />
       </el-form-item>
-      <el-form-item label="状态" prop="isEnable">
-        <el-switch v-model="formParams.isEnable">
+      <el-form-item label="状态" prop="isDisabled">
+        <el-switch v-model="formParams.isDisabled">
           <template #checked> 启用 </template>
           <template #unchecked> 禁用 </template>
         </el-switch>
@@ -40,13 +40,13 @@
 </template>
 
 <script lang="ts" setup>
-  import { ref, computed } from 'vue';
+  import { ref, computed, watch } from 'vue';
   import { ElMessage } from 'element-plus';
-  import type { formParamsType } from './types';
-
-  import { addDept, editDept, deptInfo } from '@/api/auth/dept';
-
+  import type { editDeptProps } from '@/types/dept/type';
+  import {  deptInfo, updateDepartments, saveDept } from '@/api/auth/dept';
   import { replaceParams } from '@/utils/helper/treeHelper';
+  import { IS_DISABLED } from '@/types/scene/constant';
+  import { DeptTreeItem } from '@/types/dept/type';
 
   const rules = {
     deptName: {
@@ -57,25 +57,18 @@
   };
 
   const emit = defineEmits(['change']);
-
-  const props = defineProps({
-    title: {
-      type: String,
-      default: '添加部门',
-    },
-    width: {
-      type: Number,
-      default: 450,
-    },
-    deptList: {
-      type: Array,
+  const props = withDefaults(
+    defineProps<{ title: string; width: number; deptList: Array<DeptTreeItem>; dataSource: DeptTreeItem; }>(),
+    {
+      title: '添加部门',
+      width: 450,
     },
-  });
+  );
 
   const defaultValueRef = () => ({
-    deptId: null,
-    parent: null,
-    isEnable: true,
+    id: null,
+    parentId: null,
+    isDisabled: true,
     deptName: '',
     orderNum: undefined,
   });
@@ -90,16 +83,16 @@
       {
         label: '顶级部门',
         value: 0,
-        children: replaceParams(props.deptList || [], 'deptName', 'deptId'),
+        children: replaceParams(props.deptList || [], 'deptName', 'id'),
       },
     ];
   });
 
-  const formParams = ref<formParamsType>(defaultValueRef());
+  const formParams = ref<editDeptProps>(defaultValueRef());
 
-  function openDrawer(deptId?) {
-    if (deptId) {
-      formParams.value.deptId = deptId;
+  function openDrawer(id?) {
+    if (id) {
+      formParams.value.id = id;
       getInfo();
       return;
     }
@@ -115,16 +108,19 @@
       if (!valid) {
         return message.error('请填写完整信息');
       }
-      const msg = formParams.value.deptId ? '编辑成功' : '添加成功';
-      if (formParams.value.deptId) {
-        editDept(formParams.value).then((_) => {
+      const msg = formParams.value.id ? '编辑成功' : '添加成功';
+      const params = { ...formParams.value };
+      params.isDisabled = formParams.value.isDisabled ? IS_DISABLED.FALSE : IS_DISABLED.TRUE;
+      if (formParams.value.id) {
+        updateDepartments(params).then(() => {
           message.success(msg);
           emit('change');
           handleReset();
           closeDrawer();
         });
       } else {
-        addDept(formParams.value).then((_) => {
+        delete params.id
+        saveDept(params).then(() => {
           message.success(msg);
           emit('change');
           handleReset();
@@ -140,11 +136,11 @@
   }
 
   function getInfo() {
-    deptInfo({ id: formParams.value.deptId }).then((res) => {
+    deptInfo({ id: formParams.value.id }).then((res) => {
       const params = {
-        deptId: res.deptId,
-        parent: res.parent,
-        isEnable: res.isEnable,
+        id: res.id,
+        parentId: res.parentId,
+        isDisabled: res.isDisabled,
         deptName: res.deptName,
         orderNum: res.orderNum,
       };
@@ -153,6 +149,23 @@
     });
   }
 
+  watch(
+    () => props.dataSource,
+    (value) => {
+      if (value) {
+        Object.entries(value).forEach(([key, value]) => {
+          if (['id', 'parentId', 'deptName', 'orderNum'].includes(key)) {
+            formParams.value[key] = value;
+          }
+        })
+        formParams.value.isDisabled = value?.isDisabled === IS_DISABLED.FALSE ? true : false; 
+      }
+    },
+    {
+      immediate: true
+    }
+  )
+
   defineExpose({
     openDrawer,
     closeDrawer,

+ 0 - 12
src/views/auth/dept/columns.ts

@@ -2,18 +2,6 @@ import { BasicColumn } from '@/components/Table';
 import { h } from 'vue';
 
 export const columns: BasicColumn[] = [
-  // {
-  //   label: '部门名称',
-  //   prop: 'deptName',
-  // },
-  // {
-  //   label: '上级部门名称',
-  //   prop: 'parentName',
-  // },
-  // {
-  //   label: '排序',
-  //   prop: 'orderNum',
-  // },
   {
     label: '组织名称',
     prop: 'deptName',

+ 20 - 35
src/views/auth/dept/dept.vue

@@ -1,26 +1,5 @@
 <template>
   <PageWrapper>
-    <!-- <el-card :bordered="false" class="mb-3 proCard">
-      <el-space align="center">
-        <el-input-group style="width: 380px">
-          <el-input
-            :style="{ width: '100%' }"
-            v-model="params.deptName"
-            clearable
-            placeholder="请输入部门名称"
-            @keyup.enter="reloadTable"
-          />
-          <el-button type="primary" @click="reloadTable">
-            <template #icon>
-              <el-icon>
-                <SearchOutlined />
-              </el-icon>
-            </template>
-            查询
-          </el-button>
-        </el-input-group>
-      </el-space>
-    </el-card> -->
     <el-card :bordered="false" class="proCard">
       <BasicTable
         :columns="columns"
@@ -48,15 +27,6 @@
               </template>
               添加
             </el-button>
-
-            <!-- <el-button type="error" @click="openRemoveModal" :disabled="!rowKeys.length">
-              <template #icon>
-                <el-icon>
-                  <DeleteOutlined />
-                </el-icon>
-              </template>
-              删除
-            </el-button> -->
           </el-space>
         </template>
       </BasicTable>
@@ -73,6 +43,7 @@
       ref="createDrawerRef"
       :title="drawerTitle"
       :deptList="tableData"
+      :data-source="currentDept"
       @change="reloadTable"
       v-else
     />
@@ -83,12 +54,13 @@
   import { h, reactive, ref } from 'vue';
   import { ElMessage } from 'element-plus';
   import { BasicTable, TableAction, BasicColumn } from '@/components/Table';
-  import { deptTreeList, deleteDept } from '@/api/auth/dept';
+  import { deptTreeList, deleteDept, getAllDepartments , deleteDepartments} from '@/api/auth/dept';
   import { FileAddOutlined } from '@vicons/antd';
   import CreateDrawer from './CreateDrawer.vue';
   import CreateDrawer_shangfei from './CreateDrawer-shangfei.vue';
   import { columns } from './columns';
   import { useGlobSetting } from '@/hooks/setting';
+  import type { DeptTreeItem } from '@/types/dept/type';
 
   const globSetting = useGlobSetting();
   const disableDepartmentEdit = globSetting.disableDepartmentEdit;
@@ -100,6 +72,19 @@
   const tableData = ref<any[]>([]);
   const createDrawerRef = ref();
   const drawerTitle = ref('添加部门');
+  const currentDept = ref<DeptTreeItem>({
+    id: null,
+    deptName: '',
+    parentId: null,
+    orderNum: undefined,
+    isDisabled: 0,
+    createdBy: 0,
+    updatedBy: 0,
+    createdAt: '',
+    updatedAt: '',
+    isDeleted: 0,
+    tenantId: 0
+  });
 
   const params = reactive({
     deptName: '',
@@ -112,7 +97,7 @@
     fixed: 'right',
     align: 'center',
     render(record) {
-      const { index, row } = record;
+      const { index } = record;
       if (index === 0 && disableDepartmentEdit) return null;
       return h(TableAction as any, {
         actions: [
@@ -136,7 +121,7 @@
   });
 
   const loadDataTable = async (res) => {
-    const result = await deptTreeList({ ...params, ...res });
+    const result = await getAllDepartments();
     tableData.value = result;
     return { list: result };
   };
@@ -164,14 +149,14 @@
   }
 
   function handleEdit(record: Recordable) {
-    console.log('点击了编辑', record);
     drawerTitle.value = '编辑部门';
+    currentDept.value = record;
     const { openDrawer } = createDrawerRef.value;
     openDrawer(record.deptId);
   }
 
   function handleDelete(record: Recordable) {
-    deleteDept({ id: record.deptId }).then(() => {
+    deleteDepartments(record.id).then(() => {
       message.success('删除成功');
       reloadTable();
     });

+ 2 - 2
src/views/system/user/user.vue

@@ -137,7 +137,7 @@
   import { EditType, OptionsProps, SearchParamsProps } from './types';
   import { RoleTypeEnum } from '@/types/role/constants';
   import useSceneInfos from '@/hooks/useSceneInfos';
-  import { getAllDepartments } from '@/api/system/user-query';
+  import { getAllDepartments } from '@/api/auth/dept';
   import { getRoles } from '@/api/system/role';
   import { getUserList, UserLisItem, deleteUser } from '@/api/system/user-operate';
   import { ResultEnum } from '@/enums/httpEnum';
@@ -170,7 +170,7 @@
 
   const openAddSingleDrawer = () => {
     drawerTitle.value = '添加用户';
-    if (!isSysTenant) {
+    if (isSysTenant) {
       createAdminType.value = EditType.create;
       createAdminDrawerRef.value?.openDrawer();
     } else {