stellar-ui-plus 1.20.1 → 1.20.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.
- package/components/ste-date-user/README.md +4 -0
- package/components/ste-date-user/config.json +1 -1
- package/components/ste-date-user/ste-date-user.vue +2 -1
- package/components/ste-filter-tool/README.md +6 -2
- package/components/ste-filter-tool/config.json +1 -1
- package/components/ste-filter-tool/ste-filter-tool.vue +67 -62
- package/components/ste-goods-info/ATTRIBUTES.md +1 -0
- package/components/ste-goods-info/README.md +23 -0
- package/components/ste-goods-info/config.json +1 -1
- package/components/ste-goods-info/props.ts +5 -0
- package/components/ste-goods-info/ste-goods-info.easycom.json +6 -0
- package/components/ste-goods-info/ste-goods-info.vue +14 -0
- package/components/ste-goods-list/config.json +1 -1
- package/components/ste-navbar/config.json +1 -1
- package/components/ste-navbar/ste-navbar.vue +0 -11
- package/components/ste-search-box/config.json +1 -1
- package/components/ste-search-box/ste-search-box.vue +6 -3
- package/components/ste-stepper/ste-stepper.vue +1 -0
- package/package.json +1 -4
- package/utils/time.ts +239 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { ref, defineComponent, onMounted } from 'vue';
|
|
3
|
-
import { getDateInfo } from '
|
|
3
|
+
import { getDateInfo } from '../../utils/time';
|
|
4
|
+
|
|
4
5
|
import propsData from './props';
|
|
5
6
|
defineComponent({
|
|
6
7
|
name: 'ste-date-user',
|
|
@@ -37,7 +37,9 @@
|
|
|
37
37
|
]);
|
|
38
38
|
</script>
|
|
39
39
|
<template>
|
|
40
|
-
<
|
|
40
|
+
<view style="width: 100%">
|
|
41
|
+
<ste-filter-tool :filterData="filterOptions" :menu-data="subFilters" @item-click="handleFilterClick" value="all" />
|
|
42
|
+
</view>
|
|
41
43
|
</template>
|
|
42
44
|
```
|
|
43
45
|
|
|
@@ -79,7 +81,9 @@
|
|
|
79
81
|
]);
|
|
80
82
|
</script>
|
|
81
83
|
<template>
|
|
82
|
-
<
|
|
84
|
+
<view style="width: 100%">
|
|
85
|
+
<ste-filter-tool :filterData="filterOptions2" :menu-data="subFilters2" @item-click="handleFilterClick" value="all" multiple />
|
|
86
|
+
</view>
|
|
83
87
|
</template>
|
|
84
88
|
```
|
|
85
89
|
|
|
@@ -199,83 +199,88 @@ const handleMenuConfirm = () => {
|
|
|
199
199
|
.filter-button {
|
|
200
200
|
margin-left: 16rpx;
|
|
201
201
|
color: #000;
|
|
202
|
+
|
|
203
|
+
// #ifndef MP-WEIXIN || MP-ALIPAY || APP
|
|
202
204
|
cursor: pointer;
|
|
205
|
+
// #endif
|
|
203
206
|
|
|
204
|
-
:deep(.filter-box-menu) {
|
|
205
|
-
.custom-menu-box {
|
|
206
|
-
background-color: #fff;
|
|
207
|
-
padding-top: 24rpx;
|
|
208
|
-
border-radius: 0 0 18rpx 18rpx;
|
|
209
|
-
.menu-box {
|
|
210
|
-
width: 100%;
|
|
207
|
+
// :deep(.filter-box-menu) {
|
|
211
208
|
|
|
212
|
-
|
|
213
|
-
font-size: var(--font-size-24, 24rpx);
|
|
209
|
+
// }
|
|
214
210
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
211
|
+
:deep(.custom-menu-box) {
|
|
212
|
+
background-color: #fff;
|
|
213
|
+
padding-top: 24rpx;
|
|
214
|
+
border-radius: 0 0 18rpx 18rpx;
|
|
215
|
+
.menu-box {
|
|
216
|
+
width: 100%;
|
|
218
217
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
color: #888c92;
|
|
222
|
-
margin-bottom: 20rpx;
|
|
223
|
-
}
|
|
218
|
+
margin-bottom: 56rpx;
|
|
219
|
+
font-size: var(--font-size-24, 24rpx);
|
|
224
220
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
221
|
+
.menu-item-block {
|
|
222
|
+
padding: 0 40rpx;
|
|
223
|
+
margin-bottom: 20rpx;
|
|
224
|
+
|
|
225
|
+
.menu-item-title {
|
|
226
|
+
font-size: var(--font-size-24, 24rpx);
|
|
227
|
+
color: #888c92;
|
|
228
|
+
margin-bottom: 20rpx;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
.menu-item-content {
|
|
232
|
+
display: flex;
|
|
233
|
+
flex-wrap: wrap;
|
|
234
|
+
gap: 20rpx 32rpx;
|
|
229
235
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
}
|
|
236
|
+
&.multiple {
|
|
237
|
+
.menu-item-child.active {
|
|
238
|
+
background-color: var(--active-color);
|
|
239
|
+
color: #fff;
|
|
235
240
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
241
|
+
}
|
|
242
|
+
.menu-item-child {
|
|
243
|
+
padding: 10rpx 0;
|
|
244
|
+
font-size: var(--font-size-24, 24rpx);
|
|
245
|
+
color: var(--inactive-color);
|
|
246
|
+
flex-shrink: 0;
|
|
247
|
+
padding: 16rpx 40rpx;
|
|
248
|
+
border-radius: 8rpx;
|
|
249
|
+
background: rgba(230, 232, 234, 0.5);
|
|
250
|
+
transition: all 0.2s ease;
|
|
251
|
+
cursor: pointer;
|
|
252
|
+
&.active {
|
|
253
|
+
color: var(--active-color);
|
|
249
254
|
}
|
|
250
255
|
}
|
|
251
256
|
}
|
|
252
257
|
}
|
|
258
|
+
}
|
|
253
259
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
260
|
+
.action-box {
|
|
261
|
+
// padding: 0 40rpx;
|
|
262
|
+
display: flex;
|
|
263
|
+
justify-content: space-between;
|
|
258
264
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
265
|
+
// padding-bottom: 20rpx;
|
|
266
|
+
height: 92rpx;
|
|
267
|
+
border-radius: 0 0 16rpx 16rpx;
|
|
262
268
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
}
|
|
269
|
+
.btn {
|
|
270
|
+
flex: 1;
|
|
271
|
+
font-size: var(--font-size-32, 32rpx);
|
|
272
|
+
display: flex;
|
|
273
|
+
align-items: center;
|
|
274
|
+
justify-content: center;
|
|
275
|
+
&.reset {
|
|
276
|
+
background-color: #f4f5f6;
|
|
277
|
+
border-radius: 0 0 0 16rpx;
|
|
278
|
+
color: #1c1f23;
|
|
279
|
+
}
|
|
280
|
+
&.confirm {
|
|
281
|
+
background-color: var(--active-color);
|
|
282
|
+
border-radius: 0 0 16rpx 0;
|
|
283
|
+
color: #fff;
|
|
279
284
|
}
|
|
280
285
|
}
|
|
281
286
|
}
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
| `checkboxDisabled` | 是否禁用选择框 | `boolean` | `false` | - | - |
|
|
8
8
|
| `checked` | 是否选中 | `boolean` | `false` | - | - |
|
|
9
9
|
| `watermark` | 水印URL | `string` | `` | - | - |
|
|
10
|
+
| `watermarkStyle` | 水印样式 | `Object` | `{}` | - | - |
|
|
10
11
|
| `number` | 数量 | `number` | `1` | - | - |
|
|
11
12
|
| `stepper` | 是否显示步进器 | `boolean` | `false` | - | - |
|
|
12
13
|
| `precision` | 数值精度 | `number` | `0` | - | - |
|
|
@@ -118,6 +118,29 @@
|
|
|
118
118
|
</template>
|
|
119
119
|
```
|
|
120
120
|
|
|
121
|
+
### 水印
|
|
122
|
+
|
|
123
|
+
- 属性`watermark`接收水印图片URL,用于展示水印
|
|
124
|
+
- 属性`watermarkStyle`用于控制水印样式
|
|
125
|
+
|
|
126
|
+
```html
|
|
127
|
+
<script setup lang="ts">
|
|
128
|
+
import { ref } from 'vue';
|
|
129
|
+
const data = ref({
|
|
130
|
+
image: 'https://image.whzb.com/chain/StellarUI/bg1.jpg',
|
|
131
|
+
title: '商品名称商品名称商品名称商品名称商品名称商品名称商品名称商品名称商品名称',
|
|
132
|
+
tag: '新品',
|
|
133
|
+
code: '123456',
|
|
134
|
+
barCode: '1234567890123',
|
|
135
|
+
price: '88800',
|
|
136
|
+
originalPrice: '99900',
|
|
137
|
+
});
|
|
138
|
+
</script>
|
|
139
|
+
<template>
|
|
140
|
+
<ste-goods-info :data="data" watermark="https://image.whzb.com/chain/StellarUI/已打印.png" />
|
|
141
|
+
</template>
|
|
142
|
+
```
|
|
143
|
+
|
|
121
144
|
### 点击事件
|
|
122
145
|
|
|
123
146
|
- 默认插槽内容为商品编码下的其他展示项
|
|
@@ -110,6 +110,8 @@ const _tagBg = computed(() => (props.tagBg ? props.tagBg : getColor().steThemeCo
|
|
|
110
110
|
</view>
|
|
111
111
|
</view>
|
|
112
112
|
<view class="ste-goods-info-checkbox right" v-if="checkbox === 'right'"><setCheckbox :disabled="checkboxDisabled" iconSize="30" v-model="_checked" @change="checkboxChange" /></view>
|
|
113
|
+
|
|
114
|
+
<image v-if="watermark" class="ste-goods-info-watermark" :style="watermarkStyle" :src="watermark" />
|
|
113
115
|
</view>
|
|
114
116
|
</template>
|
|
115
117
|
|
|
@@ -123,6 +125,8 @@ const _tagBg = computed(() => (props.tagBg ? props.tagBg : getColor().steThemeCo
|
|
|
123
125
|
display: flex;
|
|
124
126
|
flex-direction: row;
|
|
125
127
|
justify-content: space-between;
|
|
128
|
+
position: relative;
|
|
129
|
+
|
|
126
130
|
.ste-goods-info-image {
|
|
127
131
|
width: 160rpx;
|
|
128
132
|
height: 160rpx;
|
|
@@ -168,6 +172,16 @@ const _tagBg = computed(() => (props.tagBg ? props.tagBg : getColor().steThemeCo
|
|
|
168
172
|
}
|
|
169
173
|
}
|
|
170
174
|
|
|
175
|
+
.ste-goods-info-watermark {
|
|
176
|
+
width: 80rpx;
|
|
177
|
+
height: 80rpx;
|
|
178
|
+
position: absolute;
|
|
179
|
+
right: 2rpx;
|
|
180
|
+
bottom: 12rpx;
|
|
181
|
+
opacity: 0.4;
|
|
182
|
+
z-index: 10;
|
|
183
|
+
}
|
|
184
|
+
|
|
171
185
|
&.checkbox {
|
|
172
186
|
padding-left: 8rpx;
|
|
173
187
|
.ste-goods-info-content {
|
|
@@ -56,7 +56,6 @@ function backClick() {
|
|
|
56
56
|
<template>
|
|
57
57
|
<view class="ste-navbar-root" :style="[pageStyle, { paddingTop: `${navbarTop}rpx` }]">
|
|
58
58
|
<view class="nav" :style="{ width: `${navbarWidth}rpx`, height: `${navbarHeight}rpx`, backgroundColor: backgroundColor }">
|
|
59
|
-
<!-- #ifdef MP-WEIXIN || H5 || APP -->
|
|
60
59
|
<view class="back-box">
|
|
61
60
|
<view v-if="autoBack" class="back" :style="{ backgroundColor: backBackgroundColor, borderColor: backBorderColor, opacity: backOpacity }">
|
|
62
61
|
<ste-icon :code="backCode" weight="bold" :size="28" :color="backColor"></ste-icon>
|
|
@@ -64,10 +63,6 @@ function backClick() {
|
|
|
64
63
|
<view @click="backClick" class="back-click-hot" />
|
|
65
64
|
</view>
|
|
66
65
|
|
|
67
|
-
<!-- #endif -->
|
|
68
|
-
<!-- #ifdef MP-ALIPAY -->
|
|
69
|
-
<view class="ali-back-box" />
|
|
70
|
-
<!-- #endif -->
|
|
71
66
|
<view v-if="title && titleAlignment == 1" class="title" :style="{ color: titleColor }">{{ title }}</view>
|
|
72
67
|
<view class="title slot-default"><slot name="default"></slot></view>
|
|
73
68
|
</view>
|
|
@@ -119,12 +114,6 @@ function backClick() {
|
|
|
119
114
|
transform: translateX(-30rpx);
|
|
120
115
|
}
|
|
121
116
|
}
|
|
122
|
-
|
|
123
|
-
.ali-back-box {
|
|
124
|
-
width: 50rpx;
|
|
125
|
-
height: 50rpx;
|
|
126
|
-
padding-right: 10rpx;
|
|
127
|
-
}
|
|
128
117
|
.slot-default {
|
|
129
118
|
display: flex;
|
|
130
119
|
align-items: center;
|
|
@@ -37,17 +37,20 @@ watch(
|
|
|
37
37
|
() => props.headerValue,
|
|
38
38
|
newVal => {
|
|
39
39
|
const now = new Date();
|
|
40
|
+
let values = [];
|
|
40
41
|
if (props.type === 'dateRange') {
|
|
41
42
|
if (newVal instanceof Array) {
|
|
42
43
|
for (let i = 0; i < 2; i++) {
|
|
43
|
-
|
|
44
|
+
values[i] = dayjs(newVal[i] || now).format('YYYY-MM-DD');
|
|
44
45
|
}
|
|
45
46
|
} else {
|
|
46
|
-
|
|
47
|
+
values = [dayjs(newVal || now).format('YYYY-MM-DD'), dayjs(now).format('YYYY-MM-DD')];
|
|
47
48
|
}
|
|
48
49
|
} else {
|
|
49
|
-
|
|
50
|
+
values = [dayjs(newVal || now).format('YYYY-MM-DD')];
|
|
50
51
|
}
|
|
52
|
+
|
|
53
|
+
calendarValues.value = values;
|
|
51
54
|
},
|
|
52
55
|
{ immediate: true }
|
|
53
56
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stellar-ui-plus",
|
|
3
|
-
"version": "1.20.
|
|
3
|
+
"version": "1.20.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,8 +12,5 @@
|
|
|
12
12
|
"scripts": {
|
|
13
13
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
14
14
|
"publish-vscode-plugin": "cd ../../../plugins/ste-helper & pnpm run publish"
|
|
15
|
-
},
|
|
16
|
-
"dependencies": {
|
|
17
|
-
"@swjs/chinese-holidays": "^1.1.0"
|
|
18
15
|
}
|
|
19
16
|
}
|
package/utils/time.ts
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @desc @swjs/chinese-holidays 中国法定节假日查询
|
|
3
|
+
* @version 1.1.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
async function getRemoteHolidaysApi(year, options) {
|
|
7
|
+
return new Promise(async (resolve, reject) => {
|
|
8
|
+
uni.request({
|
|
9
|
+
url: `${options.baseUrl}/${year}.json`,
|
|
10
|
+
method: 'get',
|
|
11
|
+
success: res => {
|
|
12
|
+
console.log('res', res);
|
|
13
|
+
resolve(res.data);
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// 日期网址链接
|
|
20
|
+
// export const BASE_URL = 'https://cdn.jsdelivr.net/gh/NateScarlet/holiday-cn@master';
|
|
21
|
+
/**
|
|
22
|
+
* 中国地区 cdn 地址受到污染,因此使用 fastly.jsdelivr.net
|
|
23
|
+
*/
|
|
24
|
+
const BASE_URL = 'https://fastly.jsdelivr.net/gh/NateScarlet/holiday-cn@master';
|
|
25
|
+
const WEEKS = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @desc 假期信息
|
|
29
|
+
*/
|
|
30
|
+
class HolidaysInfo {
|
|
31
|
+
constructor(config) {
|
|
32
|
+
/**
|
|
33
|
+
* 日期的缓存
|
|
34
|
+
*/
|
|
35
|
+
this.holidays = {};
|
|
36
|
+
this.config = {
|
|
37
|
+
baseUrl: BASE_URL,
|
|
38
|
+
...(config || {}),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* @desc 获取日期信息
|
|
43
|
+
* @param {string} dateStr
|
|
44
|
+
* @returns
|
|
45
|
+
*/
|
|
46
|
+
async getDateInfo(dateStr) {
|
|
47
|
+
const date = new Date(dateStr);
|
|
48
|
+
const year = date.getFullYear();
|
|
49
|
+
const holidays = await this.getHolidaysByYear(String(year));
|
|
50
|
+
// see https://github.com/MrSeaWave/chinese-holidays/pull/124
|
|
51
|
+
// 2022年12月31的节假日日期在2023年才能获得,有些时候会有调休
|
|
52
|
+
if (date.getMonth() === 11) {
|
|
53
|
+
const nextYear = year + 1;
|
|
54
|
+
const nextHolidays = await this.getHolidaysByYear(String(nextYear));
|
|
55
|
+
holidays.push(...nextHolidays);
|
|
56
|
+
}
|
|
57
|
+
return holidays.find(info => info.date === dateStr);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* 获取当年的假期数据(包含节假日的调休
|
|
61
|
+
* @param year
|
|
62
|
+
*/
|
|
63
|
+
async getHolidaysByYear(year) {
|
|
64
|
+
if (!this.holidays[year]) {
|
|
65
|
+
await this._getRemoteData(year);
|
|
66
|
+
}
|
|
67
|
+
return this.holidays[year] || [];
|
|
68
|
+
}
|
|
69
|
+
// 从链接中获取新的年份信息
|
|
70
|
+
async _getRemoteData(year) {
|
|
71
|
+
// console.log(`------ Start: 获取远程日期(${year})数据中... ------`);
|
|
72
|
+
const resp = await getRemoteHolidaysApi(year, { baseUrl: this.config.baseUrl });
|
|
73
|
+
console.log('resp', resp);
|
|
74
|
+
//await getMethod({ url: `/${year}.json` });
|
|
75
|
+
// console.log('------ End: 结束获取 ------');
|
|
76
|
+
const { days = [] } = resp || {};
|
|
77
|
+
if (!days.length) throw new Error(`暂时没有 ${year} 年的放假数据,请稍后重试 `);
|
|
78
|
+
this.holidays[year] = days;
|
|
79
|
+
}
|
|
80
|
+
// 获取本地holidays缓存
|
|
81
|
+
getHolidaysCache() {
|
|
82
|
+
return this.holidays;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @desc 判断是否是有效日期
|
|
88
|
+
* @param {Date} date
|
|
89
|
+
* @returns {boolean}
|
|
90
|
+
*/
|
|
91
|
+
function isValidDate(date) {
|
|
92
|
+
return date instanceof Date && !Number.isNaN(date.getTime());
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* @desc 日期格式化
|
|
96
|
+
* @param {AcceptDateType} date 日期
|
|
97
|
+
* @param {string} fmt 格式规则
|
|
98
|
+
* @returns {string} 格式化后的日期
|
|
99
|
+
*/
|
|
100
|
+
function dateFormat(date, fmt = 'YYYY-MM-DD HH:mm:ss') {
|
|
101
|
+
const d = new Date(date);
|
|
102
|
+
if (!isValidDate(d)) {
|
|
103
|
+
throw new Error(`Invalid date: ${date}`);
|
|
104
|
+
}
|
|
105
|
+
const opt = {
|
|
106
|
+
'Y+': d.getFullYear().toString(), // 年
|
|
107
|
+
'M+': (d.getMonth() + 1).toString(), // 月
|
|
108
|
+
'D+': d.getDate().toString(), // 日
|
|
109
|
+
'H+': d.getHours().toString(), // 小时
|
|
110
|
+
'm+': d.getMinutes().toString(), // 分
|
|
111
|
+
's+': d.getSeconds().toString(), // 秒
|
|
112
|
+
'q+': Math.floor((d.getMonth() + 3) / 3).toString(), // 季度
|
|
113
|
+
S: d.getMilliseconds().toString(), // 毫秒
|
|
114
|
+
};
|
|
115
|
+
Object.entries(opt).forEach(([k, val]) => {
|
|
116
|
+
const ret = new RegExp(`(${k})`).exec(fmt);
|
|
117
|
+
if (ret) {
|
|
118
|
+
fmt = fmt.replace(ret[1], ret[1].length === 1 ? val : val.padStart(ret[1].length, '0'));
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
return fmt;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* @desc 当前日期是星期几
|
|
125
|
+
* @param {AcceptDateType} date 日期
|
|
126
|
+
* @returns {string}
|
|
127
|
+
*/
|
|
128
|
+
function getWeekDay(date) {
|
|
129
|
+
return WEEKS[new Date(date).getDay()];
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* @desc 判断是否是周末
|
|
133
|
+
* @param date
|
|
134
|
+
*/
|
|
135
|
+
function isWeekEnd$1(date) {
|
|
136
|
+
const day = new Date(date).getDay();
|
|
137
|
+
return day === 0 || day === 6;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
var EDateType;
|
|
141
|
+
(function (EDateType) {
|
|
142
|
+
/**
|
|
143
|
+
* 工作日
|
|
144
|
+
*/
|
|
145
|
+
EDateType[(EDateType['WorkDay'] = 1)] = 'WorkDay';
|
|
146
|
+
/**
|
|
147
|
+
* 周末
|
|
148
|
+
*/
|
|
149
|
+
EDateType[(EDateType['WeekEnd'] = 2)] = 'WeekEnd';
|
|
150
|
+
/**
|
|
151
|
+
* 法定节假日
|
|
152
|
+
*/
|
|
153
|
+
EDateType[(EDateType['Holiday'] = 3)] = 'Holiday';
|
|
154
|
+
/**
|
|
155
|
+
* 调休,节假日调班
|
|
156
|
+
*/
|
|
157
|
+
EDateType[(EDateType['LeaveInLieu'] = 4)] = 'LeaveInLieu';
|
|
158
|
+
})(EDateType || (EDateType = {}));
|
|
159
|
+
/**
|
|
160
|
+
* 判定日期的工具集
|
|
161
|
+
*/
|
|
162
|
+
class Holidays {
|
|
163
|
+
static getInstance() {
|
|
164
|
+
if (!this.instance) {
|
|
165
|
+
this.instance = new Holidays();
|
|
166
|
+
}
|
|
167
|
+
return this.instance;
|
|
168
|
+
}
|
|
169
|
+
constructor(config) {
|
|
170
|
+
/**
|
|
171
|
+
* @desc 获取当前日期数据
|
|
172
|
+
* @param {string | Date | number} date 日期
|
|
173
|
+
*/
|
|
174
|
+
this.getDateInfo = async date => {
|
|
175
|
+
const dateStr = dateFormat(date, 'YYYY-MM-DD');
|
|
176
|
+
const day = getWeekDay(date);
|
|
177
|
+
// type: 1-工作日 2-周末 3 法定节假日 4 节假日调班
|
|
178
|
+
const result = {
|
|
179
|
+
name: '工作日',
|
|
180
|
+
date: dateStr,
|
|
181
|
+
day,
|
|
182
|
+
type: 1,
|
|
183
|
+
};
|
|
184
|
+
if (isWeekEnd$1(date)) {
|
|
185
|
+
result.name = '周末';
|
|
186
|
+
result.type = 2;
|
|
187
|
+
}
|
|
188
|
+
const holiday = await this.holidaysInfo.getDateInfo(dateStr);
|
|
189
|
+
if (holiday) {
|
|
190
|
+
const { isOffDay, name } = holiday;
|
|
191
|
+
result.name = name + (isOffDay ? '' : ' 调班');
|
|
192
|
+
result.type = isOffDay ? 3 : 4;
|
|
193
|
+
}
|
|
194
|
+
return result;
|
|
195
|
+
};
|
|
196
|
+
/**
|
|
197
|
+
* @desc 判断是否是法定节假日
|
|
198
|
+
* @param {AcceptDateType} date 日期
|
|
199
|
+
*/
|
|
200
|
+
this.isHoliday = async date => {
|
|
201
|
+
const info = await this.getDateInfo(date);
|
|
202
|
+
return info.type === EDateType.Holiday;
|
|
203
|
+
};
|
|
204
|
+
/**
|
|
205
|
+
* @desc 判断是否是工作日(含节假日的调休)
|
|
206
|
+
* @param date
|
|
207
|
+
*/
|
|
208
|
+
this.isWorkingDay = async date => {
|
|
209
|
+
const info = await this.getDateInfo(date);
|
|
210
|
+
return info.type === EDateType.WorkDay || info.type === EDateType.LeaveInLieu;
|
|
211
|
+
};
|
|
212
|
+
/**
|
|
213
|
+
* @desc 判断是否是周末(不包含节假日调休上班)
|
|
214
|
+
* @param date
|
|
215
|
+
*/
|
|
216
|
+
this.isWeekEnd = async date => {
|
|
217
|
+
const info = await this.getDateInfo(date);
|
|
218
|
+
return info.type === EDateType.WeekEnd;
|
|
219
|
+
};
|
|
220
|
+
/**
|
|
221
|
+
* @desc 获取本地的假期缓存数据
|
|
222
|
+
*/
|
|
223
|
+
this.getHolidaysCache = () => {
|
|
224
|
+
return this.holidaysInfo.getHolidaysCache();
|
|
225
|
+
};
|
|
226
|
+
this.holidaysInfo = new HolidaysInfo(config);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
const holidays = Holidays.getInstance();
|
|
230
|
+
|
|
231
|
+
const isWorkingDay = holidays.isWorkingDay;
|
|
232
|
+
const isHoliday = holidays.isHoliday;
|
|
233
|
+
const isWeekEnd = holidays.isWeekEnd;
|
|
234
|
+
const getDateInfo = holidays.getDateInfo;
|
|
235
|
+
const getHolidaysCache = holidays.getHolidaysCache;
|
|
236
|
+
// 测试编译包的语法,不要使用
|
|
237
|
+
const __isHoliday__ = holidays?.isHoliday;
|
|
238
|
+
|
|
239
|
+
export { Holidays, __isHoliday__, getDateInfo, getHolidaysCache, isHoliday, isWeekEnd, isWorkingDay };
|