@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.
- package/.code.yml +17 -0
- package/.eslintignore +6 -0
- package/.stylelintrc.json +40 -0
- package/CHANGELOG.md +5 -0
- package/README.md +12 -0
- package/adapter-vue-web.ts +73 -0
- package/adapter-vue.ts +10 -0
- package/assets/audio-before-delete.svg +4 -0
- package/assets/audio-blue.png +0 -0
- package/assets/audio-bubble-blue.svg +3 -0
- package/assets/audio-bubble-red.svg +3 -0
- package/assets/audio-delete.svg +10 -0
- package/assets/audio.svg +6 -0
- package/assets/back.svg +16 -0
- package/assets/background_mobile.png +0 -0
- package/assets/camera-uni.png +0 -0
- package/assets/close-quote-icon.svg +3 -0
- package/assets/customer_avatar.png +0 -0
- package/assets/customer_avatar_mobile.png +0 -0
- package/assets/dialog-close.png +0 -0
- package/assets/double-arrow.svg +1 -0
- package/assets/download.svg +6 -0
- package/assets/emoji.png +0 -0
- package/assets/face-uni.png +0 -0
- package/assets/face.png +0 -0
- package/assets/file-h5.png +0 -0
- package/assets/files.png +0 -0
- package/assets/form-dialog-bg.png +0 -0
- package/assets/icon-arrow-left.svg +7 -0
- package/assets/icon-close.svg +6 -0
- package/assets/iconRight.svg +3 -0
- package/assets/icon_form.png +0 -0
- package/assets/icon_form_filled.png +0 -0
- package/assets/icon_question.png +0 -0
- package/assets/icon_refresh.png +0 -0
- package/assets/icon_success.png +0 -0
- package/assets/imRobotGuess.svg +4 -0
- package/assets/image-uni.png +0 -0
- package/assets/image.png +0 -0
- package/assets/keyboard_icon.png +0 -0
- package/assets/loading.png +0 -0
- package/assets/more-uni.png +0 -0
- package/assets/more_tools.png +0 -0
- package/assets/msg-audio.svg +1 -0
- package/assets/msg-copy.svg +30 -0
- package/assets/msg-del.svg +33 -0
- package/assets/msg-quote.svg +8 -0
- package/assets/msg-revoke.svg +29 -0
- package/assets/radio-check.png +0 -0
- package/assets/radio-uncheck.png +0 -0
- package/assets/radio.svg +6 -0
- package/assets/refresh.svg +4 -0
- package/assets/rotate-left.svg +7 -0
- package/assets/rotate-right.svg +7 -0
- package/assets/star.png +0 -0
- package/assets/starLine.png +0 -0
- package/assets/translate.svg +12 -0
- package/assets/video-play.png +0 -0
- package/assets/video-uni.png +0 -0
- package/assets/video.png +0 -0
- package/assets/zoom-in.svg +9 -0
- package/assets/zoom-out.svg +9 -0
- package/components/CustomerServiceChat/chat-header/index-web.vue +141 -0
- package/components/CustomerServiceChat/emoji-config/custom-emoji.ts +15 -0
- package/components/CustomerServiceChat/emoji-config/default-emoji.ts +114 -0
- package/components/CustomerServiceChat/emoji-config/index.ts +140 -0
- package/components/CustomerServiceChat/emoji-config/locales/en.ts +66 -0
- package/components/CustomerServiceChat/emoji-config/locales/zh_cn.ts +66 -0
- package/components/CustomerServiceChat/index-web.vue +250 -0
- package/components/CustomerServiceChat/message-input/index-web.vue +214 -0
- package/components/CustomerServiceChat/message-input/index.ts +2 -0
- package/components/CustomerServiceChat/message-input/message-input-button.vue +95 -0
- package/components/CustomerServiceChat/message-input/message-input-editor-web.vue +884 -0
- package/components/CustomerServiceChat/message-input/message-input-file-web.ts +38 -0
- package/components/CustomerServiceChat/message-input/message-input-quote/index.vue +204 -0
- package/components/CustomerServiceChat/message-input-toolbar/emoji-dialog-mobile/emoji-dialog-mobile.vue +145 -0
- package/components/CustomerServiceChat/message-input-toolbar/emoji-picker/emoji-picker-dialog.vue +180 -0
- package/components/CustomerServiceChat/message-input-toolbar/emoji-picker/index.ts +2 -0
- package/components/CustomerServiceChat/message-input-toolbar/emoji-picker/index.vue +90 -0
- package/components/CustomerServiceChat/message-input-toolbar/emoji-picker/style/h5.scss +26 -0
- package/components/CustomerServiceChat/message-input-toolbar/emoji-picker/style/index.scss +4 -0
- package/components/CustomerServiceChat/message-input-toolbar/emoji-picker/style/web.scss +55 -0
- package/components/CustomerServiceChat/message-input-toolbar/file-upload/index.ts +2 -0
- package/components/CustomerServiceChat/message-input-toolbar/file-upload/index.vue +77 -0
- package/components/CustomerServiceChat/message-input-toolbar/image-upload/index.ts +2 -0
- package/components/CustomerServiceChat/message-input-toolbar/image-upload/index.vue +185 -0
- package/components/CustomerServiceChat/message-input-toolbar/index-web.vue +191 -0
- package/components/CustomerServiceChat/message-input-toolbar/index.ts +2 -0
- package/components/CustomerServiceChat/message-input-toolbar/style/uni.scss +111 -0
- package/components/CustomerServiceChat/message-input-toolbar/toolbar-item-container/index.vue +149 -0
- package/components/CustomerServiceChat/message-input-toolbar/toolbar-item-container/style/color.scss +6 -0
- package/components/CustomerServiceChat/message-input-toolbar/toolbar-item-container/style/h5.scss +20 -0
- package/components/CustomerServiceChat/message-input-toolbar/toolbar-item-container/style/index.scss +5 -0
- package/components/CustomerServiceChat/message-input-toolbar/toolbar-item-container/style/uni.scss +36 -0
- package/components/CustomerServiceChat/message-input-toolbar/toolbar-item-container/style/web.scss +19 -0
- package/components/CustomerServiceChat/message-input-toolbar/video-upload/index.ts +2 -0
- package/components/CustomerServiceChat/message-input-toolbar/video-upload/index.vue +146 -0
- package/components/CustomerServiceChat/message-list/index-web.vue +712 -0
- package/components/CustomerServiceChat/message-list/link/index.ts +23 -0
- package/components/CustomerServiceChat/message-list/message-elements/message-audio-web.vue +223 -0
- package/components/CustomerServiceChat/message-list/message-elements/message-bubble-web.vue +504 -0
- package/components/CustomerServiceChat/message-list/message-elements/message-custom.vue +5 -0
- package/components/CustomerServiceChat/message-list/message-elements/message-face.vue +45 -0
- package/components/CustomerServiceChat/message-list/message-elements/message-file.vue +151 -0
- package/components/CustomerServiceChat/message-list/message-elements/message-image-web.vue +97 -0
- package/components/CustomerServiceChat/message-list/message-elements/message-location.vue +34 -0
- package/components/CustomerServiceChat/message-list/message-elements/message-quote/index-web.vue +286 -0
- package/components/CustomerServiceChat/message-list/message-elements/message-quote/interface.ts +60 -0
- package/components/CustomerServiceChat/message-list/message-elements/message-record/index.vue +139 -0
- package/components/CustomerServiceChat/message-list/message-elements/message-text.vue +94 -0
- package/components/CustomerServiceChat/message-list/message-elements/message-timestamp.vue +76 -0
- package/components/CustomerServiceChat/message-list/message-elements/message-video-web.vue +319 -0
- package/components/CustomerServiceChat/message-list/message-elements/plugins/plugin-components/index.ts +9 -0
- package/components/CustomerServiceChat/message-list/message-elements/plugins/plugin-components/message-customer/index.ts +5 -0
- package/components/CustomerServiceChat/message-list/message-elements/plugins/plugin-components/message-customer/message-customer-service.vue +22 -0
- package/components/CustomerServiceChat/message-list/message-elements/plugins/plugin-components/message-plugin-layout-web.vue +133 -0
- package/components/CustomerServiceChat/message-list/message-elements/plugins/plugin-components/message-plugin-web.vue +83 -0
- package/components/CustomerServiceChat/message-list/message-elements/read-status/index.vue +193 -0
- package/components/CustomerServiceChat/message-list/message-elements/simple-message-list/index.vue +462 -0
- package/components/CustomerServiceChat/message-list/message-elements/simple-message-list/message-container.vue +105 -0
- package/components/CustomerServiceChat/message-list/message-elements/video-play.vue +59 -0
- package/components/CustomerServiceChat/message-list/message-tool/index-web.vue +312 -0
- package/components/CustomerServiceChat/message-list/message-tool/message-revoked.vue +63 -0
- package/components/CustomerServiceChat/message-list/scroll-button/index.vue +201 -0
- package/components/CustomerServiceChat/message-list/style/color.scss +32 -0
- package/components/CustomerServiceChat/message-list/style/h5.scss +16 -0
- package/components/CustomerServiceChat/message-list/style/index.scss +11 -0
- package/components/CustomerServiceChat/message-list/style/web.scss +180 -0
- package/components/CustomerServiceChat/style/common.scss +59 -0
- package/components/CustomerServiceChat/style/h5.scss +51 -0
- package/components/CustomerServiceChat/style/index.scss +12 -0
- package/components/CustomerServiceChat/style/uni.scss +13 -0
- package/components/CustomerServiceChat/style/web.scss +46 -0
- package/components/CustomerServiceChat/style/wx.scss +5 -0
- package/components/CustomerServiceChat/utils/conversationDraft.ts +86 -0
- package/components/CustomerServiceChat/utils/sendMessage.ts +140 -0
- package/components/common/Avatar/index.vue +148 -0
- package/components/common/BottomPopup/index.ts +3 -0
- package/components/common/BottomPopup/index.vue +160 -0
- package/components/common/BottomPopup/style/h5.scss +62 -0
- package/components/common/BottomPopup/style/index.scss +3 -0
- package/components/common/BottomPopup/style/modal.scss +5 -0
- package/components/common/Dialog/index.ts +3 -0
- package/components/common/Dialog/index.vue +120 -0
- package/components/common/Dialog/style/color.scss +43 -0
- package/components/common/Dialog/style/dialog.scss +4 -0
- package/components/common/Dialog/style/h5.scss +56 -0
- package/components/common/Dialog/style/web.scss +61 -0
- package/components/common/Drawer/index.vue +164 -0
- package/components/common/Icon.vue +83 -0
- package/components/common/ImagePreviewer/image-item-web.vue +42 -0
- package/components/common/ImagePreviewer/index-web.vue +682 -0
- package/components/common/ImagePreviewer/index.ts +3 -0
- package/components/common/Overlay/index.vue +126 -0
- package/components/common/ProgressMessage/index.vue +95 -0
- package/components/common/RadioSelect/index.vue +59 -0
- package/components/common/RichText/LICENSE +21 -0
- package/components/common/RichText/README.md +244 -0
- package/components/common/RichText/dist/mp-alipay/index.acss +1 -0
- package/components/common/RichText/dist/mp-alipay/index.axml +1 -0
- package/components/common/RichText/dist/mp-alipay/index.js +8 -0
- package/components/common/RichText/dist/mp-alipay/index.json +1 -0
- package/components/common/RichText/dist/mp-alipay/node/node.acss +1 -0
- package/components/common/RichText/dist/mp-alipay/node/node.axml +1 -0
- package/components/common/RichText/dist/mp-alipay/node/node.js +1 -0
- package/components/common/RichText/dist/mp-alipay/node/node.json +1 -0
- package/components/common/RichText/dist/mp-alipay/parser.js +1 -0
- package/components/common/RichText/dist/mp-baidu/index.css +1 -0
- package/components/common/RichText/dist/mp-baidu/index.js +8 -0
- package/components/common/RichText/dist/mp-baidu/index.json +1 -0
- package/components/common/RichText/dist/mp-baidu/index.swan +1 -0
- package/components/common/RichText/dist/mp-baidu/node/node.css +1 -0
- package/components/common/RichText/dist/mp-baidu/node/node.js +1 -0
- package/components/common/RichText/dist/mp-baidu/node/node.json +1 -0
- package/components/common/RichText/dist/mp-baidu/node/node.swan +1 -0
- package/components/common/RichText/dist/mp-baidu/parser.js +1 -0
- package/components/common/RichText/dist/mp-qq/index.js +8 -0
- package/components/common/RichText/dist/mp-qq/index.json +1 -0
- package/components/common/RichText/dist/mp-qq/index.qml +1 -0
- package/components/common/RichText/dist/mp-qq/index.qss +1 -0
- package/components/common/RichText/dist/mp-qq/node/node.js +1 -0
- package/components/common/RichText/dist/mp-qq/node/node.json +1 -0
- package/components/common/RichText/dist/mp-qq/node/node.qml +1 -0
- package/components/common/RichText/dist/mp-qq/node/node.qss +1 -0
- package/components/common/RichText/dist/mp-qq/parser.js +1 -0
- package/components/common/RichText/dist/mp-toutiao/index.js +8 -0
- package/components/common/RichText/dist/mp-toutiao/index.json +1 -0
- package/components/common/RichText/dist/mp-toutiao/index.ttml +1 -0
- package/components/common/RichText/dist/mp-toutiao/index.ttss +1 -0
- package/components/common/RichText/dist/mp-toutiao/node/node.js +1 -0
- package/components/common/RichText/dist/mp-toutiao/node/node.json +1 -0
- package/components/common/RichText/dist/mp-toutiao/node/node.ttml +1 -0
- package/components/common/RichText/dist/mp-toutiao/node/node.ttss +1 -0
- package/components/common/RichText/dist/mp-toutiao/parser.js +1 -0
- package/components/common/RichText/dist/mp-weixin/index.js +8 -0
- package/components/common/RichText/dist/mp-weixin/index.json +1 -0
- package/components/common/RichText/dist/mp-weixin/index.wxml +1 -0
- package/components/common/RichText/dist/mp-weixin/index.wxss +1 -0
- package/components/common/RichText/dist/mp-weixin/node/node.js +1 -0
- package/components/common/RichText/dist/mp-weixin/node/node.json +1 -0
- package/components/common/RichText/dist/mp-weixin/node/node.wxml +1 -0
- package/components/common/RichText/dist/mp-weixin/node/node.wxss +1 -0
- package/components/common/RichText/dist/mp-weixin/parser.js +1 -0
- package/components/common/RichText/dist/uni-app/components/mp-html/mp-html.vue +498 -0
- package/components/common/RichText/dist/uni-app/components/mp-html/node/node.vue +587 -0
- package/components/common/RichText/dist/uni-app/components/mp-html/parser.js +1393 -0
- package/components/common/RichText/dist/uni-app/static/app-plus/mp-html/js/handler.js +1 -0
- package/components/common/RichText/dist/uni-app/static/app-plus/mp-html/js/uni.webview.min.js +1 -0
- package/components/common/RichText/dist/uni-app/static/app-plus/mp-html/local.html +1 -0
- package/components/common/RichText/docs/.nojekyll +0 -0
- package/components/common/RichText/docs/index.html +50 -0
- package/components/common/RichText/docs/lib/docsify.min.js +1 -0
- package/components/common/RichText/docs/lib/prism-bash.min.js +1 -0
- package/components/common/RichText/docs/lib/search.min.js +1 -0
- package/components/common/RichText/docs/lib/vue.css +858 -0
- package/components/common/RichText/gulpfile.js +113 -0
- package/components/common/RichText/lint.js +63 -0
- package/components/common/RichText/package.json +74 -0
- package/components/common/RichText/plugins/README.md +2 -0
- package/components/common/RichText/plugins/audio/README.md +25 -0
- package/components/common/RichText/plugins/audio/build.js +11 -0
- package/components/common/RichText/plugins/audio/context.js +7 -0
- package/components/common/RichText/plugins/audio/index.js +34 -0
- package/components/common/RichText/plugins/audio/miniprogram/audio.js +189 -0
- package/components/common/RichText/plugins/audio/miniprogram/audio.json +3 -0
- package/components/common/RichText/plugins/audio/miniprogram/audio.wxml +17 -0
- package/components/common/RichText/plugins/audio/miniprogram/audio.wxss +127 -0
- package/components/common/RichText/plugins/audio/miniprogram/build.js +3 -0
- package/components/common/RichText/plugins/audio/uni-app/audio.vue +269 -0
- package/components/common/RichText/plugins/audio/uni-app/build.js +3 -0
- package/components/common/RichText/plugins/card/README.md +30 -0
- package/components/common/RichText/plugins/card/build.js +14 -0
- package/components/common/RichText/plugins/card/index.js +7 -0
- package/components/common/RichText/plugins/card/miniprogram/build.js +3 -0
- package/components/common/RichText/plugins/card/miniprogram/card.js +26 -0
- package/components/common/RichText/plugins/card/miniprogram/card.json +3 -0
- package/components/common/RichText/plugins/card/miniprogram/card.wxml +9 -0
- package/components/common/RichText/plugins/card/miniprogram/card.wxss +55 -0
- package/components/common/RichText/plugins/card/uni-app/build.js +3 -0
- package/components/common/RichText/plugins/card/uni-app/card.vue +122 -0
- package/components/common/RichText/plugins/editable/README.md +137 -0
- package/components/common/RichText/plugins/editable/config.js +15 -0
- package/components/common/RichText/plugins/editable/miniprogram/build.js +813 -0
- package/components/common/RichText/plugins/editable/miniprogram/index.js +551 -0
- package/components/common/RichText/plugins/editable/uni-app/build.js +744 -0
- package/components/common/RichText/plugins/editable/uni-app/index.js +553 -0
- package/components/common/RichText/plugins/emoji/README.md +15 -0
- package/components/common/RichText/plugins/emoji/index.js +203 -0
- package/components/common/RichText/plugins/highlight/README.md +26 -0
- package/components/common/RichText/plugins/highlight/config.js +5 -0
- package/components/common/RichText/plugins/highlight/index.js +96 -0
- package/components/common/RichText/plugins/highlight/miniprogram/build.js +88 -0
- package/components/common/RichText/plugins/highlight/prism.css +125 -0
- package/components/common/RichText/plugins/highlight/prism.min.js +7 -0
- package/components/common/RichText/plugins/highlight/uni-app/build.js +88 -0
- package/components/common/RichText/plugins/img-cache/README.md +24 -0
- package/components/common/RichText/plugins/img-cache/build.js +16 -0
- package/components/common/RichText/plugins/img-cache/index.js +138 -0
- package/components/common/RichText/plugins/latex/README.md +16 -0
- package/components/common/RichText/plugins/latex/build.js +14 -0
- package/components/common/RichText/plugins/latex/index.js +77 -0
- package/components/common/RichText/plugins/latex/katex.css +1070 -0
- package/components/common/RichText/plugins/latex/katex.min.js +1 -0
- package/components/common/RichText/plugins/markdown/README.md +17 -0
- package/components/common/RichText/plugins/markdown/index.js +34 -0
- package/components/common/RichText/plugins/markdown/marked.min.js +6 -0
- package/components/common/RichText/plugins/markdown/miniprogram/build.js +70 -0
- package/components/common/RichText/plugins/markdown/uni-app/build.js +68 -0
- package/components/common/RichText/plugins/search/README.md +46 -0
- package/components/common/RichText/plugins/search/miniprogram/index.js +137 -0
- package/components/common/RichText/plugins/search/uni-app/index.js +132 -0
- package/components/common/RichText/plugins/style/README.md +30 -0
- package/components/common/RichText/plugins/style/index.js +129 -0
- package/components/common/RichText/plugins/style/parser.js +175 -0
- package/components/common/RichText/plugins/template/README.md +2 -0
- package/components/common/RichText/plugins/template/build.js +65 -0
- package/components/common/RichText/plugins/template/index.js +67 -0
- package/components/common/RichText/plugins/txv-video/README.md +18 -0
- package/components/common/RichText/plugins/txv-video/build.js +3 -0
- package/components/common/RichText/plugins/txv-video/index.js +46 -0
- package/components/common/RichText/plugins/txv-video/miniprogram/build.js +6 -0
- package/components/common/RichText/plugins/txv-video/uni-app/build.js +3 -0
- package/components/common/RichText/src/miniprogram/index.js +396 -0
- package/components/common/RichText/src/miniprogram/index.json +6 -0
- package/components/common/RichText/src/miniprogram/index.wxml +7 -0
- package/components/common/RichText/src/miniprogram/index.wxss +13 -0
- package/components/common/RichText/src/miniprogram/node/node.js +247 -0
- package/components/common/RichText/src/miniprogram/node/node.json +6 -0
- package/components/common/RichText/src/miniprogram/node/node.wxml +112 -0
- package/components/common/RichText/src/miniprogram/node/node.wxss +164 -0
- package/components/common/RichText/src/miniprogram/parser.js +1269 -0
- package/components/common/RichText/src/uni-app/components/mp-html/mp-html.vue +498 -0
- package/components/common/RichText/src/uni-app/components/mp-html/node/node.vue +585 -0
- package/components/common/RichText/src/uni-app/components/mp-html/parser.js +1393 -0
- package/components/common/RichText/src/uni-app/static/app-plus/mp-html/js/handler.js +254 -0
- package/components/common/RichText/src/uni-app/static/app-plus/mp-html/js/uni.webview.min.js +1 -0
- package/components/common/RichText/src/uni-app/static/app-plus/mp-html/local.html +33 -0
- package/components/common/RichText/tools/config.js +82 -0
- package/components/common/RichText/tools/converter.js +205 -0
- package/components/common/RichText/tools/ifdef.js +115 -0
- package/components/common/RichText/tools/minifier.js +40 -0
- package/components/common/RichText/tools/plugin.js +248 -0
- package/components/common/Toast/index-web.ts +122 -0
- package/components/common/Toast/index-web.vue +178 -0
- package/components/common/Toast/type.ts +8 -0
- package/components/common/common.scss +59 -0
- package/components/customer-icon.vue +56 -0
- package/components/message-branch.vue +120 -0
- package/components/message-customer-service.vue +114 -0
- package/components/message-form/form-branch.vue +68 -0
- package/components/message-form/form-input.vue +242 -0
- package/components/message-form/index.vue +80 -0
- package/components/message-multi-branch/branch-pc.vue +79 -0
- package/components/message-multi-branch/index.vue +60 -0
- package/components/message-multi-form/component-mobile/form-popup.vue +37 -0
- package/components/message-multi-form/component-mobile/input-mobile.vue +102 -0
- package/components/message-multi-form/component-mobile/label-mobile.vue +32 -0
- package/components/message-multi-form/component-mobile/radios-mobile.vue +161 -0
- package/components/message-multi-form/component-pc/input-pc.vue +93 -0
- package/components/message-multi-form/component-pc/label-pc.vue +33 -0
- package/components/message-multi-form/component-pc/radio-pc.vue +98 -0
- package/components/message-multi-form/form-mobile.vue +385 -0
- package/components/message-multi-form/form-pc.vue +184 -0
- package/components/message-multi-form/index.vue +61 -0
- package/components/message-product-card.vue +129 -0
- package/components/message-rating/index.vue +56 -0
- package/components/message-rating/message-rating-number.vue +247 -0
- package/components/message-rating/message-rating-star.vue +237 -0
- package/components/message-rich-text.vue +155 -0
- package/components/message-robot-welcome.vue +181 -0
- package/components/message-stream.vue +109 -0
- package/constant.ts +122 -0
- package/excluded-list.txt +6 -0
- package/index.ts +30 -0
- package/index.vue +60 -0
- package/interface.ts +176 -0
- package/logger/index.ts +12 -0
- package/logger/main.ts +120 -0
- package/package.json +62 -0
- package/script/fileCopy.js +60 -0
- package/script/syncVersion.js +35 -0
- package/server.ts +128 -0
- package/styles/common.scss +116 -0
- package/tsconfig.json +34 -0
- package/typings.d.ts +20 -0
- package/utils/chatStorage.ts +70 -0
- package/utils/copy-web.ts +141 -0
- package/utils/enableSampleTaskStatus.ts +8 -0
- package/utils/env.ts +15 -0
- package/utils/index.ts +59 -0
- package/utils/utils.ts +162 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview 自动构建程序
|
|
3
|
+
* @author Jin Yufeng
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// 载入 gulp 插件
|
|
7
|
+
const gulp = require('gulp')
|
|
8
|
+
const htmlmin = require('gulp-htmlmin')
|
|
9
|
+
const babel = require('gulp-babel')
|
|
10
|
+
const uglify = require('gulp-uglify')
|
|
11
|
+
const cleanCss = require('gulp-clean-css')
|
|
12
|
+
const clean = require('gulp-clean')
|
|
13
|
+
const gulpif = require('gulp-if')
|
|
14
|
+
const plumber = require('gulp-plumber')
|
|
15
|
+
const size = require('gulp-size')
|
|
16
|
+
|
|
17
|
+
// 载入构建工具
|
|
18
|
+
const config = require('./tools/config')
|
|
19
|
+
const converter = require('./tools/converter')
|
|
20
|
+
const ifdef = require('./tools/ifdef')
|
|
21
|
+
const minifier = require('./tools/minifier')
|
|
22
|
+
const plugin = require('./tools/plugin')
|
|
23
|
+
|
|
24
|
+
// 载入环境信息
|
|
25
|
+
const isDev = process.argv.includes('--dev')
|
|
26
|
+
let platform = process.argv[3]
|
|
27
|
+
if (!platform) {
|
|
28
|
+
throw Error('缺少平台信息')
|
|
29
|
+
}
|
|
30
|
+
platform = platform.substr(2)
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @description 清理文件夹
|
|
34
|
+
*/
|
|
35
|
+
gulp.task('clean', () => {
|
|
36
|
+
return gulp.src(`${isDev ? 'dev' : 'dist'}/${platform === 'all' ? '' : platform + '/'}*`, {
|
|
37
|
+
read: false,
|
|
38
|
+
allowEmpty: true
|
|
39
|
+
})
|
|
40
|
+
.pipe(clean())
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @description 生成原生组件包(含插件)
|
|
45
|
+
* @returns {NodeJS.ReadWriteStream}
|
|
46
|
+
*/
|
|
47
|
+
function packComp () {
|
|
48
|
+
return gulp.src(['plugins/**/*', 'src/**/*'], {
|
|
49
|
+
nodir: true
|
|
50
|
+
})
|
|
51
|
+
// 公共处理
|
|
52
|
+
.pipe(plumber()) // 错误处理
|
|
53
|
+
.pipe(plugin.build(platform)) // 构建插件
|
|
54
|
+
.pipe(ifdef(platform)) // 条件编译
|
|
55
|
+
// wxml 处理
|
|
56
|
+
.pipe(gulpif(file => file.extname === '.wxml', minifier.wxs())) // 压缩内联 wxs
|
|
57
|
+
.pipe(gulpif(file => file.extname === '.wxml', htmlmin(config.htmlmin))) // 压缩 wxml
|
|
58
|
+
.pipe(gulpif(file => file.extname === '.html', htmlmin(Object.assign({}, config.htmlmin, { // 压缩 html
|
|
59
|
+
minifyCSS: true
|
|
60
|
+
}))))
|
|
61
|
+
// js 处理
|
|
62
|
+
.pipe(gulpif(file => file.extname === '.js' && !file.stem.includes('.min') && (platform !== 'uni-app' || file.relative.includes('static')), babel(config.babel))) // es6 转 es5
|
|
63
|
+
.pipe(gulpif(file => file.extname === '.js' && !file.stem.includes('.min') && !isDev && (platform !== 'uni-app' || file.relative.includes('static')), uglify(config.uglify))) // 压缩 js
|
|
64
|
+
// wxss(css)处理
|
|
65
|
+
.pipe(gulpif(file => file.extname.includes('ss'), cleanCss(config.cleanCss))) // 压缩 wxss
|
|
66
|
+
.pipe(plugin.importCss()) // 引入插件中的 css 文件
|
|
67
|
+
// json 处理
|
|
68
|
+
.pipe(gulpif(file => file.extname === '.json', minifier.json())) // 压缩 json
|
|
69
|
+
// 公共处理
|
|
70
|
+
.pipe(converter(platform)) // 将微信端的代码转换到各个平台
|
|
71
|
+
.pipe(gulpif(!isDev, size({
|
|
72
|
+
title: `${platform} 包生成完毕`
|
|
73
|
+
})))
|
|
74
|
+
.pipe(gulp.dest(file => {
|
|
75
|
+
return `${isDev ? 'dev' : 'dist'}/${platform}/${(platform === 'uni-app' && !file.relative.includes('components') && !file.relative.includes('static')) || (platform !== 'uni-app' && isDev) ? 'components/mp-html/' : ''}`
|
|
76
|
+
}))
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
gulp.task('build', gulp.series('clean', packComp))
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @description 生成原生示例项目
|
|
83
|
+
* @returns {NodeJS.ReadWriteStream}
|
|
84
|
+
*/
|
|
85
|
+
function packDemo () {
|
|
86
|
+
return gulp.src(['tools/demo/**/*', 'test/content.js'], {
|
|
87
|
+
nodir: true
|
|
88
|
+
})
|
|
89
|
+
.pipe(ifdef(platform))
|
|
90
|
+
.pipe(gulpif(platform !== 'uni-app', converter(platform)))
|
|
91
|
+
.pipe(gulp.dest(`dev/${platform}/`))
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
gulp.task('dev', gulp.series('clean', gulp.parallel(packComp, packDemo)))
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @description 监听文件变化
|
|
98
|
+
*/
|
|
99
|
+
gulp.task('watch-demo', () => {
|
|
100
|
+
gulp.watch(['tools/demo/**/*', 'test/content.js']).on('all', (type, file) => {
|
|
101
|
+
console.log(type + ':' + file)
|
|
102
|
+
packDemo()
|
|
103
|
+
})
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
gulp.task('watch-comp', () => {
|
|
107
|
+
gulp.watch(['src/**/*', 'src/common/**/*', 'plugins/**/*']).on('all', (type, file) => {
|
|
108
|
+
console.log(type + ':' + file)
|
|
109
|
+
packComp()
|
|
110
|
+
})
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
gulp.task('watch', gulp.parallel('watch-demo', 'watch-comp'))
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const glob = require('glob')
|
|
3
|
+
const standard = require('standard')
|
|
4
|
+
|
|
5
|
+
// 解析参数
|
|
6
|
+
let fix = false
|
|
7
|
+
let mode = '**/*.@(js|vue)'
|
|
8
|
+
for (let i = 2; i < process.argv.length; i++) {
|
|
9
|
+
if (process.argv[i] === '--fix') {
|
|
10
|
+
fix = true
|
|
11
|
+
} else {
|
|
12
|
+
mode = process.argv[i]
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// 检查 js 文件
|
|
17
|
+
function lintJs (filePath, content) {
|
|
18
|
+
const res = standard.lintTextSync(content, {
|
|
19
|
+
global: ['App', 'Page', 'Component', 'wx', 'requirePlugin', 'uni', 'test', 'expect', 'plus', 'Image'],
|
|
20
|
+
fix
|
|
21
|
+
}).results
|
|
22
|
+
// 写回修复的内容
|
|
23
|
+
if (fix && res[0].output) {
|
|
24
|
+
fs.writeFileSync(filePath, res[0].output)
|
|
25
|
+
}
|
|
26
|
+
// 打印错误信息
|
|
27
|
+
for (let i = 0; i < res[0].messages.length; i++) {
|
|
28
|
+
const item = res[0].messages[i]
|
|
29
|
+
console.log(filePath + ':' + item.line + ':' + item.column + ': ' + item.message)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// 检查 vue 文件
|
|
34
|
+
function lintVue (filePath, content) {
|
|
35
|
+
// 提取 script 部分
|
|
36
|
+
const script = content.match(/<script>([\s\S]+?)<\/script>/)
|
|
37
|
+
const line = content.substr(0, script.index).split('\n').length - 1
|
|
38
|
+
const res = standard.lintTextSync(script[1], {
|
|
39
|
+
global: ['uni', 'plus', 'weex'],
|
|
40
|
+
fix
|
|
41
|
+
}).results
|
|
42
|
+
// 写回修复的内容
|
|
43
|
+
if (fix && res[0].output) {
|
|
44
|
+
fs.writeFileSync(filePath, content.replace(/<script>[\s\S]+?<\/script>/, '<script>' + res[0].output + '</script>'))
|
|
45
|
+
}
|
|
46
|
+
// 打印错误信息
|
|
47
|
+
for (let i = 0; i < res[0].messages.length; i++) {
|
|
48
|
+
const item = res[0].messages[i]
|
|
49
|
+
console.log(filePath + ':' + (line + item.line) + ':' + item.column + ': ' + item.message)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
glob(mode, {
|
|
54
|
+
ignore: ['node_modules/**', 'coverage/**', 'dist/**', 'dev/**', '**/*.min.js']
|
|
55
|
+
}, (_, files) => {
|
|
56
|
+
for (let i = 0; i < files.length; i++) {
|
|
57
|
+
if (files[i].includes('.js')) {
|
|
58
|
+
lintJs(files[i], fs.readFileSync(files[i], 'utf-8'))
|
|
59
|
+
} else if (files[i].includes('.vue')) {
|
|
60
|
+
lintVue(files[i], fs.readFileSync(files[i], 'utf-8'))
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
})
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mp-html",
|
|
3
|
+
"version": "2.5.0",
|
|
4
|
+
"description": "小程序富文本组件",
|
|
5
|
+
"miniprogram": "dist/mp-weixin",
|
|
6
|
+
"repository": "https://github.com/jin-yufeng/mp-html",
|
|
7
|
+
"author": "Jin Yufeng",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"keywords": [
|
|
10
|
+
"miniprogram",
|
|
11
|
+
"rich-text",
|
|
12
|
+
"html"
|
|
13
|
+
],
|
|
14
|
+
"standard": {
|
|
15
|
+
"globals": ["App", "Page", "Component", "wx", "requirePlugin", "uni", "plus", "weex"],
|
|
16
|
+
"envs": ["jest", "browser"]
|
|
17
|
+
},
|
|
18
|
+
"jest": {
|
|
19
|
+
"testEnvironment": "jsdom",
|
|
20
|
+
"collectCoverageFrom": [
|
|
21
|
+
"dev/mp-weixin/components/mp-html/**/*.js"
|
|
22
|
+
]
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"lint": "node lint.js",
|
|
26
|
+
"lintcss": "npx stylelint src/**/*.wxss",
|
|
27
|
+
"build:weixin": "gulp build --mp-weixin",
|
|
28
|
+
"build:qq": "gulp build --mp-qq",
|
|
29
|
+
"build:baidu": "gulp build --mp-baidu",
|
|
30
|
+
"build:alipay": "gulp build --mp-alipay",
|
|
31
|
+
"build:toutiao": "gulp build --mp-toutiao",
|
|
32
|
+
"build:uni-app": "gulp build --uni-app",
|
|
33
|
+
"build": "gulp build --mp-weixin & gulp build --mp-qq & gulp build --mp-baidu & gulp build --mp-alipay & gulp build --mp-toutiao & gulp build --uni-app",
|
|
34
|
+
"watch:weixin": "gulp watch --mp-weixin --dev",
|
|
35
|
+
"watch:qq": "gulp watch --mp-qq --dev",
|
|
36
|
+
"watch:baidu": "gulp watch --mp-baidu --dev",
|
|
37
|
+
"watch:alipay": "gulp watch --mp-alipay --dev",
|
|
38
|
+
"watch:toutiao": "gulp watch --mp-toutiao --dev",
|
|
39
|
+
"watch:uni-app": "gulp watch --uni-app --dev",
|
|
40
|
+
"dev:weixin": "gulp dev --mp-weixin --dev",
|
|
41
|
+
"dev:qq": "gulp dev --mp-qq --dev",
|
|
42
|
+
"dev:baidu": "gulp dev --mp-baidu --dev",
|
|
43
|
+
"dev:alipay": "gulp dev --mp-alipay --dev",
|
|
44
|
+
"dev:toutiao": "gulp dev --mp-toutiao --dev",
|
|
45
|
+
"dev:uni-app": "gulp dev --uni-app --dev",
|
|
46
|
+
"test": "gulp dev --mp-weixin --dev && npx jest",
|
|
47
|
+
"coverage": "gulp dev --mp-weixin --dev && npx jest --coverage",
|
|
48
|
+
"coveralls": "npx coveralls < coverage/lcov.info",
|
|
49
|
+
"clean": "gulp clean --all",
|
|
50
|
+
"clean:dev": "gulp clean --all --dev"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@babel/preset-env": "^7.12.1",
|
|
54
|
+
"coveralls": "^3.1.0",
|
|
55
|
+
"gulp": "^4.0.0",
|
|
56
|
+
"gulp-babel": "^8.0.0",
|
|
57
|
+
"gulp-clean": "^0.4.0",
|
|
58
|
+
"gulp-clean-css": "^4.3.0",
|
|
59
|
+
"gulp-htmlmin": "^5.0.1",
|
|
60
|
+
"gulp-if": "^3.0.0",
|
|
61
|
+
"gulp-plumber": "^1.2.1",
|
|
62
|
+
"gulp-size": "^3.0.0",
|
|
63
|
+
"gulp-uglify": "^2.1.2",
|
|
64
|
+
"jest": "^26.6.1",
|
|
65
|
+
"miniprogram-simulate": "^1.2.7",
|
|
66
|
+
"standard": "^16.0.3",
|
|
67
|
+
"stylelint": "^13.7.2",
|
|
68
|
+
"stylelint-config-recess-order": "^2.3.0",
|
|
69
|
+
"stylelint-config-standard": "^20.0.0",
|
|
70
|
+
"through2": "^4.0.2",
|
|
71
|
+
"uglify-js": "^2.8.29"
|
|
72
|
+
},
|
|
73
|
+
"dependencies": {}
|
|
74
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# audio
|
|
2
|
+
功能:音乐播放器
|
|
3
|
+
大小:*≈4KB*
|
|
4
|
+
支持平台:
|
|
5
|
+
|
|
6
|
+
| 微信小程序 | QQ 小程序 | 百度小程序 | 支付宝小程序 | 头条小程序 | uni-app |
|
|
7
|
+
|:---:|:---:|:---:|:---:|:---:|:---:|
|
|
8
|
+
| √ | √ | √ | √ | √ | √(nvue 不支持) |
|
|
9
|
+
|
|
10
|
+
百度小程序原生包在此 [问题](https://smartprogram.baidu.com/forum/topic/show/125787) 未解决前无法使用
|
|
11
|
+
|
|
12
|
+
说明:
|
|
13
|
+
在大多数小程序平台,*audio* 标签已被废弃或无法使用,本插件可以代替 *audio* 标签播放音乐,并实现以下优化:
|
|
14
|
+
1. *pause-video* 属性也可以应用于音频,即播放一个音视频时可以自动暂停其他正在播放的音视频
|
|
15
|
+
2. 增加了一个可以拖动的进度条
|
|
16
|
+
3. 组件大小可以根据页面宽度自动调整
|
|
17
|
+
4. 支持 *autoplay* 属性
|
|
18
|
+
5. 播放被后台打断时,页面显示后自动继续播放
|
|
19
|
+
|
|
20
|
+
基础库要求:
|
|
21
|
+
支付宝 *1.23.4+* ,其余平台满足最低要求即可
|
|
22
|
+
第 *5* 条仅微信 *2.2.3+* 、*QQ*、百度支持
|
|
23
|
+
|
|
24
|
+
?> 如果希望页面上使用本组件,组件的路径为 *path/to/mp-html/audio/audio*
|
|
25
|
+
属性和事件基本同 *audio* 组件,组件实例上提供了 *setSrc*、*play*、*seek*、*pause*、*stop* 方法可供控制播放状态
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
usingComponents: {
|
|
3
|
+
'my-audio': '../audio/audio'
|
|
4
|
+
},
|
|
5
|
+
handler (file) {
|
|
6
|
+
// 删去原来的 audio 标签
|
|
7
|
+
if (file.basename === 'node.wxml' || file.basename === 'node.vue') {
|
|
8
|
+
file.contents = Buffer.from(file.contents.toString().replace(/<audio[\s\S]+?>/, ''))
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview audio 插件
|
|
3
|
+
*/
|
|
4
|
+
const context = require('./context')
|
|
5
|
+
let index = 0
|
|
6
|
+
|
|
7
|
+
function Audio (vm) {
|
|
8
|
+
this.vm = vm
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
Audio.prototype.onUpdate = function () {
|
|
12
|
+
this.audios = []
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
Audio.prototype.onParse = function (node) {
|
|
16
|
+
if (node.name === 'audio') {
|
|
17
|
+
if (!node.attrs.id) {
|
|
18
|
+
node.attrs.id = 'a' + index++
|
|
19
|
+
}
|
|
20
|
+
this.audios.push(node.attrs.id)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
Audio.prototype.onLoad = function () {
|
|
25
|
+
setTimeout(() => {
|
|
26
|
+
for (let i = 0; i < this.audios.length; i++) {
|
|
27
|
+
const ctx = context.get(this.audios[i])
|
|
28
|
+
ctx.id = this.audios[i]
|
|
29
|
+
this.vm._videos.push(ctx)
|
|
30
|
+
}
|
|
31
|
+
}, 500)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
module.exports = Audio
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview audio 组件
|
|
3
|
+
*/
|
|
4
|
+
const context = require('./context')
|
|
5
|
+
|
|
6
|
+
Component({
|
|
7
|
+
data: {
|
|
8
|
+
time: '00:00'
|
|
9
|
+
},
|
|
10
|
+
properties: {
|
|
11
|
+
name: String, // 音乐名
|
|
12
|
+
author: String, // 作者
|
|
13
|
+
poster: String, // 海报图片地址
|
|
14
|
+
autoplay: Boolean, // 是否自动播放
|
|
15
|
+
controls: Boolean, // 是否显示控件
|
|
16
|
+
loop: Boolean, // 是否循环播放
|
|
17
|
+
src: { // 源地址
|
|
18
|
+
type: String,
|
|
19
|
+
observer (src) {
|
|
20
|
+
this.setSrc(src)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
created () {
|
|
25
|
+
// 创建内部 context
|
|
26
|
+
this._ctx = wx.createInnerAudioContext()
|
|
27
|
+
this._ctx.onError(err => {
|
|
28
|
+
this.setData({
|
|
29
|
+
error: true
|
|
30
|
+
})
|
|
31
|
+
this.triggerEvent('error', err)
|
|
32
|
+
})
|
|
33
|
+
this._ctx.onTimeUpdate(() => {
|
|
34
|
+
const time = this._ctx.currentTime
|
|
35
|
+
const min = parseInt(time / 60)
|
|
36
|
+
const sec = Math.ceil(time % 60)
|
|
37
|
+
const data = {}
|
|
38
|
+
data.time = (min > 9 ? min : '0' + min) + ':' + (sec > 9 ? sec : '0' + sec)
|
|
39
|
+
// 不在拖动状态下需要更新进度条
|
|
40
|
+
if (!this.lastTime) {
|
|
41
|
+
data.value = time / this._ctx.duration * 100
|
|
42
|
+
}
|
|
43
|
+
this.setData(data)
|
|
44
|
+
})
|
|
45
|
+
this._ctx.onEnded(() => {
|
|
46
|
+
if (!this.properties.loop) {
|
|
47
|
+
this.setData({
|
|
48
|
+
playing: false
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
// #ifndef ALIPAY
|
|
53
|
+
},
|
|
54
|
+
attached () {
|
|
55
|
+
context.set(this.id, this)
|
|
56
|
+
// #endif
|
|
57
|
+
// #ifdef MP-ALIPAY
|
|
58
|
+
context.set(this.properties.id, this)
|
|
59
|
+
this.setSrc(this.properties.src)
|
|
60
|
+
// #endif
|
|
61
|
+
},
|
|
62
|
+
// #ifdef MP-ALIPAY
|
|
63
|
+
didUpdate (e) {
|
|
64
|
+
if (e.src !== this.properties.src) {
|
|
65
|
+
this.setSrc(this.properties.src)
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
// #endif
|
|
69
|
+
detached () {
|
|
70
|
+
this._ctx.destroy()
|
|
71
|
+
// #ifndef MP-ALIPAY
|
|
72
|
+
context.remove(this.id)
|
|
73
|
+
// #endif
|
|
74
|
+
// #ifdef MP_ALIPAY
|
|
75
|
+
context.remove(this.properties.id)
|
|
76
|
+
// #endif
|
|
77
|
+
},
|
|
78
|
+
// #ifndef ALIPAY | TOUTIAO
|
|
79
|
+
pageLifetimes: {
|
|
80
|
+
show () {
|
|
81
|
+
// 播放被后台打断时,页面显示后自动继续播放
|
|
82
|
+
if (this.data.playing && this._ctx.paused) {
|
|
83
|
+
this._ctx.play()
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
// #endif
|
|
88
|
+
methods: {
|
|
89
|
+
/**
|
|
90
|
+
* @description 设置源
|
|
91
|
+
* @param {string} src 源地址
|
|
92
|
+
*/
|
|
93
|
+
setSrc (src) {
|
|
94
|
+
this._ctx.autoplay = this.properties.autoplay
|
|
95
|
+
this._ctx.loop = this.properties.loop
|
|
96
|
+
this._ctx.src = src
|
|
97
|
+
if (this.properties.autoplay && !this.data.playing) {
|
|
98
|
+
this.setData({
|
|
99
|
+
playing: true
|
|
100
|
+
})
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* @description 播放音乐
|
|
106
|
+
*/
|
|
107
|
+
play () {
|
|
108
|
+
this._ctx.play()
|
|
109
|
+
this.setData({
|
|
110
|
+
playing: true
|
|
111
|
+
})
|
|
112
|
+
this.triggerEvent('play'
|
|
113
|
+
// #ifdef MP-ALIPAY
|
|
114
|
+
, {
|
|
115
|
+
target: {
|
|
116
|
+
id: this.props.id
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// #endif
|
|
120
|
+
)
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* @description 暂停音乐
|
|
125
|
+
*/
|
|
126
|
+
pause () {
|
|
127
|
+
this._ctx.pause()
|
|
128
|
+
this.setData({
|
|
129
|
+
playing: false
|
|
130
|
+
})
|
|
131
|
+
this.triggerEvent('pause')
|
|
132
|
+
},
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* @description 设置播放速率
|
|
136
|
+
* @param {Number} rate 播放速率
|
|
137
|
+
*/
|
|
138
|
+
playbackRate (rate) {
|
|
139
|
+
this._ctx.playbackRate = rate
|
|
140
|
+
},
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @description 停止音乐
|
|
144
|
+
*/
|
|
145
|
+
stop () {
|
|
146
|
+
this._ctx.stop()
|
|
147
|
+
this.setData({
|
|
148
|
+
playing: false,
|
|
149
|
+
time: '00:00'
|
|
150
|
+
})
|
|
151
|
+
this.triggerEvent('stop')
|
|
152
|
+
},
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* @description 控制进度
|
|
156
|
+
* @param {number} sec 秒数
|
|
157
|
+
*/
|
|
158
|
+
seek (sec) {
|
|
159
|
+
this._ctx.seek(sec)
|
|
160
|
+
},
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* @description 移动进度条
|
|
164
|
+
* @param {event} e
|
|
165
|
+
* @private
|
|
166
|
+
*/
|
|
167
|
+
_seeking (e) {
|
|
168
|
+
// 避免过于频繁 setData
|
|
169
|
+
if (e.timeStamp - this.lastTime < 200) return
|
|
170
|
+
const time = Math.round(e.detail.value / 100 * this._ctx.duration)
|
|
171
|
+
const min = parseInt(time / 60)
|
|
172
|
+
const sec = time % 60
|
|
173
|
+
this.setData({
|
|
174
|
+
time: (min > 9 ? min : '0' + min) + ':' + (sec > 9 ? sec : '0' + sec)
|
|
175
|
+
})
|
|
176
|
+
this.lastTime = e.timeStamp
|
|
177
|
+
},
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* @description 进度条移动完毕
|
|
181
|
+
* @param {event} e
|
|
182
|
+
* @private
|
|
183
|
+
*/
|
|
184
|
+
_seeked (e) {
|
|
185
|
+
this._ctx.seek(e.detail.value / 100 * this._ctx.duration)
|
|
186
|
+
this.lastTime = undefined
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
})
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<view wx:if="{{controls}}" class="_contain">
|
|
2
|
+
<!-- 海报和按钮 -->
|
|
3
|
+
<view class="_poster" style="background-image:url('{{poster}}')">
|
|
4
|
+
<view class="_button" bindtap="{{playing?'pause':'play'}}">
|
|
5
|
+
<view class="{{playing?'_pause':'_play'}}" />
|
|
6
|
+
</view>
|
|
7
|
+
</view>
|
|
8
|
+
<!-- 曲名和作者 -->
|
|
9
|
+
<view class="_title">
|
|
10
|
+
<view class="_name">{{name||'未知音频'}}</view>
|
|
11
|
+
<view class="_author">{{author||'未知作者'}}</view>
|
|
12
|
+
</view>
|
|
13
|
+
<!-- 进度条 -->
|
|
14
|
+
<slider class="_slider" activeColor="#585959" block-size="12" disabled="{{error}}" value="{{value}}" bindchanging="_seeking" bindchange="_seeked" />
|
|
15
|
+
<!--播放时间-->
|
|
16
|
+
<view class="_time">{{time}}</view>
|
|
17
|
+
</view>
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/* 顶层容器 */
|
|
2
|
+
._contain {
|
|
3
|
+
position: relative;
|
|
4
|
+
display: inline-flex;
|
|
5
|
+
width: 290px;
|
|
6
|
+
background-color: #fcfcfc;
|
|
7
|
+
border: 1px solid #e0e0e0;
|
|
8
|
+
border-radius: 2px;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/* 播放、暂停按钮 */
|
|
12
|
+
._button {
|
|
13
|
+
display: flex;
|
|
14
|
+
align-items: center;
|
|
15
|
+
justify-content: center;
|
|
16
|
+
width: 20px;
|
|
17
|
+
height: 20px;
|
|
18
|
+
overflow: hidden;
|
|
19
|
+
background-color: rgb(0, 0, 0, 0.2);
|
|
20
|
+
border: 1px solid white;
|
|
21
|
+
border-radius: 50%;
|
|
22
|
+
opacity: 0.9;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
._play {
|
|
26
|
+
margin-left: 2px;
|
|
27
|
+
border-top: 4px solid transparent;
|
|
28
|
+
border-bottom: 4px solid transparent;
|
|
29
|
+
border-left: 8px solid white;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
._pause {
|
|
33
|
+
width: 8px;
|
|
34
|
+
height: 8px;
|
|
35
|
+
background-color: white;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/* 海报 */
|
|
39
|
+
._poster {
|
|
40
|
+
display: flex;
|
|
41
|
+
align-items: center;
|
|
42
|
+
justify-content: center;
|
|
43
|
+
width: 70px;
|
|
44
|
+
height: 70px;
|
|
45
|
+
background-color: #e6e6e6;
|
|
46
|
+
background-size: contain;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/* 标题栏 */
|
|
50
|
+
._title {
|
|
51
|
+
flex: 1;
|
|
52
|
+
margin: 4px 0 0 14px;
|
|
53
|
+
text-align: left;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
._author {
|
|
57
|
+
width: 45px;
|
|
58
|
+
font-size: 12px;
|
|
59
|
+
color: #888;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
._name {
|
|
63
|
+
width: 140px;
|
|
64
|
+
font-size: 15px;
|
|
65
|
+
line-height: 39px;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
._author,
|
|
69
|
+
._name {
|
|
70
|
+
overflow: hidden;
|
|
71
|
+
text-overflow: ellipsis;
|
|
72
|
+
white-space: nowrap;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/* 进度条 */
|
|
76
|
+
._slider {
|
|
77
|
+
position: absolute;
|
|
78
|
+
right: 16px;
|
|
79
|
+
bottom: 8px;
|
|
80
|
+
width: 140px;
|
|
81
|
+
margin: 0;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/* 播放时间 */
|
|
85
|
+
._time {
|
|
86
|
+
margin: 7px 14px 0 0;
|
|
87
|
+
font-size: 12px;
|
|
88
|
+
color: #888;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/* 响应式布局,大屏幕用更大的尺寸 */
|
|
92
|
+
@media (min-width: 400px) {
|
|
93
|
+
._contain {
|
|
94
|
+
width: 380px;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
._button {
|
|
98
|
+
width: 26px;
|
|
99
|
+
height: 26px;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
._poster {
|
|
103
|
+
width: 90px;
|
|
104
|
+
height: 90px;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
._author {
|
|
108
|
+
width: 60px;
|
|
109
|
+
font-size: 15px;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
._name {
|
|
113
|
+
width: 180px;
|
|
114
|
+
font-size: 19px;
|
|
115
|
+
line-height: 55px;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
._slider {
|
|
119
|
+
right: 20px;
|
|
120
|
+
bottom: 10px;
|
|
121
|
+
width: 180px;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
._time {
|
|
125
|
+
font-size: 15px;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
template: '<my-audio wx:if="{{n.name==\'audio\'}}" id="{{n.attrs.id}}" class="{{n.attrs.class}}" style="{{n.attrs.style}}" author="{{n.attrs.author}}" controls="{{n.attrs.controls}}" autoplay="{{n.attrs.autoplay}}" loop="{{n.attrs.loop}}" name="{{n.attrs.name}}" poster="{{n.attrs.poster}}" src="{{n.src[ctrl[i]||0]}}" data-i="{{i}}" data-source="audio" bindplay="play" binderror="mediaError" />'
|
|
3
|
+
}
|