stellar-ui-plus 1.17.1 → 1.17.3

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.
@@ -108,6 +108,7 @@ const cmpBtnStyle = computed(() => {
108
108
  style.fontSize = 'var(--font-size-28, 28rpx)';
109
109
  break;
110
110
  }
111
+ console.log('getColor().steThemeColor', getColor().steThemeColor);
111
112
  // 背景色 & 字体色
112
113
  style = { ...style, ...utils.bg2style(props.background ? props.background : getColor().steThemeColor) };
113
114
  style.color = props.color;
@@ -224,6 +224,43 @@
224
224
  </div>
225
225
  </ste-popup>
226
226
  ```
227
+ #### 自定义组件
228
+
229
+ - 属性`weekendColor`用于设置周末日期颜色
230
+ - 属性`monthCount`用于设置渲染的月数
231
+ - 属性`signs`用于设置标记的日期
232
+
233
+ ```html
234
+ <script setup>
235
+ import { ref, reactive } from 'vue';
236
+ import type { SignType } from '@/uni_modules/stellar-ui-plus/components/ste-calendar/date';
237
+ import utils from '@/uni_modules/stellar-ui-plus/utils/utils';
238
+ const defaultDate = ref(utils.dayjs().format('YYYY-MM'));
239
+ const signs = reactive<{ [key: string]: SignType }>({
240
+ // 标记今天
241
+ [utils.dayjs().format('YYYY-MM-DD')]: [
242
+ { content: 'XXXXX', className: 'test-signs' },
243
+ { content: 'XXXXX', className: 'test-signs' },
244
+ { content: 'XXXXX', className: 'test-signs' },
245
+ ],
246
+ // 标记明天
247
+ [utils.dayjs(Date.now() + 1000 * 60 * 60 * 24).format('YYYY-MM-DD')]: [
248
+ { content: 'XXXXX', style: { color: '#666', background: '#f5f5f5' } },
249
+ { content: 'XXXXX', style: { color: '#666', background: '#f5f5f5' } },
250
+ ],
251
+ });
252
+ </script>
253
+ <template>
254
+ <ste-select mode="month" v-model="defaultDate" width="200" options-width="420" border-color="transparency">
255
+ <template v-slot:icon>
256
+ <ste-icon code="&#xe699;"></ste-icon>
257
+ </template>
258
+ </ste-select>
259
+
260
+ <ste-calendar @select="handleConfirm" weekendColor="#999" color="#09f" :signs="signs" :defaultDate="defaultDate"
261
+ :monthCount="1" :showConfirm="false" :showTitle="false" />
262
+ </template>
263
+ ```
227
264
 
228
265
  ---$
229
266
 
@@ -1,11 +1,18 @@
1
1
  import utils from '../../utils/utils'
2
2
  import type { Dayjs } from '../../types/index'
3
+ import type { CSSProperties } from 'vue'
4
+
5
+ export type SignType = { content: string, style?: CSSProperties, className?: string, key?: number }[]
6
+
3
7
 
4
8
  export interface WeekType {
5
9
  dayText: string | number
6
10
  key: string | number
7
11
  disabled: boolean
8
12
  weekend: boolean
13
+ today: boolean
14
+ date: string | number | null
15
+ signs: SignType | null
9
16
  }
10
17
 
11
18
  export interface MonthType {
@@ -21,8 +28,9 @@ export type DateType = string | number | Dayjs | Date
21
28
  /**
22
29
  * 获取从当前月份开始的12个月
23
30
  */
24
- function getMonthList(minDate?: DateType, maxDate?: DateType) {
25
- const start = minDate ? utils.dayjs(minDate) : utils.dayjs()
31
+ function getMonthList(minDate?: DateType, maxDate?: DateType, defaultDate?: DateType, monthCount?: number) {
32
+ if (maxDate) monthCount = 12;
33
+ const start = minDate ? utils.dayjs(minDate) : utils.dayjs(defaultDate)
26
34
  const sY = Number(start.format('YYYY'))
27
35
  const sM = Number(start.format('MM'))
28
36
  const end = maxDate ? utils.dayjs(maxDate) : null
@@ -30,10 +38,9 @@ function getMonthList(minDate?: DateType, maxDate?: DateType) {
30
38
  if (end) {
31
39
  eY = Number(end.format('YYYY'))
32
40
  eM = Number(end.format('MM'))
33
- }
34
- else {
35
- eY = sM + 11 > 12 ? sY + 1 : sY
36
- eM = sM + 11 > 12 ? sM + 11 - 12 : sM + 11
41
+ } else {
42
+ eY = sM + Number(monthCount) - 1 > 12 ? sY + 1 : sY
43
+ eM = sM + Number(monthCount) - 1 > 12 ? sM + Number(monthCount) - 1 - 12 : sM + Number(monthCount) - 1
37
44
  }
38
45
  const months = []
39
46
  for (let y = sY; y <= eY; y++) {
@@ -57,9 +64,10 @@ export function getMonthDays(year: number, month: number) {
57
64
  /**
58
65
  * 获取日历数据
59
66
  */
60
- export function getCalendarData(minDate?: DateType, maxDate?: DateType, formatter = 'YYYY-MM-DD') {
67
+ export function getCalendarData(minDate?: DateType, maxDate?: DateType, defaultDate?: DateType, monthCount = 12, formatter = 'YYYY-MM-DD', signs: { [key: string]: SignType } = {}) {
61
68
  const monthDatas: MonthType[] = []
62
- const months = getMonthList(minDate, maxDate)
69
+ const months = getMonthList(minDate, maxDate, defaultDate, monthCount)
70
+ const today = utils.dayjs().format('YYYY-MM-DD');
63
71
  months.forEach((date) => {
64
72
  const daysCount = getMonthDays(date.year(), date.month())
65
73
  // 一号的星期
@@ -78,21 +86,28 @@ export function getCalendarData(minDate?: DateType, maxDate?: DateType, formatte
78
86
  const week = []
79
87
  for (let d = 0; d < 7; d++) {
80
88
  let _day
81
- if ((w === 0 && d < firstDay) || day > daysCount)
82
- _day = ''
83
- else
84
- _day = day++
85
-
89
+ if ((w === 0 && d < firstDay) || day > daysCount) _day = ''
90
+ else _day = day++
86
91
  const key = _day ? utils.dayjs(`${monthData.key}-${_day}`).format(formatter) : Math.random()
87
92
  let disabled = !_day
88
93
  if (_day)
89
94
  disabled = Boolean((minDate && key < minDate) || (maxDate && key > maxDate))
90
95
 
96
+ const daySigns = _day && signs && signs[key] ? signs[key].slice(0, 3).map(item => ({
97
+ ...item,
98
+ key: Math.random()
99
+ })) : null;
100
+
101
+
91
102
  week.push({
92
103
  dayText: _day,
93
104
  key,
94
105
  disabled,
95
106
  weekend: d === 0 || d === 6,
107
+ // 是否是今天
108
+ today: Boolean(_day && today === key),
109
+ date: _day ? key : null,
110
+ signs: daySigns,
96
111
  })
97
112
  }
98
113
  monthData.weeks.push(week)
@@ -1,5 +1,5 @@
1
1
  import type { PropType } from 'vue'
2
- import type { DateType } from './date'
2
+ import type { DateType, SignType } from './date'
3
3
 
4
4
  export default {
5
5
  title: { type: String, default: () => '日期选择' },
@@ -11,7 +11,6 @@ export default {
11
11
  color: { type: String, default: () => '' },
12
12
  minDate: { type: [String, Number, Date], default: () => 0 },
13
13
  maxDate: { type: [String, Number, Date], default: () => 0 },
14
- defaultMonth: { type: [Number, String, Date], default: () => 0 },
15
14
  maxCount: { type: [Number, String], default: () => 0 },
16
15
  formatter: { type: String, default: () => 'YYYY-MM-DD' },
17
16
  showMark: { type: Boolean, default: () => true },
@@ -23,4 +22,8 @@ export default {
23
22
  showConfirm: { type: Boolean, default: () => true },
24
23
  width: { type: [Number, String], default: () => '100%' },
25
24
  height: { type: [Number, String], default: () => '100%' },
25
+ signs: { type: Object as PropType<{ [key: string]: SignType }>, default: () => ({}) },
26
+ defaultDate: { type: [String, Number, Date], default: () => 0 },
27
+ monthCount: { type: Number, default: () => 12 },
28
+ weekendColor: { type: String, default: () => '' },
26
29
  }
@@ -72,12 +72,6 @@
72
72
  "type": "number | string | Date",
73
73
  "default": 0
74
74
  },
75
- {
76
- "name": "defaultMonth",
77
- "description": "默认展示的月份",
78
- "type": "number | string | Date",
79
- "default": 0
80
- },
81
75
  {
82
76
  "name": "maxCount",
83
77
  "description": "mode=multiple时,最多可选多少个日期",
@@ -142,6 +136,30 @@
142
136
  "type": "number | string",
143
137
  "default": "100%"
144
138
  },
139
+ {
140
+ "name": "defaultDate",
141
+ "description": "默认展示的日期",
142
+ "type": "number | string | Date",
143
+ "default": "今天"
144
+ },
145
+ {
146
+ "name": "monthCount",
147
+ "description": "渲染的月份个数",
148
+ "type": "number",
149
+ "default": 12
150
+ },
151
+ {
152
+ "name": "weekendColor",
153
+ "description": "周末颜色,默认跟随主题色",
154
+ "type": "string",
155
+ "default": ""
156
+ },
157
+ {
158
+ "name": "signs",
159
+ "description": "日历标签",
160
+ "type": "{[key:string]:SignType}",
161
+ "default": "{}"
162
+ },
145
163
  {
146
164
  "name": "[event]select",
147
165
  "description": "选择日期时触发",
@@ -167,6 +185,17 @@
167
185
  "description": "当前选中的日期列表"
168
186
  }
169
187
  ]
188
+ },
189
+ {
190
+ "name": "[event]view-month",
191
+ "description": "页面展示月份发生变化时触发",
192
+ "type": "(month:string) => void",
193
+ "params": [
194
+ {
195
+ "name": "month",
196
+ "description": "当前页面上显示的月份"
197
+ }
198
+ ]
170
199
  }
171
200
  ]
172
- }
201
+ }