@zfqh/uniapp 0.1.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 +16 -0
- package/LICENSE +21 -0
- package/README.md +39 -0
- package/docs/api/apis/core.md +189 -0
- package/docs/api/apis/index.md +82 -0
- package/docs/api/apis/request.md +369 -0
- package/docs/api/configs/api.md +32 -0
- package/docs/api/configs/app.md +43 -0
- package/docs/api/configs/brand.md +43 -0
- package/docs/api/configs/cdn.md +35 -0
- package/docs/api/configs/color.md +144 -0
- package/docs/api/configs/env.md +120 -0
- package/docs/api/configs/index.md +394 -0
- package/docs/api/configs/link.md +33 -0
- package/docs/api/configs/log.md +27 -0
- package/docs/api/configs/mp.md +34 -0
- package/docs/api/configs/navigate.md +27 -0
- package/docs/api/configs/page.md +32 -0
- package/docs/api/configs/path.md +27 -0
- package/docs/api/configs/storage.md +24 -0
- package/docs/api/configs/tabbar.md +29 -0
- package/docs/api/configs/toast.md +35 -0
- package/docs/api/configs/update.md +25 -0
- package/docs/api/configs/upload.md +45 -0
- package/docs/api/configs/ver.md +32 -0
- package/docs/api/configs/web.md +28 -0
- package/docs/api/hooks/index.md +182 -0
- package/docs/api/hooks/useI18n.md +27 -0
- package/docs/api/hooks/useOverlay.md +37 -0
- package/docs/api/hooks/usePopup.md +35 -0
- package/docs/api/hooks/useVersion.md +23 -0
- package/docs/api/index.md +269 -0
- package/docs/api/mixins/app.md +29 -0
- package/docs/api/mixins/badge.md +23 -0
- package/docs/api/mixins/debounce.md +32 -0
- package/docs/api/mixins/deep.md +29 -0
- package/docs/api/mixins/index.md +23 -0
- package/docs/api/mixins/login.md +22 -0
- package/docs/api/mixins/model.md +26 -0
- package/docs/api/mixins/redirect.md +26 -0
- package/docs/api/mixins/share.md +29 -0
- package/docs/api/mixins/show.md +27 -0
- package/docs/api/mixins/webview.md +27 -0
- package/docs/api/modules/app.md +30 -0
- package/docs/api/modules/dict.md +28 -0
- package/docs/api/modules/im.md +22 -0
- package/docs/api/modules/index.md +44 -0
- package/docs/api/modules/launch.md +26 -0
- package/docs/api/modules/location.md +25 -0
- package/docs/api/modules/login.md +35 -0
- package/docs/api/modules/network.md +26 -0
- package/docs/api/modules/system.md +29 -0
- package/docs/api/utils/audio.md +84 -0
- package/docs/api/utils/consts.md +201 -0
- package/docs/api/utils/cos.md +269 -0
- package/docs/api/utils/debounce.md +89 -0
- package/docs/api/utils/file.md +78 -0
- package/docs/api/utils/index.md +547 -0
- package/docs/api/utils/locale.md +32 -0
- package/docs/api/utils/message.md +81 -0
- package/docs/api/utils/navigate.md +267 -0
- package/docs/api/utils/pages.md +205 -0
- package/docs/api/utils/permission.md +28 -0
- package/docs/api/utils/permit.md +62 -0
- package/docs/api/utils/query.md +89 -0
- package/docs/api/utils/request.md +34 -0
- package/docs/api/utils/storage.md +145 -0
- package/docs/api/utils/subscribe.md +77 -0
- package/docs/api/utils/throttle.md +101 -0
- package/docs/api/utils/toast.md +164 -0
- package/docs/api/utils/uni.md +28 -0
- package/docs/api/utils/update.md +165 -0
- package/docs/components/g-back-button.md +76 -0
- package/docs/components/g-checkbox-list.md +101 -0
- package/docs/components/g-container.md +93 -0
- package/docs/components/g-data-list.md +106 -0
- package/docs/components/g-dot-text.md +79 -0
- package/docs/components/g-env.md +75 -0
- package/docs/components/g-float.md +83 -0
- package/docs/components/g-grid-image.md +91 -0
- package/docs/components/g-grid-swiper.md +99 -0
- package/docs/components/g-icon.md +106 -0
- package/docs/components/g-mask.md +82 -0
- package/docs/components/g-money.md +90 -0
- package/docs/components/g-more.md +78 -0
- package/docs/components/g-page-container.md +170 -0
- package/docs/components/g-permission-popup.md +117 -0
- package/docs/components/g-polyline-chat.md +102 -0
- package/docs/components/g-polyline-view.md +67 -0
- package/docs/components/g-popup.md +144 -0
- package/docs/components/g-refresh-view.md +118 -0
- package/docs/components/g-render-image.md +83 -0
- package/docs/components/g-search.md +120 -0
- package/docs/components/g-share-photo.md +77 -0
- package/docs/components/g-share-view.md +83 -0
- package/docs/components/g-share-weixin.md +81 -0
- package/docs/components/g-skeleton-view.md +71 -0
- package/docs/components/g-skeleton.md +64 -0
- package/docs/components/g-tag-editor.md +134 -0
- package/docs/components/g-timer.md +72 -0
- package/docs/components/g-trtc-room.md +116 -0
- package/docs/components/g-trtc-tui.md +84 -0
- package/docs/components/g-trtc.md +124 -0
- package/docs/components/g-upload.md +117 -0
- package/docs/components/g-waterfall.md +84 -0
- package/docs/components/index.md +109 -0
- package/docs/components/styles/base-styles.md +367 -0
- package/docs/components/styles/global-vars.md +150 -0
- package/docs/components/usage.md +112 -0
- package/docs/faq/index.md +78 -0
- package/docs/guide/getting-started.md +195 -0
- package/docs/guide/project-frame.md +297 -0
- package/docs/index.md +80 -0
- package/lib/apis/core.d.ts +12 -0
- package/lib/apis/core.js +13 -0
- package/lib/apis/index.d.ts +2 -0
- package/lib/apis/index.js +2 -0
- package/lib/apis/request.d.ts +4 -0
- package/lib/apis/request.js +27 -0
- package/lib/components/g-back-button/g-back-button.vue +141 -0
- package/lib/components/g-checkbox-list/g-checkbox-list.vue +156 -0
- package/lib/components/g-container/g-container.vue +159 -0
- package/lib/components/g-data-list/g-data-list.vue +192 -0
- package/lib/components/g-dot-text/g-dot-text.vue +114 -0
- package/lib/components/g-env/g-env.vue +123 -0
- package/lib/components/g-float/g-float.vue +131 -0
- package/lib/components/g-grid-image/g-grid-image.vue +84 -0
- package/lib/components/g-grid-swiper/g-grid-swiper.vue +224 -0
- package/lib/components/g-icon/g-icon.vue +72 -0
- package/lib/components/g-mask/g-mask.vue +126 -0
- package/lib/components/g-money/g-money.vue +174 -0
- package/lib/components/g-more/g-more.vue +68 -0
- package/lib/components/g-page-container/g-page-container.vue +470 -0
- package/lib/components/g-permission-popup/g-permission-popup.vue +80 -0
- package/lib/components/g-polyline-chat/g-polyline-chat.vue +255 -0
- package/lib/components/g-polyline-view/g-polyline-view.vue +104 -0
- package/lib/components/g-popup/g-popup.vue +449 -0
- package/lib/components/g-refresh-view/g-refresh-view.vue +213 -0
- package/lib/components/g-render-image/g-render-image.vue +222 -0
- package/lib/components/g-search/g-search.vue +274 -0
- package/lib/components/g-share-photo/g-share-photo.vue +75 -0
- package/lib/components/g-share-view/g-share-view.vue +157 -0
- package/lib/components/g-share-weixin/g-share-weixin.vue +106 -0
- package/lib/components/g-skeleton/g-skeleton.vue +55 -0
- package/lib/components/g-skeleton-view/g-skeleton-view.vue +78 -0
- package/lib/components/g-tag-editor/g-tag-editor.vue +482 -0
- package/lib/components/g-timer/g-timer.vue +61 -0
- package/lib/components/g-trtc/g-trtc.vue +347 -0
- package/lib/components/g-trtc-room/g-trtc-room.vue +524 -0
- package/lib/components/g-trtc-room/iconfont.scss +59 -0
- package/lib/components/g-trtc-tui/g-trtc-tui.vue +245 -0
- package/lib/components/g-upload/g-upload.vue +294 -0
- package/lib/components/g-waterfall/g-waterfall.vue +101 -0
- package/lib/configs/api.d.ts +7 -0
- package/lib/configs/api.js +6 -0
- package/lib/configs/app.d.ts +26 -0
- package/lib/configs/app.js +50 -0
- package/lib/configs/brand.d.ts +22 -0
- package/lib/configs/brand.js +26 -0
- package/lib/configs/cdn.d.ts +13 -0
- package/lib/configs/cdn.js +12 -0
- package/lib/configs/color.d.ts +62 -0
- package/lib/configs/color.js +66 -0
- package/lib/configs/env.d.ts +37 -0
- package/lib/configs/env.js +71 -0
- package/lib/configs/index.d.ts +170 -0
- package/lib/configs/index.js +82 -0
- package/lib/configs/link.d.ts +11 -0
- package/lib/configs/link.js +3 -0
- package/lib/configs/log.d.ts +9 -0
- package/lib/configs/log.js +8 -0
- package/lib/configs/mp.d.ts +15 -0
- package/lib/configs/mp.js +9 -0
- package/lib/configs/navigate.d.ts +17 -0
- package/lib/configs/navigate.js +5 -0
- package/lib/configs/page.d.ts +18 -0
- package/lib/configs/page.js +14 -0
- package/lib/configs/path.d.ts +11 -0
- package/lib/configs/path.js +10 -0
- package/lib/configs/storage.d.ts +7 -0
- package/lib/configs/storage.js +6 -0
- package/lib/configs/tabbar.d.ts +7 -0
- package/lib/configs/tabbar.js +6 -0
- package/lib/configs/toast.d.ts +18 -0
- package/lib/configs/toast.js +29 -0
- package/lib/configs/update.d.ts +45 -0
- package/lib/configs/update.js +6 -0
- package/lib/configs/upload.d.ts +30 -0
- package/lib/configs/upload.js +7 -0
- package/lib/configs/ver.d.ts +8 -0
- package/lib/configs/ver.js +28 -0
- package/lib/configs/web.d.ts +5 -0
- package/lib/configs/web.js +2 -0
- package/lib/hooks/index.d.ts +4 -0
- package/lib/hooks/index.js +4 -0
- package/lib/hooks/useI18n.d.ts +2 -0
- package/lib/hooks/useI18n.js +19 -0
- package/lib/hooks/useOverlay.d.ts +1 -0
- package/lib/hooks/useOverlay.js +17 -0
- package/lib/hooks/usePopup.d.ts +1 -0
- package/lib/hooks/usePopup.js +14 -0
- package/lib/hooks/useVersion.d.ts +6 -0
- package/lib/hooks/useVersion.js +21 -0
- package/lib/index.d.ts +26 -0
- package/lib/index.js +33 -0
- package/lib/mixins/app.d.ts +14 -0
- package/lib/mixins/app.js +105 -0
- package/lib/mixins/badge.d.ts +24 -0
- package/lib/mixins/badge.js +44 -0
- package/lib/mixins/debounce.d.ts +6 -0
- package/lib/mixins/debounce.js +11 -0
- package/lib/mixins/deep.d.ts +6 -0
- package/lib/mixins/deep.js +8 -0
- package/lib/mixins/index.d.ts +8 -0
- package/lib/mixins/index.js +8 -0
- package/lib/mixins/login.d.ts +4 -0
- package/lib/mixins/login.js +25 -0
- package/lib/mixins/model.d.ts +22 -0
- package/lib/mixins/model.js +29 -0
- package/lib/mixins/redirect.d.ts +8 -0
- package/lib/mixins/redirect.js +94 -0
- package/lib/mixins/share.d.ts +15 -0
- package/lib/mixins/share.js +55 -0
- package/lib/mixins/show.d.ts +9 -0
- package/lib/mixins/show.js +16 -0
- package/lib/mixins/webview.d.ts +26 -0
- package/lib/mixins/webview.js +225 -0
- package/lib/modules/app.d.ts +5 -0
- package/lib/modules/app.js +19 -0
- package/lib/modules/dict.d.ts +8 -0
- package/lib/modules/dict.js +43 -0
- package/lib/modules/im.d.ts +6 -0
- package/lib/modules/im.js +105 -0
- package/lib/modules/index.d.ts +8 -0
- package/lib/modules/index.js +8 -0
- package/lib/modules/launch.d.ts +5 -0
- package/lib/modules/launch.js +32 -0
- package/lib/modules/location.d.ts +5 -0
- package/lib/modules/location.js +57 -0
- package/lib/modules/login.d.ts +5 -0
- package/lib/modules/login.js +72 -0
- package/lib/modules/network.d.ts +5 -0
- package/lib/modules/network.js +39 -0
- package/lib/modules/system.d.ts +5 -0
- package/lib/modules/system.js +65 -0
- package/lib/styles/animate-vue.scss +3 -0
- package/lib/styles/animate.scss +27 -0
- package/lib/styles/bg-vue.scss +21 -0
- package/lib/styles/bg.scss +93 -0
- package/lib/styles/border.scss +218 -0
- package/lib/styles/flex-nvue.scss +64 -0
- package/lib/styles/flex-vue.scss +75 -0
- package/lib/styles/font.scss +59 -0
- package/lib/styles/index.scss +25 -0
- package/lib/styles/layout-nvue.scss +24 -0
- package/lib/styles/layout-vue.scss +30 -0
- package/lib/styles/layout.scss +76 -0
- package/lib/styles/opacity.scss +10 -0
- package/lib/styles/reset-vue.scss +46 -0
- package/lib/styles/shadow.scss +12 -0
- package/lib/styles/sizing-vue.scss +21 -0
- package/lib/styles/sizing.scss +21 -0
- package/lib/styles/spacing.scss +234 -0
- package/lib/styles/text-nvue.scss +21 -0
- package/lib/styles/text-vue.scss +70 -0
- package/lib/styles/text.scss +122 -0
- package/lib/styles/var.module.scss +29 -0
- package/lib/utils/audio.d.ts +14 -0
- package/lib/utils/audio.js +43 -0
- package/lib/utils/consts.d.ts +30 -0
- package/lib/utils/consts.js +52 -0
- package/lib/utils/cos.d.ts +15 -0
- package/lib/utils/cos.js +140 -0
- package/lib/utils/debounce.d.ts +2 -0
- package/lib/utils/debounce.js +30 -0
- package/lib/utils/file.d.ts +28 -0
- package/lib/utils/file.js +292 -0
- package/lib/utils/index.d.ts +166 -0
- package/lib/utils/index.js +485 -0
- package/lib/utils/locale.d.ts +6 -0
- package/lib/utils/locale.js +19 -0
- package/lib/utils/message.d.ts +9 -0
- package/lib/utils/message.js +63 -0
- package/lib/utils/navigate.d.ts +27 -0
- package/lib/utils/navigate.js +183 -0
- package/lib/utils/pages.d.ts +21 -0
- package/lib/utils/pages.js +79 -0
- package/lib/utils/permission.d.ts +16 -0
- package/lib/utils/permission.js +291 -0
- package/lib/utils/permit.d.ts +30 -0
- package/lib/utils/permit.js +181 -0
- package/lib/utils/query.d.ts +13 -0
- package/lib/utils/query.js +14 -0
- package/lib/utils/request.d.ts +8 -0
- package/lib/utils/request.js +126 -0
- package/lib/utils/storage.d.ts +53 -0
- package/lib/utils/storage.js +145 -0
- package/lib/utils/subscribe.d.ts +7 -0
- package/lib/utils/subscribe.js +94 -0
- package/lib/utils/throttle.d.ts +2 -0
- package/lib/utils/throttle.js +32 -0
- package/lib/utils/toast.d.ts +17 -0
- package/lib/utils/toast.js +66 -0
- package/lib/utils/uni.d.ts +1 -0
- package/lib/utils/uni.js +147 -0
- package/lib/utils/update.d.ts +9 -0
- package/lib/utils/update.js +376 -0
- package/package.json +49 -0
- package/types/index.d.ts +25 -0
- package/types/virtual.d.ts +1 -0
|
@@ -0,0 +1,485 @@
|
|
|
1
|
+
import { IS_WEBVIEW_ENV, WEBVIEW_ENV } from './consts';
|
|
2
|
+
import toast from './toast';
|
|
3
|
+
/**
|
|
4
|
+
* 转换图片获取完整路径
|
|
5
|
+
* @param {Object} images 图片对象
|
|
6
|
+
* @param {String} path cdn地址
|
|
7
|
+
* @param {Boolean} useImages 是否使用images目录
|
|
8
|
+
*/
|
|
9
|
+
export function transformImagePath(images, path, useImages = false) {
|
|
10
|
+
Object.keys(images).forEach((key) => {
|
|
11
|
+
let value = images[key];
|
|
12
|
+
const dir = key.replace(/\$/g, '/');
|
|
13
|
+
if (value) {
|
|
14
|
+
if (/^https?:/.test(value)) {
|
|
15
|
+
images[key] = value;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
if (value.startsWith('?')) {
|
|
19
|
+
value = `.png${value}`;
|
|
20
|
+
}
|
|
21
|
+
images[key] = `${path}${useImages ? '/images' : ''}/${dir}${value}`;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
images[key] = `${path}${useImages ? '/images' : ''}/${dir}.png`;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
return images;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* @function 转换链接获取完整路径
|
|
32
|
+
* @param {Object} links 链接对象
|
|
33
|
+
* @param {String} path cdn地址
|
|
34
|
+
*/
|
|
35
|
+
export function transformLinkPath(links, path) {
|
|
36
|
+
Object.keys(links).forEach((key) => {
|
|
37
|
+
if (!links[key].url) {
|
|
38
|
+
links[key].url = `${path}/${key}.html`;
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
return links;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* 请求延迟
|
|
45
|
+
* @param {Function} fn 请求方法
|
|
46
|
+
* @param {Number} delay 延迟时间(毫秒)
|
|
47
|
+
* @return {Function}
|
|
48
|
+
*/
|
|
49
|
+
export function requestDelay(fn, delay = 500) {
|
|
50
|
+
return new Promise((res, rej) => {
|
|
51
|
+
const start = Date.now();
|
|
52
|
+
const func = (f, e) => {
|
|
53
|
+
const end = Date.now();
|
|
54
|
+
const diff = parseInt(String(end - start));
|
|
55
|
+
if (diff < delay) {
|
|
56
|
+
setTimeout(() => {
|
|
57
|
+
f(e);
|
|
58
|
+
}, delay - diff);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
f(e);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
fn()
|
|
65
|
+
.then((e) => {
|
|
66
|
+
func(res, e);
|
|
67
|
+
})
|
|
68
|
+
.catch((e) => {
|
|
69
|
+
func(rej, e);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* 将日期转换为时间戳
|
|
75
|
+
* @param {String, Number} date 时间字符串
|
|
76
|
+
* @return {String}
|
|
77
|
+
*/
|
|
78
|
+
export function dateStringToTime(date) {
|
|
79
|
+
if (typeof date === 'number') {
|
|
80
|
+
return date;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
date = String(date || '');
|
|
84
|
+
return date ? new Date(/\.[^.]+$/.test(date) ? date : date.replace(/-/g, '/')).getTime() : Date.now();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* 将日期末尾时间去除
|
|
89
|
+
* @param {String} date 时间字符串
|
|
90
|
+
* @return {String}
|
|
91
|
+
*/
|
|
92
|
+
export function cutDate(date) {
|
|
93
|
+
return String(date || '').replace(/\s+[^\s]+$/, '');
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* @function 计算时间距离当前时间多久
|
|
97
|
+
* @param {String,Number} time 时间
|
|
98
|
+
* @param {String} separate 时间分隔
|
|
99
|
+
* @return {String}
|
|
100
|
+
*/
|
|
101
|
+
export function timeFrom(time, separate = '-') {
|
|
102
|
+
if (typeof time === 'string') {
|
|
103
|
+
time = dateStringToTime(time);
|
|
104
|
+
}
|
|
105
|
+
if (!time || isNaN(time)) {
|
|
106
|
+
return '';
|
|
107
|
+
}
|
|
108
|
+
const current = new Date().getTime();
|
|
109
|
+
const diff = current - time;
|
|
110
|
+
const oneMinuteTime = 60 * 1000;
|
|
111
|
+
const oneHourTime = oneMinuteTime * 60;
|
|
112
|
+
const oneDayTime = oneHourTime * 24;
|
|
113
|
+
const twoDayTime = oneDayTime * 2;
|
|
114
|
+
const sevenDayTime = oneDayTime * 7;
|
|
115
|
+
// 小于1分钟
|
|
116
|
+
if (diff < oneMinuteTime) {
|
|
117
|
+
return `刚刚`;
|
|
118
|
+
}
|
|
119
|
+
// 小于1小时
|
|
120
|
+
else if (diff < oneHourTime) {
|
|
121
|
+
return `${parseInt(String(diff / oneMinuteTime))}分钟前`;
|
|
122
|
+
}
|
|
123
|
+
// 小于1天
|
|
124
|
+
else if (diff < oneDayTime) {
|
|
125
|
+
return `${parseInt(String(diff / oneHourTime))}小时前`;
|
|
126
|
+
}
|
|
127
|
+
// 大于1天小于2天
|
|
128
|
+
else if (diff >= oneDayTime && diff < twoDayTime) {
|
|
129
|
+
return `昨天 ${uni.$uv.timeFormat(time, 'hh:MM')}`;
|
|
130
|
+
}
|
|
131
|
+
// 大于2天小于7天
|
|
132
|
+
else if (diff >= twoDayTime && diff < sevenDayTime) {
|
|
133
|
+
return `${parseInt(String(diff / oneDayTime))}天前`;
|
|
134
|
+
}
|
|
135
|
+
// 大于7天
|
|
136
|
+
else {
|
|
137
|
+
if (new Date(current).getFullYear() === new Date(time).getFullYear()) {
|
|
138
|
+
return uni.$uv.timeFormat(time, `mm${separate}dd hh:MM`);
|
|
139
|
+
}
|
|
140
|
+
return uni.$uv.timeFormat(time, `yyyy${separate}mm${separate}dd hh:MM`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* 获取元素区域信息
|
|
145
|
+
* @param {String} id 元素ID
|
|
146
|
+
*/
|
|
147
|
+
export function getRectById(id) {
|
|
148
|
+
return new Promise((res, rej) => {
|
|
149
|
+
try {
|
|
150
|
+
const query = uni.createSelectorQuery().in(this);
|
|
151
|
+
query
|
|
152
|
+
.select(`#${id}`)
|
|
153
|
+
.boundingClientRect((data) => {
|
|
154
|
+
res({ data });
|
|
155
|
+
})
|
|
156
|
+
.exec();
|
|
157
|
+
}
|
|
158
|
+
catch (e) {
|
|
159
|
+
rej(e);
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* 路径转换
|
|
165
|
+
* @param {String} base 路径
|
|
166
|
+
* @param {String} path 路径
|
|
167
|
+
*/
|
|
168
|
+
export function joinPath(base = '', path = '') {
|
|
169
|
+
if (!path) {
|
|
170
|
+
return base;
|
|
171
|
+
}
|
|
172
|
+
if (path.startsWith('/')) {
|
|
173
|
+
return path;
|
|
174
|
+
}
|
|
175
|
+
const i = base.indexOf('?');
|
|
176
|
+
const j = path.indexOf('?');
|
|
177
|
+
let search = '';
|
|
178
|
+
if (i !== -1) {
|
|
179
|
+
base = base.substring(0, i);
|
|
180
|
+
}
|
|
181
|
+
if (j !== -1) {
|
|
182
|
+
search = path.substring(j);
|
|
183
|
+
path = path.substring(0, j);
|
|
184
|
+
}
|
|
185
|
+
const bases = base.split('/');
|
|
186
|
+
const paths = path.split('/');
|
|
187
|
+
let towPop = false;
|
|
188
|
+
paths.forEach((ele) => {
|
|
189
|
+
if (ele === '.') {
|
|
190
|
+
bases.pop();
|
|
191
|
+
}
|
|
192
|
+
else if (ele === '..') {
|
|
193
|
+
if (!towPop) {
|
|
194
|
+
bases.pop();
|
|
195
|
+
towPop = true;
|
|
196
|
+
}
|
|
197
|
+
bases.pop();
|
|
198
|
+
}
|
|
199
|
+
else if (ele) {
|
|
200
|
+
bases.push(ele);
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
return bases.join('/') + search;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* 发送消息
|
|
207
|
+
* @param {Object} data { type: '', payload: {} }
|
|
208
|
+
*/
|
|
209
|
+
export const postMessage = (data) => {
|
|
210
|
+
// #ifdef H5
|
|
211
|
+
if (IS_WEBVIEW_ENV) {
|
|
212
|
+
if (WEBVIEW_ENV.h5) {
|
|
213
|
+
parent.postMessage({
|
|
214
|
+
type: 'WEBVIEW_APP_MESSAGE',
|
|
215
|
+
data,
|
|
216
|
+
}, '*');
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
uni.webView?.postMessage({ data });
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
window.postMessage({
|
|
224
|
+
type: 'POST_MESSAGE',
|
|
225
|
+
data,
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
// #endif
|
|
229
|
+
};
|
|
230
|
+
/**
|
|
231
|
+
* 打开导航
|
|
232
|
+
* @param {Object} data 位置数据
|
|
233
|
+
*/
|
|
234
|
+
export function openLocation(data) {
|
|
235
|
+
uni.openLocation({
|
|
236
|
+
latitude: Number(data.latitude),
|
|
237
|
+
longitude: Number(data.longitude),
|
|
238
|
+
name: data.name,
|
|
239
|
+
address: data.address,
|
|
240
|
+
fail() {
|
|
241
|
+
toast.message('位置信息有误,导航失败!');
|
|
242
|
+
},
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* 将字符以空格拆分
|
|
247
|
+
* @param {String, Number} code 字符内容
|
|
248
|
+
* @param {Number[]} format 拆分格式
|
|
249
|
+
* @return {String} 拆分后的字符
|
|
250
|
+
* @example codeSplit(18888888888, [3, 4, 4]) => 138 8888 8888
|
|
251
|
+
*/
|
|
252
|
+
export function codeSplit(code = '', format = []) {
|
|
253
|
+
if (code) {
|
|
254
|
+
const temps = String(code).split(/\s*/);
|
|
255
|
+
const codes = [];
|
|
256
|
+
format.forEach((size) => {
|
|
257
|
+
codes.push(temps.splice(0, size).join(''));
|
|
258
|
+
});
|
|
259
|
+
if (temps.length) {
|
|
260
|
+
codes.push(temps.join(''));
|
|
261
|
+
}
|
|
262
|
+
return codes.join(' ').trim();
|
|
263
|
+
}
|
|
264
|
+
return '';
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* 调用父组件方法
|
|
268
|
+
* @param {String} name 方法名称
|
|
269
|
+
* @example parentCall.call(this, 'show')
|
|
270
|
+
*/
|
|
271
|
+
export function parentCall(...args) {
|
|
272
|
+
const [name, ...rest] = args;
|
|
273
|
+
if (name) {
|
|
274
|
+
let parent = this.$parent;
|
|
275
|
+
while (parent) {
|
|
276
|
+
if (typeof parent[name] === 'function') {
|
|
277
|
+
return parent[name](...rest);
|
|
278
|
+
}
|
|
279
|
+
parent = parent.$parent;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* 深度合并
|
|
285
|
+
* @param {Object} ...args 合并对象
|
|
286
|
+
*/
|
|
287
|
+
export function deepMerge(target, ...sources) {
|
|
288
|
+
function isObject(obj) {
|
|
289
|
+
return obj && typeof obj === 'object' && !Array.isArray(obj);
|
|
290
|
+
}
|
|
291
|
+
function mergeDeep(target, source) {
|
|
292
|
+
for (const key in source) {
|
|
293
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
294
|
+
if (isObject(source[key])) {
|
|
295
|
+
if (!isObject(target[key])) {
|
|
296
|
+
target[key] = {};
|
|
297
|
+
}
|
|
298
|
+
mergeDeep(target[key], source[key]);
|
|
299
|
+
}
|
|
300
|
+
else if (source[key] != null) {
|
|
301
|
+
target[key] = source[key];
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
for (const source of sources) {
|
|
307
|
+
mergeDeep(target, source);
|
|
308
|
+
}
|
|
309
|
+
return target;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* 返回页面并通信,除了uni.navigateBack选项外,新增method、emit、data选项
|
|
313
|
+
*/
|
|
314
|
+
export function navigateBack(options) {
|
|
315
|
+
if (options) {
|
|
316
|
+
const { method, emit, data, ...rest } = options;
|
|
317
|
+
const delta = rest.delta || 1;
|
|
318
|
+
if (method) {
|
|
319
|
+
const pages = getCurrentPages();
|
|
320
|
+
const prevPage = pages[pages.length - (delta + 1)];
|
|
321
|
+
if (method && prevPage && prevPage.$vm[method]) {
|
|
322
|
+
prevPage.$vm[method](data);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
else if (emit) {
|
|
326
|
+
uni.$emit(emit, data);
|
|
327
|
+
}
|
|
328
|
+
return uni.navigateBack(rest);
|
|
329
|
+
}
|
|
330
|
+
return uni.navigateBack(options);
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* 腾讯云存储资源压缩处理,用法参考https://cloud.tencent.com/document/product/436/42215
|
|
334
|
+
* @param url 原图像地址
|
|
335
|
+
* @param rule 处理规则,默认100x
|
|
336
|
+
* @param type 处理类型,默认thumbnail
|
|
337
|
+
* @returns 处理后图像地址
|
|
338
|
+
*/
|
|
339
|
+
export function cosCompress(url, rule = '100x', type = 'thumbnail') {
|
|
340
|
+
if (url) {
|
|
341
|
+
const params = `imageMogr2/${type}/${rule}/format/webp`;
|
|
342
|
+
if (url.lastIndexOf('?') === -1) {
|
|
343
|
+
return `${url}?${params}`;
|
|
344
|
+
}
|
|
345
|
+
if (url.lastIndexOf('imageMogr2/') === -1) {
|
|
346
|
+
return `${url}&${params}`;
|
|
347
|
+
}
|
|
348
|
+
return url;
|
|
349
|
+
}
|
|
350
|
+
return '';
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* 拨打电话
|
|
354
|
+
* @param {String} phoneNumber 手机号
|
|
355
|
+
*/
|
|
356
|
+
export function phoneCall(phoneNumber) {
|
|
357
|
+
if (phoneNumber) {
|
|
358
|
+
uni.makePhoneCall({
|
|
359
|
+
phoneNumber,
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* 复制内容到剪切板
|
|
365
|
+
* @param {String} text 复制内容
|
|
366
|
+
* @param {String} tips 复制成功提示
|
|
367
|
+
*/
|
|
368
|
+
export function copyToClipboard(text = '', tips = '内容已复制') {
|
|
369
|
+
if (text) {
|
|
370
|
+
uni.setClipboardData({
|
|
371
|
+
data: text,
|
|
372
|
+
showToast: false,
|
|
373
|
+
success() {
|
|
374
|
+
// #ifndef MP-WEIXIN
|
|
375
|
+
// 微信小程序默认弹出“内容已复制”
|
|
376
|
+
toast.message(tips, {
|
|
377
|
+
position: 'bottom',
|
|
378
|
+
});
|
|
379
|
+
// #endif
|
|
380
|
+
},
|
|
381
|
+
fail(e) {
|
|
382
|
+
toast.message(e?.errMsg, {
|
|
383
|
+
position: 'bottom',
|
|
384
|
+
});
|
|
385
|
+
},
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
else {
|
|
389
|
+
toast.message('复制内容不能为空', {
|
|
390
|
+
position: 'bottom',
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* 隐藏值
|
|
396
|
+
* @param {String} str 内容
|
|
397
|
+
* @param {Number} start 开头显示数量
|
|
398
|
+
* @param {end} phone 末尾显示数量
|
|
399
|
+
* @returns {String}
|
|
400
|
+
*/
|
|
401
|
+
export function hiddenValue(str = '', start = 0, end = 0) {
|
|
402
|
+
str = String(str || '');
|
|
403
|
+
const size = str.length;
|
|
404
|
+
let startStr = '';
|
|
405
|
+
let endStr = '';
|
|
406
|
+
let centerStr = '';
|
|
407
|
+
if (start <= 0) {
|
|
408
|
+
start = 0;
|
|
409
|
+
}
|
|
410
|
+
if (end <= 0) {
|
|
411
|
+
end = 0;
|
|
412
|
+
}
|
|
413
|
+
if (size <= start || size <= end) {
|
|
414
|
+
centerStr = str;
|
|
415
|
+
}
|
|
416
|
+
else {
|
|
417
|
+
startStr = str.slice(0, start);
|
|
418
|
+
if (end > 0) {
|
|
419
|
+
endStr = str.slice(-1 * end);
|
|
420
|
+
}
|
|
421
|
+
centerStr = new Array(Math.max(size - start - end, 0)).fill('*').join('');
|
|
422
|
+
}
|
|
423
|
+
return `${startStr}${centerStr}${endStr}`;
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* 隐藏手机号
|
|
427
|
+
* @param {Number} phone 手机号
|
|
428
|
+
* @returns {String}
|
|
429
|
+
*/
|
|
430
|
+
export function hiddenPhone(phone) {
|
|
431
|
+
return String(phone || '').replace(/^(\d{3})\d{4}(\d+)$/, '$1****$2');
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* 格式化手机号
|
|
435
|
+
* @param {Number} phone 手机号
|
|
436
|
+
* @returns {String}
|
|
437
|
+
*/
|
|
438
|
+
export function formatPhone(phone) {
|
|
439
|
+
return String(phone || '').replace(/^(\d{3})(\d{4})(\d+)$/, '$1 $2 $3');
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* 数字四舍五入
|
|
443
|
+
* @param {Number} value 数值
|
|
444
|
+
* @param {Number} decimal 保留位数
|
|
445
|
+
* @returns {String}
|
|
446
|
+
*/
|
|
447
|
+
export function toFixed(value, decimal = 2) {
|
|
448
|
+
value = parseFloat(value);
|
|
449
|
+
if (isNaN(value)) {
|
|
450
|
+
value = 0;
|
|
451
|
+
}
|
|
452
|
+
if (decimal <= 0) {
|
|
453
|
+
return String(value);
|
|
454
|
+
}
|
|
455
|
+
return value.toFixed(decimal);
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* @function 选项数据转对象数据
|
|
459
|
+
* @param {Array} data 数据对象
|
|
460
|
+
* @return {Object}
|
|
461
|
+
*/
|
|
462
|
+
export function OptionsToObject(data) {
|
|
463
|
+
const obj = {};
|
|
464
|
+
if (Array.isArray(data)) {
|
|
465
|
+
data.forEach(({ label, value }) => {
|
|
466
|
+
obj[value] = label;
|
|
467
|
+
obj[label] = value;
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
return obj;
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* 简化数字,123显示100+
|
|
474
|
+
* @param {Number} num 数字
|
|
475
|
+
* @param {Number} min 最小值
|
|
476
|
+
* @return {String}
|
|
477
|
+
*/
|
|
478
|
+
export function numberPlus(num, min = 100) {
|
|
479
|
+
const value = Math.abs(Number(num) | 0);
|
|
480
|
+
if (value < min) {
|
|
481
|
+
return String(value);
|
|
482
|
+
}
|
|
483
|
+
const str = String(value);
|
|
484
|
+
return str.substring(0, 1).padEnd(str.length, '0') + '+';
|
|
485
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const defaultLocale = uni.getLocale();
|
|
2
|
+
export const fallbackLocale = 'zh-Hans';
|
|
3
|
+
function applyNamedPlaceholders(str, values) {
|
|
4
|
+
if (!values || typeof str !== 'string') {
|
|
5
|
+
return str;
|
|
6
|
+
}
|
|
7
|
+
let out = str;
|
|
8
|
+
for (const k of Object.keys(values)) {
|
|
9
|
+
out = out.split(`{${k}}`).join(String(values[k]));
|
|
10
|
+
}
|
|
11
|
+
return out;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* nvue 下 inject 未提供 t 时的回退;第二参数为命名占位 {n} 等
|
|
15
|
+
*/
|
|
16
|
+
export function showLocale(key, values) {
|
|
17
|
+
const raw = uni.$messages[uni.getLocale()]?.[key] || uni.$messages[fallbackLocale]?.[key] || key;
|
|
18
|
+
return applyNamedPlaceholders(raw, values);
|
|
19
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export const TYPES = {
|
|
2
|
+
LOGIN: '',
|
|
3
|
+
SHARE_PAGE: '',
|
|
4
|
+
GET_LOCATION: '',
|
|
5
|
+
OPEN_LOCATION: '',
|
|
6
|
+
CHNAGE_TITLE: '',
|
|
7
|
+
SAVE_IMAGE: '',
|
|
8
|
+
HIDE_LOADING: '',
|
|
9
|
+
};
|
|
10
|
+
Object.keys(TYPES).forEach((key) => {
|
|
11
|
+
TYPES[key] = key;
|
|
12
|
+
});
|
|
13
|
+
// #ifdef H5
|
|
14
|
+
window.onmessage = (e) => {
|
|
15
|
+
try {
|
|
16
|
+
if (e.data.type === 'WEBVIEW_MESSAGE') {
|
|
17
|
+
uni.$emit('WEBVIEW_MESSAGE', e.data.data);
|
|
18
|
+
const { type, payload } = e.data.data;
|
|
19
|
+
switch (type) {
|
|
20
|
+
case TYPES.LOGIN: {
|
|
21
|
+
const { token, referrer } = payload;
|
|
22
|
+
uni.$store.commit('setLoginInfo', { token });
|
|
23
|
+
uni.$store.dispatch('getInfo');
|
|
24
|
+
if (referrer) {
|
|
25
|
+
// 必须使用reLaunch,否则跳转可能无效
|
|
26
|
+
uni.reLaunch({
|
|
27
|
+
url: referrer,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
case TYPES.GET_LOCATION: {
|
|
33
|
+
if (uni.getLocationCallback) {
|
|
34
|
+
Object.keys({ ...payload, complete: undefined }).forEach((key) => {
|
|
35
|
+
if (uni.getLocationCallback && uni.getLocationCallback[key]) {
|
|
36
|
+
uni.getLocationCallback[key](payload[key]);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
delete uni.getLocationCallback;
|
|
40
|
+
}
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
case TYPES.OPEN_LOCATION: {
|
|
44
|
+
if (uni.openLocationCallback) {
|
|
45
|
+
Object.keys({ ...payload, complete: undefined }).forEach((key) => {
|
|
46
|
+
if (uni.openLocationCallback && uni.openLocationCallback[key]) {
|
|
47
|
+
uni.openLocationCallback[key](payload[key]);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
delete uni.openLocationCallback;
|
|
51
|
+
}
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
case TYPES.HIDE_LOADING: {
|
|
55
|
+
uni.hideLoading();
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
catch (e) { }
|
|
62
|
+
};
|
|
63
|
+
// #endif
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { NavigateType, ReferrerType } from '../configs/navigate';
|
|
2
|
+
type Type = NavigateType | 'switchTab';
|
|
3
|
+
interface NavigateExtendOptions {
|
|
4
|
+
type?: Type;
|
|
5
|
+
loginType?: NavigateType;
|
|
6
|
+
referrerType?: ReferrerType;
|
|
7
|
+
params?: {
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
};
|
|
10
|
+
webviewParams?: {
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
};
|
|
13
|
+
needLogin?: boolean;
|
|
14
|
+
native?: boolean;
|
|
15
|
+
}
|
|
16
|
+
interface NavigateOptions extends UniNamespace.NavigateToOptions, NavigateExtendOptions {
|
|
17
|
+
}
|
|
18
|
+
declare const navigate: {
|
|
19
|
+
(url?: string | NavigateOptions, type?: Type): boolean;
|
|
20
|
+
reLaunch(url: string | NavigateOptions): void;
|
|
21
|
+
navigateTo(url: string | NavigateOptions): void;
|
|
22
|
+
switchTab(url: string | NavigateOptions): void;
|
|
23
|
+
redirectTo(url: string | NavigateOptions): void;
|
|
24
|
+
back(e: UniNamespace.NavigateBackOptions): void;
|
|
25
|
+
interceptor(...args: string[]): string;
|
|
26
|
+
};
|
|
27
|
+
export default navigate;
|