123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- <script setup lang="ts">
- import { Form, FormSchema } from '@/components/Form'
- import { useForm } from '@/hooks/web/useForm'
- import { PropType, reactive, watch } from 'vue'
- import { useValidator } from '@/hooks/web/useValidator'
- import { useI18n } from '@/hooks/web/useI18n'
- const { t } = useI18n()
- const { required } = useValidator()
- const props = defineProps({
- currentRow: {
- type: Object as PropType<any>,
- default: () => null
- },
- treeSelectData: Array
- })
- const formSchema = reactive<FormSchema[]>([
- {
- field: 'type',
- label: '类型',
- component: 'RadioGroup',
- hidden: true,
- value: 0,
- colProps: {
- span: 24
- },
- componentProps: {
- options: [
- {
- label: '目录',
- value: 0
- },
- {
- label: '菜单',
- value: 1
- },
- {
- label: '按钮',
- value: 2
- }
- ]
- }
- },
- {
- field: 'pid',
- label: '上级菜单',
- component: 'TreeSelect',
- componentProps: {
- checkStrictly: true,
- nodeKey: 'id',
- props: {
- label: 'name'
- },
- data: props.treeSelectData
- }
- },
- {
- field: 'url',
- label: '路由地址',
- component: 'Input'
- },
- {
- field: 'redirect',
- label: '重定向路由',
- component: 'Input'
- },
- {
- field: 'orderNum',
- label: '排序',
- component: 'InputNumber'
- },
- {
- field: 'meta.title',
- label: t('menu.menuName'),
- component: 'Input'
- },
- {
- field: 'component',
- label: t('menu.component'),
- component: 'Input'
- },
- {
- field: 'name',
- label: t('menu.name'),
- component: 'Input'
- },
- {
- field: 'meta.icon',
- label: t('menu.icon'),
- component: 'IconPicker'
- },
- {
- field: 'status',
- label: t('menu.status'),
- component: 'Select',
- componentProps: {
- options: [
- {
- label: t('userDemo.disable'),
- value: 0
- },
- {
- label: t('userDemo.enable'),
- value: 1
- }
- ]
- }
- },
- {
- field: 'permissions',
- label: '授权标识',
- component: 'Input'
- },
- {
- field: 'meta.activeMenu',
- label: t('menu.activeMenu'),
- component: 'Input'
- },
- // {
- // field: 'permission',
- // label: t('menu.permission'),
- // component: 'CheckboxGroup',
- // componentProps: {
- // options: [
- // {
- // label: 'add',
- // value: 'add'
- // },
- // {
- // label: 'edit',
- // value: 'edit'
- // },
- // {
- // label: 'delete',
- // value: 'delete'
- // }
- // ]
- // }
- // },
- {
- field: 'meta.hidden',
- label: t('menu.hidden'),
- component: 'Switch'
- },
- {
- field: 'meta.alwaysShow',
- label: t('menu.alwaysShow'),
- component: 'Switch'
- },
- {
- field: 'meta.noCache',
- label: t('menu.noCache'),
- component: 'Switch'
- },
- {
- field: 'meta.breadcrumb',
- label: t('menu.breadcrumb'),
- component: 'Switch'
- },
- {
- field: 'meta.affix',
- label: t('menu.affix'),
- component: 'Switch'
- },
- {
- field: 'meta.noTagsView',
- label: t('menu.noTagsView'),
- component: 'Switch'
- },
- {
- field: 'canTo',
- label: t('menu.canTo'),
- component: 'Switch'
- }
- ])
- const rules = reactive({
- name: [required()],
- url: [required()]
- })
- const { formRegister, formMethods } = useForm()
- const { setValues, getFormData, getElFormExpose } = formMethods
- const submit = async () => {
- const elForm = await getElFormExpose()
- const valid = await elForm?.validate().catch((err) => {
- console.log(err)
- })
- if (valid) {
- const formData = await getFormData()
- return formData
- }
- }
- watch(
- () => props.currentRow,
- (currentRow) => {
- if (!currentRow) return
- let form = {
- ...currentRow
- }
- setValues(form)
- },
- {
- deep: true,
- immediate: true
- }
- )
- defineExpose({
- submit
- })
- </script>
- <template>
- <Form :rules="rules" @register="formRegister" :schema="formSchema" />
- </template>
|