@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.
Files changed (310) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/LICENSE +21 -0
  3. package/README.md +39 -0
  4. package/docs/api/apis/core.md +189 -0
  5. package/docs/api/apis/index.md +82 -0
  6. package/docs/api/apis/request.md +369 -0
  7. package/docs/api/configs/api.md +32 -0
  8. package/docs/api/configs/app.md +43 -0
  9. package/docs/api/configs/brand.md +43 -0
  10. package/docs/api/configs/cdn.md +35 -0
  11. package/docs/api/configs/color.md +144 -0
  12. package/docs/api/configs/env.md +120 -0
  13. package/docs/api/configs/index.md +394 -0
  14. package/docs/api/configs/link.md +33 -0
  15. package/docs/api/configs/log.md +27 -0
  16. package/docs/api/configs/mp.md +34 -0
  17. package/docs/api/configs/navigate.md +27 -0
  18. package/docs/api/configs/page.md +32 -0
  19. package/docs/api/configs/path.md +27 -0
  20. package/docs/api/configs/storage.md +24 -0
  21. package/docs/api/configs/tabbar.md +29 -0
  22. package/docs/api/configs/toast.md +35 -0
  23. package/docs/api/configs/update.md +25 -0
  24. package/docs/api/configs/upload.md +45 -0
  25. package/docs/api/configs/ver.md +32 -0
  26. package/docs/api/configs/web.md +28 -0
  27. package/docs/api/hooks/index.md +182 -0
  28. package/docs/api/hooks/useI18n.md +27 -0
  29. package/docs/api/hooks/useOverlay.md +37 -0
  30. package/docs/api/hooks/usePopup.md +35 -0
  31. package/docs/api/hooks/useVersion.md +23 -0
  32. package/docs/api/index.md +269 -0
  33. package/docs/api/mixins/app.md +29 -0
  34. package/docs/api/mixins/badge.md +23 -0
  35. package/docs/api/mixins/debounce.md +32 -0
  36. package/docs/api/mixins/deep.md +29 -0
  37. package/docs/api/mixins/index.md +23 -0
  38. package/docs/api/mixins/login.md +22 -0
  39. package/docs/api/mixins/model.md +26 -0
  40. package/docs/api/mixins/redirect.md +26 -0
  41. package/docs/api/mixins/share.md +29 -0
  42. package/docs/api/mixins/show.md +27 -0
  43. package/docs/api/mixins/webview.md +27 -0
  44. package/docs/api/modules/app.md +30 -0
  45. package/docs/api/modules/dict.md +28 -0
  46. package/docs/api/modules/im.md +22 -0
  47. package/docs/api/modules/index.md +44 -0
  48. package/docs/api/modules/launch.md +26 -0
  49. package/docs/api/modules/location.md +25 -0
  50. package/docs/api/modules/login.md +35 -0
  51. package/docs/api/modules/network.md +26 -0
  52. package/docs/api/modules/system.md +29 -0
  53. package/docs/api/utils/audio.md +84 -0
  54. package/docs/api/utils/consts.md +201 -0
  55. package/docs/api/utils/cos.md +269 -0
  56. package/docs/api/utils/debounce.md +89 -0
  57. package/docs/api/utils/file.md +78 -0
  58. package/docs/api/utils/index.md +547 -0
  59. package/docs/api/utils/locale.md +32 -0
  60. package/docs/api/utils/message.md +81 -0
  61. package/docs/api/utils/navigate.md +267 -0
  62. package/docs/api/utils/pages.md +205 -0
  63. package/docs/api/utils/permission.md +28 -0
  64. package/docs/api/utils/permit.md +62 -0
  65. package/docs/api/utils/query.md +89 -0
  66. package/docs/api/utils/request.md +34 -0
  67. package/docs/api/utils/storage.md +145 -0
  68. package/docs/api/utils/subscribe.md +77 -0
  69. package/docs/api/utils/throttle.md +101 -0
  70. package/docs/api/utils/toast.md +164 -0
  71. package/docs/api/utils/uni.md +28 -0
  72. package/docs/api/utils/update.md +165 -0
  73. package/docs/components/g-back-button.md +76 -0
  74. package/docs/components/g-checkbox-list.md +101 -0
  75. package/docs/components/g-container.md +93 -0
  76. package/docs/components/g-data-list.md +106 -0
  77. package/docs/components/g-dot-text.md +79 -0
  78. package/docs/components/g-env.md +75 -0
  79. package/docs/components/g-float.md +83 -0
  80. package/docs/components/g-grid-image.md +91 -0
  81. package/docs/components/g-grid-swiper.md +99 -0
  82. package/docs/components/g-icon.md +106 -0
  83. package/docs/components/g-mask.md +82 -0
  84. package/docs/components/g-money.md +90 -0
  85. package/docs/components/g-more.md +78 -0
  86. package/docs/components/g-page-container.md +170 -0
  87. package/docs/components/g-permission-popup.md +117 -0
  88. package/docs/components/g-polyline-chat.md +102 -0
  89. package/docs/components/g-polyline-view.md +67 -0
  90. package/docs/components/g-popup.md +144 -0
  91. package/docs/components/g-refresh-view.md +118 -0
  92. package/docs/components/g-render-image.md +83 -0
  93. package/docs/components/g-search.md +120 -0
  94. package/docs/components/g-share-photo.md +77 -0
  95. package/docs/components/g-share-view.md +83 -0
  96. package/docs/components/g-share-weixin.md +81 -0
  97. package/docs/components/g-skeleton-view.md +71 -0
  98. package/docs/components/g-skeleton.md +64 -0
  99. package/docs/components/g-tag-editor.md +134 -0
  100. package/docs/components/g-timer.md +72 -0
  101. package/docs/components/g-trtc-room.md +116 -0
  102. package/docs/components/g-trtc-tui.md +84 -0
  103. package/docs/components/g-trtc.md +124 -0
  104. package/docs/components/g-upload.md +117 -0
  105. package/docs/components/g-waterfall.md +84 -0
  106. package/docs/components/index.md +109 -0
  107. package/docs/components/styles/base-styles.md +367 -0
  108. package/docs/components/styles/global-vars.md +150 -0
  109. package/docs/components/usage.md +112 -0
  110. package/docs/faq/index.md +78 -0
  111. package/docs/guide/getting-started.md +195 -0
  112. package/docs/guide/project-frame.md +297 -0
  113. package/docs/index.md +80 -0
  114. package/lib/apis/core.d.ts +12 -0
  115. package/lib/apis/core.js +13 -0
  116. package/lib/apis/index.d.ts +2 -0
  117. package/lib/apis/index.js +2 -0
  118. package/lib/apis/request.d.ts +4 -0
  119. package/lib/apis/request.js +27 -0
  120. package/lib/components/g-back-button/g-back-button.vue +141 -0
  121. package/lib/components/g-checkbox-list/g-checkbox-list.vue +156 -0
  122. package/lib/components/g-container/g-container.vue +159 -0
  123. package/lib/components/g-data-list/g-data-list.vue +192 -0
  124. package/lib/components/g-dot-text/g-dot-text.vue +114 -0
  125. package/lib/components/g-env/g-env.vue +123 -0
  126. package/lib/components/g-float/g-float.vue +131 -0
  127. package/lib/components/g-grid-image/g-grid-image.vue +84 -0
  128. package/lib/components/g-grid-swiper/g-grid-swiper.vue +224 -0
  129. package/lib/components/g-icon/g-icon.vue +72 -0
  130. package/lib/components/g-mask/g-mask.vue +126 -0
  131. package/lib/components/g-money/g-money.vue +174 -0
  132. package/lib/components/g-more/g-more.vue +68 -0
  133. package/lib/components/g-page-container/g-page-container.vue +470 -0
  134. package/lib/components/g-permission-popup/g-permission-popup.vue +80 -0
  135. package/lib/components/g-polyline-chat/g-polyline-chat.vue +255 -0
  136. package/lib/components/g-polyline-view/g-polyline-view.vue +104 -0
  137. package/lib/components/g-popup/g-popup.vue +449 -0
  138. package/lib/components/g-refresh-view/g-refresh-view.vue +213 -0
  139. package/lib/components/g-render-image/g-render-image.vue +222 -0
  140. package/lib/components/g-search/g-search.vue +274 -0
  141. package/lib/components/g-share-photo/g-share-photo.vue +75 -0
  142. package/lib/components/g-share-view/g-share-view.vue +157 -0
  143. package/lib/components/g-share-weixin/g-share-weixin.vue +106 -0
  144. package/lib/components/g-skeleton/g-skeleton.vue +55 -0
  145. package/lib/components/g-skeleton-view/g-skeleton-view.vue +78 -0
  146. package/lib/components/g-tag-editor/g-tag-editor.vue +482 -0
  147. package/lib/components/g-timer/g-timer.vue +61 -0
  148. package/lib/components/g-trtc/g-trtc.vue +347 -0
  149. package/lib/components/g-trtc-room/g-trtc-room.vue +524 -0
  150. package/lib/components/g-trtc-room/iconfont.scss +59 -0
  151. package/lib/components/g-trtc-tui/g-trtc-tui.vue +245 -0
  152. package/lib/components/g-upload/g-upload.vue +294 -0
  153. package/lib/components/g-waterfall/g-waterfall.vue +101 -0
  154. package/lib/configs/api.d.ts +7 -0
  155. package/lib/configs/api.js +6 -0
  156. package/lib/configs/app.d.ts +26 -0
  157. package/lib/configs/app.js +50 -0
  158. package/lib/configs/brand.d.ts +22 -0
  159. package/lib/configs/brand.js +26 -0
  160. package/lib/configs/cdn.d.ts +13 -0
  161. package/lib/configs/cdn.js +12 -0
  162. package/lib/configs/color.d.ts +62 -0
  163. package/lib/configs/color.js +66 -0
  164. package/lib/configs/env.d.ts +37 -0
  165. package/lib/configs/env.js +71 -0
  166. package/lib/configs/index.d.ts +170 -0
  167. package/lib/configs/index.js +82 -0
  168. package/lib/configs/link.d.ts +11 -0
  169. package/lib/configs/link.js +3 -0
  170. package/lib/configs/log.d.ts +9 -0
  171. package/lib/configs/log.js +8 -0
  172. package/lib/configs/mp.d.ts +15 -0
  173. package/lib/configs/mp.js +9 -0
  174. package/lib/configs/navigate.d.ts +17 -0
  175. package/lib/configs/navigate.js +5 -0
  176. package/lib/configs/page.d.ts +18 -0
  177. package/lib/configs/page.js +14 -0
  178. package/lib/configs/path.d.ts +11 -0
  179. package/lib/configs/path.js +10 -0
  180. package/lib/configs/storage.d.ts +7 -0
  181. package/lib/configs/storage.js +6 -0
  182. package/lib/configs/tabbar.d.ts +7 -0
  183. package/lib/configs/tabbar.js +6 -0
  184. package/lib/configs/toast.d.ts +18 -0
  185. package/lib/configs/toast.js +29 -0
  186. package/lib/configs/update.d.ts +45 -0
  187. package/lib/configs/update.js +6 -0
  188. package/lib/configs/upload.d.ts +30 -0
  189. package/lib/configs/upload.js +7 -0
  190. package/lib/configs/ver.d.ts +8 -0
  191. package/lib/configs/ver.js +28 -0
  192. package/lib/configs/web.d.ts +5 -0
  193. package/lib/configs/web.js +2 -0
  194. package/lib/hooks/index.d.ts +4 -0
  195. package/lib/hooks/index.js +4 -0
  196. package/lib/hooks/useI18n.d.ts +2 -0
  197. package/lib/hooks/useI18n.js +19 -0
  198. package/lib/hooks/useOverlay.d.ts +1 -0
  199. package/lib/hooks/useOverlay.js +17 -0
  200. package/lib/hooks/usePopup.d.ts +1 -0
  201. package/lib/hooks/usePopup.js +14 -0
  202. package/lib/hooks/useVersion.d.ts +6 -0
  203. package/lib/hooks/useVersion.js +21 -0
  204. package/lib/index.d.ts +26 -0
  205. package/lib/index.js +33 -0
  206. package/lib/mixins/app.d.ts +14 -0
  207. package/lib/mixins/app.js +105 -0
  208. package/lib/mixins/badge.d.ts +24 -0
  209. package/lib/mixins/badge.js +44 -0
  210. package/lib/mixins/debounce.d.ts +6 -0
  211. package/lib/mixins/debounce.js +11 -0
  212. package/lib/mixins/deep.d.ts +6 -0
  213. package/lib/mixins/deep.js +8 -0
  214. package/lib/mixins/index.d.ts +8 -0
  215. package/lib/mixins/index.js +8 -0
  216. package/lib/mixins/login.d.ts +4 -0
  217. package/lib/mixins/login.js +25 -0
  218. package/lib/mixins/model.d.ts +22 -0
  219. package/lib/mixins/model.js +29 -0
  220. package/lib/mixins/redirect.d.ts +8 -0
  221. package/lib/mixins/redirect.js +94 -0
  222. package/lib/mixins/share.d.ts +15 -0
  223. package/lib/mixins/share.js +55 -0
  224. package/lib/mixins/show.d.ts +9 -0
  225. package/lib/mixins/show.js +16 -0
  226. package/lib/mixins/webview.d.ts +26 -0
  227. package/lib/mixins/webview.js +225 -0
  228. package/lib/modules/app.d.ts +5 -0
  229. package/lib/modules/app.js +19 -0
  230. package/lib/modules/dict.d.ts +8 -0
  231. package/lib/modules/dict.js +43 -0
  232. package/lib/modules/im.d.ts +6 -0
  233. package/lib/modules/im.js +105 -0
  234. package/lib/modules/index.d.ts +8 -0
  235. package/lib/modules/index.js +8 -0
  236. package/lib/modules/launch.d.ts +5 -0
  237. package/lib/modules/launch.js +32 -0
  238. package/lib/modules/location.d.ts +5 -0
  239. package/lib/modules/location.js +57 -0
  240. package/lib/modules/login.d.ts +5 -0
  241. package/lib/modules/login.js +72 -0
  242. package/lib/modules/network.d.ts +5 -0
  243. package/lib/modules/network.js +39 -0
  244. package/lib/modules/system.d.ts +5 -0
  245. package/lib/modules/system.js +65 -0
  246. package/lib/styles/animate-vue.scss +3 -0
  247. package/lib/styles/animate.scss +27 -0
  248. package/lib/styles/bg-vue.scss +21 -0
  249. package/lib/styles/bg.scss +93 -0
  250. package/lib/styles/border.scss +218 -0
  251. package/lib/styles/flex-nvue.scss +64 -0
  252. package/lib/styles/flex-vue.scss +75 -0
  253. package/lib/styles/font.scss +59 -0
  254. package/lib/styles/index.scss +25 -0
  255. package/lib/styles/layout-nvue.scss +24 -0
  256. package/lib/styles/layout-vue.scss +30 -0
  257. package/lib/styles/layout.scss +76 -0
  258. package/lib/styles/opacity.scss +10 -0
  259. package/lib/styles/reset-vue.scss +46 -0
  260. package/lib/styles/shadow.scss +12 -0
  261. package/lib/styles/sizing-vue.scss +21 -0
  262. package/lib/styles/sizing.scss +21 -0
  263. package/lib/styles/spacing.scss +234 -0
  264. package/lib/styles/text-nvue.scss +21 -0
  265. package/lib/styles/text-vue.scss +70 -0
  266. package/lib/styles/text.scss +122 -0
  267. package/lib/styles/var.module.scss +29 -0
  268. package/lib/utils/audio.d.ts +14 -0
  269. package/lib/utils/audio.js +43 -0
  270. package/lib/utils/consts.d.ts +30 -0
  271. package/lib/utils/consts.js +52 -0
  272. package/lib/utils/cos.d.ts +15 -0
  273. package/lib/utils/cos.js +140 -0
  274. package/lib/utils/debounce.d.ts +2 -0
  275. package/lib/utils/debounce.js +30 -0
  276. package/lib/utils/file.d.ts +28 -0
  277. package/lib/utils/file.js +292 -0
  278. package/lib/utils/index.d.ts +166 -0
  279. package/lib/utils/index.js +485 -0
  280. package/lib/utils/locale.d.ts +6 -0
  281. package/lib/utils/locale.js +19 -0
  282. package/lib/utils/message.d.ts +9 -0
  283. package/lib/utils/message.js +63 -0
  284. package/lib/utils/navigate.d.ts +27 -0
  285. package/lib/utils/navigate.js +183 -0
  286. package/lib/utils/pages.d.ts +21 -0
  287. package/lib/utils/pages.js +79 -0
  288. package/lib/utils/permission.d.ts +16 -0
  289. package/lib/utils/permission.js +291 -0
  290. package/lib/utils/permit.d.ts +30 -0
  291. package/lib/utils/permit.js +181 -0
  292. package/lib/utils/query.d.ts +13 -0
  293. package/lib/utils/query.js +14 -0
  294. package/lib/utils/request.d.ts +8 -0
  295. package/lib/utils/request.js +126 -0
  296. package/lib/utils/storage.d.ts +53 -0
  297. package/lib/utils/storage.js +145 -0
  298. package/lib/utils/subscribe.d.ts +7 -0
  299. package/lib/utils/subscribe.js +94 -0
  300. package/lib/utils/throttle.d.ts +2 -0
  301. package/lib/utils/throttle.js +32 -0
  302. package/lib/utils/toast.d.ts +17 -0
  303. package/lib/utils/toast.js +66 -0
  304. package/lib/utils/uni.d.ts +1 -0
  305. package/lib/utils/uni.js +147 -0
  306. package/lib/utils/update.d.ts +9 -0
  307. package/lib/utils/update.js +376 -0
  308. package/package.json +49 -0
  309. package/types/index.d.ts +25 -0
  310. package/types/virtual.d.ts +1 -0
