2024-10-17 15:09:27 +08:00
|
|
|
|
<template>
|
2024-11-14 11:34:25 +08:00
|
|
|
|
<el-dialog :title="dialogTitle" :model-value="dialogVisible" @close="close" v-bind="dialogMiddle">
|
2024-11-14 18:26:34 +08:00
|
|
|
|
<el-form :model="formContent" ref='dialogFormRef' :rules='rules' >
|
2024-11-14 11:34:25 +08:00
|
|
|
|
<el-form-item label="上级菜单" prop="pid" :label-width="100">
|
|
|
|
|
|
<el-tree-select
|
2024-11-14 20:36:54 +08:00
|
|
|
|
v-model="formContent.pid"
|
|
|
|
|
|
:data="functionList"
|
2024-11-14 11:34:25 +08:00
|
|
|
|
check-strictly
|
|
|
|
|
|
:render-after-expand="false"
|
|
|
|
|
|
check-on-click-node
|
2024-11-14 20:36:54 +08:00
|
|
|
|
:props="defaultProps"
|
2024-11-14 11:34:25 +08:00
|
|
|
|
/>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item label="名称" prop="name" :label-width="100">
|
|
|
|
|
|
<el-input v-model="formContent.name" />
|
|
|
|
|
|
</el-form-item>
|
2024-11-14 19:24:36 +08:00
|
|
|
|
<el-form-item label="编码" prop="code" :label-width="100">
|
|
|
|
|
|
<el-input v-model="formContent.code" />
|
|
|
|
|
|
</el-form-item>
|
2024-11-14 11:34:25 +08:00
|
|
|
|
<el-form-item label="图标" prop="icon" :label-width="100">
|
|
|
|
|
|
<IconSelect
|
|
|
|
|
|
:iconValue="formContent.icon"
|
|
|
|
|
|
@update:iconValue="(value) => formContent.icon = value"
|
|
|
|
|
|
placeholder="选择一个图标"
|
|
|
|
|
|
/>
|
2024-10-17 15:09:27 +08:00
|
|
|
|
</el-form-item>
|
2024-11-14 11:34:25 +08:00
|
|
|
|
<el-form-item label="路由地址" prop="path" :label-width="100">
|
|
|
|
|
|
<el-input v-model="formContent.path" />
|
2024-10-17 15:09:27 +08:00
|
|
|
|
</el-form-item>
|
2024-11-14 11:34:25 +08:00
|
|
|
|
<el-form-item label="组件地址" prop="component" :label-width="100">
|
|
|
|
|
|
<el-input v-model="formContent.component" />
|
2024-10-17 15:09:27 +08:00
|
|
|
|
</el-form-item>
|
2024-11-14 11:34:25 +08:00
|
|
|
|
<el-form-item label="排序" prop="sort" :label-width="100">
|
2024-11-14 18:26:34 +08:00
|
|
|
|
<el-input-number v-model="formContent.sort" :min='1' :max='999' />
|
2024-11-14 11:34:25 +08:00
|
|
|
|
</el-form-item>
|
2024-11-14 19:24:36 +08:00
|
|
|
|
<el-form-item label='类型' prop='type' :label-width="100">
|
|
|
|
|
|
<el-select v-model="formContent.type" clearable placeholder="请选择资源类型">
|
|
|
|
|
|
<el-option label="菜单" :value="0"></el-option>
|
|
|
|
|
|
<el-option label="按钮" :value="1"></el-option>
|
|
|
|
|
|
<el-option label="公共资源" :value="2"></el-option>
|
|
|
|
|
|
<el-option label="服务间调用资源" :value="3"></el-option>
|
2024-10-17 15:09:27 +08:00
|
|
|
|
</el-select>
|
2024-11-14 19:24:36 +08:00
|
|
|
|
</el-form-item>
|
2024-11-14 11:34:25 +08:00
|
|
|
|
<el-form-item label="描述" prop="remark" :label-width="100">
|
|
|
|
|
|
<el-input v-model="formContent.remark" :rows="2" type="textarea"/>
|
2024-10-17 15:09:27 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-form>
|
|
|
|
|
|
<template #footer>
|
|
|
|
|
|
<div class="dialog-footer">
|
2024-11-14 11:34:25 +08:00
|
|
|
|
<el-button @click="close()">取 消</el-button>
|
|
|
|
|
|
<el-button type="primary" @click="save()">确 定</el-button>
|
2024-10-17 15:09:27 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-dialog>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
2024-10-23 19:30:11 +08:00
|
|
|
|
<script lang="ts" setup name="ResourceDialog">
|
2024-11-14 11:34:25 +08:00
|
|
|
|
import { defineProps, defineEmits,watch,ref, type Ref, computed } from 'vue';
|
|
|
|
|
|
import { dialogMiddle } from '@/utils/elementBind'
|
2024-11-18 09:02:57 +08:00
|
|
|
|
import { ElMessage, type FormInstance, type FormItemRule } from 'element-plus'
|
2024-10-30 19:07:41 +08:00
|
|
|
|
import { useDictStore } from '@/stores/modules/dict'
|
2024-11-18 09:02:57 +08:00
|
|
|
|
import type { Function } from "@/api/user/interface/function"
|
|
|
|
|
|
import {addFunction,updateFunction,getFunctionListNoButton} from '@/api/user/function/index'
|
2024-11-14 11:34:25 +08:00
|
|
|
|
import IconSelect from '@/components/SelectIcon/index.vue'
|
|
|
|
|
|
const value = ref()
|
2024-11-14 20:36:54 +08:00
|
|
|
|
// 树形节点配置
|
|
|
|
|
|
const defaultProps = {
|
|
|
|
|
|
children: 'children',
|
|
|
|
|
|
label: 'name',
|
|
|
|
|
|
};
|
2024-11-14 11:34:25 +08:00
|
|
|
|
|
2024-10-30 19:07:41 +08:00
|
|
|
|
const dictStore = useDictStore()
|
2024-11-14 11:34:25 +08:00
|
|
|
|
// 定义弹出组件元信息
|
|
|
|
|
|
const dialogFormRef = ref()
|
|
|
|
|
|
function useMetaInfo() {
|
|
|
|
|
|
const dialogVisible = ref(false)
|
|
|
|
|
|
const titleType = ref('add')
|
|
|
|
|
|
const formContent = ref<Function.ResFunction>({
|
|
|
|
|
|
id: '',//资源表Id
|
|
|
|
|
|
pid:'',//节点(0为根节点)
|
|
|
|
|
|
pids:'',//节点上层所有节点
|
|
|
|
|
|
name: '',//名称
|
|
|
|
|
|
code:'',//资源标识
|
|
|
|
|
|
path:'',//路径
|
|
|
|
|
|
component:'',
|
|
|
|
|
|
icon:undefined as string | undefined, // 图标
|
|
|
|
|
|
sort:100,//排序
|
|
|
|
|
|
type:0,//资源类型0-菜单、1-按钮、2-公共资源、3-服务间调用资源
|
|
|
|
|
|
remark: '',//权限资源描述
|
|
|
|
|
|
state:1,//权限资源状态
|
|
|
|
|
|
})
|
|
|
|
|
|
return { dialogVisible, titleType, formContent }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const { dialogVisible, titleType, formContent } = useMetaInfo()
|
|
|
|
|
|
// 清空formContent
|
|
|
|
|
|
const resetFormContent = () => {
|
|
|
|
|
|
formContent.value = {
|
|
|
|
|
|
id: '',//资源表Id
|
|
|
|
|
|
pid:'',//节点(0为根节点)
|
|
|
|
|
|
pids:'',//节点上层所有节点
|
|
|
|
|
|
name: '',//名称
|
|
|
|
|
|
code:'',//资源标识
|
|
|
|
|
|
path:'',//路径
|
|
|
|
|
|
component:'',
|
|
|
|
|
|
icon:undefined,//图标
|
|
|
|
|
|
sort:100,//排序
|
|
|
|
|
|
type:0,//资源类型0-菜单、1-按钮、2-公共资源、3-服务间调用资源
|
|
|
|
|
|
remark:'',//权限资源描述
|
|
|
|
|
|
state:1,//权限资源状态
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let dialogTitle = computed(() => {
|
|
|
|
|
|
return titleType.value === 'add' ? '新增菜单' : '编辑菜单'
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2024-10-17 15:09:27 +08:00
|
|
|
|
|
2024-10-30 15:19:47 +08:00
|
|
|
|
|
|
|
|
|
|
// 定义规则
|
|
|
|
|
|
const formRuleRef = ref<FormInstance>()
|
|
|
|
|
|
const rules : Ref<Record<string, Array<FormItemRule>>> = ref({
|
|
|
|
|
|
name :[{required:true,trigger:'blur',message:'菜单名称必填!'}],
|
|
|
|
|
|
path :[{required:true,trigger:'blur',message:'菜单路径必填!'}],
|
2024-11-14 20:36:54 +08:00
|
|
|
|
type :[{required:true,trigger:'change',message:'菜单类型必选!'}],
|
|
|
|
|
|
component :[{required:true,trigger:'blur',message:'组件地址必填!'}],
|
|
|
|
|
|
code :[{required:true,trigger:'blur',message:'编码必填!'}]
|
2024-10-30 15:19:47 +08:00
|
|
|
|
})
|
2024-11-14 11:34:25 +08:00
|
|
|
|
|
|
|
|
|
|
// 关闭弹窗
|
|
|
|
|
|
const close = () => {
|
|
|
|
|
|
dialogVisible.value = false
|
|
|
|
|
|
// 清空dialogForm中的值
|
|
|
|
|
|
resetFormContent()
|
|
|
|
|
|
// 重置表单
|
|
|
|
|
|
dialogFormRef.value?.resetFields()
|
|
|
|
|
|
}
|
2024-10-17 15:09:27 +08:00
|
|
|
|
|
2024-11-14 11:34:25 +08:00
|
|
|
|
// 保存数据
|
|
|
|
|
|
const save = () => {
|
|
|
|
|
|
try {
|
2024-11-14 18:26:34 +08:00
|
|
|
|
console.log(formContent.value)
|
2024-11-14 11:34:25 +08:00
|
|
|
|
dialogFormRef.value?.validate(async (valid: boolean) => {
|
2024-11-14 20:36:54 +08:00
|
|
|
|
|
2024-11-14 11:34:25 +08:00
|
|
|
|
if (valid) {
|
|
|
|
|
|
if (formContent.value.id) {
|
2024-11-14 18:26:34 +08:00
|
|
|
|
await updateFunction(formContent.value);
|
2024-11-14 11:34:25 +08:00
|
|
|
|
} else {
|
2024-11-14 18:26:34 +08:00
|
|
|
|
await addFunction(formContent.value);
|
2024-11-14 11:34:25 +08:00
|
|
|
|
}
|
2024-11-14 18:26:34 +08:00
|
|
|
|
ElMessage.success({ message: `${dialogTitle.value}成功!` })
|
2024-11-14 11:34:25 +08:00
|
|
|
|
close()
|
|
|
|
|
|
// 刷新表格
|
|
|
|
|
|
await props.refreshTable!()
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
} catch (err) {
|
2024-11-14 18:26:34 +08:00
|
|
|
|
//console.error('验证过程中出现错误', err)
|
2024-10-30 15:19:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-10-17 15:09:27 +08:00
|
|
|
|
|
2024-11-14 20:36:54 +08:00
|
|
|
|
const functionList = ref<Function.ResFunction[]>([])
|
2024-11-14 11:34:25 +08:00
|
|
|
|
// 打开弹窗,可能是新增,也可能是编辑
|
|
|
|
|
|
const open = async (sign: string, data: Function.ResFunction) => {
|
2024-11-14 20:36:54 +08:00
|
|
|
|
const response = await getFunctionListNoButton()
|
|
|
|
|
|
functionList.value = response.data as unknown as Function.ResFunction[]
|
2024-11-14 11:34:25 +08:00
|
|
|
|
titleType.value = sign
|
|
|
|
|
|
dialogVisible.value = true
|
|
|
|
|
|
if (data.id) {
|
|
|
|
|
|
formContent.value = { ...data }
|
|
|
|
|
|
} else {
|
|
|
|
|
|
resetFormContent()
|
2024-10-17 15:09:27 +08:00
|
|
|
|
}
|
2024-11-14 11:34:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 对外映射
|
|
|
|
|
|
defineExpose({ open })
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
|
|
refreshTable: (() => Promise<void>) | undefined;
|
|
|
|
|
|
}>()
|
2024-10-17 15:09:27 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|