zcw-shared 1.32.6 → 1.33.0

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 (239) hide show
  1. package/dist/functions/wechat/useWxWebShare.d.ts +26 -0
  2. package/dist/functions/wechat/useWxWebShare.js +141 -0
  3. package/dist/functions/wechat/useWxWebShare.js.map +1 -0
  4. package/package.json +5 -3
  5. package/references/wechat.d.ts +35 -0
  6. package/dist/functions/platform/tencent-cloud/deploy.tcb.d.ts +0 -13
  7. package/dist/functions/platform/tencent-cloud/deploy.tcb.js +0 -46
  8. package/dist/functions/platform/tencent-cloud/deploy.tcb.js.map +0 -1
  9. package/dist/functions/platform/tencent-cloud/getSecret.d.ts +0 -4
  10. package/dist/functions/platform/tencent-cloud/getSecret.js +0 -19
  11. package/dist/functions/platform/tencent-cloud/getSecret.js.map +0 -1
  12. package/dist/functions/platform/uniapp/app-plus/buildAndroidApp.d.ts +0 -27
  13. package/dist/functions/platform/uniapp/app-plus/buildAndroidApp.js +0 -287
  14. package/dist/functions/platform/uniapp/app-plus/buildAndroidApp.js.map +0 -1
  15. package/dist/functions/platform/uniapp/build.d.ts +0 -21
  16. package/dist/functions/platform/uniapp/build.js +0 -83
  17. package/dist/functions/platform/uniapp/build.js.map +0 -1
  18. package/dist/functions/platform/uniapp/detectAndroidProjectStructure.d.ts +0 -11
  19. package/dist/functions/platform/uniapp/detectAndroidProjectStructure.js +0 -30
  20. package/dist/functions/platform/uniapp/detectAndroidProjectStructure.js.map +0 -1
  21. package/dist/functions/platform/uniapp/detectProjectType.d.ts +0 -20
  22. package/dist/functions/platform/uniapp/detectProjectType.js +0 -68
  23. package/dist/functions/platform/uniapp/detectProjectType.js.map +0 -1
  24. package/dist/functions/platform/uniapp/parseManifest.d.ts +0 -18
  25. package/dist/functions/platform/uniapp/parseManifest.js +0 -49
  26. package/dist/functions/platform/uniapp/parseManifest.js.map +0 -1
  27. package/dist/functions/platform/uniapp/waitForPages.d.ts +0 -7
  28. package/dist/functions/platform/uniapp/waitForPages.js +0 -20
  29. package/dist/functions/platform/uniapp/waitForPages.js.map +0 -1
  30. package/dist/functions/string/visualizeRegexSteps.d.ts +0 -39
  31. package/dist/functions/string/visualizeRegexSteps.js +0 -446
  32. package/dist/functions/string/visualizeRegexSteps.js.map +0 -1
  33. package/dist/functions/utils/AVLTree.d.ts +0 -19
  34. package/dist/functions/utils/AVLTree.js +0 -197
  35. package/dist/functions/utils/AVLTree.js.map +0 -1
  36. package/dist/functions/utils/BinarySearchTree.d.ts +0 -19
  37. package/dist/functions/utils/BinarySearchTree.js +0 -150
  38. package/dist/functions/utils/BinarySearchTree.js.map +0 -1
  39. package/dist/functions/utils/EventEmitter.d.ts +0 -32
  40. package/dist/functions/utils/EventEmitter.js +0 -108
  41. package/dist/functions/utils/EventEmitter.js.map +0 -1
  42. package/dist/functions/utils/Graph.d.ts +0 -19
  43. package/dist/functions/utils/Graph.js +0 -190
  44. package/dist/functions/utils/Graph.js.map +0 -1
  45. package/dist/functions/utils/HashMap.d.ts +0 -13
  46. package/dist/functions/utils/HashMap.js +0 -128
  47. package/dist/functions/utils/HashMap.js.map +0 -1
  48. package/dist/functions/utils/Heap.d.ts +0 -11
  49. package/dist/functions/utils/Heap.js +0 -91
  50. package/dist/functions/utils/Heap.js.map +0 -1
  51. package/dist/functions/utils/LRUCache.d.ts +0 -41
  52. package/dist/functions/utils/LRUCache.js +0 -182
  53. package/dist/functions/utils/LRUCache.js.map +0 -1
  54. package/dist/functions/utils/LinkedList.d.ts +0 -18
  55. package/dist/functions/utils/LinkedList.js +0 -135
  56. package/dist/functions/utils/LinkedList.js.map +0 -1
  57. package/dist/functions/utils/MyPromise.d.ts +0 -32
  58. package/dist/functions/utils/MyPromise.js +0 -254
  59. package/dist/functions/utils/MyPromise.js.map +0 -1
  60. package/dist/functions/utils/PriorityQueue.d.ts +0 -14
  61. package/dist/functions/utils/PriorityQueue.js +0 -77
  62. package/dist/functions/utils/PriorityQueue.js.map +0 -1
  63. package/dist/functions/utils/Queue.d.ts +0 -10
  64. package/dist/functions/utils/Queue.js +0 -27
  65. package/dist/functions/utils/Queue.js.map +0 -1
  66. package/dist/functions/utils/Stack.d.ts +0 -10
  67. package/dist/functions/utils/Stack.js +0 -27
  68. package/dist/functions/utils/Stack.js.map +0 -1
  69. package/dist/functions/utils/Trie.d.ts +0 -16
  70. package/dist/functions/utils/Trie.js +0 -127
  71. package/dist/functions/utils/Trie.js.map +0 -1
  72. package/dist/functions/utils/UnionFind.d.ts +0 -8
  73. package/dist/functions/utils/UnionFind.js +0 -53
  74. package/dist/functions/utils/UnionFind.js.map +0 -1
  75. package/dist/functions/utils/cachedAsync.d.ts +0 -27
  76. package/dist/functions/utils/cachedAsync.js +0 -123
  77. package/dist/functions/utils/cachedAsync.js.map +0 -1
  78. package/dist/functions/utils/compose.d.ts +0 -1
  79. package/dist/functions/utils/compose.js +0 -10
  80. package/dist/functions/utils/compose.js.map +0 -1
  81. package/dist/functions/utils/cond.d.ts +0 -1
  82. package/dist/functions/utils/cond.js +0 -15
  83. package/dist/functions/utils/cond.js.map +0 -1
  84. package/dist/functions/utils/createI18n.d.ts +0 -2
  85. package/dist/functions/utils/createI18n.js +0 -97
  86. package/dist/functions/utils/createI18n.js.map +0 -1
  87. package/dist/functions/utils/createReactive.d.ts +0 -10
  88. package/dist/functions/utils/createReactive.js +0 -50
  89. package/dist/functions/utils/createReactive.js.map +0 -1
  90. package/dist/functions/utils/curry.d.ts +0 -1
  91. package/dist/functions/utils/curry.js +0 -13
  92. package/dist/functions/utils/curry.js.map +0 -1
  93. package/dist/functions/utils/curryAdvanced.d.ts +0 -8
  94. package/dist/functions/utils/curryAdvanced.js +0 -87
  95. package/dist/functions/utils/curryAdvanced.js.map +0 -1
  96. package/dist/functions/utils/debounce.d.ts +0 -5
  97. package/dist/functions/utils/debounce.js +0 -12
  98. package/dist/functions/utils/debounce.js.map +0 -1
  99. package/dist/functions/utils/deepClone.d.ts +0 -12
  100. package/dist/functions/utils/deepClone.js +0 -131
  101. package/dist/functions/utils/deepClone.js.map +0 -1
  102. package/dist/functions/utils/errorManager.d.ts +0 -63
  103. package/dist/functions/utils/errorManager.js +0 -199
  104. package/dist/functions/utils/errorManager.js.map +0 -1
  105. package/dist/functions/utils/evolve.d.ts +0 -3
  106. package/dist/functions/utils/evolve.js +0 -15
  107. package/dist/functions/utils/evolve.js.map +0 -1
  108. package/dist/functions/utils/flatten.d.ts +0 -7
  109. package/dist/functions/utils/flatten.js +0 -60
  110. package/dist/functions/utils/flatten.js.map +0 -1
  111. package/dist/functions/utils/flattenObject.d.ts +0 -5
  112. package/dist/functions/utils/flattenObject.js +0 -102
  113. package/dist/functions/utils/flattenObject.js.map +0 -1
  114. package/dist/functions/utils/flow.d.ts +0 -1
  115. package/dist/functions/utils/flow.js +0 -14
  116. package/dist/functions/utils/flow.js.map +0 -1
  117. package/dist/functions/utils/formatString.d.ts +0 -5
  118. package/dist/functions/utils/formatString.js +0 -9
  119. package/dist/functions/utils/formatString.js.map +0 -1
  120. package/dist/functions/utils/functionBind.d.ts +0 -4
  121. package/dist/functions/utils/functionBind.js +0 -33
  122. package/dist/functions/utils/functionBind.js.map +0 -1
  123. package/dist/functions/utils/i18n.d.ts +0 -27
  124. package/dist/functions/utils/i18n.js +0 -119
  125. package/dist/functions/utils/i18n.js.map +0 -1
  126. package/dist/functions/utils/memoize.d.ts +0 -1
  127. package/dist/functions/utils/memoize.js +0 -13
  128. package/dist/functions/utils/memoize.js.map +0 -1
  129. package/dist/functions/utils/myInstanceof.d.ts +0 -5
  130. package/dist/functions/utils/myInstanceof.js +0 -56
  131. package/dist/functions/utils/myInstanceof.js.map +0 -1
  132. package/dist/functions/utils/myNew.d.ts +0 -3
  133. package/dist/functions/utils/myNew.js +0 -19
  134. package/dist/functions/utils/myNew.js.map +0 -1
  135. package/dist/functions/utils/once.d.ts +0 -1
  136. package/dist/functions/utils/once.js +0 -13
  137. package/dist/functions/utils/once.js.map +0 -1
  138. package/dist/functions/utils/partial.d.ts +0 -1
  139. package/dist/functions/utils/partial.js +0 -13
  140. package/dist/functions/utils/partial.js.map +0 -1
  141. package/dist/functions/utils/permission.d.ts +0 -40
  142. package/dist/functions/utils/permission.js +0 -189
  143. package/dist/functions/utils/permission.js.map +0 -1
  144. package/dist/functions/utils/pinia.d.ts +0 -52
  145. package/dist/functions/utils/pinia.js +0 -183
  146. package/dist/functions/utils/pinia.js.map +0 -1
  147. package/dist/functions/utils/pipe.d.ts +0 -1
  148. package/dist/functions/utils/pipe.js +0 -10
  149. package/dist/functions/utils/pipe.js.map +0 -1
  150. package/dist/functions/utils/promiseLimit.d.ts +0 -10
  151. package/dist/functions/utils/promiseLimit.js +0 -125
  152. package/dist/functions/utils/promiseLimit.js.map +0 -1
  153. package/dist/functions/utils/retryWithBackoff.d.ts +0 -12
  154. package/dist/functions/utils/retryWithBackoff.js +0 -29
  155. package/dist/functions/utils/retryWithBackoff.js.map +0 -1
  156. package/dist/functions/utils/tap.d.ts +0 -1
  157. package/dist/functions/utils/tap.js +0 -14
  158. package/dist/functions/utils/tap.js.map +0 -1
  159. package/dist/functions/utils/throttle.d.ts +0 -1
  160. package/dist/functions/utils/throttle.js +0 -11
  161. package/dist/functions/utils/throttle.js.map +0 -1
  162. package/dist/functions/utils/unique.d.ts +0 -10
  163. package/dist/functions/utils/unique.js +0 -85
  164. package/dist/functions/utils/unique.js.map +0 -1
  165. package/dist/functions/utils/until.d.ts +0 -1
  166. package/dist/functions/utils/until.js +0 -10
  167. package/dist/functions/utils/until.js.map +0 -1
  168. package/dist/hooks/createGlobalState.d.ts +0 -2
  169. package/dist/hooks/createGlobalState.js +0 -11
  170. package/dist/hooks/createGlobalState.js.map +0 -1
  171. package/dist/hooks/createInjectionState.d.ts +0 -14
  172. package/dist/hooks/createInjectionState.js +0 -20
  173. package/dist/hooks/createInjectionState.js.map +0 -1
  174. package/dist/hooks/createSharedComposable.d.ts +0 -2
  175. package/dist/hooks/createSharedComposable.js +0 -13
  176. package/dist/hooks/createSharedComposable.js.map +0 -1
  177. package/dist/hooks/injectLocal.d.ts +0 -10
  178. package/dist/hooks/injectLocal.js +0 -12
  179. package/dist/hooks/injectLocal.js.map +0 -1
  180. package/dist/hooks/provideLocal.d.ts +0 -9
  181. package/dist/hooks/provideLocal.js +0 -7
  182. package/dist/hooks/provideLocal.js.map +0 -1
  183. package/dist/hooks/useAltool.d.ts +0 -39
  184. package/dist/hooks/useAltool.js +0 -350
  185. package/dist/hooks/useAltool.js.map +0 -1
  186. package/dist/hooks/useAsyncState.d.ts +0 -30
  187. package/dist/hooks/useAsyncState.js +0 -46
  188. package/dist/hooks/useAsyncState.js.map +0 -1
  189. package/dist/hooks/useCache.d.ts +0 -18
  190. package/dist/hooks/useCache.js +0 -82
  191. package/dist/hooks/useCache.js.map +0 -1
  192. package/dist/hooks/useDebouncedRefHistory.d.ts +0 -22
  193. package/dist/hooks/useDebouncedRefHistory.js +0 -46
  194. package/dist/hooks/useDebouncedRefHistory.js.map +0 -1
  195. package/dist/hooks/useDraggable.d.ts +0 -37
  196. package/dist/hooks/useDraggable.js +0 -163
  197. package/dist/hooks/useDraggable.js.map +0 -1
  198. package/dist/hooks/useLocalStorage.d.ts +0 -8
  199. package/dist/hooks/useLocalStorage.js +0 -101
  200. package/dist/hooks/useLocalStorage.js.map +0 -1
  201. package/dist/hooks/useManualRefHistory.d.ts +0 -26
  202. package/dist/hooks/useManualRefHistory.js +0 -80
  203. package/dist/hooks/useManualRefHistory.js.map +0 -1
  204. package/dist/hooks/usePermission.d.ts +0 -7
  205. package/dist/hooks/usePermission.js +0 -123
  206. package/dist/hooks/usePermission.js.map +0 -1
  207. package/dist/hooks/usePluginSystem.d.ts +0 -11
  208. package/dist/hooks/usePluginSystem.js +0 -34
  209. package/dist/hooks/usePluginSystem.js.map +0 -1
  210. package/dist/hooks/useRefHistory.d.ts +0 -21
  211. package/dist/hooks/useRefHistory.js +0 -41
  212. package/dist/hooks/useRefHistory.js.map +0 -1
  213. package/dist/hooks/useResizable.d.ts +0 -54
  214. package/dist/hooks/useResizable.js +0 -178
  215. package/dist/hooks/useResizable.js.map +0 -1
  216. package/dist/hooks/useSessionStorage.d.ts +0 -8
  217. package/dist/hooks/useSessionStorage.js +0 -101
  218. package/dist/hooks/useSessionStorage.js.map +0 -1
  219. package/dist/hooks/useStorage.d.ts +0 -13
  220. package/dist/hooks/useStorage.js +0 -62
  221. package/dist/hooks/useStorage.js.map +0 -1
  222. package/dist/hooks/useStorageWithIndexedDB.d.ts +0 -8
  223. package/dist/hooks/useStorageWithIndexedDB.js +0 -132
  224. package/dist/hooks/useStorageWithIndexedDB.js.map +0 -1
  225. package/dist/hooks/useWebWorker.d.ts +0 -25
  226. package/dist/hooks/useWebWorker.js +0 -207
  227. package/dist/hooks/useWebWorker.js.map +0 -1
  228. package/dist/hooks/useWorkerFunction.d.ts +0 -26
  229. package/dist/hooks/useWorkerFunction.js +0 -191
  230. package/dist/hooks/useWorkerFunction.js.map +0 -1
  231. package/dist/hooks/useWorkerPool.d.ts +0 -33
  232. package/dist/hooks/useWorkerPool.js +0 -247
  233. package/dist/hooks/useWorkerPool.js.map +0 -1
  234. package/dist/vue-hooks/dom/useKeyboard.d.ts +0 -29
  235. package/dist/vue-hooks/dom/useKeyboard.js +0 -129
  236. package/dist/vue-hooks/dom/useKeyboard.js.map +0 -1
  237. package/dist/vue-hooks/state/useFileUpload.d.ts +0 -23
  238. package/dist/vue-hooks/state/useFileUpload.js +0 -93
  239. package/dist/vue-hooks/state/useFileUpload.js.map +0 -1
