2021-06-07 17:22:07 +08:00
|
|
|
|
<template>
|
2023-03-15 11:41:03 +08:00
|
|
|
|
<div class="system-menu-dialog-container layout-pd">
|
|
|
|
|
|
<el-dialog :title="title" :destroy-on-close="true" v-model="dialogVisible" width="800px">
|
2023-07-03 21:42:04 +08:00
|
|
|
|
<el-form :model="form" :inline="true" ref="menuForm" :rules="rules" label-width="auto">
|
2023-03-15 11:41:03 +08:00
|
|
|
|
<el-row :gutter="35">
|
|
|
|
|
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
|
|
|
|
|
<el-form-item class="w100" prop="type" label="类型" required>
|
|
|
|
|
|
<el-select class="w100" v-model="form.type" :disabled="typeDisabled" placeholder="请选择">
|
2023-07-06 20:59:22 +08:00
|
|
|
|
<el-option v-for="item in ResourceTypeEnum" :key="item.value" :label="item.label" :value="item.value"> </el-option>
|
2021-09-11 14:04:09 +08:00
|
|
|
|
</el-select>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-col>
|
2023-03-15 11:41:03 +08:00
|
|
|
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
|
|
|
|
|
<el-form-item class="w100" prop="name" label="名称" required>
|
2021-09-11 14:04:09 +08:00
|
|
|
|
<el-input v-model.trim="form.name" placeholder="资源名[菜单名]" auto-complete="off"></el-input>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-col>
|
2023-03-15 11:41:03 +08:00
|
|
|
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
|
|
|
|
|
<el-form-item class="w100" prop="code" label="path|code">
|
2023-06-15 19:18:29 +08:00
|
|
|
|
<template #label>
|
|
|
|
|
|
path|code
|
2023-07-06 20:59:22 +08:00
|
|
|
|
<el-tooltip
|
|
|
|
|
|
effect="dark"
|
|
|
|
|
|
content="菜单类型则为访问路径(若菜单路径不以'/'开头则访问地址会自动拼接父菜单路径)、否则为资源唯一编码"
|
|
|
|
|
|
placement="top"
|
|
|
|
|
|
>
|
2023-06-15 19:18:29 +08:00
|
|
|
|
<el-icon>
|
|
|
|
|
|
<question-filled />
|
|
|
|
|
|
</el-icon>
|
|
|
|
|
|
</el-tooltip>
|
|
|
|
|
|
</template>
|
2023-03-15 11:41:03 +08:00
|
|
|
|
<el-input v-model.trim="form.code" placeholder="菜单不以'/'开头则自动拼接父菜单路径"></el-input>
|
2021-09-11 14:04:09 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-col>
|
2023-03-15 11:41:03 +08:00
|
|
|
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" v-if="form.type === menuTypeValue">
|
|
|
|
|
|
<el-form-item class="w100" label="图标">
|
|
|
|
|
|
<icon-selector v-model="form.meta.icon" />
|
2021-09-11 14:04:09 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-col>
|
2023-03-15 11:41:03 +08:00
|
|
|
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" v-if="form.type === menuTypeValue">
|
2023-06-15 19:18:29 +08:00
|
|
|
|
<el-form-item class="w100">
|
|
|
|
|
|
<template #label>
|
|
|
|
|
|
路由名
|
|
|
|
|
|
<el-tooltip effect="dark" content="与vue的组件名一致才可使组件缓存生效,如ResourceList" placement="top">
|
|
|
|
|
|
<el-icon>
|
|
|
|
|
|
<question-filled />
|
|
|
|
|
|
</el-icon>
|
|
|
|
|
|
</el-tooltip>
|
|
|
|
|
|
</template>
|
2021-09-11 14:04:09 +08:00
|
|
|
|
<el-input v-model.trim="form.meta.routeName" placeholder="请输入路由名称"></el-input>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-col>
|
2023-03-15 11:41:03 +08:00
|
|
|
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" v-if="form.type === menuTypeValue">
|
2023-06-15 19:18:29 +08:00
|
|
|
|
<el-form-item class="w100" prop="code">
|
|
|
|
|
|
<template #label>
|
|
|
|
|
|
组件路径
|
2023-07-06 20:59:22 +08:00
|
|
|
|
<el-tooltip effect="dark" content="访问的组件路径,如:`system/resource/ResourceList`,默认在`views`目录下" placement="top">
|
2023-06-15 19:18:29 +08:00
|
|
|
|
<el-icon>
|
|
|
|
|
|
<question-filled />
|
|
|
|
|
|
</el-icon>
|
|
|
|
|
|
</el-tooltip>
|
|
|
|
|
|
</template>
|
2023-03-15 11:41:03 +08:00
|
|
|
|
<el-input v-model.trim="form.meta.component" placeholder="请输入组件路径"></el-input>
|
2021-09-11 14:04:09 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-col>
|
2023-03-15 11:41:03 +08:00
|
|
|
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" v-if="form.type === menuTypeValue">
|
2023-06-15 19:18:29 +08:00
|
|
|
|
<el-form-item class="w100" prop="isKeepAlive">
|
|
|
|
|
|
<template #label>
|
|
|
|
|
|
是否缓存
|
2023-07-06 20:59:22 +08:00
|
|
|
|
<el-tooltip
|
|
|
|
|
|
effect="dark"
|
|
|
|
|
|
content="选择是则会被`keep-alive`缓存(重新进入页面不会刷新页面及重新请求数据),需要路由名与vue的组件名一致"
|
|
|
|
|
|
placement="top"
|
|
|
|
|
|
>
|
2023-06-15 19:18:29 +08:00
|
|
|
|
<el-icon>
|
|
|
|
|
|
<question-filled />
|
|
|
|
|
|
</el-icon>
|
|
|
|
|
|
</el-tooltip>
|
|
|
|
|
|
</template>
|
2023-03-15 11:41:03 +08:00
|
|
|
|
<el-select v-model="form.meta.isKeepAlive" placeholder="请选择" class="w100">
|
2023-07-06 20:59:22 +08:00
|
|
|
|
<el-option v-for="item in trueFalseOption" :key="item.value" :label="item.label" :value="item.value"> </el-option>
|
2021-09-11 14:04:09 +08:00
|
|
|
|
</el-select>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-col>
|
2023-03-15 11:41:03 +08:00
|
|
|
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" v-if="form.type === menuTypeValue">
|
2023-06-15 19:18:29 +08:00
|
|
|
|
<el-form-item class="w100">
|
|
|
|
|
|
<template #label>
|
|
|
|
|
|
是否隐藏
|
|
|
|
|
|
<el-tooltip effect="dark" content="选择隐藏则路由将不会出现在菜单栏中,但仍然可以访问。禁用则不可访问与操作" placement="top">
|
|
|
|
|
|
<el-icon>
|
|
|
|
|
|
<question-filled />
|
|
|
|
|
|
</el-icon>
|
|
|
|
|
|
</el-tooltip>
|
|
|
|
|
|
</template>
|
2023-03-15 11:41:03 +08:00
|
|
|
|
<el-select v-model="form.meta.isHide" placeholder="请选择" class="w100">
|
2023-07-06 20:59:22 +08:00
|
|
|
|
<el-option v-for="item in trueFalseOption" :key="item.value" :label="item.label" :value="item.value"> </el-option>
|
2021-09-11 14:04:09 +08:00
|
|
|
|
</el-select>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-col>
|
2023-03-15 11:41:03 +08:00
|
|
|
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" v-if="form.type === menuTypeValue">
|
|
|
|
|
|
<el-form-item class="w100" prop="code" label="tag不可删除">
|
|
|
|
|
|
<el-select v-model="form.meta.isAffix" placeholder="请选择" class="w100">
|
2023-07-06 20:59:22 +08:00
|
|
|
|
<el-option v-for="item in trueFalseOption" :key="item.value" :label="item.label" :value="item.value"> </el-option>
|
2021-09-11 14:04:09 +08:00
|
|
|
|
</el-select>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-col>
|
2023-03-15 11:41:03 +08:00
|
|
|
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" v-if="form.type === menuTypeValue">
|
2023-06-15 19:18:29 +08:00
|
|
|
|
<el-form-item class="w100" prop="linkType">
|
|
|
|
|
|
<template #label>
|
|
|
|
|
|
外链
|
|
|
|
|
|
<el-tooltip effect="dark" content="内嵌: 以iframe展示、外链: 新标签打开" placement="top">
|
|
|
|
|
|
<el-icon>
|
|
|
|
|
|
<question-filled />
|
|
|
|
|
|
</el-icon>
|
|
|
|
|
|
</el-tooltip>
|
|
|
|
|
|
</template>
|
2023-12-27 19:55:36 +08:00
|
|
|
|
<el-select class="w100" @change="changeLinkType" v-model="form.meta.linkType" placeholder="请选择">
|
2023-06-01 12:31:32 +08:00
|
|
|
|
<el-option :key="0" label="否" :value="0"> </el-option>
|
|
|
|
|
|
<el-option :key="1" label="内嵌" :value="1"> </el-option>
|
|
|
|
|
|
<el-option :key="2" label="外链" :value="2"> </el-option>
|
2021-09-11 14:04:09 +08:00
|
|
|
|
</el-select>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-col>
|
2023-07-06 20:59:22 +08:00
|
|
|
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" v-if="form.type === menuTypeValue && form.meta.linkType > 0">
|
2023-06-01 12:31:32 +08:00
|
|
|
|
<el-form-item prop="code" label="链接地址" class="w100">
|
|
|
|
|
|
<el-input v-model.trim="form.meta.link" placeholder="外链/内嵌的链接地址(http://xxx.com)"></el-input>
|
2021-09-11 14:04:09 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-col>
|
|
|
|
|
|
</el-row>
|
2021-06-07 17:22:07 +08:00
|
|
|
|
</el-form>
|
2024-04-27 01:35:21 +08:00
|
|
|
|
|
2022-05-08 14:10:57 +08:00
|
|
|
|
<template #footer>
|
2022-05-27 15:45:12 +08:00
|
|
|
|
<div>
|
2022-05-08 14:10:57 +08:00
|
|
|
|
<el-button @click="cancel()">取 消</el-button>
|
2023-12-11 01:00:09 +08:00
|
|
|
|
<el-button type="primary" :loading="saveBtnLoading" @click="btnOk">确 定</el-button>
|
2022-05-08 14:10:57 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
2021-06-07 17:22:07 +08:00
|
|
|
|
</el-dialog>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
|
<script lang="ts" setup>
|
2024-04-17 21:28:28 +08:00
|
|
|
|
import { ref, toRefs, reactive, watchEffect } from 'vue';
|
2021-06-07 17:22:07 +08:00
|
|
|
|
import { ElMessage } from 'element-plus';
|
|
|
|
|
|
import { resourceApi } from '../api';
|
2023-07-06 20:59:22 +08:00
|
|
|
|
import { ResourceTypeEnum } from '../enums';
|
2021-06-07 17:22:07 +08:00
|
|
|
|
import { notEmpty } from '@/common/assert';
|
|
|
|
|
|
import iconSelector from '@/components/iconSelector/index.vue';
|
|
|
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
|
const props = defineProps({
|
|
|
|
|
|
visible: {
|
|
|
|
|
|
type: Boolean,
|
2021-06-07 17:22:07 +08:00
|
|
|
|
},
|
2022-10-29 20:08:15 +08:00
|
|
|
|
data: {
|
|
|
|
|
|
type: [Boolean, Object],
|
|
|
|
|
|
},
|
|
|
|
|
|
title: {
|
|
|
|
|
|
type: String,
|
|
|
|
|
|
},
|
|
|
|
|
|
typeDisabled: {
|
|
|
|
|
|
type: Boolean,
|
|
|
|
|
|
},
|
2023-07-06 20:59:22 +08:00
|
|
|
|
});
|
2022-10-29 20:08:15 +08:00
|
|
|
|
|
|
|
|
|
|
//定义事件
|
2023-07-06 20:59:22 +08:00
|
|
|
|
const emit = defineEmits(['update:visible', 'cancel', 'val-change']);
|
2022-10-29 20:08:15 +08:00
|
|
|
|
|
|
|
|
|
|
const menuForm: any = ref(null);
|
|
|
|
|
|
|
2023-07-06 20:59:22 +08:00
|
|
|
|
const menuTypeValue = ResourceTypeEnum.Menu.value;
|
2022-10-29 20:08:15 +08:00
|
|
|
|
|
|
|
|
|
|
const defaultMeta = {
|
|
|
|
|
|
routeName: '',
|
|
|
|
|
|
icon: 'Menu',
|
|
|
|
|
|
redirect: '',
|
|
|
|
|
|
component: '',
|
|
|
|
|
|
isKeepAlive: true,
|
|
|
|
|
|
isHide: false,
|
|
|
|
|
|
isAffix: false,
|
2023-06-01 12:31:32 +08:00
|
|
|
|
linkType: 0,
|
2022-10-29 20:08:15 +08:00
|
|
|
|
link: '',
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const rules = {
|
|
|
|
|
|
name: [
|
|
|
|
|
|
{
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
message: '请输入资源名称',
|
|
|
|
|
|
trigger: ['change', 'blur'],
|
2021-06-07 17:22:07 +08:00
|
|
|
|
},
|
2022-10-29 20:08:15 +08:00
|
|
|
|
],
|
2023-07-06 20:59:22 +08:00
|
|
|
|
};
|
2022-10-29 20:08:15 +08:00
|
|
|
|
|
|
|
|
|
|
const trueFalseOption = [
|
|
|
|
|
|
{
|
|
|
|
|
|
label: '是',
|
|
|
|
|
|
value: true,
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
label: '否',
|
|
|
|
|
|
value: false,
|
2021-06-07 17:22:07 +08:00
|
|
|
|
},
|
2023-07-06 20:59:22 +08:00
|
|
|
|
];
|
2021-06-07 17:22:07 +08:00
|
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
|
const state = reactive({
|
|
|
|
|
|
dialogVisible: false,
|
|
|
|
|
|
form: {
|
|
|
|
|
|
id: null,
|
|
|
|
|
|
name: null,
|
|
|
|
|
|
pid: null,
|
|
|
|
|
|
code: null,
|
|
|
|
|
|
type: null,
|
|
|
|
|
|
meta: {
|
2021-06-07 17:22:07 +08:00
|
|
|
|
routeName: '',
|
2022-10-29 20:08:15 +08:00
|
|
|
|
icon: '',
|
2021-06-07 17:22:07 +08:00
|
|
|
|
redirect: '',
|
|
|
|
|
|
component: '',
|
|
|
|
|
|
isKeepAlive: true,
|
|
|
|
|
|
isHide: false,
|
|
|
|
|
|
isAffix: false,
|
2023-06-01 12:31:32 +08:00
|
|
|
|
linkType: 0,
|
2022-10-29 20:08:15 +08:00
|
|
|
|
link: '',
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
2023-12-11 01:00:09 +08:00
|
|
|
|
submitForm: {},
|
2022-10-29 20:08:15 +08:00
|
|
|
|
});
|
2021-06-07 17:22:07 +08:00
|
|
|
|
|
2023-12-11 01:00:09 +08:00
|
|
|
|
const { dialogVisible, form, submitForm } = toRefs(state);
|
|
|
|
|
|
|
|
|
|
|
|
const { isFetching: saveBtnLoading, execute: saveResouceExec } = resourceApi.save.useApi(submitForm);
|
2021-06-07 17:22:07 +08:00
|
|
|
|
|
2024-04-17 21:28:28 +08:00
|
|
|
|
watchEffect(() => {
|
|
|
|
|
|
state.dialogVisible = props.visible;
|
|
|
|
|
|
if (props.data) {
|
|
|
|
|
|
state.form = { ...(props.data as any) };
|
2022-10-29 20:08:15 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
state.form = {} as any;
|
|
|
|
|
|
}
|
2021-06-07 17:22:07 +08:00
|
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
|
if (!state.form.meta) {
|
|
|
|
|
|
state.form.meta = defaultMeta;
|
|
|
|
|
|
}
|
2021-06-07 17:22:07 +08:00
|
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
|
// 不存在或false,都为false
|
|
|
|
|
|
const meta: any = state.form.meta;
|
|
|
|
|
|
state.form.meta.isKeepAlive = meta.isKeepAlive ? true : false;
|
|
|
|
|
|
state.form.meta.isHide = meta.isHide ? true : false;
|
|
|
|
|
|
state.form.meta.isAffix = meta.isAffix ? true : false;
|
2023-06-01 12:31:32 +08:00
|
|
|
|
state.form.meta.linkType = meta.linkType;
|
2022-10-29 20:08:15 +08:00
|
|
|
|
});
|
2021-06-07 17:22:07 +08:00
|
|
|
|
|
2023-12-27 19:55:36 +08:00
|
|
|
|
// 改变外链类型
|
|
|
|
|
|
const changeLinkType = () => {
|
|
|
|
|
|
state.form.meta.component = '';
|
2022-10-29 20:08:15 +08:00
|
|
|
|
};
|
2021-06-07 17:22:07 +08:00
|
|
|
|
|
2024-05-10 19:59:49 +08:00
|
|
|
|
const btnOk = async () => {
|
2024-05-11 12:09:55 +08:00
|
|
|
|
try {
|
|
|
|
|
|
await menuForm.value.validate();
|
|
|
|
|
|
} catch (e: any) {
|
|
|
|
|
|
ElMessage.error('请正确填写信息');
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
|
const submitForm = { ...state.form };
|
|
|
|
|
|
if (submitForm.type == 1) {
|
|
|
|
|
|
// 如果是菜单,则解析meta,如果值为false或者''则去除该值
|
|
|
|
|
|
submitForm.meta = parseMenuMeta(submitForm.meta);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
submitForm.meta = null as any;
|
|
|
|
|
|
}
|
2023-12-11 01:00:09 +08:00
|
|
|
|
|
2024-05-10 19:59:49 +08:00
|
|
|
|
state.submitForm = submitForm;
|
|
|
|
|
|
await saveResouceExec();
|
2021-06-07 17:22:07 +08:00
|
|
|
|
|
2024-05-10 19:59:49 +08:00
|
|
|
|
emit('val-change', submitForm);
|
|
|
|
|
|
ElMessage.success('保存成功');
|
|
|
|
|
|
cancel();
|
2022-10-29 20:08:15 +08:00
|
|
|
|
};
|
2021-06-07 17:22:07 +08:00
|
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
|
const parseMenuMeta = (meta: any) => {
|
|
|
|
|
|
let metaForm: any = {};
|
|
|
|
|
|
// 如果是菜单,则校验meta
|
|
|
|
|
|
notEmpty(meta.routeName, '路由名不能为空');
|
|
|
|
|
|
metaForm.routeName = meta.routeName;
|
|
|
|
|
|
if (meta.isKeepAlive) {
|
|
|
|
|
|
metaForm.isKeepAlive = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (meta.isHide) {
|
|
|
|
|
|
metaForm.isHide = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (meta.isAffix) {
|
|
|
|
|
|
metaForm.isAffix = true;
|
|
|
|
|
|
}
|
2023-06-01 12:31:32 +08:00
|
|
|
|
if (meta.linkType) {
|
|
|
|
|
|
metaForm.linkType = meta.linkType;
|
2022-10-29 20:08:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (meta.link) {
|
|
|
|
|
|
metaForm.link = meta.link;
|
2023-03-15 11:41:03 +08:00
|
|
|
|
} else {
|
2023-07-06 20:59:22 +08:00
|
|
|
|
delete metaForm['link'];
|
2022-10-29 20:08:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (meta.redirect) {
|
|
|
|
|
|
metaForm.redirect = meta.redirect;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (meta.component) {
|
|
|
|
|
|
metaForm.component = meta.component;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (meta.icon) {
|
|
|
|
|
|
metaForm.icon = meta.icon;
|
|
|
|
|
|
}
|
|
|
|
|
|
return metaForm;
|
|
|
|
|
|
};
|
2021-06-07 17:22:07 +08:00
|
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
|
const cancel = () => {
|
|
|
|
|
|
emit('update:visible', false);
|
|
|
|
|
|
emit('cancel');
|
|
|
|
|
|
};
|
2021-06-07 17:22:07 +08:00
|
|
|
|
</script>
|
2024-05-11 12:09:55 +08:00
|
|
|
|
<style lang="scss"></style>
|