@zfqh/uniapp-x 0.0.0-stage → 0.0.2
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 +44 -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,35 @@
|
|
|
1
|
+
export interface DictOption {
|
|
2
|
+
label: string;
|
|
3
|
+
value: any;
|
|
4
|
+
[key: string]: any;
|
|
5
|
+
}
|
|
6
|
+
export interface DictEntry {
|
|
7
|
+
options: DictOption[];
|
|
8
|
+
values: any[];
|
|
9
|
+
labels: string[];
|
|
10
|
+
enums: Record<string, any>;
|
|
11
|
+
}
|
|
12
|
+
export type DictInfo = Record<string, DictEntry>;
|
|
13
|
+
/** 字典数据 */
|
|
14
|
+
export declare const useDictStore: import("pinia").StoreDefinition<"dict", import("pinia")._UnwrapAll<Pick<{
|
|
15
|
+
state: import("vue").Ref<DictInfo>;
|
|
16
|
+
setDictInfo: (data: Partial<DictInfo>) => void;
|
|
17
|
+
getDictInfo: (params?: {
|
|
18
|
+
name: string;
|
|
19
|
+
cache?: boolean;
|
|
20
|
+
}) => Promise<void>;
|
|
21
|
+
}, "state">>, Pick<{
|
|
22
|
+
state: import("vue").Ref<DictInfo>;
|
|
23
|
+
setDictInfo: (data: Partial<DictInfo>) => void;
|
|
24
|
+
getDictInfo: (params?: {
|
|
25
|
+
name: string;
|
|
26
|
+
cache?: boolean;
|
|
27
|
+
}) => Promise<void>;
|
|
28
|
+
}, never>, Pick<{
|
|
29
|
+
state: import("vue").Ref<DictInfo>;
|
|
30
|
+
setDictInfo: (data: Partial<DictInfo>) => void;
|
|
31
|
+
getDictInfo: (params?: {
|
|
32
|
+
name: string;
|
|
33
|
+
cache?: boolean;
|
|
34
|
+
}) => Promise<void>;
|
|
35
|
+
}, "setDictInfo" | "getDictInfo">>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ref } from 'vue';
|
|
2
|
+
import { defineStore } from 'pinia';
|
|
3
|
+
import { getDictData } from '../apis/core';
|
|
4
|
+
/** 字典数据 */
|
|
5
|
+
export const useDictStore = defineStore('dict', () => {
|
|
6
|
+
const state = ref({});
|
|
7
|
+
function setDictInfo(data) {
|
|
8
|
+
state.value = { ...state.value, ...data };
|
|
9
|
+
}
|
|
10
|
+
async function getDictInfo(params = {}) {
|
|
11
|
+
try {
|
|
12
|
+
const { name, cache } = params;
|
|
13
|
+
if (name && (!cache || (cache && !state.value[name]))) {
|
|
14
|
+
const e = await getDictData({ type: name }, { header: { channel: 3 }, custom: { message: false } });
|
|
15
|
+
const enums = {};
|
|
16
|
+
const values = [];
|
|
17
|
+
const labels = [];
|
|
18
|
+
const options = e.data.map(({ label, value, ...rest }) => {
|
|
19
|
+
values.push(value);
|
|
20
|
+
labels.push(label);
|
|
21
|
+
enums[label] = value;
|
|
22
|
+
enums[value] = label;
|
|
23
|
+
return { label, value, ...rest };
|
|
24
|
+
});
|
|
25
|
+
setDictInfo({
|
|
26
|
+
[name]: {
|
|
27
|
+
options,
|
|
28
|
+
values,
|
|
29
|
+
labels,
|
|
30
|
+
enums,
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
catch (e) { }
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
state,
|
|
39
|
+
setDictInfo,
|
|
40
|
+
getDictInfo,
|
|
41
|
+
};
|
|
42
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export interface ImInfo {
|
|
2
|
+
userId: string;
|
|
3
|
+
usersig: string;
|
|
4
|
+
sdkappid: number;
|
|
5
|
+
isLogin: boolean;
|
|
6
|
+
isReady: boolean;
|
|
7
|
+
}
|
|
8
|
+
/** IM 状态 */
|
|
9
|
+
export declare const useImStore: import("pinia").StoreDefinition<"im", import("pinia")._UnwrapAll<Pick<{
|
|
10
|
+
state: import("vue").Ref<{
|
|
11
|
+
userId: string;
|
|
12
|
+
usersig: string;
|
|
13
|
+
sdkappid: number;
|
|
14
|
+
isLogin: boolean;
|
|
15
|
+
isReady: boolean;
|
|
16
|
+
}>;
|
|
17
|
+
setImInfo: (data?: Partial<ImInfo> | null) => void;
|
|
18
|
+
resetState: () => void;
|
|
19
|
+
waitImLogin: () => Promise<boolean>;
|
|
20
|
+
waitImReady: () => Promise<boolean>;
|
|
21
|
+
getImInfo: (params?: {
|
|
22
|
+
username: string;
|
|
23
|
+
userType?: number;
|
|
24
|
+
}) => Promise<void>;
|
|
25
|
+
}, "state">>, Pick<{
|
|
26
|
+
state: import("vue").Ref<{
|
|
27
|
+
userId: string;
|
|
28
|
+
usersig: string;
|
|
29
|
+
sdkappid: number;
|
|
30
|
+
isLogin: boolean;
|
|
31
|
+
isReady: boolean;
|
|
32
|
+
}>;
|
|
33
|
+
setImInfo: (data?: Partial<ImInfo> | null) => void;
|
|
34
|
+
resetState: () => void;
|
|
35
|
+
waitImLogin: () => Promise<boolean>;
|
|
36
|
+
waitImReady: () => Promise<boolean>;
|
|
37
|
+
getImInfo: (params?: {
|
|
38
|
+
username: string;
|
|
39
|
+
userType?: number;
|
|
40
|
+
}) => Promise<void>;
|
|
41
|
+
}, never>, Pick<{
|
|
42
|
+
state: import("vue").Ref<{
|
|
43
|
+
userId: string;
|
|
44
|
+
usersig: string;
|
|
45
|
+
sdkappid: number;
|
|
46
|
+
isLogin: boolean;
|
|
47
|
+
isReady: boolean;
|
|
48
|
+
}>;
|
|
49
|
+
setImInfo: (data?: Partial<ImInfo> | null) => void;
|
|
50
|
+
resetState: () => void;
|
|
51
|
+
waitImLogin: () => Promise<boolean>;
|
|
52
|
+
waitImReady: () => Promise<boolean>;
|
|
53
|
+
getImInfo: (params?: {
|
|
54
|
+
username: string;
|
|
55
|
+
userType?: number;
|
|
56
|
+
}) => Promise<void>;
|
|
57
|
+
}, "resetState" | "setImInfo" | "waitImLogin" | "waitImReady" | "getImInfo">>;
|
package/lib/stores/im.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { ref } from 'vue';
|
|
2
|
+
import { defineStore } from 'pinia';
|
|
3
|
+
import { getImData } from '../apis/core';
|
|
4
|
+
function getDefaultState() {
|
|
5
|
+
return {
|
|
6
|
+
userId: '',
|
|
7
|
+
usersig: '',
|
|
8
|
+
sdkappid: 0,
|
|
9
|
+
isLogin: false,
|
|
10
|
+
isReady: false,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function settleWaiters(waiters, value, error) {
|
|
14
|
+
waiters.forEach(({ resolve, reject }) => {
|
|
15
|
+
if (value) {
|
|
16
|
+
resolve(true);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
reject(error);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/** IM 状态 */
|
|
24
|
+
export const useImStore = defineStore('im', () => {
|
|
25
|
+
const state = ref(getDefaultState());
|
|
26
|
+
let loginWaiters = [];
|
|
27
|
+
let readyWaiters = [];
|
|
28
|
+
function setImInfo(data) {
|
|
29
|
+
const next = data || {};
|
|
30
|
+
if (next.isLogin != null) {
|
|
31
|
+
settleWaiters(loginWaiters, next.isLogin === true, new Error('IM Login Fail'));
|
|
32
|
+
loginWaiters = [];
|
|
33
|
+
}
|
|
34
|
+
if (next.isReady != null) {
|
|
35
|
+
settleWaiters(readyWaiters, next.isReady === true, new Error('IM Ready Fail'));
|
|
36
|
+
readyWaiters = [];
|
|
37
|
+
}
|
|
38
|
+
Object.assign(state.value, next);
|
|
39
|
+
}
|
|
40
|
+
function resetState() {
|
|
41
|
+
if (state.value.isLogin === true) {
|
|
42
|
+
uni.$emit('logoutIm');
|
|
43
|
+
}
|
|
44
|
+
state.value = getDefaultState();
|
|
45
|
+
settleWaiters(loginWaiters, false, new Error('IM Login Reset'));
|
|
46
|
+
settleWaiters(readyWaiters, false, new Error('IM Ready Reset'));
|
|
47
|
+
loginWaiters = [];
|
|
48
|
+
readyWaiters = [];
|
|
49
|
+
}
|
|
50
|
+
function waitImLogin() {
|
|
51
|
+
return new Promise((resolve, reject) => {
|
|
52
|
+
if (state.value.isLogin === true) {
|
|
53
|
+
resolve(true);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
loginWaiters.push({ resolve, reject });
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
function waitImReady() {
|
|
61
|
+
return new Promise((resolve, reject) => {
|
|
62
|
+
if (state.value.isReady === true) {
|
|
63
|
+
resolve(true);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
readyWaiters.push({ resolve, reject });
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
async function getImInfo(params = {}) {
|
|
71
|
+
try {
|
|
72
|
+
const { username, userType = 1 } = params;
|
|
73
|
+
if (!username)
|
|
74
|
+
return;
|
|
75
|
+
const { data } = await getImData({ username, userType });
|
|
76
|
+
// 防止登录其他账号,IM信息不变,先退出之前账号
|
|
77
|
+
if (state.value.isLogin === true && state.value.userId !== data.userId) {
|
|
78
|
+
uni.$emit('logoutIm');
|
|
79
|
+
setImInfo(getDefaultState());
|
|
80
|
+
// 加延迟防止新账号登录不成功
|
|
81
|
+
await new Promise((res) => {
|
|
82
|
+
setTimeout(() => {
|
|
83
|
+
res();
|
|
84
|
+
}, 1000);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
if (state.value.isLogin !== true) {
|
|
88
|
+
setImInfo(data);
|
|
89
|
+
uni.$emit('loginIm');
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
catch (e) { }
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
state,
|
|
96
|
+
setImInfo,
|
|
97
|
+
resetState,
|
|
98
|
+
waitImLogin,
|
|
99
|
+
waitImReady,
|
|
100
|
+
getImInfo,
|
|
101
|
+
};
|
|
102
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { App } from 'vue';
|
|
2
|
+
export { pinia } from './pinia';
|
|
3
|
+
export * from './app';
|
|
4
|
+
export * from './dict';
|
|
5
|
+
export * from './im';
|
|
6
|
+
export * from './launch';
|
|
7
|
+
export * from './location';
|
|
8
|
+
export * from './login';
|
|
9
|
+
export * from './network';
|
|
10
|
+
export * from './system';
|
|
11
|
+
/** 安装 Pinia,插件安装时调用 */
|
|
12
|
+
export declare function installStore(app: App): void;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { pinia } from './pinia';
|
|
2
|
+
import { useLoginStore } from './login';
|
|
3
|
+
export { pinia } from './pinia';
|
|
4
|
+
export * from './app';
|
|
5
|
+
export * from './dict';
|
|
6
|
+
export * from './im';
|
|
7
|
+
export * from './launch';
|
|
8
|
+
export * from './location';
|
|
9
|
+
export * from './login';
|
|
10
|
+
export * from './network';
|
|
11
|
+
export * from './system';
|
|
12
|
+
/** 安装 Pinia,插件安装时调用 */
|
|
13
|
+
export function installStore(app) {
|
|
14
|
+
app.use(pinia);
|
|
15
|
+
// 提前初始化登录态,保证请求拦截器在首次请求前能读取 tenantId / accessToken
|
|
16
|
+
useLoginStore(pinia);
|
|
17
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export interface LaunchInfo {
|
|
2
|
+
id: number;
|
|
3
|
+
path: string;
|
|
4
|
+
query: Record<string, any>;
|
|
5
|
+
referrerInfo: Record<string, any>;
|
|
6
|
+
scene: number;
|
|
7
|
+
}
|
|
8
|
+
/** 启动参数 */
|
|
9
|
+
export declare const useLaunchStore: import("pinia").StoreDefinition<"launch", import("pinia")._UnwrapAll<Pick<{
|
|
10
|
+
state: import("vue").Ref<{
|
|
11
|
+
id: number;
|
|
12
|
+
path: string;
|
|
13
|
+
query: Record<string, any>;
|
|
14
|
+
referrerInfo: Record<string, any>;
|
|
15
|
+
scene: number;
|
|
16
|
+
}>;
|
|
17
|
+
key: import("vue").Ref<number>;
|
|
18
|
+
setLaunchInfo: (data?: Partial<LaunchInfo> | null) => void;
|
|
19
|
+
setLaunchId: (id?: number) => void;
|
|
20
|
+
}, "key" | "state">>, Pick<{
|
|
21
|
+
state: import("vue").Ref<{
|
|
22
|
+
id: number;
|
|
23
|
+
path: string;
|
|
24
|
+
query: Record<string, any>;
|
|
25
|
+
referrerInfo: Record<string, any>;
|
|
26
|
+
scene: number;
|
|
27
|
+
}>;
|
|
28
|
+
key: import("vue").Ref<number>;
|
|
29
|
+
setLaunchInfo: (data?: Partial<LaunchInfo> | null) => void;
|
|
30
|
+
setLaunchId: (id?: number) => void;
|
|
31
|
+
}, never>, Pick<{
|
|
32
|
+
state: import("vue").Ref<{
|
|
33
|
+
id: number;
|
|
34
|
+
path: string;
|
|
35
|
+
query: Record<string, any>;
|
|
36
|
+
referrerInfo: Record<string, any>;
|
|
37
|
+
scene: number;
|
|
38
|
+
}>;
|
|
39
|
+
key: import("vue").Ref<number>;
|
|
40
|
+
setLaunchInfo: (data?: Partial<LaunchInfo> | null) => void;
|
|
41
|
+
setLaunchId: (id?: number) => void;
|
|
42
|
+
}, "setLaunchInfo" | "setLaunchId">>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ref } from 'vue';
|
|
2
|
+
import { defineStore } from 'pinia';
|
|
3
|
+
import { getStorageSync, setStorage } from '../utils/storage';
|
|
4
|
+
import { TYPES } from '../utils/consts';
|
|
5
|
+
function getDefaultState() {
|
|
6
|
+
return {
|
|
7
|
+
id: 0,
|
|
8
|
+
path: '',
|
|
9
|
+
query: {},
|
|
10
|
+
referrerInfo: {},
|
|
11
|
+
scene: 0,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/** 启动参数 */
|
|
15
|
+
export const useLaunchStore = defineStore('launch', () => {
|
|
16
|
+
const storedKey = getStorageSync(TYPES.STORAGE.LAUNCH);
|
|
17
|
+
const state = ref(getDefaultState());
|
|
18
|
+
const key = ref(typeof storedKey === 'number' ? storedKey : Number(storedKey) || 0);
|
|
19
|
+
function setLaunchInfo(data) {
|
|
20
|
+
let { scene, path } = (data || {});
|
|
21
|
+
if (scene === null) {
|
|
22
|
+
scene = 0;
|
|
23
|
+
}
|
|
24
|
+
if (path && !path.startsWith('/')) {
|
|
25
|
+
path = `/${path}`;
|
|
26
|
+
}
|
|
27
|
+
Object.assign(state.value, data, { scene, path });
|
|
28
|
+
}
|
|
29
|
+
function setLaunchId(id) {
|
|
30
|
+
key.value = id || 0;
|
|
31
|
+
setStorage(TYPES.STORAGE.LAUNCH, key.value);
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
state,
|
|
35
|
+
key,
|
|
36
|
+
setLaunchInfo,
|
|
37
|
+
setLaunchId,
|
|
38
|
+
};
|
|
39
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export interface LocationInfo {
|
|
2
|
+
name: string;
|
|
3
|
+
address: Record<string, any>;
|
|
4
|
+
longitude: number;
|
|
5
|
+
latitude: number;
|
|
6
|
+
}
|
|
7
|
+
/** 定位信息 */
|
|
8
|
+
export declare const useLocationStore: import("pinia").StoreDefinition<"location", import("pinia")._UnwrapAll<Pick<{
|
|
9
|
+
state: import("vue").Ref<{
|
|
10
|
+
name: string;
|
|
11
|
+
address: Record<string, any>;
|
|
12
|
+
longitude: number;
|
|
13
|
+
latitude: number;
|
|
14
|
+
}>;
|
|
15
|
+
setLocationInfo: (data: Partial<LocationInfo>) => void;
|
|
16
|
+
getLocationInfo: (options?: any) => Promise<void>;
|
|
17
|
+
}, "state">>, Pick<{
|
|
18
|
+
state: import("vue").Ref<{
|
|
19
|
+
name: string;
|
|
20
|
+
address: Record<string, any>;
|
|
21
|
+
longitude: number;
|
|
22
|
+
latitude: number;
|
|
23
|
+
}>;
|
|
24
|
+
setLocationInfo: (data: Partial<LocationInfo>) => void;
|
|
25
|
+
getLocationInfo: (options?: any) => Promise<void>;
|
|
26
|
+
}, never>, Pick<{
|
|
27
|
+
state: import("vue").Ref<{
|
|
28
|
+
name: string;
|
|
29
|
+
address: Record<string, any>;
|
|
30
|
+
longitude: number;
|
|
31
|
+
latitude: number;
|
|
32
|
+
}>;
|
|
33
|
+
setLocationInfo: (data: Partial<LocationInfo>) => void;
|
|
34
|
+
getLocationInfo: (options?: any) => Promise<void>;
|
|
35
|
+
}, "setLocationInfo" | "getLocationInfo">>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { ref } from 'vue';
|
|
2
|
+
import { defineStore } from 'pinia';
|
|
3
|
+
import { requestPermission } from '../utils/permission';
|
|
4
|
+
import { getStorageSync, setStorage } from '../utils/storage';
|
|
5
|
+
import { TYPES } from '../utils/consts';
|
|
6
|
+
function getDefaultState() {
|
|
7
|
+
return {
|
|
8
|
+
name: '北京', // 城市名称
|
|
9
|
+
address: {}, // 地址信息
|
|
10
|
+
longitude: 0, // 经度
|
|
11
|
+
latitude: 0, // 纬度
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/** 定位信息 */
|
|
15
|
+
export const useLocationStore = defineStore('location', () => {
|
|
16
|
+
const state = ref({ ...getDefaultState(), ...(getStorageSync(TYPES.STORAGE.LOCATION) || {}) });
|
|
17
|
+
function setLocationInfo(data) {
|
|
18
|
+
state.value = {
|
|
19
|
+
...state.value,
|
|
20
|
+
...data,
|
|
21
|
+
};
|
|
22
|
+
setStorage(TYPES.STORAGE.LOCATION, state.value);
|
|
23
|
+
}
|
|
24
|
+
async function getLocationInfo(options = {}) {
|
|
25
|
+
await requestPermission('location');
|
|
26
|
+
return await new Promise((res) => {
|
|
27
|
+
uni.getLocation({
|
|
28
|
+
...options,
|
|
29
|
+
geocode: true,
|
|
30
|
+
type: 'gcj02',
|
|
31
|
+
success: ({ latitude, longitude, address }) => {
|
|
32
|
+
if (!address) {
|
|
33
|
+
address = {};
|
|
34
|
+
}
|
|
35
|
+
if (Array.isArray(address.city)) {
|
|
36
|
+
address.city = address.city[0];
|
|
37
|
+
}
|
|
38
|
+
const data = {
|
|
39
|
+
name: address.city || address.province,
|
|
40
|
+
latitude,
|
|
41
|
+
longitude,
|
|
42
|
+
address,
|
|
43
|
+
};
|
|
44
|
+
setLocationInfo(data);
|
|
45
|
+
res();
|
|
46
|
+
},
|
|
47
|
+
fail() {
|
|
48
|
+
res();
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
state,
|
|
55
|
+
setLocationInfo,
|
|
56
|
+
getLocationInfo,
|
|
57
|
+
};
|
|
58
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
export interface LoginInfo {
|
|
2
|
+
accessToken: string | null;
|
|
3
|
+
refreshToken: string;
|
|
4
|
+
expiresTime: number;
|
|
5
|
+
phone: string;
|
|
6
|
+
email: string;
|
|
7
|
+
nickName: string;
|
|
8
|
+
userId: string;
|
|
9
|
+
username: string;
|
|
10
|
+
avatar: string;
|
|
11
|
+
storeId: string;
|
|
12
|
+
storeName: string;
|
|
13
|
+
tenantId: string;
|
|
14
|
+
tenantName: string;
|
|
15
|
+
}
|
|
16
|
+
/** 登录态 */
|
|
17
|
+
export declare const useLoginStore: import("pinia").StoreDefinition<"login", import("pinia")._UnwrapAll<Pick<{
|
|
18
|
+
state: import("vue").Ref<{
|
|
19
|
+
accessToken: string | null;
|
|
20
|
+
refreshToken: string;
|
|
21
|
+
expiresTime: number;
|
|
22
|
+
phone: string;
|
|
23
|
+
email: string;
|
|
24
|
+
nickName: string;
|
|
25
|
+
userId: string;
|
|
26
|
+
username: string;
|
|
27
|
+
avatar: string;
|
|
28
|
+
storeId: string;
|
|
29
|
+
storeName: string;
|
|
30
|
+
tenantId: string;
|
|
31
|
+
tenantName: string;
|
|
32
|
+
}>;
|
|
33
|
+
isLogin: import("vue").ComputedRef<boolean>;
|
|
34
|
+
setLoginInfo: (data: Partial<LoginInfo>) => void;
|
|
35
|
+
resetState: () => void;
|
|
36
|
+
logout: (reLaunch?: boolean) => void;
|
|
37
|
+
refreshToken: () => Promise<void>;
|
|
38
|
+
}, "state">>, Pick<{
|
|
39
|
+
state: import("vue").Ref<{
|
|
40
|
+
accessToken: string | null;
|
|
41
|
+
refreshToken: string;
|
|
42
|
+
expiresTime: number;
|
|
43
|
+
phone: string;
|
|
44
|
+
email: string;
|
|
45
|
+
nickName: string;
|
|
46
|
+
userId: string;
|
|
47
|
+
username: string;
|
|
48
|
+
avatar: string;
|
|
49
|
+
storeId: string;
|
|
50
|
+
storeName: string;
|
|
51
|
+
tenantId: string;
|
|
52
|
+
tenantName: string;
|
|
53
|
+
}>;
|
|
54
|
+
isLogin: import("vue").ComputedRef<boolean>;
|
|
55
|
+
setLoginInfo: (data: Partial<LoginInfo>) => void;
|
|
56
|
+
resetState: () => void;
|
|
57
|
+
logout: (reLaunch?: boolean) => void;
|
|
58
|
+
refreshToken: () => Promise<void>;
|
|
59
|
+
}, "isLogin">, Pick<{
|
|
60
|
+
state: import("vue").Ref<{
|
|
61
|
+
accessToken: string | null;
|
|
62
|
+
refreshToken: string;
|
|
63
|
+
expiresTime: number;
|
|
64
|
+
phone: string;
|
|
65
|
+
email: string;
|
|
66
|
+
nickName: string;
|
|
67
|
+
userId: string;
|
|
68
|
+
username: string;
|
|
69
|
+
avatar: string;
|
|
70
|
+
storeId: string;
|
|
71
|
+
storeName: string;
|
|
72
|
+
tenantId: string;
|
|
73
|
+
tenantName: string;
|
|
74
|
+
}>;
|
|
75
|
+
isLogin: import("vue").ComputedRef<boolean>;
|
|
76
|
+
setLoginInfo: (data: Partial<LoginInfo>) => void;
|
|
77
|
+
resetState: () => void;
|
|
78
|
+
logout: (reLaunch?: boolean) => void;
|
|
79
|
+
refreshToken: () => Promise<void>;
|
|
80
|
+
}, "refreshToken" | "setLoginInfo" | "resetState" | "logout">>;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { computed, ref } from 'vue';
|
|
2
|
+
import { defineStore } from 'pinia';
|
|
3
|
+
import throttle from '@zfqh/uview-x/utils/throttle';
|
|
4
|
+
import { getStorageSync, setStorage, removeStorage } from '../utils/storage';
|
|
5
|
+
import { TYPES } from '../utils/consts';
|
|
6
|
+
import query from '../utils/query';
|
|
7
|
+
import navigate from '../utils/navigate';
|
|
8
|
+
import { getPage } from '../utils/pages';
|
|
9
|
+
import { postRefreshToken } from '../apis/core';
|
|
10
|
+
const _accessToken = query.accessToken || query.token || null;
|
|
11
|
+
function getDefaultState() {
|
|
12
|
+
return {
|
|
13
|
+
accessToken: null,
|
|
14
|
+
refreshToken: '',
|
|
15
|
+
expiresTime: 0,
|
|
16
|
+
phone: '',
|
|
17
|
+
email: '',
|
|
18
|
+
nickName: '',
|
|
19
|
+
userId: '',
|
|
20
|
+
username: '',
|
|
21
|
+
avatar: '',
|
|
22
|
+
storeId: '',
|
|
23
|
+
storeName: '',
|
|
24
|
+
tenantId: '',
|
|
25
|
+
tenantName: '',
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function getInitialState() {
|
|
29
|
+
const defaultState = getDefaultState();
|
|
30
|
+
if (_accessToken) {
|
|
31
|
+
Object.keys(defaultState).forEach((key) => {
|
|
32
|
+
if (query[key] != null) {
|
|
33
|
+
defaultState[key] = query[key];
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
defaultState.accessToken = _accessToken;
|
|
37
|
+
return defaultState;
|
|
38
|
+
}
|
|
39
|
+
return { ...defaultState, ...(getStorageSync(TYPES.STORAGE.LOGIN) || {}) };
|
|
40
|
+
}
|
|
41
|
+
/** 登录态 */
|
|
42
|
+
export const useLoginStore = defineStore('login', () => {
|
|
43
|
+
const state = ref(getInitialState());
|
|
44
|
+
const isLogin = computed(() => Boolean(state.value.accessToken));
|
|
45
|
+
function setLoginInfo(data) {
|
|
46
|
+
const next = { ...data };
|
|
47
|
+
if (next.accessToken) {
|
|
48
|
+
next.accessToken = next.accessToken.replace(/^bearer\s+/i, '');
|
|
49
|
+
}
|
|
50
|
+
state.value = { ...state.value, ...next };
|
|
51
|
+
if (!_accessToken) {
|
|
52
|
+
setStorage(TYPES.STORAGE.LOGIN, state.value);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function resetState() {
|
|
56
|
+
state.value = getDefaultState();
|
|
57
|
+
removeStorage(TYPES.STORAGE.LOGIN);
|
|
58
|
+
}
|
|
59
|
+
function logout(reLaunch) {
|
|
60
|
+
throttle(() => {
|
|
61
|
+
if (isLogin.value) {
|
|
62
|
+
resetState();
|
|
63
|
+
}
|
|
64
|
+
if (reLaunch) {
|
|
65
|
+
uni.reLaunch({ url: getPage('login') });
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
navigate({ url: '', needLogin: true });
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
async function refreshToken() {
|
|
73
|
+
const refreshToken = state.value.refreshToken;
|
|
74
|
+
if (!refreshToken)
|
|
75
|
+
return;
|
|
76
|
+
try {
|
|
77
|
+
const { data } = await postRefreshToken({ refreshToken });
|
|
78
|
+
const { refreshToken: newRefreshToken, accessToken, expiresTime } = data || {};
|
|
79
|
+
setLoginInfo({ accessToken, refreshToken: newRefreshToken, expiresTime });
|
|
80
|
+
}
|
|
81
|
+
catch (e) { }
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
state,
|
|
85
|
+
isLogin,
|
|
86
|
+
setLoginInfo,
|
|
87
|
+
resetState,
|
|
88
|
+
logout,
|
|
89
|
+
refreshToken,
|
|
90
|
+
};
|
|
91
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface NetworkInfo {
|
|
2
|
+
type: string;
|
|
3
|
+
}
|
|
4
|
+
/** 网络状态 */
|
|
5
|
+
export declare const useNetworkStore: import("pinia").StoreDefinition<"network", import("pinia")._UnwrapAll<Pick<{
|
|
6
|
+
state: import("vue").Ref<{
|
|
7
|
+
type: string;
|
|
8
|
+
}>;
|
|
9
|
+
isConnected: import("vue").ComputedRef<boolean>;
|
|
10
|
+
setNetworkInfo: (data: Partial<NetworkInfo>) => void;
|
|
11
|
+
getNetworkInfo: () => Promise<NetworkInfo>;
|
|
12
|
+
}, "state">>, Pick<{
|
|
13
|
+
state: import("vue").Ref<{
|
|
14
|
+
type: string;
|
|
15
|
+
}>;
|
|
16
|
+
isConnected: import("vue").ComputedRef<boolean>;
|
|
17
|
+
setNetworkInfo: (data: Partial<NetworkInfo>) => void;
|
|
18
|
+
getNetworkInfo: () => Promise<NetworkInfo>;
|
|
19
|
+
}, "isConnected">, Pick<{
|
|
20
|
+
state: import("vue").Ref<{
|
|
21
|
+
type: string;
|
|
22
|
+
}>;
|
|
23
|
+
isConnected: import("vue").ComputedRef<boolean>;
|
|
24
|
+
setNetworkInfo: (data: Partial<NetworkInfo>) => void;
|
|
25
|
+
getNetworkInfo: () => Promise<NetworkInfo>;
|
|
26
|
+
}, "setNetworkInfo" | "getNetworkInfo">>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { computed, ref } from 'vue';
|
|
2
|
+
import { defineStore } from 'pinia';
|
|
3
|
+
function getDefaultState() {
|
|
4
|
+
return {
|
|
5
|
+
type: 'unknown',
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
/** 网络状态 */
|
|
9
|
+
export const useNetworkStore = defineStore('network', () => {
|
|
10
|
+
const state = ref(getDefaultState());
|
|
11
|
+
const isConnected = computed(() => state.value.type !== 'none');
|
|
12
|
+
function setNetworkInfo(data) {
|
|
13
|
+
Object.assign(state.value, data);
|
|
14
|
+
}
|
|
15
|
+
function getNetworkInfo() {
|
|
16
|
+
return new Promise((res) => {
|
|
17
|
+
// uni-app x App 等平台可能不提供 uni.getNetworkType:降级为 unknown,避免启动期抛错
|
|
18
|
+
const getNetworkType = uni.getNetworkType;
|
|
19
|
+
if (typeof getNetworkType !== 'function') {
|
|
20
|
+
const data = { type: 'unknown' };
|
|
21
|
+
setNetworkInfo(data);
|
|
22
|
+
res(data);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
getNetworkType({
|
|
26
|
+
success: (e) => {
|
|
27
|
+
const data = { type: e.networkType };
|
|
28
|
+
setNetworkInfo(data);
|
|
29
|
+
res(data);
|
|
30
|
+
},
|
|
31
|
+
fail: () => {
|
|
32
|
+
const data = { type: 'none' };
|
|
33
|
+
setNetworkInfo(data);
|
|
34
|
+
res(data);
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
state,
|
|
41
|
+
isConnected,
|
|
42
|
+
setNetworkInfo,
|
|
43
|
+
getNetworkInfo,
|
|
44
|
+
};
|
|
45
|
+
});
|