yuang-framework-ui-common 1.0.20 → 1.0.21

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/lib/.DS_Store ADDED
Binary file
@@ -12,7 +12,7 @@ import 'vant/lib/index.css';
12
12
  import {http} from './httpConfig';
13
13
  import moment from 'moment';
14
14
 
15
- const initConfig = (app) => {
15
+ const initConfig = (app: any) => {
16
16
  app.config.globalProperties.$http = http;
17
17
  app.config.globalProperties.$moment = moment;
18
18
 
@@ -0,0 +1,41 @@
1
+ /**
2
+ * 某个时间在当前时间的多久前
3
+ * @param time 需要语义化的时间
4
+ * @param onlyDate 超过30天是否仅返回日期
5
+ * @returns {string} 语义化后的时间
6
+ */
7
+ const getTimeAgoString = (time, onlyDate) => {
8
+ if (!time) return '';
9
+ if (typeof time === 'string') time = time.replace(/-/g, '/');
10
+ let arr = [[], []], stamp = new Date().getTime() - new Date(time).getTime();
11
+ // 30天以上返回具体日期
12
+ if (stamp > 1000 * 60 * 60 * 24 * 31) {
13
+ stamp = new Date(time);
14
+ arr[0][0] = this.digit(stamp.getFullYear(), 4);
15
+ arr[0][1] = this.digit(stamp.getMonth() + 1);
16
+ arr[0][2] = this.digit(stamp.getDate());
17
+ if (!onlyDate) { // 是否输出时间
18
+ arr[1][0] = this.digit(stamp.getHours());
19
+ arr[1][1] = this.digit(stamp.getMinutes());
20
+ arr[1][2] = this.digit(stamp.getSeconds());
21
+ }
22
+ return arr[0].join('-') + ' ' + arr[1].join(':');
23
+ }
24
+ // 30天以内,返回“多久前”
25
+ if (stamp >= 1000 * 60 * 60 * 24) {
26
+ return ((stamp / 1000 / 60 / 60 / 24) | 0) + '天前';
27
+ } else if (stamp >= 1000 * 60 * 60) {
28
+ return ((stamp / 1000 / 60 / 60) | 0) + '小时前';
29
+ } else if (stamp >= 1000 * 60 * 3) { // 3分钟以内为:刚刚
30
+ return ((stamp / 1000 / 60) | 0) + '分钟前';
31
+ } else if (stamp < 0) {
32
+ return '未来';
33
+ } else {
34
+ return '刚刚';
35
+ }
36
+ }
37
+
38
+ export {
39
+ getTimeAgoString,
40
+
41
+ }
@@ -1,6 +1,5 @@
1
1
  import { cloneDeep } from 'lodash';
2
2
 
3
3
  export {
4
-
5
4
  cloneDeep
6
5
  }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * 生成UUID
3
+ * @returns {string}
4
+ */
5
+ const getUuid = () => {
6
+ let d = new Date().getTime();
7
+ if (window.performance && typeof window.performance.now === "function") {
8
+ d += performance.now(); //use high-precision timer if available
9
+ }
10
+ let uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
11
+ var r = (d + Math.random() * 16) % 16 | 0;
12
+ d = Math.floor(d / 16);
13
+ return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16);
14
+ });
15
+ return uuid;
16
+ }
17
+ const getShortUuid = () => {
18
+ let uuid = this.getUuid();
19
+ uuid = uuid.replace(/-/g, '');
20
+ return uuid;
21
+ }
22
+
23
+ export {
24
+ getUuid,
25
+ getShortUuid
26
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yuang-framework-ui-common",
3
- "version": "1.0.20",
3
+ "version": "1.0.21",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "scripts": {
package/src/.DS_Store ADDED
Binary file