@tencentcloud/ai-desk-customer-vue 0.1.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 (351) hide show
  1. package/.code.yml +17 -0
  2. package/.eslintignore +6 -0
  3. package/.stylelintrc.json +40 -0
  4. package/CHANGELOG.md +5 -0
  5. package/README.md +12 -0
  6. package/adapter-vue-web.ts +73 -0
  7. package/adapter-vue.ts +10 -0
  8. package/assets/audio-before-delete.svg +4 -0
  9. package/assets/audio-blue.png +0 -0
  10. package/assets/audio-bubble-blue.svg +3 -0
  11. package/assets/audio-bubble-red.svg +3 -0
  12. package/assets/audio-delete.svg +10 -0
  13. package/assets/audio.svg +6 -0
  14. package/assets/back.svg +16 -0
  15. package/assets/background_mobile.png +0 -0
  16. package/assets/camera-uni.png +0 -0
  17. package/assets/close-quote-icon.svg +3 -0
  18. package/assets/customer_avatar.png +0 -0
  19. package/assets/customer_avatar_mobile.png +0 -0
  20. package/assets/dialog-close.png +0 -0
  21. package/assets/double-arrow.svg +1 -0
  22. package/assets/download.svg +6 -0
  23. package/assets/emoji.png +0 -0
  24. package/assets/face-uni.png +0 -0
  25. package/assets/face.png +0 -0
  26. package/assets/file-h5.png +0 -0
  27. package/assets/files.png +0 -0
  28. package/assets/form-dialog-bg.png +0 -0
  29. package/assets/icon-arrow-left.svg +7 -0
  30. package/assets/icon-close.svg +6 -0
  31. package/assets/iconRight.svg +3 -0
  32. package/assets/icon_form.png +0 -0
  33. package/assets/icon_form_filled.png +0 -0
  34. package/assets/icon_question.png +0 -0
  35. package/assets/icon_refresh.png +0 -0
  36. package/assets/icon_success.png +0 -0
  37. package/assets/imRobotGuess.svg +4 -0
  38. package/assets/image-uni.png +0 -0
  39. package/assets/image.png +0 -0
  40. package/assets/keyboard_icon.png +0 -0
  41. package/assets/loading.png +0 -0
  42. package/assets/more-uni.png +0 -0
  43. package/assets/more_tools.png +0 -0
  44. package/assets/msg-audio.svg +1 -0
  45. package/assets/msg-copy.svg +30 -0
  46. package/assets/msg-del.svg +33 -0
  47. package/assets/msg-quote.svg +8 -0
  48. package/assets/msg-revoke.svg +29 -0
  49. package/assets/radio-check.png +0 -0
  50. package/assets/radio-uncheck.png +0 -0
  51. package/assets/radio.svg +6 -0
  52. package/assets/refresh.svg +4 -0
  53. package/assets/rotate-left.svg +7 -0
  54. package/assets/rotate-right.svg +7 -0
  55. package/assets/star.png +0 -0
  56. package/assets/starLine.png +0 -0
  57. package/assets/translate.svg +12 -0
  58. package/assets/video-play.png +0 -0
  59. package/assets/video-uni.png +0 -0
  60. package/assets/video.png +0 -0
  61. package/assets/zoom-in.svg +9 -0
  62. package/assets/zoom-out.svg +9 -0
  63. package/components/CustomerServiceChat/chat-header/index-web.vue +141 -0
  64. package/components/CustomerServiceChat/emoji-config/custom-emoji.ts +15 -0
  65. package/components/CustomerServiceChat/emoji-config/default-emoji.ts +114 -0
  66. package/components/CustomerServiceChat/emoji-config/index.ts +140 -0
  67. package/components/CustomerServiceChat/emoji-config/locales/en.ts +66 -0
  68. package/components/CustomerServiceChat/emoji-config/locales/zh_cn.ts +66 -0
  69. package/components/CustomerServiceChat/index-web.vue +250 -0
  70. package/components/CustomerServiceChat/message-input/index-web.vue +214 -0
  71. package/components/CustomerServiceChat/message-input/index.ts +2 -0
  72. package/components/CustomerServiceChat/message-input/message-input-button.vue +95 -0
  73. package/components/CustomerServiceChat/message-input/message-input-editor-web.vue +884 -0
  74. package/components/CustomerServiceChat/message-input/message-input-file-web.ts +38 -0
  75. package/components/CustomerServiceChat/message-input/message-input-quote/index.vue +204 -0
  76. package/components/CustomerServiceChat/message-input-toolbar/emoji-dialog-mobile/emoji-dialog-mobile.vue +145 -0
  77. package/components/CustomerServiceChat/message-input-toolbar/emoji-picker/emoji-picker-dialog.vue +180 -0
  78. package/components/CustomerServiceChat/message-input-toolbar/emoji-picker/index.ts +2 -0
  79. package/components/CustomerServiceChat/message-input-toolbar/emoji-picker/index.vue +90 -0
  80. package/components/CustomerServiceChat/message-input-toolbar/emoji-picker/style/h5.scss +26 -0
  81. package/components/CustomerServiceChat/message-input-toolbar/emoji-picker/style/index.scss +4 -0
  82. package/components/CustomerServiceChat/message-input-toolbar/emoji-picker/style/web.scss +55 -0
  83. package/components/CustomerServiceChat/message-input-toolbar/file-upload/index.ts +2 -0
  84. package/components/CustomerServiceChat/message-input-toolbar/file-upload/index.vue +77 -0
  85. package/components/CustomerServiceChat/message-input-toolbar/image-upload/index.ts +2 -0
  86. package/components/CustomerServiceChat/message-input-toolbar/image-upload/index.vue +185 -0
  87. package/components/CustomerServiceChat/message-input-toolbar/index-web.vue +191 -0
  88. package/components/CustomerServiceChat/message-input-toolbar/index.ts +2 -0
  89. package/components/CustomerServiceChat/message-input-toolbar/style/uni.scss +111 -0
  90. package/components/CustomerServiceChat/message-input-toolbar/toolbar-item-container/index.vue +149 -0
  91. package/components/CustomerServiceChat/message-input-toolbar/toolbar-item-container/style/color.scss +6 -0
  92. package/components/CustomerServiceChat/message-input-toolbar/toolbar-item-container/style/h5.scss +20 -0
  93. package/components/CustomerServiceChat/message-input-toolbar/toolbar-item-container/style/index.scss +5 -0
  94. package/components/CustomerServiceChat/message-input-toolbar/toolbar-item-container/style/uni.scss +36 -0
  95. package/components/CustomerServiceChat/message-input-toolbar/toolbar-item-container/style/web.scss +19 -0
  96. package/components/CustomerServiceChat/message-input-toolbar/video-upload/index.ts +2 -0
  97. package/components/CustomerServiceChat/message-input-toolbar/video-upload/index.vue +146 -0
  98. package/components/CustomerServiceChat/message-list/index-web.vue +712 -0
  99. package/components/CustomerServiceChat/message-list/link/index.ts +23 -0
  100. package/components/CustomerServiceChat/message-list/message-elements/message-audio-web.vue +223 -0
  101. package/components/CustomerServiceChat/message-list/message-elements/message-bubble-web.vue +504 -0
  102. package/components/CustomerServiceChat/message-list/message-elements/message-custom.vue +5 -0
  103. package/components/CustomerServiceChat/message-list/message-elements/message-face.vue +45 -0
  104. package/components/CustomerServiceChat/message-list/message-elements/message-file.vue +151 -0
  105. package/components/CustomerServiceChat/message-list/message-elements/message-image-web.vue +97 -0
  106. package/components/CustomerServiceChat/message-list/message-elements/message-location.vue +34 -0
  107. package/components/CustomerServiceChat/message-list/message-elements/message-quote/index-web.vue +286 -0
  108. package/components/CustomerServiceChat/message-list/message-elements/message-quote/interface.ts +60 -0
  109. package/components/CustomerServiceChat/message-list/message-elements/message-record/index.vue +139 -0
  110. package/components/CustomerServiceChat/message-list/message-elements/message-text.vue +94 -0
  111. package/components/CustomerServiceChat/message-list/message-elements/message-timestamp.vue +76 -0
  112. package/components/CustomerServiceChat/message-list/message-elements/message-video-web.vue +319 -0
  113. package/components/CustomerServiceChat/message-list/message-elements/plugins/plugin-components/index.ts +9 -0
  114. package/components/CustomerServiceChat/message-list/message-elements/plugins/plugin-components/message-customer/index.ts +5 -0
  115. package/components/CustomerServiceChat/message-list/message-elements/plugins/plugin-components/message-customer/message-customer-service.vue +22 -0
  116. package/components/CustomerServiceChat/message-list/message-elements/plugins/plugin-components/message-plugin-layout-web.vue +133 -0
  117. package/components/CustomerServiceChat/message-list/message-elements/plugins/plugin-components/message-plugin-web.vue +83 -0
  118. package/components/CustomerServiceChat/message-list/message-elements/read-status/index.vue +193 -0
  119. package/components/CustomerServiceChat/message-list/message-elements/simple-message-list/index.vue +462 -0
  120. package/components/CustomerServiceChat/message-list/message-elements/simple-message-list/message-container.vue +105 -0
  121. package/components/CustomerServiceChat/message-list/message-elements/video-play.vue +59 -0
  122. package/components/CustomerServiceChat/message-list/message-tool/index-web.vue +312 -0
  123. package/components/CustomerServiceChat/message-list/message-tool/message-revoked.vue +63 -0
  124. package/components/CustomerServiceChat/message-list/scroll-button/index.vue +201 -0
  125. package/components/CustomerServiceChat/message-list/style/color.scss +32 -0
  126. package/components/CustomerServiceChat/message-list/style/h5.scss +16 -0
  127. package/components/CustomerServiceChat/message-list/style/index.scss +11 -0
  128. package/components/CustomerServiceChat/message-list/style/web.scss +180 -0
  129. package/components/CustomerServiceChat/style/common.scss +59 -0
  130. package/components/CustomerServiceChat/style/h5.scss +51 -0
  131. package/components/CustomerServiceChat/style/index.scss +12 -0
  132. package/components/CustomerServiceChat/style/uni.scss +13 -0
  133. package/components/CustomerServiceChat/style/web.scss +46 -0
  134. package/components/CustomerServiceChat/style/wx.scss +5 -0
  135. package/components/CustomerServiceChat/utils/conversationDraft.ts +86 -0
  136. package/components/CustomerServiceChat/utils/sendMessage.ts +140 -0
  137. package/components/common/Avatar/index.vue +148 -0
  138. package/components/common/BottomPopup/index.ts +3 -0
  139. package/components/common/BottomPopup/index.vue +160 -0
  140. package/components/common/BottomPopup/style/h5.scss +62 -0
  141. package/components/common/BottomPopup/style/index.scss +3 -0
  142. package/components/common/BottomPopup/style/modal.scss +5 -0
  143. package/components/common/Dialog/index.ts +3 -0
  144. package/components/common/Dialog/index.vue +120 -0
  145. package/components/common/Dialog/style/color.scss +43 -0
  146. package/components/common/Dialog/style/dialog.scss +4 -0
  147. package/components/common/Dialog/style/h5.scss +56 -0
  148. package/components/common/Dialog/style/web.scss +61 -0
  149. package/components/common/Drawer/index.vue +164 -0
  150. package/components/common/Icon.vue +83 -0
  151. package/components/common/ImagePreviewer/image-item-web.vue +42 -0
  152. package/components/common/ImagePreviewer/index-web.vue +682 -0
  153. package/components/common/ImagePreviewer/index.ts +3 -0
  154. package/components/common/Overlay/index.vue +126 -0
  155. package/components/common/ProgressMessage/index.vue +95 -0
  156. package/components/common/RadioSelect/index.vue +59 -0
  157. package/components/common/RichText/LICENSE +21 -0
  158. package/components/common/RichText/README.md +244 -0
  159. package/components/common/RichText/dist/mp-alipay/index.acss +1 -0
  160. package/components/common/RichText/dist/mp-alipay/index.axml +1 -0
  161. package/components/common/RichText/dist/mp-alipay/index.js +8 -0
  162. package/components/common/RichText/dist/mp-alipay/index.json +1 -0
  163. package/components/common/RichText/dist/mp-alipay/node/node.acss +1 -0
  164. package/components/common/RichText/dist/mp-alipay/node/node.axml +1 -0
  165. package/components/common/RichText/dist/mp-alipay/node/node.js +1 -0
  166. package/components/common/RichText/dist/mp-alipay/node/node.json +1 -0
  167. package/components/common/RichText/dist/mp-alipay/parser.js +1 -0
  168. package/components/common/RichText/dist/mp-baidu/index.css +1 -0
  169. package/components/common/RichText/dist/mp-baidu/index.js +8 -0
  170. package/components/common/RichText/dist/mp-baidu/index.json +1 -0
  171. package/components/common/RichText/dist/mp-baidu/index.swan +1 -0
  172. package/components/common/RichText/dist/mp-baidu/node/node.css +1 -0
  173. package/components/common/RichText/dist/mp-baidu/node/node.js +1 -0
  174. package/components/common/RichText/dist/mp-baidu/node/node.json +1 -0
  175. package/components/common/RichText/dist/mp-baidu/node/node.swan +1 -0
  176. package/components/common/RichText/dist/mp-baidu/parser.js +1 -0
  177. package/components/common/RichText/dist/mp-qq/index.js +8 -0
  178. package/components/common/RichText/dist/mp-qq/index.json +1 -0
  179. package/components/common/RichText/dist/mp-qq/index.qml +1 -0
  180. package/components/common/RichText/dist/mp-qq/index.qss +1 -0
  181. package/components/common/RichText/dist/mp-qq/node/node.js +1 -0
  182. package/components/common/RichText/dist/mp-qq/node/node.json +1 -0
  183. package/components/common/RichText/dist/mp-qq/node/node.qml +1 -0
  184. package/components/common/RichText/dist/mp-qq/node/node.qss +1 -0
  185. package/components/common/RichText/dist/mp-qq/parser.js +1 -0
  186. package/components/common/RichText/dist/mp-toutiao/index.js +8 -0
  187. package/components/common/RichText/dist/mp-toutiao/index.json +1 -0
  188. package/components/common/RichText/dist/mp-toutiao/index.ttml +1 -0
  189. package/components/common/RichText/dist/mp-toutiao/index.ttss +1 -0
  190. package/components/common/RichText/dist/mp-toutiao/node/node.js +1 -0
  191. package/components/common/RichText/dist/mp-toutiao/node/node.json +1 -0
  192. package/components/common/RichText/dist/mp-toutiao/node/node.ttml +1 -0
  193. package/components/common/RichText/dist/mp-toutiao/node/node.ttss +1 -0
  194. package/components/common/RichText/dist/mp-toutiao/parser.js +1 -0
  195. package/components/common/RichText/dist/mp-weixin/index.js +8 -0
  196. package/components/common/RichText/dist/mp-weixin/index.json +1 -0
  197. package/components/common/RichText/dist/mp-weixin/index.wxml +1 -0
  198. package/components/common/RichText/dist/mp-weixin/index.wxss +1 -0
  199. package/components/common/RichText/dist/mp-weixin/node/node.js +1 -0
  200. package/components/common/RichText/dist/mp-weixin/node/node.json +1 -0
  201. package/components/common/RichText/dist/mp-weixin/node/node.wxml +1 -0
  202. package/components/common/RichText/dist/mp-weixin/node/node.wxss +1 -0
  203. package/components/common/RichText/dist/mp-weixin/parser.js +1 -0
  204. package/components/common/RichText/dist/uni-app/components/mp-html/mp-html.vue +498 -0
  205. package/components/common/RichText/dist/uni-app/components/mp-html/node/node.vue +587 -0
  206. package/components/common/RichText/dist/uni-app/components/mp-html/parser.js +1393 -0
  207. package/components/common/RichText/dist/uni-app/static/app-plus/mp-html/js/handler.js +1 -0
  208. package/components/common/RichText/dist/uni-app/static/app-plus/mp-html/js/uni.webview.min.js +1 -0
  209. package/components/common/RichText/dist/uni-app/static/app-plus/mp-html/local.html +1 -0
  210. package/components/common/RichText/docs/.nojekyll +0 -0
  211. package/components/common/RichText/docs/index.html +50 -0
  212. package/components/common/RichText/docs/lib/docsify.min.js +1 -0
  213. package/components/common/RichText/docs/lib/prism-bash.min.js +1 -0
  214. package/components/common/RichText/docs/lib/search.min.js +1 -0
  215. package/components/common/RichText/docs/lib/vue.css +858 -0
  216. package/components/common/RichText/gulpfile.js +113 -0
  217. package/components/common/RichText/lint.js +63 -0
  218. package/components/common/RichText/package.json +74 -0
  219. package/components/common/RichText/plugins/README.md +2 -0
  220. package/components/common/RichText/plugins/audio/README.md +25 -0
  221. package/components/common/RichText/plugins/audio/build.js +11 -0
  222. package/components/common/RichText/plugins/audio/context.js +7 -0
  223. package/components/common/RichText/plugins/audio/index.js +34 -0
  224. package/components/common/RichText/plugins/audio/miniprogram/audio.js +189 -0
  225. package/components/common/RichText/plugins/audio/miniprogram/audio.json +3 -0
  226. package/components/common/RichText/plugins/audio/miniprogram/audio.wxml +17 -0
  227. package/components/common/RichText/plugins/audio/miniprogram/audio.wxss +127 -0
  228. package/components/common/RichText/plugins/audio/miniprogram/build.js +3 -0
  229. package/components/common/RichText/plugins/audio/uni-app/audio.vue +269 -0
  230. package/components/common/RichText/plugins/audio/uni-app/build.js +3 -0
  231. package/components/common/RichText/plugins/card/README.md +30 -0
  232. package/components/common/RichText/plugins/card/build.js +14 -0
  233. package/components/common/RichText/plugins/card/index.js +7 -0
  234. package/components/common/RichText/plugins/card/miniprogram/build.js +3 -0
  235. package/components/common/RichText/plugins/card/miniprogram/card.js +26 -0
  236. package/components/common/RichText/plugins/card/miniprogram/card.json +3 -0
  237. package/components/common/RichText/plugins/card/miniprogram/card.wxml +9 -0
  238. package/components/common/RichText/plugins/card/miniprogram/card.wxss +55 -0
  239. package/components/common/RichText/plugins/card/uni-app/build.js +3 -0
  240. package/components/common/RichText/plugins/card/uni-app/card.vue +122 -0
  241. package/components/common/RichText/plugins/editable/README.md +137 -0
  242. package/components/common/RichText/plugins/editable/config.js +15 -0
  243. package/components/common/RichText/plugins/editable/miniprogram/build.js +813 -0
  244. package/components/common/RichText/plugins/editable/miniprogram/index.js +551 -0
  245. package/components/common/RichText/plugins/editable/uni-app/build.js +744 -0
  246. package/components/common/RichText/plugins/editable/uni-app/index.js +553 -0
  247. package/components/common/RichText/plugins/emoji/README.md +15 -0
  248. package/components/common/RichText/plugins/emoji/index.js +203 -0
  249. package/components/common/RichText/plugins/highlight/README.md +26 -0
  250. package/components/common/RichText/plugins/highlight/config.js +5 -0
  251. package/components/common/RichText/plugins/highlight/index.js +96 -0
  252. package/components/common/RichText/plugins/highlight/miniprogram/build.js +88 -0
  253. package/components/common/RichText/plugins/highlight/prism.css +125 -0
  254. package/components/common/RichText/plugins/highlight/prism.min.js +7 -0
  255. package/components/common/RichText/plugins/highlight/uni-app/build.js +88 -0
  256. package/components/common/RichText/plugins/img-cache/README.md +24 -0
  257. package/components/common/RichText/plugins/img-cache/build.js +16 -0
  258. package/components/common/RichText/plugins/img-cache/index.js +138 -0
  259. package/components/common/RichText/plugins/latex/README.md +16 -0
  260. package/components/common/RichText/plugins/latex/build.js +14 -0
  261. package/components/common/RichText/plugins/latex/index.js +77 -0
  262. package/components/common/RichText/plugins/latex/katex.css +1070 -0
  263. package/components/common/RichText/plugins/latex/katex.min.js +1 -0
  264. package/components/common/RichText/plugins/markdown/README.md +17 -0
  265. package/components/common/RichText/plugins/markdown/index.js +34 -0
  266. package/components/common/RichText/plugins/markdown/marked.min.js +6 -0
  267. package/components/common/RichText/plugins/markdown/miniprogram/build.js +70 -0
  268. package/components/common/RichText/plugins/markdown/uni-app/build.js +68 -0
  269. package/components/common/RichText/plugins/search/README.md +46 -0
  270. package/components/common/RichText/plugins/search/miniprogram/index.js +137 -0
  271. package/components/common/RichText/plugins/search/uni-app/index.js +132 -0
  272. package/components/common/RichText/plugins/style/README.md +30 -0
  273. package/components/common/RichText/plugins/style/index.js +129 -0
  274. package/components/common/RichText/plugins/style/parser.js +175 -0
  275. package/components/common/RichText/plugins/template/README.md +2 -0
  276. package/components/common/RichText/plugins/template/build.js +65 -0
  277. package/components/common/RichText/plugins/template/index.js +67 -0
  278. package/components/common/RichText/plugins/txv-video/README.md +18 -0
  279. package/components/common/RichText/plugins/txv-video/build.js +3 -0
  280. package/components/common/RichText/plugins/txv-video/index.js +46 -0
  281. package/components/common/RichText/plugins/txv-video/miniprogram/build.js +6 -0
  282. package/components/common/RichText/plugins/txv-video/uni-app/build.js +3 -0
  283. package/components/common/RichText/src/miniprogram/index.js +396 -0
  284. package/components/common/RichText/src/miniprogram/index.json +6 -0
  285. package/components/common/RichText/src/miniprogram/index.wxml +7 -0
  286. package/components/common/RichText/src/miniprogram/index.wxss +13 -0
  287. package/components/common/RichText/src/miniprogram/node/node.js +247 -0
  288. package/components/common/RichText/src/miniprogram/node/node.json +6 -0
  289. package/components/common/RichText/src/miniprogram/node/node.wxml +112 -0
  290. package/components/common/RichText/src/miniprogram/node/node.wxss +164 -0
  291. package/components/common/RichText/src/miniprogram/parser.js +1269 -0
  292. package/components/common/RichText/src/uni-app/components/mp-html/mp-html.vue +498 -0
  293. package/components/common/RichText/src/uni-app/components/mp-html/node/node.vue +585 -0
  294. package/components/common/RichText/src/uni-app/components/mp-html/parser.js +1393 -0
  295. package/components/common/RichText/src/uni-app/static/app-plus/mp-html/js/handler.js +254 -0
  296. package/components/common/RichText/src/uni-app/static/app-plus/mp-html/js/uni.webview.min.js +1 -0
  297. package/components/common/RichText/src/uni-app/static/app-plus/mp-html/local.html +33 -0
  298. package/components/common/RichText/tools/config.js +82 -0
  299. package/components/common/RichText/tools/converter.js +205 -0
  300. package/components/common/RichText/tools/ifdef.js +115 -0
  301. package/components/common/RichText/tools/minifier.js +40 -0
  302. package/components/common/RichText/tools/plugin.js +248 -0
  303. package/components/common/Toast/index-web.ts +122 -0
  304. package/components/common/Toast/index-web.vue +178 -0
  305. package/components/common/Toast/type.ts +8 -0
  306. package/components/common/common.scss +59 -0
  307. package/components/customer-icon.vue +56 -0
  308. package/components/message-branch.vue +120 -0
  309. package/components/message-customer-service.vue +114 -0
  310. package/components/message-form/form-branch.vue +68 -0
  311. package/components/message-form/form-input.vue +242 -0
  312. package/components/message-form/index.vue +80 -0
  313. package/components/message-multi-branch/branch-pc.vue +79 -0
  314. package/components/message-multi-branch/index.vue +60 -0
  315. package/components/message-multi-form/component-mobile/form-popup.vue +37 -0
  316. package/components/message-multi-form/component-mobile/input-mobile.vue +102 -0
  317. package/components/message-multi-form/component-mobile/label-mobile.vue +32 -0
  318. package/components/message-multi-form/component-mobile/radios-mobile.vue +161 -0
  319. package/components/message-multi-form/component-pc/input-pc.vue +93 -0
  320. package/components/message-multi-form/component-pc/label-pc.vue +33 -0
  321. package/components/message-multi-form/component-pc/radio-pc.vue +98 -0
  322. package/components/message-multi-form/form-mobile.vue +385 -0
  323. package/components/message-multi-form/form-pc.vue +184 -0
  324. package/components/message-multi-form/index.vue +61 -0
  325. package/components/message-product-card.vue +129 -0
  326. package/components/message-rating/index.vue +56 -0
  327. package/components/message-rating/message-rating-number.vue +247 -0
  328. package/components/message-rating/message-rating-star.vue +237 -0
  329. package/components/message-rich-text.vue +155 -0
  330. package/components/message-robot-welcome.vue +181 -0
  331. package/components/message-stream.vue +109 -0
  332. package/constant.ts +122 -0
  333. package/excluded-list.txt +6 -0
  334. package/index.ts +30 -0
  335. package/index.vue +60 -0
  336. package/interface.ts +176 -0
  337. package/logger/index.ts +12 -0
  338. package/logger/main.ts +120 -0
  339. package/package.json +62 -0
  340. package/script/fileCopy.js +60 -0
  341. package/script/syncVersion.js +35 -0
  342. package/server.ts +128 -0
  343. package/styles/common.scss +116 -0
  344. package/tsconfig.json +34 -0
  345. package/typings.d.ts +20 -0
  346. package/utils/chatStorage.ts +70 -0
  347. package/utils/copy-web.ts +141 -0
  348. package/utils/enableSampleTaskStatus.ts +8 -0
  349. package/utils/env.ts +15 -0
  350. package/utils/index.ts +59 -0
  351. package/utils/utils.ts +162 -0
