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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zydx-plus",
3
- "version": "1.35.634",
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,
@@ -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
- leftDom.left = leftDom.offsetWidth; // 左边元素起始宽度
112
+ const startLeft = leftDom.offsetWidth; // 左边元素起始宽度
101
113
  document.onmousemove = e => {
102
114
  const endX = e.clientX; // 鼠标拖动的终止位置
103
- let moveLen = leftDom.left + (endX - startX); // 移动的距离 = endX - startX,左边区域最后的宽度 = resizeDom.left + 移动的距离
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
- leftDom.style.width = (moveLen / maxWidth) * 100 + "%"; // 设置左边区域的宽度,通过换算为百分比的形式,实现窗体放大缩小自适应
113
- rightDom.style.width = ((maxWidth - moveLen) / maxWidth) * 100 + "%"; // 右边区域 = 总大小 - 左边宽度 - 拖动条宽度
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
- width: 50%;
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
- width: 50%;
167
+ flex-shrink: 0;
154
168
  }
155
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.634',
90
+ version: '1.35.635',
91
91
  install,
92
92
  Calendar,
93
93
  Message,