From 2353bd7a8a5b7face232fa00c93c2fee362fdc4e Mon Sep 17 00:00:00 2001 From: chansee97 Date: Tue, 16 Apr 2024 10:46:51 +0800 Subject: [PATCH] fix: perfect constants --- src/constants/Regex.ts | 12 ++++++ src/constants/User.ts | 9 +++++ src/constants/business.ts | 5 --- src/constants/index.ts | 3 +- src/views/list/commonList/index.vue | 4 +- .../setting/menu/components/TableModal.vue | 40 +++++++++++++++---- 6 files changed, 58 insertions(+), 15 deletions(-) create mode 100644 src/constants/Regex.ts create mode 100644 src/constants/User.ts delete mode 100644 src/constants/business.ts diff --git a/src/constants/Regex.ts b/src/constants/Regex.ts new file mode 100644 index 0000000..d675af7 --- /dev/null +++ b/src/constants/Regex.ts @@ -0,0 +1,12 @@ +/** + * @description Some common rules + * @link https://any-rule.vercel.app/ + */ + +export enum Regex { + Url = '^(((ht|f)tps?):\\\/\\\/)?([^!@#$%^&*?.\\s-]([^!@#$%^&*?.\\s]{0,63}[^!@#$%^&*?.\\s])?\\.)+[a-z]{2,6}\\\/?', + + Email = '^(([^<>()[\\]\\\\.,;:\\s@"]+(\\.[^<>()[\\]\\\\.,;:\\s@"]+)*)|(".+"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$', + + RouteName = '^[\\w_!@#$%^&*~-]+$', +} diff --git a/src/constants/User.ts b/src/constants/User.ts new file mode 100644 index 0000000..0fad8e8 --- /dev/null +++ b/src/constants/User.ts @@ -0,0 +1,9 @@ +// export const genderLabels: Record, string> = { +// 0: '女', +// 1: '男', +// } +/** Gender */ +export enum Gender { + male, + female, +} diff --git a/src/constants/business.ts b/src/constants/business.ts deleted file mode 100644 index 441d601..0000000 --- a/src/constants/business.ts +++ /dev/null @@ -1,5 +0,0 @@ -/** 用户性别 */ -export const genderLabels: Record, string> = { - 0: '女', - 1: '男', -} diff --git a/src/constants/index.ts b/src/constants/index.ts index 9971b39..a2b4ead 100644 --- a/src/constants/index.ts +++ b/src/constants/index.ts @@ -1 +1,2 @@ -export * from './business' +export * from './Regex' +export * from './User' diff --git a/src/views/list/commonList/index.vue b/src/views/list/commonList/index.vue index bb6e4be..948cdce 100644 --- a/src/views/list/commonList/index.vue +++ b/src/views/list/commonList/index.vue @@ -4,7 +4,7 @@ import { NButton, NPopconfirm, NSpace, NSwitch, NTag } from 'naive-ui' import TableModal from './components/TableModal.vue' import { fetchUserList } from '@/service' import { useBoolean, useLoading } from '@/hooks' -import { genderLabels } from '@/constants' +import { Gender } from '@/constants' const { loading, startLoading, endLoading } = useLoading(false) const { bool: visible, setTrue: openModal } = useBoolean(false) @@ -45,7 +45,7 @@ const columns: DataTableColumns = [ if (rowData.gender) { return ( - {genderLabels[rowData.gender]} + {Gender[rowData.gender]} ) } diff --git a/src/views/setting/menu/components/TableModal.vue b/src/views/setting/menu/components/TableModal.vue index 63fb40a..00ac4b5 100644 --- a/src/views/setting/menu/components/TableModal.vue +++ b/src/views/setting/menu/components/TableModal.vue @@ -1,6 +1,10 @@