@@ -0,0 +1,254 @@
1
+ // 等待初始化完毕
2
+ document.addEventListener('UniAppJSBridgeReady', () => {
3
+ document.body.onclick = () =>
4
+ uni.postMessage({
5
+ data: {
6
+ action: 'onClick'
7
+ }
8
+ })
9
+ uni.postMessage({
10
+ data: {
11
+ action: 'onJSBridgeReady'
12
+ }
13
+ })
14
+ })
15
+
16
+ let options
17
+ let medias = []
18
+
19
+ /**
20
+ * @description 获取标签的所有属性
21
+ * @param {Element} ele
22
+ */
23
+ function getAttrs (ele) {
24
+ const attrs = Object.create(null)
25
+ for (let i = ele.attributes.length; i--;) {
26
+ attrs[ele.attributes[i].name] = ele.attributes[i].value
27
+ }
28
+ return attrs
29
+ }
30
+
31
+ /**
32
+ * @description 图片加载出错
33
+ */
34
+ function onImgError () {
35
+ if (options[1]) {
36
+ this.src = options[1]
37
+ this.onerror = null
38
+ }
39
+ // 取消监听点击
40
+ this.onclick = null
41
+ this.ontouchstart = null
42
+ uni.postMessage({
43
+ data: {
44
+ action: 'onError',
45
+ source: 'img',
46
+ attrs: getAttrs(this)
47
+ }
48
+ })
49
+ }
50
+
51
+ /**
52
+ * @description 检查是否所有图片加载完毕
53
+ */
54
+ function checkReady () {
55
+ window.unloadimgs -= 1
56
+ if (window.unloadimgs === 0) {
57
+ // 所有图片加载完毕
58
+ uni.postMessage({
59
+ data: {
60
+ action: 'onReady'
61
+ }
62
+ })
63
+ }
64
+ }
65
+
66
+ /**
67
+ * @description 创建 dom 结构
68
+ * @param {object[]} nodes 节点数组
69
+ * @param {Element} parent 父节点
70
+ * @param {string} namespace 命名空间
71
+ */
72
+ function createDom (nodes, parent, namespace) {
73
+ for (let i = 0; i < nodes.length; i++) {
74
+ const node = nodes[i]
75
+ let ele
76
+ if (!node.type || node.type === 'node') {
77
+ let name = node.name
78
+ // svg 需要设置 namespace
79
+ if (name === 'svg') {
80
+ namespace = 'http://www.w3.org/2000/svg'
81
+ }
82
+ if (name === 'html' || name === 'body') {
83
+ name = 'div'
84
+ }
85
+ // 创建标签
86
+ if (!namespace) {
87
+ ele = document.createElement(name)
88
+ } else {
89
+ ele = document.createElementNS(namespace, name)
90
+ }
91
+ // 设置属性
92
+ for (const item in node.attrs) {
93
+ ele.setAttribute(item, node.attrs[item])
94
+ }
95
+ // 递归创建子节点
96
+ if (node.children) {
97
+ createDom(node.children, ele, namespace)
98
+ }
99
+
100
+ // 处理图片
101
+ if (name === 'img') {
102
+ window.unloadimgs += 1
103
+ ele.onload = checkReady
104
+ ele.onerror = checkReady
105
+ if (!ele.src && ele.getAttribute('data-src')) {
106
+ ele.src = ele.getAttribute('data-src')
107
+ }
108
+ if (!node.attrs.ignore) {
109
+ // 监听图片点击事件
110
+ ele.onclick = function (e) {
111
+ e.stopPropagation()
112
+ uni.postMessage({
113
+ data: {
114
+ action: 'onImgTap',
115
+ attrs: getAttrs(this)
116
+ }
117
+ })
118
+ }
119
+ }
120
+ if (options[2]) {
121
+ const image = new Image()
122
+ image.src = ele.src
123
+ ele.src = options[2]
124
+ image.onload = function () {
125
+ ele.src = this.src
126
+ }
127
+ image.onerror = function () {
128
+ ele.onerror()
129
+ }
130
+ }
131
+ ele.onerror = onImgError
132
+ } else if (name === 'a') {
133
+ // 处理链接
134
+ ele.addEventListener('click', function (e) {
135
+ e.stopPropagation()
136
+ e.preventDefault() // 阻止默认跳转
137
+ const href = this.getAttribute('href')
138
+ let offset
139
+ if (href && href[0] === '#') {
140
+ offset = (document.getElementById(href.substr(1)) || {}).offsetTop
141
+ }
142
+ uni.postMessage({
143
+ data: {
144
+ action: 'onLinkTap',
145
+ attrs: getAttrs(this),
146
+ offset
147
+ }
148
+ })
149
+ }, true)
150
+ } else if (name === 'video' || name === 'audio') {
151
+ // 处理音视频
152
+ medias.push(ele)
153
+ if (!node.attrs.autoplay && !node.attrs.controls) {
154
+ ele.setAttribute('controls', 'true')
155
+ }
156
+ ele.onplay = function () {
157
+ uni.postMessage({
158
+ data: {
159
+ action: 'onPlay'
160
+ }
161
+ })
162
+ if (options[3]) {
163
+ for (let i = 0; i < medias.length; i++) {
164
+ if (medias[i] !== this) {
165
+ medias[i].pause()
166
+ }
167
+ }
168
+ }
169
+ }
170
+ ele.onerror = function () {
171
+ uni.postMessage({
172
+ data: {
173
+ action: 'onError',
174
+ source: name,
175
+ attrs: getAttrs(this)
176
+ }
177
+ })
178
+ }
179
+ } else if (name === 'table' && options[4] && !ele.style.cssText.includes('inline')) {
180
+ // 处理表格
181
+ const div = document.createElement('div')
182
+ div.style.overflow = 'auto'
183
+ div.appendChild(ele)
184
+ ele = div
185
+ } else if (name === 'svg') {
186
+ namespace = undefined
187
+ }
188
+ } else {
189
+ ele = document.createTextNode(node.text.replace(/&amp;/g, '&'))
190
+ }
191
+ parent.appendChild(ele)
192
+ }
193
+ }
194
+
195
+ // 设置 html 内容
196
+ window.setContent = function (nodes, opts, append) {
197
+ const ele = document.getElementById('content')
198
+
199
+ // 容器样式
200
+ if (opts[0]) {
201
+ document.body.style.cssText = opts[0]
202
+ }
203
+
204
+ // 长按复制
205
+ if (!opts[5]) {
206
+ ele.style.userSelect = 'none'
207
+ }
208
+
209
+ if (!append) {
210
+ ele.innerHTML = '' // 不追加则先清空
211
+ medias = []
212
+ }
213
+
214
+ options = opts
215
+ window.unloadimgs = 0
216
+ const fragment = document.createDocumentFragment()
217
+ createDom(nodes, fragment)
218
+ ele.appendChild(fragment)
219
+
220
+ // 触发事件
221
+ let height = ele.scrollHeight
222
+ uni.postMessage({
223
+ data: {
224
+ action: 'onLoad',
225
+ height
226
+ }
227
+ })
228
+ if (!window.unloadimgs) {
229
+ uni.postMessage({
230
+ data: {
231
+ action: 'onReady',
232
+ height
233
+ }
234
+ })
235
+ }
236
+
237
+ clearInterval(window.timer)
238
+ window.timer = setInterval(() => {
239
+ if (ele.scrollHeight !== height) {
240
+ height = ele.scrollHeight
241
+ uni.postMessage({
242
+ data: {
243
+ action: 'onHeightChange',
244
+ height: height
245
+ }
246
+ })
247
+ }
248
+ }, 350)
249
+ }
250
+
251
+ // 回收计时器
252
+ window.onunload = function () {
253
+ clearInterval(window.timer)
254
+ }
@@ -0,0 +1 @@
1
+ !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e=e||self).uni=n()}(this,(function(){"use strict";try{var e={};Object.defineProperty(e,"passive",{get:function(){!0}}),window.addEventListener("test-passive",null,e)}catch(e){}var n=Object.prototype.hasOwnProperty;function t(e,t){return n.call(e,t)}var i=[],a=function(e,n){var t={options:{timestamp:+new Date},name:e,arg:n};if(window.__dcloud_weex_postMessage||window.__dcloud_weex_){if("postMessage"===e){var a={data:[n]};return window.__dcloud_weex_postMessage?window.__dcloud_weex_postMessage(a):window.__dcloud_weex_.postMessage(JSON.stringify(a))}var o={type:"WEB_INVOKE_APPSERVICE",args:{data:t,webviewIds:i}};window.__dcloud_weex_postMessage?window.__dcloud_weex_postMessageToService(o):window.__dcloud_weex_.postMessageToService(JSON.stringify(o))}if(!window.plus)return window.parent.postMessage({type:"WEB_INVOKE_APPSERVICE",data:t,pageId:""},"*");if(0===i.length){var r=plus.webview.currentWebview();if(!r)throw new Error("plus.webview.currentWebview() is undefined");var d=r.parent(),s="";s=d?d.id:r.id,i.push(s)}if(plus.webview.getWebviewById("__uniapp__service"))plus.webview.postMessageToUniNView({type:"WEB_INVOKE_APPSERVICE",args:{data:t,webviewIds:i}},"__uniapp__service");else{var w=JSON.stringify(t);plus.webview.getLaunchWebview().evalJS('UniPlusBridge.subscribeHandler("'.concat("WEB_INVOKE_APPSERVICE",'",').concat(w,",").concat(JSON.stringify(i),");"))}},o={navigateTo:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=e.url;a("navigateTo",{url:encodeURI(n)})},navigateBack:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=e.delta;a("navigateBack",{delta:parseInt(n)||1})},switchTab:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=e.url;a("switchTab",{url:encodeURI(n)})},reLaunch:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=e.url;a("reLaunch",{url:encodeURI(n)})},redirectTo:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=e.url;a("redirectTo",{url:encodeURI(n)})},getEnv:function(e){window.plus?e({plus:!0}):e({h5:!0})},postMessage:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};a("postMessage",e.data||{})}},r=/uni-app/i.test(navigator.userAgent),d=/Html5Plus/i.test(navigator.userAgent),s=/complete|loaded|interactive/;var w=window.my&&navigator.userAgent.indexOf("AlipayClient")>-1;var u=window.swan&&window.swan.webView&&/swan/i.test(navigator.userAgent);var c=window.qq&&window.qq.miniProgram&&/QQ/i.test(navigator.userAgent)&&/miniProgram/i.test(navigator.userAgent);var g=window.tt&&window.tt.miniProgram&&/toutiaomicroapp/i.test(navigator.userAgent);var v=window.wx&&window.wx.miniProgram&&/micromessenger/i.test(navigator.userAgent)&&/miniProgram/i.test(navigator.userAgent);var p=window.qa&&/quickapp/i.test(navigator.userAgent);for(var l,_=function(){window.UniAppJSBridge=!0,document.dispatchEvent(new CustomEvent("UniAppJSBridgeReady",{bubbles:!0,cancelable:!0}))},f=[function(e){if(r||d)return window.__dcloud_weex_postMessage||window.__dcloud_weex_?document.addEventListener("DOMContentLoaded",e):window.plus&&s.test(document.readyState)?setTimeout(e,0):document.addEventListener("plusready",e),o},function(e){if(v)return window.WeixinJSBridge&&window.WeixinJSBridge.invoke?setTimeout(e,0):document.addEventListener("WeixinJSBridgeReady",e),window.wx.miniProgram},function(e){if(c)return window.QQJSBridge&&window.QQJSBridge.invoke?setTimeout(e,0):document.addEventListener("QQJSBridgeReady",e),window.qq.miniProgram},function(e){if(w){document.addEventListener("DOMContentLoaded",e);var n=window.my;return{navigateTo:n.navigateTo,navigateBack:n.navigateBack,switchTab:n.switchTab,reLaunch:n.reLaunch,redirectTo:n.redirectTo,postMessage:n.postMessage,getEnv:n.getEnv}}},function(e){if(u)return document.addEventListener("DOMContentLoaded",e),window.swan.webView},function(e){if(g)return document.addEventListener("DOMContentLoaded",e),window.tt.miniProgram},function(e){if(p){window.QaJSBridge&&window.QaJSBridge.invoke?setTimeout(e,0):document.addEventListener("QaJSBridgeReady",e);var n=window.qa;return{navigateTo:n.navigateTo,navigateBack:n.navigateBack,switchTab:n.switchTab,reLaunch:n.reLaunch,redirectTo:n.redirectTo,postMessage:n.postMessage,getEnv:n.getEnv}}},function(e){return document.addEventListener("DOMContentLoaded",e),o}],m=0;m<f.length&&!(l=f[m](_));m++);l||(l={});var E="undefined"!=typeof uni?uni:{};if(!E.navigateTo)for(var b in l)t(l,b)&&(E[b]=l[b]);return E.webView=l,E}));
@@ -0,0 +1,33 @@
1
+ <head>
2
+ <meta charset="utf-8">
3
+ <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
4
+ <style>
5
+ html,
6
+ body {
7
+ width: 100%;
8
+ height: 100%;
9
+ overflow-x: scroll;
10
+ overflow-y: hidden;
11
+ }
12
+
13
+ body {
14
+ margin: 0;
15
+ }
16
+
17
+ video {
18
+ width: 300px;
19
+ height: 225px;
20
+ }
21
+
22
+ img {
23
+ max-width: 100%;
24
+ -webkit-touch-callout: none;
25
+ }
26
+ </style>
27
+ </head>
28
+
29
+ <body>
30
+ <div id="content" style="overflow: hidden;"></div>
31
+ <script type="text/javascript" src="./js/uni.webview.min.js"></script>
32
+ <script type="text/javascript" src="./js/handler.js"></script>
33
+ </body>
@@ -0,0 +1,82 @@
1
+ /**
2
+ * @fileoverview 配置文件
3
+ */
4
+ module.exports = {
5
+ /**
6
+ * @description 需要的插件列表
7
+ */
8
+ plugins: [
9
+ // 按需打开注释即可
10
+ // 'audio', // 音乐播放器
11
+ // 'editable', // 内容编辑
12
+ // 'emoji', // 小表情
13
+ // 'highlight', // 代码高亮
14
+ // 'markdown', // 解析 md
15
+ // 'latex', // 解析 latex
16
+ // 'search', // 关键词搜索
17
+ // 'style', // 解析 style 标签
18
+ // 'txv-video', // 使用腾讯视频
19
+ // 'img-cache' // 图片缓存
20
+ // 'card', // 卡片展示
21
+ ],
22
+
23
+ /**
24
+ * @description 要引入到组件中的外部样式(css)
25
+ * 仅支持标签名和 class 选择器
26
+ */
27
+ externStyle: '',
28
+
29
+ /**
30
+ * @description 要引入到模板中的自定义标签(ad 等)
31
+ * 每个标签为一个 object,包含 name(标签名,必要)、attrs(属性列表,非必要)、platforms(需要添加的平台,非必要)
32
+ */
33
+ customElements: [
34
+ /*
35
+ // 需要使用广告标签则打开此注释
36
+ {
37
+ name: 'ad',
38
+ attrs: ['unit-id']
39
+ }
40
+ */
41
+ ],
42
+
43
+ /**
44
+ * @description babel 配置(es6 转 es5)
45
+ * @tutorial https://babeljs.io/docs/usage/options/
46
+ */
47
+ babel: {
48
+ presets: ['@babel/env']
49
+ },
50
+
51
+ /**
52
+ * @description js 压缩配置
53
+ * @tutorial https://www.npmjs.com/package/uglify-js#minify-options
54
+ */
55
+ uglify: {
56
+ mangle: {
57
+ toplevel: true
58
+ },
59
+ output: {
60
+ comments: /^!/
61
+ }
62
+ },
63
+
64
+ /**
65
+ * @description html 压缩配置
66
+ * @tutorial https://github.com/kangax/html-minifier#options-quick-reference
67
+ */
68
+ htmlmin: {
69
+ caseSensitive: true,
70
+ collapseWhitespace: true,
71
+ removeComments: true,
72
+ keepClosingSlash: true
73
+ },
74
+
75
+ /**
76
+ * @description css 压缩配置
77
+ * @tutorial https://github.com/jakubpawlowicz/clean-css#constructor-options
78
+ */
79
+ cleanCss: {
80
+
81
+ }
82
+ }
@@ -0,0 +1,205 @@
1
+ /**
2
+ * @fileoverview 将微信端的代码转换到各个平台
3
+ */
4
+ const through2 = require('through2')
5
+
6
+ // api 前缀
7
+ const prefix = {
8
+ weixin: {
9
+ wxml: 'wx:',
10
+ js: 'wx.'
11
+ },
12
+ qq: {
13
+ wxml: 'qq:',
14
+ js: 'qq.'
15
+ },
16
+ baidu: {
17
+ wxml: 's-',
18
+ js: 'swan.'
19
+ },
20
+ alipay: {
21
+ wxml: 'a:',
22
+ js: 'my.'
23
+ },
24
+ toutiao: {
25
+ wxml: 'tt:',
26
+ js: 'tt.'
27
+ }
28
+ }
29
+ // 文件名后缀
30
+ const suffix = {
31
+ weixin: {
32
+ wxml: '.wxml',
33
+ wxss: '.wxss'
34
+ },
35
+ qq: {
36
+ wxml: '.qml',
37
+ wxss: '.qss'
38
+ },
39
+ baidu: {
40
+ wxml: '.swan',
41
+ wxss: '.css'
42
+ },
43
+ alipay: {
44
+ wxml: '.axml',
45
+ wxss: '.acss'
46
+ },
47
+ toutiao: {
48
+ wxml: '.ttml',
49
+ wxss: '.ttss'
50
+ }
51
+ }
52
+
53
+ /**
54
+ * @description 取出两个括号之间的内容
55
+ * @param {string} content 总内容
56
+ * @param {number} i 开始位置
57
+ */
58
+ function getSection (content, i) {
59
+ let j = i + 1
60
+ let num = 1
61
+ const start = content[i]
62
+ const end = start === '(' ? ')' : '}'
63
+ while (num) {
64
+ if (content[j] === start) {
65
+ num++
66
+ } else if (content[j] === end) {
67
+ num--
68
+ }
69
+ j++
70
+ }
71
+ return content.substring(i, j)
72
+ }
73
+
74
+ /**
75
+ * @description 处理不同小程序平台间的差异
76
+ * @param {string} platform 使用平台
77
+ */
78
+ module.exports = function (platform) {
79
+ if (platform !== 'uni-app') {
80
+ platform = platform.split('-')[1]
81
+ }
82
+ return through2.obj(function (file, _, callback) {
83
+ if (file.isBuffer()) {
84
+ let content = file.contents.toString()
85
+ if (platform === 'uni-app') {
86
+ if (file.extname === '.js') {
87
+ content = content.replace(/\.properties/g, '')
88
+ }
89
+ } else {
90
+ // wxml 文件处理
91
+ if (file.extname === '.wxml') {
92
+ content = content.replace(/wx:/g, prefix[platform].wxml) // 替换 api 前缀
93
+ file.extname = suffix[platform].wxml // 修改后缀名
94
+ if (platform === 'qq') {
95
+ // wxs 转为 qs
96
+ content = content.replace(/<wxs/g, '<qs').replace(/<\/wxs/g, '</qs')
97
+ } else if (platform === 'baidu') {
98
+ content = content.replace(/s-if=['"]{{(\S+)}}['"]/g, 's-if="$1"') // s-if 和 s-for 后不加 {{}}
99
+ .replace(/s-for=['"]{{(\S+)}}['"]/g, 's-for="$1"')
100
+ .replace(/data="(.*?)"/g, 'data="{$1}"')
101
+ } else if (platform === 'alipay') {
102
+ content = content.replace('block-size', 'handle-size')
103
+ .replace(/longpress/g, 'longTap')
104
+ .replace(/bind([\S])/g, (_, $1) => { // bindevent 转为 onEvent
105
+ return 'on' + $1.toUpperCase()
106
+ }).replace(/catch([\S])/g, (_, $1) => { // catchevent 转为 catchEvent
107
+ return 'catch' + $1.toUpperCase()
108
+ })
109
+ }
110
+ } else if (file.extname === '.js') {
111
+ // js 文件处理
112
+ // 替换 api 前缀
113
+ content = content.replace(/wx\./g, prefix[platform].js)
114
+
115
+ // 支付宝格式转换
116
+ if (platform === 'alipay') {
117
+ // 将 aa.triggerEvent('bb', cc) 替换为 aa.props.onBb && aa.props.onBb(cc)
118
+ content = content.replace(/([a-zA-Z0-9._]+).triggerEvent\(['"](\S+?)['"],*/g, function (_, $1, $2) {
119
+ const method = `${$1}.props.on${$2[0].toUpperCase()}${$2.slice(1)}`
120
+ return `${method}&&${method}(`
121
+ })
122
+
123
+ // 转换 showToast
124
+ let i = content.indexOf('.showToast')
125
+ while (i !== -1) {
126
+ i += 10
127
+ const section = getSection(content, i)
128
+ content = content.substr(0, i) + section.replace('title', 'content') + content.substr(i + section.length)
129
+ i = content.indexOf('.showToast', i)
130
+ }
131
+ // 转换 showActionSheet
132
+ i = content.indexOf('.showActionSheet')
133
+ while (i !== -1) {
134
+ i += 16
135
+ const section = getSection(content, i)
136
+ content = content.substr(0, i) + section.replace('itemList', 'items') + content.substr(i + section.length)
137
+ i = content.indexOf('.showActionSheet', i)
138
+ }
139
+ // 转换 setClipboardData
140
+ i = content.indexOf('.setClipboardData')
141
+ while (i !== -1) {
142
+ i += 17
143
+ const section = getSection(content, i)
144
+ content = content.substr(0, i - 4) + section.replace('data', 'text') + content.substr(i + section.length)
145
+ i = content.indexOf('.setClipboardData', i)
146
+ }
147
+ // 组件格式转换
148
+ if (content.includes('Component({')) {
149
+ // 替换生命周期
150
+ content = content.replace('created:', 'didMount:')
151
+ .replace('attached:', 'didMount:')
152
+ .replace('detached:', 'didUnmount:')
153
+ // 将 properties 字段转为 props 格式
154
+ i = content.indexOf('{', content.indexOf('properties:'))
155
+ let props
156
+ let propsStr = '{'
157
+ const objStr = getSection(content, i)
158
+ // 取出整个 properties 字段
159
+ eval('props = ' + objStr) // eslint-disable-line
160
+ for (const item in props) {
161
+ if (!props[item]) continue
162
+ propsStr += item + ':'
163
+ if (props[item].value) {
164
+ // 设置了默认值
165
+ if (typeof props[item].value === 'boolean') {
166
+ propsStr += props[item].value ? '!0' : '!1'
167
+ } else {
168
+ propsStr += props[item].value
169
+ }
170
+ } else {
171
+ // 没有设置默认值
172
+ const type = props[item].type || props[item]
173
+ if (type === String) {
174
+ propsStr += '""'
175
+ } else if (type === Boolean) {
176
+ propsStr += '!1'
177
+ } else if (type === Number) {
178
+ propsStr += '0'
179
+ } else if (type === Object) {
180
+ propsStr += '{}'
181
+ } else if (type === Array) {
182
+ propsStr += '[]'
183
+ }
184
+ }
185
+ propsStr += ','
186
+ }
187
+ content = content.substr(0, i) + propsStr.substring(0, propsStr.length - 1) + '}' + content.substr(i + objStr.length)
188
+ }
189
+
190
+ content = content.replace(/properties/g, 'props')
191
+ .replace(/\.setNavigationBarTitle/g, '.setNavigationBar')
192
+ } else {
193
+ content = content.replace(/\.properties/g, '.data')
194
+ }
195
+ } else if (file.extname === '.wxss') {
196
+ // wxss 文件处理
197
+ file.extname = suffix[platform].wxss // 修改后缀名
198
+ }
199
+ }
200
+ file.contents = Buffer.from(content)
201
+ }
202
+ this.push(file)
203
+ callback()
204
+ })
205
+ }
@@ -0,0 +1,115 @@
1
+ /**
2
+ * @fileoverview 条件编译
3
+ */
4
+ const through2 = require('through2')
5
+
6
+ /**
7
+ * @description 条件编译
8
+ * @param {string} platform 平台
9
+ */
10
+ module.exports = function (platform) {
11
+ return through2.obj(function (file, _, callback) {
12
+ if (file.isBuffer()) {
13
+ // 文件夹级别的处理
14
+ if (file.relative.includes('miniprogram')) {
15
+ if (platform !== 'uni-app') {
16
+ // 去掉这一层
17
+ file.path = file.path.replace(/(.*)[/\\]miniprogram/, '$1')
18
+ } else {
19
+ // 不用于本平台的文件
20
+ callback()
21
+ return
22
+ }
23
+ } else if (file.relative.includes('uni-app')) {
24
+ if (platform === 'uni-app') {
25
+ file.path = file.path.replace(/(.*)[/\\]uni-app/, '$1')
26
+ } else {
27
+ callback()
28
+ return
29
+ }
30
+ }
31
+ if (platform === 'uni-app') {
32
+ // uni-app 平台 vue3 要求使用 es6 模块
33
+ let content = file.contents.toString()
34
+ if (file.basename === 'prism.min.js') {
35
+ content = content.replace('"undefined"!=typeof module&&module.exports&&(module.exports=Prism),', 'export default Prism;')
36
+ } else if (file.extname === '.js' && !file.relative.includes('static')) {
37
+ content = content.replace(/module.exports\s*=\s*/, 'export default ')
38
+ .replace(/const\s+([^\s=]+)\s*=\s*require\(([^)]+)\)/g, 'import $1 from $2')
39
+ }
40
+ file.contents = Buffer.from(content)
41
+ } else {
42
+ // 小程序平台进行进一步处理
43
+ let content = file.contents.toString()
44
+ /**
45
+ * 方式1:
46
+ * 在注释 #if(n)def xxx 和 #endif 之间的内容会根据是否定义 xxx 决定是否保留
47
+ */
48
+ const commentReg = /\/\*[\s\S]*?\*\/|\/\/[^\n]*|<!--[\s\S]*?-->/g // 提取所有注释
49
+ const copy = content // 拷贝一个副本用于搜索
50
+ let match = commentReg.exec(copy)
51
+ const stack = []
52
+ while (match) {
53
+ if (match[0].includes('#if')) {
54
+ stack.push([match[0], match.index])
55
+ } else if (match[0].includes('#endif')) {
56
+ const item = stack.pop()
57
+ if (!item) {
58
+ throw Error('条件编译错误:存在多余的 #endif,path:' + file.path + ',content: ' + content.substr(match.index, 100))
59
+ }
60
+ const def = item[0].match(/MP-[A-Z]+/gi) || [] // 取出定义条件
61
+ let hit = false
62
+ for (let i = 0; i < def.length; i++) {
63
+ if (def[i] && platform === def[i].toLowerCase()) {
64
+ hit = true // 命中
65
+ break
66
+ }
67
+ }
68
+ // 不匹配
69
+ if ((item[0].includes('#ifdef') && !hit) || (item[0].includes('#ifndef') && hit)) {
70
+ let fill = ''
71
+ // 用空格填充
72
+ for (let j = item[1] + item[0].length; j < match.index; j++) {
73
+ if (content[j] === '\n') {
74
+ fill += '\n'
75
+ } else {
76
+ fill += ' '
77
+ }
78
+ }
79
+ content = content.substr(0, item[1] + item[0].length) + fill + content.substr(match.index)
80
+ }
81
+ }
82
+ match = commentReg.exec(copy)
83
+ }
84
+ if (stack.length) {
85
+ throw Error('条件编译错误:存在未闭合的 #ifdef,path:' + file.path + ',content: ' + content.substr(stack[0][1], 100))
86
+ }
87
+
88
+ /**
89
+ * 方式2:
90
+ * wxml 中属性前加平台名将仅编译到该平台,如 mp-weixin:attr
91
+ */
92
+ if (file.extname === '.wxml') {
93
+ content = content.replace(/([^:\s]+:[^=\s]+)\s*=\s*"(.*?)"/g, ($, $1, $2) => {
94
+ const platforms = $1.split(':')
95
+ let name = platforms.pop()
96
+ const last = platforms[platforms.length - 1]
97
+ if (last && !last.includes('mp')) {
98
+ name = platforms.pop() + ':' + name
99
+ }
100
+ if (!platforms.length) return $
101
+ let i
102
+ for (i = platforms.length; i--;) {
103
+ if (platform === platforms[i].toLowerCase()) break
104
+ }
105
+ if (i >= 0) return `${name}="${$2}"`
106
+ return ''
107
+ })
108
+ }
109
+ file.contents = Buffer.from(content)
110
+ }
111
+ }
112
+ this.push(file)
113
+ callback()
114
+ })
115
+ }