From 5f7c77d9c636c460bccf66ed0f2e2829a91b1a0b Mon Sep 17 00:00:00 2001 From: chansee97 Date: Mon, 27 May 2024 11:30:15 +0800 Subject: [PATCH] perf: perfect entity type --- src/components/common/Pagination.vue | 6 +- src/constants/User.ts | 4 -- src/directives/permission.ts | 4 +- src/hooks/usePermission.ts | 2 +- src/layouts/components/common/NoticeList.vue | 2 +- src/layouts/components/header/Notices.vue | 2 +- src/service/api/login.ts | 4 +- src/service/api/system.ts | 4 +- src/store/auth.ts | 4 +- src/typings/api.d.ts | 30 ---------- src/typings/api/login.d.ts | 17 ++++++ src/typings/entities.d.ts | 55 ------------------- src/typings/entities/demoList.d.ts | 15 +++++ src/typings/entities/message.d.ts | 16 ++++++ src/typings/entities/role.d.ts | 13 +++++ src/typings/entities/user.d.ts | 28 ++++++++++ src/typings/global.d.ts | 11 +++- src/typings/route.d.ts | 2 +- .../list/commonList/components/TableModal.vue | 2 +- src/views/list/commonList/index.vue | 35 +++++------- src/views/permission/permission/index.vue | 4 +- .../setting/account/components/TableModal.vue | 4 +- src/views/setting/account/index.vue | 19 +++---- .../setting/menu/components/TableModal.vue | 2 +- src/views/setting/menu/index.vue | 7 +-- 25 files changed, 149 insertions(+), 143 deletions(-) delete mode 100644 src/typings/api.d.ts create mode 100644 src/typings/api/login.d.ts delete mode 100644 src/typings/entities.d.ts create mode 100644 src/typings/entities/demoList.d.ts create mode 100644 src/typings/entities/message.d.ts create mode 100644 src/typings/entities/role.d.ts create mode 100644 src/typings/entities/user.d.ts diff --git a/src/components/common/Pagination.vue b/src/components/common/Pagination.vue index 11e224f..768e14e 100644 --- a/src/components/common/Pagination.vue +++ b/src/components/common/Pagination.vue @@ -5,7 +5,11 @@ const props = defineProps({ default: 0, }, }) -const emit = defineEmits(['change']) + +const emit = defineEmits<{ + change: [page: number, pageSize: number] // 具名元组语法 +}>() + const page = ref(1) const pageSize = ref(10) const displayOrder: Array<'pages' | 'size-picker' | 'quick-jumper'> = ['size-picker', 'pages'] diff --git a/src/constants/User.ts b/src/constants/User.ts index 0fad8e8..a8104ea 100644 --- a/src/constants/User.ts +++ b/src/constants/User.ts @@ -1,7 +1,3 @@ -// export const genderLabels: Record, string> = { -// 0: '女', -// 1: '男', -// } /** Gender */ export enum Gender { male, diff --git a/src/directives/permission.ts b/src/directives/permission.ts index efe212d..27e2449 100644 --- a/src/directives/permission.ts +++ b/src/directives/permission.ts @@ -4,7 +4,7 @@ import { usePermission } from '@/hooks' export function install(app: App) { const { hasPermission } = usePermission() - function updatapermission(el: HTMLElement, permission: Auth.RoleType | Auth.RoleType[]) { + function updatapermission(el: HTMLElement, permission: Entity.RoleType | Entity.RoleType[]) { if (!permission) throw new Error('v-permissson Directive with no explicit role attached') @@ -12,7 +12,7 @@ export function install(app: App) { el.parentElement?.removeChild(el) } - const permissionDirective: Directive = { + const permissionDirective: Directive = { mounted(el, binding) { updatapermission(el, binding.value) }, diff --git a/src/hooks/usePermission.ts b/src/hooks/usePermission.ts index 94afaa9..1c48e0e 100644 --- a/src/hooks/usePermission.ts +++ b/src/hooks/usePermission.ts @@ -6,7 +6,7 @@ export function usePermission() { const authStore = useAuthStore() function hasPermission( - permission: Auth.RoleType | Auth.RoleType[] | undefined, + permission: Entity.RoleType | Entity.RoleType[] | undefined, ) { if (!permission) return true diff --git a/src/layouts/components/common/NoticeList.vue b/src/layouts/components/common/NoticeList.vue index 9f8d1ec..026bc1f 100644 --- a/src/layouts/components/common/NoticeList.vue +++ b/src/layouts/components/common/NoticeList.vue @@ -1,6 +1,6 @@ diff --git a/src/views/setting/account/components/TableModal.vue b/src/views/setting/account/components/TableModal.vue index 313b7d8..0599823 100644 --- a/src/views/setting/account/components/TableModal.vue +++ b/src/views/setting/account/components/TableModal.vue @@ -20,7 +20,7 @@ const { bool: modalVisible, setTrue: showModal, setFalse: hiddenModal } = useBoo const { loading: submitLoading, startLoading, endLoading } = useLoading(false) const formModel = ref() -const defaultFormModal: Auth.User = { +const defaultFormModal: Entity.User = { userName: '', gender: undefined, email: '', @@ -107,7 +107,7 @@ const rules = { }, } -const options = ref([]) +const options = ref([]) async function getRoleList() { const { data } = await fetchRoleList() options.value = data diff --git a/src/views/setting/account/index.vue b/src/views/setting/account/index.vue index ecc80f2..22fcada 100644 --- a/src/views/setting/account/index.vue +++ b/src/views/setting/account/index.vue @@ -25,7 +25,7 @@ function delteteUser(id: number) { window.$message.success(`删除用户id:${id}`) } -const columns: DataTableColumns = [ +const columns: DataTableColumns = [ { title: '姓名', align: 'center', @@ -74,8 +74,8 @@ const columns: DataTableColumns = [ value={row.status} checked-value={1} unchecked-value={0} - onUpdateValue={disabled => - handleUpdateDisabled(disabled, row.id!)} + onUpdateValue={value => + handleUpdateDisabled(value, row.id!)} > {{ checked: () => '启用', unchecked: () => '禁用' }} @@ -87,16 +87,15 @@ const columns: DataTableColumns = [ align: 'center', key: 'actions', render: (row) => { - const rowData = row as unknown as Auth.User return ( modalRef.value.openModal('edit', rowData)} + onClick={() => modalRef.value.openModal('edit', row)} > 编辑 - delteteUser(rowData.id!)}> + delteteUser(row.id!)}> {{ default: () => '确认删除', trigger: () => 删除, @@ -108,11 +107,11 @@ const columns: DataTableColumns = [ }, ] -const listData = ref([]) -function handleUpdateDisabled(disabled: boolean, id: number) { +const listData = ref([]) +function handleUpdateDisabled(value: 0 | 1, id: number) { const index = listData.value.findIndex(item => item.id === id) if (index > -1) - listData.value[index].disabled = disabled + listData.value[index].status = value } async function getUserList() { @@ -161,7 +160,7 @@ const treeData = ref([