@@ -0,0 +1,183 @@
1
+ import page from '../configs/page';
2
+ import nav from '../configs/navigate';
3
+ import app from '../configs/app';
4
+ import { IS_WEBVIEW_ENV, WEBVIEW_ENV } from './consts';
5
+ import { inPages, getPage } from './pages';
6
+ import { joinPath } from './index';
7
+ // 检测协议路径
8
+ const checkProtocolMatch = (url) => url.match(/^(\w+):\//);
9
+ // 转换绝对路径
10
+ const getAbsoUrl = (url, current) => {
11
+ if (!url.startsWith('/') && !checkProtocolMatch(url)) {
12
+ url = joinPath(current, url);
13
+ if (!url.startsWith('/')) {
14
+ url = `/${url}`;
15
+ }
16
+ }
17
+ return url;
18
+ };
19
+ // 节流,防止重复执行
20
+ let throttling = false;
21
+ const navigate = function (url = '', type = 'navigateTo') {
22
+ if (!throttling) {
23
+ throttling = true;
24
+ setTimeout(() => {
25
+ throttling = false;
26
+ }, 500);
27
+ let needLogin = false;
28
+ let isNative = !page.pages?.length;
29
+ let navigateOptions = {};
30
+ let webviewParams = {};
31
+ let loginType = nav.loginType;
32
+ let referrerType = nav.referrerType;
33
+ let opts = {};
34
+ if (typeof url === 'string') {
35
+ url = { url };
36
+ }
37
+ if (typeof url === 'object') {
38
+ opts = url;
39
+ const { type: _type, url: _url = '', params: _params = {}, webviewParams: _webviewParams = {}, needLogin: _needLogin = needLogin, loginType: _loginType = loginType, referrerType: _referrerType = referrerType, native: _isNative = isNative, ...rest } = url;
40
+ url = `${_url}${uni.$uv.queryParams(_params)}`;
41
+ needLogin = !!_needLogin;
42
+ isNative = !!_isNative;
43
+ loginType = _loginType;
44
+ referrerType = _referrerType;
45
+ type = _type || type;
46
+ webviewParams = _webviewParams;
47
+ navigateOptions = rest;
48
+ }
49
+ const indexPage = getPage('index').replace(/^\/+/, '');
50
+ const loginPage = getPage('login');
51
+ const webviewPage = getPage('webview');
52
+ const { isLogin } = uni.$store?.getters || {};
53
+ const { route = indexPage, options = {} } = (getCurrentPages().pop() || {});
54
+ const current = `/${route}${uni.$uv.queryParams(options)}`;
55
+ let absoUrl = getAbsoUrl(url, current);
56
+ let originalUrl = url;
57
+ url = navigate.interceptor.call(this, url, absoUrl);
58
+ if (typeof url !== 'string') {
59
+ throttling = false;
60
+ return;
61
+ }
62
+ if (originalUrl !== url) {
63
+ originalUrl = url;
64
+ absoUrl = getAbsoUrl(url, current);
65
+ }
66
+ if (!originalUrl) {
67
+ if (isLogin) {
68
+ throttling = false;
69
+ return;
70
+ }
71
+ // 跳转地址为空表示需要登录
72
+ needLogin = true;
73
+ }
74
+ // 路径转为绝对路径
75
+ url = absoUrl;
76
+ // 是否需要登录
77
+ if (!needLogin) {
78
+ needLogin = inPages(page.needLoginPages, url);
79
+ }
80
+ // 是否是原生页面
81
+ if (!isNative && url.startsWith('/')) {
82
+ isNative = inPages(page.nativePages, url);
83
+ }
84
+ if (!isNative) {
85
+ if (app?.code && !checkProtocolMatch(url)) {
86
+ url = `${app.code}:/${url}`;
87
+ }
88
+ }
89
+ else if (IS_WEBVIEW_ENV && opts['native'] === false) {
90
+ isNative = false;
91
+ }
92
+ const protocolMatch = checkProtocolMatch(url);
93
+ // 带协议路径需要转换为webview方式加载
94
+ if (protocolMatch) {
95
+ isNative = true;
96
+ const params = Object.assign({}, webviewParams);
97
+ if (/^https?:/.test(url)) {
98
+ // #ifdef H5
99
+ // 一些网站同源策略,无法iframe中打开
100
+ if ((WEBVIEW_ENV.h5 || !IS_WEBVIEW_ENV) && ['mp.weixin.qq.com'].includes(new URL(url).hostname)) {
101
+ top.location.href = url;
102
+ return false;
103
+ }
104
+ // #endif
105
+ // http协议
106
+ Object.assign(params, { url: encodeURIComponent(url) });
107
+ }
108
+ else {
109
+ // 自定义协议
110
+ url = url.replace(new RegExp(`^(${protocolMatch[0]})`), '');
111
+ Object.assign(params, { url: encodeURIComponent(url), app: protocolMatch[1] });
112
+ }
113
+ url = `${webviewPage}${uni.$uv.queryParams(params)}`;
114
+ }
115
+ if (needLogin) {
116
+ if (!isLogin) {
117
+ const opts = {
118
+ url: loginPage,
119
+ };
120
+ if (referrerType === 'combine') {
121
+ // 登录后会先跳转到来源页面,再跳转目标页面
122
+ if (url !== current) {
123
+ url = `/${route}${uni.$uv.queryParams({ ...options, __navigate: encodeURIComponent(url) })}`;
124
+ }
125
+ }
126
+ else if (referrerType === 'referrer') {
127
+ // 登录后跳转到来源页面
128
+ url = current;
129
+ }
130
+ else if (referrerType === 'target') {
131
+ // 登录后跳转到目标页面
132
+ }
133
+ if (['target', 'referrer', 'combine'].includes(referrerType)) {
134
+ opts.url += `${opts.url.includes('?') ? '&' : '?'}__referrer=${encodeURIComponent(url)}`;
135
+ }
136
+ if (uni.webView && IS_WEBVIEW_ENV) {
137
+ uni.webView[loginType](opts);
138
+ }
139
+ else {
140
+ uni[loginType](opts);
141
+ }
142
+ return false;
143
+ }
144
+ }
145
+ if (originalUrl) {
146
+ if (inPages(page.tabBarPages, url)) {
147
+ if (['navigateTo', 'redirectTo'].includes(type)) {
148
+ type = 'switchTab';
149
+ }
150
+ }
151
+ if (isNative && uni.webView && IS_WEBVIEW_ENV) {
152
+ uni.webView[type]({
153
+ url,
154
+ });
155
+ }
156
+ else {
157
+ uni[type]({
158
+ url,
159
+ ...navigateOptions,
160
+ });
161
+ }
162
+ }
163
+ }
164
+ };
165
+ navigate.reLaunch = (url) => {
166
+ navigate(url, 'reLaunch');
167
+ };
168
+ navigate.navigateTo = (url) => {
169
+ navigate(url, 'navigateTo');
170
+ };
171
+ navigate.switchTab = (url) => {
172
+ navigate(url, 'switchTab');
173
+ };
174
+ navigate.redirectTo = (url) => {
175
+ navigate(url, 'redirectTo');
176
+ };
177
+ navigate.back = (e) => {
178
+ uni.navigateBack(e);
179
+ };
180
+ navigate.interceptor = (...args) => {
181
+ return args[0];
182
+ };
183
+ export default navigate;
@@ -0,0 +1,21 @@
1
+ export declare const getPage: (name: string) => string;
2
+ export declare const inPages: (pages: string[], url: string | {
3
+ url: string;
4
+ [key: string]: any;
5
+ }) => boolean;
6
+ export declare const createPages: (original?: {
7
+ pages?: any[];
8
+ subPackages?: any[];
9
+ tabBar?: any;
10
+ global?: {
11
+ native?: boolean;
12
+ needLogin?: boolean;
13
+ notRedirect?: boolean;
14
+ };
15
+ }, basePath?: string) => {
16
+ pages: string[];
17
+ tabBarPages: string[];
18
+ nativePages: string[];
19
+ needLoginPages: string[];
20
+ notRedirectPages: string[];
21
+ };
@@ -0,0 +1,79 @@
1
+ import path from '../configs/path';
2
+ export const getPage = (name) => {
3
+ let page = '';
4
+ if (path[name]) {
5
+ page = path[name];
6
+ }
7
+ return page;
8
+ };
9
+ export const inPages = (pages, url) => {
10
+ if (typeof url === 'object') {
11
+ url = url.url;
12
+ }
13
+ if (!Array.isArray(pages) || !url || typeof url !== 'string') {
14
+ return false;
15
+ }
16
+ return pages.some((page) => {
17
+ page = String(page);
18
+ const [path] = page.split('**');
19
+ if (path !== page) {
20
+ return url.startsWith(path);
21
+ }
22
+ return url.replace(/\?.*$/, '') === path;
23
+ });
24
+ };
25
+ export const createPages = (original = {}, basePath = '') => {
26
+ const pages = [];
27
+ const tabBarPages = [];
28
+ const nativePages = [];
29
+ const needLoginPages = [];
30
+ const notRedirectPages = [];
31
+ const create = ({ path, root, ...rest }) => {
32
+ if (path) {
33
+ const { native, needLogin, notRedirect } = { ...original.global, ...rest };
34
+ const array = [''];
35
+ if (basePath) {
36
+ array.push(basePath);
37
+ }
38
+ if (root && basePath !== `/${root}`) {
39
+ array.push(root);
40
+ }
41
+ array.push(path);
42
+ const page = array.join('/').replace(/\/+/, '/');
43
+ pages.push(page);
44
+ if (native || native == null) {
45
+ nativePages.push(page);
46
+ }
47
+ if (needLogin) {
48
+ needLoginPages.push(page);
49
+ }
50
+ if (notRedirect) {
51
+ notRedirectPages.push(page);
52
+ }
53
+ }
54
+ };
55
+ if (original.pages) {
56
+ original.pages.forEach((page) => {
57
+ create(page);
58
+ });
59
+ }
60
+ if (original.subPackages) {
61
+ original.subPackages.forEach(({ root, pages: list }) => {
62
+ list.forEach((page) => {
63
+ create(Object.assign(page, { root }));
64
+ });
65
+ });
66
+ }
67
+ if (original.tabBar && original.tabBar.list) {
68
+ original.tabBar.list.forEach(({ pagePath }) => {
69
+ tabBarPages.push(`/${pagePath}`);
70
+ });
71
+ }
72
+ return {
73
+ pages,
74
+ tabBarPages,
75
+ nativePages,
76
+ needLoginPages,
77
+ notRedirectPages,
78
+ };
79
+ };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * 本模块封装了Android、iOS的应用权限判断、打开应用权限设置界面、以及位置系统服务是否开启
3
+ */
4
+ declare function requestAndroidPermission(permissionID: string | string[]): Promise<unknown>;
5
+ declare function judgeIosPermission(permissionID: any): boolean;
6
+ declare function gotoAppPermissionSetting(): void;
7
+ declare function checkSystemEnableLocation(): Promise<any>;
8
+ declare function checkSystemEnableBluetooth(): Promise<unknown>;
9
+ declare const _default: {
10
+ judgeIosPermission: typeof judgeIosPermission;
11
+ requestAndroidPermission: typeof requestAndroidPermission;
12
+ checkSystemEnableLocation: typeof checkSystemEnableLocation;
13
+ checkSystemEnableBluetooth: typeof checkSystemEnableBluetooth;
14
+ gotoAppPermissionSetting: typeof gotoAppPermissionSetting;
15
+ };
16
+ export default _default;
@@ -0,0 +1,291 @@
1
+ /**
2
+ * 本模块封装了Android、iOS的应用权限判断、打开应用权限设置界面、以及位置系统服务是否开启
3
+ */
4
+ let isIos = false;
5
+ // #ifdef APP-PLUS
6
+ isIos = plus.os.name == 'iOS';
7
+ // #endif
8
+ // 判断推送权限是否开启
9
+ function judgeIosPermissionPush() {
10
+ let result = false;
11
+ const UIApplication = plus.ios.importClass('UIApplication');
12
+ const app = UIApplication.sharedApplication();
13
+ let enabledTypes = 0;
14
+ if (app.currentUserNotificationSettings) {
15
+ const settings = app.currentUserNotificationSettings();
16
+ enabledTypes = settings.plusGetAttribute('types');
17
+ console.log('enabledTypes1:' + enabledTypes);
18
+ if (enabledTypes == 0) {
19
+ console.log('推送权限没有开启');
20
+ }
21
+ else {
22
+ result = true;
23
+ console.log('已经开启推送功能!');
24
+ }
25
+ plus.ios.deleteObject(settings);
26
+ }
27
+ else {
28
+ enabledTypes = app.enabledRemoteNotificationTypes();
29
+ if (enabledTypes == 0) {
30
+ console.log('推送权限没有开启!');
31
+ }
32
+ else {
33
+ result = true;
34
+ console.log('已经开启推送功能!');
35
+ }
36
+ console.log('enabledTypes2:' + enabledTypes);
37
+ }
38
+ plus.ios.deleteObject(app);
39
+ plus.ios.deleteObject(UIApplication);
40
+ return result;
41
+ }
42
+ // 判断定位权限是否开启
43
+ function judgeIosPermissionLocation() {
44
+ let result = false;
45
+ const cllocationManger = plus.ios.importClass('CLLocationManager');
46
+ const status = cllocationManger.authorizationStatus();
47
+ result = status != 2;
48
+ console.log('定位权限开启:' + result);
49
+ // 以下代码判断了手机设备的定位是否关闭,推荐另行使用方法 checkSystemEnableLocation
50
+ /* var enable = cllocationManger.locationServicesEnabled();
51
+ var status = cllocationManger.authorizationStatus();
52
+ console.log("enable:" + enable);
53
+ console.log("status:" + status);
54
+ if (enable && status != 2) {
55
+ result = true;
56
+ console.log("手机定位服务已开启且已授予定位权限");
57
+ } else {
58
+ console.log("手机系统的定位没有打开或未给予定位权限");
59
+ } */
60
+ plus.ios.deleteObject(cllocationManger);
61
+ return result;
62
+ }
63
+ // 判断麦克风权限是否开启
64
+ function judgeIosPermissionRecord() {
65
+ let result = false;
66
+ const avaudiosession = plus.ios.importClass('AVAudioSession');
67
+ const avaudio = avaudiosession.sharedInstance();
68
+ const permissionStatus = avaudio.recordPermission();
69
+ console.log('permissionStatus:' + permissionStatus);
70
+ if (permissionStatus == 1684369017 || permissionStatus == 1970168948) {
71
+ console.log('麦克风权限没有开启');
72
+ }
73
+ else {
74
+ result = true;
75
+ console.log('麦克风权限已经开启');
76
+ }
77
+ plus.ios.deleteObject(avaudiosession);
78
+ return result;
79
+ }
80
+ // 判断相机权限是否开启
81
+ function judgeIosPermissionCamera() {
82
+ let result = false;
83
+ const AVCaptureDevice = plus.ios.importClass('AVCaptureDevice');
84
+ const authStatus = AVCaptureDevice.authorizationStatusForMediaType('vide');
85
+ console.log('authStatus:' + authStatus);
86
+ if (authStatus == 3) {
87
+ result = true;
88
+ console.log('相机权限已经开启');
89
+ }
90
+ else {
91
+ console.log('相机权限没有开启');
92
+ }
93
+ plus.ios.deleteObject(AVCaptureDevice);
94
+ return result;
95
+ }
96
+ // 判断相册权限是否开启
97
+ function judgeIosPermissionPhotoLibrary() {
98
+ let result = false;
99
+ const PHPhotoLibrary = plus.ios.importClass('PHPhotoLibrary');
100
+ const authStatus = PHPhotoLibrary.authorizationStatus();
101
+ console.log('authStatus:' + authStatus);
102
+ if (authStatus == 3) {
103
+ result = true;
104
+ console.log('相册权限已经开启');
105
+ }
106
+ else {
107
+ console.log('相册权限没有开启');
108
+ }
109
+ plus.ios.deleteObject(PHPhotoLibrary);
110
+ return result;
111
+ }
112
+ // 判断通讯录权限是否开启
113
+ function judgeIosPermissionContact() {
114
+ let result = false;
115
+ const CNContactStore = plus.ios.importClass('CNContactStore');
116
+ const cnAuthStatus = CNContactStore.authorizationStatusForEntityType(0);
117
+ if (cnAuthStatus == 3) {
118
+ result = true;
119
+ console.log('通讯录权限已经开启');
120
+ }
121
+ else {
122
+ console.log('通讯录权限没有开启');
123
+ }
124
+ plus.ios.deleteObject(CNContactStore);
125
+ return result;
126
+ }
127
+ // 判断日历权限是否开启
128
+ function judgeIosPermissionCalendar() {
129
+ let result = false;
130
+ const EKEventStore = plus.ios.importClass('EKEventStore');
131
+ const ekAuthStatus = EKEventStore.authorizationStatusForEntityType(0);
132
+ if (ekAuthStatus == 3) {
133
+ result = true;
134
+ console.log('日历权限已经开启');
135
+ }
136
+ else {
137
+ console.log('日历权限没有开启');
138
+ }
139
+ plus.ios.deleteObject(EKEventStore);
140
+ return result;
141
+ }
142
+ // 判断备忘录权限是否开启
143
+ function judgeIosPermissionMemo() {
144
+ let result = false;
145
+ const EKEventStore = plus.ios.importClass('EKEventStore');
146
+ const ekAuthStatus = EKEventStore.authorizationStatusForEntityType(1);
147
+ if (ekAuthStatus == 3) {
148
+ result = true;
149
+ console.log('备忘录权限已经开启');
150
+ }
151
+ else {
152
+ console.log('备忘录权限没有开启');
153
+ }
154
+ plus.ios.deleteObject(EKEventStore);
155
+ return result;
156
+ }
157
+ // Android权限查询
158
+ function requestAndroidPermission(permissionID) {
159
+ return new Promise((resolve) => {
160
+ plus.android.requestPermissions([].concat(permissionID), // 理论上支持多个权限同时查询,但实际上本函数封装只处理了一个权限的情况。有需要的可自行扩展封装
161
+ function (resultObj) {
162
+ let result = 0;
163
+ for (let i = 0; i < resultObj.granted.length; i++) {
164
+ const grantedPermission = resultObj.granted[i];
165
+ console.log('已获取的权限:' + grantedPermission);
166
+ result = 1;
167
+ }
168
+ for (let i = 0; i < resultObj.deniedPresent.length; i++) {
169
+ const deniedPresentPermission = resultObj.deniedPresent[i];
170
+ console.log('拒绝本次申请的权限:' + deniedPresentPermission);
171
+ result = 0;
172
+ }
173
+ for (let i = 0; i < resultObj.deniedAlways.length; i++) {
174
+ const deniedAlwaysPermission = resultObj.deniedAlways[i];
175
+ console.log('永久拒绝申请的权限:' + deniedAlwaysPermission);
176
+ result = -1;
177
+ }
178
+ resolve(result);
179
+ // 若所需权限被拒绝,则打开APP设置界面,可以在APP设置界面打开相应权限
180
+ // if (result != 1) {
181
+ // gotoAppPermissionSetting()
182
+ // }
183
+ }, function (error) {
184
+ console.log('申请权限错误:' + error.code + ' = ' + error.message);
185
+ resolve({
186
+ code: error.code,
187
+ message: error.message,
188
+ });
189
+ });
190
+ });
191
+ }
192
+ // 使用一个方法,根据参数判断权限
193
+ function judgeIosPermission(permissionID) {
194
+ if (permissionID == 'location') {
195
+ return judgeIosPermissionLocation();
196
+ }
197
+ else if (permissionID == 'camera') {
198
+ return judgeIosPermissionCamera();
199
+ }
200
+ else if (permissionID == 'photoLibrary') {
201
+ return judgeIosPermissionPhotoLibrary();
202
+ }
203
+ else if (permissionID == 'record') {
204
+ return judgeIosPermissionRecord();
205
+ }
206
+ else if (permissionID == 'push') {
207
+ return judgeIosPermissionPush();
208
+ }
209
+ else if (permissionID == 'contact') {
210
+ return judgeIosPermissionContact();
211
+ }
212
+ else if (permissionID == 'calendar') {
213
+ return judgeIosPermissionCalendar();
214
+ }
215
+ else if (permissionID == 'memo') {
216
+ return judgeIosPermissionMemo();
217
+ }
218
+ return false;
219
+ }
220
+ // 跳转到**应用**的权限页面
221
+ function gotoAppPermissionSetting() {
222
+ if (isIos) {
223
+ const UIApplication = plus.ios.importClass('UIApplication');
224
+ const application2 = UIApplication.sharedApplication();
225
+ const NSURL2 = plus.ios.importClass('NSURL');
226
+ // var setting2 = NSURL2.URLWithString("prefs:root=LOCATION_SERVICES");
227
+ const setting2 = NSURL2.URLWithString('app-settings:');
228
+ application2.openURL(setting2);
229
+ plus.ios.deleteObject(setting2);
230
+ plus.ios.deleteObject(NSURL2);
231
+ plus.ios.deleteObject(application2);
232
+ }
233
+ else {
234
+ // console.log(plus.device.vendor);
235
+ const Intent = plus.android.importClass('android.content.Intent');
236
+ const Settings = plus.android.importClass('android.provider.Settings');
237
+ const Uri = plus.android.importClass('android.net.Uri');
238
+ const mainActivity = plus.android.runtimeMainActivity();
239
+ const intent = new Intent();
240
+ intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
241
+ const uri = Uri.fromParts('package', mainActivity.getPackageName(), null);
242
+ intent.setData(uri);
243
+ mainActivity.startActivity(intent);
244
+ }
245
+ }
246
+ // 检查系统的设备服务是否开启
247
+ async function checkSystemEnableLocation() {
248
+ if (isIos) {
249
+ let result = false;
250
+ const cllocationManger = plus.ios.importClass('CLLocationManager');
251
+ result = cllocationManger.locationServicesEnabled();
252
+ console.log('系统定位开启:' + result);
253
+ plus.ios.deleteObject(cllocationManger);
254
+ return result;
255
+ }
256
+ else {
257
+ const context = plus.android.importClass('android.content.Context');
258
+ const locationManager = plus.android.importClass('android.location.LocationManager');
259
+ const main = plus.android.runtimeMainActivity();
260
+ const mainSvr = main.getSystemService(context.LOCATION_SERVICE);
261
+ const result = mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER) || uni.getSystemSetting().locationEnabled;
262
+ console.log('系统定位开启:' + result);
263
+ return result;
264
+ }
265
+ }
266
+ async function checkSystemEnableBluetooth() {
267
+ const result = new Promise((res) => {
268
+ if (isIos) {
269
+ res(true);
270
+ }
271
+ else {
272
+ const bluetoothAdapter = plus.android.importClass('android.bluetooth.BluetoothAdapter');
273
+ const adapter = bluetoothAdapter.getDefaultAdapter();
274
+ if (adapter?.isEnabled()) {
275
+ res(true);
276
+ }
277
+ else {
278
+ res(false);
279
+ }
280
+ }
281
+ });
282
+ console.log('系统蓝牙开启:' + result);
283
+ return result;
284
+ }
285
+ export default {
286
+ judgeIosPermission,
287
+ requestAndroidPermission,
288
+ checkSystemEnableLocation,
289
+ checkSystemEnableBluetooth,
290
+ gotoAppPermissionSetting,
291
+ };
@@ -0,0 +1,30 @@
1
+ declare const permissionData: {
2
+ location: {
3
+ id: string;
4
+ system: string;
5
+ content: string;
6
+ };
7
+ storage: {
8
+ id: string;
9
+ system: string;
10
+ content: string;
11
+ };
12
+ camera: {
13
+ id: string;
14
+ system: string;
15
+ content: string;
16
+ };
17
+ record: {
18
+ id: string;
19
+ system: string;
20
+ content: string;
21
+ };
22
+ bluetooth: {
23
+ id: string | string[];
24
+ system: string;
25
+ content: string;
26
+ };
27
+ };
28
+ export declare function openAuthorizeSetting(name: string): void;
29
+ export declare function requestPermission(name: keyof typeof permissionData, system?: boolean): Promise<number>;
30
+ export {};