@ftlab/one-vue3 0.3.8-4 → 0.3.8-6

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
@@ -7,7 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
9
9
 
10
- ## [v0.3.8-4](https://gitlab.ftlapp.cn/ftl/ftlab/one-vue3/compare/v0.3.8-3...v0.3.8-4)
10
+ ## [v0.3.8-6](https://gitlab.ftlapp.cn/ftl/ftlab/one-vue3/compare/v0.3.8-5...v0.3.8-6)
11
+
12
+ ### Commits
13
+
14
+ - fix [`8aeaf2d`](https://gitlab.ftlapp.cn/ftl/ftlab/one-vue3/commit/8aeaf2d9b4540abe50c0a8d30c95161ea7fc9b76)
15
+
16
+ ## [v0.3.8-5](https://gitlab.ftlapp.cn/ftl/ftlab/one-vue3/compare/v0.3.8-4...v0.3.8-5) - 2025-06-04
17
+
18
+ ### Commits
19
+
20
+ - fix [`1caf48e`](https://gitlab.ftlapp.cn/ftl/ftlab/one-vue3/commit/1caf48ef7c93b8fb53e8bb70b2b730186dbd260a)
21
+
22
+ ## [v0.3.8-4](https://gitlab.ftlapp.cn/ftl/ftlab/one-vue3/compare/v0.3.8-3...v0.3.8-4) - 2025-06-04
11
23
 
12
24
  ### Commits
13
25
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ftlab/one-vue3",
3
- "version": "0.3.8-4",
3
+ "version": "0.3.8-6",
4
4
  "description": "One for Apps based on Element UI",
5
5
  "main": "dist/ftlOne.js",
6
6
  "type": "module",
package/utils/date.ts ADDED
@@ -0,0 +1,127 @@
1
+ import dayjs from 'dayjs';
2
+ import utc from 'dayjs/plugin/utc';
3
+ import timezone from 'dayjs/plugin/timezone';
4
+
5
+ dayjs.extend(timezone);
6
+ dayjs.extend(utc);
7
+
8
+ type dateFormat = (date: string | Date | null | undefined, format?: string, defaultStr?: string) => string;
9
+ type dateTransform = (date: string | Date | null | undefined, defaultStr?: string) => Date | string;
10
+ type tzTransform = (date: string | Date | null | undefined, tz: string) => Date | string;
11
+ type dateValidate = (date: any) => boolean;
12
+
13
+ const TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss';
14
+
15
+ /**
16
+ * @description 判断是否合法输入
17
+ * @param {(string|Date)} value 日期
18
+ * @returns {boolean}
19
+ */
20
+
21
+ const isValidDate: dateValidate = (value) => {
22
+ const date = new Date(value);
23
+ if (!isNaN(date.getTime())) {
24
+ const year = date.getFullYear();
25
+ const month = date.getMonth() + 1;
26
+ const day = date.getDate();
27
+ if (day === 29 && month === 2) {
28
+ if ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0) {
29
+ return true;
30
+ } else {
31
+ return false;
32
+ }
33
+ }
34
+ return true;
35
+ }
36
+ return !isNaN(date.getTime());
37
+ };
38
+
39
+ /**
40
+ * @description utc时间转cn时间
41
+ * @param {(string|Date)} date 日期
42
+ * @param {string} [format] 时间格式
43
+ * @param {string} [default=''] 默认返回值
44
+ * @return {string}
45
+ */
46
+ const utc_cn: dateFormat = (date, format, defaultStr = '') => {
47
+ if (!date || !isValidDate(date)) return defaultStr;
48
+ return dayjs(date)
49
+ .utc()
50
+ .tz('Asia/Shanghai')
51
+ .format(format || TIME_FORMAT);
52
+ };
53
+
54
+ /**
55
+ * @description utc时间转fr时间
56
+ * @param {(string|Date)} date 日期
57
+ * @param {string} [format] 时间格式
58
+ * @param {string} [default=''] 默认返回值
59
+ * @return {string}
60
+ */
61
+
62
+ const utc_fr: dateFormat = (date, format, defaultStr = '') => {
63
+ if (!date || !isValidDate(date)) return defaultStr;
64
+ return dayjs(date)
65
+ .utc()
66
+ .tz('Europe/Paris')
67
+ .format(format || TIME_FORMAT);
68
+ };
69
+
70
+ /**
71
+ * @description 本地时间转utc日期
72
+ * @param {(string|Date)} date 日期
73
+ * @param {string} [default=''] 默认返回值
74
+ * @return {Date}
75
+ */
76
+
77
+ const local_utc_date: dateTransform = (date, defaultStr = '') => {
78
+ if (!date || !isValidDate(date)) return defaultStr;
79
+ const localDate = new Date(dayjs(date).format(TIME_FORMAT)).getTime();
80
+ const utcChargeTime = new Date(dayjs(date).utc().format(TIME_FORMAT)).getTime();
81
+ const diff = (localDate - utcChargeTime) / (1000 * 3600);
82
+ return diff > 0 ? dayjs(date).utc().add(diff, 'hours').toDate() : dayjs(date).utc().subtract(diff, 'hours').toDate();
83
+ };
84
+
85
+ /**
86
+ * @description 本地时间保存为指定时区的日期
87
+ * @param {(string|Date)} date 日期
88
+ * @param {string} tz 时区
89
+ * @return {Date}
90
+ */
91
+
92
+ const local_tz_date: tzTransform = (date, tz) => {
93
+ if (!date || !isValidDate(date)) return '';
94
+ const localOffsetInMinutes = dayjs(date).utcOffset();
95
+ const tzOffsetInMinutes = dayjs(date).tz(tz).utcOffset();
96
+ const offsetDifference = localOffsetInMinutes - tzOffsetInMinutes;
97
+ return offsetDifference > 0
98
+ ? dayjs(date).add(offsetDifference, 'minutes').toDate()
99
+ : dayjs(date).subtract(offsetDifference, 'minutes').toDate();
100
+ };
101
+
102
+ /**
103
+ * @description 本地时间保存为中国日期
104
+ * @param {(string|Date)} date 日期
105
+ * @param {string} [default=''] 默认返回值
106
+ * @return {Date}
107
+ */
108
+
109
+ const local_cn_date: dateTransform = (date, defaultStr = '') => {
110
+ if (!date || !isValidDate(date)) return defaultStr;
111
+ return local_tz_date(date, 'Asia/Shanghai');
112
+ };
113
+
114
+ /**
115
+ * @description 本地时间保存为法国日期
116
+ * @param {(string|Date)} date 日期
117
+ * @param {string} [default=''] 默认返回值
118
+ * @return {Date}
119
+ */
120
+
121
+ const local_fr_date: dateTransform = (date, defaultStr = '') => {
122
+ if (!date || !isValidDate(date)) return defaultStr;
123
+ return local_tz_date(date, 'Europe/Paris');
124
+ };
125
+
126
+ export { utc_cn, utc_fr, local_utc_date, local_cn_date, local_fr_date, local_tz_date, isValidDate, dayjs };
127
+ export type { dateFormat, dateTransform, tzTransform, dateValidate };
package/utils/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './date';
2
+ export { default as storage } from './storage';
3
+ export * from './utils';
@@ -0,0 +1,27 @@
1
+ export default {
2
+ get(key) {
3
+ return localStorage.getItem(key);
4
+ },
5
+ set(key, value) {
6
+ localStorage.setItem(key, value);
7
+ },
8
+ remove(key) {
9
+ localStorage.removeItem(key);
10
+ },
11
+ // 保存token到本地缓存
12
+ setToken(token) {
13
+ this.set('token', token);
14
+ },
15
+ // 保存用户信息到本地缓存
16
+ setAuth(auth) {
17
+ this.set('auth', JSON.stringify(auth));
18
+ },
19
+ // 读取token
20
+ getToken() {
21
+ return this.get('token');
22
+ },
23
+ // 读取用户信息
24
+ getAuth() {
25
+ return this.get('auth') ? JSON.parse(this.get('auth')) : {};
26
+ },
27
+ };
package/utils/utils.ts ADDED
@@ -0,0 +1,10 @@
1
+ // 防抖
2
+ export function debounce(fn, delay = 1000) {
3
+ let timer: NodeJS.Timer;
4
+ return function (...args) {
5
+ clearTimeout(timer);
6
+ timer = setTimeout(() => {
7
+ fn.apply(this, args);
8
+ }, delay);
9
+ };
10
+ }