From e393e1f5259bdfc6f5c3ae49ded76762dbc436dd Mon Sep 17 00:00:00 2001 From: chenchun Date: Wed, 4 Sep 2024 16:24:26 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=96=B0=E5=A2=9E=E5=B2=97=E4=BD=8D?= =?UTF-8?q?=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Dtos/Post/PostCreateInputVo.cs | 7 +- .../Dtos/Post/PostUpdateInputVo.cs | 7 +- Yi.Pure.Vue3/locales/en.yaml | 3 +- Yi.Pure.Vue3/locales/zh-CN.yaml | 1 + Yi.Pure.Vue3/mock/asyncRoutes.ts | 11 +- Yi.Pure.Vue3/src/api/system/post.ts | 29 +- Yi.Pure.Vue3/src/api/system/role.ts | 4 +- Yi.Pure.Vue3/src/layout/hooks/useNav.ts | 5 +- Yi.Pure.Vue3/src/utils/file.ts | 8 + Yi.Pure.Vue3/src/utils/http/index.ts | 8 +- .../src/views/system/menu/utils/hook.tsx | 32 +- Yi.Pure.Vue3/src/views/system/post/form.vue | 57 ++++ Yi.Pure.Vue3/src/views/system/post/index.vue | 293 +++++++++++++++++ .../src/views/system/post/utils/hook.tsx | 298 ++++++++++++++++++ .../src/views/system/post/utils/rule.ts | 8 + .../src/views/system/post/utils/types.ts | 18 ++ Yi.Pure.Vue3/src/views/system/role/index.vue | 6 +- .../src/views/system/role/utils/hook.tsx | 4 +- .../src/views/system/user/utils/hook.tsx | 70 ++-- 19 files changed, 782 insertions(+), 87 deletions(-) create mode 100644 Yi.Pure.Vue3/src/utils/file.ts create mode 100644 Yi.Pure.Vue3/src/views/system/post/form.vue create mode 100644 Yi.Pure.Vue3/src/views/system/post/index.vue create mode 100644 Yi.Pure.Vue3/src/views/system/post/utils/hook.tsx create mode 100644 Yi.Pure.Vue3/src/views/system/post/utils/rule.ts create mode 100644 Yi.Pure.Vue3/src/views/system/post/utils/types.ts diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application.Contracts/Dtos/Post/PostCreateInputVo.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application.Contracts/Dtos/Post/PostCreateInputVo.cs index 0dc73506..cffdb958 100644 --- a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application.Contracts/Dtos/Post/PostCreateInputVo.cs +++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application.Contracts/Dtos/Post/PostCreateInputVo.cs @@ -5,12 +5,9 @@ namespace Yi.Framework.Rbac.Application.Contracts.Dtos.Post /// public class PostCreateInputVo { - public Guid Id { get; set; } - public DateTime CreationTime { get; set; } = DateTime.Now; - public long? CreatorId { get; set; } public bool? State { get; set; } - public string PostCode { get; set; } = string.Empty; - public string PostName { get; set; } = string.Empty; + public string PostCode { get; set; } + public string PostName { get; set; } public string? Remark { get; set; } } } diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application.Contracts/Dtos/Post/PostUpdateInputVo.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application.Contracts/Dtos/Post/PostUpdateInputVo.cs index 2304f8ac..0fd1154a 100644 --- a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application.Contracts/Dtos/Post/PostUpdateInputVo.cs +++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application.Contracts/Dtos/Post/PostUpdateInputVo.cs @@ -2,12 +2,9 @@ namespace Yi.Framework.Rbac.Application.Contracts.Dtos.Post { public class PostUpdateInputVo { - public Guid Id { get; set; } - public DateTime CreationTime { get; set; } = DateTime.Now; - public Guid? CreatorId { get; set; } public bool? State { get; set; } - public string PostCode { get; set; } = string.Empty; - public string PostName { get; set; } = string.Empty; + public string PostCode { get; set; } + public string PostName { get; set; } public string? Remark { get; set; } } } diff --git a/Yi.Pure.Vue3/locales/en.yaml b/Yi.Pure.Vue3/locales/en.yaml index 3793277b..aace64a0 100644 --- a/Yi.Pure.Vue3/locales/en.yaml +++ b/Yi.Pure.Vue3/locales/en.yaml @@ -71,6 +71,7 @@ menus: pureRole: Role Manage pureSystemMenu: Menu Manage pureDept: Dept Manage + purePost: Post Manage pureSysMonitor: System Monitor pureOnlineUser: Online User pureLoginLog: Login Log @@ -233,4 +234,4 @@ login: purePassWordRuleReg: The password format should be any combination of 8-18 digits purePassWordSureReg: Please enter confirm password purePassWordDifferentReg: The two passwords do not match! - purePassWordUpdateReg: Password has been updated \ No newline at end of file + purePassWordUpdateReg: Password has been updated diff --git a/Yi.Pure.Vue3/locales/zh-CN.yaml b/Yi.Pure.Vue3/locales/zh-CN.yaml index 7be27a8e..c25d8ff4 100644 --- a/Yi.Pure.Vue3/locales/zh-CN.yaml +++ b/Yi.Pure.Vue3/locales/zh-CN.yaml @@ -71,6 +71,7 @@ menus: pureRole: 角色管理 pureSystemMenu: 菜单管理 pureDept: 部门管理 + purePost: 岗位管理 pureSysMonitor: 系统监控 pureOnlineUser: 在线用户 pureLoginLog: 登录日志 diff --git a/Yi.Pure.Vue3/mock/asyncRoutes.ts b/Yi.Pure.Vue3/mock/asyncRoutes.ts index 1988afa4..c0525f83 100644 --- a/Yi.Pure.Vue3/mock/asyncRoutes.ts +++ b/Yi.Pure.Vue3/mock/asyncRoutes.ts @@ -51,6 +51,15 @@ const systemManagementRouter = { title: "menus.pureDept", //roles: ["admin"] } + }, + { + path: "/system/post/index", + name: "SystemPost", + meta: { + icon: "ant-design:deployment-unit-outlined", + title: "menus.purePost", + //roles: ["admin"] + } } ] }; @@ -328,7 +337,7 @@ export default defineFakeRoute([ return [ systemManagementRouter, systemMonitorRouter, - permissionRouter, + //permissionRouter, // frameRouter, // tabsRouter ]; diff --git a/Yi.Pure.Vue3/src/api/system/post.ts b/Yi.Pure.Vue3/src/api/system/post.ts index 3e4d5a84..ecef3ffb 100644 --- a/Yi.Pure.Vue3/src/api/system/post.ts +++ b/Yi.Pure.Vue3/src/api/system/post.ts @@ -2,31 +2,36 @@ import { http } from "@/utils/http"; import type { Result, ResultPage } from "@/api/result"; /** 查询岗位列表 */ -export const getList = (data?: object) => { - return http.request("get", "/dept", { data }); +export const getPostList = (data?: object) => { + return http.request("get", "/post", { data }); }; -/** 查询部门详细 */ +/** 查询岗位详细 */ export const getPost = id => { - return http.request("get", `/dept/${id}`, {}); + return http.request("get", `/post/${id}`, {}); }; -/** 新增部门 */ +/** 新增岗位 */ export const addPost = data => { - return http.request("post", `/dept`, { data }); + return http.request("post", `/post`, { data }); }; -/** 修改部门 */ +/** 修改岗位 */ export const updatePost = (id, data) => { - return http.request("put", `/dept/${id}`, { data }); + return http.request("put", `/post/${id}`, { data }); }; -/** 删除部门 */ -export const delPost = id => { - return http.request("delete", `/dept`, { params: { id } }); +/** 修改岗位状态 */ +export const updatePostStatus = (id, state) => { + return http.request("put", `/post/${id}/${state}`, {}); }; -/** 获取部门选择框列表 */ +/** 删除岗位 */ +export const delPost = ids => { + return http.request("delete", `/post`, { params: { id:ids } }); +}; + +/** 获取岗位选择框列表 */ export const getPostOptionSelect = () => { return http.request("get", `/post`, {}); }; diff --git a/Yi.Pure.Vue3/src/api/system/role.ts b/Yi.Pure.Vue3/src/api/system/role.ts index ea26a0e6..a112cf85 100644 --- a/Yi.Pure.Vue3/src/api/system/role.ts +++ b/Yi.Pure.Vue3/src/api/system/role.ts @@ -7,7 +7,7 @@ export const getRoleOption = () => { }; /** 查询角色列表 */ -export const listRole = query => { +export const getRoleList = query => { return http.request("get", `/role`, { params: query }); }; @@ -26,7 +26,7 @@ export const updateRole = (roleId, data) => { return http.request("put", `/role/${roleId}`, { data }); }; -/** 修改角色 */ +/** 修改角色状态 */ export const changeRoleStatus = (roleId, state) => { return http.request("put", `/role/${roleId}/${state}`, {}); }; diff --git a/Yi.Pure.Vue3/src/layout/hooks/useNav.ts b/Yi.Pure.Vue3/src/layout/hooks/useNav.ts index 33e6df47..5e1f9009 100644 --- a/Yi.Pure.Vue3/src/layout/hooks/useNav.ts +++ b/Yi.Pure.Vue3/src/layout/hooks/useNav.ts @@ -14,6 +14,7 @@ import { useUserStoreHook } from "@/store/modules/user"; import { useGlobal, isAllEmpty } from "@pureadmin/utils"; import { useEpThemeStoreHook } from "@/store/modules/epTheme"; import { usePermissionStoreHook } from "@/store/modules/permission"; +import {getFileUrl} from "@/utils/file" import ExitFullscreen from "@iconify-icons/ri/fullscreen-exit-fill"; import Fullscreen from "@iconify-icons/ri/fullscreen-fill"; @@ -40,9 +41,7 @@ export function useNav() { /** 头像(如果头像为空则使用 src/assets/user.jpg ) */ const userAvatar = computed(() => { - return isAllEmpty(useUserStoreHook()?.avatar) - ? Avatar - : useUserStoreHook()?.avatar; + return getFileUrl(useUserStoreHook()?.avatar,Avatar); }); /** 昵称(如果昵称为空则显示用户名) */ diff --git a/Yi.Pure.Vue3/src/utils/file.ts b/Yi.Pure.Vue3/src/utils/file.ts new file mode 100644 index 00000000..fe6e61cf --- /dev/null +++ b/Yi.Pure.Vue3/src/utils/file.ts @@ -0,0 +1,8 @@ +import {isAllEmpty} from "@pureadmin/utils"; + +export function getFileUrl(fileId: string, tryPath: string): string { + if (isAllEmpty(fileId)) { + return tryPath; + } + return `${import.meta.env.VITE_APP_BASE_API}/file/${fileId}`; +} diff --git a/Yi.Pure.Vue3/src/utils/http/index.ts b/Yi.Pure.Vue3/src/utils/http/index.ts index e1cd9252..f9f8677b 100644 --- a/Yi.Pure.Vue3/src/utils/http/index.ts +++ b/Yi.Pure.Vue3/src/utils/http/index.ts @@ -12,7 +12,8 @@ import { stringify } from "qs"; import NProgress from "../progress"; import { getToken, formatToken } from "@/utils/auth"; import { useUserStoreHook } from "@/store/modules/user"; - +import {message} from "@/utils/message"; +import { transformI18n } from "@/plugins/i18n"; // 相关配置请参考:www.axios-js.com/zh-cn/docs/#axios-request-config-1 const defaultConfig: AxiosRequestConfig = { baseURL: import.meta.env.VITE_APP_BASE_API, @@ -134,13 +135,14 @@ class PureHttp { } return response; }, - (error: PureHttpError) => { + (error: any) => { const $error = error; + message(error.response.data.error.message, { type: "error" }); $error.isCancelRequest = Axios.isCancel($error); // 关闭进度条动画 NProgress.done(); // 所有的响应异常 区分来源为取消请求/非取消请求 - return Promise.reject($error); + return Promise.reject($error); } ); } diff --git a/Yi.Pure.Vue3/src/views/system/menu/utils/hook.tsx b/Yi.Pure.Vue3/src/views/system/menu/utils/hook.tsx index 225fb577..c56b4258 100644 --- a/Yi.Pure.Vue3/src/views/system/menu/utils/hook.tsx +++ b/Yi.Pure.Vue3/src/views/system/menu/utils/hook.tsx @@ -1,7 +1,7 @@ import editForm from "../form.vue"; import { handleTree } from "@/utils/tree"; import { message } from "@/utils/message"; -import { addMenu, delMenu, getListMenu, updateMenu } from "@/api/system/menu"; +import {addMenu, delMenu, getListMenu, getMenu, updateMenu} from "@/api/system/menu"; import { transformI18n } from "@/plugins/i18n"; import { addDialog } from "@/components/ReDialog"; import { reactive, ref, onMounted, h } from "vue"; @@ -129,32 +129,32 @@ export function useMenu() { } async function openDialog(title = "新增", row?: FormItemProps) { - // let data: any = null; - // if (title == "修改") { - // data = await getMenu(row.id); - // } + let data: any = null; + if (title == "修改") { + data = await getMenu(row.id); + } addDialog({ title: `${title}菜单`, props: { formInline: { menuName: row?.menuName ?? "", menuType: - row?.menuType == undefined + data?.menuType == undefined ? 0 : menuTypeOptions.findIndex( option => option.value === row?.menuType ), higherMenuOptions: formatHigherMenuOptions(cloneDeep(dataList.value)), - id: row?.id ?? "", - parentId: row?.parentId ?? 0, - router: row?.router ?? "", - component: row?.component ?? "", - orderNum: row?.orderNum ?? 0, - icon: row?.icon ?? "", - permissionCode: row?.permissionCode ?? "", - showLink: row?.isShow ?? true, - isLink: row?.isLink ?? false, - state: row?.state ?? true + id: data?.id ?? "", + parentId: data?.parentId ?? 0, + router: data?.router ?? "", + component: data?.component ?? "", + orderNum: data?.orderNum ?? 0, + icon: data?.icon ?? "", + permissionCode: data?.permissionCode ?? "", + showLink: data?.isShow ?? true, + isLink: data?.isLink ?? false, + state: data?.state ?? true } }, width: "45%", diff --git a/Yi.Pure.Vue3/src/views/system/post/form.vue b/Yi.Pure.Vue3/src/views/system/post/form.vue new file mode 100644 index 00000000..d3c6e025 --- /dev/null +++ b/Yi.Pure.Vue3/src/views/system/post/form.vue @@ -0,0 +1,57 @@ + + + diff --git a/Yi.Pure.Vue3/src/views/system/post/index.vue b/Yi.Pure.Vue3/src/views/system/post/index.vue new file mode 100644 index 00000000..2a768c2a --- /dev/null +++ b/Yi.Pure.Vue3/src/views/system/post/index.vue @@ -0,0 +1,293 @@ + + + + + diff --git a/Yi.Pure.Vue3/src/views/system/post/utils/hook.tsx b/Yi.Pure.Vue3/src/views/system/post/utils/hook.tsx new file mode 100644 index 00000000..0769a5e9 --- /dev/null +++ b/Yi.Pure.Vue3/src/views/system/post/utils/hook.tsx @@ -0,0 +1,298 @@ +import dayjs from "dayjs"; +import editForm from "../form.vue"; +import {message} from "@/utils/message"; +import {ElMessageBox} from "element-plus"; +import {usePublicHooks} from "../../hooks"; +import {transformI18n} from "@/plugins/i18n"; +import {addDialog} from "@/components/ReDialog"; +import type {FormItemProps} from "../utils/types"; +import type {PaginationProps} from "@pureadmin/table"; +import {getKeyList, deviceDetection} from "@pureadmin/utils"; +import { + getPostList, + addPost, + updatePost, + delPost, + getPost, + updatePostStatus +} from "@/api/system/post" + +import { + type Ref, + reactive, + ref, + onMounted, + h, + toRaw, + watch, + nextTick +} from "vue"; + +export function usePost(treeRef: Ref) { + const form = reactive({ + postName: "", + postCode: "", + state: true, + skipCount: 1, + maxResultCount: 10 + }); + const curRow = ref(); + const formRef = ref(); + const dataList = ref([]); + const treeIds = ref([]); + const treeData = ref([]); + const isShow = ref(false); + const loading = ref(true); + const isLinkage = ref(false); + const treeSearchValue = ref(); + const switchLoadMap = ref({}); + const isExpandAll = ref(false); + const isSelectAll = ref(false); + const {switchStyle} = usePublicHooks(); + const pagination = reactive({ + total: 0, + pageSize: 10, + currentPage: 1, + background: true + }); + const columns: TableColumnList = [ + { + label: "岗位编号", + prop: "id" + }, + { + label: "岗位名称", + prop: "postName" + }, + { + label: "岗位标识", + prop: "postCode" + }, + { + label: "状态", + cellRenderer: scope => ( + onChange(scope as any)} + /> + ), + minWidth: 90 + }, + {label:"排序",prop:"orderNum"}, + { + label: "备注", + prop: "remark", + minWidth: 160 + }, + { + label: "创建时间", + prop: "creationTime", + minWidth: 160, + formatter: ({creationTime}) => + dayjs(creationTime).format("YYYY-MM-DD HH:mm:ss") + }, + { + label: "操作", + fixed: "right", + width: 210, + slot: "operation" + } + ]; + + async function onChange({row, index}) { + ElMessageBox.confirm( + `确认要${ + row.state === false ? "停用" : "启用" + }${ + row.roleName + }吗?`, + "系统提示", + { + confirmButtonText: "确定", + cancelButtonText: "取消", + type: "warning", + dangerouslyUseHTMLString: true, + draggable: true + } + ) + .then(async () => { + switchLoadMap.value[index] = Object.assign( + {}, + switchLoadMap.value[index], + { + loading: true + } + ); + + await updatePostStatus(row.id, row.state); + + switchLoadMap.value[index] = Object.assign( + {}, + switchLoadMap.value[index], + { + loading: false + } + ); + message(`已${row.state === false ? "停用" : "启用"}${row.roleName}`, { + type: "success" + }); + }) + .catch(() => { + row.state === false ? (row.state = true) : (row.state = false); + }); + } + + async function handleDelete(row) { + await delPost([row.id]); + message(`您删除了角色名称为${row.roleName}的这条数据`, {type: "success"}); + onSearch(); + } + + function handleSizeChange(val: number) { + form.maxResultCount = val; + onSearch(); + } + + function handleCurrentChange(val: number) { + form.skipCount = val; + onSearch(); + } + + function handleSelectionChange(val) { + console.log("handleSelectionChange", val); + } + + async function onSearch() { + loading.value = true; + const {data} = await getPostList(toRaw(form)); + dataList.value = data.items; + pagination.total = data.totalCount; + loading.value = false; + } + + const resetForm = formEl => { + if (!formEl) return; + formEl.resetFields(); + onSearch(); + }; + + async function openDialog(title = "新增", row?: FormItemProps) { + let data: any = null; + if (title == "修改") { + data = (await getPost(row?.id)).data; + } + addDialog({ + title: `${title}岗位`, + props: { + formInline: { + postName: row?.postName ?? "", + postCode: row?.postCode ?? "", + remark: row?.remark ?? "", + orderNum: data?.orderNum ?? 0, + } + }, + width: "40%", + draggable: true, + fullscreen: deviceDetection(), + fullscreenIcon: true, + closeOnClickModal: false, + contentRenderer: () => h(editForm, {ref: formRef}), + beforeSure: (done, {options}) => { + const FormRef = formRef.value.getRef(); + const curData = options.props.formInline as FormItemProps; + + function chores() { + message(`您${title}了岗位名称为${curData.postName}的这条数据`, { + type: "success" + }); + done(); // 关闭弹框 + onSearch(); // 刷新表格数据 + } + + FormRef.validate(async valid => { + if (valid) { + // 表单规则校验通过 + if (title === "新增") { + // 实际开发先调用新增接口,再进行下面操作 + await addPost(curData); + chores(); + } else { + // 实际开发先调用修改接口,再进行下面操作 + await updatePost(row?.id, curData); + chores(); + } + } + }); + } + }); + } + + /** 高亮当前权限选中行 */ + function rowStyle({row: {id}}) { + return { + cursor: "pointer", + background: id === curRow.value?.id ? "var(--el-fill-color-light)" : "" + }; + } + + /** 数据权限 可自行开发 */ + // function handleDatabase() {} + + const onQueryChanged = (query: string) => { + treeRef.value!.filter(query); + }; + + const filterMethod = (query: string, node) => { + return transformI18n(node.title)!.includes(query); + }; + + onMounted(async () => { + onSearch(); + }); + + watch(isExpandAll, val => { + val + ? treeRef.value.setExpandedKeys(treeIds.value) + : treeRef.value.setExpandedKeys([]); + }); + + watch(isSelectAll, val => { + val + ? treeRef.value.setCheckedKeys(treeIds.value) + : treeRef.value.setCheckedKeys([]); + }); + + return { + form, + isShow, + curRow, + loading, + columns, + rowStyle, + dataList, + treeData, + isLinkage, + pagination, + isExpandAll, + isSelectAll, + treeSearchValue, + onSearch, + resetForm, + openDialog, + handleDelete, + filterMethod, + transformI18n, + onQueryChanged, + handleSizeChange, + handleCurrentChange, + handleSelectionChange + }; +} diff --git a/Yi.Pure.Vue3/src/views/system/post/utils/rule.ts b/Yi.Pure.Vue3/src/views/system/post/utils/rule.ts new file mode 100644 index 00000000..31b03350 --- /dev/null +++ b/Yi.Pure.Vue3/src/views/system/post/utils/rule.ts @@ -0,0 +1,8 @@ +import { reactive } from "vue"; +import type { FormRules } from "element-plus"; + +/** 自定义表单规则校验 */ +export const formRules = reactive({ + postName: [{ required: true, message: "岗位名称为必填项", trigger: "blur" }], + postCode: [{ required: true, message: "岗位标识为必填项", trigger: "blur" }] +}); diff --git a/Yi.Pure.Vue3/src/views/system/post/utils/types.ts b/Yi.Pure.Vue3/src/views/system/post/utils/types.ts new file mode 100644 index 00000000..f0ce33fc --- /dev/null +++ b/Yi.Pure.Vue3/src/views/system/post/utils/types.ts @@ -0,0 +1,18 @@ +// 虽然字段很少 但是抽离出来 后续有扩展字段需求就很方便了 + +interface FormItemProps { + id?: string; + /** 角色名称 */ + postName: string; + /** 角色编号 */ + postCode: string; + /** 备注 */ + remark: string; + orderNum: number; + +} +interface FormProps { + formInline: FormItemProps; +} + +export type { FormItemProps, FormProps }; diff --git a/Yi.Pure.Vue3/src/views/system/role/index.vue b/Yi.Pure.Vue3/src/views/system/role/index.vue index 6c7025ee..9349f993 100644 --- a/Yi.Pure.Vue3/src/views/system/role/index.vue +++ b/Yi.Pure.Vue3/src/views/system/role/index.vue @@ -98,7 +98,7 @@ onMounted(() => { :model="form" class="search-form bg-bg_color w-[99/100] pl-8 pt-[12px] overflow-auto" > - + { class="!w-[180px]" /> - + { class="!w-[180px]" /> - + ( + cellRenderer: ({row}) => ( ), @@ -113,7 +114,7 @@ export function useUser(tableRef: Ref, treeRef: Ref) { label: "性别", prop: "sex", minWidth: 90, - cellRenderer: ({ row, props }) => ( + cellRenderer: ({row, props}) => ( - phone == null ? "-" : hideTextAtIndex(phone, { start: 3, end: 6 }) + formatter: ({phone}) => + phone == null ? "-" : hideTextAtIndex(phone, {start: 3, end: 6}) }, { label: "状态", @@ -158,7 +159,7 @@ export function useUser(tableRef: Ref, treeRef: Ref) { label: "创建时间", minWidth: 90, prop: "creationTime", - formatter: ({ creationTime }) => + formatter: ({creationTime}) => dayjs(creationTime).format("YYYY-MM-DD HH:mm:ss") }, { @@ -182,17 +183,17 @@ export function useUser(tableRef: Ref, treeRef: Ref) { password: "" }); const pwdProgress = [ - { color: "#e74242", text: "非常弱" }, - { color: "#EFBD47", text: "弱" }, - { color: "#ffa500", text: "一般" }, - { color: "#1bbf1b", text: "强" }, - { color: "#008000", text: "非常强" } + {color: "#e74242", text: "非常弱"}, + {color: "#EFBD47", text: "弱"}, + {color: "#ffa500", text: "一般"}, + {color: "#1bbf1b", text: "强"}, + {color: "#008000", text: "非常强"} ]; // 当前密码强度(0-4) const curScore = ref(); const roleOptions = ref([]); - function onChange({ row, index }) { + function onChange({row, index}) { ElMessageBox.confirm( `确认要${ row.state === 0 ? "停用" : "启用" @@ -241,7 +242,7 @@ export function useUser(tableRef: Ref, treeRef: Ref) { async function handleDelete(row) { await delUser([row.id]); - message(`您删除了用户编号为${row.id}的这条数据`, { type: "success" }); + message(`您删除了用户编号为${row.id}的这条数据`, {type: "success"}); onSearch(); } @@ -285,7 +286,7 @@ export function useUser(tableRef: Ref, treeRef: Ref) { async function onSearch() { loading.value = true; - const { data } = await getUserList(toRaw(form)); + const {data} = await getUserList(toRaw(form)); dataList.value = data.items; pagination.total = data.totalCount; // pagination.pageSize = data.pageSize; @@ -304,7 +305,7 @@ export function useUser(tableRef: Ref, treeRef: Ref) { onSearch(); }; - function onTreeSelect({ id, selected }) { + function onTreeSelect({id, selected}) { form.deptId = selected ? id : ""; onSearch(); } @@ -320,6 +321,7 @@ export function useUser(tableRef: Ref, treeRef: Ref) { } return newTreeList; } + async function openDialog(title = "新增", row?: FormItemProps) { let data: any = null; //打开弹窗之前,如果是修改,还需进行查询详情 @@ -351,8 +353,8 @@ export function useUser(tableRef: Ref, treeRef: Ref) { fullscreen: deviceDetection(), fullscreenIcon: true, closeOnClickModal: false, - contentRenderer: () => h(editForm, { ref: formRef }), - beforeSure: (done, { options }) => { + contentRenderer: () => h(editForm, {ref: formRef}), + beforeSure: (done, {options}) => { const FormRef = formRef.value.getRef(); const curData = options.props.formInline as FormItemProps; @@ -394,7 +396,7 @@ export function useUser(tableRef: Ref, treeRef: Ref) { contentRenderer: () => h(ReCropperPreview, { ref: cropRef, - imgSrc: row.avatar || userAvatar, + imgSrc: getFileUrl(row.avatar, userAvatar), onCropper: info => (avatarInfo.value = info) }), beforeSure: done => { @@ -409,7 +411,7 @@ export function useUser(tableRef: Ref, treeRef: Ref) { watch( pwdForm, - ({ password }) => + ({password}) => (curScore.value = isAllEmpty(password) ? -1 : zxcvbn(password).score) ); @@ -444,10 +446,10 @@ export function useUser(tableRef: Ref, treeRef: Ref) {
- {pwdProgress.map(({ color, text }, idx) => ( + {pwdProgress.map(({color, text}, idx) => (

{text}

@@ -492,7 +494,7 @@ export function useUser(tableRef: Ref, treeRef: Ref) { onSearch(); // 归属部门 - const { data } = await getDeptList(); + const {data} = await getDeptList(); higherDeptOptions.value = handleTree(data.items); treeData.value = handleTree(data.items); treeLoading.value = false;