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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zydx-plus",
3
- "version": "1.35.635",
3
+ "version": "1.35.637",
4
4
  "description": "Vue.js",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -46,73 +46,71 @@ export default {
46
46
  watch: {
47
47
  isShowsRight() {
48
48
  this.$nextTick(() => {
49
- if (this.isShowsRight) {
50
- this.resetWidth()
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
- if (this.isShowsLeft) {
60
- this.resetWidth()
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
- 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
- }
61
+ // 由 props 与可见性直接计算初始宽度,保证首屏渲染即为正确宽度,避免闪动
62
+ return this.getInitWidth()
83
63
  },
84
64
  mounted() {
85
65
  this.handleResize()
86
66
  },
87
67
  methods: {
88
- // props 重新计算左右初始宽度(供显示切换/外部调用)
89
- resetWidth() {
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
- this.leftWidth = lw + '%'
94
- this.rightWidth = (100 - lw) + '%'
95
- } else {
96
- this.leftWidth = w + 'px'
97
- this.rightWidth = `calc(100% - ${w}px - 10px)`
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
- leftDom = this.$refs.leftRef,
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
- const startX = e.clientX; // 记录坐标起始位置
112
- const startLeft = leftDom.offsetWidth; // 左边元素起始宽度
103
+ e.preventDefault()
104
+ // 记录按下瞬间分隔条位置,计算鼠标相对分隔条左边缘的抓取偏移
105
+ const handleRect = resizeDom.parentElement.getBoundingClientRect()
106
+ const grabOffset = e.clientX - handleRect.left
113
107
  document.onmousemove = e => {
114
- const endX = e.clientX; // 鼠标拖动的终止位置
115
- let moveLen = startLeft + (endX - startX); // 移动的距离 = endX - startX,左边区域最后的宽度 = startLeft + 移动的距离
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
- // 拖动时更新 data 属性(响应式绑定到 :style),避免与模板样式冲突
125
- this.leftWidth = (moveLen / maxWidth) * 100 + "%"; // 设置左边区域的宽度,通过换算为百分比的形式,实现窗体放大缩小自适应
126
- this.rightWidth = ((maxWidth - moveLen) / maxWidth) * 100 + "%"; // 右边区域 = 总大小 - 左边宽度 - 拖动条宽度
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;
package/src/index.js CHANGED
@@ -87,7 +87,7 @@ function install(app) {
87
87
  }
88
88
 
89
89
  export default {
90
- version: '1.35.635',
90
+ version: '1.35.637',
91
91
  install,
92
92
  Calendar,
93
93
  Message,