@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.
Files changed (130) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/LICENSE +21 -0
  3. package/README.md +61 -3
  4. package/lib/apis/core.d.ts +18 -0
  5. package/lib/apis/core.js +19 -0
  6. package/lib/apis/index.d.ts +2 -0
  7. package/lib/apis/index.js +2 -0
  8. package/lib/apis/request.d.ts +4 -0
  9. package/lib/apis/request.js +57 -0
  10. package/lib/configs/api.d.ts +7 -0
  11. package/lib/configs/api.js +6 -0
  12. package/lib/configs/app.d.ts +20 -0
  13. package/lib/configs/app.js +18 -0
  14. package/lib/configs/cdn.d.ts +15 -0
  15. package/lib/configs/cdn.js +17 -0
  16. package/lib/configs/env.d.ts +37 -0
  17. package/lib/configs/env.js +71 -0
  18. package/lib/configs/index.d.ts +130 -0
  19. package/lib/configs/index.js +76 -0
  20. package/lib/configs/link.d.ts +11 -0
  21. package/lib/configs/link.js +3 -0
  22. package/lib/configs/log.d.ts +9 -0
  23. package/lib/configs/log.js +8 -0
  24. package/lib/configs/mp.d.ts +15 -0
  25. package/lib/configs/mp.js +9 -0
  26. package/lib/configs/navigate.d.ts +17 -0
  27. package/lib/configs/navigate.js +5 -0
  28. package/lib/configs/page.d.ts +18 -0
  29. package/lib/configs/page.js +14 -0
  30. package/lib/configs/path.d.ts +11 -0
  31. package/lib/configs/path.js +10 -0
  32. package/lib/configs/storage.d.ts +7 -0
  33. package/lib/configs/storage.js +6 -0
  34. package/lib/configs/tabbar.d.ts +7 -0
  35. package/lib/configs/tabbar.js +6 -0
  36. package/lib/configs/toast.d.ts +18 -0
  37. package/lib/configs/toast.js +29 -0
  38. package/lib/configs/updater.d.ts +15 -0
  39. package/lib/configs/updater.js +33 -0
  40. package/lib/configs/upload.d.ts +30 -0
  41. package/lib/configs/upload.js +19 -0
  42. package/lib/configs/ver.d.ts +8 -0
  43. package/lib/configs/ver.js +28 -0
  44. package/lib/configs/web.d.ts +5 -0
  45. package/lib/configs/web.js +2 -0
  46. package/lib/hooks/index.d.ts +11 -0
  47. package/lib/hooks/index.js +11 -0
  48. package/lib/hooks/useAppLifecycle.d.ts +8 -0
  49. package/lib/hooks/useAppLifecycle.js +87 -0
  50. package/lib/hooks/useBadge.d.ts +8 -0
  51. package/lib/hooks/useBadge.js +47 -0
  52. package/lib/hooks/useNeedLogin.d.ts +1 -0
  53. package/lib/hooks/useNeedLogin.js +27 -0
  54. package/lib/hooks/useOverlay.d.ts +1 -0
  55. package/lib/hooks/useOverlay.js +17 -0
  56. package/lib/hooks/usePageShow.d.ts +2 -0
  57. package/lib/hooks/usePageShow.js +16 -0
  58. package/lib/hooks/usePopup.d.ts +1 -0
  59. package/lib/hooks/usePopup.js +14 -0
  60. package/lib/hooks/useRedirect.d.ts +5 -0
  61. package/lib/hooks/useRedirect.js +92 -0
  62. package/lib/hooks/useReferrer.d.ts +1 -0
  63. package/lib/hooks/useReferrer.js +11 -0
  64. package/lib/hooks/useShare.d.ts +12 -0
  65. package/lib/hooks/useShare.js +49 -0
  66. package/lib/hooks/useVersion.d.ts +6 -0
  67. package/lib/hooks/useVersion.js +21 -0
  68. package/lib/hooks/useWebview.d.ts +14 -0
  69. package/lib/hooks/useWebview.js +294 -0
  70. package/lib/index.d.ts +27 -0
  71. package/lib/index.js +26 -0
  72. package/lib/stores/app.d.ts +51 -0
  73. package/lib/stores/app.js +57 -0
  74. package/lib/stores/dict.d.ts +35 -0
  75. package/lib/stores/dict.js +42 -0
  76. package/lib/stores/im.d.ts +57 -0
  77. package/lib/stores/im.js +102 -0
  78. package/lib/stores/index.d.ts +12 -0
  79. package/lib/stores/index.js +17 -0
  80. package/lib/stores/launch.d.ts +42 -0
  81. package/lib/stores/launch.js +39 -0
  82. package/lib/stores/location.d.ts +35 -0
  83. package/lib/stores/location.js +58 -0
  84. package/lib/stores/login.d.ts +80 -0
  85. package/lib/stores/login.js +91 -0
  86. package/lib/stores/network.d.ts +26 -0
  87. package/lib/stores/network.js +45 -0
  88. package/lib/stores/pinia.d.ts +2 -0
  89. package/lib/stores/pinia.js +3 -0
  90. package/lib/stores/system.d.ts +39 -0
  91. package/lib/stores/system.js +36 -0
  92. package/lib/styles/index.scss +9 -0
  93. package/lib/styles/reset-vue.scss +15 -0
  94. package/lib/utils/audio.d.ts +14 -0
  95. package/lib/utils/audio.js +43 -0
  96. package/lib/utils/consts.d.ts +74 -0
  97. package/lib/utils/consts.js +110 -0
  98. package/lib/utils/cos.d.ts +17 -0
  99. package/lib/utils/cos.js +141 -0
  100. package/lib/utils/file.d.ts +28 -0
  101. package/lib/utils/file.js +292 -0
  102. package/lib/utils/index.d.ts +166 -0
  103. package/lib/utils/index.js +486 -0
  104. package/lib/utils/message.d.ts +1 -0
  105. package/lib/utils/message.js +55 -0
  106. package/lib/utils/navigate.d.ts +28 -0
  107. package/lib/utils/navigate.js +192 -0
  108. package/lib/utils/pages.d.ts +21 -0
  109. package/lib/utils/pages.js +83 -0
  110. package/lib/utils/permission.d.ts +17 -0
  111. package/lib/utils/permission.js +278 -0
  112. package/lib/utils/query.d.ts +20 -0
  113. package/lib/utils/query.js +51 -0
  114. package/lib/utils/request.d.ts +8 -0
  115. package/lib/utils/request.js +139 -0
  116. package/lib/utils/storage.d.ts +40 -0
  117. package/lib/utils/storage.js +128 -0
  118. package/lib/utils/subscribe.d.ts +7 -0
  119. package/lib/utils/subscribe.js +94 -0
  120. package/lib/utils/toast.d.ts +17 -0
  121. package/lib/utils/toast.js +66 -0
  122. package/lib/utils/uni.d.ts +1 -0
  123. package/lib/utils/uni.js +141 -0
  124. package/lib/utils/update.d.ts +41 -0
  125. package/lib/utils/update.js +322 -0
  126. package/lib/utils/url.d.ts +14 -0
  127. package/lib/utils/url.js +40 -0
  128. package/package.json +38 -4
  129. package/types/index.d.ts +78 -0
  130. package/types/virtual.d.ts +1 -0