@@ -0,0 +1,26 @@
1
+ import type { Navigator } from '../../../references/browser.d';
2
+ import type { Console } from '../../../references/console.d';
3
+ import type { WxWeb } from '../../../references/wechat.d';
4
+ export interface UseWxWebShareOptions {
5
+ title: string;
6
+ desc?: string;
7
+ link: string;
8
+ imgUrl?: string;
9
+ timelineTitle?: string;
10
+ onSuccess?: () => void;
11
+ onCancel?: () => void;
12
+ onFail?: (error: Error) => void;
13
+ }
14
+ export interface UseWxWebShareDeps {
15
+ getUserAgent: () => Navigator['userAgent'];
16
+ getWx: () => WxWeb | undefined;
17
+ loadWxScript?: (url: string) => Promise<void>;
18
+ jssdkUrl?: string;
19
+ warn?: Console['warn'];
20
+ errorLog?: Console['error'];
21
+ }
22
+ export interface UseWxWebShareResult {
23
+ isWeChat: boolean;
24
+ applied: boolean;
25
+ }
26
+ export declare const useWxWebShare: (options: UseWxWebShareOptions, deps: UseWxWebShareDeps) => Promise<UseWxWebShareResult>;
@@ -0,0 +1,141 @@
1
+ const WECHAT_UA_REGEXP = /MicroMessenger/i;
2
+ const DEFAULT_JSSDK_URL = 'https://res.wx.qq.com/open/js/jweixin-1.6.0.js';
3
+ let cachedWx;
4
+ let wxLoadingPromise;
5
+ const normalizeError = (source) => {
6
+ if (source instanceof Error) {
7
+ return source;
8
+ }
9
+ if (typeof source === 'string') {
10
+ return new Error(source);
11
+ }
12
+ if (source && typeof source === 'object') {
13
+ const maybeError = source;
14
+ if (maybeError.errMsg) {
15
+ return new Error(maybeError.errMsg);
16
+ }
17
+ }
18
+ return new Error('微信分享调用失败');
19
+ };
20
+ const ensureWxInstance = async (deps) => {
21
+ if (cachedWx) {
22
+ return cachedWx;
23
+ }
24
+ const existing = deps.getWx();
25
+ if (existing) {
26
+ cachedWx = existing;
27
+ return existing;
28
+ }
29
+ if (!deps.loadWxScript) {
30
+ throw new Error('useWxWebShare: 未检测到微信 JSSDK 实例,且缺少 loadWxScript 依赖用以加载脚本');
31
+ }
32
+ if (!wxLoadingPromise) {
33
+ wxLoadingPromise = deps
34
+ .loadWxScript(deps.jssdkUrl ?? DEFAULT_JSSDK_URL)
35
+ .then(() => {
36
+ const loaded = deps.getWx();
37
+ if (!loaded) {
38
+ throw new Error('useWxWebShare: 微信 JSSDK 脚本加载后仍未检测到 wx 实例');
39
+ }
40
+ cachedWx = loaded;
41
+ return loaded;
42
+ })
43
+ .finally(() => {
44
+ wxLoadingPromise = undefined;
45
+ });
46
+ }
47
+ return wxLoadingPromise;
48
+ };
49
+ const isWeChatEnvironment = (userAgent) => {
50
+ return typeof userAgent === 'string' && WECHAT_UA_REGEXP.test(userAgent);
51
+ };
52
+ const buildAppMessageOptions = (params) => {
53
+ const { title, desc, link, imgUrl, onSuccess, onCancel, onFail } = params;
54
+ return {
55
+ title,
56
+ desc,
57
+ link,
58
+ imgUrl,
59
+ success: onSuccess,
60
+ cancel: onCancel,
61
+ fail: (error) => {
62
+ onFail?.(normalizeError(error));
63
+ }
64
+ };
65
+ };
66
+ const buildTimelineOptions = (params) => {
67
+ const { timelineTitle, title, link, imgUrl, onSuccess, onCancel, onFail } = params;
68
+ return {
69
+ title: timelineTitle ?? title,
70
+ link,
71
+ imgUrl,
72
+ success: onSuccess,
73
+ cancel: onCancel,
74
+ fail: (error) => {
75
+ onFail?.(normalizeError(error));
76
+ }
77
+ };
78
+ };
79
+ export const useWxWebShare = async (options, deps) => {
80
+ const userAgent = deps.getUserAgent();
81
+ if (!isWeChatEnvironment(userAgent)) {
82
+ deps.warn?.('useWxWebShare: 当前环境不是微信内置浏览器,跳过分享设置');
83
+ return {
84
+ isWeChat: false,
85
+ applied: false
86
+ };
87
+ }
88
+ if (!options || typeof options !== 'object') {
89
+ throw new Error('useWxWebShare: 必须提供分享配置参数');
90
+ }
91
+ if (!options.title || !options.link) {
92
+ throw new Error('useWxWebShare: title 和 link 为必填项');
93
+ }
94
+ const messageOptions = buildAppMessageOptions(options);
95
+ const timelineOptions = buildTimelineOptions(options);
96
+ const wx = await ensureWxInstance(deps);
97
+ const shareToFriend = wx.updateAppMessageShareData ?? wx.onMenuShareAppMessage;
98
+ const shareToTimeline = wx.updateTimelineShareData ?? wx.onMenuShareTimeline;
99
+ if (!shareToFriend) {
100
+ throw new Error('useWxWebShare: 当前微信环境缺少 updateAppMessageShareData/onMenuShareAppMessage 接口');
101
+ }
102
+ if (!shareToTimeline) {
103
+ throw new Error('useWxWebShare: 当前微信环境缺少 updateTimelineShareData/onMenuShareTimeline 接口');
104
+ }
105
+ return new Promise((resolve, reject) => {
106
+ let resolved = false;
107
+ const handleReady = () => {
108
+ try {
109
+ shareToFriend(messageOptions);
110
+ shareToTimeline(timelineOptions);
111
+ resolved = true;
112
+ resolve({
113
+ isWeChat: true,
114
+ applied: true
115
+ });
116
+ }
117
+ catch (error) {
118
+ const normalized = normalizeError(error);
119
+ options.onFail?.(normalized);
120
+ deps.errorLog?.('useWxWebShare: 注册分享时出现错误', normalized);
121
+ reject(normalized);
122
+ }
123
+ };
124
+ const handleError = (error) => {
125
+ const normalized = normalizeError(error);
126
+ deps.errorLog?.('useWxWebShare: 微信 JSSDK 初始化失败', normalized);
127
+ options.onFail?.(normalized);
128
+ if (!resolved) {
129
+ reject(normalized);
130
+ }
131
+ };
132
+ try {
133
+ wx.ready(handleReady);
134
+ wx.error(handleError);
135
+ }
136
+ catch (error) {
137
+ handleError(error);
138
+ }
139
+ });
140
+ };
141
+ //# sourceMappingURL=useWxWebShare.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useWxWebShare.js","sourceRoot":"","sources":["../../../src/functions/wechat/useWxWebShare.ts"],"names":[],"mappings":"AAkDA,MAAM,gBAAgB,GAAG,iBAAiB,CAAA;AAC1C,MAAM,iBAAiB,GAAG,gDAAgD,CAAA;AAE1E,IAAI,QAA2B,CAAA;AAC/B,IAAI,gBAA4C,CAAA;AAEhD,MAAM,cAAc,GAAG,CAAC,MAAe,EAAS,EAAE;IAChD,IAAI,MAAM,YAAY,KAAK,EAAE,CAAC;QAC5B,OAAO,MAAM,CAAA;IACf,CAAC;IAED,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,CAAA;IAC1B,CAAC;IAED,IAAI,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QACzC,MAAM,UAAU,GAAG,MAAsB,CAAA;QACzC,IAAI,UAAU,CAAC,MAAM,EAAE,CAAC;YACtB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AC5B,IAAI,CAAC,QAAQ,EAAE,CAAC,0BAA0B,EAAE,UAAU,CAAC,CAAA;gBACvD,MAAM,CAAC,UAAU,CAAC,CAAA;YACpB,CAAC;QACH,CAAC,CAAA;QAED,MAAM,WAAW,GAAG,CAAC,KAAc,EAAE,EAAE;YACrC,MAAM,UAAU,GAAG,cAAc,CAAC,KAAK,CAAC,CAAA;YACxC,IAAI,CAAC,QAAQ,EAAE,CAAC,+BAA+B,EAAE,UAAU,CAAC,CAAA;YAC5D,OAAO,CAAC,MAAM,EAAE,CAAC,UAAU,CAAC,CAAA;YAE5B,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACd,MAAM,CAAC,UAAU,CAAC,CAAA;YACpB,CAAC;QACH,CAAC,CAAA;QAED,IAAI,CAAC;YACH,EAAE,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;YACrB,EAAE,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;QACvB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,WAAW,CAAC,KAAK,CAAC,CAAA;QACpB,CAAC;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zcw-shared",
3
- "version": "1.32.6",
3
+ "version": "1.33.0",
4
4
  "files": [
5
5
  "references",
6
6
  "dist",
@@ -15,12 +15,13 @@
15
15
  "devDependencies": {
16
16
  "@cloudbase/manager-node": "^4.3.2",
17
17
  "cos-nodejs-sdk-v5": "^2.14.4",
18
+ "jszip": "^3.10.1",
18
19
  "tsx": "^4.20.3",
19
20
  "typescript": "^5.8.3",
20
21
  "vitepress": "^1.6.4",
21
22
  "vue": "^3.5.22",
22
- "zcw-shared": "^1.28.0",
23
- "zcw-vue-ui": "1.23.0"
23
+ "zcw-shared": "^1.32.6",
24
+ "zcw-vue-ui": "1.24.0"
24
25
  },
25
26
  "exports": {
26
27
  "./constants/colorPatterns": "./dist/constants/colorPatterns.js",
@@ -231,6 +232,7 @@
231
232
  "./functions/vue/isVueComponent": "./dist/functions/vue/isVueComponent.js",
232
233
  "./functions/vue/parseVueFile": "./dist/functions/vue/parseVueFile.js",
233
234
  "./functions/wechat/miniapp/downloadFile": "./dist/functions/wechat/miniapp/downloadFile.js",
235
+ "./functions/wechat/useWxWebShare": "./dist/functions/wechat/useWxWebShare.js",
234
236
  "./functions/xml/modifyXml": "./dist/functions/xml/modifyXml.js",
235
237
  "./reactive/createReactive": "./dist/reactive/createReactive.js",
236
238
  "./reactive/createReactiveErrorManager": "./dist/reactive/createReactiveErrorManager.js",
@@ -46,4 +46,39 @@ export interface Wx {
46
46
  success: (res: { confirm: boolean; cancel: boolean }) => void
47
47
  fail?: (err: any) => void
48
48
  }): void
49
+ }
50
+
51
+ // 微信网页 JSSDK 类型声明
52
+
53
+ export interface WxJsSdkError {
54
+ errMsg?: string
55
+ [key: string]: any
56
+ }
57
+
58
+ interface WxWebShareCallbacks {
59
+ success?: () => void
60
+ cancel?: () => void
61
+ fail?: (error: any) => void
62
+ }
63
+
64
+ export interface WxWebShareOptions extends WxWebShareCallbacks {
65
+ title: string
66
+ desc?: string
67
+ link: string
68
+ imgUrl?: string
69
+ }
70
+
71
+ export interface WxWebTimelineShareOptions extends WxWebShareCallbacks {
72
+ title: string
73
+ link: string
74
+ imgUrl?: string
75
+ }
76
+
77
+ export interface WxWeb {
78
+ ready(callback: () => void): void
79
+ error(callback: (error: WxJsSdkError) => void): void
80
+ updateAppMessageShareData?(options: WxWebShareOptions): void
81
+ updateTimelineShareData?(options: WxWebTimelineShareOptions): void
82
+ onMenuShareAppMessage?(options: WxWebShareOptions): void
83
+ onMenuShareTimeline?(options: WxWebTimelineShareOptions): void
49
84
  }
