zydx-plus 1.35.635 → 1.35.637
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/components/variableBox/index.vue +43 -44
- package/src/index.js +1 -1
package/package.json
CHANGED
|
@@ -46,73 +46,71 @@ export default {
|
|
|
46
46
|
watch: {
|
|
47
47
|
isShowsRight() {
|
|
48
48
|
this.$nextTick(() => {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
this.handleResize()
|
|
52
|
-
} else if (this.$refs.leftRef) {
|
|
53
|
-
this.leftWidth = '100%'
|
|
54
|
-
}
|
|
49
|
+
this.resetWidth()
|
|
50
|
+
this.handleResize()
|
|
55
51
|
})
|
|
56
52
|
},
|
|
57
53
|
isShowsLeft() {
|
|
58
54
|
this.$nextTick(() => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
this.handleResize()
|
|
62
|
-
} else if (this.$refs.rightRef) {
|
|
63
|
-
this.rightWidth = '100%'
|
|
64
|
-
}
|
|
55
|
+
this.resetWidth()
|
|
56
|
+
this.handleResize()
|
|
65
57
|
})
|
|
66
58
|
}
|
|
67
59
|
},
|
|
68
60
|
data() {
|
|
69
|
-
// 由 props
|
|
70
|
-
|
|
71
|
-
if (this.isPercent) {
|
|
72
|
-
const lw = w <= 0 || w >= 100 ? 30 : w
|
|
73
|
-
return {
|
|
74
|
-
leftWidth: lw + '%',
|
|
75
|
-
rightWidth: (100 - lw) + '%'
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return {
|
|
79
|
-
leftWidth: w + 'px',
|
|
80
|
-
// px 模式右侧占满剩余空间,无需测量容器宽度即可首屏正确
|
|
81
|
-
rightWidth: `calc(100% - ${w}px - 10px)`
|
|
82
|
-
}
|
|
61
|
+
// 由 props 与可见性直接计算初始宽度,保证首屏渲染即为正确宽度,避免闪动
|
|
62
|
+
return this.getInitWidth()
|
|
83
63
|
},
|
|
84
64
|
mounted() {
|
|
85
65
|
this.handleResize()
|
|
86
66
|
},
|
|
87
67
|
methods: {
|
|
88
|
-
//
|
|
89
|
-
|
|
68
|
+
// 根据 props 与可见性计算左右宽度
|
|
69
|
+
getInitWidth() {
|
|
70
|
+
// 右侧隐藏时,左侧占满 100%
|
|
71
|
+
if (!this.isShowsRight) {
|
|
72
|
+
return { leftWidth: '100%', rightWidth: '0' }
|
|
73
|
+
}
|
|
74
|
+
// 左侧隐藏时,右侧占满 100%
|
|
75
|
+
if (!this.isShowsLeft) {
|
|
76
|
+
return { leftWidth: '0', rightWidth: '100%' }
|
|
77
|
+
}
|
|
90
78
|
const w = this.leftInitWidth
|
|
91
79
|
if (this.isPercent) {
|
|
92
80
|
const lw = w <= 0 || w >= 100 ? 30 : w
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
81
|
+
return { leftWidth: lw + '%', rightWidth: (100 - lw) + '%' }
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
leftWidth: w + 'px',
|
|
85
|
+
// px 模式右侧占满剩余空间,无需测量容器宽度即可首屏正确
|
|
86
|
+
rightWidth: `calc(100% - ${w}px - 10px)`
|
|
98
87
|
}
|
|
99
88
|
},
|
|
89
|
+
// 由 props 与可见性重新计算左右宽度(供显示切换/外部调用)
|
|
90
|
+
resetWidth() {
|
|
91
|
+
const { leftWidth, rightWidth } = this.getInitWidth()
|
|
92
|
+
this.leftWidth = leftWidth
|
|
93
|
+
this.rightWidth = rightWidth
|
|
94
|
+
},
|
|
100
95
|
handleResize() {
|
|
101
96
|
// 获取Dom节点
|
|
102
97
|
const boxDom = this.$refs.boxRef,
|
|
103
|
-
|
|
104
|
-
resizeDom = this.$refs.resizeRef,
|
|
105
|
-
rightDom = this.$refs.rightRef;
|
|
98
|
+
resizeDom = this.$refs.resizeRef;
|
|
106
99
|
if (resizeDom) {
|
|
107
100
|
// 使用 .resize div 的实际宽度(10px)而非 img 宽度(30px),避免拖动位置偏左
|
|
108
101
|
const resizeWidth = resizeDom.parentElement.offsetWidth
|
|
109
|
-
const maxWidth = boxDom.clientWidth - resizeWidth; // 左右两边区域的总宽度 = 外层容器宽度 - 中间区域拖拉框的宽度
|
|
110
102
|
resizeDom.onmousedown = e => {
|
|
111
|
-
|
|
112
|
-
|
|
103
|
+
e.preventDefault()
|
|
104
|
+
// 记录按下瞬间分隔条位置,计算鼠标相对分隔条左边缘的抓取偏移
|
|
105
|
+
const handleRect = resizeDom.parentElement.getBoundingClientRect()
|
|
106
|
+
const grabOffset = e.clientX - handleRect.left
|
|
113
107
|
document.onmousemove = e => {
|
|
114
|
-
|
|
115
|
-
|
|
108
|
+
// 每帧重新测量容器实际宽度与位置,避免整体宽度变化(窗口/父容器缩放)导致的累计偏移
|
|
109
|
+
const curBoxRect = boxDom.getBoundingClientRect()
|
|
110
|
+
const containerWidth = curBoxRect.width
|
|
111
|
+
const maxWidth = containerWidth - resizeWidth; // 左右两边区域的总宽度 = 外层容器宽度 - 中间区域拖拉框的宽度
|
|
112
|
+
// 鼠标相对容器左边缘的位置 - 抓取偏移 = 新的左区域宽度(px),使抓取点始终贴合分隔条
|
|
113
|
+
let moveLen = (e.clientX - curBoxRect.left) - grabOffset
|
|
116
114
|
// 限制左边区域的最小宽度为 leftMinWidth
|
|
117
115
|
if (moveLen < this.leftMinWidth) {
|
|
118
116
|
moveLen = this.leftMinWidth;
|
|
@@ -121,9 +119,10 @@ export default {
|
|
|
121
119
|
if (moveLen > maxWidth - this.rightMinWidth) {
|
|
122
120
|
moveLen = maxWidth - this.rightMinWidth;
|
|
123
121
|
}
|
|
124
|
-
//
|
|
125
|
-
|
|
126
|
-
this.
|
|
122
|
+
// 百分比基准用完整容器宽,右侧再减去 resize 宽度,
|
|
123
|
+
// 保证 left% + right% + resize(10px) = 100%,避免拖拽后总宽多出 10px
|
|
124
|
+
this.leftWidth = (moveLen / containerWidth) * 100 + "%"; // 设置左边区域的宽度,通过换算为百分比的形式,实现窗体放大缩小自适应
|
|
125
|
+
this.rightWidth = ((containerWidth - moveLen - resizeWidth) / containerWidth) * 100 + "%"; // 右边区域 = 容器 - 左边宽度 - 拖动条宽度
|
|
127
126
|
};
|
|
128
127
|
document.onmouseup = () => {
|
|
129
128
|
document.onmousemove = null;
|