浏览代码

Merge branch 'v2' into mini

kailong321200875 1 年之前
父节点
当前提交
c3a2cc0a5f

+ 85 - 6
mock/department/index.ts

@@ -14,36 +14,65 @@ for (let i = 0; i < 5; i++) {
     // 部门名称
     departmentName: citys[i],
     id: toAnyString(),
+    createTime: '@datetime',
+    // 状态
+    status: Mock.Random.integer(0, 1),
+    // 备注
+    remark: '@cword(10, 15)',
     children: [
       {
         // 部门名称
         departmentName: '研发部',
-        id: toAnyString()
+        createTime: '@datetime',
+        // 状态
+        status: Mock.Random.integer(0, 1),
+        id: toAnyString(),
+        remark: '@cword(10, 15)'
       },
       {
         // 部门名称
         departmentName: '产品部',
-        id: toAnyString()
+        createTime: '@datetime',
+        // 状态
+        status: Mock.Random.integer(0, 1),
+        id: toAnyString(),
+        remark: '@cword(10, 15)'
       },
       {
         // 部门名称
         departmentName: '运营部',
-        id: toAnyString()
+        createTime: '@datetime',
+        // 状态
+        status: Mock.Random.integer(0, 1),
+        id: toAnyString(),
+        remark: '@cword(10, 15)'
       },
       {
         // 部门名称
         departmentName: '市场部',
-        id: toAnyString()
+        createTime: '@datetime',
+        // 状态
+        status: Mock.Random.integer(0, 1),
+        id: toAnyString(),
+        remark: '@cword(10, 15)'
       },
       {
         // 部门名称
         departmentName: '销售部',
-        id: toAnyString()
+        createTime: '@datetime',
+        // 状态
+        status: Mock.Random.integer(0, 1),
+        id: toAnyString(),
+        remark: '@cword(10, 15)'
       },
       {
         // 部门名称
         departmentName: '客服部',
-        id: toAnyString()
+        createTime: '@datetime',
+        // 状态
+        status: Mock.Random.integer(0, 1),
+        id: toAnyString(),
+        remark: '@cword(10, 15)'
       }
     ]
   })
@@ -65,6 +94,21 @@ export default [
       }
     }
   },
+  {
+    url: '/department/table/list',
+    method: 'get',
+    response: () => {
+      return {
+        data: {
+          code: code,
+          data: {
+            list: departmentList,
+            total: 5
+          }
+        }
+      }
+    }
+  },
   {
     url: '/department/users',
     method: 'get',
@@ -136,5 +180,40 @@ export default [
         }
       }
     }
+  },
+  // 保存接口
+  {
+    url: '/department/save',
+    method: 'post',
+    timeout: 1000,
+    response: () => {
+      return {
+        data: {
+          code: code,
+          data: 'success'
+        }
+      }
+    }
+  },
+  // 删除接口
+  {
+    url: '/department/delete',
+    method: 'post',
+    response: ({ body }) => {
+      const ids = body.ids
+      if (!ids) {
+        return {
+          code: '500',
+          message: '请选择需要删除的数据'
+        }
+      } else {
+        return {
+          data: {
+            code: code,
+            data: 'success'
+          }
+        }
+      }
+    }
   }
 ] as MockMethod[]

+ 12 - 0
src/api/department/index.ts

