wl-design-mobile 0.7.3 → 0.7.5

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # wl-design-mobile
2
-
3
- ## Setup
4
- ```
5
- npm i wl-design-mobile
6
- ```
1
+ # wl-design-mobile
2
+
3
+ ## Setup
4
+ ```
5
+ npm i wl-design-mobile
6
+ ```
@@ -1,3 +1,3 @@
1
- .img-upload-container {
2
- padding: 0px 14px 12px 14px;
3
- }
1
+ .img-upload-container {
2
+ padding: 0px 14px 12px 14px;
3
+ }
@@ -1,39 +1,39 @@
1
- .coll-div {
2
- margin-bottom: 8px;
3
- }
4
-
5
- .indicator-title {
6
- display: flex;
7
- align-items: center;
8
- color: var(--scl-blue);
9
- font-size: 14px;
10
- font-family: 微软雅黑, serif Regular;
11
- }
12
-
13
- .indicator-title .color-line {
14
- width: 3px;
15
- height: 14px;
16
- margin-right: 8px;
17
- }
18
-
19
- .coll-title-icon {
20
- justify-content: center;
21
- align-items: center;
22
- align-content: center;
23
- }
24
-
25
- /* 覆盖折叠面板的标题的padding */
26
- /deep/ .van-cell {
27
- padding: 12px 10px;
28
- }
29
-
30
- /* 覆盖去掉折叠面板的标题下面的线 */
31
- /deep/ .van-cell::after {
32
- border: none;
33
- }
34
-
35
- /* 覆盖折叠面板的内容的padding */
36
- /deep/ .van-collapse-item__content {
37
- padding: 0px 0px 0px 0px;
38
- }
39
-
1
+ .coll-div {
2
+ margin-bottom: 8px;
3
+ }
4
+
5
+ .indicator-title {
6
+ display: flex;
7
+ align-items: center;
8
+ color: var(--scl-blue);
9
+ font-size: 14px;
10
+ font-family: 微软雅黑, serif Regular;
11
+ }
12
+
13
+ .indicator-title .color-line {
14
+ width: 3px;
15
+ height: 14px;
16
+ margin-right: 8px;
17
+ }
18
+
19
+ .coll-title-icon {
20
+ justify-content: center;
21
+ align-items: center;
22
+ align-content: center;
23
+ }
24
+
25
+ /* 覆盖折叠面板的标题的padding */
26
+ /deep/ .van-cell {
27
+ padding: 12px 10px;
28
+ }
29
+
30
+ /* 覆盖去掉折叠面板的标题下面的线 */
31
+ /deep/ .van-cell::after {
32
+ border: none;
33
+ }
34
+
35
+ /* 覆盖折叠面板的内容的padding */
36
+ /deep/ .van-collapse-item__content {
37
+ padding: 0px 0px 0px 0px;
38
+ }
39
+
@@ -47,7 +47,7 @@
47
47
  border: none;
48
48
  outline: none;
49
49
  background: none;
50
- font-size: 14px;
50
+ font-size: 16px;
51
51
  color: var(--scl-gray-5);
52
52
  display: flex;
53
53
  justify-content: flex-start;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wl-design-mobile",
