refactor(测试跟踪): 功能用例列表页,记住模块树的宽度

--bug=1025065 --user=陈建星 左侧模块宽度调整后记住用户的操作 https://www.tapd.cn/55049933/s/1358949
This commit is contained in:
chenjianxing 2023-04-03 19:28:34 +08:00 committed by jianxing
parent 9201fe07ce
commit c08ce30a15
2 changed files with 47 additions and 8 deletions

View File

@ -1,5 +1,5 @@
<template> <template>
<el-aside :width="asideHidden ? '0' : width" class="ms-aside-container" <el-aside :width="asideHidden ? '0' : defaultWidth" class="ms-aside-container"
:id="id" :id="id"
:style="{ :style="{
// 'margin-left': !asideHidden ? 0 : '-' + asideHiddenMargin, // 'margin-left': !asideHidden ? 0 : '-' + asideHiddenMargin,
@ -24,6 +24,16 @@ import {getUUID} from "../../utils";
export default { export default {
name: "MsAsideContainer", name: "MsAsideContainer",
components: {MsHorizontalDragBar}, components: {MsHorizontalDragBar},
data() {
return {
asideHidden: false,
hiddenBottomTop: null,
id: null,
asideHiddenMargin: '292px',
defaultWidth: '269px',
observer: null
}
},
props: { props: {
width: { width: {
type: String, type: String,
@ -52,6 +62,12 @@ export default {
type: Number, type: Number,
default: null default: null
}, },
//
enableRememberWidth: Boolean,
pageKey: {
type: String,
default: null
}
}, },
watch: { watch: {
asideHidden() { asideHidden() {
@ -75,13 +91,32 @@ export default {
this.$nextTick(() => { this.$nextTick(() => {
this.setHiddenBottomTop(); this.setHiddenBottomTop();
}); });
if (this.pageKey && this.enableRememberWidth) {
let rememberKey = 'WIDTH_' + this.pageKey;
let rememberWidth = localStorage.getItem(rememberKey);
if (rememberWidth) {
//
this.defaultWidth = rememberWidth;
} else {
this.defaultWidth = this.width;
}
let element = document.getElementById(this.id);
let MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver
this.observer = new MutationObserver(() => {
// localStorage
localStorage.setItem(rememberKey, getComputedStyle(element).getPropertyValue('width'));
})
this.observer.observe(element, { attributes: true, attributeFilter: ['style'], attributeOldValue: true })
}
}, },
data() { beforeDestroyed () {
return { if (this.observer) {
asideHidden: false, this.observer.disconnect()
hiddenBottomTop: null, this.observer.takeRecords()
id: null, this.observer = null
asideHiddenMargin: '292px'
} }
}, },
methods: { methods: {

View File

@ -32,7 +32,11 @@
<div style="display: flex; height: calc(100vh - 130px)" class = "test-case-aside-layout"> <div style="display: flex; height: calc(100vh - 130px)" class = "test-case-aside-layout">
<!-- case-aside-container --> <!-- case-aside-container -->
<ms-aside-container v-show="isAsideHidden" :min-width="'0'" :enable-aside-hidden.sync="enableAsideHidden"> <ms-aside-container v-show="isAsideHidden"
page-key="TEST_CASE_LIST"
:enable-remember-width="true"
:min-width="'0'"
:enable-aside-hidden.sync="enableAsideHidden">
<test-case-node-tree <test-case-node-tree
:type="'edit'" :type="'edit'"
:total='total' :total='total'