|
|
@@ -1,36 +1,185 @@ |
|
|
|
<template> |
|
|
|
<Modal :options="getModalOptions" @on-close="handleClose"> |
|
|
|
<Modal |
|
|
|
:options="getModalOptions" |
|
|
|
:on-close="handleClose" |
|
|
|
:on-positive-click="handleConfirm" |
|
|
|
:on-negative-click="handleClose" |
|
|
|
> |
|
|
|
<template #Context> |
|
|
|
111 |
|
|
|
<n-form ref="formRef" :model="menuForm" :rules="menuRules" require-mark-placement="left" :label-width="80" label-placement="left"> |
|
|
|
<n-grid x-gap="12" :cols="2"> |
|
|
|
<n-gi> |
|
|
|
<n-form-item label="上级菜单" path="pid"> |
|
|
|
<n-select |
|
|
|
v-model:value="menuForm.pid" |
|
|
|
placeholder="请选择上级菜单" |
|
|
|
:options="getMenuList" |
|
|
|
/> |
|
|
|
</n-form-item> |
|
|
|
</n-gi> |
|
|
|
<n-gi> |
|
|
|
<n-form-item label="菜单类型" path="type"> |
|
|
|
<n-radio-group v-model:value="menuForm.type" name="type"> |
|
|
|
<n-radio v-for="item in typeOptions" :key="`type_${item.key}`" :value="item.key"> |
|
|
|
{{ item.label }} |
|
|
|
</n-radio> |
|
|
|
</n-radio-group> |
|
|
|
</n-form-item> |
|
|
|
</n-gi> |
|
|
|
<n-gi> |
|
|
|
<n-form-item label="菜单名称" path="title"> |
|
|
|
<n-input v-model:value="menuForm.title" placeholder="请输入菜单名称" /> |
|
|
|
</n-form-item> |
|
|
|
</n-gi> |
|
|
|
<n-gi> |
|
|
|
<n-form-item label="打开方式" path="target"> |
|
|
|
<n-radio-group v-model:value="menuForm.target" name="target"> |
|
|
|
<n-radio v-for="item in openOptions" :key="`target_${item.key}`" :value="item.key"> |
|
|
|
{{ item.label }} |
|
|
|
</n-radio> |
|
|
|
</n-radio-group> |
|
|
|
</n-form-item> |
|
|
|
</n-gi> |
|
|
|
<n-gi> |
|
|
|
<n-form-item label="菜单图标" path="icon"> |
|
|
|
<n-input v-model:value="menuForm.icon" placeholder="请选择菜单图标" /> |
|
|
|
</n-form-item> |
|
|
|
</n-gi> |
|
|
|
<n-gi> |
|
|
|
<n-form-item label="权限标识" path="permission"> |
|
|
|
<n-input v-model:value="menuForm.permission" placeholder="请输入权限标识" /> |
|
|
|
</n-form-item> |
|
|
|
</n-gi> |
|
|
|
<n-gi> |
|
|
|
<n-form-item label="路由地址" path="path"> |
|
|
|
<n-input v-model:value="menuForm.path" placeholder="请输入路由地址" /> |
|
|
|
</n-form-item> |
|
|
|
</n-gi> |
|
|
|
<n-gi> |
|
|
|
<n-form-item label="排序号" path="sort"> |
|
|
|
<n-input v-model:value="menuForm.sort" placeholder="请输入排序号" /> |
|
|
|
</n-form-item> |
|
|
|
</n-gi> |
|
|
|
<n-gi> |
|
|
|
<n-form-item label="组件路径" path="component"> |
|
|
|
<n-input v-model:value="menuForm.component" placeholder="请输入组件路径" /> |
|
|
|
</n-form-item> |
|
|
|
</n-gi> |
|
|
|
<n-gi> |
|
|
|
<n-form-item label="是否可见" path="hide"> |
|
|
|
<n-radio-group v-model:value="menuForm.hide" name="hide"> |
|
|
|
<n-radio v-for="item in visibleOptions" :key="`hide_${item.key}`" :value="item.key"> |
|
|
|
{{ item.label }} |
|
|
|
</n-radio> |
|
|
|
</n-radio-group> |
|
|
|
</n-form-item> |
|
|
|
</n-gi> |
|
|
|
<n-gi> |
|
|
|
<n-form-item label="菜单状态" path="status"> |
|
|
|
<n-radio-group v-model:value="menuForm.status" name="status"> |
|
|
|
<n-radio v-for="item in statusOptions" :key="`status_${item.key}`" :value="item.key"> |
|
|
|
{{ item.label }} |
|
|
|
</n-radio> |
|
|
|
</n-radio-group> |
|
|
|
</n-form-item> |
|
|
|
</n-gi> |
|
|
|
|
|
|
|
</n-grid> |
|
|
|
</n-form> |
|
|
|
</template> |
|
|
|
</Modal> |
|
|
|
</template> |
|
|
|
|
|
|
|
<script> |
|
|
|
import { defineComponent, computed } from 'vue' |
|
|
|
import Modal from '@/components/CardModal/index.vue' |
|
|
|
import { defineComponent, computed, reactive, toRefs, ref } from 'vue' |
|
|
|
import Modal from '@/components/Modal/index.vue' |
|
|
|
import { addMenu } from '@/api/system/menu/index.js' |
|
|
|
export default defineComponent({ |
|
|
|
name: 'MenuModal', |
|
|
|
components: { Modal }, |
|
|
|
props: { |
|
|
|
/* 可见 */ |
|
|
|
visible: { |
|
|
|
type: Boolean, |
|
|
|
default: false |
|
|
|
}, |
|
|
|
row: { |
|
|
|
/* 选中的数据 */ |
|
|
|
data: { |
|
|
|
type: Object, |
|
|
|
default: () => {} |
|
|
|
}, |
|
|
|
menuList: { |
|
|
|
type: Array, |
|
|
|
default: () => [] |
|
|
|
} |
|
|
|
}, |
|
|
|
emits: { |
|
|
|
'update:visible': null, |
|
|
|
onClose: null, |
|
|
|
done: null |
|
|
|
'update:visible': null |
|
|
|
}, |
|
|
|
setup(props, { emit }) { |
|
|
|
const data = reactive({ |
|
|
|
menuForm: { |
|
|
|
pid: null, |
|
|
|
type: '0', |
|
|
|
title: '', |
|
|
|
target: '0', |
|
|
|
icon: '', |
|
|
|
permission: '', |
|
|
|
path: '', |
|
|
|
sort: '', |
|
|
|
component: '', |
|
|
|
hide: '0', |
|
|
|
status: '1' |
|
|
|
}, |
|
|
|
menuRules: { |
|
|
|
title: { |
|
|
|
required: true, |
|
|
|
message: '请输入菜单名称', |
|
|
|
trigger: ['blur'] |
|
|
|
}, |
|
|
|
sort: { |
|
|
|
required: true, |
|
|
|
message: '请输入排序号', |
|
|
|
trigger: ['blur'] |
|
|
|
} |
|
|
|
}, |
|
|
|
typeOptions: [ |
|
|
|
{ key: '0', label: '菜单' }, |
|
|
|
{ key: '1', label: '按钮' } |
|
|
|
], |
|
|
|
openOptions: [ |
|
|
|
{ key: '0', label: '组件' }, |
|
|
|
{ key: '1', label: '内链' }, |
|
|
|
{ key: '2', label: '外链' } |
|
|
|
], |
|
|
|
visibleOptions: [ |
|
|
|
{ key: '0', label: '可见' }, |
|
|
|
{ key: '1', label: '不可见' } |
|
|
|
], |
|
|
|
statusOptions: [ |
|
|
|
{ key: '1', label: '在用' }, |
|
|
|
{ key: '2', label: '停用' } |
|
|
|
] |
|
|
|
}) |
|
|
|
|
|
|
|
const getMenuList = computed(() => { |
|
|
|
const list = props.menuList.map((item) => { |
|
|
|
const menu = { |
|
|
|
label: item.title, |
|
|
|
value: item.pid |
|
|
|
} |
|
|
|
return menu |
|
|
|
}) |
|
|
|
return list |
|
|
|
}) |
|
|
|
|
|
|
|
const getModalOptions = computed(() => { |
|
|
|
return { |
|
|
|
show: props.visible |
|
|
|
show: props.visible, |
|
|
|
title: props.data ? '修改菜单' : '新建菜单', |
|
|
|
width: 700, |
|
|
|
negativeText: '取消', |
|
|
|
positiveText: '确认' |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
@@ -38,10 +187,32 @@ export default defineComponent({ |
|
|
|
const handleClose = () => { |
|
|
|
emit('update:visible', false) |
|
|
|
} |
|
|
|
const formRef = ref() |
|
|
|
const handleConfirm = () => { |
|
|
|
formRef.value?.validate((errors) => { |
|
|
|
if (!errors) { |
|
|
|
const params = { |
|
|
|
...data.menuForm |
|
|
|
} |
|
|
|
addMenu(params) |
|
|
|
.then(res => { |
|
|
|
console.log(res) |
|
|
|
handleClose() |
|
|
|
}) |
|
|
|
} else { |
|
|
|
// console.log('error') |
|
|
|
} |
|
|
|
}) |
|
|
|
return false |
|
|
|
} |
|
|
|
|
|
|
|
return { |
|
|
|
...toRefs(data), |
|
|
|
formRef, |
|
|
|
getMenuList, |
|
|
|
getModalOptions, |
|
|
|
handleClose |
|
|
|
handleClose, |
|
|
|
handleConfirm |
|
|
|
} |
|
|
|
} |
|
|
|
}) |