Skip to content

Commit

Permalink
fix: revert useDefault
Browse files Browse the repository at this point in the history
  • Loading branch information
chansee97 committed Jun 8, 2024
1 parent 530231a commit 57739f9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 41 deletions.
1 change: 0 additions & 1 deletion src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './useBoolean'
export * from './useEcharts'
export * from './usePermission'
export * from './useDefault'
15 changes: 0 additions & 15 deletions src/hooks/useDefault.ts

This file was deleted.

11 changes: 5 additions & 6 deletions src/views/setting/account/components/TableModal.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { useBoolean, useDefault } from '@/hooks'
import { useBoolean } from '@/hooks'
import { fetchRoleList } from '@/service'
interface Props {
Expand All @@ -19,14 +19,14 @@ const { bool: modalVisible, setTrue: showModal, setFalse: hiddenModal } = useBoo
const { bool: submitLoading, setTrue: startLoading, setFalse: endLoading } = useBoolean(false)
const formModel = useDefault<Entity.User>({
const formDefault: Entity.User = {
userName: '',
gender: undefined,
email: '',
tel: '',
role: [],
status: 1,
})
}
const formModel = ref<Entity.User>({ ...formDefault })
type ModalType = 'add' | 'view' | 'edit'
const modalType = shallowRef<ModalType>('add')
Expand All @@ -46,8 +46,7 @@ async function openModal(type: ModalType = 'add', data: any) {
getRoleList()
const handlers = {
async add() {
// @ts-expect-error undefined is safe
formModel.value = undefined
formModel.value = { ...formDefault }
},
async view() {
if (!data)
Expand Down
24 changes: 5 additions & 19 deletions src/views/setting/menu/components/TableModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {
FormItemRule,
} from 'naive-ui'
import HelpInfo from '@/components/common/HelpInfo.vue'
import { useBoolean, useDefault } from '@/hooks'
import { useBoolean } from '@/hooks'
import { Regex } from '@/constants'
import { fetchRoleList } from '@/service'
Expand All @@ -24,24 +24,20 @@ const emit = defineEmits<{
const { bool: modalVisible, setTrue: showModal, setFalse: hiddenModal } = useBoolean(false)
const { bool: submitLoading, setTrue: startLoading, setFalse: endLoading } = useBoolean(false)
const formModel = useDefault<AppRoute.RowRoute>({
const formDefault: AppRoute.RowRoute = {
name: '',
path: '',
id: -1,
pid: null,
title: '',
icon: '',
requiresAuth: true,
roles: [],
keepAlive: false,
hide: false,
order: undefined,
href: undefined,
activeMenu: undefined,
withoutTab: true,
pinTab: false,
menuType: 'page',
})
}
const formModel = ref<AppRoute.RowRoute>({ ...formDefault })
type ModalType = 'add' | 'view' | 'edit'
const modalType = shallowRef<ModalType>('add')
Expand All @@ -61,8 +57,7 @@ async function openModal(type: ModalType = 'add', data: AppRoute.RowRoute) {
showModal()
const handlers = {
async add() {
// @ts-expect-error undefined is safe
formModel.value = undefined
formModel.value = { ...formDefault }
},
async view() {
if (!data)
Expand Down Expand Up @@ -164,15 +159,6 @@ const rules = {
message: '请输入菜单标题',
trigger: 'blur',
},
href: {
validator(rule: FormItemRule, value: string) {
if (!new RegExp(Regex.Url).test(value))
return new Error('请输入正确的URL地址')
return true
},
trigger: 'blur',
},
}
const options = ref<Entity.Role[]>([])
Expand Down

0 comments on commit 57739f9

Please sign in to comment.