uview-pro 0.2.0 → 0.2.1

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/changelog.md CHANGED
@@ -1,3 +1,25 @@
1
+ ## 0.2.1(2025-09-29)
2
+
3
+ ### 🚀 Chore | 构建/工程依赖/工具
4
+
5
+ - 优化代码格式化和 ESLint 配置 ([771eacd](https://github.com/anyup/uView-Pro/commit/771eacd58d410e468a8aec4225bbe7b402480b2f))
6
+
7
+ ### ⚡ Performance Improvements | 性能优化
8
+
9
+ - 压缩部分js工具库 ([6615b70](https://github.com/anyup/uView-Pro/commit/6615b7085a51c4fbc9f884ec68e05db1a1e89e27))
10
+
11
+ ### ✨ Features | 新功能
12
+
13
+ - **u-calendar:** 日历组件增加农历显示功能 ([e2368ac](https://github.com/anyup/uView-Pro/commit/e2368ac88b0abb4493ab12a1785eb2a0e38e502c))
14
+
15
+ ### ♻️ Code Refactoring | 代码重构
16
+
17
+ - **calendar:** 重构日历组件类型定义 ([0040e9e](https://github.com/anyup/uView-Pro/commit/0040e9e1095446536370e9aca3c135bc05527acb))
18
+
19
+ ### 🐛 Bug Fixes | Bug 修复
20
+
21
+ - **u-input:** 修复输入框禁用状态时清空按钮仍显示的问题 ([722715f](https://github.com/anyup/uView-Pro/commit/722715f7d6607584c0e158ba2de2342147e3be17))
22
+
1
23
  ## 0.2.0(2025-09-28)
2
24
 
3
25
  ### ♻️ Code Refactoring | 代码重构
@@ -1,11 +1,13 @@
1
1
  import { type ExtractPropTypes, type PropType } from 'vue';
2
- import type { CalendarMode, ThemeType } from '../../types/global';
2
+ import type { CalendarChangeDate, CalendarChangeRange, CalendarMode, ThemeType } from '../../types/global';
3
+ import { baseProps } from '../common/props';
3
4
 
4
5
  /**
5
6
  * calendar 日历类型定义
6
7
  * @description 供 u-calendar 组件 props 使用
7
8
  */
8
9
  export const CalendarProps = {
10
+ ...baseProps,
9
11
  /** 是否开启底部安全区适配 */
10
12
  safeAreaInsetBottom: { type: Boolean, default: false },
11
13
  /** 是否允许通过点击遮罩关闭Picker */
@@ -57,7 +59,15 @@ export const CalendarProps = {
57
59
  /** 是否显示右上角的关闭图标 */
58
60
  closeable: { type: Boolean, default: true },
59
61
  /** 顶部的提示文字 */
60
- toolTip: { type: String, default: '选择日期' }
62
+ toolTip: { type: String, default: '选择日期' },
63
+ /** 是否显示农历 */
64
+ showLunar: { type: Boolean, default: false }
61
65
  };
62
66
 
63
67
  export type CalendarProps = ExtractPropTypes<typeof CalendarProps>;
68
+
69
+ export type CalendarEmits = {
70
+ (e: 'update:modelValue', value: boolean): void;
71
+ (e: 'input', value: boolean): void;
72
+ (e: 'change', value: CalendarChangeDate | CalendarChangeRange): void;
73
+ };
@@ -11,7 +11,7 @@
11
11
  :border-radius="borderRadius"
12
12
  :closeable="closeable"
13
13
  >
14
- <view class="u-calendar">
14
+ <view class="u-calendar" :class="props.customClass" :style="$u.toStyle(customStyle)">
15
15
  <view class="u-calendar__header">
16
16
  <view class="u-calendar__header__text" v-if="!slots.tooltip">
17
17
  {{ toolTip }}
@@ -65,6 +65,17 @@
65
65
  <view class="u-calendar__content__item__tips" :style="{ color: activeColor }" v-if="mode == 'range' && endDate == `${year}-${month}-${index + 1}`">{{
66
66
  endText
67
67
  }}</view>
68
+ <view
69
+ v-if="
70
+ props.showLunar &&
71
+ !(mode == 'range' && startDate == `${year}-${month}-${index + 1}` && startDate != endDate) &&
72
+ !(mode == 'range' && endDate == `${year}-${month}-${index + 1}`)
73
+ "
74
+ class="u-calendar__content__item__tips"
75
+ :style="{ color: getColor(index, 2) }"
76
+ >
77
+ {{ lunarArr[index]?.dayCn === '初一' ? lunarArr[index].monthCn : (lunarArr[index]?.dayCn ?? '') }}
78
+ </view>
68
79
  </view>
69
80
  <view class="u-calendar__content__bg-month">{{ month }}</view>
70
81
  </view>
@@ -84,7 +95,8 @@
84
95
  <script setup lang="ts">
85
96
  import { ref, computed, watch, onMounted, useSlots } from 'vue';
86
97
  import { $u } from '../..';
87
- import { CalendarProps } from './types';
98
+ import { CalendarProps, type CalendarEmits } from './types';
99
+ import Calendar from '../../libs/util/calendar';
88
100
 
89
101
  defineOptions({
90
102
  name: 'u-calendar'
@@ -121,7 +133,7 @@ defineOptions({
121
133
  */
122
134
 
123
135
  const props = defineProps(CalendarProps);
124
- const emit = defineEmits(['update:modelValue', 'input', 'change']);
136
+ const emit = defineEmits<CalendarEmits>();
125
137
  const slots = useSlots();
126
138
 
127
139
  // 组件内部状态
@@ -130,6 +142,7 @@ const weekday = ref(1);
130
142
  const weekdayArr = ref<number[]>([]);
131
143
  const days = ref(0);
132
144
  const daysArr = ref<number[]>([]);
145
+ const lunarArr = ref<any[]>([]);
133
146
  const showTitle = ref('');
134
147
  const year = ref(2020);
135
148
  const month = ref(0);
@@ -151,6 +164,7 @@ const max = ref<{ year: number; month: number; day: number } | null>(null);
151
164
  const weekDayZh = ref(['日', '一', '二', '三', '四', '五', '六']);
152
165
 
153
166
  const dataChange = computed(() => `${props.mode}-${props.minDate}-${props.maxDate}`);
167
+ const lunarChange = computed(() => props.showLunar);
154
168
  // 如果用户有传递z-index值,优先使用
155
169
  const uZIndex = computed(() => (props.zIndex ? props.zIndex : $u.zIndex.popup));
156
170
  const popupValue = computed({
@@ -158,7 +172,7 @@ const popupValue = computed({
158
172
  set: (val: boolean) => emit('update:modelValue', val)
159
173
  });
160
174
 
161
- watch(dataChange, () => {
175
+ watch([dataChange, lunarChange], () => {
162
176
  init();
163
177
  });
164
178
 
@@ -327,11 +341,33 @@ function changeData() {
327
341
  weekday.value = getWeekday(year.value, month.value);
328
342
  weekdayArr.value = generateArray(1, weekday.value);
329
343
  showTitle.value = `${year.value}年${month.value}月`;
344
+ if (props.showLunar) {
345
+ lunarArr.value = [];
346
+ daysArr.value.forEach(d => {
347
+ lunarArr.value.push(getLunar(year.value, month.value, d));
348
+ });
349
+ }
330
350
  if (props.isChange && props.mode == 'date') {
331
351
  btnFix(true);
332
352
  }
333
353
  }
334
354
 
355
+ /**
356
+ * 获取农历
357
+ */
358
+ function getLunar(year, month, day) {
359
+ const val = Calendar.solar2lunar(year, month, day);
360
+ return {
361
+ dayCn: val.IDayCn,
362
+ weekCn: val.ncWeek,
363
+ monthCn: val.IMonthCn,
364
+ day: val.lDay,
365
+ week: val.nWeek,
366
+ month: val.lMonth,
367
+ year: val.lYear
368
+ };
369
+ }
370
+
335
371
  /**
336
372
  * 日期点击事件
337
373
  */
@@ -403,6 +439,7 @@ function btnFix(show: boolean) {
403
439
  // 今天
404
440
  isToday = true;
405
441
  }
442
+ const lunar = props.showLunar ? getLunar(y, m, d) : null;
406
443
  emit('change', {
407
444
  year: y,
408
445
  month: m,
@@ -410,7 +447,8 @@ function btnFix(show: boolean) {
410
447
  days: daysNum,
411
448
  result: result,
412
449
  week: weekText,
413
- isToday: isToday
450
+ isToday: isToday,
451
+ lunar: lunar
414
452
  // switch: show //是否是切换年月操作
415
453
  });
416
454
  } else {
@@ -423,6 +461,12 @@ function btnFix(show: boolean) {
423
461
  let endDayStr = formatNum(endDay.value);
424
462
  let endDateStr = `${endYear.value}-${endMonthStr}-${endDayStr}`;
425
463
  let endWeek = getWeekText(endDateStr);
464
+ let startLunar = null;
465
+ let endLunar = null;
466
+ if (props.showLunar) {
467
+ startLunar = getLunar(startYear.value, startMonth.value, startDay.value);
468
+ endLunar = getLunar(endYear.value, endMonth.value, endDay.value);
469
+ }
426
470
  emit('change', {
427
471
  startYear: startYear.value,
428
472
  startMonth: startMonth.value,
@@ -433,7 +477,9 @@ function btnFix(show: boolean) {
433
477
  endMonth: endMonth.value,
434
478
  endDay: endDay.value,
435
479
  endDate: endDateStr,
436
- endWeek: endWeek
480
+ endWeek: endWeek,
481
+ startLunar: startLunar,
482
+ endLunar: endLunar
437
483
  });
438
484
  }
439
485
  }
@@ -58,7 +58,7 @@
58
58
  @confirm="onConfirm"
59
59
  />
60
60
  <view class="u-input__right-icon u-flex">
61
- <view class="u-input__right-icon__clear u-input__right-icon__item" v-if="clearable && modelValue != ''">
61
+ <view class="u-input__right-icon__clear u-input__right-icon__item" v-if="clearable && modelValue != '' && !disabled">
62
62
  <u-icon size="32" name="close-circle-fill" color="#c0c4cc" @click="onClear" />
63
63
  </view>
64
64
  <view class="u-input__right-icon__clear u-input__right-icon__item" v-if="passwordIcon && type == 'password'">