zhangwei
4 天以前 9a416e0c3308badb6135ce921e6307f31e0dd463
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<template>
    <el-card shadow="hover" header="快捷入口">
        <template #header>
            <el-icon style="display: inline; vertical-align: middle"> <ele-Guide /> </el-icon>
            <span> 快捷入口 </span>
        </template>
        <ul class="myMods">
            <li v-for="mod in myMods" :key="mod.path!">
                <router-link :to="{ path: mod.path! }">
                    <SvgIcon :name="mod.meta?.icon" style="font-size: 18px" />
                    <p>{{ mod.meta?.title }}</p>
                </router-link>
            </li>
            <li class="modItem-add" @click="addMods">
                <a>
                    <el-icon><ele-Plus :style="{ color: '#fff' }" /></el-icon>
                </a>
            </li>
        </ul>
 
        <el-drawer title="添加应用" v-model="modsDrawer" :size="520" destroy-on-close :before-close="beforeClose">
            <div class="setMods mt15">
                <h4>我的常用 ( {{ myMods.length }} )</h4>
                <VueDraggable tag="ul" v-model="myMods" :animation="200" group="app" class="draggable-box">
                    <li v-for="item in myMods" :key="item.id">
                        <SvgIcon :name="item.meta?.icon" style="font-size: 18px" />
                        <p>{{ item.meta?.title }}</p>
                    </li>
                </VueDraggable>
            </div>
            <div class="setMods">
                <h4>全部应用 ( {{ filterMods.length }} )</h4>
                <VueDraggable tag="ul" v-model="filterMods" :animation="200" group="app" class="draggable-box-all">
                    <li v-for="item in filterMods" :key="item.id" :style="{ background: '#909399' }">
                        <SvgIcon :name="item.meta?.icon" style="font-size: 18px" />
                        <p>{{ item.meta?.title }}</p>
                    </li>
                </VueDraggable>
            </div>
            <template #footer>
                <div style="margin: 0 20px 20px 0">
                    <el-button @click="beforeClose">取消</el-button>
                    <el-button type="primary" @click="saveMods">保存</el-button>
                </div>
            </template>
        </el-drawer>
    </el-card>
</template>
 
<script lang="ts">
export default {
    title: '快捷入口',
    icon: 'ele-Guide',
    description: '可以配置的快捷入口',
};
</script>
 
<script setup lang="ts" name="myapp">
import { onMounted, ref } from 'vue';
import { ElMessage } from 'element-plus';
import { VueDraggable } from 'vue-draggable-plus';
import { getAPI } from '/@/utils/axios-utils';
import { SysUserMenuApi } from '/@/api-services/api';
import { MenuOutput } from '/@/api-services/models';
import { useRequestOldRoutes } from '/@/stores/requestOldRoutes';
 
const mods = ref<MenuOutput[]>([]); // 所有应用
const myMods = ref<MenuOutput[]>([]); // 我的常用
const myModsName = ref<Array<string | null | undefined>>([]); // 我的常用
const filterMods = ref<MenuOutput[]>([]); // 过滤我的常用后的应用
const modsDrawer = ref<boolean>(false);
 
onMounted(() => {
    getMods();
});
 
// 请求已收藏菜单列表
const getFavoriteMenuList = async () => {
    try {
        const res = await getAPI(SysUserMenuApi).apiSysUserMenuUserMenuListGet();
        return res.data.result || [];
    } catch (error) {
        return [];
    }
};
 
const addMods = () => {
    modsDrawer.value = true;
};
 
const getMods = async () => {
    var menuTree = (useRequestOldRoutes().requestOldRoutes as MenuOutput[]) || [];
    filterMenu(menuTree);
 
    myMods.value = await getFavoriteMenuList();
 
    myModsName.value = myMods.value.map((v: MenuOutput) => v.name);
    filterMods.value = mods.value.filter((item: MenuOutput) => {
        return !myModsName.value.includes(item.name);
    });
};
 
// 递归拿到所有可显示非iframe的2级菜单
const filterMenu = (map: MenuOutput[]) => {
    map.forEach((item: MenuOutput) => {
        if (item.meta?.isHide || item.type == 3 || item.status != 1) {
            return false;
        }
        if (item.meta?.isIframe) {
            item.path = `/i/${item.name}`;
        }
        if (item.children && item.children.length > 0) {
            filterMenu(item.children);
        } else {
            mods.value.push(item);
        }
    });
};
 
// 保存我的常用
const saveMods = async () => {
    const menuIds = myMods.value.map((v: MenuOutput) => v.id) as any;
    await getAPI(SysUserMenuApi).apiSysUserMenuAddPost({ menuIdList: menuIds });
    ElMessage.success('设置常用成功');
    modsDrawer.value = false;
};
 
// 取消
const beforeClose = async () => {
    myMods.value = await getFavoriteMenuList();
    myModsName.value = myMods.value.map((v: MenuOutput) => v.name);
    filterMods.value = mods.value.filter((item: MenuOutput) => {
        return !myModsName.value.includes(item.name);
    });
    modsDrawer.value = false;
};
</script>
 
<style scoped lang="scss">
.myMods {
    list-style: none;
    margin: -10px;
}
.myMods li {
    display: inline-block;
    width: 100px;
    height: 100px;
    vertical-align: top;
    transition: all 0.3s ease;
    margin: 10px;
    border-radius: 5px;
    background: var(--el-color-primary);
}
.myMods li:hover {
    opacity: 0.5;
}
.myMods li a {
    width: 100%;
    height: 100%;
    padding: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: #fff;
}
.myMods li i {
    font-size: 26px;
    color: #fff;
}
.myMods li p {
    font-size: 14px;
    color: #fff;
    margin-top: 10px;
    width: 100%;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}
 
.modItem-add {
    border: 1px dashed #ddd;
    cursor: pointer;
}
.modItem-add i {
    font-size: 30px;
    color: #999 !important;
}
.modItem-add:hover,
.modItem-add:hover i {
    border-color: #409eff;
    color: #409eff !important;
}
 
.draggable-box {
    border: 1px dashed var(--el-color-primary);
    padding: 15px;
}
 
.draggable-box-all {
    border: 1px dashed var(--el-color-primary);
    padding: 15px;
    height: calc(100vh - 330px);
    overflow-y: scroll;
}
 
.draggable-box-all::-webkit-scrollbar {
    display: none;
}
 
.setMods {
    padding: 0 20px;
}
.setMods h4 {
    font-size: 14px;
    font-weight: normal;
}
.setMods ul {
    margin: 20px -5px;
    min-height: 90px;
}
.setMods li {
    display: inline-block;
    width: 80px;
    height: 80px;
    text-align: center;
    margin: 5px;
    color: #fff;
    vertical-align: top;
    padding: 4px;
    padding-top: 15px;
    cursor: move;
    border-radius: 3px;
    background: var(--el-color-primary);
}
.setMods li i {
    font-size: 20px;
}
.setMods li p {
    font-size: 12px;
    margin-top: 10px;
}
.setMods li.sortable-ghost {
    opacity: 0.3;
}
a {
    text-decoration: none;
}
</style>