3
- "version": "0.7.3",
3
+ "version": "0.7.5",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "finch",
@@ -29,23 +29,23 @@ export default {
29
29
 
30
30
  data() {
31
31
  return {
32
- selectedDate_: new Date(),
33
- weekStart: null,
34
- startX: 0,
35
- endX: 0,
36
- isDragging: false,
37
- swipeThreshold: 50,
38
- clickDisabled: false,
39
- // 模拟数据存储,实际项目中可能从接口获取
40
- dataDates: new Set()
32
+ selectedDate_: new Date(), // 当前选中的日期(Date对象),用于判断选中状态
33
+ weekStart: null, // 当前周的开始日期(周一)
34
+ startX: 0, // 触摸/鼠标起始X坐标
35
+ endX: 0, // 触摸/鼠标结束X坐标
36
+ isDragging: false, // 是否正在拖动
37
+ swipeThreshold: 50, // 滑动阈值(像素),超过这个值才触发切换周
38
+ clickDisabled: false, // 是否禁用点击(滑动后禁用点击,避免触发日期选择)
39
+ dataDates: new Set() // 有数据的日期集合(用于显示红点)
41
40
  }
42
41
  },
43
42
  props: {
43
+ // 选中的日期(格式:yyyyMMDD),为空时使用今天
44
44
  selectedDate: {
45
45
  type: String,
46
46
  default: ""
47
47
  },
48
- // 新增props:传入有数据的日期列表
48
+ // 有数据的日期列表
49
49
  dataDatesList: {
50
50
  type: Array,
51
51
  default: () => []
@@ -74,6 +74,15 @@ export default {
74
74
  this.$forceUpdate();
75
75
  },
76
76
  deep: true
77
+ },
78
+ // 监听选中日期变化
79
+ selectedDate: {
80
+ handler(newDate) {
81
+ if (newDate) {
82
+ this.initWithWeekDate(newDate);
83
+ this.$forceUpdate();
84
+ }
85
+ }
77
86
  }
78
87
  },
79
88
 
@@ -100,6 +109,22 @@ export default {
100
109
  },
101
110
 
102
111
  methods: {
112
+ /**
113
+ * 获取当前周的开始和结束日期
114
+ * @returns {Object} 包含 weekStart 和 weekEnd 的对象
115
+ */
116
+ getWeekRange() {
117
+ const weekStartDate = this.formatDateToYYYYMMDD(this.weekStart);
118
+ const weekEndDateObj = new Date(this.weekStart);
119
+ weekEndDateObj.setDate(this.weekStart.getDate() + 6);
120
+ const weekEndDate = this.formatDateToYYYYMMDD(weekEndDateObj);
121
+
122
+ return {
123
+ weekStart: weekStartDate,
124
+ weekEnd: weekEndDate
125
+ };
126
+ },
127
+
103
128
  /**
104
129
  * 初始化数据日期集合
105
130
  * @param {Array} dateList - 日期字符串数组,格式:["20241205", "20241206"]
@@ -124,14 +149,12 @@ export default {
124
149
  const date = this.parseYYYYMMDD(dateFormat);
125
150
 
126
151
  if (date) {
127
- console.log("根据传入日期初始化:", dateFormat);
128
152
  this.setWeekStart(date);
129
- this.selectedDate_ = new Date(date);
153
+ this.selectedDate_ = date;
130
154
  } else {
131
- console.log("日期解析失败,使用今天");
132
155
  const today = new Date();
133
156
  this.setWeekStart(today);
134
- this.selectedDate_ = new Date(today);
157
+ this.selectedDate_ = today;
135
158
  }
136
159
  },
137
160
 
@@ -167,6 +190,10 @@ export default {
167
190
  }
168
191
  },
169
192
 
193
+ /**
194
+ * 设置周起始日期(周一)
195
+ * @param {Date} date - 任意日期
196
+ */
170
197
  setWeekStart(date) {
171
198
  const d = new Date(date);
172
199
  const day = d.getDay();
@@ -176,11 +203,22 @@ export default {
176
203
  this.weekStart = d;
177
204
  },
178
205
 
206
+ /**
207
+ * 判断两个日期是否是同一天
208
+ * @param {Date} d1 - 日期1
209
+ * @param {Date} d2 - 日期2
210
+ * @returns {boolean} 是否是同一天
211
+ */
179
212
  isSameDay(d1, d2) {
180
213
  if (!d1 || !d2) return false;
181
214
  return d1.toDateString() === d2.toDateString();
182
215
  },
183
216
 
217
+ /**
218
+ * 格式化日期为 YYYYMMDD 字符串
219
+ * @param {Date} date - 日期对象
220
+ * @returns {string} 格式化后的日期字符串
221
+ */
184
222
  formatDateToYYYYMMDD(date) {
185
223
  const year = date.getFullYear();
186
224
  const month = (date.getMonth() + 1).toString().padStart(2, '0');
@@ -188,6 +226,10 @@ export default {
188
226
  return `${year}${month}${day}`;
189
227
  },
190
228
 
229
+ /**
230
+ * 选择日期
231
+ * @param {Object} day - 日期对象(包含 date 属性)
232
+ */
191
233
  selectDay(day) {
192
234
  if (this.clickDisabled) {
193
235
  this.clickDisabled = false;
@@ -195,25 +237,41 @@ export default {
195
237
  }
196
238
  this.selectedDate_ = new Date(day.date);
197
239
  const clickDate = this.formatDateToYYYYMMDD(this.selectedDate_);
198
- console.log('选中的日期:', clickDate);
199
- // 触发自定义事件,传递YYYYMMDD格式的日期
200
240
  this.$emit('click', clickDate);
201
241
  },
202
242
 
243
+ /**
244
+ * 切换到上一周
245
+ */
203
246
  goPrevWeek() {
204
- console.log('-- goPrevWeek --')
205
247
  const newWeekStart = new Date(this.weekStart);
206
248
  newWeekStart.setDate(this.weekStart.getDate() - 7);
207
249
  this.setWeekStart(newWeekStart);
250
+ this.emitWeekChange();
208
251
  },
209
252
 
253
+ /**
254
+ * 切换到下一周
255
+ */
210
256
  goNextWeek() {
211
- console.log('-- goNextWeek --')
212
257
  const newWeekStart = new Date(this.weekStart);
213
258
  newWeekStart.setDate(this.weekStart.getDate() + 7);
214
259
  this.setWeekStart(newWeekStart);
260
+ this.emitWeekChange();
261
+ },
262
+
263
+ /**
264
+ * 触发周变化事件
265
+ */
266
+ emitWeekChange() {
267
+ const weekRange = this.getWeekRange();
268
+ this.$emit('on-week-change', weekRange);
215
269
  },
216
270
 
271
+ /**
272
+ * 触摸开始事件
273
+ * @param {TouchEvent} e - 触摸事件
274
+ */
217
275
  handleTouchStart(e) {
218
276
  this.startX = e.touches[0].clientX;
219
277
  this.endX = this.startX;
@@ -221,11 +279,18 @@ export default {
221
279
  this.clickDisabled = false;
222
280
  },
223
281
 
282
+ /**
283
+ * 触摸移动事件
284
+ * @param {TouchEvent} e - 触摸事件
285
+ */
224
286
  handleTouchMove(e) {
225
287
  if (!this.isDragging) return;
226
288
  this.endX = e.touches[0].clientX;
227
289
  },
228
290
 
291
+ /**
292
+ * 触摸结束事件
293
+ */
229
294
  handleTouchEnd() {
230
295
  if (!this.isDragging) return;
231
296
 
@@ -235,6 +300,10 @@ export default {
235
300
  this.isDragging = false;
236
301
  },
237
302
 
303
+ /**
304
+ * 鼠标按下事件
305
+ * @param {MouseEvent} e - 鼠标事件
306
+ */
238
307
  handleMouseDown(e) {
239
308
  this.startX = e.clientX;
240
309
  this.endX = this.startX;
@@ -242,11 +311,18 @@ export default {
242
311
  this.clickDisabled = false;
243
312
  },
244
313
 
314
+ /**
315
+ * 鼠标移动事件
316
+ * @param {MouseEvent} e - 鼠标事件
317
+ */
245
318
  handleMouseMove(e) {
246
319
  if (!this.isDragging) return;
247
320
  this.endX = e.clientX;
248
321
  },
249
322
 
323
+ /**
324
+ * 鼠标松开事件
325
+ */
250
326
  handleMouseUp() {
251
327
  if (!this.isDragging) return;
252
328
 
@@ -256,10 +332,17 @@ export default {
256
332
  this.isDragging = false;
257
333
  },
258
334
 
335
+ /**
336
+ * 鼠标离开事件
337
+ */
259
338
  handleMouseLeave() {
260
339
  this.isDragging = false;
261
340
  },
262
341
 
342
+ /**
343
+ * 处理滑动操作
344
+ * @param {number} deltaX - 滑动距离(正值向左滑,负值向右滑)
345
+ */
263
346
  handleSwipe(deltaX) {
264
347
  if (Math.abs(deltaX) > this.swipeThreshold) {
265
348
  this.clickDisabled = true;
package/util/assist.js CHANGED
@@ -1,43 +1,43 @@
1
- // 深拷贝
2
- export function deepCopy(data) {
3
- let i;
4
- const t = typeOf(data);
5
- let o;
6
-
7
- if (t === 'array') {
8
- o = [];
9
- } else if (t === 'object') {
10
- o = {};
11
- } else {
12
- return data;
13
- }
14
-
15
- if (t === 'array') {
16
- for (i = 0; i < data.length; i++) {
17
- o.push(deepCopy(data[i]));
18
- }
19
- } else if (t === 'object') {
20
- for (i in data) {
21
- o[i] = deepCopy(data[i]);
22
- }
23
- }
24
- return o;
25
- }
26
-
27
- // 判断对象类型
28
- export function typeOf(obj) {
29
- const toString = Object.prototype.toString;
30
- const map = {
31
- '[object Boolean]': 'boolean',
32
- '[object Number]': 'number',
33
- '[object String]': 'string',
34
- '[object Function]': 'function',
35
- '[object Array]': 'array',
36
- '[object Date]': 'date',
37
- '[object RegExp]': 'regExp',
38
- '[object Undefined]': 'undefined',
39
- '[object Null]': 'null',
40
- '[object Object]': 'object'
41
- };
42
- return map[toString.call(obj)];
43
- }
1
+ // 深拷贝
2
+ export function deepCopy(data) {
3
+ let i;
4
+ const t = typeOf(data);
5
+ let o;
6
+
7
+ if (t === 'array') {
8
+ o = [];
9
+ } else if (t === 'object') {
10
+ o = {};
11
+ } else {
12
+ return data;
13
+ }
14
+
15
+ if (t === 'array') {
16
+ for (i = 0; i < data.length; i++) {
17
+ o.push(deepCopy(data[i]));
18
+ }
19
+ } else if (t === 'object') {
20
+ for (i in data) {
21
+ o[i] = deepCopy(data[i]);
22
+ }
23
+ }
24
+ return o;
25
+ }
26
+
27
+ // 判断对象类型
28
+ export function typeOf(obj) {
29
+ const toString = Object.prototype.toString;
30
+ const map = {
31
+ '[object Boolean]': 'boolean',
32
+ '[object Number]': 'number',
33
+ '[object String]': 'string',
34
+ '[object Function]': 'function',
35
+ '[object Array]': 'array',
36
+ '[object Date]': 'date',
37
+ '[object RegExp]': 'regExp',
38
+ '[object Undefined]': 'undefined',
39
+ '[object Null]': 'null',
40
+ '[object Object]': 'object'
41
+ };
42
+ return map[toString.call(obj)];
43
+ }
package/util/bus.js CHANGED
@@ -1,4 +1,4 @@
1
- import Vue from 'vue'
2
-
3
- const Bus = new Vue();
4
- export default Bus;
1
+ import Vue from 'vue'
2
+
3
+ const Bus = new Vue();
4
+ export default Bus;