mirror of
https://github.com/chansee97/nova-admin.git
synced 2025-04-05 19:41:59 +08:00
fix: perfect constants
This commit is contained in:
parent
5d1eb3cb3c
commit
2353bd7a8a
12
src/constants/Regex.ts
Normal file
12
src/constants/Regex.ts
Normal file
@ -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_!@#$%^&*~-]+$',
|
||||||
|
}
|
9
src/constants/User.ts
Normal file
9
src/constants/User.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
// export const genderLabels: Record<NonNullable<CommonList.GenderType>, string> = {
|
||||||
|
// 0: '女',
|
||||||
|
// 1: '男',
|
||||||
|
// }
|
||||||
|
/** Gender */
|
||||||
|
export enum Gender {
|
||||||
|
male,
|
||||||
|
female,
|
||||||
|
}
|
@ -1,5 +0,0 @@
|
|||||||
/** 用户性别 */
|
|
||||||
export const genderLabels: Record<NonNullable<CommonList.GenderType>, string> = {
|
|
||||||
0: '女',
|
|
||||||
1: '男',
|
|
||||||
}
|
|
@ -1 +1,2 @@
|
|||||||
export * from './business'
|
export * from './Regex'
|
||||||
|
export * from './User'
|
||||||
|
@ -4,7 +4,7 @@ import { NButton, NPopconfirm, NSpace, NSwitch, NTag } from 'naive-ui'
|
|||||||
import TableModal from './components/TableModal.vue'
|
import TableModal from './components/TableModal.vue'
|
||||||
import { fetchUserList } from '@/service'
|
import { fetchUserList } from '@/service'
|
||||||
import { useBoolean, useLoading } from '@/hooks'
|
import { useBoolean, useLoading } from '@/hooks'
|
||||||
import { genderLabels } from '@/constants'
|
import { Gender } from '@/constants'
|
||||||
|
|
||||||
const { loading, startLoading, endLoading } = useLoading(false)
|
const { loading, startLoading, endLoading } = useLoading(false)
|
||||||
const { bool: visible, setTrue: openModal } = useBoolean(false)
|
const { bool: visible, setTrue: openModal } = useBoolean(false)
|
||||||
@ -45,7 +45,7 @@ const columns: DataTableColumns = [
|
|||||||
if (rowData.gender) {
|
if (rowData.gender) {
|
||||||
return (
|
return (
|
||||||
<NTag type={tagType[rowData.gender]}>
|
<NTag type={tagType[rowData.gender]}>
|
||||||
{genderLabels[rowData.gender]}
|
{Gender[rowData.gender]}
|
||||||
</NTag>
|
</NTag>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import type {
|
||||||
|
FormItemRule,
|
||||||
|
} from 'naive-ui'
|
||||||
import HelpInfo from '@/components/common/HelpInfo.vue'
|
import HelpInfo from '@/components/common/HelpInfo.vue'
|
||||||
import { useLoading } from '@/hooks'
|
import { useLoading } from '@/hooks'
|
||||||
|
import { Regex } from '@/constants'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
modalName?: string
|
modalName?: string
|
||||||
@ -129,7 +133,16 @@ function filterDirectory(node: any[]) {
|
|||||||
const rules = {
|
const rules = {
|
||||||
'name': {
|
'name': {
|
||||||
required: true,
|
required: true,
|
||||||
message: '请输入菜单名称',
|
// message: '请输入菜单名称',
|
||||||
|
validator(rule: FormItemRule, value: string) {
|
||||||
|
if (!value)
|
||||||
|
return new Error('请输入菜单名称')
|
||||||
|
|
||||||
|
if (!new RegExp(Regex.RouteName).test(value))
|
||||||
|
return new Error('菜单只能包含英文数字_!@#$%^&*~-')
|
||||||
|
|
||||||
|
return true
|
||||||
|
},
|
||||||
trigger: 'blur',
|
trigger: 'blur',
|
||||||
},
|
},
|
||||||
'path': {
|
'path': {
|
||||||
@ -147,6 +160,15 @@ const rules = {
|
|||||||
message: '请输入菜单标题',
|
message: '请输入菜单标题',
|
||||||
trigger: 'blur',
|
trigger: 'blur',
|
||||||
},
|
},
|
||||||
|
'meta.herf': {
|
||||||
|
validator(rule: FormItemRule, value: string) {
|
||||||
|
if (!new RegExp(Regex.Url).test(value))
|
||||||
|
return new Error('请输入正确的URL地址')
|
||||||
|
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
trigger: 'blur',
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
const options = [
|
const options = [
|
||||||
@ -189,13 +211,13 @@ const options = [
|
|||||||
/>
|
/>
|
||||||
</n-form-item-grid-item>
|
</n-form-item-grid-item>
|
||||||
<n-form-item-grid-item :span="1" label="菜单名称" path="name">
|
<n-form-item-grid-item :span="1" label="菜单名称" path="name">
|
||||||
<n-input v-model:value="formModel.name" />
|
<n-input v-model:value="formModel.name" placeholder="Eg: system" />
|
||||||
</n-form-item-grid-item>
|
</n-form-item-grid-item>
|
||||||
<n-form-item-grid-item :span="1" label="标题" path="meta.title">
|
<n-form-item-grid-item :span="1" label="标题" path="meta.title">
|
||||||
<n-input v-model:value="formModel['meta.title']" />
|
<n-input v-model:value="formModel['meta.title']" placeholder="Eg: My-System" />
|
||||||
</n-form-item-grid-item>
|
</n-form-item-grid-item>
|
||||||
<n-form-item-grid-item :span="2" label="路由路径" path="path">
|
<n-form-item-grid-item :span="2" label="路由路径" path="path">
|
||||||
<n-input v-model:value="formModel.path" />
|
<n-input v-model:value="formModel.path" placeholder="Eg: /system/user" />
|
||||||
</n-form-item-grid-item>
|
</n-form-item-grid-item>
|
||||||
<n-form-item-grid-item :span="1" label="菜单类型" path="meta.menuType">
|
<n-form-item-grid-item :span="1" label="菜单类型" path="meta.menuType">
|
||||||
<n-radio-group v-model:value="formModel['meta.menuType']" name="radiogroup">
|
<n-radio-group v-model:value="formModel['meta.menuType']" name="radiogroup">
|
||||||
@ -213,9 +235,13 @@ const options = [
|
|||||||
<icon-select v-model:value="formModel['meta.icon']" :disabled="modalType === 'view'" />
|
<icon-select v-model:value="formModel['meta.icon']" :disabled="modalType === 'view'" />
|
||||||
</n-form-item-grid-item>
|
</n-form-item-grid-item>
|
||||||
<n-form-item-grid-item v-if="formModel['meta.menuType'] === 'page'" :span="2" label="组件路径" path="componentPath">
|
<n-form-item-grid-item v-if="formModel['meta.menuType'] === 'page'" :span="2" label="组件路径" path="componentPath">
|
||||||
<n-input v-model:value="formModel.componentPath" />
|
<n-input v-model:value="formModel.componentPath" placeholder="Eg: /system/user/index.vue" />
|
||||||
</n-form-item-grid-item>
|
</n-form-item-grid-item>
|
||||||
<n-form-item-grid-item :span="1" label="菜单排序" path="meta.order">
|
<n-form-item-grid-item :span="1" path="meta.order">
|
||||||
|
<template #label>
|
||||||
|
菜单排序
|
||||||
|
<HelpInfo message="数字越小,同级中越靠前" />
|
||||||
|
</template>
|
||||||
<n-input-number v-model:value="formModel['meta.order']" />
|
<n-input-number v-model:value="formModel['meta.order']" />
|
||||||
</n-form-item-grid-item>
|
</n-form-item-grid-item>
|
||||||
<n-form-item-grid-item v-if="formModel['meta.menuType'] === 'page'" :span="1" path="meta.herf">
|
<n-form-item-grid-item v-if="formModel['meta.menuType'] === 'page'" :span="1" path="meta.herf">
|
||||||
@ -223,7 +249,7 @@ const options = [
|
|||||||
外链页面
|
外链页面
|
||||||
<HelpInfo message="填写后,点击菜单将跳转到该地址,组件路径任意填写" />
|
<HelpInfo message="填写后,点击菜单将跳转到该地址,组件路径任意填写" />
|
||||||
</template>
|
</template>
|
||||||
<n-input v-model:value="formModel['meta.herf']" />
|
<n-input v-model:value="formModel['meta.herf']" placeholder="Eg: https://example.com" />
|
||||||
</n-form-item-grid-item>
|
</n-form-item-grid-item>
|
||||||
<n-form-item-grid-item :span="1" label="登录访问" path="meta.requiresAuth">
|
<n-form-item-grid-item :span="1" label="登录访问" path="meta.requiresAuth">
|
||||||
<n-switch v-model:value="formModel['meta.requiresAuth']" />
|
<n-switch v-model:value="formModel['meta.requiresAuth']" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user