@@ -16,3 +16,15 @@ export const deleteUserByIdApi = (ids: string[] | number[]) => {
 export const saveUserApi = (data: any) => {
   return request.post({ url: '/department/user/save', data })
 }
+
+export const saveDepartmentApi = (data: any) => {
+  return request.post({ url: '/department/save', data })
+}
+
+export const deleteDepartmentApi = (ids: string[] | number[]) => {
+  return request.post({ url: '/department/delete', data: { ids } })
+}
+
+export const getDepartmentTableApi = (params: any) => {
+  return request.get({ url: '/department/table/list', params })
+}

+ 9 - 9
src/components/Form/src/Form.vue

@@ -24,7 +24,7 @@ import { useRenderRadio } from './components/useRenderRadio'
 import { useRenderCheckbox } from './components/useRenderCheckbox'
 import { useDesign } from '@/hooks/web/useDesign'
 import { findIndex } from '@/utils'
-import { set } from 'lodash-es'
+import { get, set } from 'lodash-es'
 import { FormProps } from './types'
 import {
   FormSchema,
@@ -319,18 +319,18 @@ export default defineComponent({
 
             const Comp = () => {
               // 如果field是多层路径,需要转换成对象
-              const fields = item.field.split('.')
-              // 循环fields,绑定v-model
-              const vModel = fields.reduce((prev, next, index) => {
-                if (index === 0) {
-                  return formModel.value[next]
+              const itemVal = computed({
+                get: () => {
+                  return get(formModel.value, item.field)
+                },
+                set: (val) => {
+                  set(formModel.value, item.field, val)
                 }
-                return prev[next]
-              }, {})
+              })
 
               return (
                 <Com
-                  vModel={vModel}
+                  vModel={itemVal.value}
                   ref={(el: any) => setComponentRefMap(el, item.field)}
                   {...(autoSetPlaceholder && setTextPlaceholder(item))}
                   {...setComponentProps(item)}

+ 5 - 1
src/components/Form/src/helper/index.ts

@@ -150,7 +150,11 @@ export const initModel = (schema: FormSchema[], formModel: Recordable) => {
       // const hasField = Reflect.has(model, v.field)
       const hasField = get(model, v.field)
       // 如果先前已经有值存在,则不进行重新赋值,而是采用现有的值
-      set(model, v.field, hasField ? get(model, v.field) : v.value !== void 0 ? v.value : undefined)
+      set(
+        model,
+        v.field,
+        hasField !== void 0 ? get(model, v.field) : v.value !== void 0 ? v.value : undefined
+      )
       // model[v.field] = hasField ? model[v.field] : v.value !== void 0 ? v.value : undefined
     }
   })

+ 16 - 5
src/components/Search/src/Search.vue

@@ -9,6 +9,7 @@ import { initModel } from '@/components/Form/src/helper'
 import ActionButton from './components/ActionButton.vue'
 import { SearchProps } from './types'
 import { FormItemProp } from 'element-plus'
+import { isObject, isEmptyVal } from '@/utils/is'
 
 const props = defineProps({
   // 生成Form的布局结构数组
@@ -130,12 +131,22 @@ watch(
 
 const filterModel = async () => {
   const model = await getFormData()
-  unref(getProps).removeNoValueItem &&
-    Object.keys(model).forEach((key) => {
-      if (model[key] === void 0 || model[key] === '') {
-        delete model[key]
+  if (unref(getProps).removeNoValueItem) {
+    // 使用reduce过滤空值,并返回一个新对象
+    return Object.keys(model).reduce((prev, next) => {
+      const value = model[next]
+      if (!isEmptyVal(value)) {
+        if (isObject(value)) {
+          if (Object.keys(value).length > 0) {
+            prev[next] = value
+          }
+        } else {
+          prev[next] = value
+        }
       }
-    })
+      return prev
+    }, {})
+  }
   return model
 }
 

+ 8 - 2
src/locales/en.ts

@@ -160,7 +160,8 @@ export default {
     inputPassword: 'InputPassword',
     sticky: 'Sticky',
     treeTable: 'Tree table',
-    PicturePreview: 'Table Image Preview'
+    PicturePreview: 'Table Image Preview',
+    department: 'Department management'
   },
   permission: {
     hasPermission: 'Please set the operation permission value'
@@ -496,7 +497,12 @@ export default {
     email: 'Email',
     createTime: 'Create time',
     // 所属部门
-    department: 'Department'
+    department: 'Department',
+    departmentName: 'Department name',
+    status: 'Status',
+    enable: 'Enable',
+    disable: 'Disable',
+    superiorDepartment: 'Superior department'
   },
   inputPasswordDemo: {
     title: 'InputPassword',

+ 11 - 2
src/locales/zh-CN.ts

@@ -160,7 +160,8 @@ export default {
     inputPassword: '密码输入框',
     sticky: '黏性',
     treeTable: '树形表格',
-    PicturePreview: '表格图片预览'
+    PicturePreview: '表格图片预览',
+    department: '部门管理'
   },
   permission: {
     hasPermission: '请设置操作权限值'
@@ -488,7 +489,15 @@ export default {
     email: '邮箱',
     createTime: '创建时间',
     // 所属部门
-    department: '所属部门'
+    department: '所属部门',
+    departmentName: '部门名称',
+    status: '状态',
+    // 启用
+    enable: '启用',
+    // 禁用
+    disable: '禁用',
+    // 上级部门
+    superiorDepartment: '上级部门'
   },
   inputPasswordDemo: {
     title: '密码输入框',

+ 4 - 0
src/utils/is.ts

@@ -108,3 +108,7 @@ export const isDark = (): boolean => {
 export const isImgPath = (path: string): boolean => {
   return /(https?:\/\/|data:image\/).*?\.(png|jpg|jpeg|gif|svg|webp|ico)/gi.test(path)
 }
+
+export const isEmptyVal = (val: any): boolean => {
+  return val === '' || val === null || val === undefined
+}