<script lang="ts" name="fBS_Menu" setup>
|
import { ref, reactive, onMounted } from "vue";
|
import { ElMessage } from "element-plus";
|
import type { FormRules } from "element-plus";
|
import { formatDate } from '/@/utils/formatTime';
|
import { useFBS_MenuApi } from '/@/api/Customer/fBS_Menu';
|
|
//父级传递来的函数,用于回调
|
const emit = defineEmits(["reloadTable"]);
|
const fBS_MenuApi = useFBS_MenuApi();
|
const ruleFormRef = ref();
|
|
const state = reactive({
|
title: '',
|
loading: false,
|
showDialog: false,
|
ruleForm: {} as any,
|
stores: {},
|
dropdownData: {} as any,
|
});
|
|
// 自行添加其他规则
|
const rules = ref<FormRules>({
|
pid: [{required: true, message: '请选择父Id!', trigger: 'blur',},],
|
type: [{required: true, message: '请选择菜单类型!', trigger: 'change',},],
|
title: [{required: true, message: '请选择菜单名称!', trigger: 'blur',},],
|
isIframe: [{required: true, message: '请选择是否内嵌!', trigger: 'blur',},],
|
isHide: [{required: true, message: '请选择是否隐藏!', trigger: 'blur',},],
|
isKeepAlive: [{required: true, message: '请选择是否缓存!', trigger: 'blur',},],
|
isAffix: [{required: true, message: '请选择是否固定!', trigger: 'blur',},],
|
orderNo: [{required: true, message: '请选择排序!', trigger: 'blur',},],
|
status: [{required: true, message: '请选择状态!', trigger: 'change',},],
|
});
|
|
// 页面加载时
|
onMounted(async () => {
|
});
|
|
// 打开弹窗
|
const openDialog = async (row: any, title: string) => {
|
state.title = title;
|
row = row ?? { status: 1,orderNo: 100, };
|
state.ruleForm = row.id ? await fBS_MenuApi.detail(row.id).then(res => res.data.result) : JSON.parse(JSON.stringify(row));
|
state.showDialog = true;
|
};
|
|
// 关闭弹窗
|
const closeDialog = () => {
|
emit("reloadTable");
|
state.showDialog = false;
|
};
|
|
// 提交
|
const submit = async () => {
|
ruleFormRef.value.validate(async (isValid: boolean, fields?: any) => {
|
if (isValid) {
|
let values = state.ruleForm;
|
await fBS_MenuApi[state.ruleForm.id ? 'update' : 'add'](values);
|
closeDialog();
|
} else {
|
ElMessage({
|
message: `表单有${Object.keys(fields).length}处验证失败,请修改后再提交`,
|
type: "error",
|
});
|
}
|
});
|
};
|
|
//将属性或者函数暴露给父组件
|
defineExpose({ openDialog });
|
</script>
|
<template>
|
<div class="fBS_Menu-container">
|
<el-dialog v-model="state.showDialog" :width="800" draggable :close-on-click-modal="false">
|
<template #header>
|
<div style="color: #fff">
|
<span>{{ state.title }}</span>
|
</div>
|
</template>
|
<el-form :model="state.ruleForm" ref="ruleFormRef" label-width="auto" :rules="rules">
|
<el-row :gutter="35">
|
<el-form-item v-show="false">
|
<el-input v-model="state.ruleForm.id" />
|
</el-form-item>
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
|
<el-form-item label="父Id" prop="pid">
|
<el-input v-model="state.ruleForm.pid" placeholder="请输入父Id" maxlength="19" show-word-limit clearable />
|
</el-form-item>
|
</el-col>
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
|
<el-form-item label="菜单类型" prop="type">
|
<g-sys-dict v-model="state.ruleForm.type" code="MenuTypeEnum" render-as="select" placeholder="请选择菜单类型" clearable filterable />
|
</el-form-item>
|
</el-col>
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
|
<el-form-item label="路由名称" prop="name">
|
<el-input v-model="state.ruleForm.name" placeholder="请输入路由名称" maxlength="64" show-word-limit clearable />
|
</el-form-item>
|
</el-col>
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
|
<el-form-item label="路由地址" prop="path">
|
<el-input v-model="state.ruleForm.path" placeholder="请输入路由地址" maxlength="128" show-word-limit clearable />
|
</el-form-item>
|
</el-col>
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
|
<el-form-item label="组件路径" prop="component">
|
<el-input v-model="state.ruleForm.component" placeholder="请输入组件路径" maxlength="128" show-word-limit clearable />
|
</el-form-item>
|
</el-col>
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
|
<el-form-item label="重定向" prop="redirect">
|
<el-input v-model="state.ruleForm.redirect" placeholder="请输入重定向" maxlength="128" show-word-limit clearable />
|
</el-form-item>
|
</el-col>
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
|
<el-form-item label="权限标识" prop="permission">
|
<el-input v-model="state.ruleForm.permission" placeholder="请输入权限标识" maxlength="128" show-word-limit clearable />
|
</el-form-item>
|
</el-col>
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
|
<el-form-item label="菜单名称" prop="title">
|
<el-input v-model="state.ruleForm.title" placeholder="请输入菜单名称" maxlength="64" show-word-limit clearable />
|
</el-form-item>
|
</el-col>
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
|
<el-form-item label="图标" prop="icon">
|
<el-input v-model="state.ruleForm.icon" placeholder="请输入图标" maxlength="128" show-word-limit clearable />
|
</el-form-item>
|
</el-col>
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
|
<el-form-item label="是否内嵌" prop="isIframe">
|
<el-switch v-model="state.ruleForm.isIframe" active-text="是" inactive-text="否" />
|
</el-form-item>
|
</el-col>
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
|
<el-form-item label="外链链接" prop="outLink">
|
<el-input v-model="state.ruleForm.outLink" placeholder="请输入外链链接" maxlength="256" show-word-limit clearable />
|
</el-form-item>
|
</el-col>
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
|
<el-form-item label="是否隐藏" prop="isHide">
|
<el-switch v-model="state.ruleForm.isHide" active-text="是" inactive-text="否" />
|
</el-form-item>
|
</el-col>
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
|
<el-form-item label="是否缓存" prop="isKeepAlive">
|
<el-switch v-model="state.ruleForm.isKeepAlive" active-text="是" inactive-text="否" />
|
</el-form-item>
|
</el-col>
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
|
<el-form-item label="是否固定" prop="isAffix">
|
<el-switch v-model="state.ruleForm.isAffix" active-text="是" inactive-text="否" />
|
</el-form-item>
|
</el-col>
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
|
<el-form-item label="排序" prop="orderNo">
|
<el-input-number v-model="state.ruleForm.orderNo" placeholder="请输入排序" clearable />
|
</el-form-item>
|
</el-col>
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" v-if="state.ruleForm.id" >
|
<el-form-item label="状态" prop="status">
|
<g-sys-dict v-model="state.ruleForm.status" code="StatusEnum" render-as="select" placeholder="请选择状态" clearable filterable />
|
</el-form-item>
|
</el-col>
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
|
<el-form-item label="备注" prop="remark">
|
<el-input v-model="state.ruleForm.remark" placeholder="请输入备注" maxlength="256" show-word-limit clearable />
|
</el-form-item>
|
</el-col>
|
</el-row>
|
</el-form>
|
<template #footer>
|
<span class="dialog-footer">
|
<el-button @click="() => state.showDialog = false">取 消</el-button>
|
<el-button @click="submit" type="primary" v-reclick="1000">确 定</el-button>
|
</span>
|
</template>
|
</el-dialog>
|
</div>
|
</template>
|
<style lang="scss" scoped>
|
:deep(.el-select), :deep(.el-input-number) {
|
width: 100%;
|
}
|
</style>
|