同步6/16
This commit is contained in:
382
src/views/workbench/components/quick.vue
Normal file
382
src/views/workbench/components/quick.vue
Normal file
@@ -0,0 +1,382 @@
|
||||
<template>
|
||||
<div class="quicly_box">
|
||||
<div class="quickly_item" v-for="(item, index) in quickBox" :key="index" @click="handleRouter(item.menuPath)">
|
||||
<div class="quickly_item_icon" v-if="item.menuIcon">
|
||||
<svg-icon :icon-class="item.menuIcon" />
|
||||
</div>
|
||||
<div class="quickly_item_content">{{ item.menuName }}</div>
|
||||
<!-- <div class="actionsbox">
|
||||
<div class="routeactions">
|
||||
<el-icon><Position /></el-icon>
|
||||
<span style="padding-left: 0.1rem">跳转</span>
|
||||
</div>
|
||||
<div class="deleteaction">
|
||||
<el-icon><Delete /></el-icon>
|
||||
<span style="padding-left: 0.1rem">删除</span>
|
||||
</div>
|
||||
</div> -->
|
||||
<div class="deleteaction" @click="delteRoute(item.id)">
|
||||
<el-icon class="icons"><Remove /></el-icon>
|
||||
</div>
|
||||
</div>
|
||||
<div @click="addQuieckDialog" class="quickly_item add">
|
||||
<el-icon><Plus /></el-icon>
|
||||
<span>添加</span>
|
||||
</div>
|
||||
|
||||
<!-- 添加快捷入口 -->
|
||||
<el-dialog :title="dialog.title" v-model="dialog.visible" width="500px" append-to-body>
|
||||
<el-form ref="repairProjectFormRef" :model="form" :rules="rules" label-width="80px">
|
||||
<!-- <el-form-item label="名称" prop="name">
|
||||
<el-input v-model="form.name" placeholder="请输入" />
|
||||
</el-form-item> -->
|
||||
<!-- <el-form-item label="图标" prop="icon">
|
||||
<el-input v-model="form.icon" placeholder="请输入" />
|
||||
</el-form-item> -->
|
||||
<el-form-item label="展示页面" prop="path">
|
||||
<!-- <el-input v-model="form.path" placeholder="请输入" /> -->
|
||||
<el-cascader
|
||||
@change="handleCascader"
|
||||
clearable
|
||||
:props="{ value: 'path', label: 'name', children: 'children' }"
|
||||
v-model="path"
|
||||
:options="quicklylist"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="排序" prop="path">
|
||||
<el-input-number v-model="form.sortOrder"></el-input-number>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button type="primary" @click="submitQuick">确 定</el-button>
|
||||
<el-button>取 消</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { addQuicklyshortcut, delQuicklyshortcut, getQuicklyshortcut } from '@/api/workflow';
|
||||
import { usePermissionStore } from '@/store/modules/permission';
|
||||
|
||||
// ! 快捷入口
|
||||
const quickBox = ref<
|
||||
{
|
||||
'id': string;
|
||||
'menuId': null;
|
||||
'menuName': string;
|
||||
'menuPath': string;
|
||||
'menuIcon': string;
|
||||
'sortOrder': number;
|
||||
}[]
|
||||
>([]);
|
||||
const router = useRouter();
|
||||
function handleRouter(val: string) {
|
||||
router.push({
|
||||
path: val
|
||||
});
|
||||
}
|
||||
|
||||
const dialog = reactive<DialogOption>({
|
||||
visible: false,
|
||||
title: '添加快捷入口'
|
||||
});
|
||||
const form = ref({
|
||||
menuName: '',
|
||||
menuPath: '',
|
||||
menuIcon: '',
|
||||
sortOrder: 1
|
||||
});
|
||||
const path = ref([]);
|
||||
const rules = {
|
||||
menuPath: [{ required: true, trigger: 'blur', message: '请选择快捷入口页面' }]
|
||||
};
|
||||
const quicklylist = ref([]);
|
||||
function addQuieckDialog() {
|
||||
form.value = {
|
||||
menuName: '',
|
||||
menuPath: '',
|
||||
menuIcon: '',
|
||||
sortOrder: 1
|
||||
};
|
||||
const permissionStore = usePermissionStore();
|
||||
const routes = permissionStore.getDefaultRoutes();
|
||||
handleroutestoshowlist(routes);
|
||||
dialog.visible = true;
|
||||
}
|
||||
function getquicklist() {
|
||||
getQuicklyshortcut().then((res) => {
|
||||
quickBox.value = res.data;
|
||||
});
|
||||
}
|
||||
getquicklist();
|
||||
function handleroutestoshowlist(rotues) {
|
||||
// 1. 输入校验:确保 routes 是数组
|
||||
if (!Array.isArray(rotues)) {
|
||||
return [];
|
||||
}
|
||||
const arr = rotues.map((ele) => _hanle(null, ele, 1)).filter((item) => item);
|
||||
quicklylist.value = arr;
|
||||
}
|
||||
function _hanle(parentRoute, currentRoute, level) {
|
||||
// 非页面路由
|
||||
if (currentRoute.hidden && level === 1) {
|
||||
return null;
|
||||
}
|
||||
// 2. 辅助判断:排除常见的非列表/首页关键词(根据业务需求调整)
|
||||
// 使用正则边界匹配,避免误伤 (如 'main' 不匹配 'domain')
|
||||
const excludeKeywords = /(edit|main|Main|view)/i;
|
||||
if (excludeKeywords.test(currentRoute.path)) {
|
||||
return null;
|
||||
}
|
||||
if (!currentRoute.meta) {
|
||||
if (currentRoute.children && currentRoute.children.length > 0) {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
const obj = {
|
||||
name: currentRoute.meta.title || '',
|
||||
icon: currentRoute.meta.icon || '',
|
||||
path: currentRoute.path,
|
||||
level: level,
|
||||
children: []
|
||||
};
|
||||
|
||||
// 3. 路径拼接
|
||||
if (parentRoute) {
|
||||
if (currentRoute.path.startsWith('/')) {
|
||||
obj.path = currentRoute.path;
|
||||
} else {
|
||||
const parentPath = parentRoute.path.endsWith('/') ? parentRoute.path.slice(0, -1) : parentRoute.path;
|
||||
const childPath = currentRoute.path.startsWith('/') ? currentRoute.path : '/' + currentRoute.path;
|
||||
obj.path = parentPath + childPath;
|
||||
}
|
||||
}
|
||||
// 4. 递归处理子节点
|
||||
if (level < 2 && currentRoute.children && Array.isArray(currentRoute.children)) {
|
||||
obj.children = currentRoute.children.map((item) => _hanle(obj, item, level + 1)).filter((item) => item !== null); // 过滤掉 null 值
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
function handleCascader(val) {
|
||||
const parentpath = val[0];
|
||||
const childrenpath = val[1];
|
||||
const find = quicklylist.value.find((item) => item.path === parentpath);
|
||||
if (find) {
|
||||
const find2 = find.children.find((item) => item.path === childrenpath);
|
||||
if (find2) {
|
||||
form.value = {
|
||||
...form.value,
|
||||
menuIcon: find2.icon,
|
||||
menuName: find2.name,
|
||||
menuPath: find2.path
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
function submitQuick() {
|
||||
addQuicklyshortcut(form.value).then((res) => {
|
||||
ElMessage.success(res.msg);
|
||||
dialog.visible = false;
|
||||
getquicklist();
|
||||
});
|
||||
}
|
||||
function delteRoute(id: string) {
|
||||
delQuicklyshortcut(id).then(() => {
|
||||
getquicklist();
|
||||
});
|
||||
}
|
||||
// ! 快捷入口
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
.quicly_box {
|
||||
max-height: 410px;
|
||||
overflow-y: auto;
|
||||
padding-top: 20px;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
@media (max-width: 1950px) {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
max-height: 410px;
|
||||
}
|
||||
@media (max-width: 1750px) {
|
||||
max-height: 550px;
|
||||
}
|
||||
@media (max-width: 1600px) {
|
||||
max-height: 550px;
|
||||
}
|
||||
@media (max-width: 1200px) {
|
||||
max-height: 550px;
|
||||
}
|
||||
gap: 10px;
|
||||
|
||||
.quickly_item {
|
||||
margin-bottom: 20px;
|
||||
|
||||
height: 56px;
|
||||
background: #ffffff;
|
||||
border-radius: 12px 12px 12px 12px;
|
||||
border: 1px solid #c0daff;
|
||||
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
cursor: pointer;
|
||||
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
|
||||
font-size: 0.685rem;
|
||||
@media (max-width: 2000px) {
|
||||
font-size: 0.65rem;
|
||||
}
|
||||
@media (max-width: 1500px) {
|
||||
height: 46px;
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
@media (max-width: 1250px) {
|
||||
height: 36px;
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background-color: #0084ff09;
|
||||
}
|
||||
.quickly_item_icon {
|
||||
margin-right: 8px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
.quickly_item_content {
|
||||
font-weight: 500;
|
||||
color: #222222;
|
||||
}
|
||||
|
||||
// &:hover {
|
||||
// .actionsbox {
|
||||
// opacity: 1;
|
||||
// .routeactions {
|
||||
// transform: rotateY(0deg);
|
||||
// }
|
||||
// .deleteaction {
|
||||
// transform: rotateY(0deg);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
&:hover {
|
||||
.deleteaction {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.deleteaction {
|
||||
position: absolute;
|
||||
transition: all 0.3s;
|
||||
opacity: 0;
|
||||
right: 0;
|
||||
top: 0;
|
||||
z-index: 1;
|
||||
background-color: #bbbbbb42;
|
||||
border: 1px solid #bbbbbb42;
|
||||
text-align: center;
|
||||
width: 1.2rem;
|
||||
height: 1.2rem;
|
||||
border-radius: 0 0 0 0.5rem;
|
||||
line-height: 1.2rem;
|
||||
font-size: 15px;
|
||||
@media (max-width: 2000px) {
|
||||
width: 1.4rem;
|
||||
height: 1.4rem;
|
||||
border-radius: 0 0 0 0.5rem;
|
||||
line-height: 1.4rem;
|
||||
font-size: 15px;
|
||||
}
|
||||
@media (max-width: 1700px) {
|
||||
width: 1.7rem;
|
||||
height: 1.7rem;
|
||||
border-radius: 0 0 0 0.5rem;
|
||||
line-height: 1.7rem;
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
@media (max-width: 1500px) {
|
||||
width: 1.7rem;
|
||||
height: 1.7rem;
|
||||
border-radius: 0 0 0 0.5rem;
|
||||
line-height: 1.7rem;
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
@media (max-width: 1250px) {
|
||||
width: 1.6rem;
|
||||
height: 1.6rem;
|
||||
border-radius: 0 0 0 0.8rem;
|
||||
line-height: 1.6rem;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
color: red;
|
||||
i.icons {
|
||||
transform: rotateZ(360deg);
|
||||
}
|
||||
}
|
||||
i.icons {
|
||||
transition: all 0.3s;
|
||||
}
|
||||
}
|
||||
|
||||
.actionsbox {
|
||||
opacity: 1;
|
||||
transition: all 0.3s;
|
||||
position: absolute;
|
||||
z-index: 1;
|
||||
left: 0;
|
||||
top: 0;
|
||||
inset: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
.routeactions,
|
||||
.deleteaction {
|
||||
font-size: 15px;
|
||||
color: #fff;
|
||||
flex: 0.5;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: all 0.3s;
|
||||
|
||||
@media (max-width: 1500px) {
|
||||
font-size: 13px;
|
||||
}
|
||||
@media (max-width: 1250px) {
|
||||
font-size: 11px;
|
||||
}
|
||||
}
|
||||
.routeactions {
|
||||
background-color: #0083ff;
|
||||
transform-origin: left center;
|
||||
transform: rotateY(90deg);
|
||||
}
|
||||
.deleteaction {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
background-color: red;
|
||||
transform-origin: right center;
|
||||
transform: rotateY(-90deg);
|
||||
}
|
||||
}
|
||||
|
||||
&.add {
|
||||
text-align: center;
|
||||
color: #036aff;
|
||||
vertical-align: baseline;
|
||||
span {
|
||||
margin-left: 5px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user