Browse Source

标签页

master
luobinjie 3 months ago
parent
commit
e62a33ffdd
  1. 93
      src/components/common/CommonTab.vue
  2. 44
      src/views/Home.vue

93
src/components/common/CommonTab.vue

@ -10,6 +10,7 @@
icon="el-icon-arrow-left"
:disabled="isLeftDisabled"
></el-button>
<el-button icon="el-icon-delete" size="medium" :disabled="tags.length==0" @click="clearControlLabel"></el-button>
</div>
<div class="tag-style" ref="tagBox">
<div class="scrollWrapper" ref="scrollWrapper" id="nav">
@ -69,27 +70,43 @@ export default {
mounted() {
this.scrollWrapper = this.$refs.scrollWrapper;
this.$nextTick(() => {
this.updateButtonStates();
// 使
this.debouncedUpdateButtonStates();
});
this.scrollWrapper.addEventListener("scroll", this.handleScroll);
window.addEventListener("resize", this.updateButtonStates);
// 便
this._resizeHandler = this.debouncedUpdateButtonStates;
window.addEventListener("resize", this._resizeHandler);
},
beforeDestroy() {
//
if (this.scrollWrapper) {
this.scrollWrapper.removeEventListener("scroll", this.handleScroll);
}
window.removeEventListener("resize", this.updateButtonStates);
if (this._resizeHandler) {
window.removeEventListener("resize", this._resizeHandler);
}
},
methods: {
//
debounce(func, wait = 100) {
let timeout = null;
const self = this;
return function () {
const args = arguments;
if (timeout) clearTimeout(timeout);
timeout = setTimeout(() => {
timeout = null;
func.apply(self, args);
}, wait);
};
},
...mapMutations({
close: "closeTab",
}),
handleScroll() {
// 使 setTimeout
setTimeout(() => {
this.updateButtonStates();
}, 50);
// 使
this.debouncedUpdateButtonStates();
},
//
arrowBack() {
@ -100,9 +117,21 @@ export default {
this.$refs.scrollWrapper.scrollBy({ left: 300, behavior: "smooth" });
},
updateButtonStates() {
const { scrollLeft, scrollWidth, clientWidth } = this.scrollWrapper;
//
if (!this.scrollWrapper || !this.tags || this.tags.length === 0) {
this.isLeftDisabled = true;
this.isRightDisabled = true;
return;
}
// / 0 undefined使 Number()
const scrollLeft = Number(this.scrollWrapper.scrollLeft || 0);
const scrollWidth = Number(this.scrollWrapper.scrollWidth || 0);
const clientWidth = Number(this.scrollWrapper.clientWidth || 0);
this.isLeftDisabled = scrollLeft <= 0;
this.isRightDisabled = scrollLeft + clientWidth >= scrollWidth - 1;
//
this.isRightDisabled = scrollWidth <= clientWidth || scrollLeft + clientWidth >= scrollWidth - 1;
},
scrollToActiveTag() {
this.$nextTick(() => {
@ -134,9 +163,9 @@ export default {
behavior: 'smooth'
});
//
//
setTimeout(() => {
this.updateButtonStates();
this.debouncedUpdateButtonStates();
}, 150);
}
});
@ -149,37 +178,61 @@ export default {
this.handleScroll();
return;
}
//
if (index === length) {
if (this.tags[index - 1]) {
try {
this.$router.push(this.tags[index - 1].routeUrl);
} catch (e) {
this.$router.push({ path: this.tags[index - 1].routeUrl });
}
} else {
this.$router.push({ path: "/home" });
}
} else {
//
try {
this.$router.push(this.tags[index].routeUrl);
} catch (e) {
this.$router.push({ path: this.tags[index].routeUrl });
}
}
this.handleScroll();
},
changeMenu(item) {
if (item.displayName !== this.$route.name) {
// tabsList
// 使 tabsList routeUrl key
try {
this.$router.push(item.routeUrl);
} catch (e) {
this.$router.push({ path: item.routeUrl });
} else {
// this.$message({
// message: '',
// type: 'error'
// });
}
}
this.$nextTick(() => {
this.scrollToActiveTag();
});
},
async clearControlLabel() {
await this.$store.commit("clearMenuTab");
clearControlLabel() {
this.$store.commit("clearMenuTab");
// DOM
this.$nextTick(() => {
if (this.$refs.scrollWrapper) {
this.$refs.scrollWrapper.scrollLeft = 0;
}
// //
// this.debouncedUpdateButtonStates();
this.$router.push({ path: "/home" });
});
},
},
created() {
//
this.debouncedUpdateButtonStates = this.debounce(function () {
this.updateButtonStates();
}, 100);
},
};
</script>
@ -204,7 +257,7 @@ export default {
pointer-events: all;
cursor: pointer;
position: relative;
margin: 0 64px;
margin: 0 64px 0 138px;
}
.scrollWrapper {
display: flex;
@ -216,7 +269,7 @@ export default {
height: 0;
}
.el-tag {
margin: 0 5px;
margin: 0 60px;
cursor: pointer;
padding: 0 0px 0 10px;
}

44
src/views/Home.vue

@ -147,7 +147,7 @@
<common-tab></common-tab>
<el-main style="margin-top: 84px;">
<keep-alive>
<router-view></router-view>
<router-view :key="$route.fullPath"></router-view>
</keep-alive>
</el-main>
</el-container>
@ -217,13 +217,16 @@ export default {
lsysConfig: {
apiurl: "http://10.1.12.140:9529",
softName: "创业体检管理系统"
}
},
};
},
computed: {
...mapState(["window", "dialogWin", "sysConfig"]),
},
created() {
// openedTabs
this.$set(this, 'openedTabs', {});
let expires_in = parseInt(window.sessionStorage.getItem("expires_in"));
//console.log("dqtime / expires_in",dqtime,expires_in)
if (!expires_in) {
@ -278,8 +281,41 @@ export default {
// console.log(key, keyPath);
// tree: any, childNodeName: any, idName: any, idVal: any
let node = getTreeNode(this.menuPriv, "treeChildren", "id", key);
if (node && this.$route.path !== '/' + node.routeUrl){
this.$store.commit('selectMenu', node)
if (!node) return;
// normalize current path (route.path may start with '/')
const currentPath = this.$route.path || '';
const targetPath = node.routeUrl && node.routeUrl.startsWith('/') ? node.routeUrl : '/' + node.routeUrl;
if (currentPath === targetPath) return;
if (this.LocalConfig.normal.displayTab) {
const exists = this.$store.state.tabsList.some(tab => tab.displayName === node.displayName);
if (exists) {
// 使 tabsList routeUrl
const tab = this.$store.state.tabsList.find(t => t.displayName === node.displayName) || {};
const routeTo = tab.routeUrl || node.routeUrl || targetPath;
// router.push
try {
this.$router.push(routeTo);
} catch (e) {
this.$router.push({ path: routeTo });
}
} else {
// routeUrl tabsList
const ts = Date.now();
const base = node.routeUrl || targetPath;
const sep = base.indexOf('?') > -1 ? '&' : '?';
const full = base + sep + 't=' + ts;
const tabToAdd = Object.assign({}, node, { routeUrl: full });
this.$store.commit('selectMenu', tabToAdd);
try {
this.$router.push(full);
} catch (e) {
this.$router.push({ path: full });
}
}
} else {
this.$store.commit('selectMenu', node);
this.$router.push({ path: node.routeUrl });
}
},

Loading…
Cancel
Save