zydx-plus 1.35.634 → 1.35.636
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 +59 -44
- package/src/index.js +1 -1
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="box" ref="boxRef">
|
|
3
3
|
<!-- 左侧内容,默认展示70%,默认最小宽度310px-->
|
|
4
|
-
<div v-if="isShowsLeft" class="left" ref="leftRef">
|
|
4
|
+
<div v-if="isShowsLeft" class="left" ref="leftRef" :style="{ width: leftWidth }">
|
|
5
5
|
<slot name="left"></slot>
|
|
6
6
|
</div>
|
|
7
7
|
<div v-if="isShowsRight && isShowsLeft" class="resize">
|
|
8
8
|
<img src="./drag.png" ref="resizeRef" style="width: 30px;height: 30px;position: absolute;top: 280px;left: 50%;transform: translateX(-15px)" alt="">
|
|
9
9
|
</div>
|
|
10
|
-
<div v-if="isShowsRight" class="right" ref="rightRef">
|
|
10
|
+
<div v-if="isShowsRight" class="right" ref="rightRef" :style="{ width: rightWidth }">
|
|
11
11
|
<!-- 右侧内容,默认展示30%,默认最小宽度310px-->
|
|
12
12
|
<slot name="right"></slot>
|
|
13
13
|
</div>
|
|
@@ -44,63 +44,75 @@ export default {
|
|
|
44
44
|
},
|
|
45
45
|
},
|
|
46
46
|
watch: {
|
|
47
|
-
isShowsRight
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
},
|
|
57
|
-
immediate: true,
|
|
58
|
-
deep: true
|
|
47
|
+
isShowsRight() {
|
|
48
|
+
this.$nextTick(() => {
|
|
49
|
+
if (this.isShowsRight) {
|
|
50
|
+
this.resetWidth()
|
|
51
|
+
this.handleResize()
|
|
52
|
+
} else if (this.$refs.leftRef) {
|
|
53
|
+
this.leftWidth = '100%'
|
|
54
|
+
}
|
|
55
|
+
})
|
|
59
56
|
},
|
|
60
|
-
isShowsLeft
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
},
|
|
70
|
-
immediate: true,
|
|
71
|
-
deep: true
|
|
57
|
+
isShowsLeft() {
|
|
58
|
+
this.$nextTick(() => {
|
|
59
|
+
if (this.isShowsLeft) {
|
|
60
|
+
this.resetWidth()
|
|
61
|
+
this.handleResize()
|
|
62
|
+
} else if (this.$refs.rightRef) {
|
|
63
|
+
this.rightWidth = '100%'
|
|
64
|
+
}
|
|
65
|
+
})
|
|
72
66
|
}
|
|
73
67
|
},
|
|
74
68
|
data() {
|
|
75
|
-
|
|
69
|
+
// 由 props 直接计算初始宽度,保证首屏渲染即为正确宽度,避免闪动
|
|
70
|
+
const w = this.leftInitWidth
|
|
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
|
+
}
|
|
76
83
|
},
|
|
77
84
|
mounted() {
|
|
85
|
+
this.handleResize()
|
|
78
86
|
},
|
|
79
87
|
methods: {
|
|
88
|
+
// 由 props 重新计算左右初始宽度(供显示切换/外部调用)
|
|
89
|
+
resetWidth() {
|
|
90
|
+
const w = this.leftInitWidth
|
|
91
|
+
if (this.isPercent) {
|
|
92
|
+
const lw = w <= 0 || w >= 100 ? 30 : w
|
|
93
|
+
this.leftWidth = lw + '%'
|
|
94
|
+
this.rightWidth = (100 - lw) + '%'
|
|
95
|
+
} else {
|
|
96
|
+
this.leftWidth = w + 'px'
|
|
97
|
+
this.rightWidth = `calc(100% - ${w}px - 10px)`
|
|
98
|
+
}
|
|
99
|
+
},
|
|
80
100
|
handleResize() {
|
|
81
101
|
// 获取Dom节点
|
|
82
102
|
const boxDom = this.$refs.boxRef,
|
|
83
103
|
leftDom = this.$refs.leftRef,
|
|
84
|
-
resizeDom = this.$refs.resizeRef
|
|
85
|
-
rightDom = this.$refs.rightRef;
|
|
104
|
+
resizeDom = this.$refs.resizeRef;
|
|
86
105
|
if (resizeDom) {
|
|
87
106
|
// 使用 .resize div 的实际宽度(10px)而非 img 宽度(30px),避免拖动位置偏左
|
|
88
107
|
const resizeWidth = resizeDom.parentElement.offsetWidth
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
this.leftInitWidth<=0||this.leftInitWidth>=100 ? 30 : this.leftInitWidth
|
|
92
|
-
: this.leftInitWidth}${this.isPercent? '%' : 'px'}`
|
|
93
|
-
rightDom.style.width = `${this.isPercent?
|
|
94
|
-
this.leftInitWidth<=0||this.leftInitWidth>=100 ? 70 : 100-this.leftInitWidth
|
|
95
|
-
: maxWidth-this.leftInitWidth}${this.isPercent? '%' : 'px'}`
|
|
96
|
-
/*leftDom.style.width = '50%'
|
|
97
|
-
rightDom.style.width = '50%'*/
|
|
108
|
+
const containerWidth = boxDom.clientWidth
|
|
109
|
+
const maxWidth = containerWidth - resizeWidth; // 左右两边区域的总宽度 = 外层容器宽度 - 中间区域拖拉框的宽度
|
|
98
110
|
resizeDom.onmousedown = e => {
|
|
99
111
|
const startX = e.clientX; // 记录坐标起始位置
|
|
100
|
-
|
|
112
|
+
const startLeft = leftDom.offsetWidth; // 左边元素起始宽度
|
|
101
113
|
document.onmousemove = e => {
|
|
102
114
|
const endX = e.clientX; // 鼠标拖动的终止位置
|
|
103
|
-
let moveLen =
|
|
115
|
+
let moveLen = startLeft + (endX - startX); // 移动的距离 = endX - startX,左边区域最后的宽度 = startLeft + 移动的距离
|
|
104
116
|
// 限制左边区域的最小宽度为 leftMinWidth
|
|
105
117
|
if (moveLen < this.leftMinWidth) {
|
|
106
118
|
moveLen = this.leftMinWidth;
|
|
@@ -109,8 +121,10 @@ export default {
|
|
|
109
121
|
if (moveLen > maxWidth - this.rightMinWidth) {
|
|
110
122
|
moveLen = maxWidth - this.rightMinWidth;
|
|
111
123
|
}
|
|
112
|
-
|
|
113
|
-
|
|
124
|
+
// 百分比基准用完整容器宽,右侧再减去 resize 宽度,
|
|
125
|
+
// 保证 left% + right% + resize(10px) = 100%,避免拖拽后总宽多出 10px
|
|
126
|
+
this.leftWidth = (moveLen / containerWidth) * 100 + "%"; // 设置左边区域的宽度,通过换算为百分比的形式,实现窗体放大缩小自适应
|
|
127
|
+
this.rightWidth = ((containerWidth - moveLen - resizeWidth) / containerWidth) * 100 + "%"; // 右边区域 = 容器 - 左边宽度 - 拖动条宽度
|
|
114
128
|
};
|
|
115
129
|
document.onmouseup = () => {
|
|
116
130
|
document.onmousemove = null;
|
|
@@ -134,11 +148,12 @@ export default {
|
|
|
134
148
|
box-sizing: border-box;
|
|
135
149
|
}
|
|
136
150
|
.left {
|
|
137
|
-
|
|
151
|
+
flex-shrink: 0;
|
|
138
152
|
}
|
|
139
153
|
.resize {
|
|
140
154
|
position: relative;
|
|
141
155
|
width: 10px;
|
|
156
|
+
flex-shrink: 0;
|
|
142
157
|
cursor: col-resize;
|
|
143
158
|
background-size: cover;
|
|
144
159
|
background-position: center;
|
|
@@ -150,6 +165,6 @@ export default {
|
|
|
150
165
|
background-color: white;
|
|
151
166
|
}
|
|
152
167
|
.right {
|
|
153
|
-
|
|
168
|
+
flex-shrink: 0;
|
|
154
169
|
}
|
|
155
170
|
</style>
|