diff --git a/mock/department/index.ts b/mock/department/index.ts index 8a96b95..34b5341 100644 --- a/mock/department/index.ts +++ b/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[] diff --git a/src/api/department/index.ts b/src/api/department/index.ts index 6339ad4..b6ece1e 100644 --- a/src/api/department/index.ts +++ b/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 }) +} diff --git a/src/components/Form/src/Form.vue b/src/components/Form/src/Form.vue index fdf9178..347ea4f 100644 --- a/src/components/Form/src/Form.vue +++ b/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 ( setComponentRefMap(el, item.field)} {...(autoSetPlaceholder && setTextPlaceholder(item))} {...setComponentProps(item)} diff --git a/src/components/Form/src/helper/index.ts b/src/components/Form/src/helper/index.ts index 74fb284..423993c 100644 --- a/src/components/Form/src/helper/index.ts +++ b/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 } }) diff --git a/src/components/Search/src/Search.vue b/src/components/Search/src/Search.vue index 354fefe..2fe42ec 100644 --- a/src/components/Search/src/Search.vue +++ b/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 } diff --git a/src/locales/en.ts b/src/locales/en.ts index 2423139..00cf611 100644 --- a/src/locales/en.ts +++ b/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', diff --git a/src/locales/zh-CN.ts b/src/locales/zh-CN.ts index 30fe2c7..8a86b76 100644 --- a/src/locales/zh-CN.ts +++ b/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: '密码输入框', diff --git a/src/utils/is.ts b/src/utils/is.ts index 2adaa37..8ac2e50 100644 --- a/src/utils/is.ts +++ b/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 +}