From 1595cb282aab5399862fac6406b5de550863e3b6 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子Li <15040126243@163.com> Date: 星期一, 03 四月 2023 00:05:09 +0800 Subject: [PATCH] update 调整代码格式 --- src/layout/components/TagsView/index.vue | 310 +++++++++++++++++++++++++------------------------- 1 files changed, 155 insertions(+), 155 deletions(-) diff --git a/src/layout/components/TagsView/index.vue b/src/layout/components/TagsView/index.vue index 9f4db62..43b122f 100644 --- a/src/layout/components/TagsView/index.vue +++ b/src/layout/components/TagsView/index.vue @@ -1,3 +1,34 @@ +<template> + <div id="tags-view-container" class="tags-view-container"> + <scroll-pane ref="scrollPaneRef" class="tags-view-wrapper" @scroll="handleScroll"> + <router-link + v-for="tag in visitedViews" + :key="tag.path" + :data-path="tag.path" + :class="isActive(tag) ? 'active' : ''" + :to="{ path: tag.path ? tag.path : '', query: tag.query, fullPath: tag.fullPath ? tag.fullPath : '' }" + class="tags-view-item" + :style="activeStyle(tag)" + @click.middle="!isAffix(tag) ? closeSelectedTag(tag) : ''" + @contextmenu.prevent="openMenu(tag, $event)" + > + {{ tag.title }} + <span v-if="!isAffix(tag)" @click.prevent.stop="closeSelectedTag(tag)"> + <close class="el-icon-close" style="width: 1em; height: 1em;vertical-align: middle;" /> + </span> + </router-link> + </scroll-pane> + <ul v-show="visible" :style="{ left: left + 'px', top: top + 'px' }" class="contextmenu"> + <li @click="refreshSelectedTag(selectedTag)"><refresh-right style="width: 1em; height: 1em;" /> 鍒锋柊椤甸潰</li> + <li v-if="!isAffix(selectedTag)" @click="closeSelectedTag(selectedTag)"><close style="width: 1em; height: 1em;" /> 鍏抽棴褰撳墠</li> + <li @click="closeOthersTags"><circle-close style="width: 1em; height: 1em;" /> 鍏抽棴鍏朵粬</li> + <li v-if="!isFirstView()" @click="closeLeftTags"><back style="width: 1em; height: 1em;" /> 鍏抽棴宸︿晶</li> + <li v-if="!isLastView()" @click="closeRightTags"><right style="width: 1em; height: 1em;" /> 鍏抽棴鍙充晶</li> + <li @click="closeAllTags(selectedTag)"><circle-close style="width: 1em; height: 1em;" /> 鍏ㄩ儴鍏抽棴</li> + </ul> + </div> +</template> + <script setup lang="ts"> import ScrollPane from './ScrollPane.vue' import { getNormalPath } from '@/utils/ruoyi' @@ -23,215 +54,184 @@ const theme = computed(() => useSettingsStore().theme); watch(route, () => { - addTags(); - moveToCurrentTag(); + addTags(); + moveToCurrentTag(); }) watch(visible, (value) => { - if (value) { - document.body.addEventListener('click', closeMenu); - } else { - document.body.removeEventListener('click', closeMenu); - } + if (value) { + document.body.addEventListener('click', closeMenu); + } else { + document.body.removeEventListener('click', closeMenu); + } }) const isActive = (r: TagView): boolean => { - return r.path === route.path; + return r.path === route.path; } const activeStyle = (tag: TagView) => { - if (!isActive(tag)) return {}; - return { - "background-color": theme.value, - "border-color": theme.value - }; + if (!isActive(tag)) return {}; + return { + "background-color": theme.value, + "border-color": theme.value + }; } const isAffix = (tag: TagView) => { - return tag.meta && tag.meta.affix; + return tag.meta && tag.meta.affix; } const isFirstView = () => { - try { - return selectedTag.value.fullPath === '/index' || selectedTag.value.fullPath === visitedViews.value[1].fullPath; - } catch (err) { - return false; - } + try { + return selectedTag.value.fullPath === '/index' || selectedTag.value.fullPath === visitedViews.value[1].fullPath; + } catch (err) { + return false; + } } const isLastView = () => { - try { - return selectedTag.value.fullPath === visitedViews.value[visitedViews.value.length - 1].fullPath; - } catch (err) { - return false; - } + try { + return selectedTag.value.fullPath === visitedViews.value[visitedViews.value.length - 1].fullPath; + } catch (err) { + return false; + } } const filterAffixTags = (routes:RouteOption [], basePath = '') => { - let tags:TagView[] = [] - routes.forEach(route => { - if (route.meta && route.meta.affix) { - const tagPath = getNormalPath(basePath + '/' + route.path); - tags.push({ - fullPath: tagPath, - path: tagPath, - name: route.name, - meta: { ...route.meta } - }) - } - if (route.children) { - const tempTags = filterAffixTags(route.children, route.path); - if (tempTags.length >= 1) { - tags = [...tags, ...tempTags]; - } - } - }) - return tags + let tags:TagView[] = [] + routes.forEach(route => { + if (route.meta && route.meta.affix) { + const tagPath = getNormalPath(basePath + '/' + route.path); + tags.push({ + fullPath: tagPath, + path: tagPath, + name: route.name, + meta: { ...route.meta } + }) + } + if (route.children) { + const tempTags = filterAffixTags(route.children, route.path); + if (tempTags.length >= 1) { + tags = [...tags, ...tempTags]; + } + } + }) + return tags } const initTags = () => { - const res = filterAffixTags(routes.value); - affixTags.value = res; - for (const tag of res) { - // Must have tag name - if (tag.name) { - useTagsViewStore().addVisitedView(tag); + const res = filterAffixTags(routes.value); + affixTags.value = res; + for (const tag of res) { + // Must have tag name + if (tag.name) { + useTagsViewStore().addVisitedView(tag); + } } - } } const addTags = () => { - const { name } = route; - if (name) { - useTagsViewStore().addView(route); - if (route.meta.link) { - useTagsViewStore().addIframeView(route); + const { name } = route; + if (name) { + useTagsViewStore().addView(route); + if (route.meta.link) { + useTagsViewStore().addIframeView(route); + } } - } - return false + return false } const moveToCurrentTag = () => { - nextTick(() => { - for (const r of visitedViews.value) { - if (r.path === route.path) { - scrollPaneRef.value.moveToTarget(r); - // when query is different then update - if (r.fullPath !== route.fullPath) { - useTagsViewStore().updateVisitedView(route); + nextTick(() => { + for (const r of visitedViews.value) { + if (r.path === route.path) { + scrollPaneRef.value.moveToTarget(r); + // when query is different then update + if (r.fullPath !== route.fullPath) { + useTagsViewStore().updateVisitedView(route); + } + } } - } - } - }) + }) } const refreshSelectedTag = (view: TagView) => { - proxy?.$tab.refreshPage(view); - if (route.meta.link) { - useTagsViewStore().delIframeView(route); - } + proxy?.$tab.refreshPage(view); + if (route.meta.link) { + useTagsViewStore().delIframeView(route); + } } const closeSelectedTag = (view: TagView) => { - proxy?.$tab.closePage(view).then(({ visitedViews }: any) => { - if (isActive(view)) { - toLastView(visitedViews, view); - } - }) + proxy?.$tab.closePage(view).then(({ visitedViews }: any) => { + if (isActive(view)) { + toLastView(visitedViews, view); + } + }) } const closeRightTags = () => { - proxy?.$tab.closeRightPage(selectedTag.value).then(visitedViews => { - if (!visitedViews.find(i => i.fullPath === route.fullPath)) { - toLastView(visitedViews); - } - }) + proxy?.$tab.closeRightPage(selectedTag.value).then(visitedViews => { + if (!visitedViews.find(i => i.fullPath === route.fullPath)) { + toLastView(visitedViews); + } + }) } const closeLeftTags = () => { - proxy?.$tab.closeLeftPage(selectedTag.value).then(visitedViews => { - if (!visitedViews.find(i => i.fullPath === route.fullPath)) { - toLastView(visitedViews); - } - }) + proxy?.$tab.closeLeftPage(selectedTag.value).then(visitedViews => { + if (!visitedViews.find(i => i.fullPath === route.fullPath)) { + toLastView(visitedViews); + } + }) } const closeOthersTags = () => { - router.push(selectedTag.value as RouteLocationRaw).catch(() => { }); - proxy?.$tab.closeOtherPage(selectedTag.value).then(() => { - moveToCurrentTag(); - }) + router.push(selectedTag.value as RouteLocationRaw).catch(() => { }); + proxy?.$tab.closeOtherPage(selectedTag.value).then(() => { + moveToCurrentTag(); + }) } const closeAllTags = (view: TagView) => { - proxy?.$tab.closeAllPage().then(({ visitedViews }) => { - if (affixTags.value.some(tag => tag.path === route.path)) { - return; - } - toLastView(visitedViews, view); - }) + proxy?.$tab.closeAllPage().then(({ visitedViews }) => { + if (affixTags.value.some(tag => tag.path === route.path)) { + return; + } + toLastView(visitedViews, view); + }) } const toLastView = (visitedViews:TagView[], view?: TagView) => { - const latestView = visitedViews.slice(-1)[0]; - if (latestView) { - router.push(latestView.fullPath as string); - } else { - // now the default is to redirect to the home page if there is no tags-view, - // you can adjust it according to your needs. - if (view?.name === 'Dashboard') { - // to reload home page - router.replace({ path: '/redirect' + view?.fullPath }); + const latestView = visitedViews.slice(-1)[0]; + if (latestView) { + router.push(latestView.fullPath as string); } else { - router.push('/'); + // now the default is to redirect to the home page if there is no tags-view, + // you can adjust it according to your needs. + if (view?.name === 'Dashboard') { + // to reload home page + router.replace({ path: '/redirect' + view?.fullPath }); + } else { + router.push('/'); + } } - } } const openMenu = (tag: TagView, e: MouseEvent) => { - const menuMinWidth = 105; - const offsetLeft = proxy?.$el.getBoundingClientRect().left; // container margin left - const offsetWidth = proxy?.$el.offsetWidth; // container width - const maxLeft = offsetWidth - menuMinWidth; // left boundary - const l = e.clientX - offsetLeft + 15; // 15: margin right + const menuMinWidth = 105; + const offsetLeft = proxy?.$el.getBoundingClientRect().left; // container margin left + const offsetWidth = proxy?.$el.offsetWidth; // container width + const maxLeft = offsetWidth - menuMinWidth; // left boundary + const l = e.clientX - offsetLeft + 15; // 15: margin right - if (l > maxLeft) { - left.value = maxLeft; - } else { - left.value = l; - } + if (l > maxLeft) { + left.value = maxLeft; + } else { + left.value = l; + } - top.value = e.clientY - visible.value = true; - selectedTag.value = tag; + top.value = e.clientY + visible.value = true; + selectedTag.value = tag; } const closeMenu = () => { - visible.value = false; + visible.value = false; } const handleScroll = () => { - closeMenu(); + closeMenu(); } onMounted(() => { - initTags(); - addTags(); + initTags(); + addTags(); }) </script> - -<template> - <div id="tags-view-container" class="tags-view-container"> - <scroll-pane ref="scrollPaneRef" class="tags-view-wrapper" @scroll="handleScroll"> - <router-link - v-for="tag in visitedViews" - :key="tag.path" - :data-path="tag.path" - :class="isActive(tag) ? 'active' : ''" - :to="{ path: tag.path ? tag.path : '', query: tag.query, fullPath: tag.fullPath ? tag.fullPath : '' }" - class="tags-view-item" - :style="activeStyle(tag)" - @click.middle="!isAffix(tag) ? closeSelectedTag(tag) : ''" - @contextmenu.prevent="openMenu(tag, $event)" - > - {{ tag.title }} - <span v-if="!isAffix(tag)" @click.prevent.stop="closeSelectedTag(tag)"> - <close class="el-icon-close" style="width: 1em; height: 1em;vertical-align: middle;" /> - </span> - </router-link> - </scroll-pane> - <ul v-show="visible" :style="{ left: left + 'px', top: top + 'px' }" class="contextmenu"> - <li @click="refreshSelectedTag(selectedTag)"><refresh-right style="width: 1em; height: 1em;" /> 鍒锋柊椤甸潰</li> - <li v-if="!isAffix(selectedTag)" @click="closeSelectedTag(selectedTag)"><close style="width: 1em; height: 1em;" /> 鍏抽棴褰撳墠</li> - <li @click="closeOthersTags"><circle-close style="width: 1em; height: 1em;" /> 鍏抽棴鍏朵粬</li> - <li v-if="!isFirstView()" @click="closeLeftTags"><back style="width: 1em; height: 1em;" /> 鍏抽棴宸︿晶</li> - <li v-if="!isLastView()" @click="closeRightTags"><right style="width: 1em; height: 1em;" /> 鍏抽棴鍙充晶</li> - <li @click="closeAllTags(selectedTag)"><circle-close style="width: 1em; height: 1em;" /> 鍏ㄩ儴鍏抽棴</li> - </ul> - </div> -</template> <style lang="scss" scoped> .tags-view-container { -- Gitblit v1.9.3