@@ -1,13 +0,0 @@
1
- import type { DeployOptions, DeployResult, SecretType } from '../../../../types/tencent-cloud.d';
2
- import type { TencentCloudSecret, CloudBaseManager } from '../../../../references/tencent-cloud.d';
3
- import type { FileSystem } from '../../../../references/node.d';
4
- import type { Console } from '../../../../references/console.d';
5
- export interface DeployTCBDeps {
6
- existsSync: FileSystem['existsSync'];
7
- init: CloudBaseManager['init'];
8
- log: Console['log'];
9
- error: Console['error'];
10
- getSecret: (type: SecretType) => TencentCloudSecret | null;
11
- }
12
- export declare function deployToTCB(options: DeployOptions, deps: DeployTCBDeps): Promise<DeployResult>;
13
- export default deployToTCB;
@@ -1,46 +0,0 @@
1
- export async function deployToTCB(options, deps) {
2
- const { localPath, cloudPath = '/', envId, secretType, showProgress = true } = options;
3
- try {
4
- if (!deps.existsSync(localPath)) {
5
- return {
6
- success: false,
7
- error: `本地路径不存在: ${localPath}`
8
- };
9
- }
10
- const secret = deps.getSecret(secretType);
11
- if (!secret || !secret.secretId || !secret.secretKey) {
12
- return {
13
- success: false,
14
- error: `无效的密钥类型: ${secretType}`
15
- };
16
- }
17
- const app = deps.init({
18
- secretId: secret.secretId,
19
- secretKey: secret.secretKey,
20
- envId
21
- });
22
- const hosting = app.hosting;
23
- await hosting.uploadFiles({
24
- localPath,
25
- cloudPath,
26
- onProgress: showProgress ? (progressData) => {
27
- deps.log(`上传进度: ${progressData.percent}%`);
28
- } : undefined
29
- });
30
- deps.log('文件上传成功');
31
- return {
32
- success: true,
33
- message: '部署成功'
34
- };
35
- }
36
- catch (error) {
37
- const errorMessage = error instanceof Error ? error.message : String(error);
38
- deps.error('部署失败:', error);
39
- return {
40
- success: false,
41
- error: `部署失败: ${errorMessage}`
42
- };
43
- }
44
- }
45
- export default deployToTCB;
46
- //# sourceMappingURL=deploy.tcb.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"deploy.tcb.js","sourceRoot":"","sources":["../../../../src/functions/platform/tencent-cloud/deploy.tcb.ts"],"names":[],"mappings":"AAuDA,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,OAAsB,EACtB,IAAmB;IAEnB,MAAM,EACJ,SAAS,EACT,SAAS,GAAG,GAAG,EACf,KAAK,EACL,UAAU,EACV,YAAY,GAAG,IAAI,EACpB,GAA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EAAE,KAAK,CAAC,CAAA;QAC1B,OAAO;YACL,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,SAAS,YAAY,EAAE;SAC/B,CAAA;IACH,CAAC;AACH,CAAC;AAQD,eAAe,WAAW,CAAA"}
@@ -1,4 +0,0 @@
1
- import type { TencentCloudSecret } from '../../../../references/tencent-cloud.d';
2
- import type { SecretType } from '../../../../types/tencent-cloud.d';
3
- export declare function getSecret(type: SecretType): TencentCloudSecret;
4
- export default getSecret;
@@ -1,19 +0,0 @@
1
- const secretMap = {
2
- personal: {
3
- secretId: 'AKIDKVQ5VjiQu73j9IBnFRN2QYQ2MQEl22mI',
4
- secretKey: 'IL7cqoWy94lDsGSXP9gxzkGXcSFrDJ8h',
5
- },
6
- individual: {
7
- secretId: 'AKID2A6oIZcT5TcWBetteARULxKSM1ResARl',
8
- secretKey: 'INFtISN3VmocDZgYBZicIitpWyEG4f2B',
9
- },
10
- enterprise: {
11
- secretId: 'AKIDRhqpgKn46uVvACzd7ORGTbaLtHSSEn8H',
12
- secretKey: '95tV4Ql02wpY5QaaOzTlrjOr8OQFsHUW',
13
- },
14
- };
15
- export function getSecret(type) {
16
- return secretMap[type];
17
- }
18
- export default getSecret;
19
- //# sourceMappingURL=getSecret.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getSecret.js","sourceRoot":"","sources":["../../../../src/functions/platform/tencent-cloud/getSecret.ts"],"names":[],"mappings":"AAIA,MAAM,SAAS,GAA2C;IACxD,QAAQ,EAAE;QAER,QAAQ,EAAE,sCAAsC;QAChD,SAAS,EAAE,kCAAkC;KAC9C;IACD,UAAU,EAAE;QAEV,QAAQ,EAAE,sCAAsC;QAChD,SAAS,EAAE,kCAAkC;KAC9C;IACD,UAAU,EAAE;QAEV,QAAQ,EAAE,sCAAsC;QAChD,SAAS,EAAE,kCAAkC;KAC9C;CACF,CAAA;AAoCD,MAAM,UAAU,SAAS,CAAC,IAAgB;IACxC,OAAO,SAAS,CAAC,IAAI,CAAC,CAAA;AACxB,CAAC;AAKD,eAAe,SAAS,CAAA"}
@@ -1,27 +0,0 @@
1
- import type { UniAppAndroidBuildOptions, UniAppAndroidBuildResult } from '../../../../../types/uniapp-android-build.d';
2
- import type { FileSystem, Path, ChildProcess } from '../../../../../references/node.d';
3
- import type { XMLParserConstructor, XMLSerializerConstructor } from '../../../../../references/xml.d';
4
- import type { JSON5Parser } from '../../../../../references/json5.d';
5
- import type { XPath } from '../../../../../references/xpath.d';
6
- import type { setTimeout } from '../../../../../references/timer.d';
7
- export interface BuildAndroidAppDeps {
8
- existsSync: FileSystem['existsSync'];
9
- readFileSync: FileSystem['readFileSync'];
10
- writeFileSync: FileSystem['writeFileSync'];
11
- copyFileSync: FileSystem['copyFileSync'];
12
- mkdirSync: FileSystem['mkdirSync'];
13
- readdirSync: FileSystem['readdirSync'];
14
- statSync: FileSystem['statSync'];
15
- cp: FileSystem['promises']['cp'];
16
- join: Path['join'];
17
- dirname: Path['dirname'];
18
- basename: Path['basename'];
19
- exec: ChildProcess['exec'];
20
- platform: string;
21
- parse: JSON5Parser['parse'];
22
- xmlParser: XMLParserConstructor;
23
- xmlSerializer: XMLSerializerConstructor;
24
- xpath: XPath;
25
- setTimeout: typeof setTimeout;
26
- }
27
- export declare function buildAndroidApp(options: UniAppAndroidBuildOptions, deps: BuildAndroidAppDeps): Promise<UniAppAndroidBuildResult>;
@@ -1,287 +0,0 @@
1
- import { parseManifest } from '../../../uniapp/parseManifest';
2
- import { build } from '../../../uniapp/build';
3
- import { buildProject } from '../../../android/buildProject';
4
- import { modifyManifest } from '../../../android/modifyManifest';
5
- import { modifyGradle } from '../../../android/modifyGradle';
6
- import { modifyXml } from '../../../xml/modifyXml';
7
- import { detectUniAppAndroidProjectStructure } from '../../../uniapp/detectAndroidProjectStructure';
8
- import { detectAllAndroidModules } from '../../../android/detectAndroidModules';
9
- export async function buildAndroidApp(options, deps) {
10
- const logs = [];
11
- if (!options.uniappProjectPath) {
12
- return {
13
- success: false,
14
- error: 'uniappProjectPath 是必需的',
15
- logs
16
- };
17
- }
18
- try {
19
- logs.push('步骤 1: 解析 manifest.json 配置');
20
- const parseResult = parseManifest(options.uniappProjectPath, {
21
- existsSync: deps.existsSync,
22
- readFileSync: deps.readFileSync,
23
- join: deps.join,
24
- parse: deps.parse
25
- });
26
- if (!parseResult.success) {
27
- return {
28
- success: false,
29
- error: parseResult.error,
30
- logs
31
- };
32
- }
33
- const manifest = parseResult.manifest;
34
- logs.push('步骤 2: 构建 UniApp 项目');
35
- const buildDeps = {
36
- exec: deps.exec,
37
- join: deps.join,
38
- existsSync: deps.existsSync,
39
- setTimeout: deps.setTimeout
40
- };
41
- const uniBuildResult = await build(options.uniappProjectPath, 'app-plus', buildDeps);
42
- if (!uniBuildResult.success) {
43
- return {
44
- success: false,
45
- error: `构建失败: ${uniBuildResult.error}`,
46
- logs: [...logs, ...uniBuildResult.logs]
47
- };
48
- }
49
- logs.push(...uniBuildResult.logs);
50
- logs.push('步骤 3: 配置 Android 原生工程');
51
- const projectStructure = detectUniAppAndroidProjectStructure(options.projectPath, {
52
- existsSync: deps.existsSync,
53
- join: deps.join
54
- });
55
- logs.push(`使用模块目录: ${projectStructure.moduleDir}`);
56
- const distPath = deps.join(options.uniappProjectPath, 'dist');
57
- logs.push('复制应用资源');
58
- const targetPath = deps.join(options.projectPath, projectStructure.moduleDir, 'src', 'main', 'assets', 'apps', manifest.appid, 'www');
59
- try {
60
- const targetDir = deps.dirname(targetPath);
61
- if (!deps.existsSync(targetDir)) {
62
- deps.mkdirSync(targetDir, { recursive: true });
63
- }
64
- await deps.cp(`${distPath}/build/app`, targetPath, { recursive: true, force: true });
65
- logs.push('应用资源复制完成');
66
- }
67
- catch (error) {
68
- return {
69
- success: false,
70
- error: `复制应用资源失败: ${error instanceof Error ? error.message : String(error)}`,
71
- logs
72
- };
73
- }
74
- logs.push('配置 AndroidManifest.xml');
75
- const manifestModifications = [
76
- {
77
- xpath: "//meta-data[@android:name='DCLOUD_STREAMAPP_CHANNEL']",
78
- action: 'removeElement'
79
- },
80
- {
81
- xpath: "//application",
82
- action: 'addElement',
83
- elementName: 'meta-data',
84
- attributes: {
85
- 'android:name': 'DCLOUD_STREAMAPP_CHANNEL',
86
- 'android:value': 'google'
87
- }
88
- }
89
- ];
90
- if (options.appkey) {
91
- manifestModifications.push({
92
- xpath: "//meta-data[@android:name='dcloud_appkey']",
93
- action: 'removeElement'
94
- }, {
95
- xpath: "//application",
96
- action: 'addElement',
97
- elementName: 'meta-data',
98
- attributes: {
99
- 'android:name': 'dcloud_appkey',
100
- 'android:value': options.appkey
101
- }
102
- });
103
- }
104
- const allModules = detectAllAndroidModules(options.projectPath, {
105
- readdirSync: deps.readdirSync,
106
- statSync: deps.statSync,
107
- existsSync: deps.existsSync,
108
- join: deps.join
109
- });
110
- logs.push(`检测到 ${allModules.length} 个Android模块: ${allModules.join(', ')}`);
111
- let manifestConfigured = false;
112
- for (const moduleDir of allModules) {
113
- const manifestPath = deps.join(options.projectPath, moduleDir, 'src', 'main', 'AndroidManifest.xml');
114
- const manifestResult = await modifyManifest(manifestPath, manifestModifications, {
115
- existsSync: deps.existsSync,
116
- readFileSync: deps.readFileSync,
117
- writeFileSync: deps.writeFileSync,
118
- xmlParser: deps.xmlParser,
119
- xmlSerializer: deps.xmlSerializer,
120
- xpath: deps.xpath
121
- });
122
- if (manifestResult.success) {
123
- logs.push(`${moduleDir} 模块的 AndroidManifest.xml 配置完成`);
124
- manifestConfigured = true;
125
- }
126
- else {
127
- logs.push(`${moduleDir} 模块的 AndroidManifest.xml 配置失败: ${manifestResult.error}`);
128
- }
129
- }
130
- if (allModules.length === 0) {
131
- const manifestPath = deps.join(options.projectPath, projectStructure.moduleDir, 'src', 'main', 'AndroidManifest.xml');
132
- const manifestResult = await modifyManifest(manifestPath, manifestModifications, {
133
- existsSync: deps.existsSync,
134
- readFileSync: deps.readFileSync,
135
- writeFileSync: deps.writeFileSync,
136
- xmlParser: deps.xmlParser,
137
- xmlSerializer: deps.xmlSerializer,
138
- xpath: deps.xpath
139
- });
140
- if (!manifestResult.success) {
141
- return {
142
- success: false,
143
- error: `配置 AndroidManifest.xml 失败: ${manifestResult.error}`,
144
- logs
145
- };
146
- }
147
- logs.push('AndroidManifest.xml 配置完成');
148
- manifestConfigured = true;
149
- }
150
- if (!manifestConfigured) {
151
- return {
152
- success: false,
153
- error: '未能成功配置任何模块的 AndroidManifest.xml',
154
- logs
155
- };
156
- }
157
- logs.push('配置 build.gradle');
158
- const buildGradlePath = deps.join(options.projectPath, projectStructure.moduleDir, 'build.gradle');
159
- const gradleResult = await modifyGradle(buildGradlePath, {
160
- applicationId: options.applicationId,
161
- versionName: '1.0.0',
162
- versionCode: 1,
163
- signing: options.signing ? {
164
- keystore: options.signing.keystorePath,
165
- keystorePassword: options.signing.keystorePassword,
166
- keyAlias: options.signing.keyAlias,
167
- keyPassword: options.signing.keyPassword
168
- } : undefined
169
- }, {
170
- existsSync: deps.existsSync,
171
- readFileSync: deps.readFileSync,
172
- writeFileSync: deps.writeFileSync,
173
- copyFileSync: deps.copyFileSync,
174
- join: deps.join,
175
- dirname: deps.dirname,
176
- basename: deps.basename
177
- });
178
- if (!gradleResult.success) {
179
- return {
180
- success: false,
181
- error: `配置 build.gradle 失败: ${gradleResult.error}`,
182
- logs
183
- };
184
- }
185
- logs.push('build.gradle 配置完成');
186
- if (manifest.name) {
187
- logs.push('配置 strings.xml');
188
- const stringsXmlPath = deps.join(options.projectPath, projectStructure.moduleDir, 'src', 'main', 'res', 'values', 'strings.xml');
189
- const stringsResult = await modifyXml(stringsXmlPath, {
190
- app_name: manifest.name
191
- }, {
192
- tagName: 'string',
193
- matchAttribute: 'name',
194
- modifyType: 'textContent'
195
- }, {
196
- existsSync: deps.existsSync,
197
- readFileSync: deps.readFileSync,
198
- writeFileSync: deps.writeFileSync,
199
- xmlParser: deps.xmlParser,
200
- xmlSerializer: deps.xmlSerializer
201
- });
202
- if (stringsResult.success) {
203
- logs.push('strings.xml 配置完成');
204
- }
205
- else {
206
- logs.push(`strings.xml 配置失败: ${stringsResult.error}`);
207
- }
208
- }
209
- logs.push('配置 dcloud_control.xml');
210
- const dcloudControlXmlPath = deps.join(options.projectPath, projectStructure.moduleDir, 'src', 'main', 'assets', 'data', 'dcloud_control.xml');
211
- try {
212
- if (deps.existsSync(dcloudControlXmlPath)) {
213
- const xmlContent = deps.readFileSync(dcloudControlXmlPath, 'utf8');
214
- const parser = new deps.xmlParser();
215
- const xmlDoc = parser.parseFromString(xmlContent, 'text/xml');
216
- const appsElements = xmlDoc.getElementsByTagName('apps');
217
- if (appsElements.length > 0) {
218
- const appsElement = appsElements[0];
219
- const existingAppElements = appsElement.getElementsByTagName('app');
220
- while (existingAppElements.length > 0) {
221
- appsElement.removeChild(existingAppElements[0]);
222
- }
223
- logs.push('已删除所有现有的 app 元素');
224
- const newAppElement = xmlDoc.createElement('app');
225
- newAppElement.setAttribute('appid', manifest.appid);
226
- newAppElement.setAttribute('appver', '');
227
- if (options.appkey) {
228
- newAppElement.setAttribute('appkey', options.appkey);
229
- logs.push(`设置 appkey: ${options.appkey}`);
230
- }
231
- appsElement.appendChild(newAppElement);
232
- logs.push(`添加新的 app 元素,appid: ${manifest.appid}`);
233
- const serializer = new deps.xmlSerializer();
234
- const newXmlContent = serializer.serializeToString(xmlDoc);
235
- deps.writeFileSync(dcloudControlXmlPath, newXmlContent, 'utf8');
236
- logs.push('dcloud_control.xml 配置完成');
237
- }
238
- else {
239
- logs.push('dcloud_control.xml 中未找到 apps 元素');
240
- }
241
- }
242
- else {
243
- logs.push('dcloud_control.xml 文件不存在');
244
- }
245
- }
246
- catch (error) {
247
- logs.push(`配置 dcloud_control.xml 失败: ${error instanceof Error ? error.message : String(error)}`);
248
- }
249
- logs.push('步骤 4: 编译 Android 应用');
250
- const androidBuildDeps = {
251
- existsSync: deps.existsSync,
252
- readdirSync: deps.readdirSync,
253
- statSync: deps.statSync,
254
- join: deps.join,
255
- platform: deps.platform,
256
- exec: deps.exec,
257
- setTimeout: deps.setTimeout
258
- };
259
- const buildResult = await buildProject({
260
- projectPath: options.projectPath,
261
- buildVariant: 'debug'
262
- }, androidBuildDeps);
263
- if (!buildResult.success) {
264
- return {
265
- success: false,
266
- error: `编译失败: ${buildResult.error}`,
267
- logs: [...logs, ...buildResult.logs]
268
- };
269
- }
270
- logs.push(...buildResult.logs);
271
- logs.push('Android 离线打包完成');
272
- return {
273
- success: true,
274
- outputPath: buildResult.outputPath,
275
- logs
276
- };
277
- }
278
- catch (error) {
279
- const errorMessage = error instanceof Error ? error.message : String(error);
280
- return {
281
- success: false,
282
- error: `打包过程中发生异常: ${errorMessage}`,
283
- logs
284
- };
285
- }
286
- }
287
- //# sourceMappingURL=buildAndroidApp.js.map