wl-design-mobile 0.7.3 → 0.7.4
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/search/lambo-week-date-select.vue +101 -18
package/package.json
CHANGED
|
@@ -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
|
-
//
|
|
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_ =
|
|
153
|
+
this.selectedDate_ = date;
|
|
130
154
|
} else {
|
|
131
|
-
console.log("日期解析失败,使用今天");
|
|
132
155
|
const today = new Date();
|
|
133
156
|
this.setWeekStart(today);
|
|
134
|
-
this.selectedDate_ =
|
|
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;
|