Commit 93a97cd52635423db6dde8bfa908f851962d5d50
1 parent
fa79f422
perf: 优化表单校验和查询参数
Showing
23 changed files
with
161 additions
and
34 deletions
yudao-ui-admin-vue3/src/utils/tree.ts
| ... | ... | @@ -213,7 +213,7 @@ export const eachTree = (treeDatas: any[], callBack: Fn, parentNode = {}) => { |
| 213 | 213 | * @param {*} parentId 父节点字段 默认 'parentId' |
| 214 | 214 | * @param {*} children 孩子节点字段 默认 'children' |
| 215 | 215 | */ |
| 216 | -export const handleTree = (data, id?: string, parentId?: string, children?: string) => { | |
| 216 | +export const handleTree = (data: any[], id?: string, parentId?: string, children?: string) => { | |
| 217 | 217 | const config = { |
| 218 | 218 | id: id || 'id', |
| 219 | 219 | parentId: parentId || 'parentId', |
| ... | ... | @@ -222,7 +222,7 @@ export const handleTree = (data, id?: string, parentId?: string, children?: stri |
| 222 | 222 | |
| 223 | 223 | const childrenListMap = {} |
| 224 | 224 | const nodeIds = {} |
| 225 | - const tree = [] | |
| 225 | + const tree: any[] = [] | |
| 226 | 226 | |
| 227 | 227 | for (const d of data) { |
| 228 | 228 | const parentId = d[config.parentId] | ... | ... |
yudao-ui-admin-vue3/src/views/infra/apiAccessLog/apiAccessLog.data.ts
| ... | ... | @@ -50,7 +50,16 @@ const crudSchemas = reactive<CrudSchema[]>([ |
| 50 | 50 | }, |
| 51 | 51 | { |
| 52 | 52 | label: '请求时间', |
| 53 | - field: 'beginTime' | |
| 53 | + field: 'beginTime', | |
| 54 | + search: { | |
| 55 | + show: true, | |
| 56 | + component: 'DatePicker', | |
| 57 | + componentProps: { | |
| 58 | + type: 'datetimerange', | |
| 59 | + valueFormat: 'YYYY-MM-DD HH:mm:ss', | |
| 60 | + defaultTime: [new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 2, 1, 23, 59, 59)] | |
| 61 | + } | |
| 62 | + } | |
| 54 | 63 | }, |
| 55 | 64 | { |
| 56 | 65 | label: '执行时长', | ... | ... |
yudao-ui-admin-vue3/src/views/infra/apiErrorLog/apiErrorLog.data.ts
| ... | ... | @@ -50,7 +50,16 @@ const crudSchemas = reactive<CrudSchema[]>([ |
| 50 | 50 | }, |
| 51 | 51 | { |
| 52 | 52 | label: '异常发生时间', |
| 53 | - field: 'exceptionTime' | |
| 53 | + field: 'exceptionTime', | |
| 54 | + search: { | |
| 55 | + show: true, | |
| 56 | + component: 'DatePicker', | |
| 57 | + componentProps: { | |
| 58 | + type: 'datetimerange', | |
| 59 | + valueFormat: 'YYYY-MM-DD HH:mm:ss', | |
| 60 | + defaultTime: [new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 2, 1, 23, 59, 59)] | |
| 61 | + } | |
| 62 | + } | |
| 54 | 63 | }, |
| 55 | 64 | { |
| 56 | 65 | label: '异常名', | ... | ... |
yudao-ui-admin-vue3/src/views/infra/codegen/codegen.data.ts
| ... | ... | @@ -50,6 +50,15 @@ const crudSchemas = reactive<CrudSchema[]>([ |
| 50 | 50 | field: 'createTime', |
| 51 | 51 | form: { |
| 52 | 52 | show: false |
| 53 | + }, | |
| 54 | + search: { | |
| 55 | + show: true, | |
| 56 | + component: 'DatePicker', | |
| 57 | + componentProps: { | |
| 58 | + type: 'datetimerange', | |
| 59 | + valueFormat: 'YYYY-MM-DD HH:mm:ss', | |
| 60 | + defaultTime: [new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 2, 1, 23, 59, 59)] | |
| 61 | + } | |
| 53 | 62 | } |
| 54 | 63 | }, |
| 55 | 64 | { | ... | ... |
yudao-ui-admin-vue3/src/views/infra/config/config.data.ts
| ... | ... | @@ -91,6 +91,15 @@ const crudSchemas = reactive<CrudSchema[]>([ |
| 91 | 91 | field: 'createTime', |
| 92 | 92 | form: { |
| 93 | 93 | show: false |
| 94 | + }, | |
| 95 | + search: { | |
| 96 | + show: true, | |
| 97 | + component: 'DatePicker', | |
| 98 | + componentProps: { | |
| 99 | + type: 'datetimerange', | |
| 100 | + valueFormat: 'YYYY-MM-DD HH:mm:ss', | |
| 101 | + defaultTime: [new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 2, 1, 23, 59, 59)] | |
| 102 | + } | |
| 94 | 103 | } |
| 95 | 104 | }, |
| 96 | 105 | { | ... | ... |
yudao-ui-admin-vue3/src/views/infra/dataSourceConfig/dataSourceConfig.data.ts
| ... | ... | @@ -58,6 +58,15 @@ const crudSchemas = reactive<CrudSchema[]>([ |
| 58 | 58 | field: 'createTime', |
| 59 | 59 | form: { |
| 60 | 60 | show: false |
| 61 | + }, | |
| 62 | + search: { | |
| 63 | + show: true, | |
| 64 | + component: 'DatePicker', | |
| 65 | + componentProps: { | |
| 66 | + type: 'datetimerange', | |
| 67 | + valueFormat: 'YYYY-MM-DD HH:mm:ss', | |
| 68 | + defaultTime: [new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 2, 1, 23, 59, 59)] | |
| 69 | + } | |
| 61 | 70 | } |
| 62 | 71 | }, |
| 63 | 72 | { | ... | ... |
yudao-ui-admin-vue3/src/views/infra/fileConfig/fileConfig.data.ts
| ... | ... | @@ -76,6 +76,15 @@ const crudSchemas = reactive<CrudSchema[]>([ |
| 76 | 76 | field: 'createTime', |
| 77 | 77 | form: { |
| 78 | 78 | show: false |
| 79 | + }, | |
| 80 | + search: { | |
| 81 | + show: true, | |
| 82 | + component: 'DatePicker', | |
| 83 | + componentProps: { | |
| 84 | + type: 'datetimerange', | |
| 85 | + valueFormat: 'YYYY-MM-DD HH:mm:ss', | |
| 86 | + defaultTime: [new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 2, 1, 23, 59, 59)] | |
| 87 | + } | |
| 79 | 88 | } |
| 80 | 89 | }, |
| 81 | 90 | { | ... | ... |
yudao-ui-admin-vue3/src/views/infra/fileList/fileList.data.ts
| ... | ... | @@ -36,6 +36,15 @@ const crudSchemas = reactive<CrudSchema[]>([ |
| 36 | 36 | field: 'createTime', |
| 37 | 37 | form: { |
| 38 | 38 | show: false |
| 39 | + }, | |
| 40 | + search: { | |
| 41 | + show: true, | |
| 42 | + component: 'DatePicker', | |
| 43 | + componentProps: { | |
| 44 | + type: 'datetimerange', | |
| 45 | + valueFormat: 'YYYY-MM-DD HH:mm:ss', | |
| 46 | + defaultTime: [new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 2, 1, 23, 59, 59)] | |
| 47 | + } | |
| 39 | 48 | } |
| 40 | 49 | }, |
| 41 | 50 | { | ... | ... |
yudao-ui-admin-vue3/src/views/pay/app/app.data.ts
| ... | ... | @@ -8,9 +8,10 @@ const { t } = useI18n() // 国际化 |
| 8 | 8 | // 表单校验 |
| 9 | 9 | export const rules = reactive({ |
| 10 | 10 | name: [required], |
| 11 | - code: [required], | |
| 12 | - sort: [required], | |
| 13 | - status: [required] | |
| 11 | + status: [required], | |
| 12 | + payNotifyUrl: [required], | |
| 13 | + refundNotifyUrl: [required], | |
| 14 | + merchantId: [required] | |
| 14 | 15 | }) |
| 15 | 16 | |
| 16 | 17 | // CrudSchema |
| ... | ... | @@ -53,6 +54,15 @@ const crudSchemas = reactive<CrudSchema[]>([ |
| 53 | 54 | field: 'createTime', |
| 54 | 55 | form: { |
| 55 | 56 | show: false |
| 57 | + }, | |
| 58 | + search: { | |
| 59 | + show: true, | |
| 60 | + component: 'DatePicker', | |
| 61 | + componentProps: { | |
| 62 | + type: 'datetimerange', | |
| 63 | + valueFormat: 'YYYY-MM-DD HH:mm:ss', | |
| 64 | + defaultTime: [new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 2, 1, 23, 59, 59)] | |
| 65 | + } | |
| 56 | 66 | } |
| 57 | 67 | }, |
| 58 | 68 | { | ... | ... |
yudao-ui-admin-vue3/src/views/pay/merchant/merchant.data.ts
| ... | ... | @@ -7,9 +7,9 @@ const { t } = useI18n() // 国际化 |
| 7 | 7 | |
| 8 | 8 | // 表单校验 |
| 9 | 9 | export const rules = reactive({ |
| 10 | + no: [required], | |
| 10 | 11 | name: [required], |
| 11 | - code: [required], | |
| 12 | - sort: [required], | |
| 12 | + shortName: [required], | |
| 13 | 13 | status: [required] |
| 14 | 14 | }) |
| 15 | 15 | |
| ... | ... | @@ -77,6 +77,15 @@ const crudSchemas = reactive<CrudSchema[]>([ |
| 77 | 77 | field: 'createTime', |
| 78 | 78 | form: { |
| 79 | 79 | show: false |
| 80 | + }, | |
| 81 | + search: { | |
| 82 | + show: true, | |
| 83 | + component: 'DatePicker', | |
| 84 | + componentProps: { | |
| 85 | + type: 'datetimerange', | |
| 86 | + valueFormat: 'YYYY-MM-DD HH:mm:ss', | |
| 87 | + defaultTime: [new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 2, 1, 23, 59, 59)] | |
| 88 | + } | |
| 80 | 89 | } |
| 81 | 90 | }, |
| 82 | 91 | { | ... | ... |
yudao-ui-admin-vue3/src/views/pay/order/order.data.ts
| ... | ... | @@ -158,6 +158,22 @@ const crudSchemas = reactive<CrudSchema[]>([ |
| 158 | 158 | field: 'channelOrderNo' |
| 159 | 159 | }, |
| 160 | 160 | { |
| 161 | + label: t('common.createTime'), | |
| 162 | + field: 'createTime', | |
| 163 | + form: { | |
| 164 | + show: false | |
| 165 | + }, | |
| 166 | + search: { | |
| 167 | + show: true, | |
| 168 | + component: 'DatePicker', | |
| 169 | + componentProps: { | |
| 170 | + type: 'datetimerange', | |
| 171 | + valueFormat: 'YYYY-MM-DD HH:mm:ss', | |
| 172 | + defaultTime: [new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 2, 1, 23, 59, 59)] | |
| 173 | + } | |
| 174 | + } | |
| 175 | + }, | |
| 176 | + { | |
| 161 | 177 | label: t('table.action'), |
| 162 | 178 | field: 'action', |
| 163 | 179 | width: '270px', | ... | ... |
yudao-ui-admin-vue3/src/views/pay/refund/refund.data.ts
| ... | ... | @@ -84,6 +84,15 @@ const crudSchemas = reactive<CrudSchema[]>([ |
| 84 | 84 | field: 'createTime', |
| 85 | 85 | form: { |
| 86 | 86 | show: false |
| 87 | + }, | |
| 88 | + search: { | |
| 89 | + show: true, | |
| 90 | + component: 'DatePicker', | |
| 91 | + componentProps: { | |
| 92 | + type: 'datetimerange', | |
| 93 | + valueFormat: 'YYYY-MM-DD HH:mm:ss', | |
| 94 | + defaultTime: [new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 2, 1, 23, 59, 59)] | |
| 95 | + } | |
| 87 | 96 | } |
| 88 | 97 | }, |
| 89 | 98 | { | ... | ... |
yudao-ui-admin-vue3/src/views/system/dept/dept.data.ts
| 1 | 1 | import { required } from '@/utils/formRules' |
| 2 | 2 | import { reactive } from 'vue' |
| 3 | +// 表单校验 | |
| 4 | +export const rules = reactive({ | |
| 5 | + name: [required], | |
| 6 | + sort: [required], | |
| 7 | + email: [required], | |
| 8 | + phone: [ | |
| 9 | + { | |
| 10 | + pattern: | |
| 11 | + /^(?:(?:\+|00)86)?1(?:(?:3[\d])|(?:4[5-79])|(?:5[0-35-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[189]))\d{8}$/, | |
| 12 | + trigger: 'blur', | |
| 13 | + message: '请输入正确的手机号码' | |
| 14 | + } | |
| 15 | + ] | |
| 16 | +}) | |
| 3 | 17 | |
| 4 | 18 | export const modelSchema = reactive<FormSchema[]>([ |
| 5 | 19 | { | ... | ... |
yudao-ui-admin-vue3/src/views/system/dept/index.vue
| ... | ... | @@ -5,7 +5,7 @@ import { handleTree } from '@/utils/tree' |
| 5 | 5 | import { onMounted, ref, unref, watch } from 'vue' |
| 6 | 6 | import * as DeptApi from '@/api/system/dept' |
| 7 | 7 | import { Form, FormExpose } from '@/components/Form' |
| 8 | -import { modelSchema } from './dept.data' | |
| 8 | +import { modelSchema, rules } from './dept.data' | |
| 9 | 9 | import { DeptVO } from '@/api/system/dept/types' |
| 10 | 10 | import { useMessage } from '@/hooks/web/useMessage' |
| 11 | 11 | import { getListSimpleUsersApi } from '@/api/system/user' |
| ... | ... | @@ -159,7 +159,7 @@ onMounted(async () => { |
| 159 | 159 | </div> |
| 160 | 160 | <div v-if="showForm"> |
| 161 | 161 | <!-- 操作工具栏 --> |
| 162 | - <Form :schema="modelSchema" ref="formRef"> | |
| 162 | + <Form ref="formRef" :schema="modelSchema" :rules="rules"> | |
| 163 | 163 | <template #parentId> |
| 164 | 164 | <el-tree-select |
| 165 | 165 | node-key="id" | ... | ... |
yudao-ui-admin-vue3/src/views/system/dict/dict.data.ts
| ... | ... | @@ -7,9 +7,9 @@ import { CrudSchema, useCrudSchemas } from '@/hooks/web/useCrudSchemas' |
| 7 | 7 | const { t } = useI18n() |
| 8 | 8 | // 表单校验 |
| 9 | 9 | export const dictDataRules = reactive({ |
| 10 | - dictType: [required], | |
| 11 | 10 | label: [required], |
| 12 | - value: [required] | |
| 11 | + value: [required], | |
| 12 | + sort: [required] | |
| 13 | 13 | }) |
| 14 | 14 | // crudSchemas |
| 15 | 15 | export const crudSchemas = reactive<CrudSchema[]>([ | ... | ... |
yudao-ui-admin-vue3/src/views/system/menu/index.vue
| ... | ... | @@ -25,11 +25,12 @@ import { MenuVO } from '@/api/system/menu/types' |
| 25 | 25 | import { SystemMenuTypeEnum, CommonStatusEnum } from '@/utils/constants' |
| 26 | 26 | import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' |
| 27 | 27 | import { useMessage } from '@/hooks/web/useMessage' |
| 28 | +import { required } from '@/utils/formRules.js' | |
| 28 | 29 | const message = useMessage() |
| 29 | 30 | const { t } = useI18n() // 国际化 |
| 30 | 31 | // ========== 创建菜单树结构 ========== |
| 31 | 32 | const loading = ref(true) |
| 32 | -const menuData = ref([]) // 树形结构 | |
| 33 | +const menuData = ref<any[]>([]) // 树形结构 | |
| 33 | 34 | const getList = async () => { |
| 34 | 35 | const res = await MenuApi.getMenuListApi(queryParams) |
| 35 | 36 | menuData.value = handleTree(res) |
| ... | ... | @@ -44,7 +45,7 @@ const menuProps = { |
| 44 | 45 | const menuOptions = ref() // 树形结构 |
| 45 | 46 | const getTree = async () => { |
| 46 | 47 | const res = await MenuApi.listSimpleMenusApi() |
| 47 | - const menu = { id: 0, name: '主类目', children: [] } | |
| 48 | + const menu = { id: 0, name: '主类目', children: [] as any[] } | |
| 48 | 49 | menu.children = handleTree(res) |
| 49 | 50 | console.info(menu) |
| 50 | 51 | menuOptions.value = menu |
| ... | ... | @@ -85,12 +86,12 @@ const menuForm = ref<MenuVO>({ |
| 85 | 86 | createTime: '' |
| 86 | 87 | }) |
| 87 | 88 | // 表单校验 |
| 88 | -const rules = { | |
| 89 | - name: [{ required: true, message: '菜单名称不能为空', trigger: 'blur' }], | |
| 90 | - sort: [{ required: true, message: '菜单顺序不能为空', trigger: 'blur' }], | |
| 91 | - path: [{ required: true, message: '路由地址不能为空', trigger: 'blur' }], | |
| 92 | - status: [{ required: true, message: '状态不能为空', trigger: 'blur' }] | |
| 93 | -} | |
| 89 | +const rules = reactive({ | |
| 90 | + name: [required], | |
| 91 | + sort: [required], | |
| 92 | + path: [required], | |
| 93 | + status: [required] | |
| 94 | +}) | |
| 94 | 95 | // 设置标题 |
| 95 | 96 | const setDialogTile = (type: string) => { |
| 96 | 97 | dialogTitle.value = t('action.' + type) | ... | ... |
yudao-ui-admin-vue3/src/views/system/notice/notice.data.ts
yudao-ui-admin-vue3/src/views/system/post/post.data.ts
yudao-ui-admin-vue3/src/views/system/sms/smsTemplate/sms.template.data.ts
| ... | ... | @@ -8,13 +8,12 @@ const { t } = useI18n() // 国际化 |
| 8 | 8 | // 表单校验 |
| 9 | 9 | export const rules = reactive({ |
| 10 | 10 | type: [required], |
| 11 | + status: [required], | |
| 12 | + code: [required], | |
| 11 | 13 | name: [required], |
| 12 | 14 | content: [required], |
| 13 | 15 | apiTemplateId: [required], |
| 14 | - channelId: [required], | |
| 15 | - code: [required], | |
| 16 | - sort: [required], | |
| 17 | - status: [required] | |
| 16 | + channelId: [required] | |
| 18 | 17 | }) |
| 19 | 18 | |
| 20 | 19 | // CrudSchema | ... | ... |
yudao-ui-admin-vue3/src/views/system/user/index.vue
| ... | ... | @@ -63,7 +63,7 @@ const { getList, setSearchParams, delList, exportList } = methods |
| 63 | 63 | |
| 64 | 64 | // ========== 创建部门树结构 ========== |
| 65 | 65 | const filterText = ref('') |
| 66 | -const deptOptions = ref([]) // 树形结构 | |
| 66 | +const deptOptions = ref<any[]>([]) // 树形结构 | |
| 67 | 67 | const searchForm = ref<FormExpose>() |
| 68 | 68 | const treeRef = ref<InstanceType<typeof ElTree>>() |
| 69 | 69 | const getTree = async () => { | ... | ... |
yudao-ui-admin-vue3/src/views/system/user/user.data.ts
| ... | ... | @@ -7,8 +7,18 @@ import { CrudSchema, useCrudSchemas } from '@/hooks/web/useCrudSchemas' |
| 7 | 7 | const { t } = useI18n() |
| 8 | 8 | // 表单校验 |
| 9 | 9 | export const rules = reactive({ |
| 10 | + username: [required], | |
| 10 | 11 | nickname: [required], |
| 11 | - status: [required] | |
| 12 | + email: [required], | |
| 13 | + status: [required], | |
| 14 | + mobile: [ | |
| 15 | + { | |
| 16 | + pattern: | |
| 17 | + /^(?:(?:\+|00)86)?1(?:(?:3[\d])|(?:4[5-79])|(?:5[0-35-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[189]))\d{8}$/, | |
| 18 | + trigger: 'blur', | |
| 19 | + message: '请输入正确的手机号码' | |
| 20 | + } | |
| 21 | + ] | |
| 12 | 22 | }) |
| 13 | 23 | // crudSchemas |
| 14 | 24 | const crudSchemas = reactive<CrudSchema[]>([ | ... | ... |
yudao-ui-admin/src/views/system/dept/index.vue
| ... | ... | @@ -167,7 +167,7 @@ export default { |
| 167 | 167 | ], |
| 168 | 168 | phone: [ |
| 169 | 169 | { |
| 170 | - pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/, | |
| 170 | + pattern: /^(?:(?:\+|00)86)?1(?:(?:3[\d])|(?:4[5-79])|(?:5[0-35-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[189]))\d{8}$/, | |
| 171 | 171 | message: "请输入正确的手机号码", |
| 172 | 172 | trigger: "blur" |
| 173 | 173 | } | ... | ... |
yudao-ui-admin/src/views/system/tenant/index.vue
| ... | ... | @@ -183,8 +183,6 @@ export default { |
| 183 | 183 | accountCount: [{ required: true, message: "账号额度不能为空", trigger: "blur" }], |
| 184 | 184 | expireTime: [{ required: true, message: "过期时间不能为空", trigger: "blur" }], |
| 185 | 185 | domain: [{ required: true, message: "绑定域名不能为空", trigger: "blur" }], |
| 186 | - username: [{ required: true, message: "用户名称不能为空", trigger: "blur" }], | |
| 187 | - password: [{ required: true, message: "用户密码不能为空", trigger: "blur" }], | |
| 188 | 186 | } |
| 189 | 187 | }; |
| 190 | 188 | }, | ... | ... |