zydx-plus 1.35.633 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zydx-plus",
3
- "version": "1.35.633",
3
+ "version": "1.35.635",
4
4
  "description": "Vue.js",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -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
- handler: function (v) {
49
- setTimeout(() => {
50
- if (this.isShowsRight) {
51
- this.handleResize()
52
- } else {
53
- this.$refs.leftRef.style.width = '100%'
54
- }
55
- }, 200)
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
- handler: function (v) {
62
- setTimeout(() => {
63
- if (this.isShowsLeft) {
64
- this.handleResize()
65
- } else {
66
- this.$refs.rightRef.style.width = '100%'
67
- }
68
- }, 200)
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
- return {};
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,
@@ -84,21 +104,15 @@ export default {
84
104
  resizeDom = this.$refs.resizeRef,
85
105
  rightDom = this.$refs.rightRef;
86
106
  if (resizeDom) {
87
- const maxWidth = boxDom.clientWidth - resizeDom.offsetWidth; // 左右两边区域的总宽度 = 外层容器宽度 - 中间区域拖拉框的宽度
88
- leftDom.style.width = `${this.isPercent?
89
- this.leftInitWidth<=0||this.leftInitWidth>=100 ? 30 : this.leftInitWidth
90
- : this.leftInitWidth}${this.isPercent? '%' : 'px'}`
91
- rightDom.style.width = `${this.isPercent?
92
- this.leftInitWidth<=0||this.leftInitWidth>=100 ? 70 : 100-this.leftInitWidth
93
- : maxWidth-this.leftInitWidth}${this.isPercent? '%' : 'px'}`
94
- /*leftDom.style.width = '50%'
95
- rightDom.style.width = '50%'*/
107
+ // 使用 .resize div 的实际宽度(10px)而非 img 宽度(30px),避免拖动位置偏左
108
+ const resizeWidth = resizeDom.parentElement.offsetWidth
109
+ const maxWidth = boxDom.clientWidth - resizeWidth; // 左右两边区域的总宽度 = 外层容器宽度 - 中间区域拖拉框的宽度
96
110
  resizeDom.onmousedown = e => {
97
111
  const startX = e.clientX; // 记录坐标起始位置
98
- leftDom.left = leftDom.offsetWidth; // 左边元素起始宽度
112
+ const startLeft = leftDom.offsetWidth; // 左边元素起始宽度
99
113
  document.onmousemove = e => {
100
114
  const endX = e.clientX; // 鼠标拖动的终止位置
101
- let moveLen = leftDom.left + (endX - startX); // 移动的距离 = endX - startX,左边区域最后的宽度 = resizeDom.left + 移动的距离
115
+ let moveLen = startLeft + (endX - startX); // 移动的距离 = endX - startX,左边区域最后的宽度 = startLeft + 移动的距离
102
116
  // 限制左边区域的最小宽度为 leftMinWidth
103
117
  if (moveLen < this.leftMinWidth) {
104
118
  moveLen = this.leftMinWidth;
@@ -107,8 +121,9 @@ export default {
107
121
  if (moveLen > maxWidth - this.rightMinWidth) {
108
122
  moveLen = maxWidth - this.rightMinWidth;
109
123
  }
110
- leftDom.style.width = (moveLen / maxWidth) * 100 + "%"; // 设置左边区域的宽度,通过换算为百分比的形式,实现窗体放大缩小自适应
111
- rightDom.style.width = ((maxWidth - moveLen) / maxWidth) * 100 + "%"; // 右边区域 = 总大小 - 左边宽度 - 拖动条宽度
124
+ // 拖动时更新 data 属性(响应式绑定到 :style),避免与模板样式冲突
125
+ this.leftWidth = (moveLen / maxWidth) * 100 + "%"; // 设置左边区域的宽度,通过换算为百分比的形式,实现窗体放大缩小自适应
126
+ this.rightWidth = ((maxWidth - moveLen) / maxWidth) * 100 + "%"; // 右边区域 = 总大小 - 左边宽度 - 拖动条宽度
112
127
  };
113
128
  document.onmouseup = () => {
114
129
  document.onmousemove = null;
@@ -132,11 +147,12 @@ export default {
132
147
  box-sizing: border-box;
133
148
  }
134
149
  .left {
135
- width: 50%;
150
+ flex-shrink: 0;
136
151
  }
137
152
  .resize {
138
153
  position: relative;
139
154
  width: 10px;
155
+ flex-shrink: 0;
140
156
  cursor: col-resize;
141
157
  background-size: cover;
142
158
  background-position: center;
@@ -148,6 +164,6 @@ export default {
148
164
  background-color: white;
149
165
  }
150
166
  .right {
151
- width: 50%;
167
+ flex-shrink: 0;
152
168
  }
153
169
  </style>
package/src/index.js CHANGED
@@ -87,7 +87,7 @@ function install(app) {
87
87
  }
88
88
 
89
89
  export default {
90
- version: '1.35.633',
90
+ version: '1.35.635',
91
91
  install,
92
92
  Calendar,
93
93
  Message,