zydx-plus 1.35.634 → 1.35.635
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 +55 -41
- 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,39 +44,59 @@ 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,
|
|
@@ -87,20 +107,12 @@ export default {
|
|
|
87
107
|
// 使用 .resize div 的实际宽度(10px)而非 img 宽度(30px),避免拖动位置偏左
|
|
88
108
|
const resizeWidth = resizeDom.parentElement.offsetWidth
|
|
89
109
|
const maxWidth = boxDom.clientWidth - resizeWidth; // 左右两边区域的总宽度 = 外层容器宽度 - 中间区域拖拉框的宽度
|
|
90
|
-
leftDom.style.width = `${this.isPercent?
|
|
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%'*/
|
|
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,9 @@ export default {
|
|
|
109
121
|
if (moveLen > maxWidth - this.rightMinWidth) {
|
|
110
122
|
moveLen = maxWidth - this.rightMinWidth;
|
|
111
123
|
}
|
|
112
|
-
|
|
113
|
-
|
|
124
|
+
// 拖动时更新 data 属性(响应式绑定到 :style),避免与模板样式冲突
|
|
125
|
+
this.leftWidth = (moveLen / maxWidth) * 100 + "%"; // 设置左边区域的宽度,通过换算为百分比的形式,实现窗体放大缩小自适应
|
|
126
|
+
this.rightWidth = ((maxWidth - moveLen) / maxWidth) * 100 + "%"; // 右边区域 = 总大小 - 左边宽度 - 拖动条宽度
|
|
114
127
|
};
|
|
115
128
|
document.onmouseup = () => {
|
|
116
129
|
document.onmousemove = null;
|
|
@@ -134,11 +147,12 @@ export default {
|
|
|
134
147
|
box-sizing: border-box;
|
|
135
148
|
}
|
|
136
149
|
.left {
|
|
137
|
-
|
|
150
|
+
flex-shrink: 0;
|
|
138
151
|
}
|
|
139
152
|
.resize {
|
|
140
153
|
position: relative;
|
|
141
154
|
width: 10px;
|
|
155
|
+
flex-shrink: 0;
|
|
142
156
|
cursor: col-resize;
|
|
143
157
|
background-size: cover;
|
|
144
158
|
background-position: center;
|
|
@@ -150,6 +164,6 @@ export default {
|
|
|
150
164
|
background-color: white;
|
|
151
165
|
}
|
|
152
166
|
.right {
|
|
153
|
-
|
|
167
|
+
flex-shrink: 0;
|
|
154
168
|
}
|
|
155
169
|
</style>
|