@zfqh/uniapp-x 0.0.0-stage → 0.0.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 +36 -0
- package/LICENSE +21 -0
- package/README.md +61 -3
- package/lib/apis/core.d.ts +18 -0
- package/lib/apis/core.js +19 -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 +57 -0
- package/lib/configs/api.d.ts +7 -0
- package/lib/configs/api.js +6 -0
- package/lib/configs/app.d.ts +20 -0
- package/lib/configs/app.js +18 -0
- package/lib/configs/cdn.d.ts +15 -0
- package/lib/configs/cdn.js +17 -0
- package/lib/configs/env.d.ts +37 -0
- package/lib/configs/env.js +71 -0
- package/lib/configs/index.d.ts +130 -0
- package/lib/configs/index.js +76 -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/updater.d.ts +15 -0
- package/lib/configs/updater.js +33 -0
- package/lib/configs/upload.d.ts +30 -0
- package/lib/configs/upload.js +19 -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 +11 -0
- package/lib/hooks/index.js +11 -0
- package/lib/hooks/useAppLifecycle.d.ts +8 -0
- package/lib/hooks/useAppLifecycle.js +87 -0
- package/lib/hooks/useBadge.d.ts +8 -0
- package/lib/hooks/useBadge.js +47 -0
- package/lib/hooks/useNeedLogin.d.ts +1 -0
- package/lib/hooks/useNeedLogin.js +27 -0
- package/lib/hooks/useOverlay.d.ts +1 -0
- package/lib/hooks/useOverlay.js +17 -0
- package/lib/hooks/usePageShow.d.ts +2 -0
- package/lib/hooks/usePageShow.js +16 -0
- package/lib/hooks/usePopup.d.ts +1 -0
- package/lib/hooks/usePopup.js +14 -0
- package/lib/hooks/useRedirect.d.ts +5 -0
- package/lib/hooks/useRedirect.js +92 -0
- package/lib/hooks/useReferrer.d.ts +1 -0
- package/lib/hooks/useReferrer.js +11 -0
- package/lib/hooks/useShare.d.ts +12 -0
- package/lib/hooks/useShare.js +49 -0
- package/lib/hooks/useVersion.d.ts +6 -0
- package/lib/hooks/useVersion.js +21 -0
- package/lib/hooks/useWebview.d.ts +14 -0
- package/lib/hooks/useWebview.js +294 -0
- package/lib/index.d.ts +27 -0
- package/lib/index.js +26 -0
- package/lib/stores/app.d.ts +51 -0
- package/lib/stores/app.js +57 -0
- package/lib/stores/dict.d.ts +35 -0
- package/lib/stores/dict.js +42 -0
- package/lib/stores/im.d.ts +57 -0
- package/lib/stores/im.js +102 -0
- package/lib/stores/index.d.ts +12 -0
- package/lib/stores/index.js +17 -0
- package/lib/stores/launch.d.ts +42 -0
- package/lib/stores/launch.js +39 -0
- package/lib/stores/location.d.ts +35 -0
- package/lib/stores/location.js +58 -0
- package/lib/stores/login.d.ts +80 -0
- package/lib/stores/login.js +91 -0
- package/lib/stores/network.d.ts +26 -0
- package/lib/stores/network.js +45 -0
- package/lib/stores/pinia.d.ts +2 -0
- package/lib/stores/pinia.js +3 -0
- package/lib/stores/system.d.ts +39 -0
- package/lib/stores/system.js +36 -0
- package/lib/styles/index.scss +9 -0
- package/lib/styles/reset-vue.scss +15 -0
- package/lib/utils/audio.d.ts +14 -0
- package/lib/utils/audio.js +43 -0
- package/lib/utils/consts.d.ts +74 -0
- package/lib/utils/consts.js +110 -0
- package/lib/utils/cos.d.ts +17 -0
- package/lib/utils/cos.js +141 -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 +486 -0
- package/lib/utils/message.d.ts +1 -0
- package/lib/utils/message.js +55 -0
- package/lib/utils/navigate.d.ts +28 -0
- package/lib/utils/navigate.js +192 -0
- package/lib/utils/pages.d.ts +21 -0
- package/lib/utils/pages.js +83 -0
- package/lib/utils/permission.d.ts +17 -0
- package/lib/utils/permission.js +278 -0
- package/lib/utils/query.d.ts +20 -0
- package/lib/utils/query.js +51 -0
- package/lib/utils/request.d.ts +8 -0
- package/lib/utils/request.js +139 -0
- package/lib/utils/storage.d.ts +40 -0
- package/lib/utils/storage.js +128 -0
- package/lib/utils/subscribe.d.ts +7 -0
- package/lib/utils/subscribe.js +94 -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 +141 -0
- package/lib/utils/update.d.ts +41 -0
- package/lib/utils/update.js +322 -0
- package/lib/utils/url.d.ts +14 -0
- package/lib/utils/url.js +40 -0
- package/package.json +38 -4
- package/types/index.d.ts +78 -0
- package/types/virtual.d.ts +1 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { onLoad, onPageShow } from '@dcloudio/uni-app';
|
|
2
|
+
import { parseQuery } from '../utils/query';
|
|
3
|
+
import navigate from '../utils/navigate';
|
|
4
|
+
import { inPages } from '../utils/pages';
|
|
5
|
+
import page from '../configs/page';
|
|
6
|
+
import pathConfig from '../configs/path';
|
|
7
|
+
import { IS_WEBVIEW_ENV, TYPES } from '../utils/consts';
|
|
8
|
+
import { pinia } from '../stores/pinia';
|
|
9
|
+
import { useLoginStore } from '../stores/login';
|
|
10
|
+
/** 登录后重定向 */
|
|
11
|
+
export function useRedirect(webview) {
|
|
12
|
+
const loginStore = useLoginStore(pinia);
|
|
13
|
+
onLoad((options = {}) => {
|
|
14
|
+
const { __referrer, __navigate } = options;
|
|
15
|
+
if (__referrer) {
|
|
16
|
+
// 由登录拦截器跳转本页面,记录来源
|
|
17
|
+
pathConfig['referrer'] = decodeURIComponent(__referrer);
|
|
18
|
+
}
|
|
19
|
+
else if (__navigate) {
|
|
20
|
+
// 登录成功,跳回来源页面后,若需要重定向,则跳转
|
|
21
|
+
navigate(__navigate.startsWith('/') ? __navigate : decodeURIComponent(__navigate), __navigate ? 'navigateTo' : 'redirectTo');
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
onPageShow(() => {
|
|
25
|
+
const routes = getCurrentPages();
|
|
26
|
+
const current = `/${routes.pop()?.route}`;
|
|
27
|
+
if (!loginStore.isLogin) {
|
|
28
|
+
// #ifdef H5
|
|
29
|
+
// 防止登录后,返回webview页面再次跳转登录页面
|
|
30
|
+
if (IS_WEBVIEW_ENV) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
// #endif
|
|
34
|
+
// 检测页面是否跳转登录
|
|
35
|
+
if (inPages(page.needLoginPages, current)) {
|
|
36
|
+
navigate({ url: '', needLogin: true });
|
|
37
|
+
}
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
// 禁止跳转
|
|
41
|
+
if (inPages(page.notRedirectPages, current)) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const url = pathConfig['referrer'];
|
|
45
|
+
if (url) {
|
|
46
|
+
pathConfig['referrer'] = '';
|
|
47
|
+
const isCurrent = url.startsWith(current);
|
|
48
|
+
if (webview) {
|
|
49
|
+
// 登录后,跳回的页面是webview页面,则需要重新加载该页面
|
|
50
|
+
// #ifdef MP
|
|
51
|
+
if (inPages(page.tabBarPages, current)) {
|
|
52
|
+
// tabbar页面无法在原页面刷新,直接 reLaunch 重新打开来源页
|
|
53
|
+
uni.reLaunch({
|
|
54
|
+
url,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
// 非tabbar页面,重新打开页面
|
|
59
|
+
uni[routes.length >= 2 ? 'redirectTo' : 'reLaunch']({
|
|
60
|
+
url,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
// #endif
|
|
64
|
+
// #ifndef MP
|
|
65
|
+
const { accessToken = '' } = loginStore.state;
|
|
66
|
+
const [, search] = url.split('?');
|
|
67
|
+
const { url: _url } = parseQuery(search || '');
|
|
68
|
+
webview.postMessage({
|
|
69
|
+
type: TYPES.MESSAGE.LOGIN,
|
|
70
|
+
payload: {
|
|
71
|
+
accessToken,
|
|
72
|
+
referrer: decodeURIComponent(_url),
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
// #endif
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
if (isCurrent) {
|
|
79
|
+
const [, __navigate] = url.split('__navigate=');
|
|
80
|
+
if (__navigate) {
|
|
81
|
+
// 跳回其他页面,则判断参数是否需要重定向
|
|
82
|
+
navigate(__navigate.startsWith('/') ? __navigate : decodeURIComponent(__navigate));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
// 登录后返回其他页面,比如reLaunch到首页,则重新跳转到原页面
|
|
87
|
+
navigate(url);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useReferrer(): import("vue").Ref<string>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ref } from 'vue';
|
|
2
|
+
import { onLoad } from '@dcloudio/uni-app';
|
|
3
|
+
export function useReferrer() {
|
|
4
|
+
const referrer = ref('');
|
|
5
|
+
onLoad((options) => {
|
|
6
|
+
if (options?.__referrer) {
|
|
7
|
+
referrer.value = decodeURIComponent(options.__referrer);
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
return referrer;
|
|
11
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type MaybeRefOrGetter } from 'vue';
|
|
2
|
+
export interface ShareData {
|
|
3
|
+
title?: string;
|
|
4
|
+
path?: string;
|
|
5
|
+
content?: string;
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
}
|
|
8
|
+
/** 分享数据 */
|
|
9
|
+
export declare function useShare(shareData?: MaybeRefOrGetter<ShareData>): {
|
|
10
|
+
mergeShareData: import("vue").ComputedRef<ShareData>;
|
|
11
|
+
sendShareDataMessage: () => void;
|
|
12
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { computed, toValue, watch } from 'vue';
|
|
2
|
+
import { onPageShow, onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app';
|
|
3
|
+
import { queryParams } from '@zfqh/uview-x/utils/function';
|
|
4
|
+
import { IS_WEBVIEW_ENV, TYPES } from '../utils/consts';
|
|
5
|
+
import { postMessage } from '../utils/index';
|
|
6
|
+
/** 分享数据 */
|
|
7
|
+
export function useShare(shareData = {}) {
|
|
8
|
+
const mergeShareData = computed(() => {
|
|
9
|
+
const { route = '', options = {} } = getCurrentPages().pop() || {};
|
|
10
|
+
return {
|
|
11
|
+
path: `/${route}${queryParams(options)}`,
|
|
12
|
+
content: '',
|
|
13
|
+
// #ifdef H5
|
|
14
|
+
title: document.title,
|
|
15
|
+
// #endif
|
|
16
|
+
...toValue(shareData),
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
function sendShareDataMessage() {
|
|
20
|
+
// #ifdef H5
|
|
21
|
+
if (IS_WEBVIEW_ENV) {
|
|
22
|
+
try {
|
|
23
|
+
postMessage({
|
|
24
|
+
type: TYPES.MESSAGE.SHARE_PAGE,
|
|
25
|
+
payload: mergeShareData.value,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
catch (e) { }
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
uni.showShareMenu(mergeShareData.value);
|
|
32
|
+
}
|
|
33
|
+
// #endif
|
|
34
|
+
}
|
|
35
|
+
// #ifdef H5
|
|
36
|
+
watch(() => toValue(shareData), sendShareDataMessage, { deep: true });
|
|
37
|
+
onPageShow(() => {
|
|
38
|
+
sendShareDataMessage();
|
|
39
|
+
});
|
|
40
|
+
// #endif
|
|
41
|
+
// #ifdef MP
|
|
42
|
+
onShareAppMessage(() => mergeShareData.value);
|
|
43
|
+
onShareTimeline(() => mergeShareData.value);
|
|
44
|
+
// #endif
|
|
45
|
+
return {
|
|
46
|
+
mergeShareData,
|
|
47
|
+
sendShareDataMessage,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { reactive } from 'vue';
|
|
2
|
+
import ver from '../configs/ver';
|
|
3
|
+
export function useVersion() {
|
|
4
|
+
const version = reactive({
|
|
5
|
+
name: ver.name,
|
|
6
|
+
code: ver.code,
|
|
7
|
+
});
|
|
8
|
+
// #ifdef APP-PLUS
|
|
9
|
+
plus.runtime.getProperty(plus.runtime.appid, (res) => {
|
|
10
|
+
if (!version.name) {
|
|
11
|
+
version.name = res.version;
|
|
12
|
+
}
|
|
13
|
+
if (!version.code) {
|
|
14
|
+
version.code = Number(res.versionCode);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
// #endif
|
|
18
|
+
return {
|
|
19
|
+
version,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type MaybeRef, type Ref } from 'vue';
|
|
2
|
+
import type { ShareData } from './useShare';
|
|
3
|
+
export interface UseWebviewOptions {
|
|
4
|
+
/** H5 下承载页根节点,用于向 iframe 发送消息;缺省回退组件实例 $el */
|
|
5
|
+
root?: MaybeRef<Element | null | undefined>;
|
|
6
|
+
}
|
|
7
|
+
export interface UseWebviewReturn {
|
|
8
|
+
shareData: Ref<ShareData>;
|
|
9
|
+
webviewUrl: Ref<string>;
|
|
10
|
+
onMessage: (e: any) => Promise<void>;
|
|
11
|
+
postMessage: (data: any) => void;
|
|
12
|
+
}
|
|
13
|
+
/** webview 承载页逻辑 */
|
|
14
|
+
export declare function useWebview(options?: UseWebviewOptions): UseWebviewReturn;
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import { computed, getCurrentInstance, nextTick, ref, toValue, watch } from 'vue';
|
|
2
|
+
import { onLoad, onPageShow, onReady, onUnload } from '@dcloudio/uni-app';
|
|
3
|
+
import { queryParams } from '@zfqh/uview-x/utils/function';
|
|
4
|
+
import { getLocale } from '@zfqh/uview-x';
|
|
5
|
+
import SimpleUrl from '../utils/url';
|
|
6
|
+
import { parseQuery, stringifyQuery } from '../utils/query';
|
|
7
|
+
import { PLATFORM_CODE, IS_WEBVIEW_ENV, SYSTEM_INFO, TYPES, LANGUAGE } from '../utils/consts';
|
|
8
|
+
import appConfig from '../configs/app';
|
|
9
|
+
import { requestPermission, openAuthorizeSetting } from '../utils/permission';
|
|
10
|
+
import web from '../configs/web';
|
|
11
|
+
import cdn from '../configs/cdn';
|
|
12
|
+
import link from '../configs/link';
|
|
13
|
+
import pathConfig from '../configs/path';
|
|
14
|
+
import { base64ToPath } from '../utils/file';
|
|
15
|
+
import query from '../utils/query';
|
|
16
|
+
import { pinia } from '../stores/pinia';
|
|
17
|
+
import { useLoginStore } from '../stores/login';
|
|
18
|
+
import { usePageShow } from './usePageShow';
|
|
19
|
+
/** webview 承载页逻辑 */
|
|
20
|
+
export function useWebview(options = {}) {
|
|
21
|
+
const instance = getCurrentInstance();
|
|
22
|
+
const loginStore = useLoginStore(pinia);
|
|
23
|
+
const pageShow = usePageShow();
|
|
24
|
+
const shareData = ref({});
|
|
25
|
+
const params = ref({});
|
|
26
|
+
const webviewUrl = ref('');
|
|
27
|
+
const changed = ref(true);
|
|
28
|
+
let initialParams = {};
|
|
29
|
+
let webView = null;
|
|
30
|
+
let post = null;
|
|
31
|
+
let onWindowMessage = null;
|
|
32
|
+
let isIframe = false;
|
|
33
|
+
const queryString = computed(() => {
|
|
34
|
+
const { accessToken, storeId, userId, tenantId, storeName, tenantName, nickName, username } = loginStore.state || {};
|
|
35
|
+
// 语言取 @zfqh/uview-x 的 getLocale()(storage / 系统语言,始终有值);
|
|
36
|
+
// 未创建 i18n 实例时也会带上系统语言,不再依赖实例上的 locale Ref
|
|
37
|
+
const locale = getLocale();
|
|
38
|
+
const q = {
|
|
39
|
+
token: accessToken,
|
|
40
|
+
storeId,
|
|
41
|
+
userId,
|
|
42
|
+
tenantId,
|
|
43
|
+
storeName,
|
|
44
|
+
tenantName,
|
|
45
|
+
nickName,
|
|
46
|
+
username,
|
|
47
|
+
app: appConfig.code || appConfig.appId,
|
|
48
|
+
channel: appConfig.channel,
|
|
49
|
+
platform: PLATFORM_CODE,
|
|
50
|
+
safeTop: SYSTEM_INFO.safeAreaInsets.top,
|
|
51
|
+
safeBottom: SYSTEM_INFO.safeAreaInsets.bottom,
|
|
52
|
+
locale,
|
|
53
|
+
xLanguage: LANGUAGE[locale],
|
|
54
|
+
accelerate: cdn.isAccelerate ? 1 : undefined,
|
|
55
|
+
};
|
|
56
|
+
if (query.primary) {
|
|
57
|
+
if (String(query.primary).startsWith('#')) {
|
|
58
|
+
query.primary = encodeURIComponent(query.primary);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return stringifyQuery(q, { encode: false });
|
|
62
|
+
});
|
|
63
|
+
watch(queryString, () => {
|
|
64
|
+
changed.value = 'changed';
|
|
65
|
+
});
|
|
66
|
+
function getRootEl() {
|
|
67
|
+
const provided = toValue(options.root);
|
|
68
|
+
if (provided) {
|
|
69
|
+
return provided;
|
|
70
|
+
}
|
|
71
|
+
return instance?.proxy?.$el;
|
|
72
|
+
}
|
|
73
|
+
async function onMessage(e) {
|
|
74
|
+
try {
|
|
75
|
+
const { type, payload } = e.detail.data.pop();
|
|
76
|
+
switch (type) {
|
|
77
|
+
case TYPES.MESSAGE.SAVE_IMAGE: {
|
|
78
|
+
const { data } = payload;
|
|
79
|
+
await requestPermission('storage');
|
|
80
|
+
const filePath = await base64ToPath(data);
|
|
81
|
+
uni.saveImageToPhotosAlbum({
|
|
82
|
+
filePath,
|
|
83
|
+
success() {
|
|
84
|
+
uni.showToast({
|
|
85
|
+
title: '已保存到相册',
|
|
86
|
+
position: 'bottom',
|
|
87
|
+
});
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
case TYPES.MESSAGE.CHNAGE_TITLE: {
|
|
93
|
+
const { title } = payload;
|
|
94
|
+
uni.setNavigationBarTitle({
|
|
95
|
+
title,
|
|
96
|
+
});
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
case TYPES.MESSAGE.SHARE_PAGE: {
|
|
100
|
+
if (!payload.path) {
|
|
101
|
+
uni.share(payload);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
const { path, ...shareRest } = payload;
|
|
105
|
+
const { route } = getCurrentPages().pop();
|
|
106
|
+
const currentParams = { ...params.value };
|
|
107
|
+
delete currentParams.url;
|
|
108
|
+
shareData.value = {
|
|
109
|
+
...shareRest,
|
|
110
|
+
path: `/${route}${queryParams({ url: encodeURIComponent(path), ...currentParams })}`,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
case TYPES.MESSAGE.PERM_LOCATION:
|
|
116
|
+
case TYPES.MESSAGE.PERM_BLUETOOTH: {
|
|
117
|
+
openAuthorizeSetting(payload.name);
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
case TYPES.MESSAGE.GET_LOCATION:
|
|
121
|
+
case TYPES.MESSAGE.OPEN_LOCATION: {
|
|
122
|
+
const messageType = TYPES.MESSAGE.GET_LOCATION || TYPES.MESSAGE.OPEN_LOCATION;
|
|
123
|
+
const success = (data) => {
|
|
124
|
+
postMessage({
|
|
125
|
+
type: messageType,
|
|
126
|
+
payload: {
|
|
127
|
+
success: data,
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
const fail = (data) => {
|
|
132
|
+
postMessage({
|
|
133
|
+
type: messageType,
|
|
134
|
+
payload: {
|
|
135
|
+
fail: data,
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
};
|
|
139
|
+
try {
|
|
140
|
+
await requestPermission('location');
|
|
141
|
+
uni.getLocation({
|
|
142
|
+
...payload,
|
|
143
|
+
success,
|
|
144
|
+
fail,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
fail(error);
|
|
149
|
+
}
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
catch (e) { }
|
|
155
|
+
}
|
|
156
|
+
function postMessage(data) {
|
|
157
|
+
try {
|
|
158
|
+
if (!post) {
|
|
159
|
+
// #ifdef H5
|
|
160
|
+
let ele = getRootEl();
|
|
161
|
+
if (ele?.tagName !== 'IFRAME') {
|
|
162
|
+
ele =
|
|
163
|
+
ele?.parentNode?.querySelector?.('iframe') || document.querySelector(`iframe[src="${webviewUrl.value}"]`);
|
|
164
|
+
}
|
|
165
|
+
webView = ele?.contentWindow;
|
|
166
|
+
post = (payload) => {
|
|
167
|
+
webView?.postMessage({ type: 'WEBVIEW_MESSAGE', data: payload }, '*');
|
|
168
|
+
};
|
|
169
|
+
// #endif
|
|
170
|
+
// #ifdef APP-PLUS
|
|
171
|
+
webView = instance?.proxy?.$scope?.$getAppWebview()?.children()?.[0];
|
|
172
|
+
post = (payload) => {
|
|
173
|
+
webView?.evalJS(`window.onmessage({ data: { type: 'WEBVIEW_MESSAGE', data: ${JSON.stringify(payload)} } })`);
|
|
174
|
+
};
|
|
175
|
+
// #endif
|
|
176
|
+
}
|
|
177
|
+
post?.(data);
|
|
178
|
+
}
|
|
179
|
+
catch (e) { }
|
|
180
|
+
}
|
|
181
|
+
function initUrl() {
|
|
182
|
+
const currentParams = params.value;
|
|
183
|
+
if (currentParams.url) {
|
|
184
|
+
currentParams.url = decodeURIComponent(currentParams.url);
|
|
185
|
+
if (/^%/.test(currentParams.url)) {
|
|
186
|
+
currentParams.url = decodeURIComponent(currentParams.url);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const { type, app: _app, url: _url, ...rest } = currentParams;
|
|
190
|
+
let url = _url;
|
|
191
|
+
let title = rest.title;
|
|
192
|
+
let src = '';
|
|
193
|
+
if (_app && web[_app] && /^(https?|file):/.test(web[_app])) {
|
|
194
|
+
const u = new SimpleUrl(web[_app], true);
|
|
195
|
+
u.set('query', {
|
|
196
|
+
...u.query,
|
|
197
|
+
...parseQuery(queryString.value),
|
|
198
|
+
...rest,
|
|
199
|
+
_: Date.now(),
|
|
200
|
+
});
|
|
201
|
+
u.set('hash', `#${url}`);
|
|
202
|
+
src = u.toString();
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
if (link && link[type]) {
|
|
206
|
+
const { url: _linkUrl, title: _title } = link[type];
|
|
207
|
+
if (_linkUrl) {
|
|
208
|
+
url = _linkUrl;
|
|
209
|
+
}
|
|
210
|
+
if (_title) {
|
|
211
|
+
title = _title;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if (url && /^(https?|file):/.test(url)) {
|
|
215
|
+
const u = new SimpleUrl(url, true);
|
|
216
|
+
u.set('query', { ...u.query, _: Date.now() });
|
|
217
|
+
src = u.toString();
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
if (title) {
|
|
221
|
+
uni.setNavigationBarTitle({
|
|
222
|
+
title,
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
webviewUrl.value = src;
|
|
226
|
+
}
|
|
227
|
+
onLoad((p) => {
|
|
228
|
+
params.value = {
|
|
229
|
+
...params.value,
|
|
230
|
+
...p,
|
|
231
|
+
};
|
|
232
|
+
initialParams = {
|
|
233
|
+
...params.value,
|
|
234
|
+
};
|
|
235
|
+
});
|
|
236
|
+
onPageShow(async () => {
|
|
237
|
+
if (changed.value !== true) {
|
|
238
|
+
await nextTick();
|
|
239
|
+
}
|
|
240
|
+
if (changed.value === true || (changed.value === 'changed' && !pathConfig['referrer'])) {
|
|
241
|
+
params.value = {
|
|
242
|
+
...initialParams,
|
|
243
|
+
};
|
|
244
|
+
initUrl();
|
|
245
|
+
changed.value = false;
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
onReady(() => {
|
|
249
|
+
// #ifdef H5
|
|
250
|
+
if (!IS_WEBVIEW_ENV) {
|
|
251
|
+
onWindowMessage = (e) => {
|
|
252
|
+
if (pageShow.value) {
|
|
253
|
+
try {
|
|
254
|
+
if (e.data.type === 'WEBVIEW_APP_MESSAGE') {
|
|
255
|
+
onMessage({ detail: { data: [e.data.data] } });
|
|
256
|
+
}
|
|
257
|
+
else if (e.data.type === 'WEB_INVOKE_APPSERVICE') {
|
|
258
|
+
// webview页面自定义iframe,嵌套页面中调用uni.webView[xx](),必须实现如下功能,否则无效
|
|
259
|
+
if (!isIframe) {
|
|
260
|
+
const root = getRootEl();
|
|
261
|
+
if (root?.tagName === 'IFRAME' || root?.parentNode?.querySelector?.('iframe')) {
|
|
262
|
+
isIframe = true;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
if (isIframe) {
|
|
266
|
+
const { name, arg } = e.data.data || {};
|
|
267
|
+
if (['navigateTo', 'redirectTo', 'reLaunch', 'switchTab', 'navigateBack'].includes(name)) {
|
|
268
|
+
uni[name](arg);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
catch (e) { }
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
window.addEventListener('message', onWindowMessage);
|
|
277
|
+
}
|
|
278
|
+
// #endif
|
|
279
|
+
});
|
|
280
|
+
onUnload(() => {
|
|
281
|
+
// #ifdef H5
|
|
282
|
+
if (onWindowMessage) {
|
|
283
|
+
window.removeEventListener('message', onWindowMessage);
|
|
284
|
+
onWindowMessage = null;
|
|
285
|
+
}
|
|
286
|
+
// #endif
|
|
287
|
+
});
|
|
288
|
+
return {
|
|
289
|
+
shareData,
|
|
290
|
+
webviewUrl,
|
|
291
|
+
onMessage,
|
|
292
|
+
postMessage,
|
|
293
|
+
};
|
|
294
|
+
}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { App } from 'vue';
|
|
2
|
+
import toast from './utils/toast';
|
|
3
|
+
import navigate from './utils/navigate';
|
|
4
|
+
import config from './configs';
|
|
5
|
+
import cos from './utils/cos';
|
|
6
|
+
import './utils/uni';
|
|
7
|
+
import './utils/message';
|
|
8
|
+
export * from './hooks';
|
|
9
|
+
export * from './utils';
|
|
10
|
+
export * from './utils/file';
|
|
11
|
+
export * from './utils/storage';
|
|
12
|
+
export * from './utils/pages';
|
|
13
|
+
export * from './utils/consts';
|
|
14
|
+
export * from './utils/request';
|
|
15
|
+
export * from './utils/subscribe';
|
|
16
|
+
export * from './utils/permission';
|
|
17
|
+
export * from './utils/audio';
|
|
18
|
+
export * from './utils/update';
|
|
19
|
+
export * from './stores';
|
|
20
|
+
export { default as query } from './utils/query';
|
|
21
|
+
export { defineConfig, defineEnvConfig } from './configs';
|
|
22
|
+
export { cos, toast, navigate, config };
|
|
23
|
+
declare function install(app: App): void;
|
|
24
|
+
declare const _default: {
|
|
25
|
+
install: typeof install;
|
|
26
|
+
};
|
|
27
|
+
export default _default;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import toast from './utils/toast';
|
|
2
|
+
import navigate from './utils/navigate';
|
|
3
|
+
import config from './configs';
|
|
4
|
+
import cos from './utils/cos';
|
|
5
|
+
import { installStore } from './stores';
|
|
6
|
+
import './utils/uni';
|
|
7
|
+
import './utils/message';
|
|
8
|
+
export * from './hooks';
|
|
9
|
+
export * from './utils';
|
|
10
|
+
export * from './utils/file';
|
|
11
|
+
export * from './utils/storage';
|
|
12
|
+
export * from './utils/pages';
|
|
13
|
+
export * from './utils/consts';
|
|
14
|
+
export * from './utils/request';
|
|
15
|
+
export * from './utils/subscribe';
|
|
16
|
+
export * from './utils/permission';
|
|
17
|
+
export * from './utils/audio';
|
|
18
|
+
export * from './utils/update';
|
|
19
|
+
export * from './stores';
|
|
20
|
+
export { default as query } from './utils/query';
|
|
21
|
+
export { defineConfig, defineEnvConfig } from './configs';
|
|
22
|
+
export { cos, toast, navigate, config };
|
|
23
|
+
function install(app) {
|
|
24
|
+
installStore(app);
|
|
25
|
+
}
|
|
26
|
+
export default { install };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export interface AppInfo {
|
|
2
|
+
appId: string;
|
|
3
|
+
identifier: string;
|
|
4
|
+
iconUrl: string;
|
|
5
|
+
name: string;
|
|
6
|
+
brief: string;
|
|
7
|
+
configJson: Record<string, any>;
|
|
8
|
+
perms: any[];
|
|
9
|
+
appType: number;
|
|
10
|
+
}
|
|
11
|
+
/** 应用详情 */
|
|
12
|
+
export declare const useAppStore: import("pinia").StoreDefinition<"app", import("pinia")._UnwrapAll<Pick<{
|
|
13
|
+
state: import("vue").Ref<{
|
|
14
|
+
appId: string;
|
|
15
|
+
identifier: string;
|
|
16
|
+
iconUrl: string;
|
|
17
|
+
name: string;
|
|
18
|
+
brief: string;
|
|
19
|
+
configJson: Record<string, any>;
|
|
20
|
+
perms: any[];
|
|
21
|
+
appType: number;
|
|
22
|
+
}>;
|
|
23
|
+
setAppInfo: (data?: Partial<AppInfo> | null) => void;
|
|
24
|
+
getAppInfo: () => Promise<void>;
|
|
25
|
+
}, "state">>, Pick<{
|
|
26
|
+
state: import("vue").Ref<{
|
|
27
|
+
appId: string;
|
|
28
|
+
identifier: string;
|
|
29
|
+
iconUrl: string;
|
|
30
|
+
name: string;
|
|
31
|
+
brief: string;
|
|
32
|
+
configJson: Record<string, any>;
|
|
33
|
+
perms: any[];
|
|
34
|
+
appType: number;
|
|
35
|
+
}>;
|
|
36
|
+
setAppInfo: (data?: Partial<AppInfo> | null) => void;
|
|
37
|
+
getAppInfo: () => Promise<void>;
|
|
38
|
+
}, never>, Pick<{
|
|
39
|
+
state: import("vue").Ref<{
|
|
40
|
+
appId: string;
|
|
41
|
+
identifier: string;
|
|
42
|
+
iconUrl: string;
|
|
43
|
+
name: string;
|
|
44
|
+
brief: string;
|
|
45
|
+
configJson: Record<string, any>;
|
|
46
|
+
perms: any[];
|
|
47
|
+
appType: number;
|
|
48
|
+
}>;
|
|
49
|
+
setAppInfo: (data?: Partial<AppInfo> | null) => void;
|
|
50
|
+
getAppInfo: () => Promise<void>;
|
|
51
|
+
}, "setAppInfo" | "getAppInfo">>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ref } from 'vue';
|
|
2
|
+
import { defineStore } from 'pinia';
|
|
3
|
+
import { getStorageSync, setStorage } from '../utils/storage';
|
|
4
|
+
import { TYPES } from '../utils/consts';
|
|
5
|
+
import { getAppData, getAppByUser } from '../apis/core';
|
|
6
|
+
import appConfig from '../configs/app';
|
|
7
|
+
import { pinia } from './pinia';
|
|
8
|
+
import { useLoginStore } from './login';
|
|
9
|
+
function getDefaultState() {
|
|
10
|
+
return {
|
|
11
|
+
appId: '',
|
|
12
|
+
identifier: '',
|
|
13
|
+
iconUrl: '',
|
|
14
|
+
name: '',
|
|
15
|
+
brief: '',
|
|
16
|
+
configJson: {},
|
|
17
|
+
perms: [],
|
|
18
|
+
appType: 0,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function normalizeAppInfo(data) {
|
|
22
|
+
const info = { ...getDefaultState(), ...(data || {}) };
|
|
23
|
+
try {
|
|
24
|
+
if (typeof info.configJson === 'string') {
|
|
25
|
+
info.configJson = JSON.parse(info.configJson || '{}');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
info.configJson = {};
|
|
30
|
+
}
|
|
31
|
+
return info;
|
|
32
|
+
}
|
|
33
|
+
/** 应用详情 */
|
|
34
|
+
export const useAppStore = defineStore('app', () => {
|
|
35
|
+
const state = ref(normalizeAppInfo(getStorageSync(TYPES.STORAGE.APP)));
|
|
36
|
+
function setAppInfo(data) {
|
|
37
|
+
state.value = normalizeAppInfo(data);
|
|
38
|
+
setStorage(TYPES.STORAGE.APP, state.value);
|
|
39
|
+
}
|
|
40
|
+
async function getAppInfo() {
|
|
41
|
+
try {
|
|
42
|
+
const appId = appConfig.appId;
|
|
43
|
+
if (!appId)
|
|
44
|
+
return;
|
|
45
|
+
const loginStore = useLoginStore(pinia);
|
|
46
|
+
const request = loginStore.isLogin ? getAppByUser : getAppData;
|
|
47
|
+
const { data } = await request({ appId }, { custom: { message: false } });
|
|
48
|
+
setAppInfo(data);
|
|
49
|
+
}
|
|
50
|
+
catch (e) { }
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
state,
|
|
54
|
+
setAppInfo,
|
|
55
|
+
getAppInfo,
|
|
56
|
+
};
|
|
57
|
+
});
|