@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,140 @@
1
+ import HmacSHA1 from 'crypto-js/hmac-sha1';
2
+ import SHA1 from 'crypto-js/sha1';
3
+ import Base64 from 'crypto-js/enc-base64';
4
+ import Crypto from 'crypto-js/core';
5
+ import upload from '../configs/upload';
6
+ import { cosCompress } from './index';
7
+ const data = {};
8
+ let promise = null;
9
+ export async function checkRefreshToken() {
10
+ if (!promise) {
11
+ // 每次上传都会生成token
12
+ // 批量上传一次多张使用一个token
13
+ promise = upload.request({ mode: 'cos' }).then((e) => {
14
+ Object.assign(data, e);
15
+ return true;
16
+ });
17
+ setTimeout(() => {
18
+ promise = null;
19
+ }, 1000);
20
+ }
21
+ return promise;
22
+ }
23
+ class COS {
24
+ async uploadFile(params) {
25
+ const { Bucket, Region, Key, FilePath, File } = params;
26
+ return new Promise((resolve, reject) => {
27
+ const cosHost = `${Bucket}.cos.${Region}.myqcloud.com`;
28
+ const now = data.create_time || Math.round(Date.now() / 1000);
29
+ const exp = now + 1800; // 30分钟过期
30
+ const qKeyTime = now + ';' + exp;
31
+ const qSignAlgorithm = 'sha1';
32
+ const qAk = data.secret_id;
33
+ const policyData = {
34
+ expiration: new Date(exp * 1000).toISOString(),
35
+ conditions: [
36
+ { 'q-sign-algorithm': qSignAlgorithm },
37
+ { 'q-ak': qAk },
38
+ { 'q-sign-time': qKeyTime },
39
+ { bucket: Bucket },
40
+ { key: Key },
41
+ ],
42
+ };
43
+ const policy = JSON.stringify(policyData);
44
+ const signKey = HmacSHA1(qKeyTime, data.secret_key).toString(Crypto.enc.Hex);
45
+ const stringToSign = SHA1(policy).toString(Crypto.enc.Hex);
46
+ const qSignature = HmacSHA1(stringToSign, signKey).toString(Crypto.enc.Hex);
47
+ const FormData = {
48
+ key: Key,
49
+ policy: Base64.stringify(Crypto.enc.Utf8.parse(policy)),
50
+ success_action_status: 200,
51
+ 'x-cos-security-token': data.session_token,
52
+ 'q-sign-algorithm': qSignAlgorithm,
53
+ 'q-ak': qAk,
54
+ 'q-key-time': qKeyTime,
55
+ 'q-signature': qSignature,
56
+ };
57
+ uni.uploadFile({
58
+ url: `https://${cosHost}`,
59
+ filePath: FilePath,
60
+ file: File,
61
+ name: 'file',
62
+ formData: FormData,
63
+ success: (res) => {
64
+ if (res.statusCode === 200) {
65
+ resolve({ Location: `${cosHost}/${Key}` });
66
+ }
67
+ else {
68
+ const { data: e, statusCode } = res;
69
+ const codeMatch = e.match(/<Code>([^<>]+)<\/Code>/);
70
+ if (codeMatch && codeMatch[1] === 'ExpiredToken' && data.expire_time !== 0) {
71
+ data.expire_time = 0;
72
+ checkRefreshToken()
73
+ .then(() => {
74
+ this.uploadFile(params)
75
+ .then((e) => {
76
+ resolve(e);
77
+ })
78
+ .catch((e) => {
79
+ reject(e);
80
+ });
81
+ })
82
+ .catch((e) => {
83
+ reject(e);
84
+ });
85
+ }
86
+ else {
87
+ const err = {
88
+ code: statusCode,
89
+ msg: 'Upload Fail',
90
+ };
91
+ const msgMatch = e.match(/<Message>([^<>]+)<\/Message>/);
92
+ if (msgMatch) {
93
+ err.msg = msgMatch[1];
94
+ }
95
+ reject(err);
96
+ }
97
+ }
98
+ },
99
+ fail: (err) => {
100
+ reject({
101
+ msg: err.errMsg || err.message || err.msg,
102
+ });
103
+ },
104
+ });
105
+ });
106
+ }
107
+ }
108
+ const cos = new COS();
109
+ export async function uploadFile(file, opts = {}) {
110
+ let ext = '.png';
111
+ if (file.name) {
112
+ const match = file.name.match(/\.\w+$/);
113
+ if (match) {
114
+ ext = match[0];
115
+ }
116
+ }
117
+ const key = `${opts.path || ''}${uni.$uv.timeFormat(new Date().getTime(), 'yyyymmddhhMMss')}${uni.$uv.guid(50)}${ext}`;
118
+ await checkRefreshToken();
119
+ const params = {
120
+ Bucket: data.bucket,
121
+ Region: data.region,
122
+ Key: opts.key || key,
123
+ };
124
+ if (file.path) {
125
+ params.FilePath = file.path;
126
+ }
127
+ else {
128
+ params.File = file;
129
+ }
130
+ const e = await cos.uploadFile(params);
131
+ const { Location } = e;
132
+ return {
133
+ url: `https://${Location}`,
134
+ };
135
+ }
136
+ export default {
137
+ checkRefreshToken,
138
+ uploadFile,
139
+ compress: cosCompress,
140
+ };
@@ -0,0 +1,2 @@
1
+ export default function Debounce(): void;
2
+ export declare const debounce: any;
@@ -0,0 +1,30 @@
1
+ export default function Debounce() {
2
+ this.timeout = false;
3
+ }
4
+ /**
5
+ * @function 防抖
6
+ * @param {Function} func 要执行的回调函数
7
+ * @param {Number} wait 延时的时间
8
+ * @param {Boolean} immediate 是否立即执行
9
+ */
10
+ Debounce.prototype.exec = function (func, wait = 500, immediate = false) {
11
+ // 清除定时器
12
+ if (this.timeout !== null)
13
+ clearTimeout(this.timeout);
14
+ // 立即执行,此类情况一般用不到
15
+ if (immediate) {
16
+ const callNow = !this.timeout;
17
+ this.timeout = setTimeout(() => {
18
+ this.timeout = null;
19
+ }, wait);
20
+ if (callNow)
21
+ typeof func === 'function' && func();
22
+ }
23
+ else {
24
+ // 设置定时器,当最后一次操作后,timeout不会再被清除,所以在延时wait毫秒后执行func回调方法
25
+ this.timeout = setTimeout(() => {
26
+ typeof func === 'function' && func();
27
+ }, wait);
28
+ }
29
+ };
30
+ export const debounce = new Debounce();
@@ -0,0 +1,28 @@
1
+ /**
2
+ * 图片地址转换为base64格式图片
3
+ * @param {string} url 图片地址 网络地址 本地相对路径
4
+ * @param {string} type base64图片类型 默认webp
5
+ */
6
+ export declare function urlToBase64(url: any, type?: string): any;
7
+ /**
8
+ * dataUrl转base64
9
+ * @param {String} url url值
10
+ */
11
+ export declare function dataUrlToBase64(url?: string): string;
12
+ /**
13
+ * base64转文件对象
14
+ * @param {String} base64 base64值
15
+ * @param {String} filename 文件名
16
+ */
17
+ export declare function base64ToFile(base64?: string, filename?: string): File;
18
+ /**
19
+ * path转base64
20
+ * @param {String} path 文件本地路径
21
+ */
22
+ export declare function pathToBase64(path: string): Promise<unknown>;
23
+ /**
24
+ * base64转本地path
25
+ * @param {String} base64 base64值
26
+ * @param {String} filename 文件名
27
+ */
28
+ export declare function base64ToPath(base64?: string, filename?: string): Promise<string>;
@@ -0,0 +1,292 @@
1
+ function biggerThan(v1 = '', v2 = '') {
2
+ const v1Array = v1.split('.');
3
+ const v2Array = v2.split('.');
4
+ let update = false;
5
+ for (let index = 0; index < v2Array.length; index++) {
6
+ const diff = Number(v1Array[index]) - Number(v2Array[index]);
7
+ if (diff !== 0) {
8
+ update = diff > 0;
9
+ break;
10
+ }
11
+ }
12
+ return update;
13
+ }
14
+ function getLocalFilePath(path = '') {
15
+ if (path.indexOf('_www') === 0 ||
16
+ path.indexOf('_doc') === 0 ||
17
+ path.indexOf('_documents') === 0 ||
18
+ path.indexOf('_downloads') === 0) {
19
+ return path;
20
+ }
21
+ if (path.indexOf('file://') === 0) {
22
+ return path;
23
+ }
24
+ if (path.indexOf('/storage/emulated/0/') === 0) {
25
+ return path;
26
+ }
27
+ if (path.indexOf('/') === 0) {
28
+ const localFilePath = plus.io.convertAbsoluteFileSystem(path);
29
+ if (localFilePath !== path) {
30
+ return localFilePath;
31
+ }
32
+ else {
33
+ path = path.substring(1);
34
+ }
35
+ }
36
+ return '_www/' + path;
37
+ }
38
+ /**
39
+ * 图片地址转换为base64格式图片
40
+ * @param {string} url 图片地址 网络地址 本地相对路径
41
+ * @param {string} type base64图片类型 默认webp
42
+ */
43
+ export function urlToBase64(url, type = 'webp') {
44
+ let promises;
45
+ // 网络地址 或者h5端本地相对路径 可使用request方式
46
+ promises = new Promise((resolve, reject) => {
47
+ uni.request({
48
+ url: url,
49
+ method: 'GET',
50
+ responseType: 'arraybuffer',
51
+ success: (res) => {
52
+ const base64 = `data:image/${type};base64,${uni.arrayBufferToBase64(res.data)}`;
53
+ resolve(base64);
54
+ },
55
+ fail: (err) => {
56
+ reject(err);
57
+ },
58
+ });
59
+ });
60
+ // #ifdef APP
61
+ if (!url.startsWith('http')) {
62
+ // app真机本地相对路径
63
+ promises = new Promise((resolve, reject) => {
64
+ // 使用compressImage获取到安卓本地路径file:///...
65
+ uni.compressImage({
66
+ src: url,
67
+ quality: 100,
68
+ success: (res) => {
69
+ const tempUrl = res.tempFilePath;
70
+ plus.io.resolveLocalFileSystemURL(tempUrl, (entry) => {
71
+ entry.file((e) => {
72
+ const fileReader = new plus.io.FileReader();
73
+ fileReader.onload = (r) => {
74
+ resolve(r.target.result);
75
+ };
76
+ fileReader.readAsDataURL(e);
77
+ });
78
+ });
79
+ },
80
+ fail: (err) => {
81
+ reject(err);
82
+ },
83
+ });
84
+ });
85
+ }
86
+ // #endif
87
+ return promises;
88
+ }
89
+ /**
90
+ * dataUrl转base64
91
+ * @param {String} url url值
92
+ */
93
+ export function dataUrlToBase64(url = '') {
94
+ const array = url.split(',');
95
+ return array[array.length - 1] || '';
96
+ }
97
+ /**
98
+ * base64转文件对象
99
+ * @param {String} base64 base64值
100
+ * @param {String} filename 文件名
101
+ */
102
+ export function base64ToFile(base64 = '', filename = '') {
103
+ const arr = base64.split(',');
104
+ const match = arr[0]?.match(/:(.*?);/);
105
+ if (match) {
106
+ const mime = match[1];
107
+ const bstr = atob(arr[1]);
108
+ let n = bstr.length;
109
+ const u8arr = new Uint8Array(n);
110
+ while (n--) {
111
+ u8arr[n] = bstr.charCodeAt(n);
112
+ }
113
+ return new File([u8arr], filename || mime.replace('/', '.'), { type: mime });
114
+ }
115
+ return new File([], '');
116
+ }
117
+ /**
118
+ * path转base64
119
+ * @param {String} path 文件本地路径
120
+ */
121
+ export function pathToBase64(path) {
122
+ return new Promise(function (resolve, reject) {
123
+ // #ifdef H5
124
+ if (typeof window === 'object' && 'document' in window) {
125
+ if (typeof FileReader === 'function') {
126
+ const xhr = new XMLHttpRequest();
127
+ xhr.open('GET', path, true);
128
+ xhr.responseType = 'blob';
129
+ xhr.onload = function () {
130
+ if (this.status === 200) {
131
+ const fileReader = new FileReader();
132
+ fileReader.onload = function (e) {
133
+ resolve(e.target.result);
134
+ };
135
+ fileReader.onerror = reject;
136
+ fileReader.readAsDataURL(this.response);
137
+ }
138
+ };
139
+ xhr.onerror = reject;
140
+ xhr.send();
141
+ return;
142
+ }
143
+ const canvas = document.createElement('canvas');
144
+ const c2x = canvas.getContext('2d');
145
+ const img = new Image();
146
+ img.onload = function () {
147
+ canvas.width = img.width;
148
+ canvas.height = img.height;
149
+ c2x.drawImage(img, 0, 0);
150
+ resolve(canvas.toDataURL());
151
+ canvas.height = canvas.width = 0;
152
+ };
153
+ img.onerror = reject;
154
+ img.src = path;
155
+ return;
156
+ }
157
+ // #endif
158
+ // #ifdef APP
159
+ if (typeof plus === 'object') {
160
+ plus.io.resolveLocalFileSystemURL(getLocalFilePath(path), function (entry) {
161
+ entry.file(function (file) {
162
+ const fileReader = new plus.io.FileReader();
163
+ fileReader.onload = function (data) {
164
+ resolve(data.target.result);
165
+ };
166
+ fileReader.onerror = function (error) {
167
+ reject(error);
168
+ };
169
+ fileReader.readAsDataURL(file);
170
+ }, function (error) {
171
+ reject(error);
172
+ });
173
+ }, function (error) {
174
+ reject(error);
175
+ });
176
+ return;
177
+ }
178
+ // #endif
179
+ // #ifdef MP
180
+ if (uni.canIUse('getFileSystemManager')) {
181
+ uni.getFileSystemManager().readFile({
182
+ filePath: path,
183
+ encoding: 'base64',
184
+ success: function (res) {
185
+ resolve('data:image/webp;base64,' + res.data);
186
+ },
187
+ fail: function (error) {
188
+ reject(error);
189
+ },
190
+ });
191
+ return;
192
+ }
193
+ // #endif
194
+ reject(new Error('not support'));
195
+ });
196
+ }
197
+ /**
198
+ * base64转本地path
199
+ * @param {String} base64 base64值
200
+ * @param {String} filename 文件名
201
+ */
202
+ export function base64ToPath(base64 = '', filename = '') {
203
+ return new Promise(function (resolve, reject) {
204
+ // #ifdef H5
205
+ if (typeof window === 'object' && 'document' in window) {
206
+ const arr = base64.split(',');
207
+ const type = arr[0].match(/:(.*?);/)[1];
208
+ const str = atob(arr[1]);
209
+ let n = str.length;
210
+ const array = new Uint8Array(n);
211
+ while (n--) {
212
+ array[n] = str.charCodeAt(n);
213
+ }
214
+ return resolve((window.URL || window.webkitURL).createObjectURL(new Blob([array], {
215
+ type: type,
216
+ })));
217
+ }
218
+ // #endif
219
+ // 移动端
220
+ let extName = base64.split(',')[0].match(/data:\S+\/(\S+);/) || '';
221
+ if (extName) {
222
+ extName = extName[1].split(';')[0];
223
+ }
224
+ else {
225
+ reject(new Error('base64 error'));
226
+ }
227
+ const fileName = (filename || Date.now()) + '.' + extName;
228
+ // #ifdef APP
229
+ if (typeof plus === 'object') {
230
+ const basePath = '_doc';
231
+ // let basePath = '_www/'
232
+ const dirPath = 'uniapp_temp';
233
+ const filePath = basePath + '/' + dirPath + '/' + fileName;
234
+ if (!biggerThan(plus.os.name === 'Android' ? '1.9.9.80627' : '1.9.9.80472', plus.runtime.innerVersion)) {
235
+ plus.io.resolveLocalFileSystemURL(basePath, function (entry) {
236
+ entry.getDirectory(dirPath, {
237
+ create: true,
238
+ exclusive: false,
239
+ }, function (entry) {
240
+ entry.getFile(fileName, {
241
+ create: true,
242
+ exclusive: false,
243
+ }, function (entry) {
244
+ entry.createWriter(function (writer) {
245
+ writer.onwrite = function () {
246
+ resolve(filePath);
247
+ };
248
+ writer.onerror = reject;
249
+ writer.seek(0);
250
+ writer.writeAsBinary(dataUrlToBase64(base64));
251
+ }, reject);
252
+ }, reject);
253
+ }, reject);
254
+ }, reject);
255
+ return;
256
+ }
257
+ const bitmap = new plus.nativeObj.Bitmap(fileName);
258
+ bitmap.loadBase64Data(base64, function () {
259
+ bitmap.save(filePath, {}, function () {
260
+ bitmap.clear();
261
+ resolve(filePath);
262
+ }, function (error) {
263
+ bitmap.clear();
264
+ reject(error);
265
+ });
266
+ }, function (error) {
267
+ bitmap.clear();
268
+ reject(error);
269
+ });
270
+ return;
271
+ }
272
+ // #endif
273
+ // #ifdef MP
274
+ if (uni.canIUse('getFileSystemManager')) {
275
+ const filePath = uni['env'].USER_DATA_PATH + '/' + fileName;
276
+ uni.getFileSystemManager().writeFile({
277
+ filePath: filePath,
278
+ data: dataUrlToBase64(base64),
279
+ encoding: 'base64',
280
+ success: function () {
281
+ resolve(filePath);
282
+ },
283
+ fail: function (error) {
284
+ reject(error);
285
+ },
286
+ });
287
+ return;
288
+ }
289
+ // #endif
290
+ reject(new Error('not support'));
291
+ });
292
+ }
@@ -0,0 +1,166 @@
1
+ /**
2
+ * 转换图片获取完整路径
3
+ * @param {Object} images 图片对象
4
+ * @param {String} path cdn地址
5
+ * @param {Boolean} useImages 是否使用images目录
6
+ */
7
+ export declare function transformImagePath<T>(images: T, path: string, useImages?: boolean): T;
8
+ /**
9
+ * @function 转换链接获取完整路径
10
+ * @param {Object} links 链接对象
11
+ * @param {String} path cdn地址
12
+ */
13
+ export declare function transformLinkPath<T>(links: T, path: string): T;
14
+ /**
15
+ * 请求延迟
16
+ * @param {Function} fn 请求方法
17
+ * @param {Number} delay 延迟时间(毫秒)
18
+ * @return {Function}
19
+ */
20
+ export declare function requestDelay(fn: () => Promise<any>, delay?: number): Promise<any>;
21
+ /**
22
+ * 将日期转换为时间戳
23
+ * @param {String, Number} date 时间字符串
24
+ * @return {String}
25
+ */
26
+ export declare function dateStringToTime(date: string | number): number;
27
+ /**
28
+ * 将日期末尾时间去除
29
+ * @param {String} date 时间字符串
30
+ * @return {String}
31
+ */
32
+ export declare function cutDate(date: string): string;
33
+ /**
34
+ * @function 计算时间距离当前时间多久
35
+ * @param {String,Number} time 时间
36
+ * @param {String} separate 时间分隔
37
+ * @return {String}
38
+ */
39
+ export declare function timeFrom(time: any, separate?: string): string;
40
+ /**
41
+ * 获取元素区域信息
42
+ * @param {String} id 元素ID
43
+ */
44
+ export declare function getRectById(id: string): Promise<{
45
+ data: {
46
+ height: number;
47
+ width: number;
48
+ top: number;
49
+ right: number;
50
+ bottom: number;
51
+ left: number;
52
+ };
53
+ }>;
54
+ /**
55
+ * 路径转换
56
+ * @param {String} base 路径
57
+ * @param {String} path 路径
58
+ */
59
+ export declare function joinPath(base?: string, path?: string): string;
60
+ /**
61
+ * 发送消息
62
+ * @param {Object} data { type: '', payload: {} }
63
+ */
64
+ export declare const postMessage: (data: {
65
+ type: string;
66
+ payload: {
67
+ [key: string]: string;
68
+ };
69
+ }) => void;
70
+ /**
71
+ * 打开导航
72
+ * @param {Object} data 位置数据
73
+ */
74
+ export declare function openLocation(data: UniNamespace.OpenLocationOptions): void;
75
+ /**
76
+ * 将字符以空格拆分
77
+ * @param {String, Number} code 字符内容
78
+ * @param {Number[]} format 拆分格式
79
+ * @return {String} 拆分后的字符
80
+ * @example codeSplit(18888888888, [3, 4, 4]) => 138 8888 8888
81
+ */
82
+ export declare function codeSplit(code?: string, format?: any[]): string;
83
+ /**
84
+ * 调用父组件方法
85
+ * @param {String} name 方法名称
86
+ * @example parentCall.call(this, 'show')
87
+ */
88
+ export declare function parentCall(...args: any[]): any;
89
+ /**
90
+ * 深度合并
91
+ * @param {Object} ...args 合并对象
92
+ */
93
+ export declare function deepMerge(target: {
94
+ [key: string]: any;
95
+ }, ...sources: {
96
+ [key: string]: any;
97
+ }[]): {
98
+ [key: string]: any;
99
+ };
100
+ /**
101
+ * 返回页面并通信,除了uni.navigateBack选项外,新增method、emit、data选项
102
+ */
103
+ export declare function navigateBack(options?: UniNamespace.NavigateBackOptions & {
104
+ method?: string;
105
+ emit?: string;
106
+ data?: any;
107
+ }): Promise<any>;
108
+ /**
109
+ * 腾讯云存储资源压缩处理,用法参考https://cloud.tencent.com/document/product/436/42215
110
+ * @param url 原图像地址
111
+ * @param rule 处理规则,默认100x
112
+ * @param type 处理类型,默认thumbnail
113
+ * @returns 处理后图像地址
114
+ */
115
+ export declare function cosCompress(url: string, rule?: string, type?: 'thumbnail' | 'cut' | 'rotate'): string;
116
+ /**
117
+ * 拨打电话
118
+ * @param {String} phoneNumber 手机号
119
+ */
120
+ export declare function phoneCall(phoneNumber: string): void;
121
+ /**
122
+ * 复制内容到剪切板
123
+ * @param {String} text 复制内容
124
+ * @param {String} tips 复制成功提示
125
+ */
126
+ export declare function copyToClipboard(text?: string, tips?: string): void;
127
+ /**
128
+ * 隐藏值
129
+ * @param {String} str 内容
130
+ * @param {Number} start 开头显示数量
131
+ * @param {end} phone 末尾显示数量
132
+ * @returns {String}
133
+ */
134
+ export declare function hiddenValue(str?: string, start?: number, end?: number): string;
135
+ /**
136
+ * 隐藏手机号
137
+ * @param {Number} phone 手机号
138
+ * @returns {String}
139
+ */
140
+ export declare function hiddenPhone(phone: string | number): string;
141
+ /**
142
+ * 格式化手机号
143
+ * @param {Number} phone 手机号
144
+ * @returns {String}
145
+ */
146
+ export declare function formatPhone(phone: string | number): string;
147
+ /**
148
+ * 数字四舍五入
149
+ * @param {Number} value 数值
150
+ * @param {Number} decimal 保留位数
151
+ * @returns {String}
152
+ */
153
+ export declare function toFixed(value: string | number, decimal?: number): string;
154
+ /**
155
+ * @function 选项数据转对象数据
156
+ * @param {Array} data 数据对象
157
+ * @return {Object}
158
+ */
159
+ export declare function OptionsToObject(data: any): {};
160
+ /**
161
+ * 简化数字,123显示100+
162
+ * @param {Number} num 数字
163
+ * @param {Number} min 最小值
164
+ * @return {String}
165
+ */
166
+ export declare function numberPlus(num: number | string, min?: number): string;