@@ -0,0 +1,8 @@
1
+ /** 打印日志配置 */
2
+ const log = {
3
+ /** 打印请求日志 */
4
+ request: false,
5
+ /** 打印响应日志 */
6
+ response: false,
7
+ };
8
+ export default log;
@@ -0,0 +1,15 @@
1
+ declare const envVersions: readonly ["release", "develop", "trial"];
2
+ type EnvVersion = (typeof envVersions)[number];
3
+ type Mp = {
4
+ envVersion: EnvVersion;
5
+ envType: number;
6
+ };
7
+ /** 小程序配置 */
8
+ declare const mp: Mp;
9
+ export type MpConfig = {
10
+ /** 小程序环境 release正式版,develop开发板,trial体验版 */
11
+ envVersion?: EnvVersion;
12
+ /** 小程序环境 0正式版,1开发版,2体验版 */
13
+ envType?: number;
14
+ };
15
+ export default mp;
@@ -0,0 +1,9 @@
1
+ const envVersions = ['release', 'develop', 'trial'];
2
+ /** 小程序配置 */
3
+ const mp = {
4
+ /** 小程序环境 */
5
+ envVersion: 'release',
6
+ /** 小程序环境 */
7
+ envType: 0,
8
+ };
9
+ export default mp;
@@ -0,0 +1,17 @@
1
+ export type NavigateType = 'navigateTo' | 'reLaunch' | 'redirectTo';
2
+ export type ReferrerType = 'none' | 'target' | 'referrer' | 'combine';
3
+ /** 导航配置 */
4
+ type Navigate = {
5
+ /** 登录跳转类型 */
6
+ loginType: NavigateType;
7
+ /** 来源页面类型 */
8
+ referrerType: ReferrerType;
9
+ };
10
+ export type NavigateConfig = {
11
+ /** 登录跳转类型 */
12
+ loginType?: NavigateType;
13
+ /** 来源页面类型 */
14
+ referrerType?: ReferrerType;
15
+ };
16
+ declare const navigate: Navigate;
17
+ export default navigate;
@@ -0,0 +1,5 @@
1
+ const navigate = {
2
+ loginType: 'navigateTo',
3
+ referrerType: 'target',
4
+ };
5
+ export default navigate;
@@ -0,0 +1,18 @@
1
+ /** 页面集合配置 */
2
+ declare const page: {
3
+ /** 所有页面 */
4
+ pages: string[];
5
+ /** tabbar页面 */
6
+ tabBarPages: string[];
7
+ /** 原生页面 */
8
+ nativePages: string[];
9
+ /** 需要登录页面 */
10
+ needLoginPages: string[];
11
+ /** 无需重定向页面 */
12
+ notRedirectPages: string[];
13
+ };
14
+ type Keys = keyof typeof page;
15
+ export type PageConfig = {
16
+ [key in Keys]?: string[];
17
+ };
18
+ export default page;
@@ -0,0 +1,14 @@
1
+ /** 页面集合配置 */
2
+ const page = {
3
+ /** 所有页面 */
4
+ pages: [],
5
+ /** tabbar页面 */
6
+ tabBarPages: [],
7
+ /** 原生页面 */
8
+ nativePages: [],
9
+ /** 需要登录页面 */
10
+ needLoginPages: [],
11
+ /** 无需重定向页面 */
12
+ notRedirectPages: [],
13
+ };
14
+ export default page;
@@ -0,0 +1,11 @@
1
+ /** 页面别名配置 */
2
+ declare const path: {
3
+ /** 首页 */
4
+ index: string;
5
+ /** 登录页 */
6
+ login: string;
7
+ /** webview页面 */
8
+ webview: string;
9
+ };
10
+ export type PathConfig = Partial<typeof path>;
11
+ export default path;
@@ -0,0 +1,10 @@
1
+ /** 页面别名配置 */
2
+ const path = {
3
+ /** 首页 */
4
+ index: '/pages/index/index',
5
+ /** 登录页 */
6
+ login: '/pages/login/login',
7
+ /** webview页面 */
8
+ webview: '/pages/webview/webview',
9
+ };
10
+ export default path;
@@ -0,0 +1,7 @@
1
+ /** 存储配置 */
2
+ declare const storage: {
3
+ /** 存储前缀 */
4
+ prefix: string;
5
+ };
6
+ export type StorageConfig = Partial<typeof storage>;
7
+ export default storage;
@@ -0,0 +1,6 @@
1
+ /** 存储配置 */
2
+ const storage = {
3
+ /** 存储前缀 */
4
+ prefix: 'zfqh',
5
+ };
6
+ export default storage;
@@ -0,0 +1,7 @@
1
+ /** tabbar配置 */
2
+ declare const tabbar: {
3
+ /** 角标索引 */
4
+ badgeIndex: number;
5
+ };
6
+ export type TabbarConfig = Partial<typeof tabbar>;
7
+ export default tabbar;
@@ -0,0 +1,6 @@
1
+ /** tabbar配置 */
2
+ const tabbar = {
3
+ /** 角标索引 */
4
+ badgeIndex: -1,
5
+ };
6
+ export default tabbar;
@@ -0,0 +1,18 @@
1
+ /** toast配置 */
2
+ declare const toast: {
3
+ /** 是否自定义 */
4
+ custom: boolean;
5
+ /** 自定义toast显式逻辑 */
6
+ show(options: UniNamespace.ShowToastOptions): boolean;
7
+ /** 自定义toast隐藏逻辑 */
8
+ hide(): boolean;
9
+ };
10
+ export type ToastConfig = {
11
+ /** 是否自定义 */
12
+ custom?: boolean;
13
+ /** 自定义toast显式逻辑 */
14
+ show?(options: UniNamespace.ShowToastOptions): boolean;
15
+ /** 自定义toast隐藏逻辑 */
16
+ hide?(): boolean;
17
+ };
18
+ export default toast;
@@ -0,0 +1,29 @@
1
+ /** toast配置 */
2
+ const toast = {
3
+ /** 是否自定义 */
4
+ custom: false,
5
+ /** 自定义toast显式逻辑 */
6
+ show(options) {
7
+ const page = getCurrentPages().pop();
8
+ if (page?.$vm?.$refs?.toast?.show) {
9
+ const { icon, title, ...rest } = options;
10
+ page.$vm.$refs.toast.show({
11
+ type: ['error', 'success'].includes(icon) ? icon : 'default',
12
+ message: title,
13
+ ...rest,
14
+ });
15
+ return true;
16
+ }
17
+ return false;
18
+ },
19
+ /** 自定义toast隐藏逻辑 */
20
+ hide() {
21
+ const page = getCurrentPages().pop();
22
+ if (page?.$vm?.$refs?.toast?.hide) {
23
+ page.$vm.$refs.toast.hide();
24
+ return true;
25
+ }
26
+ return false;
27
+ },
28
+ };
29
+ export default toast;
@@ -0,0 +1,15 @@
1
+ /** 更新配置参数 */
2
+ export type UpdateParams = {
3
+ version: number;
4
+ appId: string;
5
+ type: number;
6
+ platform?: string;
7
+ };
8
+ /** 更新配置 */
9
+ export type UpdaterConfig = {
10
+ /** 版本检查请求,客户端可根据业务自行覆盖 */
11
+ request: (params: UpdateParams) => Promise<any>;
12
+ };
13
+ /** 更新配置 */
14
+ declare const Updater: UpdaterConfig;
15
+ export default Updater;
@@ -0,0 +1,33 @@
1
+ import { getLastVersion } from '../apis/core';
2
+ import cdn from './cdn';
3
+ /** 将 COS 链接转为静态域名链接 */
4
+ function convertCosUrl(url) {
5
+ if (!url)
6
+ return url;
7
+ const isAccelerate = !!cdn.isAccelerate;
8
+ // 非加速模式仅处理 .apk
9
+ if (!isAccelerate && !/\.apk$/i.test(url))
10
+ return url;
11
+ const match = url.match(/^https?:\/\/([^.]+)\.cos\.[^.]+\.myqcloud\.com(\/.+)/);
12
+ if (!match)
13
+ return url;
14
+ const [, bucket, path] = match;
15
+ const envMatch = bucket.match(/^([a-z]+)-zfqh-/);
16
+ const envPrefix = envMatch ? envMatch[1] : '';
17
+ if (envPrefix) {
18
+ return `https://${envPrefix}-static.qihuang-ai.com${path}`;
19
+ }
20
+ return `https://${isAccelerate ? 'acc-' : ''}static.qihuang-ai.com${path}`;
21
+ }
22
+ /** 更新配置 */
23
+ const Updater = {
24
+ /** 版本检查请求,默认调用 getLastVersion 并处理 COS 链接 */
25
+ request: async (params) => {
26
+ const res = await getLastVersion(params, { custom: { message: false } });
27
+ if (res?.data?.fileUrl) {
28
+ res.data.fileUrl = convertCosUrl(res.data.fileUrl);
29
+ }
30
+ return res;
31
+ },
32
+ };
33
+ export default Updater;
@@ -0,0 +1,30 @@
1
+ export type UploadResponceData = {
2
+ /** 秘钥ID */
3
+ secret_id?: string;
4
+ /** 秘钥KEY */
5
+ secret_key?: string;
6
+ /** 上传Token */
7
+ session_token?: string;
8
+ /** Token生成时间 */
9
+ create_time?: number;
10
+ /** Token过期时间 */
11
+ expire_time?: number;
12
+ /** 空间别名 */
13
+ bucket?: string;
14
+ /** 空间所属区域别名 */
15
+ region?: string;
16
+ [key: string]: any;
17
+ };
18
+ type UploadParams = {
19
+ /** 上传类型 */
20
+ mode?: 'cos' | 'oss' | 'none';
21
+ [key: string]: any;
22
+ };
23
+ /** 上传配置 */
24
+ export type UploadConfig = {
25
+ /** 上传请求,例如获取Token */
26
+ request: (params?: UploadParams) => Promise<UploadResponceData>;
27
+ };
28
+ /** 上传配置 */
29
+ declare const Upload: UploadConfig;
30
+ export default Upload;
@@ -0,0 +1,19 @@
1
+ import { getTencentToken } from '../apis/core';
2
+ import cdn from './cdn';
3
+ /** 上传配置 */
4
+ const Upload = {
5
+ /** 上传请求,默认调用 getTencentToken 获取腾讯云临时密钥 */
6
+ request: async () => {
7
+ const { data } = await getTencentToken();
8
+ return {
9
+ secret_id: data.tmpSecretId,
10
+ secret_key: data.tmpSecretKey,
11
+ session_token: data.sessionToken,
12
+ create_time: data.createTime,
13
+ expire_time: data.expirationTime,
14
+ bucket: data.bucket,
15
+ region: cdn.isAccelerate ? 'accelerate' : data.region,
16
+ };
17
+ },
18
+ };
19
+ export default Upload;
@@ -0,0 +1,8 @@
1
+ /** 版本配置 */
2
+ declare const ver: {
3
+ code: number;
4
+ name: string;
5
+ suffix: string;
6
+ };
7
+ export type VerConfig = Partial<typeof ver>;
8
+ export default ver;
@@ -0,0 +1,28 @@
1
+ import { reactive } from 'vue';
2
+ // #ifndef APP-PLUS
3
+ import { SYSTEM_INFO } from '../utils/consts';
4
+ // #endif
5
+ /** 版本配置 */
6
+ const ver = reactive({
7
+ /** 版本号 */
8
+ code: 0,
9
+ /** 版本名 */
10
+ name: '',
11
+ /** 版本名后缀 */
12
+ suffix: '',
13
+ });
14
+ // #ifdef APP-PLUS
15
+ plus.runtime.getProperty(plus.runtime.appid, (e) => {
16
+ if (!ver.code) {
17
+ ver.code = Number(e.versionCode);
18
+ }
19
+ if (!ver.name) {
20
+ ver.name = e.version;
21
+ }
22
+ });
23
+ // #endif
24
+ // #ifndef APP-PLUS
25
+ ver.code = Number(SYSTEM_INFO.appVersionCode);
26
+ ver.name = SYSTEM_INFO.appVersion;
27
+ // #endif
28
+ export default ver;
@@ -0,0 +1,5 @@
1
+ export type WebConfig = {
2
+ [key: string]: string;
3
+ };
4
+ declare const web: WebConfig;
5
+ export default web;
@@ -0,0 +1,2 @@
1
+ const web = {};
2
+ export default web;
@@ -0,0 +1,11 @@
1
+ export * from './useOverlay';
2
+ export * from './usePopup';
3
+ export * from './useVersion';
4
+ export * from './useReferrer';
5
+ export * from './useNeedLogin';
6
+ export * from './usePageShow';
7
+ export * from './useBadge';
8
+ export * from './useAppLifecycle';
9
+ export * from './useShare';
10
+ export * from './useWebview';
11
+ export * from './useRedirect';
@@ -0,0 +1,11 @@
1
+ export * from './useOverlay';
2
+ export * from './usePopup';
3
+ export * from './useVersion';
4
+ export * from './useReferrer';
5
+ export * from './useNeedLogin';
6
+ export * from './usePageShow';
7
+ export * from './useBadge';
8
+ export * from './useAppLifecycle';
9
+ export * from './useShare';
10
+ export * from './useWebview';
11
+ export * from './useRedirect';
@@ -0,0 +1,8 @@
1
+ /**
2
+ * App 生命周期逻辑(网络监听、启动参数、启动页登录拦截)。
3
+ * 只返回处理器,由 App.vue / App.uvue 的生命周期手动调用。
4
+ */
5
+ export declare function useAppLifecycle(): {
6
+ handleLaunch: (options?: any) => void;
7
+ handleShow: (options?: any) => void;
8
+ };
@@ -0,0 +1,87 @@
1
+ import { IS_WEBVIEW_ENV } from '../utils/consts';
2
+ import navigate from '../utils/navigate';
3
+ import { inPages } from '../utils/pages';
4
+ import page from '../configs/page';
5
+ import { pinia } from '../stores/pinia';
6
+ import { useLaunchStore } from '../stores/launch';
7
+ import { useLoginStore } from '../stores/login';
8
+ import { useNetworkStore } from '../stores/network';
9
+ let networkListening = false;
10
+ /**
11
+ * App 生命周期逻辑(网络监听、启动参数、启动页登录拦截)。
12
+ * 只返回处理器,由 App.vue / App.uvue 的生命周期手动调用。
13
+ */
14
+ export function useAppLifecycle() {
15
+ const loginStore = useLoginStore(pinia);
16
+ const networkStore = useNetworkStore(pinia);
17
+ const launchStore = useLaunchStore(pinia);
18
+ function handleLaunch(options = {}) {
19
+ if (!networkListening) {
20
+ networkListening = true;
21
+ networkStore.getNetworkInfo();
22
+ if (typeof uni.onNetworkStatusChange === 'function') {
23
+ uni.onNetworkStatusChange((e) => {
24
+ networkStore.setNetworkInfo({
25
+ type: e.networkType,
26
+ });
27
+ });
28
+ }
29
+ }
30
+ // 检测启动页面是否需要登录
31
+ if (!loginStore.isLogin) {
32
+ const path = `/${options.path || ''}`;
33
+ const query = options.query || {};
34
+ if (inPages(page.needLoginPages, path)) {
35
+ (async () => {
36
+ // #ifdef H5
37
+ if (IS_WEBVIEW_ENV && !uni.webView) {
38
+ function checkWebView() {
39
+ if (!uni.webView) {
40
+ return new Promise((res) => {
41
+ setTimeout(() => {
42
+ res(checkWebView());
43
+ }, 100);
44
+ });
45
+ }
46
+ return Promise.resolve();
47
+ }
48
+ // 延迟处理,防止uni.webView不生效
49
+ await checkWebView();
50
+ }
51
+ // #endif
52
+ navigate({
53
+ url: path,
54
+ params: query,
55
+ });
56
+ })();
57
+ }
58
+ }
59
+ }
60
+ function handleShow(options = {}) {
61
+ // 为了防止无意义的多次onShow执行,如选择文件、授权
62
+ // 操作时会将uni.showAppFromBackground设置为false
63
+ if (!uni.showAppFromBackground) {
64
+ if (uni.showAppFromBackground === false) {
65
+ setTimeout(() => {
66
+ // 需异步设置为true,否则App.onShow即使加了uni.showAppFromBackground判断,还是会执行
67
+ uni.showAppFromBackground = true;
68
+ });
69
+ }
70
+ }
71
+ else {
72
+ // 部分设备可能为string
73
+ if (typeof options.referrerInfo?.extraData === 'string') {
74
+ try {
75
+ options.referrerInfo.extraData = JSON.parse(options.referrerInfo.extraData);
76
+ }
77
+ catch (e) { }
78
+ }
79
+ // 设置启动信息
80
+ launchStore.setLaunchInfo(options);
81
+ }
82
+ }
83
+ return {
84
+ handleLaunch,
85
+ handleShow,
86
+ };
87
+ }
@@ -0,0 +1,8 @@
1
+ import { type MaybeRefOrGetter } from 'vue';
2
+ /** tabBar 未读角标 */
3
+ export declare function useBadge(unreadCount: MaybeRefOrGetter<number>): {
4
+ pageShow: import("vue").Ref<boolean>;
5
+ setTabBarBadge: () => void;
6
+ };
7
+ /** APP 应用角标 */
8
+ export declare function useAppBadge(unreadCount: MaybeRefOrGetter<number>): void;
@@ -0,0 +1,47 @@
1
+ import { toValue, watch } from 'vue';
2
+ import tabbar from '../configs/tabbar';
3
+ import { usePageShow } from './usePageShow';
4
+ /** tabBar 未读角标 */
5
+ export function useBadge(unreadCount) {
6
+ const pageShow = usePageShow();
7
+ function setTabBarBadge() {
8
+ if (tabbar.badgeIndex > 0) {
9
+ const count = Number(toValue(unreadCount)) || 0;
10
+ if (count) {
11
+ uni.setTabBarBadge({
12
+ index: tabbar.badgeIndex,
13
+ text: String(count),
14
+ fail() { },
15
+ });
16
+ }
17
+ else {
18
+ uni.removeTabBarBadge({
19
+ index: tabbar.badgeIndex,
20
+ fail() { },
21
+ });
22
+ }
23
+ }
24
+ }
25
+ watch(pageShow, (show) => {
26
+ if (show) {
27
+ setTabBarBadge();
28
+ }
29
+ });
30
+ watch(() => Number(toValue(unreadCount)) || 0, () => {
31
+ if (pageShow.value) {
32
+ setTabBarBadge();
33
+ }
34
+ }, { immediate: true });
35
+ return {
36
+ pageShow,
37
+ setTabBarBadge,
38
+ };
39
+ }
40
+ /** APP 应用角标 */
41
+ export function useAppBadge(unreadCount) {
42
+ // #ifdef APP-PLUS
43
+ watch(() => Number(toValue(unreadCount)) || 0, (count) => {
44
+ plus.runtime.setBadgeNumber(isNaN(count) ? 0 : count);
45
+ }, { immediate: true });
46
+ // #endif
47
+ }
@@ -0,0 +1 @@
1
+ export declare function useNeedLogin(flag?: boolean): void;
@@ -0,0 +1,27 @@
1
+ import { onPageShow } from '@dcloudio/uni-app';
2
+ import { pinia } from '../stores/pinia';
3
+ import { useLoginStore } from '../stores/login';
4
+ import page from '../configs/page';
5
+ import { inPages } from '../utils/pages';
6
+ import navigate from '../utils/navigate';
7
+ // #ifdef H5
8
+ import { IS_WEBVIEW_ENV } from '../utils/consts';
9
+ // #endif
10
+ export function useNeedLogin(flag = false) {
11
+ const loginStore = useLoginStore(pinia);
12
+ onPageShow(() => {
13
+ if (uni.showAppFromBackground) {
14
+ // #ifdef H5
15
+ if (IS_WEBVIEW_ENV && loginStore.state?.accessToken == null) {
16
+ return;
17
+ }
18
+ // #endif
19
+ const { route } = getCurrentPages().pop() || {};
20
+ if (!loginStore.isLogin && !!route) {
21
+ if (!flag || inPages(page.needLoginPages, `/${route}`)) {
22
+ navigate({ url: '', needLogin: true });
23
+ }
24
+ }
25
+ }
26
+ });
27
+ }
@@ -0,0 +1 @@
1
+ export declare function useOverlay(visible?: boolean, delay?: number): import("vue").Ref<boolean>[];
@@ -0,0 +1,17 @@
1
+ import { ref, watch } from 'vue';
2
+ export function useOverlay(visible = false, delay = 300) {
3
+ const showOverlay = ref(visible);
4
+ const showChildren = ref(visible);
5
+ watch(showOverlay, (e) => {
6
+ if (e) {
7
+ showChildren.value = true;
8
+ }
9
+ else {
10
+ setTimeout(() => {
11
+ showChildren.value = false;
12
+ }, delay);
13
+ }
14
+ });
15
+ return [showOverlay, showChildren];
16
+ }
17
+ ;
@@ -0,0 +1,2 @@
1
+ /** 页面显示状态 */
2
+ export declare function usePageShow(): import("vue").Ref<boolean>;
@@ -0,0 +1,16 @@
1
+ import { ref } from 'vue';
2
+ import { onPageHide, onPageShow, onUnload } from '@dcloudio/uni-app';
3
+ /** 页面显示状态 */
4
+ export function usePageShow() {
5
+ const pageShow = ref(false);
6
+ onPageShow(() => {
7
+ pageShow.value = true;
8
+ });
9
+ onPageHide(() => {
10
+ pageShow.value = false;
11
+ });
12
+ onUnload(() => {
13
+ pageShow.value = false;
14
+ });
15
+ return pageShow;
16
+ }
@@ -0,0 +1 @@
1
+ export declare function usePopup(visible: any): import("vue").Ref<any>;
@@ -0,0 +1,14 @@
1
+ import { ref, watch } from 'vue';
2
+ export function usePopup(visible) {
3
+ const popup = ref();
4
+ watch(visible, (e) => {
5
+ if (e) {
6
+ popup.value.open();
7
+ }
8
+ else {
9
+ popup.value.close();
10
+ }
11
+ });
12
+ return popup;
13
+ }
14
+ ;
@@ -0,0 +1,5 @@
1
+ import type { UseWebviewReturn } from './useWebview';
2
+ type RedirectWebview = Pick<UseWebviewReturn, 'postMessage'>;
3
+ /** 登录后重定向 */
4
+ export declare function useRedirect(webview?: RedirectWebview): void;
5
+ export {};