diff --git a/api/form/index.ts b/api/form/index.ts new file mode 100644 index 0000000..6ee1e23 --- /dev/null +++ b/api/form/index.ts @@ -0,0 +1,19 @@ +import { Request } from '../../utils/request' + +export const GetCheckoutRoomNum = (roomNum: string) => Request({ + url: `/room/checkout?roomNum=${roomNum}`, + method: 'get' +}) +export const PostAnonLogin = (data: any) => Request({ + url: `/auth/anon-login`, + method: 'post', + data, +}) +export const GetAgoraConf = () => Request({ + url: `/home/agora-conf`, + method: 'get', +}) +export const GetRoomRtcToken = (roomNum: string) => Request({ + url: `/room/tk/rtc?roomNum=${roomNum}`, + method: 'get', +}) diff --git a/api/meeting/index.ts b/api/meeting/index.ts new file mode 100644 index 0000000..de1b195 --- /dev/null +++ b/api/meeting/index.ts @@ -0,0 +1,50 @@ +import { Request } from '../../utils/request' + +export const GetRoomUser = (roomNum: string) => Request({ + url: `/room/user?roomNum=${roomNum}`, + method: 'get' +}) + +export const GetShowUser = (roomNum: string) => Request({ + url: `/room/show-user?roomNum=${roomNum}`, + method: 'get' +}) + +export const GetApplySpeak = (roomNum: string) => Request({ + url: `/room/apply-speak?roomNum=${roomNum}`, + method: 'get' +}) + +export const PostMuteAll = (data: any) => { + return Request({ + url: `/room/mute-all?roomNum=${data.roomNum}&enableMicr=${data.enableMicr}`, + method: 'get', + }) +} + +export const PostOpenMicr = (data: any) => { + return Request({ + url: `/room/oper-micr?roomNum=${data.roomNum}&enableMicr=${data.enableMicr}&uid=${data.uid}`, + method: 'get', + }) +} + +export const PostOpenCamera = (data: any) => + Request({ + url: `/room/oper-camera`, + method: 'get', + data + }) + +export const DeleteRoomManager = (data: any) => + Request({ + url: `/room/manager`, + method: 'delete', + data + }) + +export const GetRoomInfo = (roomNum: string) => + Request({ + url: `/room/${roomNum}`, + method: 'get', + }) diff --git a/app.js b/app.js index 2c70df4..2aff100 100644 --- a/app.js +++ b/app.js @@ -1,10 +1,5 @@ -import gulpError from './utils/gulpError'; App({ - onShow() { - if (gulpError !== 'gulpErrorPlaceHolder') { - wx.redirectTo({ - url: `/pages/gulp-error/index?gulpError=${gulpError}`, - }); - } - }, + onShow() { + + } }); diff --git a/app.json b/app.json index 05c393c..50a56d4 100644 --- a/app.json +++ b/app.json @@ -1,113 +1,24 @@ { "pages": [ - "pages/home/home", - "pages/button/button", - "pages/tabs/tabs", - "pages/icon/icon", - "pages/loading/loading", - "pages/progress/progress", - "pages/cascader/cascader", - "pages/cell/cell", - "pages/cell-group/cell-group", - "pages/collapse/collapse", - "pages/input/input", - "pages/badge/badge", - "pages/textarea/textarea", - "pages/message/message", - "pages/toast/toast", - "pages/stepper/stepper", - "pages/slider/slider", - "pages/radio/radio", - "pages/switch/switch", - "pages/sticky/sticky", - "pages/tag/tag", - "pages/checkbox/checkbox", - "pages/gulp-error/index", - "pages/fab/fab", - "pages/tab-bar/tab-bar", - "pages/transition/transition", - "pages/popup/popup", - "pages/steps/steps", - "pages/dropdown-menu/dropdown-menu", - "pages/drawer/drawer", - "pages/pull-down-refresh/pull-down-refresh", - "pages/skeleton/skeleton", - "pages/footer/footer", - "pages/divider/divider", - "pages/empty/empty", - "pages/back-top/back-top", - "pages/grid/grid", - "pages/upload/upload", - "pages/count-down/count-down", - "pages/overlay/overlay", - "pages/image/image", - "pages/search/search", - "pages/home/navigateFail/navigateFail", - "pages/navbar/navbar", - "pages/date-time-picker/date-time-picker", - "pages/notice-bar/notice-bar", - "pages/image-viewer/image-viewer", - "pages/result/result", - "pages/result/result-page", - "pages/link/link" - ], - "subpackages": [ - { - "root": "pages/side-bar/", - "pages": ["side-bar", "base/index", "switch/index", "custom/index", "with-icon/index"] - }, - { - "root": "pages/action-sheet/", - "pages": ["action-sheet"] - }, - { - "root": "pages/avatar/", - "pages": ["avatar"] - }, - { - "root": "pages/calendar/", - "pages": ["calendar"] - }, - { - "root": "pages/dialog/", - "pages": ["dialog"] - }, - { - "root": "pages/picker/", - "pages": ["picker"] - }, - { - "root": "pages/rate/", - "pages": ["rate"] - }, - { - "root": "pages/swiper/", - "pages": ["swiper"] - }, - { - "root": "pages/swipe-cell/", - "pages": ["swipe-cell"] - }, - { - "root": "pages/tree-select/", - "pages": ["tree-select"] - }, - { - "root": "pages/indexes/", - "pages": ["indexes", "base/index", "custom/index"] - } + "pages/form/index", + "pages/meeting/index" ], + "subpackages": [], "usingComponents": { - "t-demo": "./components/demo-block/index", + "status-bar-height": "components/status-bar-height/index", + "header-tab": "components/header-tab/index", + "t-input": "tdesign-miniprogram/input/input", "t-button": "tdesign-miniprogram/button/button", - "t-icon": "tdesign-miniprogram/icon/icon" + "t-icon": "tdesign-miniprogram/icon/icon", + "t-avatar": "tdesign-miniprogram/avatar/avatar", + "t-message": "tdesign-miniprogram/message/message", + "t-dialog": "tdesign-miniprogram/dialog/dialog", + "t-popup": "tdesign-miniprogram/popup/popup" }, + "entryPagePath": "pages/form/index", "window": { - "backgroundTextStyle": "light", - "navigationBarBackgroundColor": "#f6f6f6", - "backgroundColor": "#f6f6f6", - "navigationBarTitleText": "TDesign", + "navigationStyle": "custom", "navigationBarTextStyle": "black" }, "sitemapLocation": "sitemap.json" -} +} \ No newline at end of file diff --git a/app.wxss b/app.wxss index c397851..382ef28 100644 --- a/app.wxss +++ b/app.wxss @@ -1,19 +1,10 @@ +image { + display: block; +} + page { - background: #f6f6f6; -} -.demo { - padding-bottom: 56rpx; -} -.demo-title { - font-size: 48rpx; - font-weight: 700; - line-height: 64rpx; - margin: 48rpx 32rpx 0; - color: var(--td-font-gray-1, rgba(0, 0, 0, 0.9)); -} -.demo-desc { - font-size: 28rpx; - color: var(--td-font-gray-2, rgba(0, 0, 0, 0.6)); - margin: 16rpx 32rpx 0; - line-height: 44rpx; -} + --td-button-primary-color: white; + --td-button-primary-bg-color: #5575F2; + --td-button-primary-border-color: #5575F2; + --td-switch-checked-color: #5575F2; +} \ No newline at end of file diff --git a/assets/TDesignLogo@2x.png b/assets/TDesignLogo@2x.png deleted file mode 100644 index ab44a89..0000000 Binary files a/assets/TDesignLogo@2x.png and /dev/null differ diff --git a/assets/icon1-active.png b/assets/icon1-active.png new file mode 100644 index 0000000..2451b91 Binary files /dev/null and b/assets/icon1-active.png differ diff --git a/assets/icon1.png b/assets/icon1.png new file mode 100644 index 0000000..6d08544 Binary files /dev/null and b/assets/icon1.png differ diff --git a/assets/icon2-active.png b/assets/icon2-active.png new file mode 100644 index 0000000..ab92720 Binary files /dev/null and b/assets/icon2-active.png differ diff --git a/assets/icon2.png b/assets/icon2.png new file mode 100644 index 0000000..6240217 Binary files /dev/null and b/assets/icon2.png differ diff --git a/assets/icon3-active.png b/assets/icon3-active.png new file mode 100644 index 0000000..b2357c8 Binary files /dev/null and b/assets/icon3-active.png differ diff --git a/assets/icon3.png b/assets/icon3.png new file mode 100644 index 0000000..46d733b Binary files /dev/null and b/assets/icon3.png differ diff --git a/assets/icon4.png b/assets/icon4.png new file mode 100644 index 0000000..fa7c474 Binary files /dev/null and b/assets/icon4.png differ diff --git a/assets/icon5.png b/assets/icon5.png new file mode 100644 index 0000000..bb70c70 Binary files /dev/null and b/assets/icon5.png differ diff --git a/assets/icon6.png b/assets/icon6.png new file mode 100644 index 0000000..bf25396 Binary files /dev/null and b/assets/icon6.png differ diff --git a/assets/icon7-active.png b/assets/icon7-active.png new file mode 100644 index 0000000..757ee17 Binary files /dev/null and b/assets/icon7-active.png differ diff --git a/assets/icon7.png b/assets/icon7.png new file mode 100644 index 0000000..93cf87e Binary files /dev/null and b/assets/icon7.png differ diff --git a/assets/icon8.png b/assets/icon8.png new file mode 100644 index 0000000..12d0958 Binary files /dev/null and b/assets/icon8.png differ diff --git a/assets/icon9.png b/assets/icon9.png new file mode 100644 index 0000000..81a9878 Binary files /dev/null and b/assets/icon9.png differ diff --git a/components/demo-block/index.d.ts b/components/demo-block/index.d.ts deleted file mode 100644 index 8b13789..0000000 --- a/components/demo-block/index.d.ts +++ /dev/null @@ -1 +0,0 @@ - diff --git a/components/demo-block/index.js b/components/demo-block/index.js deleted file mode 100644 index 007225f..0000000 --- a/components/demo-block/index.js +++ /dev/null @@ -1,27 +0,0 @@ -Component({ - options: { - multipleSlots: true, - addGlobalClass: true, - }, - properties: { - title: { - type: String, - default: '', - }, - desc: { - type: String, - default: '', - }, - operList: Array, - padding: { - type: Boolean, - default: false, - }, - }, - methods: { - clickHandle(e) { - const { type } = e.currentTarget.dataset; - this.triggerEvent('clickoper', type); - }, - }, -}); diff --git a/components/demo-block/index.json b/components/demo-block/index.json deleted file mode 100644 index 467ce29..0000000 --- a/components/demo-block/index.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "component": true -} diff --git a/components/demo-block/index.wxml b/components/demo-block/index.wxml deleted file mode 100644 index ff89daa..0000000 --- a/components/demo-block/index.wxml +++ /dev/null @@ -1,18 +0,0 @@ - - - {{ title }} - {{ desc }} - - - - {{ operItem.title }} - - - {{ btnItem.text }} - - - - - - - diff --git a/components/demo-block/index.wxss b/components/demo-block/index.wxss deleted file mode 100644 index 6553930..0000000 --- a/components/demo-block/index.wxss +++ /dev/null @@ -1,43 +0,0 @@ -.demo-block { - margin: var(--td-spacer-4, 64rpx) 0 0; -} -.demo-block__header { - color: #000; - margin: 0 var(--td-spacer-2, 32rpx); -} -.demo-block__header-title { - font-weight: 700; - font-size: 36rpx; - line-height: 52rpx; -} -.demo-block__header-desc { - margin-top: var(--td-spacer, 16rpx); - font-size: var(--td-font-size-base, 28rpx); - white-space: pre-line; - color: var(--td-font-gray-2, rgba(0, 0, 0, 0.6)); - line-height: 22px; -} -.demo-block__oper { - margin-top: var(--td-spacer, 16rpx); -} -.demo-block__oper-subtitle { - font-size: var(--td-font-size-s, 24rpx); - margin-bottom: var(--td-spacer-2, 32rpx); - opacity: 0.4; -} -.demo-block__oper-btn { - margin: 0 0 var(--td-spacer-2, 32rpx) 0; - height: 96rpx; -} -.demo-block__slot { - margin-top: var(--td-spacer-2, 32rpx); -} -.demo-block__slot.with-padding { - margin: var(--td-spacer-2, 32rpx) var(--td-spacer-2, 32rpx) 0; -} -.demo-block_notitle { - margin-top: 0px; -} -.demo-block_notitle .demo-block_subtitle { - margin-top: var(--td-spacer-3, 48rpx); -} diff --git a/components/header-tab/index.json b/components/header-tab/index.json new file mode 100644 index 0000000..e8cfaaf --- /dev/null +++ b/components/header-tab/index.json @@ -0,0 +1,4 @@ +{ + "component": true, + "usingComponents": {} +} \ No newline at end of file diff --git a/components/header-tab/index.scss b/components/header-tab/index.scss new file mode 100644 index 0000000..8a11a7a --- /dev/null +++ b/components/header-tab/index.scss @@ -0,0 +1,18 @@ +.header-tab { + flex-shrink: 0; + + &-title { + position: relative; + text-align: center; + width: 100%; + padding: 24rpx 0; + + &-back { + position: absolute; + left: 40rpx; + top: 50%; + transform: translate(0, -50%); + } + } + +} \ No newline at end of file diff --git a/components/header-tab/index.ts b/components/header-tab/index.ts new file mode 100644 index 0000000..3fce1fc --- /dev/null +++ b/components/header-tab/index.ts @@ -0,0 +1,43 @@ +Component({ + properties: { + title: { + type: String, + value: '无' + }, + backGround: { + type: String, + value: 'white' + }, + isBack: { + type: Boolean, + value: true + }, + isStatusBarHeight: { + type: Boolean, + value: true + }, + color: { + type: String, + value: 'black' + }, + titleStyle: { + type: String, + }, + iconSize: { + type: String, + value: '48' + }, + }, + data: { + + }, + methods: { + back() { + wx.navigateBack() + }, + }, + ready() { + + + } +}) diff --git a/components/header-tab/index.wxml b/components/header-tab/index.wxml new file mode 100644 index 0000000..cda9fa0 --- /dev/null +++ b/components/header-tab/index.wxml @@ -0,0 +1,7 @@ + + + + {{title}} + + + \ No newline at end of file diff --git a/components/pull-down-list/index.d.ts b/components/pull-down-list/index.d.ts deleted file mode 100644 index 8639a8d..0000000 --- a/components/pull-down-list/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -declare const itemHeight: number; diff --git a/components/pull-down-list/index.js b/components/pull-down-list/index.js deleted file mode 100644 index ef76163..0000000 --- a/components/pull-down-list/index.js +++ /dev/null @@ -1,41 +0,0 @@ -const itemHeight = 56 * 2; -Component({ - data: { - childBoxHeight: 0, - }, - externalClasses: ['t-class'], - properties: { - defaultOpen: { - type: Boolean, - value: false, - }, - name: { - type: String, - value: '', - }, - icon: { - type: String, - value: '', - }, - childArr: { - type: Array, - value: [], - observer(childArr) { - this.setData({ - childBoxHeight: this.data.defaultOpen ? itemHeight * childArr.length : 0, - }); - }, - }, - }, - methods: { - switchHandle() { - const { childArr, childBoxHeight } = this.data; - this.setData({ - childBoxHeight: childBoxHeight > 0 ? 0 : childArr.length * itemHeight, - }); - }, - tapChild(e) { - this.triggerEvent('click', e.target.dataset); - }, - }, -}); diff --git a/components/pull-down-list/index.json b/components/pull-down-list/index.json deleted file mode 100644 index 32640e0..0000000 --- a/components/pull-down-list/index.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "component": true -} \ No newline at end of file diff --git a/components/pull-down-list/index.wxml b/components/pull-down-list/index.wxml deleted file mode 100644 index cf58f3b..0000000 --- a/components/pull-down-list/index.wxml +++ /dev/null @@ -1,12 +0,0 @@ - - - {{ name }} - - - - - {{ item.name }} {{ item.label }} - - - - diff --git a/components/pull-down-list/index.wxss b/components/pull-down-list/index.wxss deleted file mode 100644 index ce6c2f1..0000000 --- a/components/pull-down-list/index.wxss +++ /dev/null @@ -1,49 +0,0 @@ -.pullDownList { - width: 100%; - box-sizing: border-box; - background-color: #fff; - border-radius: 8rpx; - margin-bottom: 24rpx; - overflow: hidden; -} -.pullDownList .switchBox { - height: 120rpx; - display: flex; - justify-content: space-between; - align-items: center; - padding: 0 32rpx; - font-size: 32rpx; - line-height: 48rpx; - color: #333; -} -.pullDownList .name, -.pullDownList .icon { - transition: opacity 0.3s; -} -.pullDownList .name { - opacity: 0.9; -} -.pullDownList.actived .name { - opacity: 0.4; -} -.pullDownList.actived .icon { - opacity: 0.4; -} -.pullDownList .childBox { - transition: height 0.3s; -} -.pullDownList .childBox .child { - box-sizing: border-box; - border-bottom: 1rpx solid #e5e5e5; - height: 112rpx; - display: flex; - justify-content: space-between; - align-items: center; - margin-left: 32rpx; - margin-right: 32rpx; - font-size: 32rpx; - opacity: 0.9; -} -.pullDownList .childBox .child:last-of-type { - border-bottom-color: transparent; -} diff --git a/components/status-bar-height/index.json b/components/status-bar-height/index.json new file mode 100644 index 0000000..e8cfaaf --- /dev/null +++ b/components/status-bar-height/index.json @@ -0,0 +1,4 @@ +{ + "component": true, + "usingComponents": {} +} \ No newline at end of file diff --git a/demos/radio/basic/basic.wxss b/components/status-bar-height/index.scss similarity index 100% rename from demos/radio/basic/basic.wxss rename to components/status-bar-height/index.scss diff --git a/components/status-bar-height/index.ts b/components/status-bar-height/index.ts new file mode 100644 index 0000000..eb3c0b2 --- /dev/null +++ b/components/status-bar-height/index.ts @@ -0,0 +1,16 @@ +Component({ + properties: { + + }, + data: { + height: 0 + }, + methods: { + + }, + ready() { + this.setData({ + height: wx.getWindowInfo().statusBarHeight + }) + } +}) diff --git a/components/status-bar-height/index.wxml b/components/status-bar-height/index.wxml new file mode 100644 index 0000000..d168bae --- /dev/null +++ b/components/status-bar-height/index.wxml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/demos/radio/basic/basic.d.ts b/demos/radio/basic/basic.d.ts deleted file mode 100644 index 8b13789..0000000 --- a/demos/radio/basic/basic.d.ts +++ /dev/null @@ -1 +0,0 @@ - diff --git a/demos/radio/basic/basic.js b/demos/radio/basic/basic.js deleted file mode 100644 index b79c512..0000000 --- a/demos/radio/basic/basic.js +++ /dev/null @@ -1 +0,0 @@ -Component({}); diff --git a/demos/radio/basic/basic.json b/demos/radio/basic/basic.json deleted file mode 100644 index 467ce29..0000000 --- a/demos/radio/basic/basic.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "component": true -} diff --git a/demos/radio/basic/basic.wxml b/demos/radio/basic/basic.wxml deleted file mode 100644 index c1c2a69..0000000 --- a/demos/radio/basic/basic.wxml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/demos/radio/group/group.d.ts b/demos/radio/group/group.d.ts deleted file mode 100644 index 8b13789..0000000 --- a/demos/radio/group/group.d.ts +++ /dev/null @@ -1 +0,0 @@ - diff --git a/demos/radio/group/group.js b/demos/radio/group/group.js deleted file mode 100644 index 074920b..0000000 --- a/demos/radio/group/group.js +++ /dev/null @@ -1,22 +0,0 @@ -Component({ - properties: { - items: { - type: Array, - value: [], - }, - value: { - type: String, - value: '', - }, - }, - data: { - currentValue: '', - }, - methods: { - onChange(event) { - this.setData({ - currentValue: event.detail.name, - }); - }, - }, -}); diff --git a/demos/radio/group/group.json b/demos/radio/group/group.json deleted file mode 100644 index 467ce29..0000000 --- a/demos/radio/group/group.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "component": true -} diff --git a/demos/radio/group/group.wxml b/demos/radio/group/group.wxml deleted file mode 100644 index 8ff56d4..0000000 --- a/demos/radio/group/group.wxml +++ /dev/null @@ -1,12 +0,0 @@ - - - diff --git a/lib/agora-miniapp-sdk.js b/lib/agora-miniapp-sdk.js new file mode 100644 index 0000000..fec3c9f --- /dev/null +++ b/lib/agora-miniapp-sdk.js @@ -0,0 +1,2 @@ +/*! For license information please see agora-miniapp-sdk.js.LICENSE.txt */ +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("AgoraSDK",[],t):"object"==typeof exports?exports.AgoraSDK=t():e.AgoraSDK=t()}(self,(()=>(()=>{var __webpack_modules__={537:e=>{"use strict";e.exports=function(e,t){for(var n=new Array(arguments.length-1),r=0,i=2,o=!0;i{"use strict";var n=t;n.length=function(e){var t=e.length;if(!t)return 0;for(var n=0;--t%4>1&&"="===e.charAt(t);)++n;return Math.ceil(3*e.length)/4-n};for(var r=new Array(64),i=new Array(123),o=0;o<64;)i[r[o]=o<26?o+65:o<52?o+71:o<62?o-4:o-59|43]=o++;n.encode=function(e,t,n){for(var i,o=null,s=[],a=0,c=0;t>2],i=(3&l)<<4,c=1;break;case 1:s[a++]=r[i|l>>4],i=(15&l)<<2,c=2;break;case 2:s[a++]=r[i|l>>6],s[a++]=r[63&l],c=0}a>8191&&((o||(o=[])).push(String.fromCharCode.apply(String,s)),a=0)}return c&&(s[a++]=r[i],s[a++]=61,1===c&&(s[a++]=61)),o?(a&&o.push(String.fromCharCode.apply(String,s.slice(0,a))),o.join("")):String.fromCharCode.apply(String,s.slice(0,a))};var s="invalid encoding";n.decode=function(e,t,n){for(var r,o=n,a=0,c=0;c1)break;if(void 0===(l=i[l]))throw Error(s);switch(a){case 0:r=l,a=1;break;case 1:t[n++]=r<<2|(48&l)>>4,r=l,a=2;break;case 2:t[n++]=(15&r)<<4|(60&l)>>2,r=l,a=3;break;case 3:t[n++]=(3&r)<<6|l,a=0}}if(1===a)throw Error(s);return n-o},n.test=function(e){return/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(e)}},211:e=>{"use strict";function t(){this._listeners={}}e.exports=t,t.prototype.on=function(e,t,n){return(this._listeners[e]||(this._listeners[e]=[])).push({fn:t,ctx:n||this}),this},t.prototype.off=function(e,t){if(void 0===e)this._listeners={};else if(void 0===t)this._listeners[e]=[];else for(var n=this._listeners[e],r=0;r{"use strict";function t(e){return"undefined"!=typeof Float32Array?function(){var t=new Float32Array([-0]),n=new Uint8Array(t.buffer),r=128===n[3];function i(e,r,i){t[0]=e,r[i]=n[0],r[i+1]=n[1],r[i+2]=n[2],r[i+3]=n[3]}function o(e,r,i){t[0]=e,r[i]=n[3],r[i+1]=n[2],r[i+2]=n[1],r[i+3]=n[0]}function s(e,r){return n[0]=e[r],n[1]=e[r+1],n[2]=e[r+2],n[3]=e[r+3],t[0]}function a(e,r){return n[3]=e[r],n[2]=e[r+1],n[1]=e[r+2],n[0]=e[r+3],t[0]}e.writeFloatLE=r?i:o,e.writeFloatBE=r?o:i,e.readFloatLE=r?s:a,e.readFloatBE=r?a:s}():function(){function t(e,t,n,r){var i=t<0?1:0;if(i&&(t=-t),0===t)e(1/t>0?0:2147483648,n,r);else if(isNaN(t))e(2143289344,n,r);else if(t>34028234663852886e22)e((i<<31|2139095040)>>>0,n,r);else if(t<11754943508222875e-54)e((i<<31|Math.round(t/1401298464324817e-60))>>>0,n,r);else{var o=Math.floor(Math.log(t)/Math.LN2);e((i<<31|o+127<<23|8388607&Math.round(t*Math.pow(2,-o)*8388608))>>>0,n,r)}}function s(e,t,n){var r=e(t,n),i=2*(r>>31)+1,o=r>>>23&255,s=8388607&r;return 255===o?s?NaN:i*(1/0):0===o?1401298464324817e-60*i*s:i*Math.pow(2,o-150)*(s+8388608)}e.writeFloatLE=t.bind(null,n),e.writeFloatBE=t.bind(null,r),e.readFloatLE=s.bind(null,i),e.readFloatBE=s.bind(null,o)}(),"undefined"!=typeof Float64Array?function(){var t=new Float64Array([-0]),n=new Uint8Array(t.buffer),r=128===n[7];function i(e,r,i){t[0]=e,r[i]=n[0],r[i+1]=n[1],r[i+2]=n[2],r[i+3]=n[3],r[i+4]=n[4],r[i+5]=n[5],r[i+6]=n[6],r[i+7]=n[7]}function o(e,r,i){t[0]=e,r[i]=n[7],r[i+1]=n[6],r[i+2]=n[5],r[i+3]=n[4],r[i+4]=n[3],r[i+5]=n[2],r[i+6]=n[1],r[i+7]=n[0]}function s(e,r){return n[0]=e[r],n[1]=e[r+1],n[2]=e[r+2],n[3]=e[r+3],n[4]=e[r+4],n[5]=e[r+5],n[6]=e[r+6],n[7]=e[r+7],t[0]}function a(e,r){return n[7]=e[r],n[6]=e[r+1],n[5]=e[r+2],n[4]=e[r+3],n[3]=e[r+4],n[2]=e[r+5],n[1]=e[r+6],n[0]=e[r+7],t[0]}e.writeDoubleLE=r?i:o,e.writeDoubleBE=r?o:i,e.readDoubleLE=r?s:a,e.readDoubleBE=r?a:s}():function(){function t(e,t,n,r,i,o){var s=r<0?1:0;if(s&&(r=-r),0===r)e(0,i,o+t),e(1/r>0?0:2147483648,i,o+n);else if(isNaN(r))e(0,i,o+t),e(2146959360,i,o+n);else if(r>17976931348623157e292)e(0,i,o+t),e((s<<31|2146435072)>>>0,i,o+n);else{var a;if(r<22250738585072014e-324)e((a=r/5e-324)>>>0,i,o+t),e((s<<31|a/4294967296)>>>0,i,o+n);else{var c=Math.floor(Math.log(r)/Math.LN2);1024===c&&(c=1023),e(4503599627370496*(a=r*Math.pow(2,-c))>>>0,i,o+t),e((s<<31|c+1023<<20|1048576*a&1048575)>>>0,i,o+n)}}}function s(e,t,n,r,i){var o=e(r,i+t),s=e(r,i+n),a=2*(s>>31)+1,c=s>>>20&2047,l=4294967296*(1048575&s)+o;return 2047===c?l?NaN:a*(1/0):0===c?5e-324*a*l:a*Math.pow(2,c-1075)*(l+4503599627370496)}e.writeDoubleLE=t.bind(null,n,0,4),e.writeDoubleBE=t.bind(null,r,4,0),e.readDoubleLE=s.bind(null,i,0,4),e.readDoubleBE=s.bind(null,o,4,0)}(),e}function n(e,t,n){t[n]=255&e,t[n+1]=e>>>8&255,t[n+2]=e>>>16&255,t[n+3]=e>>>24}function r(e,t,n){t[n]=e>>>24,t[n+1]=e>>>16&255,t[n+2]=e>>>8&255,t[n+3]=255&e}function i(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0}function o(e,t){return(e[t]<<24|e[t+1]<<16|e[t+2]<<8|e[t+3])>>>0}e.exports=t(t)},199:module=>{"use strict";function inquire(moduleName){try{var mod=eval("quire".replace(/^/,"re"))(moduleName);if(mod&&(mod.length||Object.keys(mod).length))return mod}catch(e){}return null}module.exports=inquire},662:e=>{"use strict";e.exports=function(e,t,n){var r=n||8192,i=r>>>1,o=null,s=r;return function(n){if(n<1||n>i)return e(n);s+n>r&&(o=e(r),s=0);var a=t.call(o,s,s+=n);return 7&s&&(s=1+(7|s)),a}}},997:(e,t)=>{"use strict";var n=t;n.length=function(e){for(var t=0,n=0,r=0;r191&&r<224?o[s++]=(31&r)<<6|63&e[t++]:r>239&&r<365?(r=((7&r)<<18|(63&e[t++])<<12|(63&e[t++])<<6|63&e[t++])-65536,o[s++]=55296+(r>>10),o[s++]=56320+(1023&r)):o[s++]=(15&r)<<12|(63&e[t++])<<6|63&e[t++],s>8191&&((i||(i=[])).push(String.fromCharCode.apply(String,o)),s=0);return i?(s&&i.push(String.fromCharCode.apply(String,o.slice(0,s))),i.join("")):String.fromCharCode.apply(String,o.slice(0,s))},n.write=function(e,t,n){for(var r,i,o=n,s=0;s>6|192,t[n++]=63&r|128):55296==(64512&r)&&56320==(64512&(i=e.charCodeAt(s+1)))?(r=65536+((1023&r)<<10)+(1023&i),++s,t[n++]=r>>18|240,t[n++]=r>>12&63|128,t[n++]=r>>6&63|128,t[n++]=63&r|128):(t[n++]=r>>12|224,t[n++]=r>>6&63|128,t[n++]=63&r|128);return n-o}},699:(e,t,n)=>{"use strict";var r,i,o,s,a,c=n(100),l=c.Writer,u=c.util,p=c.roots.default||(c.roots.default={});p.io=((a={}).agora=((s={}).pb=((o={}).CounterCompact=function(){function e(e){if(this.items=[],e)for(var t=Object.keys(e),n=0;n{"use strict";n.r(t),n.d(t,{DOMAIN_NAME:()=>o,SDK_VERSION:()=>i,VERSION:()=>r});var r="1.1.0",i="2.6.4",o="mini-app.broadcastapp.agoraio.cn"},426:(e,t,n)=>{"use strict";n.r(t),n.d(t,{generateSessionId:()=>s,is32Uint:()=>l,isWeiXin:()=>c,random:()=>o,shouldUseHttps:()=>a});var r=n(171),i=n.n(r),o=function(e){isNaN(e)&&(e=1e3);var t=+new Date,n=(t=(9301*t+49297)%233280)/233280;return Math.ceil(n*e)},s=function(){return i()().replace(/-/g,"").toUpperCase()},a=function(){return"https:"==document.location.protocol},c=function(){try{return wx,!0}catch(e){return!1}},l=function(e){return!!(0<=e&&e<=4294967295)}},186:(e,t,n)=>{"use strict";n.r(t),n.d(t,{default:()=>u});var r=n(861),i=n(671),o=n(144),s=n(687),a=n.n(s),c=(n(568),n(446)),l=function(){function e(t){var n=t.appId,r=t.content,o=t.ts;(0,i.Z)(this,e),this.appId=n,this.content=r,this.ts=o}return(0,o.Z)(e,[{key:"upload",value:function(){var e=this;return new Promise((function(t,n){wx.request({url:"https://report-ad.agoralab.co/v1/log/report",method:"post",data:{data:e.content,appId:e.appId,ts:e.ts,src:"miniapp",version:c.SDK_VERSION},success:function(){t()},fail:function(e){n(e)}})}))}}]),e}();const u=new(function(){function e(){(0,i.Z)(this,e),this.level=3,this.onLog=null,this.logItems=[],this.appId="",this.sid=""}return(0,o.Z)(e,[{key:"setOptions",value:function(e){var t=e.appId,n=void 0===t?"":t,r=e.sid,i=void 0===r?"":r;this.appId=n,this.sid=i}},{key:"setLogLevel",value:function(e){if("number"!=typeof e||!(e<=4&&e>=-1))throw Error("Invalid level");this.level=e}},{key:"_storeLog",value:function(e){this.logItems.push({msg:e,sid:this.sid}),this.logItems.length>5e4&&this.logItems.shift()}},{key:"_log",value:function(){for(var e="",t=arguments.length,n=new Array(t),r=0;r{"use strict";n.r(t),n.d(t,{checkValidBoolean:()=>l,checkValidEnum:()=>i,checkValidFloatNumber:()=>c,checkValidNumber:()=>a,checkValidObject:()=>o,checkValidString:()=>s,getServerUrlIp:()=>b,isASCII:()=>_,isArray:()=>w,isEmpty:()=>O,isInteger:()=>g,isNumber:()=>v,isString:()=>m,isValidBoolean:()=>d,isValidChannelName:()=>y,isValidNumber:()=>p,isValidString:()=>u,isValidToken:()=>f,stringifyErr:()=>E,throttle:()=>S,transformElapseStr:()=>R});var r=n(2),i=function(e,t,n){for(var r=0;r=t&&e.length<=n},p=function(e,t,n){return g(e)&&e>=t&&e<=n},h=function(e,t,n){return v(e)&&e>=t&&e<=n},d=function(e){return"boolean"==typeof e},f=function(e){return u(e,1,2047)},y=function(e){return m(e)&&/^[a-zA-Z0-9 \!\#\$\%\&\(\)\+\-\:\;\<\=\.\>\?\@\[\]\^\_\{\}\|\~\,]{1,64}$/.test(e)},_=function(e){if("string"==typeof e){for(var t=0;t255)return!1}return!0}},g=function(e){return"number"==typeof e&&e%1==0},v=function(e){return"number"==typeof e},m=function(e){return"string"==typeof e},w=function(e){return e instanceof Array},O=function(e){return null==e},E=function(e){return e instanceof Error||e.message?e.message:JSON.stringify(e)},b=function(e){var t=/wss:\/\/miniapp.agoraio.cn\/(\S+)\/api/g.exec(e);return t instanceof Array&&t[1]||""},R=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;return(e=Number(e))<=0?"<0ms":e>0&&e<=50?"0~50ms":e>50&&e<=100?"50~100ms":e>100&&e<=200?"100~200ms":e>200&&e<=300?"200~300ms":e>300&&e<=500?"300~500ms":e>500&&e<=800?"500~800ms":e>800&&e<=1e3?"800~1000ms":e>1e3&&e<=1500?"1~1.5s":e>1500&&e<=2e3?"1.5~2s":e>2e3&&e<=3e3?"2~3s":e>3e3&&e<=5e3?"3~5s":e>5e3&&e<=8e3?"5~8s":e>8e3&&e<=1e4?"8~10s":">10s"},S=function(e){var t,n,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return function(){for(var i=arguments.length,o=new Array(i),s=0;s{var t={utf8:{stringToBytes:function(e){return t.bin.stringToBytes(unescape(encodeURIComponent(e)))},bytesToString:function(e){return decodeURIComponent(escape(t.bin.bytesToString(e)))}},bin:{stringToBytes:function(e){for(var t=[],n=0;n{var t,n;t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n={rotl:function(e,t){return e<>>32-t},rotr:function(e,t){return e<<32-t|e>>>t},endian:function(e){if(e.constructor==Number)return 16711935&n.rotl(e,8)|4278255360&n.rotl(e,24);for(var t=0;t0;e--)t.push(Math.floor(256*Math.random()));return t},bytesToWords:function(e){for(var t=[],n=0,r=0;n>>5]|=e[n]<<24-r%32;return t},wordsToBytes:function(e){for(var t=[],n=0;n<32*e.length;n+=8)t.push(e[n>>>5]>>>24-n%32&255);return t},bytesToHex:function(e){for(var t=[],n=0;n>>4).toString(16)),t.push((15&e[n]).toString(16));return t.join("")},hexToBytes:function(e){for(var t=[],n=0;n>>6*(3-o)&63)):n.push("=");return n.join("")},base64ToBytes:function(e){e=e.replace(/[^A-Z0-9+\/]/gi,"");for(var n=[],r=0,i=0;r>>6-2*i);return n}},e.exports=n},738:e=>{function t(e){return!!e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)}e.exports=function(e){return null!=e&&(t(e)||function(e){return"function"==typeof e.readFloatLE&&"function"==typeof e.slice&&t(e.slice(0,0))}(e)||!!e._isBuffer)}},568:(e,t,n)=>{var r,i,o,s,a;r=n(12),i=n(487).utf8,o=n(738),s=n(487).bin,(a=function(e,t){e.constructor==String?e=t&&"binary"===t.encoding?s.stringToBytes(e):i.stringToBytes(e):o(e)?e=Array.prototype.slice.call(e,0):Array.isArray(e)||e.constructor===Uint8Array||(e=e.toString());for(var n=r.bytesToWords(e),c=8*e.length,l=1732584193,u=-271733879,p=-1732584194,h=271733878,d=0;d>>24)|4278255360&(n[d]<<24|n[d]>>>8);n[c>>>5]|=128<>>9<<4)]=c;var f=a._ff,y=a._gg,_=a._hh,g=a._ii;for(d=0;d>>0,u=u+m>>>0,p=p+w>>>0,h=h+O>>>0}return r.endian([l,u,p,h])})._ff=function(e,t,n,r,i,o,s){var a=e+(t&n|~t&r)+(i>>>0)+s;return(a<>>32-o)+t},a._gg=function(e,t,n,r,i,o,s){var a=e+(t&r|n&~r)+(i>>>0)+s;return(a<>>32-o)+t},a._hh=function(e,t,n,r,i,o,s){var a=e+(t^n^r)+(i>>>0)+s;return(a<>>32-o)+t},a._ii=function(e,t,n,r,i,o,s){var a=e+(n^(t|~r))+(i>>>0)+s;return(a<>>32-o)+t},a._blocksize=16,a._digestsize=16,e.exports=function(e,t){if(null==e)throw new Error("Illegal argument "+e);var n=r.wordsToBytes(a(e,t));return t&&t.asBytes?n:t&&t.asString?s.bytesToString(n):r.bytesToHex(n)}},100:(e,t,n)=>{"use strict";e.exports=n(482)},482:(e,t,n)=>{"use strict";var r=t;function i(){r.util._configure(),r.Writer._configure(r.BufferWriter),r.Reader._configure(r.BufferReader)}r.build="minimal",r.Writer=n(173),r.BufferWriter=n(155),r.Reader=n(408),r.BufferReader=n(593),r.util=n(693),r.rpc=n(994),r.roots=n(54),r.configure=i,i()},408:(e,t,n)=>{"use strict";e.exports=c;var r,i=n(693),o=i.LongBits,s=i.utf8;function a(e,t){return RangeError("index out of range: "+e.pos+" + "+(t||1)+" > "+e.len)}function c(e){this.buf=e,this.pos=0,this.len=e.length}var l,u="undefined"!=typeof Uint8Array?function(e){if(e instanceof Uint8Array||Array.isArray(e))return new c(e);throw Error("illegal buffer")}:function(e){if(Array.isArray(e))return new c(e);throw Error("illegal buffer")},p=function(){return i.Buffer?function(e){return(c.create=function(e){return i.Buffer.isBuffer(e)?new r(e):u(e)})(e)}:u};function h(){var e=new o(0,0),t=0;if(!(this.len-this.pos>4)){for(;t<3;++t){if(this.pos>=this.len)throw a(this);if(e.lo=(e.lo|(127&this.buf[this.pos])<<7*t)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(127&this.buf[this.pos++])<<7*t)>>>0,e}for(;t<4;++t)if(e.lo=(e.lo|(127&this.buf[this.pos])<<7*t)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(127&this.buf[this.pos])<<28)>>>0,e.hi=(e.hi|(127&this.buf[this.pos])>>4)>>>0,this.buf[this.pos++]<128)return e;if(t=0,this.len-this.pos>4){for(;t<5;++t)if(e.hi=(e.hi|(127&this.buf[this.pos])<<7*t+3)>>>0,this.buf[this.pos++]<128)return e}else for(;t<5;++t){if(this.pos>=this.len)throw a(this);if(e.hi=(e.hi|(127&this.buf[this.pos])<<7*t+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}function d(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}function f(){if(this.pos+8>this.len)throw a(this,8);return new o(d(this.buf,this.pos+=4),d(this.buf,this.pos+=4))}c.create=p(),c.prototype._slice=i.Array.prototype.subarray||i.Array.prototype.slice,c.prototype.uint32=(l=4294967295,function(){if(l=(127&this.buf[this.pos])>>>0,this.buf[this.pos++]<128)return l;if(l=(l|(127&this.buf[this.pos])<<7)>>>0,this.buf[this.pos++]<128)return l;if(l=(l|(127&this.buf[this.pos])<<14)>>>0,this.buf[this.pos++]<128)return l;if(l=(l|(127&this.buf[this.pos])<<21)>>>0,this.buf[this.pos++]<128)return l;if(l=(l|(15&this.buf[this.pos])<<28)>>>0,this.buf[this.pos++]<128)return l;if((this.pos+=5)>this.len)throw this.pos=this.len,a(this,10);return l}),c.prototype.int32=function(){return 0|this.uint32()},c.prototype.sint32=function(){var e=this.uint32();return e>>>1^-(1&e)|0},c.prototype.bool=function(){return 0!==this.uint32()},c.prototype.fixed32=function(){if(this.pos+4>this.len)throw a(this,4);return d(this.buf,this.pos+=4)},c.prototype.sfixed32=function(){if(this.pos+4>this.len)throw a(this,4);return 0|d(this.buf,this.pos+=4)},c.prototype.float=function(){if(this.pos+4>this.len)throw a(this,4);var e=i.float.readFloatLE(this.buf,this.pos);return this.pos+=4,e},c.prototype.double=function(){if(this.pos+8>this.len)throw a(this,4);var e=i.float.readDoubleLE(this.buf,this.pos);return this.pos+=8,e},c.prototype.bytes=function(){var e=this.uint32(),t=this.pos,n=this.pos+e;if(n>this.len)throw a(this,e);return this.pos+=e,Array.isArray(this.buf)?this.buf.slice(t,n):t===n?new this.buf.constructor(0):this._slice.call(this.buf,t,n)},c.prototype.string=function(){var e=this.bytes();return s.read(e,0,e.length)},c.prototype.skip=function(e){if("number"==typeof e){if(this.pos+e>this.len)throw a(this,e);this.pos+=e}else do{if(this.pos>=this.len)throw a(this)}while(128&this.buf[this.pos++]);return this},c.prototype.skipType=function(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;4!=(e=7&this.uint32());)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error("invalid wire type "+e+" at offset "+this.pos)}return this},c._configure=function(e){r=e,c.create=p(),r._configure();var t=i.Long?"toLong":"toNumber";i.merge(c.prototype,{int64:function(){return h.call(this)[t](!1)},uint64:function(){return h.call(this)[t](!0)},sint64:function(){return h.call(this).zzDecode()[t](!1)},fixed64:function(){return f.call(this)[t](!0)},sfixed64:function(){return f.call(this)[t](!1)}})}},593:(e,t,n)=>{"use strict";e.exports=o;var r=n(408);(o.prototype=Object.create(r.prototype)).constructor=o;var i=n(693);function o(e){r.call(this,e)}o._configure=function(){i.Buffer&&(o.prototype._slice=i.Buffer.prototype.slice)},o.prototype.string=function(){var e=this.uint32();return this.buf.utf8Slice?this.buf.utf8Slice(this.pos,this.pos=Math.min(this.pos+e,this.len)):this.buf.toString("utf-8",this.pos,this.pos=Math.min(this.pos+e,this.len))},o._configure()},54:e=>{"use strict";e.exports={}},994:(e,t,n)=>{"use strict";t.Service=n(948)},948:(e,t,n)=>{"use strict";e.exports=i;var r=n(693);function i(e,t,n){if("function"!=typeof e)throw TypeError("rpcImpl must be a function");r.EventEmitter.call(this),this.rpcImpl=e,this.requestDelimited=Boolean(t),this.responseDelimited=Boolean(n)}(i.prototype=Object.create(r.EventEmitter.prototype)).constructor=i,i.prototype.rpcCall=function e(t,n,i,o,s){if(!o)throw TypeError("request must be specified");var a=this;if(!s)return r.asPromise(e,a,t,n,i,o);if(a.rpcImpl)try{return a.rpcImpl(t,n[a.requestDelimited?"encodeDelimited":"encode"](o).finish(),(function(e,n){if(e)return a.emit("error",e,t),s(e);if(null!==n){if(!(n instanceof i))try{n=i[a.responseDelimited?"decodeDelimited":"decode"](n)}catch(e){return a.emit("error",e,t),s(e)}return a.emit("data",n,t),s(null,n)}a.end(!0)}))}catch(e){return a.emit("error",e,t),void setTimeout((function(){s(e)}),0)}else setTimeout((function(){s(Error("already ended"))}),0)},i.prototype.end=function(e){return this.rpcImpl&&(e||this.rpcImpl(null,null,null),this.rpcImpl=null,this.emit("end").off()),this}},630:(e,t,n)=>{"use strict";e.exports=i;var r=n(693);function i(e,t){this.lo=e>>>0,this.hi=t>>>0}var o=i.zero=new i(0,0);o.toNumber=function(){return 0},o.zzEncode=o.zzDecode=function(){return this},o.length=function(){return 1};var s=i.zeroHash="\0\0\0\0\0\0\0\0";i.fromNumber=function(e){if(0===e)return o;var t=e<0;t&&(e=-e);var n=e>>>0,r=(e-n)/4294967296>>>0;return t&&(r=~r>>>0,n=~n>>>0,++n>4294967295&&(n=0,++r>4294967295&&(r=0))),new i(n,r)},i.from=function(e){if("number"==typeof e)return i.fromNumber(e);if(r.isString(e)){if(!r.Long)return i.fromNumber(parseInt(e,10));e=r.Long.fromString(e)}return e.low||e.high?new i(e.low>>>0,e.high>>>0):o},i.prototype.toNumber=function(e){if(!e&&this.hi>>>31){var t=1+~this.lo>>>0,n=~this.hi>>>0;return t||(n=n+1>>>0),-(t+4294967296*n)}return this.lo+4294967296*this.hi},i.prototype.toLong=function(e){return r.Long?new r.Long(0|this.lo,0|this.hi,Boolean(e)):{low:0|this.lo,high:0|this.hi,unsigned:Boolean(e)}};var a=String.prototype.charCodeAt;i.fromHash=function(e){return e===s?o:new i((a.call(e,0)|a.call(e,1)<<8|a.call(e,2)<<16|a.call(e,3)<<24)>>>0,(a.call(e,4)|a.call(e,5)<<8|a.call(e,6)<<16|a.call(e,7)<<24)>>>0)},i.prototype.toHash=function(){return String.fromCharCode(255&this.lo,this.lo>>>8&255,this.lo>>>16&255,this.lo>>>24,255&this.hi,this.hi>>>8&255,this.hi>>>16&255,this.hi>>>24)},i.prototype.zzEncode=function(){var e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this},i.prototype.zzDecode=function(){var e=-(1&this.lo);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this},i.prototype.length=function(){var e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return 0===n?0===t?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:n<128?9:10}},693:function(e,t,n){"use strict";var r=t;function i(e,t,n){for(var r=Object.keys(t),i=0;i0)},r.Buffer=function(){try{var e=r.inquire("buffer").Buffer;return e.prototype.utf8Write?e:null}catch(e){return null}}(),r._Buffer_from=null,r._Buffer_allocUnsafe=null,r.newBuffer=function(e){return"number"==typeof e?r.Buffer?r._Buffer_allocUnsafe(e):new r.Array(e):r.Buffer?r._Buffer_from(e):"undefined"==typeof Uint8Array?e:new Uint8Array(e)},r.Array="undefined"!=typeof Uint8Array?Uint8Array:Array,r.Long=r.global.dcodeIO&&r.global.dcodeIO.Long||r.global.Long||r.inquire("long"),r.key2Re=/^true|false|0|1$/,r.key32Re=/^-?(?:0|[1-9][0-9]*)$/,r.key64Re=/^(?:[\\x00-\\xff]{8}|-?(?:0|[1-9][0-9]*))$/,r.longToHash=function(e){return e?r.LongBits.from(e).toHash():r.LongBits.zeroHash},r.longFromHash=function(e,t){var n=r.LongBits.fromHash(e);return r.Long?r.Long.fromBits(n.lo,n.hi,t):n.toNumber(Boolean(t))},r.merge=i,r.lcFirst=function(e){return e.charAt(0).toLowerCase()+e.substring(1)},r.newError=o,r.ProtocolError=o("ProtocolError"),r.oneOfGetter=function(e){for(var t={},n=0;n-1;--n)if(1===t[e[n]]&&void 0!==this[e[n]]&&null!==this[e[n]])return e[n]}},r.oneOfSetter=function(e){return function(t){for(var n=0;n{"use strict";e.exports=p;var r,i=n(693),o=i.LongBits,s=i.base64,a=i.utf8;function c(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}function l(){}function u(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}function p(){this.len=0,this.head=new c(l,0,0),this.tail=this.head,this.states=null}var h=function(){return i.Buffer?function(){return(p.create=function(){return new r})()}:function(){return new p}};function d(e,t,n){t[n]=255&e}function f(e,t){this.len=e,this.next=void 0,this.val=t}function y(e,t,n){for(;e.hi;)t[n++]=127&e.lo|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[n++]=127&e.lo|128,e.lo=e.lo>>>7;t[n++]=e.lo}function _(e,t,n){t[n]=255&e,t[n+1]=e>>>8&255,t[n+2]=e>>>16&255,t[n+3]=e>>>24}p.create=h(),p.alloc=function(e){return new i.Array(e)},i.Array!==Array&&(p.alloc=i.pool(p.alloc,i.Array.prototype.subarray)),p.prototype._push=function(e,t,n){return this.tail=this.tail.next=new c(e,t,n),this.len+=t,this},f.prototype=Object.create(c.prototype),f.prototype.fn=function(e,t,n){for(;e>127;)t[n++]=127&e|128,e>>>=7;t[n]=e},p.prototype.uint32=function(e){return this.len+=(this.tail=this.tail.next=new f((e>>>=0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this},p.prototype.int32=function(e){return e<0?this._push(y,10,o.fromNumber(e)):this.uint32(e)},p.prototype.sint32=function(e){return this.uint32((e<<1^e>>31)>>>0)},p.prototype.uint64=function(e){var t=o.from(e);return this._push(y,t.length(),t)},p.prototype.int64=p.prototype.uint64,p.prototype.sint64=function(e){var t=o.from(e).zzEncode();return this._push(y,t.length(),t)},p.prototype.bool=function(e){return this._push(d,1,e?1:0)},p.prototype.fixed32=function(e){return this._push(_,4,e>>>0)},p.prototype.sfixed32=p.prototype.fixed32,p.prototype.fixed64=function(e){var t=o.from(e);return this._push(_,4,t.lo)._push(_,4,t.hi)},p.prototype.sfixed64=p.prototype.fixed64,p.prototype.float=function(e){return this._push(i.float.writeFloatLE,4,e)},p.prototype.double=function(e){return this._push(i.float.writeDoubleLE,8,e)};var g=i.Array.prototype.set?function(e,t,n){t.set(e,n)}:function(e,t,n){for(var r=0;r>>0;if(!t)return this._push(d,1,0);if(i.isString(e)){var n=p.alloc(t=s.length(e));s.decode(e,n,0),e=n}return this.uint32(t)._push(g,t,e)},p.prototype.string=function(e){var t=a.length(e);return t?this.uint32(t)._push(a.write,t,e):this._push(d,1,0)},p.prototype.fork=function(){return this.states=new u(this),this.head=this.tail=new c(l,0,0),this.len=0,this},p.prototype.reset=function(){return this.states?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new c(l,0,0),this.len=0),this},p.prototype.ldelim=function(){var e=this.head,t=this.tail,n=this.len;return this.reset().uint32(n),n&&(this.tail.next=e.next,this.tail=t,this.len+=n),this},p.prototype.finish=function(){for(var e=this.head.next,t=this.constructor.alloc(this.len),n=0;e;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t},p._configure=function(e){r=e,p.create=h(),r._configure()}},155:(e,t,n)=>{"use strict";e.exports=o;var r=n(173);(o.prototype=Object.create(r.prototype)).constructor=o;var i=n(693);function o(){r.call(this)}function s(e,t,n){e.length<40?i.utf8.write(e,t,n):t.utf8Write?t.utf8Write(e,n):t.write(e,n)}o._configure=function(){o.alloc=i._Buffer_allocUnsafe,o.writeBytesBuffer=i.Buffer&&i.Buffer.prototype instanceof Uint8Array&&"set"===i.Buffer.prototype.set.name?function(e,t,n){t.set(e,n)}:function(e,t,n){if(e.copy)e.copy(t,n,0,e.length);else for(var r=0;r>>0;return this.uint32(t),t&&this._push(o.writeBytesBuffer,t,e),this},o.prototype.string=function(e){var t=i.Buffer.byteLength(e);return this.uint32(t),t&&this._push(s,t,e),this},o._configure()},500:function(e,t,n){"use strict";var r,i=this&&this.__extends||(r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},r(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),o=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{c(r.next(e))}catch(e){o(e)}}function a(e){try{c(r.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))},s=this&&this.__generator||function(e,t){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((i=(i=s.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]{for(var t=[],n=0;n<256;++n)t[n]=(n+256).toString(16).substr(1);e.exports=function(e,n){var r=n||0,i=t;return[i[e[r++]],i[e[r++]],i[e[r++]],i[e[r++]],"-",i[e[r++]],i[e[r++]],"-",i[e[r++]],i[e[r++]],"-",i[e[r++]],i[e[r++]],"-",i[e[r++]],i[e[r++]],i[e[r++]],i[e[r++]],i[e[r++]],i[e[r++]]].join("")}},217:e=>{var t="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(t){var n=new Uint8Array(16);e.exports=function(){return t(n),n}}else{var r=new Array(16);e.exports=function(){for(var e,t=0;t<16;t++)0==(3&t)&&(e=4294967296*Math.random()),r[t]=e>>>((3&t)<<3)&255;return r}}},171:(e,t,n)=>{var r=n(217),i=n(327);e.exports=function(e,t,n){var o=t&&n||0;"string"==typeof e&&(t="binary"===e?new Array(16):null,e=null);var s=(e=e||{}).random||(e.rng||r)();if(s[6]=15&s[6]|64,s[8]=63&s[8]|128,t)for(var a=0;a<16;++a)t[o+a]=s[a];return t||i(s)}},795:function(e,t,n){var r;!function(t){"use strict";function i(){}var o=i.prototype,s=t.EventEmitter;function a(e,t){for(var n=e.length;n--;)if(e[n].listener===t)return n;return-1}function c(e){return function(){return this[e].apply(this,arguments)}}function l(e){return"function"==typeof e||e instanceof RegExp||!(!e||"object"!=typeof e)&&l(e.listener)}o.getListeners=function(e){var t,n,r=this._getEvents();if(e instanceof RegExp)for(n in t={},r)r.hasOwnProperty(n)&&e.test(n)&&(t[n]=r[n]);else t=r[e]||(r[e]=[]);return t},o.flattenListeners=function(e){var t,n=[];for(t=0;t{var r=n(698).default;function i(){"use strict";e.exports=i=function(){return n},e.exports.__esModule=!0,e.exports.default=e.exports;var t,n={},o=Object.prototype,s=o.hasOwnProperty,a=Object.defineProperty||function(e,t,n){e[t]=n.value},c="function"==typeof Symbol?Symbol:{},l=c.iterator||"@@iterator",u=c.asyncIterator||"@@asyncIterator",p=c.toStringTag||"@@toStringTag";function h(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{h({},"")}catch(t){h=function(e,t,n){return e[t]=n}}function d(e,t,n,r){var i=t&&t.prototype instanceof w?t:w,o=Object.create(i.prototype),s=new L(r||[]);return a(o,"_invoke",{value:A(e,n,s)}),o}function f(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}n.wrap=d;var y="suspendedStart",_="suspendedYield",g="executing",v="completed",m={};function w(){}function O(){}function E(){}var b={};h(b,l,(function(){return this}));var R=Object.getPrototypeOf,S=R&&R(R(M([])));S&&S!==o&&s.call(S,l)&&(b=S);var k=E.prototype=w.prototype=Object.create(b);function P(e){["next","throw","return"].forEach((function(t){h(e,t,(function(e){return this._invoke(t,e)}))}))}function I(e,t){function n(i,o,a,c){var l=f(e[i],e,o);if("throw"!==l.type){var u=l.arg,p=u.value;return p&&"object"==r(p)&&s.call(p,"__await")?t.resolve(p.__await).then((function(e){n("next",e,a,c)}),(function(e){n("throw",e,a,c)})):t.resolve(p).then((function(e){u.value=e,a(u)}),(function(e){return n("throw",e,a,c)}))}c(l.arg)}var i;a(this,"_invoke",{value:function(e,r){function o(){return new t((function(t,i){n(e,r,t,i)}))}return i=i?i.then(o,o):o()}})}function A(e,n,r){var i=y;return function(o,s){if(i===g)throw new Error("Generator is already running");if(i===v){if("throw"===o)throw s;return{value:t,done:!0}}for(r.method=o,r.arg=s;;){var a=r.delegate;if(a){var c=T(a,r);if(c){if(c===m)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(i===y)throw i=v,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);i=g;var l=f(e,n,r);if("normal"===l.type){if(i=r.done?v:_,l.arg===m)continue;return{value:l.arg,done:r.done}}"throw"===l.type&&(i=v,r.method="throw",r.arg=l.arg)}}}function T(e,n){var r=n.method,i=e.iterator[r];if(i===t)return n.delegate=null,"throw"===r&&e.iterator.return&&(n.method="return",n.arg=t,T(e,n),"throw"===n.method)||"return"!==r&&(n.method="throw",n.arg=new TypeError("The iterator does not provide a '"+r+"' method")),m;var o=f(i,e.iterator,n.arg);if("throw"===o.type)return n.method="throw",n.arg=o.arg,n.delegate=null,m;var s=o.arg;return s?s.done?(n[e.resultName]=s.value,n.next=e.nextLoc,"return"!==n.method&&(n.method="next",n.arg=t),n.delegate=null,m):s:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,m)}function C(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function N(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function L(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(C,this),this.reset(!0)}function M(e){if(e||""===e){var n=e[l];if(n)return n.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var i=-1,o=function n(){for(;++i=0;--i){var o=this.tryEntries[i],a=o.completion;if("root"===o.tryLoc)return r("end");if(o.tryLoc<=this.prev){var c=s.call(o,"catchLoc"),l=s.call(o,"finallyLoc");if(c&&l){if(this.prev=0;--n){var r=this.tryEntries[n];if(r.tryLoc<=this.prev&&s.call(r,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),N(n),m}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var i=r.arg;N(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,n,r){return this.delegate={iterator:M(e),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=t),m}},n}e.exports=i,e.exports.__esModule=!0,e.exports.default=e.exports},698:e=>{function t(n){return e.exports=t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e.exports.__esModule=!0,e.exports.default=e.exports,t(n)}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports},687:(e,t,n)=>{var r=n(61)();e.exports=r;try{regeneratorRuntime=r}catch(e){"object"==typeof globalThis?globalThis.regeneratorRuntime=r:Function("r","regeneratorRuntime = r")(r)}},861:(e,t,n)=>{"use strict";function r(e,t,n,r,i,o,s){try{var a=e[o](s),c=a.value}catch(e){return void n(e)}a.done?t(c):Promise.resolve(c).then(r,i)}function i(e){return function(){var t=this,n=arguments;return new Promise((function(i,o){var s=e.apply(t,n);function a(e){r(s,i,o,a,c,"next",e)}function c(e){r(s,i,o,a,c,"throw",e)}a(void 0)}))}}n.d(t,{Z:()=>i})},671:(e,t,n)=>{"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}n.d(t,{Z:()=>r})},144:(e,t,n)=>{"use strict";n.d(t,{Z:()=>o});var r=n(142);function i(e,t){for(var n=0;n{"use strict";n.d(t,{Z:()=>i});var r=n(2);function i(e){var t=function(e,t){if("object"!=(0,r.Z)(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var i=n.call(e,"string");if("object"!=(0,r.Z)(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==(0,r.Z)(t)?t:String(t)}},2:(e,t,n)=>{"use strict";function r(e){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r(e)}n.d(t,{Z:()=>r})}},__webpack_module_cache__={};function __webpack_require__(e){var t=__webpack_module_cache__[e];if(void 0!==t)return t.exports;var n=__webpack_module_cache__[e]={exports:{}};return __webpack_modules__[e].call(n.exports,n,n.exports,__webpack_require__),n.exports}__webpack_require__.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return __webpack_require__.d(t,{a:t}),t},__webpack_require__.d=(e,t)=>{for(var n in t)__webpack_require__.o(t,n)&&!__webpack_require__.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},__webpack_require__.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),__webpack_require__.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),__webpack_require__.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var __webpack_exports__={};return(()=>{"use strict";__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,{ChannelMediaRelayConfiguration:()=>I.ChannelMediaRelayConfiguration,Client:()=>le,LOG:()=>a.default,SDK_VERSION:()=>s.SDK_VERSION});var e=__webpack_require__(861),t=__webpack_require__(671),n=__webpack_require__(144),r=__webpack_require__(687),i=__webpack_require__.n(r),o=__webpack_require__(426),s=__webpack_require__(446),a=__webpack_require__(186);function c(){return c=Object.assign?Object.assign.bind():function(e){for(var t=1;t0&&void 0!==u[0]?u[0]:0,o=u.length>1&&void 0!==u[1]?u[1]:{},this.vid||(this.vid=O().vid),s={m:"net_status",ls:{type:0===r?"live-pusher":"live-player",vid:String(this.vid),app_id:this.appId,version:this.sdk_version,ip:this.ip,wx_version:null===(t=this.systemInfo)||void 0===t?void 0:t.version,wx_basic_version:null===(n=this.systemInfo)||void 0===n?void 0:n.SDKVersion},vs:{videoBitrate:String(null==o?void 0:o.videoBitrate),audioBitrate:String(null==o?void 0:o.audioBitrate),videoFPS:String(null==o?void 0:o.videoFPS),videoGOP:String(null==o?void 0:o.videoGOP),netSpeed:String(null==o?void 0:o.netSpeed),netQualityLevel:String(null==o?void 0:o.netQualityLevel),netJitter:String(null==o?void 0:o.netJitter)}},this.netStatusPts.push(s),10!==this.netStatusPts.length){e.next=11;break}return a=Date.now(),c=this.netStatusPts.splice(0,10),l={pts:c,sign:h()("src=miniapp_sdk&ts=".concat(a)),src:"miniapp_sdk",ts:a},e.next=11,this.request({body:l,url:this.url});case 11:case"end":return e.stop()}}),e,this)}))),function(){return l.apply(this,arguments)})},{key:"report",value:(o=(0,e.Z)(i().mark((function e(t){var n,r,o,s,a,l,u,p,d,y,_,g=arguments;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(o=g.length>1&&void 0!==g[1]?g[1]:"",s=g.length>2&&void 0!==g[2]?g[2]:"",a=g.length>3&&void 0!==g[3]?g[3]:"",l=g.length>4&&void 0!==g[4]?g[4]:{},this.vid||(this.vid=O().vid),u={m:"online_user"===t?"online_user":"event",ls:f({vid:String(this.vid),app_id:this.appId,version:this.sdk_version,ip:this.ip,wx_version:null===(n=this.systemInfo)||void 0===n?void 0:n.version,wx_basic_version:null===(r=this.systemInfo)||void 0===r?void 0:r.SDKVersion},l),vs:{count:1}},"online_user"!==t&&((p={event:t,result:"success"===o?"1":"0",err_code:s.toString()}).message="string"==typeof a?a:JSON.stringify(a),c(u.ls,p)),this.pts.push(u),10!==this.pts.length){e.next=14;break}return d=this.pts.splice(0,10),y=Date.now(),_={pts:d,sign:h()("src=miniapp_sdk&ts=".concat(y)),src:"miniapp_sdk",ts:y},e.next=14,this.request({body:_,url:this.url});case 14:case"end":return e.stop()}}),e,this)}))),function(e){return o.apply(this,arguments)})},{key:"request",value:function(e){return new Promise((function(t,n){wx.request({url:e.url,data:e.body,header:{"content-type":"application/json"},method:"POST",success:function(e){200===e.statusCode?t(e):a.default.error("grafana report fail: ".concat(e.statusCode))},fail:function(e){a.default.error("grafana report fail",JSON.stringify(e)),n(e)}})}))}}]),r}(),v=function(){function e(){(0,t.Z)(this,e),this.ts=-1}return(0,n.Z)(e,[{key:"start",value:function(){return this.ts=(new Date).getTime(),this}},{key:"elapse",value:function(){if(-1===this.ts)throw new Error("timer not started");return(new Date).getTime()-this.ts}}],[{key:"create",value:function(){return new e}}]),e}(),m=__webpack_require__(483),w={ip:"",vid:""};function O(){return w}var E=["https://uap-ap-web-1.agora.io/api/v1","https://uap-ap-web-3.agora.io/api/v1","https://uap-ap-web-2.agoraio.cn/api/v1","https://uap-ap-web-4.agoraio.cn/api/v1"],b="connected",R="disconnected";const S=function(){function e(n,r){(0,t.Z)(this,e),this.serverlist=[],this.option=n,this.index=0,this.isInit=!0,this.state=R,this.hasInvokeClose=!1,this.emitter=r,this.on=this.emitter.on,this.off=this.emitter.off,this.emit=this.emitter.emit}return(0,n.Z)(e,[{key:"connect",value:function(){var e=this,t=this.option.grafanaReport;this.state!==R&&this.close(),function(e){var t=e.grafanaReport,n=e.argusReport,r={command:"convergeAllocateEdge",sid:e.sid,appId:e.appId,token:e.appId,uid:e.uid+"",cname:e.channel,ts:Math.floor(Date.now()/1e3),version:s.VERSION,seq:0,requestId:1};return new Promise((function(i,o){var s=0,c=v.create().start(),l=function(r,i){n.reportJoinCS(e.channel,e.uid,!1,c.elapse(),JSON.stringify(r),i,null),s++,a.default.error("get server list failed, counter:".concat(s," url:").concat(i," "),JSON.stringify(r)),4===s&&(t&&t.report("get_server_list",_,null==r?void 0:r.code,null==r?void 0:r.reason),o(r))},u=function(o){wx.request({url:o,data:{service_name:"miniapp",json_body:JSON.stringify(r)},header:{"content-type":"application/json","X-Packet-URI":61,"X-Packet-Service-Type":0},method:"POST",success:function(r){var s,u,p=r.data;if(r.profile?(s=r.profile.peerIP,w.ip=s):a.default.info("skip user IP report!"),200!==r.statusCode){var h="choose server fail";l({code:r.statusCode,reason:h},o),t&&t.report("choose_server",_,r.statusCode,h)}else{var d=c.elapse(),f=(0,m.transformElapseStr)(d),g=JSON.parse(p.json_body);u=g.vid,w.vid=u;var v=function(e){if(void 0!==e)return e.map((function(e){var t=e.address.split("."),n=t.length;return"wss://miniapp.agoraio.cn/".concat(t[n-4],"-").concat(t[n-3],"-").concat(t[n-2],"-").concat(t[n-1],"/api")}));a.default.error("miniapp service is not enabled for this AppID")}(g.servers);n.reportJoinCS(e.channel,e.uid,!0,d,null,o,v.join(",")),t.report("choose_server",y,"","",{elapse:f}),a.default.info("get server list request success,url:".concat(o,",time:").concat(d,"ms,elapse:").concat(f,",serverlist:").concat(JSON.stringify(v))),i({serverlist:v,url:o})}},fail:function(e){var n=e.errMsg||"choose server fail";l({code:901,reason:n},o),t&&t.report("choose_server",_,901,n)}})};e.apUrl?u(e.apUrl):E.map((function(e,t){u(e)}))}))}(this.option).then((function(t){var n=t.serverlist,r=t.url;a.default.info("websocket get server list final success, url:".concat(r,",serverlist:").concat(JSON.stringify(n))),e.index=0,e.serverlist=n,e.option&&e.option.servers&&(e.serverlist=e.option.servers),e.connectWorker(e.serverlist[e.index])})).catch((function(n){a.default.error("websocket connect failed in get server list ".concat(JSON.stringify(n))),t&&t.report("wxsocket_connect",_,null==n?void 0:n.code,null==n?void 0:n.reason),e.emit&&e.emit("socketError",n)}))}},{key:"connectWorker",value:function(){var e=this;this.state="connecting";var t=this.serverlist[this.index];a.default.info("websocket connect server: ",t);var n=this.option,r=(n.sid,n.channel),i=n.uid,o=n.argusReport,s=n.grafanaReport,c=v.create().start();this.ws=wx.connectSocket({url:t,fail:function(n){var l=JSON.stringify(n);a.default.error("websocket connect worker failed url:".concat(t," "),l),o&&o.reportConnectWS(r,i,!1,c.elapse(),l,null,t),s&&s.report("wxsocket_connect_worker",_,n.statusCode,l,{retry:String(e.index)})},success:function(n){var l=c.elapse(),u=(0,m.transformElapseStr)(l);if(a.default.info("websocket connect worker success,url:".concat(t,",time:").concat(l,"ms,elapse:").concat(u)),e.option.grafanaReport){var p=(0,m.getServerUrlIp)(t);e.option.grafanaReport.setOptions({ip:p})}o&&o.reportConnectWS(r,i,!0,l,null,null,t),s&&s.report("wxsocket_connect_worker",y,"","".concat(t),{elapse:u,retry:String(e.index)})}}),this.ws.onOpen(this._onopen.bind(this)),this.ws.onMessage(this._onmessage.bind(this)),this.ws.onError((function(e){a.default.error("websocket onerror: "+JSON.stringify(e)),o&&o.reportConnectWS(r,i,!1,c.elapse(),JSON.stringify(e),null,t),s&&s.report("wxsocket_connect_worker_on_error",_,"",JSON.stringify(e))})),this.establishWSTimeoutTimer=setTimeout((function(){e.state!==b&&e.connectNextWorker()}),5e3)}},{key:"connectNextWorker",value:function(){var e=this,t=this.option.grafanaReport;this.close().then((function(n){if(a.default.info("websocket connect next worker current:".concat(e.index," total:").concat(e.serverlist.length)),e.index>=e.serverlist.length-1){var r={code:905,reason:"connect websocket failed"};a.default.error("websocket connect next worker failed, all serverlist tried. ",JSON.stringify(r)),e.emit&&e.emit("socketError",{code:r.code,reason:r.reason,wsurl:JSON.stringify(e.serverlist)}),t&&t.report("wxsocket_connect_next_worker",_,r.code,r.reason)}else e.index++,e.connectWorker()}))}},{key:"_onopen",value:function(){a.default.info("websocket onopen"),clearTimeout(this.establishWSTimeoutTimer),this.state=b,this.isInit=!1,this.hasInvokeClose?a.default.info("websocket already invoke ws.Close, will not throw onopen event"):(this.ws.onClose(this._onclose.bind(this)),this.emit&&this.emit("onopen"))}},{key:"_onclose",value:function(e){a.default.info("websocket onclose:"+JSON.stringify(e)),this.emitter.emit("_wsClose"),clearTimeout(this.establishWSTimeoutTimer),this.state=R,e&&"close"==e.reason||this.hasInvokeClose||(this.isInit?this.connectNextWorker():this.emit&&this.emit("onclose",e))}},{key:"_onmessage",value:function(e){if(!this.hasInvokeClose){var t=JSON.parse(null==e?void 0:e.data)||{};"pong"!==(null==t?void 0:t.command)&&a.default.info("websocket receive message: ",JSON.stringify(e)),this.isConnected()&&this.emit&&this.emit("onmessage",e)}}},{key:"isConnected",value:function(){return this.state===b}},{key:"sendMessage",value:function(e){var t=JSON.parse(e)||{};"ping"!==(null==t?void 0:t.command)&&a.default.info("websocket send message: ",e),this.isConnected()&&this.ws&&this.ws.send({data:e})}},{key:"_checkServerList",value:function(e){return e instanceof Array!=0&&0!=e.length}},{key:"destroy",value:function(e){var t=this;this.state!==R&&this.close(),this.on("_wsClose",(function n(){t.off("_wsClose",n),t.serverlist=null,t.ws=null,t.emitter=null,t.on=null,t.off=null,t.emit=null,e&&e()}))}},{key:"close",value:function(){var e=this;return new Promise((function(t,n){return e.state==R?t():(clearTimeout(e.establishWSTimeoutTimer),e.hasInvokeClose=!0,e.state=R,e.ws?void e.ws.close({reason:"close",success:function(){a.default.info("websocket close success"),t()},fail:function(t){a.default.error("websocket close failed: ",JSON.stringify(t));var r=e.option,i=(r.sid,r.channel),o=r.uid,s=r.argusReport,c=r.grafanaReport;n();var l=e.serverlist[e.index];s&&s.reportConnectWS(i,o,!1,0,JSON.stringify(t),null,l),c&&c.report("wxsocket_close",_,"",JSON.stringify(t))},complete:function(){e.ws=null}}):t())}))}}]),e}(),k=function(){function e(n){(0,t.Z)(this,e),this.appId=n.appId,this.channel=n.channel,this.uid=n.uid+"",this.sid=n.sid,this.seq=1,this.requestId=2}return(0,n.Z)(e,[{key:"setSid",value:function(e){this.sid=e}},{key:"_getWorkerManagerMsg",value:function(){return{appId:this.appId,cname:this.channel,uid:this.uid,sid:this.sid,sdkVersion:s.VERSION,seq:++this.seq,requestId:++this.requestId,ts:Math.floor(Date.now()/1e3)}}},{key:"send",value:function(e){var t=this._getWorkerManagerMsg();return t.clientRequest=e,t}},{key:"updatePushUrl",value:function(){var e=this._getWorkerManagerMsg();return e.clientRequest={action:"update_url",role:"publish",uid:+this.uid},e}},{key:"ping",value:function(){return{command:"ping",requestId:++this.requestId,appId:this.appId,cname:this.channel,uid:this.uid+"",sid:this.sid,ts:Math.floor(Date.now()/1e3)}}},{key:"ping2",value:function(){var e=this._getWorkerManagerMsg();return e.clientRequest={action:"ping"},e}},{key:"setRole",value:function(e){var t=this._getWorkerManagerMsg();return t.clientRequest={action:"set_role",role:e},t}},{key:"rejoin",value:function(e,t,n,r,i,o,s,a,c){var l=this._getWorkerManagerMsg();return l.clientRequest={action:"join",role:o,appId:e,customAudioCodec:a,key_vocs:r||e,key_vos:r||e,channel_name:t,uid:n+"",known_speakers:i,clientType:"undefined"==typeof qq?"wechat":"qq",audio_only:s,uidType:c},l}},{key:"join",value:function(e,t,n,r,i,o,a,c,l,u){var p=this._getWorkerManagerMsg();return p.clientRequest={action:"join",role:i,appId:e,customAudioCodec:l,key_vocs:r||e,key_vos:r||e,channel_name:t,uid:n+"",vid:O().vid.toString(),device:o,os:a,version:s.SDK_VERSION,clientType:"undefined"==typeof qq?"wechat":"qq",audio_only:c,uidType:u},p}},{key:"muteLocal",value:function(e,t){var n=this._getWorkerManagerMsg();return n.clientRequest={action:"mute_local",uid:+e,target:t,mute:!0},n}},{key:"unmuteLocal",value:function(e,t){var n=this._getWorkerManagerMsg();return n.clientRequest={action:"mute_local",uid:+e,target:t,mute:!1},n}},{key:"mute",value:function(e,t){var n=this._getWorkerManagerMsg();return n.clientRequest={action:"mute",uid:+e,target:t},n}},{key:"unmute",value:function(e,t){var n=this._getWorkerManagerMsg();return n.clientRequest={action:"unmute",uid:+e,target:t},n}},{key:"publish",value:function(e){var t=this._getWorkerManagerMsg();return t.clientRequest={action:"publish",uid:+e},t}},{key:"unpublish",value:function(e){var t=this._getWorkerManagerMsg();return t.clientRequest={action:"unpublish",uid:+e},t}},{key:"subscribe",value:function(e,t){var n=this._getWorkerManagerMsg();return n.clientRequest={action:"subscribe",uid:+e,options:{audio:t.audio,video:t.video}},n}},{key:"unsubscribe",value:function(e){var t=this._getWorkerManagerMsg();return t.clientRequest={action:"unsubscribe",uid:[+e]},t}},{key:"setRemoteVideoStreamType",value:function(e,t){var n=this._getWorkerManagerMsg();return n.clientRequest={action:"set_remote_stream_type",uid:+e,type:t},n}},{key:"renewToken",value:function(e){var t=this._getWorkerManagerMsg();return t.clientRequest={action:"update_key",key_vos:e},t}},{key:"leave",value:function(e){var t=this._getWorkerManagerMsg();return t.clientRequest={action:"leave",uid:+e},t}}]),e}();function P(e){return{all:e=e||new Map,on:function(t,n){var r=e.get(t);r?r.push(n):e.set(t,[n])},off:function(t,n){var r=e.get(t);r&&(n?r.splice(r.indexOf(n)>>>0,1):e.set(t,[]))},emit:function(t,n){var r=e.get(t);r&&r.slice().map((function(e){e(n)})),(r=e.get("*"))&&r.slice().map((function(e){e(t,n)}))}}}var I=__webpack_require__(500),A=__webpack_require__.n(I);const T=function(){function r(e,n){(0,t.Z)(this,r),this.appId=e.appId,this.channel=e.channel,this.uid=e.uid,this.sid=e.sid,this.role=e.role,this.channelKey=e.channelKey,this.clientId="client",this.option=e,this.timers=new Set,this.grafanaReport=e.grafanaReport,this.argusReport=e.argusReport,this.audioCodec=e.audioCodec,this.uidType=e.uidType,this.clientEmitter=n,this.emitter=new P,this.on=this.emitter.on,this.off=this.emitter.off,this.emit=this.emitter.emit,this.join=this.join.bind(this),this.msgManager=new k(e)}var o,s,c;return(0,n.Z)(r,[{key:"connect",value:function(){var e=this;return new Promise((function(t,n){e.ws=new S(e.option,e.emitter),e.ws.connect(),e.on("onmessage",e._onMessage.bind(e)),e.on("socketError",(function(t){n(t),a.default.error("worker socket error: ",JSON.stringify(t)),e.grafanaReport&&e.grafanaReport.report("worker_connect_socket_error",_,"",JSON.stringify(t))})),e.on("onopen",(function n(){e.off&&e.off("onopen",n),e._ping(),t()})),e.on("onclose",(function(t){a.default.error("worker on close: ",JSON.stringify(t)),e.ws=null,e.clientEmitter.emit("error",{code:904,reason:"websocket disconnected"}),e.grafanaReport&&e.grafanaReport.report("worker_connect_on_close",_,"",JSON.stringify(t))}))}))}},{key:"_onMessage",value:function(e){if(e&&e.data){var t=JSON.parse(e.data);if(t&&"pong"!==t.command&&(a.default.info("worker onmessage: ",t),this.argusReport.reportServerEvent(this.channel,this.uid,!0,0,"serverEvent",t)),t.requestId&&this.emit(t.requestId,t),"serverStatus"===t.command){if(t.code&&200!==t.code){if(this.grafanaReport&&this.grafanaReport.report("worker_on_message",_,t.code,null==t?void 0:t.reason),503===t.code)return;a.default.error("worker onmessage error: ",JSON.stringify(t)),this.clientEmitter.emit("error",{code:t.code,reason:t.reason||"server error"})}if(t.serverStatus){a.default.info("Receive message from server: ".concat(JSON.stringify(t.serverStatus)));var n=t.serverStatus.action;if("audio-mute"==n)return t.serverStatus.mute?this.clientEmitter.emit("mute-audio",{uid:t.serverStatus.uid}):this.clientEmitter.emit("unmute-audio",{uid:t.serverStatus.uid});if("video-mute"==n)return t.serverStatus.mute?this.clientEmitter.emit("mute-video",{uid:t.serverStatus.uid}):this.clientEmitter.emit("unmute-video",{uid:t.serverStatus.uid});if("key-expired"===n)return this.clientEmitter.emit("token-privilege-did-expire");if("key-will-expire"===n)return this.clientEmitter.emit("token-privilege-will-expire");if("client-is-banned-by-server"===n)return this.clientEmitter.emit("client-banned");this.clientEmitter.emit(n,t.serverStatus)}}}}},{key:"_sendMessage",value:function(e){var t=this;if(this.ws)return new Promise((function(n,r){if(!t.isWSConnected())return r({code:904,reason:"websocket disconnected",wsurl:t.getWSUrl()});"ping"!==e.command&&a.default.info("worker send message: ",e);var i,o=e?e.requestId:null,s=function e(s){if(t.ws)return t.off(o,e),clearTimeout(i),t.timers.delete(i),200==s.code?n(s.serverResponse):r({code:s.code,reason:s.msg||s.reason,serverResponse:s.serverResponse,wsurl:t.getWSUrl()})};if(!o)return r({code:902,reason:"no requestid"});t.ws.sendMessage(JSON.stringify(e)),t.on(o,s),i=setTimeout((function(){return s({code:903,reason:"time out"})}),1e4),t.timers.add(i)}))}},{key:"_ping",value:function(){var e=this;this.pingTimer=setInterval((function(){e.ws.sendMessage(JSON.stringify(e.msgManager.ping()))}),3e3)}},{key:"setRole",value:function(e){return this._sendMessage(this.msgManager.setRole(e))}},{key:"rejoin",value:function(e,t){return this._sendMessage(this.msgManager.rejoin(this.appId,this.channel,this.uid,this.channelKey,e,this.role,t,this.audioCodec,this.uidType))}},{key:"join",value:function(e,t,n){return this._sendMessage(this.msgManager.join(this.appId,this.channel,this.uid,this.channelKey,this.role,e,t,n,this.audioCodec,this.uidType))}},{key:"send",value:function(e){return this._sendMessage(this.msgManager.send(e))}},{key:"updatePushUrl",value:function(){return this._sendMessage(this.msgManager.updatePushUrl())}},{key:"publish",value:function(){return this._sendMessage(this.msgManager.publish(this.uid))}},{key:"unpublish",value:function(){return this._sendMessage(this.msgManager.unpublish(this.uid))}},{key:"subscribe",value:function(e,t){return this._sendMessage(this.msgManager.subscribe(e,t))}},{key:"unsubscribe",value:function(e){return this._sendMessage(this.msgManager.unsubscribe(e))}},{key:"setRemoteVideoStreamType",value:function(e,t){return this._sendMessage(this.msgManager.setRemoteVideoStreamType(e,t))}},{key:"mute",value:function(e,t){return this._sendMessage(this.msgManager.mute(e,t))}},{key:"unmute",value:function(e,t){return this._sendMessage(this.msgManager.unmute(e,t))}},{key:"muteLocal",value:function(e){return this._sendMessage(this.msgManager.muteLocal(this.uid,e))}},{key:"unmuteLocal",value:function(e){return this._sendMessage(this.msgManager.unmuteLocal(this.uid,e))}},{key:"renewToken",value:function(e){return this._sendMessage(this.msgManager.renewToken(e))}},{key:"leave",value:function(){return this._sendMessage(this.msgManager.leave(this.uid))}},{key:"isWSConnected",value:function(){return!!this.ws&&this.ws.isConnected()}},{key:"getWSUrl",value:function(){return this.ws?this.ws.serverlist[this.ws.index]:""}},{key:"destroy",value:function(){var e=this;return new Promise((function(t,n){clearInterval(e.pingTimer),e.timers.size&&(e.timers.forEach((function(e){clearInterval(e)})),e.timers.clear()),e.ws?e.ws.destroy((function(){e.ws=null,e.emitter=null,e.on=null,e.off=null,e.emit=null,t()})):t()}))}},{key:"startChannelMediaRelay",value:(c=(0,e.Z)(i().mark((function e(t){var n,r,o,s,c,l=this;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.channelMediaRelayController){e.next=2;break}throw new I.ChannelMediaError("RELAY_ALREADY_START","",I.CHANNEL_MEDIA_RELAY_ERROR.RELAY_ALREADY_START);case 2:return n=function(e){l.clientEmitter.emit("channel-media-relay-event",{code:e})},r=function(e,t,n){e===I.CHANNEL_MEDIA_RELAY_STATE.RELAY_STATE_FAILURE&&t===I.CHANNEL_MEDIA_RELAY_ERROR.SERVER_CONNECTION_LOST&&(l.channelMediaRelayController.dispose(),l.channelMediaRelayController=null),l.clientEmitter.emit("channel-media-relay-state",{state:e,code:t,data:n})},o={token:this.appId,appId:this.appId,cname:this.channel,uid:this.uid,sid:this.sid,clientId:this.clientId},this.channelMediaRelayController=new(A())(o,this.clientId),this.channelMediaRelayController.on("event",n),this.channelMediaRelayController.on("state",r),e.prev=8,e.next=11,this.channelMediaRelayController.startChannelMediaRelay(t);case 11:e.next=23;break;case 13:throw e.prev=13,e.t0=e.catch(8),a.default.error("[".concat(this.clientId,"] startChannelMediaRelay exception: ").concat(JSON.stringify(e.t0))),s=I.CHANNEL_MEDIA_RELAY_STATE.RELAY_STATE_FAILURE,"",c=e.t0 instanceof I.ChannelMediaError?"SetSourceChannelStatus"===e.t0.data||e.t0.data&&e.t0.data.serverResponse&&"SetSourceChannel"===e.t0.data.serverResponse.command?"FAILED_JOIN_SRC":"SetDestChannelStatus"===e.t0.data||e.t0.data&&e.t0.data.serverResponse&&"SetDestChannel"===e.t0.data.serverResponse.command?"FAILED_JOIN_DEST":e.t0.data&&e.t0.data.serverResponse&&"StartPacketTransfer"===e.t0.data.serverResponse.command?"FAILED_PACKET_SENT_TO_DEST":e.t0.message===I.CHANNEL_MEDIA_ERROR.REQUEST_TIMEOUT||e.t0.message===I.CHANNEL_MEDIA_ERROR.WAIT_STATUS_TIMEOUT?"SERVER_NO_RESPONSE":e.t0.message===I.CHANNEL_MEDIA_ERROR.REQUEST_FAILED||e.t0.message===I.CHANNEL_MEDIA_ERROR.WAIT_STATUS_ERROR?"SERVER_ERROR_RESPONSE":e.t0.message===I.CHANNEL_MEDIA_ERROR.AP_REQUEST_TIMEOUT?"NO_RESOURCE_AVAILABLE":e.t0.message===I.CHANNEL_MEDIA_ERROR.WS_ABORT||e.t0.message===I.CHANNEL_MEDIA_ERROR.AP_REQUEST_ABORT?"OPERATION_ABORT":"INTERNAL_ERROR":"INTERNAL_ERROR",this.clientEmitter.emit("channel-media-relay-state",{state:s,code:I.CHANNEL_MEDIA_RELAY_ERROR[c]}),this.channelMediaRelayController&&(this.channelMediaRelayController.dispose(),this.channelMediaConfig=null,this.channelMediaRelayController=null),this.clientEmitter.emit("channel-media-relay-state",{state:I.CHANNEL_MEDIA_RELAY_STATE.RELAY_STATE_IDLE}),new I.ChannelMediaError(c,null,I.CHANNEL_MEDIA_RELAY_ERROR[c]);case 23:this.clientEmitter.emit("channel-media-relay-state",{state:I.CHANNEL_MEDIA_RELAY_STATE.RELAY_STATE_RUNNING,code:I.CHANNEL_MEDIA_RELAY_ERROR.RELAY_OK}),this.channelMediaConfig=t;case 25:case"end":return e.stop()}}),e,this,[[8,13]])}))),function(e){return c.apply(this,arguments)})},{key:"updateChannelMediaRelay",value:(s=(0,e.Z)(i().mark((function e(t){var n,r;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.channelMediaRelayController){e.next=2;break}throw new I.ChannelMediaError("RELAY_NOT_START",null,I.CHANNEL_MEDIA_RELAY_ERROR.RELAY_NOT_START);case 2:return e.prev=2,e.next=5,this.channelMediaRelayController.updateChannelMediaRelay(t);case 5:e.next=18;break;case 7:throw e.prev=7,e.t0=e.catch(2),a.default.debug("[".concat(this.clientId,"] updateChannelMediaRelay exception: ").concat(JSON.stringify(e.t0))),n=I.CHANNEL_MEDIA_RELAY_STATE.RELAY_STATE_FAILURE,"",r=e.t0 instanceof I.ChannelMediaError?e.t0.message===I.CHANNEL_MEDIA_ERROR.REQUEST_TIMEOUT||e.t0.message===I.CHANNEL_MEDIA_ERROR.WAIT_STATUS_TIMEOUT?"SERVER_NO_RESPONSE":e.t0.message===I.CHANNEL_MEDIA_ERROR.REQUEST_FAILED||e.t0.message===I.CHANNEL_MEDIA_ERROR.WAIT_STATUS_ERROR?"SERVER_ERROR_RESPONSE":e.t0.message===I.CHANNEL_MEDIA_ERROR.WS_ABORT||e.t0.message===I.CHANNEL_MEDIA_ERROR.AP_REQUEST_ABORT?"OPERATION_ABORT":"INTERNAL_ERROR":"INTERNAL_ERROR",this.clientEmitter.emit("channel-media-relay-event",{code:I.CHANNEL_MEDIA_RELAY_EVENT.PACKET_UPDATE_DEST_CHANNEL_REFUSED}),this.clientEmitter.emit("channel-media-relay-state",{state:n,code:I.CHANNEL_MEDIA_RELAY_ERROR[r]}),this.channelMediaRelayController&&(this.channelMediaRelayController.dispose(),this.channelMediaConfig=null,this.channelMediaRelayController=null),this.clientEmitter.emit("channel-media-relay-state",{state:I.CHANNEL_MEDIA_RELAY_STATE.RELAY_STATE_IDLE}),new I.ChannelMediaError(r,null,I.CHANNEL_MEDIA_RELAY_ERROR[r]);case 18:this.channelMediaConfig=t;case 19:case"end":return e.stop()}}),e,this,[[2,7]])}))),function(e){return s.apply(this,arguments)})},{key:"stopChannelMediaRelay",value:(o=(0,e.Z)(i().mark((function e(){var t,n;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.channelMediaRelayController){e.next=2;break}throw new I.ChannelMediaError("RELAY_NOT_START",null,I.CHANNEL_MEDIA_RELAY_ERROR.RELAY_NOT_START);case 2:return e.prev=2,e.next=5,this.channelMediaRelayController.stopChannelMediaRelay();case 5:e.next=17;break;case 7:throw e.prev=7,e.t0=e.catch(2),a.default.debug("[".concat(this.clientId,"] stopChannelMediaRelay exception: ").concat(JSON.stringify(e.t0))),t=I.CHANNEL_MEDIA_RELAY_STATE.RELAY_STATE_FAILURE,"",n=e.t0 instanceof I.ChannelMediaError?e.t0.message===I.CHANNEL_MEDIA_ERROR.REQUEST_TIMEOUT||e.t0.message===I.CHANNEL_MEDIA_ERROR.WAIT_STATUS_TIMEOUT?"SERVER_NO_RESPONSE":e.t0.message===I.CHANNEL_MEDIA_ERROR.REQUEST_FAILED||e.t0.message===I.CHANNEL_MEDIA_ERROR.WAIT_STATUS_ERROR?"SERVER_ERROR_RESPONSE":"INTERNAL_ERROR":"INTERNAL_ERROR",this.clientEmitter.emit("channel-media-relay-state",{state:t,code:I.CHANNEL_MEDIA_RELAY_ERROR[n]}),this.channelMediaRelayController&&(this.channelMediaRelayController.dispose(),this.channelMediaConfig=null,this.channelMediaRelayController=null),this.emit("channel-media-relay-state",{state:I.CHANNEL_MEDIA_RELAY_STATE.RELAY_STATE_IDLE}),new I.ChannelMediaError(n,null,I.CHANNEL_MEDIA_RELAY_ERROR[n]);case 17:this.channelMediaConfig=null,this.channelMediaRelayController=null;case 19:case"end":return e.stop()}}),e,this,[[2,7]])}))),function(){return o.apply(this,arguments)})}]),r}();var C={videoBitrate:"Miniapp_SDK_Pusher_Video_Bitrate",audioBitrate:"Miniapp_SDK_Pusher_Audio_Bitrate",videoFPS:"Miniapp_SDK_Pusher_Video_FPS",videoGOP:"Miniapp_SDK_Pusher_Video_GOP",netSpeed:"Miniapp_SDK_Pusher_Net_Speed",videoCache:"Miniapp_SDK_Pusher_Video_Cache",audioCache:"Miniapp_SDK_Pusher_Audio_Cache",videoWidth:"Miniapp_SDK_Pusher_Video_Width",videoHeight:"Miniapp_SDK_Pusher_Video_Height",netJitter:"Miniapp_SDK_Pusher_Net_Jitter",netQualityLevel:"Miniapp_SDK_Pusher_Net_QualityLevel"},N={videoBitrate:"Miniapp_SDK_Player_Video_Bitrate",audioBitrate:"Miniapp_SDK_Player_Audio_Bitrate",videoFPS:"Miniapp_SDK_Player_Video_FPS",videoGOP:"Miniapp_SDK_Player_Video_GOP",netSpeed:"Miniapp_SDK_Player_Net_Speed",videoCache:"Miniapp_SDK_Player_Video_Cache",audioCache:"Miniapp_SDK_Player_Audio_Cache",vDecCacheSize:"Miniapp_SDK_Player_V_Dec_Cache_Size",vSumCacheSize:"Miniapp_SDK_Player_V_Sum_Cache_Size",avPlayInterval:"Miniapp_SDK_Player_AV_Play_Interval",avRecvInterval:"Miniapp_SDK_Player_AV_Recv_Interval",audioCacheThreshold:"Miniapp_SDK_Player_Audio_Cache_Threshold",videoWidth:"Miniapp_SDK_Player_Video_Width",videoHeight:"Miniapp_SDK_Player_Video_Height",netJitter:"Miniapp_SDK_Player_Net_Jitter",netQualityLevel:"Miniapp_SDK_Player_Net_QualityLevel"},L=__webpack_require__(699),M=__webpack_require__.n(L),j=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:10;if("function"!=typeof e)throw Error("request must be function");var n=function(e,t){!function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;if(null==e)e=1;else if(0===e)throw new Error("Concurrency must not be zero")}(t);var n=[],r=[];return{concurrency:t,push:function(e,t){var r=this;n.push({task:e,callback:t}),setTimeout((function(){r.process()}),0)},process:function(){for(var e=this,t=function(){var t,i=n.shift();r.push(i),function(e,t){e(t)}(i.task,(t=function(){e.pull(i),"function"==typeof i.callback&&i.callback.apply(i,arguments),e.process()},function(){if(null===t)throw new Error("Callback was already called");var e=t;return t=null,e.apply(void 0,arguments)}))};this.concurrency>r.length&&n.length;)t()},pull:function(e){var t=r.indexOf(e);-1!==t&&r.splice(t,1)}}}(0,t);return function(t){n.push((function(n){var r=t.complete;t.complete=function(){n(),"function"==typeof r&&r.apply(void 0,arguments)},e(t)}))}}(wx.request,2);function D(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function x(e){for(var t=1;t4&&void 0!==arguments[4]&&arguments[4],c=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0,l=arguments.length>6?arguments[6]:void 0,u=arguments.length>7?arguments[7]:void 0;if("function"==typeof s){var p=l,h=u;l=s,u=c,s=p||!1,c=h||0}return new Promise((function(p,h){if(i._dealSid(),i.grafanaReport.onlineUser(),i.worker)return i._startNetworkJudge(),l&&l(),p();if(e){if("string"!=typeof e||"null"===e.toLowerCase()){var d=new Error("Invalid channelKey");return a.default.error("client rejoin channel failed: ".concat(d.message)),u&&u(d),void h(d)}}else e=i.appId;if(!t||"string"!=typeof t||"null"===t.toLowerCase()||t.length>128){var f=new Error("Invalid channel");return a.default.error("client rejoin channel failed: ".concat(f.message)),u&&u(f),void h(f)}if("boolean"!=typeof s){var g=new Error("isAudioOnly should be boolean");return a.default.error("client rejoin channel failed: ".concat(g.message)),u&&u(g),h(g),void i.grafanaReport.report("join",_,"",g.message)}if(1==c){if(!n.trim()){var w=new Error("uid empty");return a.default.error("client rejoin channel failed: ".concat(w.message)),u&&u(w),void h(w)}i.uid=n}else if(i.uid=n||(0,o.random)(1e7),i.uid=Number.parseInt(i.uid),!(0,o.is32Uint)(i.uid)){var O=new Error("Invalid uid type");return a.default.error("client rejoin channel failed: ".concat(O.message)),u&&u(O),void h(O)}i.channel=t,i.worker=new T({appId:i.appId,channel:i.channel,uid:i.uid,sid:i.sid,role:i.role,servers:i.servers,apUrl:i.apUrl,channelKey:e,grafanaReport:i.grafanaReport,argusReport:i.argusReport,audioCodec:i.audioCodec,uidType:c},i.emitter);var E=v.create().start();i.worker.connect().then((function(){return i.worker.rejoin(r,s)})).then((function(e){setTimeout((function(){a.default.info("client rejoin channel success"),l&&l(i.uid),p(i.uid),i.argusReport.reportRejoin(i.channel,i.uid,!0,E.elapse(),null,i.appId,i.worker&&i.worker.getWSUrl()),i.grafanaReport.report("join",y),i._startNetworkJudge()}),1),e&&e.uid&&(i.uid=e.uid,i.worker.uid=e.uid)})).catch((function(e){i.destroy(),a.default.error("client rejoin channel failed: ".concat((0,m.stringifyErr)(e))),u&&u(e),h(e),i.argusReport.reportRejoin(i.channel,i.uid,!1,E.elapse(),JSON.stringify(e),i.appId,i.worker&&i.worker.getWSUrl()),i.grafanaReport.report("join",_,e.code,null==e?void 0:e.reason)}))}))}},{key:"join",value:function(e,t,n){var r=this,i=arguments.length>3&&void 0!==arguments[3]&&arguments[3],s=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0,c=arguments.length>5?arguments[5]:void 0,l=arguments.length>6?arguments[6]:void 0;if("function"==typeof i){var u=c,p=l;c=i,l=s,i=u||!1,s=p||0}return new Promise((function(u,p){if(r._dealSid(),r.grafanaReport.onlineUser(),r.worker)return a.default.info("client join channel success"),c&&c(),r._startNetworkJudge(),u();if(e){if("string"!=typeof e||"null"===e.toLowerCase()){var h=new Error("Invalid channelKey");return a.default.error("client join channel failed: ".concat(h.message)),l&&l(h),p(h),void r.grafanaReport.report("join",_,"",h.message)}}else e=r.appId;if(!t||"string"!=typeof t||"null"===t.toLowerCase()||t.length>128){var d=new Error("Invalid channel");return a.default.error("client join channel failed: ".concat(d.message)),l&&l(d),p(d),void r.grafanaReport.report("join",_,"",d.message)}if("boolean"!=typeof i){var f=new Error("isAudioOnly should be boolean");return a.default.error("client join channel failed: ".concat(f.message)),l&&l(f),p(f),void r.grafanaReport.report("join",_,"",f.message)}if(1==s){if(!n.trim()){var g=new Error("uid empty");return a.default.error("client join channel failed: ".concat(g.message)),l&&l(g),p(g),void r.grafanaReport.report("join",_,"",g.message)}r.uid=n}else if(r.uid=n||(0,o.random)(1e7),r.uid=Number.parseInt(r.uid),!(0,o.is32Uint)(r.uid)){var w=new Error("Invalid uid type");return a.default.error("client join channel failed: ".concat(w.message)),l&&l(w),p(w),void r.grafanaReport.report("join",_,"",w.message)}r.channel=t,r.worker=new T({appId:r.appId,channel:r.channel,uid:r.uid,sid:r.sid,role:r.role,servers:r.servers,apUrl:r.apUrl,channelKey:e,grafanaReport:r.grafanaReport,argusReport:r.argusReport,audioCodec:r.audioCodec,uidType:s},r.emitter);var O=v.create().start();r.worker.connect().then((function(){return r.worker.join(r.systemInfo.model,r.systemInfo.system,i)})).then((function(e){var t=O.elapse(),n=(0,m.transformElapseStr)(t);setTimeout((function(){a.default.info("client join channel success,time:".concat(t,"ms,elapse:").concat(n)),c&&c(r.uid),u(r.uid),r._startNetworkJudge(),r.argusReport.reportJoin(r.channel,r.uid,!0,t),r.grafanaReport.report("join",y,"","",{elapse:n})}),1),e&&e.uid&&(r.uid=e.uid,r.worker.uid=e.uid)})).catch((function(e){r.destroy(),a.default.error("client join channel failed: ".concat((0,m.stringifyErr)(e))),l&&l(e),p(e),r.argusReport.reportJoin(r.channel,r.uid,!1,O.elapse(),JSON.stringify(e)),r.grafanaReport.report("join",_,null==e?void 0:e.code,null==e?void 0:e.reason)}))}))}},{key:"publish",value:function(e,t){var n=this;return new Promise((function(r,i){n._checkWorker();var o=v.create().start();n.worker.publish().then((function(t){n.pushUrl=t.url,setTimeout((function(){a.default.info("client publish url: ".concat(t.url," success")),e&&e(t.url),r(t.url),n.argusReport.reportPublish(t.url,n.channel,n.uid,!0,o.elapse()),n.grafanaReport.report("publish",y)}),1)})).catch((function(e){a.default.error("client publish failed: ".concat((0,m.stringifyErr)(e))),t&&t(e),i(e),n.argusReport.reportPublish(null,n.channel,n.uid,!1,o.elapse(),JSON.stringify(e)),n.grafanaReport.report("publish",_,e.code,null==e?void 0:e.reason)}))}))}},{key:"unpublish",value:function(e,t){var n=this;return new Promise((function(r,i){n._checkWorker();var o=v.create().start();n.worker.unpublish().then((function(t){n.pushUrl=null,setTimeout((function(){a.default.info("client unpublish success"),e&&e(),r(),n.argusReport.reportUnPublish(n.channel,n.uid,!0,o.elapse()),n.grafanaReport.report("unpublish",y)}),1)})).catch((function(e){a.default.error("client unpublish failed: ".concat((0,m.stringifyErr)(e))),t&&t(e),i(e),n.argusReport.reportUnPublish(n.channel,n.uid,!1,o.elapse(),JSON.stringify(e)),n.grafanaReport.report("unpublish",_,e.code,null==e?void 0:e.reason)}))}))}},{key:"subscribe",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{audio:!0,video:!0},r=arguments.length>2?arguments[2]:void 0,i=arguments.length>3?arguments[3]:void 0;if("function"==typeof n){var o=i;i=r,r=n,n=o||{audio:!0,video:!0}}return new Promise((function(o,s){t._checkUid(e),t._checkWorker();var c=v.create().start();t.worker.subscribe(e,n).then((function(n){t.playUrls.set(e,n.url),setTimeout((function(){a.default.info("client stream ".concat(e," subscribed successful")),r&&r(n.url,n.rotation),o({url:n.url,rotation:n.rotation}),t.argusReport.reportSubscribe(n.url,e,t.channel,t.uid,!0,c.elapse()),t.grafanaReport.report("subscribe",y)}),1)})).catch((function(n){a.default.error("client stream ".concat(e," subscribed failed: ").concat((0,m.stringifyErr)(n))),i&&i(n),s(n),t.argusReport.reportSubscribe(null,e,t.channel,t.uid,!1,c.elapse(),JSON.stringify(n)),t.grafanaReport.report("subscribe",_,n.code,null==n?void 0:n.reason)}))}))}},{key:"unsubscribe",value:function(e,t,n){var r=this;return new Promise((function(i,o){r._checkUid(e),r._checkWorker();var s=v.create().start();r.worker.unsubscribe(e).then((function(n){r.playUrls.delete(e),setTimeout((function(){a.default.info("client unsubscribe ".concat(e," successful")),t&&t(),i(),r.argusReport.reportUnSubscribe(e,r.channel,r.uid,!0,s.elapse(),null),r.grafanaReport.report("unsubscribe",y)}),1)})).catch((function(t){a.default.error("client unsubscribe ".concat(e," failed: ").concat((0,m.stringifyErr)(t))),n&&n(t),o(t),r.argusReport.reportUnSubscribe(e,r.channel,r.uid,!1,s.elapse(),JSON.stringify(t)),r.grafanaReport.report("unsubscribe",_,t.code,null==t?void 0:t.reason)}))}))}},{key:"mute",value:function(e,t,n,r){var i=this;return new Promise((function(o,s){if(i._checkUid(e),i._checkWorker(),"video"!==t&&"audio"!==t&&"all"!==t){var c=new Error('target should be "video", "audio" or "all"');return a.default.error("client mute ".concat(e," failed: ").concat(c.message)),r&&r(c),void s(c)}var l=v.create().start();i.worker.mute(e,t).then((function(r){setTimeout((function(){a.default.info("client mute ".concat(e," ").concat(t," success")),n&&n(),o(),i.argusReport.reportMuteRemote(i.channel,i.uid,!0,l.elapse(),null,e,i.targetMap[t],1),i.grafanaReport.report("mute",y)}),1)})).catch((function(n){a.default.error("client mute ".concat(e," ").concat(t," failed: ").concat((0,m.stringifyErr)(n))),r&&r(n),s(n),i.argusReport.reportMuteRemote(i.channel,i.uid,!1,l.elapse(),JSON.stringify(n),e,i.targetMap[t],1),i.grafanaReport.report("mute",_,n.code,null==n?void 0:n.reason)}))}))}},{key:"unmute",value:function(e,t,n,r){var i=this;return new Promise((function(o,s){if(i._checkUid(e),i._checkWorker(),"video"!==t&&"audio"!==t&&"all"!==t){var c=new Error('target should be "video", "audio" or "all"');return a.default.error("client unmute ".concat(e," ").concat(t," failed: ").concat(c.message)),r&&r(c),void s(c)}var l=v.create().start();i.worker.unmute(e,t).then((function(r){setTimeout((function(){a.default.info("client unmute ".concat(e," ").concat(t," success")),n&&n(),o(),i.argusReport.reportMuteRemote(i.channel,i.uid,!0,l.elapse(),null,e,i.targetMap[t],-1),i.grafanaReport.report("unmute",y)}),1)})).catch((function(n){a.default.error("client unmute ".concat(e," ").concat(t," failed: ").concat((0,m.stringifyErr)(n))),r&&r(n),s(n),i.argusReport.reportMuteRemote(i.channel,i.uid,!1,l.elapse(),JSON.stringify(n),e,i.targetMap[t],-1),i.grafanaReport.report("unmute",_,n.code,null==n?void 0:n.reason)}))}))}},{key:"setRemoteVideoStreamType",value:function(e,t,n,r){var i=this;return new Promise((function(o,s){i._checkUid(e),i._checkWorker();var c=v.create().start();i.worker.setRemoteVideoStreamType(e,t).then((function(r){setTimeout((function(){a.default.info("client set remoteVideoStreamType ".concat(e," ").concat(t," success")),n&&n(),o(),i.argusReport.reportSetRemoteStreamType(i.channel,i.uid,!0,c.elapse(),null,t),i.grafanaReport.report("set_remote_stream_type",y)}),1)})).catch((function(n){a.default.error("client set remoteVideoStreamType ".concat(e," ").concat(t," failed: ").concat((0,m.stringifyErr)(n))),r&&r(n),s(n),i.argusReport.reportSetRemoteStreamType(i.channel,i.uid,!1,c.elapse(),JSON.stringify(n),t),i.grafanaReport.report("set_remote_stream_type",_,n.code,null==n?void 0:n.reason)}))}))}},{key:"renewToken",value:function(e,t,n){var r=this;return new Promise((function(i,o){r._checkWorker();var s=v.create().start();r.worker.renewToken(e).then((function(e){setTimeout((function(){a.default.info("client renew token success"),t&&t(),i(),r.argusReport.reportRenewToken(r.channel,r.uid,!0,s.elapse(),null),r.grafanaReport.report("renew_token",y)}),1)})).catch((function(e){a.default.error("client renew token failed: ".concat((0,m.stringifyErr)(e))),n&&n(e),o(e),r.argusReport.reportRenewToken(r.channel,r.uid,!1,s.elapse(),JSON.stringify(e)),r.grafanaReport.report("renew_token",_,e.code,null==e?void 0:e.reason)}))}))}},{key:"muteLocal",value:function(e,t,n){var r=this;return new Promise((function(i,o){if(r._checkWorker(),"video"!==e&&"audio"!==e&&"all"!==e){var s=new Error('target should be "video", "audio" or "all"');return a.default.error("client muteLocal failed: ".concat(s.message)),n&&n(s),void o(s)}var c=v.create().start();r.worker.muteLocal(e).then((function(n){setTimeout((function(){a.default.info("client muteLocal ".concat(e," success")),t&&t(),i(),r.argusReport.reportMuteLocal(r.channel,r.uid,!0,c.elapse(),null,r.targetMap[e],1),r.grafanaReport.report("mute_local",y)}),1)})).catch((function(t){a.default.error("client muteLocal ".concat(e," failed: ").concat((0,m.stringifyErr)(t))),n&&n(t),o(t),r.argusReport.reportMuteLocal(r.channel,r.uid,!1,c.elapse(),JSON.stringify(t),r.targetMap[e],1),r.grafanaReport.report("mute_local",_,t.code,null==t?void 0:t.reason)}))}))}},{key:"unmuteLocal",value:function(e,t,n){var r=this;return new Promise((function(i,o){if(r._checkWorker(),"video"!==e&&"audio"!==e&&"all"!==e){var s=new Error('target should be "video", "audio" or "all"');return a.default.error("client unmuteLocal failed: ".concat(s.message)),n&&n(s),void o(s)}var c=v.create().start();r.worker.unmuteLocal(e).then((function(n){setTimeout((function(){a.default.info("client unmuteLocal ".concat(e," success")),t&&t(),i(),r.argusReport.reportMuteLocal(r.channel,r.uid,!0,c.elapse(),null,r.targetMap[e],-1),r.grafanaReport.report("unmute_local",y)}),1)})).catch((function(t){a.default.error("client unmuteLocal ".concat(e," failed: ").concat((0,m.stringifyErr)(t))),n&&n(t),o(t),r.argusReport.reportMuteLocal(r.channel,r.uid,!1,c.elapse(),JSON.stringify(t),r.targetMap[e],-1),r.grafanaReport.report("unmute_local",_,t.code,null==t?void 0:t.reason)}))}))}},{key:"leave",value:function(t,n){var r=this;return new Promise((function(o,s){if(r.worker&&r.worker.isWSConnected()){var c=v.create().start();r.worker.leave().then(function(){var n=(0,e.Z)(i().mark((function e(n){return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r.argusReport.reportLeave(r.channel,r.uid,!0,c.elapse()),r.grafanaReport.report("leave",y),e.next=4,r.destroy();case 4:setTimeout((function(){a.default.info("client leave success"),t&&t(),o()}),1);case 5:case"end":return e.stop()}}),e)})));return function(e){return n.apply(this,arguments)}}()).catch((function(e){a.default.error("client leave failed: ".concat((0,m.stringifyErr)(e))),n&&n(e),s(e),r.argusReport.reportLeave(r.channel,r.uid,!1,c.elapse(),JSON.stringify(e)),r.grafanaReport.report("leave",_,e.code,null==e?void 0:e.reason)}))}else a.default.info("client leave success without worker"),t&&t(),o(),r._stopNetworkJudge(),r._resetData()}))}},{key:"isConnected",value:function(){return!(!this.worker||!this.worker.isWSConnected())}},{key:"updatePusherStateChange",value:function(e){if(this.pushUrl){var t=e.detail.code,n=e.detail.message;a.default.info("client update pusher state, code:".concat(t," message:").concat(n)),this.argusReport.reportPusherStateChange(this.channel,this.uid,t>=1002,0,this.pushUrl,t,{message:n}),1002===t?this.grafanaReport.report("pusher_state_change",y,t,n):-1307===t&&this.grafanaReport.report("pusher_state_change",_,t,n)}}},{key:"updatePlayerStateChange",value:function(e,t){var n=this.playUrls.get(Number(e));if(n){var r=t.detail.code,i=t.detail.message;if(a.default.info("client update player state, uid:".concat(e," code:").concat(r," message:").concat(i)),this.argusReport.reportPlayerStateChange(e,this.channel,this.uid,r>=2002,0,n,r,{message:i}),2003===r||-2301===r){var o=2003===r?y:_;this.grafanaReport.report("player_state_change",o,r,i)}}}},{key:"updatePusherNetStatus",value:function(e){if(this.pushUrl){var t=e.detail.info;this.argusReport.setPusherNetData(t),oe(this.grafanaReport,0,t)}}},{key:"updatePlayerNetStatus",value:function(e,t){if(this.playUrls.get(Number(e))){var n=t.detail.info;this.argusReport.setPlayerNetData(e,n),se(this.grafanaReport,1,n,e)}}},{key:"send",value:function(e,t,n){var r=this;return new Promise((function(i,o){r._checkWorker(),r.worker.send(e).then((function(e){t&&t(e),i(e)})).catch((function(e){n&&n(e),o(e)}))}))}},{key:"updatePushUrl",value:function(e,t){var n=this;return new Promise((function(r,i){n._checkWorker(),n.worker.updatePushUrl().then((function(t){setTimeout((function(){a.default.info("client updatePushUrl success"),e&&e(t),r(t),n.grafanaReport.report("update_url",y)}),1)})).catch((function(e){a.default.error("client updatePushUrl failed: ".concat((0,m.stringifyErr)(e))),t&&t(e),i(e),n.grafanaReport.report("update_url",_,e.code,null==e?void 0:e.reason)}))}))}},{key:"destroy",value:function(e,t){var n=this;return new Promise((function(r,i){n.worker?n.worker.destroy().then((function(){n.pushUrl=null,n.playUrls.clear(),a.default.info("client destroy success"),e&&e(),r()})).catch((function(e){a.default.error("client destroy failed: ".concat((0,m.stringifyErr)(e))),t&&t(e),i(e)})).finally((function(){n.worker=null,n._stopNetworkJudge(),n._resetData()})):(n.pushUrl=null,n.playUrls.clear(),a.default.info("client destroy success without worker"),e&&e(),r(),n._stopNetworkJudge(),n._resetData()),n.grafanaReport.destroy(),n.argusReport.destroy()}))}},{key:"startChannelMediaRelay",value:function(e,t){if(!(e instanceof I.ChannelMediaRelayConfiguration))throw"Configration should be instance of [ChannelMediaRelayConfiguration]";var n=e.getSrcChannelMediaInfo(),r=e.getDestChannelMediaInfos();if((0,m.isEmpty)(n))throw"srcChannelMediaInfo should not be empty";if((0,m.isEmpty)(r)||0===r.length)throw"destChannelMediaInfos should not be empty";if(a.default.info("[startChannelMediaRelay]: srcInfo: ",n," destInfo: ",r),!(0,o.is32Uint)(n.uid))throw"Invalid uid in srcChannelMediaInfo";if(!(0,m.isValidChannelName)(n.channelName))throw"Invalid channelName in srcChannelMediaInfo";if(n.token&&!(0,m.isValidToken)(n.token))throw"Invalid token in srcChannelMediaInfo";if(r.forEach((function(e){if(!(0,o.is32Uint)(e.uid))throw"Invalid uid in destChannelMediaInfo";if(!(0,m.isValidChannelName)(e.channelName))throw"Invalid channelName in destChannelMediaInfo";if(e.token&&!(0,m.isValidToken)(e.token))throw"Invalid token in destChannelMediaInfo"})),!this.worker)throw"startChannelMediaRelay should be used after join";this.worker.startChannelMediaRelay(e).then((function(){a.default.info("client startChannelMediaRelay success"),t&&t()})).catch((function(e){a.default.error("client startChannelMediaRelay failed: ".concat((0,m.stringifyErr)(e))),t&&t(e)}))}},{key:"updateChannelMediaRelay",value:function(e,t){if(!(e instanceof I.ChannelMediaRelayConfiguration))throw"Configration should be instance of [ChannelMediaRelayConfiguration]";var n=e.getSrcChannelMediaInfo(),r=e.getDestChannelMediaInfos();if((0,m.isEmpty)(n))throw"srcChannelMediaInfo should not be empty";if((0,m.isEmpty)(r)||0===r.length)throw"destChannelMediaInfos should not be empty";if(a.default.info("[updateChannelMediaRelay]: srcInfo: ",n," destInfo: ",r),!(0,o.is32Uint)(n.uid))throw"Invalid uid in srcChannelMediaInfo";if(!(0,m.isValidChannelName)(n.channelName))throw"Invalid channelName in srcChannelMediaInfo";if(n.token&&!(0,m.isValidToken)(n.token))throw"Invalid token in srcChannelMediaInfo";if(r.forEach((function(e){if(!(0,o.is32Uint)(e.uid))throw"Invalid uid in destChannelMediaInfo";if(!(0,m.isValidChannelName)(e.channelName))throw"Invalid channelName in destChannelMediaInfo";if(e.token&&!(0,m.isValidToken)(e.token))throw"Invalid token in destChannelMediaInfo"})),!this.worker)throw"updateChannelMediaRelay should be used after join";this.worker.updateChannelMediaRelay(e).then((function(){a.default.info("client updateChannelMediaRelay success"),t&&t()})).catch((function(e){a.default.error("client updateChannelMediaRelay failed: ".concat((0,m.stringifyErr)(e))),t&&t(e)}))}},{key:"stopChannelMediaRelay",value:function(e){a.default.info("[stopChannelMediaRelay]"),this.worker.stopChannelMediaRelay().then((function(){a.default.info("client stopChannelMediaRelay success"),e&&e()})).catch((function(t){a.default.error("client stopChannelMediaRelay failed: ".concat((0,m.stringifyErr)(t))),e&&e(t)}))}},{key:"_checkUid",value:function(e){if(!e||"number"!=typeof e||!(0,o.is32Uint)(e)){var t=new Error("Invalid uid type");throw a.default.error("client ".concat(t.message)),t}}},{key:"_checkWorker",value:function(){if(!this.worker||!this.worker.isWSConnected()){var e=new Error("Disconnected from server");throw a.default.error("client ".concat(e.message)),e}}},{key:"_dealSid",value:function(){this.sid||(this.sid=(0,o.generateSessionId)(),this.argusReport.sid=this.sid,a.default.setOptions({appId:this.appId,sid:this.sid}),a.default.info("client sid: ".concat(this.sid)))}},{key:"_startNetworkJudge",value:function(){this.networkJudge||(this.networkJudge=!0,a.default.info("client start network judge"),wx.onNetworkStatusChange(ae),wx.onNetworkWeakChange(ce))}},{key:"_stopNetworkJudge",value:function(){this.networkJudge&&(this.networkJudge=!1,a.default.info("client stop network judge"),wx.offNetworkStatusChange(ae),wx.offNetworkWeakChange(ce))}},{key:"_resetData",value:function(){this.sid=""}}]),r}()})(),__webpack_exports__})())); diff --git a/miniprogram_npm/dayjs/index.js b/miniprogram_npm/dayjs/index.js new file mode 100644 index 0000000..3fa8603 --- /dev/null +++ b/miniprogram_npm/dayjs/index.js @@ -0,0 +1,13 @@ +module.exports = (function() { +var __MODS__ = {}; +var __DEFINE__ = function(modId, func, req) { var m = { exports: {}, _tempexports: {} }; __MODS__[modId] = { status: 0, func: func, req: req, m: m }; }; +var __REQUIRE__ = function(modId, source) { if(!__MODS__[modId]) return require(source); if(!__MODS__[modId].status) { var m = __MODS__[modId].m; m._exports = m._tempexports; var desp = Object.getOwnPropertyDescriptor(m, "exports"); if (desp && desp.configurable) Object.defineProperty(m, "exports", { set: function (val) { if(typeof val === "object" && val !== m._exports) { m._exports.__proto__ = val.__proto__; Object.keys(val).forEach(function (k) { m._exports[k] = val[k]; }); } m._tempexports = val }, get: function () { return m._tempexports; } }); __MODS__[modId].status = 1; __MODS__[modId].func(__MODS__[modId].req, m, m.exports); } return __MODS__[modId].m.exports; }; +var __REQUIRE_WILDCARD__ = function(obj) { if(obj && obj.__esModule) { return obj; } else { var newObj = {}; if(obj != null) { for(var k in obj) { if (Object.prototype.hasOwnProperty.call(obj, k)) newObj[k] = obj[k]; } } newObj.default = obj; return newObj; } }; +var __REQUIRE_DEFAULT__ = function(obj) { return obj && obj.__esModule ? obj.default : obj; }; +__DEFINE__(1731653753936, function(require, module, exports) { +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).dayjs=e()}(this,(function(){var t=1e3,e=6e4,n=36e5,r="millisecond",i="second",s="minute",u="hour",a="day",o="week",c="month",f="quarter",h="year",d="date",l="Invalid Date",$=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,y=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,M={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(t){var e=["th","st","nd","rd"],n=t%100;return"["+t+(e[(n-20)%10]||e[n]||e[0])+"]"}},m=function(t,e,n){var r=String(t);return!r||r.length>=e?t:""+Array(e+1-r.length).join(n)+t},v={s:m,z:function(t){var e=-t.utcOffset(),n=Math.abs(e),r=Math.floor(n/60),i=n%60;return(e<=0?"+":"-")+m(r,2,"0")+":"+m(i,2,"0")},m:function t(e,n){if(e.date()1)return t(u[0])}else{var a=e.name;D[a]=e,i=a}return!r&&i&&(g=i),i||!r&&g},O=function(t,e){if(S(t))return t.clone();var n="object"==typeof e?e:{};return n.date=t,n.args=arguments,new _(n)},b=v;b.l=w,b.i=S,b.w=function(t,e){return O(t,{locale:e.$L,utc:e.$u,x:e.$x,$offset:e.$offset})};var _=function(){function M(t){this.$L=w(t.locale,null,!0),this.parse(t),this.$x=this.$x||t.x||{},this[p]=!0}var m=M.prototype;return m.parse=function(t){this.$d=function(t){var e=t.date,n=t.utc;if(null===e)return new Date(NaN);if(b.u(e))return new Date;if(e instanceof Date)return new Date(e);if("string"==typeof e&&!/Z$/i.test(e)){var r=e.match($);if(r){var i=r[2]-1||0,s=(r[7]||"0").substring(0,3);return n?new Date(Date.UTC(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,s)):new Date(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,s)}}return new Date(e)}(t),this.init()},m.init=function(){var t=this.$d;this.$y=t.getFullYear(),this.$M=t.getMonth(),this.$D=t.getDate(),this.$W=t.getDay(),this.$H=t.getHours(),this.$m=t.getMinutes(),this.$s=t.getSeconds(),this.$ms=t.getMilliseconds()},m.$utils=function(){return b},m.isValid=function(){return!(this.$d.toString()===l)},m.isSame=function(t,e){var n=O(t);return this.startOf(e)<=n&&n<=this.endOf(e)},m.isAfter=function(t,e){return O(t)=e?t:\"\"+Array(e+1-r.length).join(n)+t},v={s:m,z:function(t){var e=-t.utcOffset(),n=Math.abs(e),r=Math.floor(n/60),i=n%60;return(e<=0?\"+\":\"-\")+m(r,2,\"0\")+\":\"+m(i,2,\"0\")},m:function t(e,n){if(e.date()1)return t(u[0])}else{var a=e.name;D[a]=e,i=a}return!r&&i&&(g=i),i||!r&&g},O=function(t,e){if(S(t))return t.clone();var n=\"object\"==typeof e?e:{};return n.date=t,n.args=arguments,new _(n)},b=v;b.l=w,b.i=S,b.w=function(t,e){return O(t,{locale:e.$L,utc:e.$u,x:e.$x,$offset:e.$offset})};var _=function(){function M(t){this.$L=w(t.locale,null,!0),this.parse(t),this.$x=this.$x||t.x||{},this[p]=!0}var m=M.prototype;return m.parse=function(t){this.$d=function(t){var e=t.date,n=t.utc;if(null===e)return new Date(NaN);if(b.u(e))return new Date;if(e instanceof Date)return new Date(e);if(\"string\"==typeof e&&!/Z$/i.test(e)){var r=e.match($);if(r){var i=r[2]-1||0,s=(r[7]||\"0\").substring(0,3);return n?new Date(Date.UTC(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,s)):new Date(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,s)}}return new Date(e)}(t),this.init()},m.init=function(){var t=this.$d;this.$y=t.getFullYear(),this.$M=t.getMonth(),this.$D=t.getDate(),this.$W=t.getDay(),this.$H=t.getHours(),this.$m=t.getMinutes(),this.$s=t.getSeconds(),this.$ms=t.getMilliseconds()},m.$utils=function(){return b},m.isValid=function(){return!(this.$d.toString()===l)},m.isSame=function(t,e){var n=O(t);return this.startOf(e)<=n&&n<=this.endOf(e)},m.isAfter=function(t,e){return O(t)()=>(t||e((t={exports:{}}).exports,t),t.exports);var U=W(L=>{"use strict";Object.defineProperty(L,"__esModule",{value:!0}),function(e,t){for(var r in t)Object.defineProperty(e,r,{enumerable:!0,get:t[r]})}(L,{getDataOnPath:function(){return se},parseMultiDataPaths:function(){return ce}});var N=/^\s/,k=function(e,t){throw Error('Parsing data path "'+e+'" failed at char "'+e[t]+'" (index '+t+")")},ae=function(e,t){for(var r=t.index;t.index{z.exports=function(){let t=null,r;function n(i){return i?typeof i=="object"||typeof i=="function":!1}function a(i){if(i!==null&&!n(i))throw new TypeError("Object prototype may only be an Object or null: "+i)}let o=Object,u=!!o.create||!({__proto__:null}instanceof o),c=o.create||(u?function(s){return a(s),{__proto__:s}}:function(s){if(a(s),s===null)throw new SyntaxError("Native Object.create is required to create objects with null prototype");var l=function(){};return l.prototype=s,new l}),d=function(){return null},g=o.getPrototypeOf||([].__proto__===Array.prototype?function(s){let l=s.__proto__;return n(l)?l:null}:d);return r=function(i,s){if((this&&this instanceof r?this.constructor:void 0)===void 0)throw new TypeError("Constructor Proxy requires 'new'");if(!n(i)||!n(s))throw new TypeError("Cannot create proxy with a non-object as target or handler");let h=function(){};t=function(){i=null,h=function(f){throw new TypeError(`Cannot perform '${f}' on a proxy that has been revoked`)}},setTimeout(function(){t=null},0);let b=s;s={get:null,set:null,apply:null,construct:null};for(let f in b){if(!(f in s))throw new TypeError(`Proxy polyfill does not support trap '${f}'`);s[f]=b[f]}typeof b=="function"&&(s.apply=b.apply.bind(b));let v=g(i),p,_=!1,w=!1;typeof i=="function"?(p=function(){let m=this&&this.constructor===p,y=Array.prototype.slice.call(arguments);if(h(m?"construct":"apply"),m&&s.construct)return s.construct.call(this,i,y);if(!m&&s.apply)return s.apply(i,this,y);if(m){y.unshift(i);let j=i.bind.apply(i,y);return new j}return i.apply(this,y)},_=!0):i instanceof Array?(p=[],w=!0):p=u||v!==null?c(v):{};let O=s.get?function(f){return h("get"),s.get(this,f,p)}:function(f){return h("get"),this[f]},x=s.set?function(f,m){h("set");let y=s.set(this,f,m,p)}:function(f,m){h("set"),this[f]=m},q=o.getOwnPropertyNames(i),A={};q.forEach(function(f){if((_||w)&&f in p)return;let y={enumerable:!!o.getOwnPropertyDescriptor(i,f).enumerable,get:O.bind(i,f),set:x.bind(i,f)};o.defineProperty(p,f,y),A[f]=!0});let P=!0;if(_||w){let f=o.setPrototypeOf||([].__proto__===Array.prototype?function(y,j){return a(j),y.__proto__=j,y}:d);v&&f(p,v)||(P=!1)}if(s.get||!P)for(let f in i)A[f]||o.defineProperty(p,f,{get:O.bind(i,f)});return o.seal(i),o.seal(p),p},r.revocable=function(i,s){return{proxy:new r(i,s),revoke:t}},r}});var G=W(R=>{"use strict";function D(e){return e&&typeof Symbol<"u"&&e.constructor===Symbol?"symbol":typeof e}Object.defineProperty(R,"__esModule",{value:!0}),function(e,t){for(var r in t)Object.defineProperty(e,r,{enumerable:!0,get:t[r]})}(R,{create:function(){return de},unwrap:function(){return function e(t){if(t!==null&&(t===void 0?"undefined":D(t))==="object"&&D(t.__rawObject__)!=="object"){if(Array.isArray(t))return t.map(function(n){return e(n)});var r={};return Object.keys(t).forEach(function(n){r[n]=e(t[n])}),r}return(t===void 0?"undefined":D(t))!=="object"||t===null||D(t.__rawObject__)!=="object"?t:t.__rawObject__}}});var T,fe=(0,((T=Z())&&T.__esModule?T:{default:T}).default)(),K=function(e,t,r){if((e===void 0?"undefined":D(e))!=="object"||e===null)return e;var n={get:function(a,o){if(o==="__rawObject__")return a;var u=r.concat(o),c=a[o];return t.push({kind:"value",path:u,value:c}),K(c,t,u)},ownKeys:function(a){var o=r.slice(),u=Object.keys(a).sort();return t.push({kind:"keys",path:o,keys:u}),u}};try{return new Proxy(e,n)}catch{return new fe(e,n)}};function de(e,t){return K(e,t,[])}});var ne=W(V=>{"use strict";Object.defineProperty(V,"__esModule",{value:!0}),function(e,t){for(var r in t)Object.defineProperty(e,r,{enumerable:!0,get:t[r]})}(V,{behavior:function(){return ve},computed:function(){return ye},watch:function(){return be}});var M,J,pe=Y(require("rfdc")),le=Y(require("fast-deep-equal")),E=te(U()),F=te(G());function Y(e){return e&&e.__esModule?e:{default:e}}function ee(e){if(typeof WeakMap!="function")return null;var t=new WeakMap,r=new WeakMap;return(ee=function(n){return n?r:t})(e)}function te(e,t){if(!t&&e&&e.__esModule)return e;if(e===null||typeof e!="object"&&typeof e!="function")return{default:e};var r=ee(t);if(r&&r.has(e))return r.get(e);var n={__proto__:null},a=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var o in e)if(o!=="default"&&Object.prototype.hasOwnProperty.call(e,o)){var u=a?Object.getOwnPropertyDescriptor(e,o):null;u&&(u.get||u.set)?Object.defineProperty(n,o,u):n[o]=e[o]}return n.default=e,r&&r.set(e,n),n}var Q=(0,pe.default)({proto:!0});(M=J||(J={}))[M.CREATED=0]="CREATED",M[M.ATTACHED=1]="ATTACHED";var he=0;function X(e,t){return e===t||e!=e&&t!=t}var S=function(){"use strict";function e(){this.observersItems=[],this.computedWatchDefId=he++,this.computedList=[],this.watchList=[];var r=this.computedWatchDefId,n=this.computedList,a=this.watchList;this.observersItems.push({fields:"_computedWatchInit",observer:function(){var o=this,u=this.data._computedWatchInit;if(u===0){var c={computedUpdaters:[],computedRelatedPathValues:Array(n.length),watchCurVal:Array(a.length),_triggerFromComputedAttached:Object.create(null)};this._computedWatchInfo||(this._computedWatchInfo={}),this._computedWatchInfo[r]=c,a.forEach(function(g,i){var s=g.map(function(l){var h=l.path,b=l.options,v=E.getDataOnPath(o.data,h);return b.deepCmp?Q(v):v});c.watchCurVal[i]=s})}else if(u===1){var d=this._computedWatchInfo[r];n.forEach(function(g,i){var s,l=g[0],h=g[1],b=[],v=h(F.create(o.data,b));o.setData(((s={})[l]=F.unwrap(v),s)),d._triggerFromComputedAttached[l]=!0,d.computedRelatedPathValues[i]=b,d.computedUpdaters.push(function(){for(var p,_=d.computedRelatedPathValues[i],w=!1,O=0;O<_.length;O++){var x=_[O];if(x.kind==="keys"){var q=x.path,A=x.keys,P=Object.keys(E.getDataOnPath(o.data,q)).sort();if(P.length!==A.length){w=!0;break}for(var f=0;f new Date(o)) + constructorHandlers.set(Map, (o, fn) => new Map(cloneArray(Array.from(o), fn))) + constructorHandlers.set(Set, (o, fn) => new Set(cloneArray(Array.from(o), fn))) + if (opts.constructorHandlers) { + for (const handler of opts.constructorHandlers) { + constructorHandlers.set(handler[0], handler[1]) + } + } + + let handler = null + + return opts.proto ? cloneProto : clone + + function cloneArray (a, fn) { + const keys = Object.keys(a) + const a2 = new Array(keys.length) + for (let i = 0; i < keys.length; i++) { + const k = keys[i] + const cur = a[k] + if (typeof cur !== 'object' || cur === null) { + a2[k] = cur + } else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) { + a2[k] = handler(cur, fn) + } else if (ArrayBuffer.isView(cur)) { + a2[k] = copyBuffer(cur) + } else { + a2[k] = fn(cur) + } + } + return a2 + } + + function clone (o) { + if (typeof o !== 'object' || o === null) return o + if (Array.isArray(o)) return cloneArray(o, clone) + if (o.constructor !== Object && (handler = constructorHandlers.get(o.constructor))) { + return handler(o, clone) + } + const o2 = {} + for (const k in o) { + if (Object.hasOwnProperty.call(o, k) === false) continue + const cur = o[k] + if (typeof cur !== 'object' || cur === null) { + o2[k] = cur + } else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) { + o2[k] = handler(cur, clone) + } else if (ArrayBuffer.isView(cur)) { + o2[k] = copyBuffer(cur) + } else { + o2[k] = clone(cur) + } + } + return o2 + } + + function cloneProto (o) { + if (typeof o !== 'object' || o === null) return o + if (Array.isArray(o)) return cloneArray(o, cloneProto) + if (o.constructor !== Object && (handler = constructorHandlers.get(o.constructor))) { + return handler(o, cloneProto) + } + const o2 = {} + for (const k in o) { + const cur = o[k] + if (typeof cur !== 'object' || cur === null) { + o2[k] = cur + } else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) { + o2[k] = handler(cur, cloneProto) + } else if (ArrayBuffer.isView(cur)) { + o2[k] = copyBuffer(cur) + } else { + o2[k] = cloneProto(cur) + } + } + return o2 + } +} + +function rfdcCircles (opts) { + const refs = [] + const refsNew = [] + + const constructorHandlers = new Map() + constructorHandlers.set(Date, (o) => new Date(o)) + constructorHandlers.set(Map, (o, fn) => new Map(cloneArray(Array.from(o), fn))) + constructorHandlers.set(Set, (o, fn) => new Set(cloneArray(Array.from(o), fn))) + if (opts.constructorHandlers) { + for (const handler of opts.constructorHandlers) { + constructorHandlers.set(handler[0], handler[1]) + } + } + + let handler = null + return opts.proto ? cloneProto : clone + + function cloneArray (a, fn) { + const keys = Object.keys(a) + const a2 = new Array(keys.length) + for (let i = 0; i < keys.length; i++) { + const k = keys[i] + const cur = a[k] + if (typeof cur !== 'object' || cur === null) { + a2[k] = cur + } else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) { + a2[k] = handler(cur, fn) + } else if (ArrayBuffer.isView(cur)) { + a2[k] = copyBuffer(cur) + } else { + const index = refs.indexOf(cur) + if (index !== -1) { + a2[k] = refsNew[index] + } else { + a2[k] = fn(cur) + } + } + } + return a2 + } + + function clone (o) { + if (typeof o !== 'object' || o === null) return o + if (Array.isArray(o)) return cloneArray(o, clone) + if (o.constructor !== Object && (handler = constructorHandlers.get(o.constructor))) { + return handler(o, clone) + } + const o2 = {} + refs.push(o) + refsNew.push(o2) + for (const k in o) { + if (Object.hasOwnProperty.call(o, k) === false) continue + const cur = o[k] + if (typeof cur !== 'object' || cur === null) { + o2[k] = cur + } else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) { + o2[k] = handler(cur, clone) + } else if (ArrayBuffer.isView(cur)) { + o2[k] = copyBuffer(cur) + } else { + const i = refs.indexOf(cur) + if (i !== -1) { + o2[k] = refsNew[i] + } else { + o2[k] = clone(cur) + } + } + } + refs.pop() + refsNew.pop() + return o2 + } + + function cloneProto (o) { + if (typeof o !== 'object' || o === null) return o + if (Array.isArray(o)) return cloneArray(o, cloneProto) + if (o.constructor !== Object && (handler = constructorHandlers.get(o.constructor))) { + return handler(o, cloneProto) + } + const o2 = {} + refs.push(o) + refsNew.push(o2) + for (const k in o) { + const cur = o[k] + if (typeof cur !== 'object' || cur === null) { + o2[k] = cur + } else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) { + o2[k] = handler(cur, cloneProto) + } else if (ArrayBuffer.isView(cur)) { + o2[k] = copyBuffer(cur) + } else { + const i = refs.indexOf(cur) + if (i !== -1) { + o2[k] = refsNew[i] + } else { + o2[k] = cloneProto(cur) + } + } + } + refs.pop() + refsNew.pop() + return o2 + } +} + +}, function(modId) {var map = {}; return __REQUIRE__(map[modId], modId); }) +return __REQUIRE__(1731653753938); +})() +//miniprogram-npm-outsideDeps=[] +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/miniprogram_npm/rfdc/index.js.map b/miniprogram_npm/rfdc/index.js.map new file mode 100644 index 0000000..a6fba6a --- /dev/null +++ b/miniprogram_npm/rfdc/index.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["index.js"],"names":[],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"index.js","sourcesContent":["\nmodule.exports = rfdc\n\nfunction copyBuffer (cur) {\n if (cur instanceof Buffer) {\n return Buffer.from(cur)\n }\n\n return new cur.constructor(cur.buffer.slice(), cur.byteOffset, cur.length)\n}\n\nfunction rfdc (opts) {\n opts = opts || {}\n if (opts.circles) return rfdcCircles(opts)\n\n const constructorHandlers = new Map()\n constructorHandlers.set(Date, (o) => new Date(o))\n constructorHandlers.set(Map, (o, fn) => new Map(cloneArray(Array.from(o), fn)))\n constructorHandlers.set(Set, (o, fn) => new Set(cloneArray(Array.from(o), fn)))\n if (opts.constructorHandlers) {\n for (const handler of opts.constructorHandlers) {\n constructorHandlers.set(handler[0], handler[1])\n }\n }\n\n let handler = null\n\n return opts.proto ? cloneProto : clone\n\n function cloneArray (a, fn) {\n const keys = Object.keys(a)\n const a2 = new Array(keys.length)\n for (let i = 0; i < keys.length; i++) {\n const k = keys[i]\n const cur = a[k]\n if (typeof cur !== 'object' || cur === null) {\n a2[k] = cur\n } else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) {\n a2[k] = handler(cur, fn)\n } else if (ArrayBuffer.isView(cur)) {\n a2[k] = copyBuffer(cur)\n } else {\n a2[k] = fn(cur)\n }\n }\n return a2\n }\n\n function clone (o) {\n if (typeof o !== 'object' || o === null) return o\n if (Array.isArray(o)) return cloneArray(o, clone)\n if (o.constructor !== Object && (handler = constructorHandlers.get(o.constructor))) {\n return handler(o, clone)\n }\n const o2 = {}\n for (const k in o) {\n if (Object.hasOwnProperty.call(o, k) === false) continue\n const cur = o[k]\n if (typeof cur !== 'object' || cur === null) {\n o2[k] = cur\n } else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) {\n o2[k] = handler(cur, clone)\n } else if (ArrayBuffer.isView(cur)) {\n o2[k] = copyBuffer(cur)\n } else {\n o2[k] = clone(cur)\n }\n }\n return o2\n }\n\n function cloneProto (o) {\n if (typeof o !== 'object' || o === null) return o\n if (Array.isArray(o)) return cloneArray(o, cloneProto)\n if (o.constructor !== Object && (handler = constructorHandlers.get(o.constructor))) {\n return handler(o, cloneProto)\n }\n const o2 = {}\n for (const k in o) {\n const cur = o[k]\n if (typeof cur !== 'object' || cur === null) {\n o2[k] = cur\n } else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) {\n o2[k] = handler(cur, cloneProto)\n } else if (ArrayBuffer.isView(cur)) {\n o2[k] = copyBuffer(cur)\n } else {\n o2[k] = cloneProto(cur)\n }\n }\n return o2\n }\n}\n\nfunction rfdcCircles (opts) {\n const refs = []\n const refsNew = []\n\n const constructorHandlers = new Map()\n constructorHandlers.set(Date, (o) => new Date(o))\n constructorHandlers.set(Map, (o, fn) => new Map(cloneArray(Array.from(o), fn)))\n constructorHandlers.set(Set, (o, fn) => new Set(cloneArray(Array.from(o), fn)))\n if (opts.constructorHandlers) {\n for (const handler of opts.constructorHandlers) {\n constructorHandlers.set(handler[0], handler[1])\n }\n }\n\n let handler = null\n return opts.proto ? cloneProto : clone\n\n function cloneArray (a, fn) {\n const keys = Object.keys(a)\n const a2 = new Array(keys.length)\n for (let i = 0; i < keys.length; i++) {\n const k = keys[i]\n const cur = a[k]\n if (typeof cur !== 'object' || cur === null) {\n a2[k] = cur\n } else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) {\n a2[k] = handler(cur, fn)\n } else if (ArrayBuffer.isView(cur)) {\n a2[k] = copyBuffer(cur)\n } else {\n const index = refs.indexOf(cur)\n if (index !== -1) {\n a2[k] = refsNew[index]\n } else {\n a2[k] = fn(cur)\n }\n }\n }\n return a2\n }\n\n function clone (o) {\n if (typeof o !== 'object' || o === null) return o\n if (Array.isArray(o)) return cloneArray(o, clone)\n if (o.constructor !== Object && (handler = constructorHandlers.get(o.constructor))) {\n return handler(o, clone)\n }\n const o2 = {}\n refs.push(o)\n refsNew.push(o2)\n for (const k in o) {\n if (Object.hasOwnProperty.call(o, k) === false) continue\n const cur = o[k]\n if (typeof cur !== 'object' || cur === null) {\n o2[k] = cur\n } else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) {\n o2[k] = handler(cur, clone)\n } else if (ArrayBuffer.isView(cur)) {\n o2[k] = copyBuffer(cur)\n } else {\n const i = refs.indexOf(cur)\n if (i !== -1) {\n o2[k] = refsNew[i]\n } else {\n o2[k] = clone(cur)\n }\n }\n }\n refs.pop()\n refsNew.pop()\n return o2\n }\n\n function cloneProto (o) {\n if (typeof o !== 'object' || o === null) return o\n if (Array.isArray(o)) return cloneArray(o, cloneProto)\n if (o.constructor !== Object && (handler = constructorHandlers.get(o.constructor))) {\n return handler(o, cloneProto)\n }\n const o2 = {}\n refs.push(o)\n refsNew.push(o2)\n for (const k in o) {\n const cur = o[k]\n if (typeof cur !== 'object' || cur === null) {\n o2[k] = cur\n } else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) {\n o2[k] = handler(cur, cloneProto)\n } else if (ArrayBuffer.isView(cur)) {\n o2[k] = copyBuffer(cur)\n } else {\n const i = refs.indexOf(cur)\n if (i !== -1) {\n o2[k] = refsNew[i]\n } else {\n o2[k] = cloneProto(cur)\n }\n }\n }\n refs.pop()\n refsNew.pop()\n return o2\n }\n}\n"]} \ No newline at end of file diff --git a/miniprogram_npm/signalr-for-wx/AbortController.js b/miniprogram_npm/signalr-for-wx/AbortController.js new file mode 100644 index 0000000..7944488 --- /dev/null +++ b/miniprogram_npm/signalr-for-wx/AbortController.js @@ -0,0 +1,39 @@ +// 版权所有(c).NET基金会。保留所有权利。 +// 在2.0版Apache许可下授权。有关许可证信息,请参见项目根目录中的License.txt。 +//粗略填写 https://developer.mozilla.org/en-US/docs/Web/API/AbortController +//实际上,我们从来没有使用被polyfill填充的API,我们总是使用polyfill,因为 +//它现在还是一个非常新的API。 +/** + * + * @private + */ +var AbortController = /** @class */ (function () { + function AbortController() { + this.isAborted = false; + this.onabort = null; + } + AbortController.prototype.abort = function () { + if (!this.isAborted) { + this.isAborted = true; + if (this.onabort) { + this.onabort(); + } + } + }; + Object.defineProperty(AbortController.prototype, "signal", { + get: function () { + return this; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(AbortController.prototype, "aborted", { + get: function () { + return this.isAborted; + }, + enumerable: true, + configurable: true + }); + return AbortController; +}()); +export { AbortController }; diff --git a/miniprogram_npm/signalr-for-wx/DefualtRequest.js b/miniprogram_npm/signalr-for-wx/DefualtRequest.js new file mode 100644 index 0000000..48571b7 --- /dev/null +++ b/miniprogram_npm/signalr-for-wx/DefualtRequest.js @@ -0,0 +1,50 @@ +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +import { Request } from "./wx-request/index"; +import { RequestMethod, ResponseType } from "./wx-request/model"; +/** + * 生成默认请求库 + * + * @export + * @class DefaultRequest + */ +var DefaultRequest = /** @class */ (function (_super) { + __extends(DefaultRequest, _super); + function DefaultRequest(config, logger) { + var _this = _super.call(this) || this; + _this.logger = logger + ? logger + : { + log: function (logLevel, message) { + /* 屏蔽打印 */ + } + }; + // default config + _this.setConfig(__assign({ about: false, forceEnableHttps: false, headers: {}, method: RequestMethod.GET, responseEncoding: ResponseType.JSON, timeout: 2 * 60 * 1000, transformRequest: [], transformResponse: [] }, config)); + return _this; + } + return DefaultRequest; +}(Request)); +export default DefaultRequest; diff --git a/miniprogram_npm/signalr-for-wx/Errors.js b/miniprogram_npm/signalr-for-wx/Errors.js new file mode 100644 index 0000000..d9a5f9b --- /dev/null +++ b/miniprogram_npm/signalr-for-wx/Errors.js @@ -0,0 +1,114 @@ +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +// 版权所有(c).NET基金会。保留所有权利。 +// 在2.0版Apache许可下授权。有关许可证信息,请参见项目根目录中的License.txt。 +/** + * Error thrown when an HTTP request fails. + * HTTP请求失败时引发错误。 + */ +var HttpError = /** @class */ (function (_super) { + __extends(HttpError, _super); + /** Constructs a new instance of {@link @aspnet/signalr.HttpError}. + * + * @param {string} errorMessage A descriptive error message. + * @param {number} statusCode The HTTP status code represented by this error. + */ + function HttpError(errorMessage, statusCode) { + var _newTarget = this.constructor; + var _this = this; + var trueProto = _newTarget.prototype; + _this = _super.call(this, errorMessage) || this; + _this.statusCode = statusCode; + // Workaround issue in Typescript compiler + // https://github.com/Microsoft/TypeScript/issues/13965#issuecomment-278570200 + _this.__proto__ = trueProto; + return _this; + } + return HttpError; +}(Error)); +export { HttpError }; +/** + * Error thrown when a timeout elapses. + * 超时错误 + */ +var TimeoutError = /** @class */ (function (_super) { + __extends(TimeoutError, _super); + /** Constructs a new instance of {@link @aspnet/signalr.TimeoutError}. + * + * @param {string} errorMessage A descriptive error message. + */ + function TimeoutError(errorMessage) { + var _newTarget = this.constructor; + if (errorMessage === void 0) { errorMessage = "A timeout occurred."; } + var _this = this; + var trueProto = _newTarget.prototype; + _this = _super.call(this, errorMessage) || this; + // Workaround issue in Typescript compiler + // https://github.com/Microsoft/TypeScript/issues/13965#issuecomment-278570200 + _this.__proto__ = trueProto; + return _this; + } + return TimeoutError; +}(Error)); +export { TimeoutError }; +/** + * Error thrown when an action is aborted. + * 连接错误 + */ +var AbortError = /** @class */ (function (_super) { + __extends(AbortError, _super); + /** Constructs a new instance of {@link AbortError}. + * + * @param {string} errorMessage A descriptive error message. + */ + function AbortError(errorMessage) { + var _newTarget = this.constructor; + if (errorMessage === void 0) { errorMessage = "An abort occurred."; } + var _this = this; + var trueProto = _newTarget.prototype; + _this = _super.call(this, errorMessage) || this; + // Workaround issue in Typescript compiler + // https://github.com/Microsoft/TypeScript/issues/13965#issuecomment-278570200 + _this.__proto__ = trueProto; + return _this; + } + return AbortError; +}(Error)); +export { AbortError }; +/** + * Error thrown when message event is not found. + * 事件未定义 + */ +var EventNotFoundError = /** @class */ (function (_super) { + __extends(EventNotFoundError, _super); + /** Constructs a new instance of {@link AbortError}. + * + * @param {string} errorMessage A descriptive error message. + */ + function EventNotFoundError(invocationMessage, errorMessage) { + var _newTarget = this.constructor; + if (errorMessage === void 0) { errorMessage = "message event not found."; } + var _this = this; + var trueProto = _newTarget.prototype; + _this = _super.call(this, errorMessage) || this; + _this.methodName = invocationMessage.target; + _this.invocationMessage = invocationMessage; + // Workaround issue in Typescript compiler + // https://github.com/Microsoft/TypeScript/issues/13965#issuecomment-278570200 + _this.__proto__ = trueProto; + return _this; + } + return EventNotFoundError; +}(Error)); +export { EventNotFoundError }; diff --git a/miniprogram_npm/signalr-for-wx/HandshakeProtocol.js b/miniprogram_npm/signalr-for-wx/HandshakeProtocol.js new file mode 100644 index 0000000..1ec667c --- /dev/null +++ b/miniprogram_npm/signalr-for-wx/HandshakeProtocol.js @@ -0,0 +1,67 @@ +// 版权所有(c).NET基金会。保留所有权利。 +// 在2.0版Apache许可下授权。有关许可证信息,请参见项目根目录中的License.txt。 +import { TextMessageFormat } from "./TextMessageFormat"; +import { isArrayBuffer } from "./Utils"; +/** + * 握手协议 + * @private + */ +var HandshakeProtocol = /** @class */ (function () { + function HandshakeProtocol() { + } + // Handshake request is always JSON - 握手请求总是JSON + HandshakeProtocol.prototype.writeHandshakeRequest = function (handshakeRequest) { + // commond + return TextMessageFormat.write(JSON.stringify(handshakeRequest)); + }; + /** + * 解析握手协议 response + * + * @param {*} data + * @returns {[any, HandshakeResponseMessage]} + * @memberof HandshakeProtocol + */ + HandshakeProtocol.prototype.parseHandshakeResponse = function (data) { + var responseMessage; + var messageData; + var remainingData; + // ! 删除了 @aspnet/signlaR 原有的 Buffer(仅适用 nodejs)判断 + if (isArrayBuffer(data)) { + // Format is binary but still need to read JSON text from handshake response - fy: 格式是二进制的,但仍然需要从握手响应中读取JSON文本 + var binaryData = new Uint8Array(data); + var separatorIndex = binaryData.indexOf(TextMessageFormat.RecordSeparatorCode); + if (separatorIndex === -1) { + throw new Error("Message is incomplete."); + } + // content before separator is handshake response - fy:分隔符前的内容是握手响应 + // optional content after is additional messages - fy:后面是附加消息的可选内容 + var responseLength = separatorIndex + 1; + messageData = String.fromCharCode.apply(null, binaryData.slice(0, responseLength)); + remainingData = (binaryData.byteLength > responseLength) ? binaryData.slice(responseLength).buffer : null; + } + else { + var textData = data; + var separatorIndex = textData.indexOf(TextMessageFormat.RecordSeparator); + if (separatorIndex === -1) { + throw new Error("Message is incomplete."); + } + // content before separator is handshake response - fy:分隔符前的内容是握手响应 + // optional content after is additional messages - fy:后面是附加消息的可选内容 + var responseLength = separatorIndex + 1; + messageData = textData.substring(0, responseLength); + remainingData = (textData.length > responseLength) ? textData.substring(responseLength) : null; + } + // At this point we should have just the single handshake message - fy: 在这一点上,我们应该只有一个握手信息 + var messages = TextMessageFormat.parse(messageData); + var response = JSON.parse(messages[0]); + if (response.type) { + throw new Error("Expected a handshake response from the server. -(fy: 需要来自服务器的握手响应)"); + } + responseMessage = response; + // multiple messages could have arrived with handshake - fy: 握手时可能会收到多条消息 + // return additional data to be parsed as usual, or null if all parsed - fy: 返回要像往常一样分析的其他数据,如果所有数据都已分析,则返回null + return [remainingData, responseMessage]; + }; + return HandshakeProtocol; +}()); +export { HandshakeProtocol }; diff --git a/miniprogram_npm/signalr-for-wx/HttpConnection.js b/miniprogram_npm/signalr-for-wx/HttpConnection.js new file mode 100644 index 0000000..db4235a --- /dev/null +++ b/miniprogram_npm/signalr-for-wx/HttpConnection.js @@ -0,0 +1,479 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +import { LogLevel } from "./ILogger"; +import { HttpTransportType, TransferFormat } from "./ITransport"; +import { LongPollingTransport } from "./LongPollingTransport"; +import { Arg, createLogger } from "./Utils"; +import DefaultRequest from "./DefualtRequest"; +import { ResponseType } from "./wx-request/model/ResponseType"; +import { WxSocketTransport } from "./WxSocketTransport"; +var MAX_REDIRECTS = 100; +var WxSocketModule = WxSocketTransport; +var LongPollingModule = LongPollingTransport; +/** @private */ +var HttpConnection = /** @class */ (function () { + function HttpConnection(url, options) { + if (options === void 0) { options = {}; } + this.features = {}; + Arg.isRequired(url, "url"); + this.logger = createLogger(options.logger); + options = options || {}; + // ! 这里修改为自定义解析 和 默认传入 全路径方式 + this.baseUrl = options.resolveUrl ? options.resolveUrl(url) : this.resolveUrl(url); + options.logMessageContent = options.logMessageContent || false; + // ! 修改 options 参数赋值方式 + if (!options.WxSocket && wx) { + options.WxSocket = WxSocketModule; + } + if (!options.LongPolling) { + options.LongPolling = LongPollingModule; + } + this.request = options.request || new DefaultRequest({}, this.logger); + this.connectionState = 2 /* Disconnected */; + this.options = options; + this.onreceive = null; + this.onclose = null; + } + HttpConnection.prototype.start = function (transferFormat) { + transferFormat = transferFormat || TransferFormat.Binary; + Arg.isIn(transferFormat, TransferFormat, "transferFormat"); + this.logger.log(LogLevel.Debug, "Starting connection with transfer format '" + TransferFormat[transferFormat] + "'.", TransferFormat); + if (this.connectionState !== 2 /* Disconnected */) { + return Promise.reject(new Error("Cannot start a connection that is not in the 'Disconnected' state. state is " + this.connectionState)); + } + this.connectionState = 0 /* Connecting */; + this.startPromise = this.startInternal(transferFormat); + return this.startPromise; + }; + HttpConnection.prototype.send = function (data) { + if (this.connectionState !== 1 /* Connected */) { + throw new Error("Cannot send data if the connection is not in the 'Connected' State."); + } + // Transport will not be null if state is connected + return this.transport.send(data); + }; + HttpConnection.prototype.stop = function (error) { + return __awaiter(this, void 0, void 0, function () { + var e_1; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + this.connectionState = 2 /* Disconnected */; + // Set error as soon as possible otherwise there is a race between + // the transport closing and providing an error and the error from a close message + // We would prefer the close message error. + this.stopError = error; + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, this.startPromise]; + case 2: + _a.sent(); + return [3 /*break*/, 4]; + case 3: + e_1 = _a.sent(); + return [3 /*break*/, 4]; + case 4: + if (!this.transport) return [3 /*break*/, 6]; + return [4 /*yield*/, this.transport.stop()]; + case 5: + _a.sent(); + this.transport = undefined; + _a.label = 6; + case 6: return [2 /*return*/]; + } + }); + }); + }; + HttpConnection.prototype.startInternal = function (transferFormat) { + return __awaiter(this, void 0, void 0, function () { + var url, negotiateResponse, redirects, _loop_1, this_1, state_1, e_2; + var _this = this; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + url = this.baseUrl; + this.accessTokenFactory = this.options.accessTokenFactory; + this.socketUrlFactory = this.options.socketUrlFactory; + _a.label = 1; + case 1: + _a.trys.push([1, 12, , 13]); + if (!this.options.skipNegotiation) return [3 /*break*/, 5]; + if (!(this.options.transport === HttpTransportType.WebSockets)) return [3 /*break*/, 3]; + // No need to add a connection ID in this case + this.transport = this.constructTransport(HttpTransportType.WebSockets); + // We should just call connect directly in this case. + // No fallback or negotiate in this case. + return [4 /*yield*/, this.transport.connect({ + url: url, + header: {}, + protocols: [], + tcpNoDelay: true, + transferFormat: transferFormat + })]; + case 2: + // We should just call connect directly in this case. + // No fallback or negotiate in this case. + _a.sent(); + return [3 /*break*/, 4]; + case 3: throw Error("Negotiation can only be skipped when using the WxSocket transport directly."); + case 4: return [3 /*break*/, 11]; + case 5: + negotiateResponse = null; + redirects = 0; + _loop_1 = function () { + var accessToken_1; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this_1.getNegotiationResponse(url)]; + case 1: + negotiateResponse = _a.sent(); + // the user tries to stop the connection when it is being started + if (this_1.connectionState === 2 /* Disconnected */) { + return [2 /*return*/, { value: void 0 }]; + } + if (negotiateResponse.error) { + throw Error(negotiateResponse.error); + } + if (negotiateResponse.ProtocolVersion) { + throw Error("检测到尝试连接到一个 非 ASP.NET Core 服务器。此客户端仅支持连接到ASP.NET Core 服务器。. See https://aka.ms/signalr-core-differences for details."); + } + if (negotiateResponse.url) { + url = negotiateResponse.url; + } + if (negotiateResponse.accessToken) { + accessToken_1 = negotiateResponse.accessToken; + // ! 通过 /negotiate 接口返回的assessToken 仅支持 accessTokenFactory(),如果实现了 socketUrlFactory(),会忽略掉这个token + this_1.accessTokenFactory = function () { return accessToken_1; }; + } + redirects++; + return [2 /*return*/]; + } + }); + }; + this_1 = this; + _a.label = 6; + case 6: return [5 /*yield**/, _loop_1()]; + case 7: + state_1 = _a.sent(); + if (typeof state_1 === "object") + return [2 /*return*/, state_1.value]; + _a.label = 8; + case 8: + if (negotiateResponse.url && redirects < MAX_REDIRECTS) return [3 /*break*/, 6]; + _a.label = 9; + case 9: + if (redirects === MAX_REDIRECTS && negotiateResponse.url) { + throw Error("Negotiate redirection limit exceeded. -fy : 超出协商重定向限制"); + } + return [4 /*yield*/, this.createTransport(url, this.options.transport, negotiateResponse, transferFormat)]; + case 10: + _a.sent(); + _a.label = 11; + case 11: + if (this.transport instanceof LongPollingTransport) { + this.features.inherentKeepAlive = true; + } + this.transport.onreceive = this.onreceive; + this.transport.onclose = function (e) { return _this.stopConnection(e); }; + // only change the state if we were connecting to not overwrite + // the state if the connection is already marked as Disconnected + this.changeState(0 /* Connecting */, 1 /* Connected */); + return [2 /*return*/]; + case 12: + e_2 = _a.sent(); + this.logger.log(LogLevel.Error, "Failed to start the connection: ", e_2); + this.connectionState = 2 /* Disconnected */; + this.transport = undefined; + throw e_2; + case 13: return [2 /*return*/]; + } + }); + }); + }; + HttpConnection.prototype.getNegotiationResponse = function (url) { + return __awaiter(this, void 0, void 0, function () { + var headers, token, negotiateUrl, response, e_3; + var _a; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + if (!this.accessTokenFactory) return [3 /*break*/, 2]; + return [4 /*yield*/, this.accessTokenFactory()]; + case 1: + token = _b.sent(); + if (token) { + headers = (_a = {}, + _a["Authorization"] = "Bearer " + token, + _a); + } + _b.label = 2; + case 2: + negotiateUrl = this.resolveNegotiateUrl(url); + this.logger.log(LogLevel.Debug, "Sending negotiation request: " + negotiateUrl + "."); + _b.label = 3; + case 3: + _b.trys.push([3, 5, , 6]); + return [4 /*yield*/, this.request.post(negotiateUrl, {}, { + headers: headers, + responseType: ResponseType.TEXT + })]; + case 4: + response = _b.sent(); + if (response.statusCode !== 200) { + throw Error("Unexpected status code returned from negotiate " + response.statusCode); + } + return [2 /*return*/, JSON.parse(response.data)]; + case 5: + e_3 = _b.sent(); + this.logger.log(LogLevel.Error, "Failed to complete negotiation with the server: ", e_3); + throw e_3; + case 6: return [2 /*return*/]; + } + }); + }); + }; + HttpConnection.prototype.createConnectUrl = function (url, connectionId) { + if (!connectionId) { + return url; + } + return url + (url.indexOf("?") === -1 ? "?" : "&") + ("id=" + connectionId); + }; + HttpConnection.prototype.createTransport = function (url, requestedTransport, negotiateResponse, requestedTransferFormat) { + return __awaiter(this, void 0, void 0, function () { + var connectUrl, transports, _i, transports_1, endpoint, transport, ex_1; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + connectUrl = this.createConnectUrl(url, negotiateResponse.connectionId); + if (!this.isITransport(requestedTransport)) return [3 /*break*/, 2]; + this.logger.log(LogLevel.Debug, "Connection was provided an instance of ITransport, using that directly."); + this.transport = requestedTransport; + return [4 /*yield*/, this.transport.connect({ + url: connectUrl, + transferFormat: requestedTransferFormat + })]; + case 1: + _a.sent(); + // only change the state if we were connecting to not overwrite + // the state if the connection is already marked as Disconnected + this.changeState(0 /* Connecting */, 1 /* Connected */); + return [2 /*return*/]; + case 2: + transports = negotiateResponse.availableTransports || []; + _i = 0, transports_1 = transports; + _a.label = 3; + case 3: + if (!(_i < transports_1.length)) return [3 /*break*/, 9]; + endpoint = transports_1[_i]; + this.connectionState = 0 /* Connecting */; + transport = this.resolveTransport(endpoint, requestedTransport, requestedTransferFormat); + if (!(typeof transport === "number")) return [3 /*break*/, 8]; + this.transport = this.constructTransport(transport); + if (!!negotiateResponse.connectionId) return [3 /*break*/, 5]; + return [4 /*yield*/, this.getNegotiationResponse(url)]; + case 4: + negotiateResponse = _a.sent(); + connectUrl = this.createConnectUrl(url, negotiateResponse.connectionId); + _a.label = 5; + case 5: + _a.trys.push([5, 7, , 8]); + return [4 /*yield*/, this.transport.connect({ + url: connectUrl, + transferFormat: requestedTransferFormat + })]; + case 6: + _a.sent(); + this.changeState(0 /* Connecting */, 1 /* Connected */); + return [2 /*return*/]; + case 7: + ex_1 = _a.sent(); + this.logger.log(LogLevel.Error, "Failed to start the transport '" + HttpTransportType[transport] + "':", ex_1); + this.connectionState = 2 /* Disconnected */; + negotiateResponse.connectionId = undefined; + return [3 /*break*/, 8]; + case 8: + _i++; + return [3 /*break*/, 3]; + case 9: throw new Error("Unable to initialize any of the available transports."); + } + }); + }); + }; + /** + * + * @description 这里对原来的实例化方式进行了改写,如果传入的是实例化完成的 Transport ,将直接返回 + * 如果是传入继承 Transport的 class,将执行 new Transport(options) + * - 这里对原生的多项入参合并成了options(这点差异需要注意) + * @private + * @param {HttpTransportType} transport + * @returns + * @memberof HttpConnection + */ + HttpConnection.prototype.constructTransport = function (transport) { + var _a = this.options, WxSocket = _a.WxSocket, LongPolling = _a.LongPolling, wxSocketTransportOptions = _a.wxSocketTransportOptions, longPollingTransportOptions = _a.longPollingTransportOptions; + switch (transport) { + case HttpTransportType.WebSockets: // wx socket 方式 + if (WxSocket instanceof WxSocketTransport) { + return WxSocket; + } + else { + return new WxSocket(wxSocketTransportOptions + ? wxSocketTransportOptions + : { + // token 工厂 + accessTokenFactory: this.accessTokenFactory, + // socket 单独实现一个socket url factory(用于后端改了 accecc_token 参数名的场景) + socketUrlFactory: this.socketUrlFactory, + // logger + logger: this.logger, + logMessageContent: this.options.logMessageContent || false, + /** 是否允许替换socket连接 + * + * 小程序 版本 < 1.7.0 时, 最多允许存在一个socket连接, 此参数用于是否允许在这个情况下,替换这个打开的socket + */ + allowReplaceSocket: true, + /** 是否启用消息队列缓存连接建立前消息,并在建立连接后发送 */ + enableMessageQueue: this.options.enableMessageQueue == undefined ? true : this.options.enableMessageQueue, + /** 重连设置 */ + reconnect: { + enable: true, + max: 3 + } + }); + } + case HttpTransportType.LongPolling: // 长轮询方式 + if (LongPolling instanceof LongPollingTransport) { + return LongPolling; + } + else { + return new LongPolling(longPollingTransportOptions + ? longPollingTransportOptions + : { + request: this.request, + accessTokenFactory: this.accessTokenFactory, + logger: this.logger, + logMessageContent: this.options.logMessageContent || false + }); + } + default: + throw new Error("Unknown transport: " + transport + "."); + } + }; + HttpConnection.prototype.resolveTransport = function (endpoint, requestedTransport, requestedTransferFormat) { + var transport = HttpTransportType[endpoint.transport]; + if (transport === null || transport === undefined) { + this.logger.log(LogLevel.Debug, "Skipping transport '" + endpoint.transport + "' because it is not supported by this client."); + } + else { + var transferFormats = endpoint.transferFormats.map(function (s) { return TransferFormat[s]; }); + if (transportMatches(requestedTransport, transport)) { + if (transferFormats.indexOf(requestedTransferFormat) >= 0) { + if (transport === HttpTransportType.WebSockets && !this.options.WxSocket) { + this.logger.log(LogLevel.Debug, "Skipping transport '" + HttpTransportType[transport] + "' because it is not supported in your environment.'"); + } + else { + this.logger.log(LogLevel.Debug, "Selecting transport '" + HttpTransportType[transport] + "'."); + return transport; + } + } + else { + this.logger.log(LogLevel.Debug, "Skipping transport '" + HttpTransportType[transport] + "' because it does not support the requested transfer format '" + TransferFormat[requestedTransferFormat] + "'."); + } + } + else { + this.logger.log(LogLevel.Debug, "Skipping transport '" + HttpTransportType[transport] + "' because it was disabled by the client."); + } + } + return null; + }; + HttpConnection.prototype.isITransport = function (transport) { + return transport && typeof transport === "object" && "connect" in transport; + }; + HttpConnection.prototype.changeState = function (from, to) { + if (this.connectionState === from) { + this.connectionState = to; + return true; + } + return false; + }; + HttpConnection.prototype.stopConnection = function (error) { + this.transport = undefined; + // If we have a stopError, it takes precedence over the error from the transport + error = this.stopError || error; + if (error) { + this.logger.log(LogLevel.Error, "Connection disconnected with error '" + error + "'."); + } + else { + this.logger.log(LogLevel.Information, "Connection disconnected."); + } + this.connectionState = 2 /* Disconnected */; + if (this.onclose) { + this.onclose(error); + } + }; + /** + * ! 由于小程序内必须指定 BaseUrl 关系,这里如果不是全路径的话,暂时直接抛出异常 + * @param url + */ + HttpConnection.prototype.resolveUrl = function (url) { + // startsWith is not supported in IE + if (url.lastIndexOf("https://", 0) === 0 || url.lastIndexOf("http://", 0) === 0) { + return url; + } + else { + throw new Error("HttpConnection. \u89E3\u6790url\u9519\u8BEF,\u5C0F\u7A0B\u5E8F\u5185\u9700\u8981\u4F20\u5165\u5168\u8DEF\u5F84 ->link: " + url); + } + }; + HttpConnection.prototype.resolveNegotiateUrl = function (url) { + var index = url.indexOf("?"); + var negotiateUrl = url.substring(0, index === -1 ? url.length : index); + if (negotiateUrl[negotiateUrl.length - 1] !== "/") { + negotiateUrl += "/"; + } + negotiateUrl += "negotiate"; + negotiateUrl += index === -1 ? "" : url.substring(index); + return negotiateUrl; + }; + return HttpConnection; +}()); +export { HttpConnection }; +function transportMatches(requestedTransport, actualTransport) { + return !requestedTransport || (actualTransport & requestedTransport) !== 0; +} diff --git a/miniprogram_npm/signalr-for-wx/HubConnection.js b/miniprogram_npm/signalr-for-wx/HubConnection.js new file mode 100644 index 0000000..2b56bbb --- /dev/null +++ b/miniprogram_npm/signalr-for-wx/HubConnection.js @@ -0,0 +1,546 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +import { HandshakeProtocol } from "./HandshakeProtocol"; +import { MessageType } from "./IHubProtocol"; +import { LogLevel } from "./ILogger"; +import { Arg, Subject } from "./Utils"; +import { EventNotFoundError } from "./Errors"; +var DEFAULT_TIMEOUT_IN_MS = 30 * 1000; +var DEFAULT_PING_INTERVAL_IN_MS = 15 * 1000; +/** Describes the current state of the {@link HubConnection} to the server. */ +export var HubConnectionState; +(function (HubConnectionState) { + /** The hub connection is disconnected. */ + HubConnectionState[HubConnectionState["Disconnected"] = 0] = "Disconnected"; + /** The hub connection is connected. */ + HubConnectionState[HubConnectionState["Connected"] = 1] = "Connected"; +})(HubConnectionState || (HubConnectionState = {})); +/** Represents a connection to a SignalR Hub. */ +var HubConnection = /** @class */ (function () { + function HubConnection(connection, logger, protocol) { + var _this = this; + Arg.isRequired(connection, "connection"); + Arg.isRequired(logger, "logger"); + Arg.isRequired(protocol, "protocol"); + this.serverTimeoutInMilliseconds = DEFAULT_TIMEOUT_IN_MS; + this.keepAliveIntervalInMilliseconds = DEFAULT_PING_INTERVAL_IN_MS; + this.logger = logger; + this.protocol = protocol; + this.connection = connection; + this.handshakeProtocol = new HandshakeProtocol(); + this.connection.onreceive = function (data) { return _this.processIncomingData(data); }; + this.connection.onclose = function (error) { return _this.connectionClosed(error); }; + this.callbacks = {}; + this.methods = {}; + this.closedCallbacks = []; + this.id = 0; + this.receivedHandshakeResponse = false; + this.connectionState = HubConnectionState.Disconnected; + this.cachedPingMessage = this.protocol.writeMessage({ type: MessageType.Ping }); + } + /** @internal */ + // Using a public static factory method means we can have a private constructor and an _internal_ + // create method that can be used by HubConnectionBuilder. An "internal" constructor would just + // be stripped away and the '.d.ts' file would have no constructor, which is interpreted as a + // public parameter-less constructor. + HubConnection.create = function (connection, logger, protocol) { + return new HubConnection(connection, logger, protocol); + }; + Object.defineProperty(HubConnection.prototype, "state", { + /** Indicates the state of the {@link HubConnection} to the server. */ + get: function () { + return this.connectionState; + }, + enumerable: true, + configurable: true + }); + /** Starts the connection. + * + * @returns {Promise} A Promise that resolves when the connection has been successfully established, or rejects with an error. + */ + HubConnection.prototype.start = function () { + return __awaiter(this, void 0, void 0, function () { + var handshakeRequest, handshakePromise; + var _this = this; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + handshakeRequest = { + protocol: this.protocol.name, + version: this.protocol.version + }; + this.logger.log(LogLevel.Debug, "Starting HubConnection."); + this.receivedHandshakeResponse = false; + handshakePromise = new Promise(function (resolve, reject) { + _this.handshakeResolver = resolve; + _this.handshakeRejecter = reject; + }); + return [4 /*yield*/, this.connection.start(this.protocol.transferFormat)]; + case 1: + _a.sent(); + this.logger.log(LogLevel.Debug, "Sending handshake request."); + return [4 /*yield*/, this.sendMessage(this.handshakeProtocol.writeHandshakeRequest(handshakeRequest))]; + case 2: + _a.sent(); + this.logger.log(LogLevel.Information, "Using HubProtocol '" + this.protocol.name + "'.", this.protocol); + // defensively cleanup timeout in case we receive a message from the server before we finish start + this.cleanupTimeout(); + this.resetTimeoutPeriod(); + this.resetKeepAliveInterval(); + // Wait for the handshake to complete before marking connection as connected + return [4 /*yield*/, handshakePromise]; + case 3: + // Wait for the handshake to complete before marking connection as connected + _a.sent(); + this.connectionState = HubConnectionState.Connected; + return [2 /*return*/]; + } + }); + }); + }; + /** Stops the connection. + * + * @returns {Promise} A Promise that resolves when the connection has been successfully terminated, or rejects with an error. + */ + HubConnection.prototype.stop = function () { + this.logger.log(LogLevel.Debug, "Stopping HubConnection."); + this.cleanupTimeout(); + this.cleanupPingTimer(); + return this.connection.stop(); + }; + /** Invokes a streaming hub method on the server using the specified name and arguments. + * + * @typeparam T The type of the items returned by the server. + * @param {string} methodName The name of the server method to invoke. + * @param {any[]} args The arguments used to invoke the server method. + * @returns {IStreamResult} An object that yields results from the server as they are received. + */ + HubConnection.prototype.stream = function (methodName) { + var _this = this; + var args = []; + for (var _i = 1; _i < arguments.length; _i++) { + args[_i - 1] = arguments[_i]; + } + var invocationDescriptor = this.createStreamInvocation(methodName, args); + var subject = new Subject(function () { + var cancelInvocation = _this.createCancelInvocation(invocationDescriptor.invocationId); + var cancelMessage = _this.protocol.writeMessage(cancelInvocation); + delete _this.callbacks[invocationDescriptor.invocationId]; + return _this.sendMessage(cancelMessage); + }); + this.callbacks[invocationDescriptor.invocationId] = function (invocationEvent, error) { + if (error) { + subject.error(error); + return; + } + else if (invocationEvent) { + // invocationEvent will not be null when an error is not passed to the callback + if (invocationEvent.type === MessageType.Completion) { + if (invocationEvent.error) { + subject.error(new Error(invocationEvent.error)); + } + else { + subject.complete(); + } + } + else { + subject.next(invocationEvent.item); + } + } + }; + var message = this.protocol.writeMessage(invocationDescriptor); + this.sendMessage(message).catch(function (e) { + subject.error(e); + delete _this.callbacks[invocationDescriptor.invocationId]; + }); + return subject; + }; + HubConnection.prototype.sendMessage = function (message) { + this.resetKeepAliveInterval(); + return this.connection.send(message); + }; + /** Invokes a hub method on the server using the specified name and arguments. Does not wait for a response from the receiver. + * + * The Promise returned by this method resolves when the client has sent the invocation to the server. The server may still + * be processing the invocation. + * + * @param {string} methodName The name of the server method to invoke. + * @param {any[]} args The arguments used to invoke the server method. + * @returns {Promise} A Promise that resolves when the invocation has been successfully sent, or rejects with an error. + */ + HubConnection.prototype.send = function (methodName) { + var args = []; + for (var _i = 1; _i < arguments.length; _i++) { + args[_i - 1] = arguments[_i]; + } + var invocationDescriptor = this.createInvocation(methodName, args, true); + var message = this.protocol.writeMessage(invocationDescriptor); + return this.sendMessage(message); + }; + /** Invokes a hub method on the server using the specified name and arguments. + * + * The Promise returned by this method resolves when the server indicates it has finished invoking the method. When the promise + * resolves, the server has finished invoking the method. If the server method returns a result, it is produced as the result of + * resolving the Promise. + * + * @typeparam T The expected return type. + * @param {string} methodName The name of the server method to invoke. + * @param {any[]} args The arguments used to invoke the server method. + * @returns {Promise} A Promise that resolves with the result of the server method (if any), or rejects with an error. + */ + HubConnection.prototype.invoke = function (methodName) { + var _this = this; + var args = []; + for (var _i = 1; _i < arguments.length; _i++) { + args[_i - 1] = arguments[_i]; + } + var invocationDescriptor = this.createInvocation(methodName, args, false); + var p = new Promise(function (resolve, reject) { + // invocationId will always have a value for a non-blocking invocation + _this.callbacks[invocationDescriptor.invocationId] = function (invocationEvent, error) { + if (error) { + reject(error); + return; + } + else if (invocationEvent) { + // invocationEvent will not be null when an error is not passed to the callback + if (invocationEvent.type === MessageType.Completion) { + if (invocationEvent.error) { + reject(new Error(invocationEvent.error)); + } + else { + resolve(invocationEvent.result); + } + } + else { + reject(new Error("Unexpected message type: " + invocationEvent.type)); + } + } + }; + var message = _this.protocol.writeMessage(invocationDescriptor); + _this.sendMessage(message).catch(function (e) { + reject(e); + // invocationId will always have a value for a non-blocking invocation + delete _this.callbacks[invocationDescriptor.invocationId]; + }); + }); + return p; + }; + HubConnection.prototype.on = function (methodName, newMethod, only) { + if (!methodName || !newMethod) { + return; + } + methodName = methodName.toLowerCase(); + if (only) { + this.methods[methodName] = [newMethod]; + return; + } + if (!this.methods[methodName]) { + this.methods[methodName] = []; + } + // Preventing adding the same handler multiple times. + if (this.methods[methodName].indexOf(newMethod) !== -1) { + return; + } + this.methods[methodName].push(newMethod); + }; + HubConnection.prototype.off = function (methodName, method) { + if (!methodName) { + return; + } + methodName = methodName.toLowerCase(); + var handlers = this.methods[methodName]; + if (!handlers) { + return; + } + if (method) { + var removeIdx = handlers.indexOf(method); + if (removeIdx !== -1) { + handlers.splice(removeIdx, 1); + if (handlers.length === 0) { + delete this.methods[methodName]; + } + } + } + else { + delete this.methods[methodName]; + } + }; + /** Registers a handler that will be invoked when the connection is closed. + * + * @param {Function} callback The handler that will be invoked when the connection is closed. Optionally receives a single argument containing the error that caused the connection to close (if any). + */ + HubConnection.prototype.onclose = function (callback) { + if (callback) { + this.closedCallbacks.push(callback); + } + }; + HubConnection.prototype.onEventNotFound = function (callback) { + if (callback) { + this.eventNotFoundCallback = callback; + } + }; + HubConnection.prototype.processIncomingData = function (data) { + this.cleanupTimeout(); + if (!this.receivedHandshakeResponse) { + data = this.processHandshakeResponse(data); + this.receivedHandshakeResponse = true; + } + // Data may have all been read when processing handshake response + if (data) { + // Parse the messages + var messages = this.protocol.parseMessages(data, this.logger); + for (var _i = 0, messages_1 = messages; _i < messages_1.length; _i++) { + var message = messages_1[_i]; + switch (message.type) { + case MessageType.Invocation: + this.invokeClientMethod(message); + break; + case MessageType.StreamItem: + case MessageType.Completion: + var callback = this.callbacks[message.invocationId]; + if (callback != null) { + if (message.type === MessageType.Completion) { + delete this.callbacks[message.invocationId]; + } + callback(message); + } + break; + case MessageType.Ping: + // Don't care about pings + break; + case MessageType.Close: + this.logger.log(LogLevel.Information, "Close message received from server."); + // We don't want to wait on the stop itself. + // tslint:disable-next-line:no-floating-promises + this.connection.stop(message.error ? new Error("Server returned an error on close: " + message.error) : undefined); + break; + default: + this.logger.log(LogLevel.Warning, "Invalid message type: " + message.type + ".", message); + break; + } + } + } + this.resetTimeoutPeriod(); + }; + HubConnection.prototype.processHandshakeResponse = function (data) { + var _a; + var responseMessage; + var remainingData; + try { + _a = this.handshakeProtocol.parseHandshakeResponse(data), remainingData = _a[0], responseMessage = _a[1]; + } + catch (e) { + var message = "Error parsing handshake response: " + e; + this.logger.log(LogLevel.Error, message); + var error = new Error(message); + // We don't want to wait on the stop itself. + // tslint:disable-next-line:no-floating-promises + this.connection.stop(error); + this.handshakeRejecter(error); + throw error; + } + if (responseMessage.error) { + var message = "Server returned handshake error: " + responseMessage.error; + this.logger.log(LogLevel.Error, message); + this.handshakeRejecter(message); + // We don't want to wait on the stop itself. + // tslint:disable-next-line:no-floating-promises + this.connection.stop(new Error(message)); + throw new Error(message); + } + else { + this.logger.log(LogLevel.Debug, "Server handshake complete."); + } + this.handshakeResolver(); + return remainingData; + }; + HubConnection.prototype.resetKeepAliveInterval = function () { + var _this = this; + this.cleanupPingTimer(); + this.pingServerHandle = setTimeout(function () { return __awaiter(_this, void 0, void 0, function () { + var _a; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + if (!(this.connectionState === HubConnectionState.Connected)) return [3 /*break*/, 4]; + _b.label = 1; + case 1: + _b.trys.push([1, 3, , 4]); + return [4 /*yield*/, this.sendMessage(this.cachedPingMessage)]; + case 2: + _b.sent(); + return [3 /*break*/, 4]; + case 3: + _a = _b.sent(); + // We don't care about the error. It should be seen elsewhere in the client. + // The connection is probably in a bad or closed state now, cleanup the timer so it stops triggering + this.cleanupPingTimer(); + return [3 /*break*/, 4]; + case 4: return [2 /*return*/]; + } + }); + }); }, this.keepAliveIntervalInMilliseconds); + }; + HubConnection.prototype.resetTimeoutPeriod = function () { + var _this = this; + if (!this.connection.features || !this.connection.features.inherentKeepAlive) { + // Set the timeout timer + this.timeoutHandle = setTimeout(function () { return _this.serverTimeout(); }, this.serverTimeoutInMilliseconds); + } + }; + HubConnection.prototype.serverTimeout = function () { + // The server hasn't talked to us in a while. It doesn't like us anymore ... :( + // Terminate the connection, but we don't need to wait on the promise. + // tslint:disable-next-line:no-floating-promises + this.connection.stop(new Error("Server timeout elapsed without receiving a message from the server.")); + }; + HubConnection.prototype.invokeClientMethod = function (invocationMessage) { + var _this = this; + var methods = this.methods[invocationMessage.target.toLowerCase()]; + if (methods) { + try { + // Time:2020年1月1日 22:30:30 增加一个 try cache, 获取 signalr 在特定场景下,处理事件失败会关闭问题. + methods.forEach(function (m) { return m.apply(_this, invocationMessage.arguments); }); + } + catch (error) { + console.error(error); + } + if (invocationMessage.invocationId) { + // This is not supported in v1. So we return an error to avoid blocking the server waiting for the response. + var message = "Server requested a response, which is not supported in this version of the client."; + this.logger.log(LogLevel.Error, message); + // We don't need to wait on this Promise. + // tslint:disable-next-line:no-floating-promises + this.connection.stop(new Error(message)); + } + } + else { + var message = "No client method with the name '" + invocationMessage.target + "' found."; + this.logger.log(LogLevel.Warning, message); + this.logger.log(LogLevel.Information, "Current Event Methods:" + Object.keys(this.methods)); + this.eventNotFound(new EventNotFoundError(invocationMessage, message)); + } + }; + HubConnection.prototype.connectionClosed = function (error) { + var _this = this; + var callbacks = this.callbacks; + this.callbacks = {}; + this.connectionState = HubConnectionState.Disconnected; + // if handshake is in progress start will be waiting for the handshake promise, so we complete it + // if it has already completed this should just noop + if (this.handshakeRejecter) { + this.handshakeRejecter(error); + } + Object.keys(callbacks).forEach(function (key) { + var callback = callbacks[key]; + callback(null, error ? error : new Error("Invocation canceled due to connection being closed.")); + }); + this.cleanupTimeout(); + this.cleanupPingTimer(); + this.closedCallbacks.forEach(function (c) { return c.apply(_this, [error]); }); + }; + HubConnection.prototype.eventNotFound = function (error) { + return __awaiter(this, void 0, void 0, function () { + var r; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!this.eventNotFoundCallback) return [3 /*break*/, 2]; + return [4 /*yield*/, this.eventNotFoundCallback(error)]; + case 1: + r = _a.sent(); + if (r === true) { + this.logger.log(LogLevel.Information, "retry invoke local message callback."); + this.invokeClientMethod(error.invocationMessage); + } + _a.label = 2; + case 2: return [2 /*return*/]; + } + }); + }); + }; + HubConnection.prototype.cleanupPingTimer = function () { + if (this.pingServerHandle) { + clearTimeout(this.pingServerHandle); + } + }; + HubConnection.prototype.cleanupTimeout = function () { + if (this.timeoutHandle) { + clearTimeout(this.timeoutHandle); + } + }; + HubConnection.prototype.createInvocation = function (methodName, args, nonblocking) { + if (nonblocking) { + return { + arguments: args, + target: methodName, + type: MessageType.Invocation + }; + } + else { + var id = this.id; + this.id++; + return { + arguments: args, + invocationId: id.toString(), + target: methodName, + type: MessageType.Invocation + }; + } + }; + HubConnection.prototype.createStreamInvocation = function (methodName, args) { + var id = this.id; + this.id++; + return { + arguments: args, + invocationId: id.toString(), + target: methodName, + type: MessageType.StreamInvocation + }; + }; + HubConnection.prototype.createCancelInvocation = function (id) { + return { + invocationId: id, + type: MessageType.CancelInvocation + }; + }; + return HubConnection; +}()); +export { HubConnection }; diff --git a/miniprogram_npm/signalr-for-wx/HubConnectionBuilder.js b/miniprogram_npm/signalr-for-wx/HubConnectionBuilder.js new file mode 100644 index 0000000..0406f21 --- /dev/null +++ b/miniprogram_npm/signalr-for-wx/HubConnectionBuilder.js @@ -0,0 +1,71 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +import { HttpConnection } from "./HttpConnection"; +import { HubConnection } from "./HubConnection"; +import { JsonHubProtocol } from "./JsonHubProtocol"; +import { NullLogger } from "./Loggers"; +import { Arg, ConsoleLogger } from "./Utils"; +/** A builder for configuring {@link @aspnet/signalr.HubConnection} instances. */ +var HubConnectionBuilder = /** @class */ (function () { + function HubConnectionBuilder() { + } + HubConnectionBuilder.prototype.configureLogging = function (logging) { + Arg.isRequired(logging, "logging"); + if (isLogger(logging)) { + this.logger = logging; + } + else { + this.logger = new ConsoleLogger(logging); + } + return this; + }; + HubConnectionBuilder.prototype.withUrl = function (url, transportTypeOrOptions) { + Arg.isRequired(url, "url"); + this.url = url; + // Flow-typing knows where it's at. Since HttpTransportType is a number and IHttpConnectionOptions is guaranteed + // to be an object, we know (as does TypeScript) this comparison is all we need to figure out which overload was called. + if (typeof transportTypeOrOptions === "object") { + this.httpConnectionOptions = transportTypeOrOptions; + } + else { + this.httpConnectionOptions = { + transport: transportTypeOrOptions, + }; + } + return this; + }; + /** Configures the {@link @aspnet/signalr.HubConnection} to use the specified Hub Protocol. + * + * @param {IHubProtocol} protocol The {@link @aspnet/signalr.IHubProtocol} implementation to use. + */ + HubConnectionBuilder.prototype.withHubProtocol = function (protocol) { + Arg.isRequired(protocol, "protocol"); + this.protocol = protocol; + return this; + }; + /** Creates a {@link @aspnet/signalr.HubConnection} from the configuration options specified in this builder. + * + * @returns {HubConnection} The configured {@link @aspnet/signalr.HubConnection}. + */ + HubConnectionBuilder.prototype.build = function () { + // If httpConnectionOptions has a logger, use it. Otherwise, override it with the one + // provided to configureLogger + var httpConnectionOptions = this.httpConnectionOptions || {}; + // If it's 'null', the user **explicitly** asked for null, don't mess with it. + if (httpConnectionOptions.logger === undefined) { + // If our logger is undefined or null, that's OK, the HttpConnection constructor will handle it. + httpConnectionOptions.logger = this.logger; + } + // Now create the connection + if (!this.url) { + throw new Error("The 'HubConnectionBuilder.withUrl' method must be called before building the connection."); + } + var connection = new HttpConnection(this.url, httpConnectionOptions); + return HubConnection.create(connection, this.logger || NullLogger.instance, this.protocol || new JsonHubProtocol()); + }; + return HubConnectionBuilder; +}()); +export { HubConnectionBuilder }; +function isLogger(logger) { + return logger.log !== undefined; +} diff --git a/miniprogram_npm/signalr-for-wx/IConnection.js b/miniprogram_npm/signalr-for-wx/IConnection.js new file mode 100644 index 0000000..95328c3 --- /dev/null +++ b/miniprogram_npm/signalr-for-wx/IConnection.js @@ -0,0 +1,2 @@ +// 版权所有(c).NET基金会。保留所有权利。 +// 在2.0版Apache许可下授权。有关许可证信息,请参见项目根目录中的License.txt。 diff --git a/miniprogram_npm/signalr-for-wx/IHttpConnectionOptions.js b/miniprogram_npm/signalr-for-wx/IHttpConnectionOptions.js new file mode 100644 index 0000000..95328c3 --- /dev/null +++ b/miniprogram_npm/signalr-for-wx/IHttpConnectionOptions.js @@ -0,0 +1,2 @@ +// 版权所有(c).NET基金会。保留所有权利。 +// 在2.0版Apache许可下授权。有关许可证信息,请参见项目根目录中的License.txt。 diff --git a/miniprogram_npm/signalr-for-wx/IHubProtocol.js b/miniprogram_npm/signalr-for-wx/IHubProtocol.js new file mode 100644 index 0000000..d04194b --- /dev/null +++ b/miniprogram_npm/signalr-for-wx/IHubProtocol.js @@ -0,0 +1,34 @@ +// 版权所有(c).NET基金会。保留所有权利。 +// 在2.0版Apache许可下授权。有关许可证信息,请参见项目根目录中的License.txt。 +/* 定义消息的类型[枚举] */ +export var MessageType; +(function (MessageType) { + /** + * - 指示消息是一个 `调用消息` 并实现 {@link @aspnet/signalr.InvocationMessage} 接口。 + */ + MessageType[MessageType["Invocation"] = 1] = "Invocation"; + /** + * - 指示消息是一个 `流消息` 并实现 {@link @aspnet/signalr.StreamItemMessage} 接口。 + */ + MessageType[MessageType["StreamItem"] = 2] = "StreamItem"; + /** + * - 指示消息是一个 `完成消息` 并实现 {@link @aspnet/signalr.CompletionMessage} 接口。 + */ + MessageType[MessageType["Completion"] = 3] = "Completion"; + /** + * - 指示消息是一个 `流调用消息` 并实现 {@link @aspnet/signalr.StreamInvocationMessage} 接口。 + */ + MessageType[MessageType["StreamInvocation"] = 4] = "StreamInvocation"; + /** + * - 指示消息是一个 `取消调用消息` 并实现 {@link @aspnet/signalr.CancelInvocationMessage} 接口。 + */ + MessageType[MessageType["CancelInvocation"] = 5] = "CancelInvocation"; + /** + * - 指示消息是一个 `Ping消息` 并实现 {@link @aspnet/signalr.PingMessage} 接口。 + */ + MessageType[MessageType["Ping"] = 6] = "Ping"; + /** + * - 指示消息是一个 `关闭消息` 并实现 {@link @aspnet/signalr.CloseMessage} 接口。 + */ + MessageType[MessageType["Close"] = 7] = "Close"; +})(MessageType || (MessageType = {})); diff --git a/miniprogram_npm/signalr-for-wx/ILogger.js b/miniprogram_npm/signalr-for-wx/ILogger.js new file mode 100644 index 0000000..67bdc07 --- /dev/null +++ b/miniprogram_npm/signalr-for-wx/ILogger.js @@ -0,0 +1,25 @@ +// 版权所有(c).NET基金会。保留所有权利。 +// 在2.0版Apache许可下授权。有关许可证信息,请参见项目根目录中的License.txt。 +//这些值被设计为与ASP.NET日志级别匹配,因为这是我们在这里模拟的模式。 +/** + * 指示日志消息的严重性。 + * 日志级别按严重性递增的顺序排列。所以“Debug”比“Trace”等更严重。 + * + */ +export var LogLevel; +(function (LogLevel) { + /** 极低严重性诊断消息的日志级别. */ + LogLevel[LogLevel["Trace"] = 0] = "Trace"; + /** 调试错误. */ + LogLevel[LogLevel["Debug"] = 1] = "Debug"; + /** 消息. */ + LogLevel[LogLevel["Information"] = 2] = "Information"; + /** 警告. */ + LogLevel[LogLevel["Warning"] = 3] = "Warning"; + /** 错误. */ + LogLevel[LogLevel["Error"] = 4] = "Error"; + /** 严重错误. */ + LogLevel[LogLevel["Critical"] = 5] = "Critical"; + /** 最高日志级别。在配置日志记录以指示不应发出日志消息时使用. */ + LogLevel[LogLevel["None"] = 6] = "None"; +})(LogLevel || (LogLevel = {})); diff --git a/miniprogram_npm/signalr-for-wx/ITransport.js b/miniprogram_npm/signalr-for-wx/ITransport.js new file mode 100644 index 0000000..606fed1 --- /dev/null +++ b/miniprogram_npm/signalr-for-wx/ITransport.js @@ -0,0 +1,21 @@ +// 版权所有(c).NET基金会。保留所有权利。 +// 在2.0版Apache许可下授权。有关许可证信息,请参见项目根目录中的License.txt。 +//这在将来会被当作一个位标志,所以我们使用两个值的幂来保持它。 +/**指定特定的HTTP传输类型。*/ +export var HttpTransportType; +(function (HttpTransportType) { + /**未指定传输首选项。*/ + HttpTransportType[HttpTransportType["None"] = 0] = "None"; + /**指定WebSocket传输。*/ + HttpTransportType[HttpTransportType["WebSockets"] = 1] = "WebSockets"; + /**指定长轮询传输。*/ + HttpTransportType[HttpTransportType["LongPolling"] = 4] = "LongPolling"; +})(HttpTransportType || (HttpTransportType = {})); +/**指定连接的传输格式。*/ +export var TransferFormat; +(function (TransferFormat) { + /**指定仅通过连接传输文本数据。*/ + TransferFormat[TransferFormat["Text"] = 1] = "Text"; + /**指定将通过连接传输二进制数据。*/ + TransferFormat[TransferFormat["Binary"] = 2] = "Binary"; +})(TransferFormat || (TransferFormat = {})); diff --git a/miniprogram_npm/signalr-for-wx/JsonHubProtocol.js b/miniprogram_npm/signalr-for-wx/JsonHubProtocol.js new file mode 100644 index 0000000..518aaae --- /dev/null +++ b/miniprogram_npm/signalr-for-wx/JsonHubProtocol.js @@ -0,0 +1,129 @@ +// 版权所有(c).NET基金会。保留所有权利。 +// 在2.0版Apache许可下授权。有关许可证信息,请参见项目根目录中的License.txt。 +import { MessageType } from "./IHubProtocol"; +import { LogLevel } from "./ILogger"; +import { TransferFormat } from "./ITransport"; +import { NullLogger } from "./Loggers"; +import { TextMessageFormat } from "./TextMessageFormat"; +var JSON_HUB_PROTOCOL_NAME = "json"; +/** Implements the JSON Hub Protocol. */ +var JsonHubProtocol = /** @class */ (function () { + function JsonHubProtocol() { + /** @inheritDoc */ + this.name = JSON_HUB_PROTOCOL_NAME; + /** @inheritDoc */ + this.version = 1; + /** @inheritDoc */ + this.transferFormat = TransferFormat.Text; + } + /** + * Creates an array of {@link @aspnet/signalr.HubMessage} objects from the specified serialized representation. + * 从指定的序列化表示创建{@link@aspnet/signaler.HubMessage}对象数组 + * + * @param {string} input 包含序列化表示的字符串 A string containing the serialized representation. + * @param {ILogger} logger + */ + JsonHubProtocol.prototype.parseMessages = function (input, logger) { + // 接口允许传入“ArrayBuffer”,但此实现不允许。所以让我们抛出一个有用的错误 + if (typeof input !== "string") { + throw new Error("Invalid input for JSON hub protocol. Expected a string. (fy:包含一个无效的JSON协议输入,但是这里需要输入string 消息)"); + } + // fixed + if (!input) { + return []; + } + // fixed + if (logger === null) { + logger = NullLogger.instance; + } + // string 类型消息格式化转换 + var messages = TextMessageFormat.parse(input); + var hubMessages = []; + for (var _i = 0, messages_1 = messages; _i < messages_1.length; _i++) { + var message = messages_1[_i]; + // 转换消息 + var parsedMessage = JSON.parse(message); + if (typeof parsedMessage.type !== "number") { + throw new Error("Invalid payload. (fy: 无效的消息)"); + } + switch (parsedMessage.type) { + case MessageType.Invocation: // 调用命令 + this.isInvocationMessage(parsedMessage); + break; + case MessageType.StreamItem: // 流消息 + this.isStreamItemMessage(parsedMessage); + break; + case MessageType.Completion: // 完成消息 + this.isCompletionMessage(parsedMessage); + break; + case MessageType.Ping: // ping 命令 + // Single value, no need to validate + break; + case MessageType.Close: // 关闭命令 + // All optional values, no need to validate + break; + default: // 未定义命令,抛出异常 + // Future protocol changes can add message types, old clients can ignore them + logger.log(LogLevel.Information, "Unknown message type '" + parsedMessage.type + "' ignored."); + continue; + } + hubMessages.push(parsedMessage); + } + return hubMessages; + }; + /** + * Writes the specified {@link @aspnet/signalr.HubMessage} to a string and returns it. + * 将指定的{@link@aspnet/signalr.HubMessage}写入字符串并返回 + * + * @param {HubMessage} message The message to write. 消息内容 + * @returns {string} 包含消息的序列化表示形式的字符串。 + */ + JsonHubProtocol.prototype.writeMessage = function (message) { + return TextMessageFormat.write(JSON.stringify(message)); + }; + /** + * 判断是否是一个正常的调用消息 + * @param message + */ + JsonHubProtocol.prototype.isInvocationMessage = function (message) { + this.assertNotEmptyString(message.target, "Invalid payload for Invocation message."); + if (message.invocationId !== undefined) { + this.assertNotEmptyString(message.invocationId, "Invalid payload for Invocation message. (fy:无效的 [调用] 消息)"); + } + }; + /** + * 判断是否是一个流消息子项 + * @param message + */ + JsonHubProtocol.prototype.isStreamItemMessage = function (message) { + this.assertNotEmptyString(message.invocationId, "Invalid payload for StreamItem message. (fy:无效的 [StreamItem] 消息)"); + if (message.item === undefined) { + throw new Error("Invalid payload for StreamItem message. (fy:无效的 [StreamItem] 消息)"); + } + }; + /** + * 判断是否是一个完整的消息 + * @param message + */ + JsonHubProtocol.prototype.isCompletionMessage = function (message) { + if (message.result && message.error) { + throw new Error("Invalid payload for Completion message (fy:消息不完整)."); + } + if (!message.result && message.error) { + this.assertNotEmptyString(message.error, "Invalid payload for Completion message (fy:消息不完整)."); + } + this.assertNotEmptyString(message.invocationId, "Invalid payload for Completion message (fy:消息不完整)."); + }; + /** + * 断言非空字符串 + * @param value + * @param errorMessage + */ + JsonHubProtocol.prototype.assertNotEmptyString = function (value, errorMessage) { + if (typeof value !== "string" || value === "") { + throw new Error(errorMessage); + } + }; + return JsonHubProtocol; +}()); +export { JsonHubProtocol }; diff --git a/miniprogram_npm/signalr-for-wx/Loggers.js b/miniprogram_npm/signalr-for-wx/Loggers.js new file mode 100644 index 0000000..59fc6f5 --- /dev/null +++ b/miniprogram_npm/signalr-for-wx/Loggers.js @@ -0,0 +1,17 @@ +// 版权所有(c).NET基金会。保留所有权利。 +// 在2.0版Apache许可下授权。有关许可证信息,请参见项目根目录中的License.txt。 +/** 未定义 logger 时使用的 空输出实现. */ +var NullLogger = /** @class */ (function () { + function NullLogger() { + } + NullLogger.prototype.log = function (logLevel) { + var msg = []; + for (var _i = 1; _i < arguments.length; _i++) { + msg[_i - 1] = arguments[_i]; + } + }; + /** The singleton instance of the {@link @aspnet/signalr.NullLogger}. */ + NullLogger.instance = new NullLogger(); + return NullLogger; +}()); +export { NullLogger }; diff --git a/miniprogram_npm/signalr-for-wx/LongPollingTransport.js b/miniprogram_npm/signalr-for-wx/LongPollingTransport.js new file mode 100644 index 0000000..c3adad2 --- /dev/null +++ b/miniprogram_npm/signalr-for-wx/LongPollingTransport.js @@ -0,0 +1,380 @@ +// 版权所有(c).NET基金会。保留所有权利。 +// 在2.0版Apache许可下授权。有关许可证信息,请参见项目根目录中的License.txt。 +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +import { AbortController } from "./AbortController"; +import { HttpError, TimeoutError } from "./Errors"; +import { LogLevel } from "./ILogger"; +import { TransferFormat } from "./ITransport"; +import { Arg, getDataDetail, sendMessage } from "./Utils"; +import { ResponseType } from "./wx-request/model/ResponseType"; +import { NullLogger } from './Loggers'; +import DefaultRequest from "./DefualtRequest"; +// Not exported from 'index', this type is internal. +/** + * 长轮询 + * @private + */ +var LongPollingTransport = /** @class */ (function () { + /** + * 导出 request 工具 + * @param {Request} request + * @param {((() => string | Promise) | undefined)} accessTokenFactory access-token-factory + * @param {ILogger} logger + * @param {boolean} logMessageContent + * @memberof LongPollingTransport + */ + function LongPollingTransport(options) { + this.accessTokenFactory = options.accessTokenFactory ? options.accessTokenFactory : undefined; + this.logger = options.logger ? options.logger : new NullLogger(); + this.pollAbort = new AbortController(); + this.logMessageContent = options.logMessageContent ? options.logMessageContent : false; + this.request = options.request ? options.request : new DefaultRequest({}, this.logger); + this.running = false; + this.onreceive = null; + this.onclose = null; + } + Object.defineProperty(LongPollingTransport.prototype, "pollAborted", { + // This is an internal type, not exported from 'index' so this is really just internal. + get: function () { + return this.pollAbort.aborted; + }, + enumerable: true, + configurable: true + }); + /** + * 连接 - 这里理解为请求 + * + * @param {string} url + * @param {TransferFormat} transferFormat + * @returns {Promise} + * @memberof LongPollingTransport + */ + LongPollingTransport.prototype.connect = function (options) { + return __awaiter(this, void 0, void 0, function () { + var pollOptions, token, response; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + /* 验证参数完整性,不完整抛出异常 */ + Arg.isRequired(options, "options"); + Arg.isRequired(options.transferFormat, "transferFormat"); + Arg.isIn(options.transferFormat, TransferFormat, "transferFormat"); + // update options + this.url = options.url; + // print log + this.logger.log(LogLevel.Trace, "(LongPolling transport) Connecting."); + pollOptions = { + config: { + // 中断信号 + about: this.pollAbort.signal.aborted, + timeout: 120 * 1000 // 超时时间 2 min + }, + // origin header 头 + headers: {} + }; + if (options.transferFormat === TransferFormat.Binary) { + pollOptions.responseType = ResponseType.ARRAY_BUFFER; + } + return [4 /*yield*/, this.getAccessToken()]; + case 1: + token = _a.sent(); + this.updateHeaderToken(pollOptions, token); + // Make initial long polling request + // Server uses first long polling request to finish initializing connection and it returns without data + //发出初始长轮询请求 + //服务器使用第一个长轮询请求完成连接初始化,它返回时不带数据 + this.logger.log(LogLevel.Trace, "(LongPolling transport) polling: [url]" + this.url); + return [4 /*yield*/, this.request.get(this.url, { + _: Date.now() + }, pollOptions)]; + case 2: + response = _a.sent(); + if (response.statusCode !== 200) { + this.logger.log(LogLevel.Error, "(LongPolling transport) Unexpected response code: " + response.statusCode + "."); + // Mark running as false so that the poll immediately ends and runs the close logic + // ! 重写了 内置 的 创建 `HttpError` 方法 + this.closeError = new HttpError(response.errMsg || "", response.statusCode); + this.running = false; + } + else { + this.running = true; + } + this.receiving = this.poll(this.url, pollOptions); + return [2 /*return*/, Promise.resolve({ + errMsg: "connect success" + })]; + } + }); + }); + }; + /** + * 获取 access-token + * + * @private + * @returns {(Promise)} + * @memberof LongPollingTransport + */ + LongPollingTransport.prototype.getAccessToken = function () { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!this.accessTokenFactory) return [3 /*break*/, 2]; + return [4 /*yield*/, this.accessTokenFactory()]; + case 1: return [2 /*return*/, _a.sent()]; + case 2: return [2 /*return*/, null]; + } + }); + }); + }; + /** + * 更新 access-token + * + * @private + * @param {RequestOption} request + * @param {(string | null)} token + * @returns + * @memberof LongPollingTransport + */ + LongPollingTransport.prototype.updateHeaderToken = function (request, token) { + /** + * fix header + */ + if (!request.headers) { + request.headers = {}; + } + /** + * push token to headers + */ + if (token) { + // tslint:disable-next-line:no-string-literal + request.headers["Authorization"] = "Bearer " + token; + return; + } + // tslint:disable-next-line:no-string-literal + if (request.headers["Authorization"]) { + // tslint:disable-next-line:no-string-literal + delete request.headers["Authorization"]; + } + }; + /** + * 异步计数? + * + * @private + * @param {string} url + * @param {RequestOption} pollOptions + * @returns {Promise} + * @memberof LongPollingTransport + */ + LongPollingTransport.prototype.poll = function (url, pollOptions) { + return __awaiter(this, void 0, void 0, function () { + var token, pollUrl, response, e_1; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + _a.trys.push([0, , 8, 9]); + _a.label = 1; + case 1: + if (!this.running) return [3 /*break*/, 7]; + return [4 /*yield*/, this.getAccessToken()]; + case 2: + token = _a.sent(); + this.updateHeaderToken(pollOptions, token); + _a.label = 3; + case 3: + _a.trys.push([3, 5, , 6]); + pollUrl = url + "&_=" + Date.now(); + this.logger.log(LogLevel.Trace, "(LongPolling transport) polling: " + pollUrl + ". - (fy:\u957F\u8F6E\u8BE2\u4F20\u8F93 - polling)"); + return [4 /*yield*/, this.request.get(this.url, { + _: Date.now() + }, pollOptions)]; + case 4: + response = _a.sent(); + if (response.statusCode === 204) { + this.logger.log(LogLevel.Information, "(LongPolling transport) Poll terminated by server. - (fy:长轮询传输 - 由服务器终止轮询。)"); + this.running = false; + } + else if (response.statusCode !== 200) { + this.logger.log(LogLevel.Error, "(LongPolling transport) Unexpected response code: " + response.statusCode + ". - (fy:\u957F\u8F6E\u8BE2\u4F20\u8F93 - \u610F\u5916\u7684\u54CD\u5E94\u4EE3\u7801)"); + // Unexpected status code + this.closeError = new HttpError(response.errMsg || "", response.statusCode); + this.running = false; + } + else { + // Process the response + if (response.data) { + this.logger.log(LogLevel.Trace, "(LongPolling transport) data received. " + getDataDetail(response.data, this.logMessageContent) + "."); + if (this.onreceive) { + this.onreceive(response.data); + } + } + else { + // This is another way timeout manifest. + this.logger.log(LogLevel.Trace, "(LongPolling transport) Poll timed out, reissuing."); + } + } + return [3 /*break*/, 6]; + case 5: + e_1 = _a.sent(); + if (!this.running) { + // Log but disregard errors that occur after stopping - fy: 记录但忽略停止后发生的错误 + this.logger.log(LogLevel.Trace, "(LongPolling transport) Poll errored after shutdown: " + e_1.message); + } + else { + if (e_1 instanceof TimeoutError) { + // Ignore timeouts and reissue the poll. - 忽略超时并重新发出投票 + this.logger.log(LogLevel.Trace, "(LongPolling transport) Poll timed out, reissuing. - (fy:长轮询传输 - 请求超时)"); + } + else { + // Close the connection with the error as the result. + this.closeError = e_1; + this.running = false; + } + } + return [3 /*break*/, 6]; + case 6: return [3 /*break*/, 1]; + case 7: return [3 /*break*/, 9]; + case 8: + this.logger.log(LogLevel.Trace, "(LongPolling transport) Polling complete. - (fy:长轮询传输 - 请求完成)"); + // We will reach here with pollAborted==false when the server returned a response causing the transport to stop. + // If pollAborted==true then client initiated the stop and the stop method will raise the close event after DELETE is sent. + //当服务器返回导致传输停止的响应时,我们将使用pollAborted==false到达这里。 + //如果pollAborted==true,则客户端启动了stop,stop方法将在发送DELETE后引发close事件。 + if (!this.pollAborted) { + this.raiseOnClose(); + } + return [7 /*endfinally*/]; + case 9: return [2 /*return*/]; + } + }); + }); + }; + /** + * 发送轮询包 + * + * @param {*} data + * @returns {Promise} + * @memberof LongPollingTransport + */ + LongPollingTransport.prototype.send = function (data) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + if (!this.running) { + return [2 /*return*/, Promise.reject(new Error("Cannot send until the transport is connected"))]; + } + return [2 /*return*/, sendMessage(this.logger, "LongPolling", this.request, this.url, this.accessTokenFactory, data, this.logMessageContent)]; + }); + }); + }; + /** + * 停止 + * + * @returns {Promise} + * @memberof LongPollingTransport + */ + LongPollingTransport.prototype.stop = function () { + return __awaiter(this, void 0, void 0, function () { + var deleteOptions, token, e_2; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + this.logger.log(LogLevel.Trace, "(LongPolling transport) Stopping polling."); + // Tell receiving loop to stop, abort any current request, and then wait for it to finish + this.running = false; + this.pollAbort.abort(); + _a.label = 1; + case 1: + _a.trys.push([1, 5, 6, 7]); + return [4 /*yield*/, this.receiving]; + case 2: + _a.sent(); // 这里 receiving 本身是一个 promise result, 用这个对象来监控请求未完成 + // Send DELETE to clean up long polling on the server + // 发送DELETE以清除服务器上的长轮询 + this.logger.log(LogLevel.Trace, "(LongPolling transport) sending DELETE request to " + this.url + "."); + deleteOptions = { + headers: {} + }; + return [4 /*yield*/, this.getAccessToken()]; + case 3: + token = _a.sent(); + this.updateHeaderToken(deleteOptions, token); + return [4 /*yield*/, this.request.delete(this.url, {}, deleteOptions)]; + case 4: + _a.sent(); + this.logger.log(LogLevel.Trace, "(LongPolling transport) DELETE request sent."); + return [2 /*return*/, Promise.resolve({ + errMsg: "stop success" + })]; + case 5: + e_2 = _a.sent(); + this.logger.log(LogLevel.Error, "(LongPolling transport) Stop error.", e_2); + return [2 /*return*/, Promise.reject({ + errMsg: "stop fail" + })]; + case 6: + this.logger.log(LogLevel.Trace, "(LongPolling transport) Stop finished."); + // Raise close event here instead of in polling + // It needs to happen after the DELETE request is sent + //在此处引发关闭事件,而不是在轮询中 + //它需要在发送删除请求后发生 + this.raiseOnClose(); + return [7 /*endfinally*/]; + case 7: return [2 /*return*/]; + } + }); + }); + }; + /** + * 调用关闭回调 + * + * @private + * @memberof LongPollingTransport + */ + LongPollingTransport.prototype.raiseOnClose = function () { + if (this.onclose) { + var logMessage = "(LongPolling transport) Firing onclose event."; + if (this.closeError) { + logMessage += " Error: " + this.closeError; + } + this.logger.log(LogLevel.Trace, logMessage); + this.onclose(this.closeError); + } + }; + return LongPollingTransport; +}()); +export { LongPollingTransport }; diff --git a/miniprogram_npm/signalr-for-wx/Polyfills.js b/miniprogram_npm/signalr-for-wx/Polyfills.js new file mode 100644 index 0000000..5f1c2d6 --- /dev/null +++ b/miniprogram_npm/signalr-for-wx/Polyfills.js @@ -0,0 +1,13 @@ +// 版权所有(c).NET基金会。保留所有权利。 +// 在2.0版Apache许可下授权。有关许可证信息,请参见项目根目录中的License.txt +// Not exported from index +/** + * 小程序socket连接状态[枚举] + */ +export var WxSocketReadyState; +(function (WxSocketReadyState) { + WxSocketReadyState[WxSocketReadyState["CONNECTING"] = 0] = "CONNECTING"; + WxSocketReadyState[WxSocketReadyState["OPEN"] = 1] = "OPEN"; + WxSocketReadyState[WxSocketReadyState["CLOSING"] = 2] = "CLOSING"; + WxSocketReadyState[WxSocketReadyState["CLOSED"] = 3] = "CLOSED"; +})(WxSocketReadyState || (WxSocketReadyState = {})); diff --git a/miniprogram_npm/signalr-for-wx/Stream.js b/miniprogram_npm/signalr-for-wx/Stream.js new file mode 100644 index 0000000..95328c3 --- /dev/null +++ b/miniprogram_npm/signalr-for-wx/Stream.js @@ -0,0 +1,2 @@ +// 版权所有(c).NET基金会。保留所有权利。 +// 在2.0版Apache许可下授权。有关许可证信息,请参见项目根目录中的License.txt。 diff --git a/miniprogram_npm/signalr-for-wx/TextMessageFormat.js b/miniprogram_npm/signalr-for-wx/TextMessageFormat.js new file mode 100644 index 0000000..4252522 --- /dev/null +++ b/miniprogram_npm/signalr-for-wx/TextMessageFormat.js @@ -0,0 +1,46 @@ +// 版权所有(c).NET基金会。保留所有权利。 +// 在2.0版Apache许可下授权。有关许可证信息,请参见项目根目录中的License.txt。 +// 未从索引导出 +/** + * 文本类型消息格式化 + * @private + */ +var TextMessageFormat = /** @class */ (function () { + function TextMessageFormat() { + } + /** + * 输出一个格式化过的消息 + * @param output + */ + TextMessageFormat.write = function (output) { + return "" + output + TextMessageFormat.RecordSeparator; + }; + /** + * 解析 + * @param input + */ + TextMessageFormat.parse = function (input) { + if (input[input.length - 1] !== TextMessageFormat.RecordSeparator) { + throw new Error("Message is incomplete."); + } + var messages = input.split(TextMessageFormat.RecordSeparator); + messages.pop(); + return messages; + }; + /** + * 记录分隔符 code + * + * @static + * @memberof TextMessageFormat + */ + TextMessageFormat.RecordSeparatorCode = 0x1e; + /** + * 记录分隔符(string) + * + * @static + * @memberof TextMessageFormat + */ + TextMessageFormat.RecordSeparator = String.fromCharCode(TextMessageFormat.RecordSeparatorCode); + return TextMessageFormat; +}()); +export { TextMessageFormat }; diff --git a/miniprogram_npm/signalr-for-wx/Utils.js b/miniprogram_npm/signalr-for-wx/Utils.js new file mode 100644 index 0000000..84004d4 --- /dev/null +++ b/miniprogram_npm/signalr-for-wx/Utils.js @@ -0,0 +1,324 @@ +// 版权所有(c).NET基金会。保留所有权利。 +// 在2.0版Apache许可下授权。有关许可证信息,请参见项目根目录中的License.txt。 +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __spreadArrays = (this && this.__spreadArrays) || function () { + for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; + for (var r = Array(s), k = 0, i = 0; i < il; i++) + for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) + r[k] = a[j]; + return r; +}; +import { LogLevel } from "./ILogger"; +import { NullLogger } from "./Loggers"; +import { ResponseType } from "./wx-request/model/ResponseType"; +/** + * 参数处理方法 + * @private + */ +var Arg = /** @class */ (function () { + function Arg() { + } + /** + * 是否存在 + * + * @static + * @param {*} val + * @param {string} name + * @memberof Arg + */ + Arg.isRequired = function (val, name) { + if (val === null || val === undefined) { + throw new Error("The '" + name + "' argument is required."); + } + }; + /** + * 是否包含 + * + * @static + * @param {*} val + * @param {*} values + * @param {string} name + * @memberof Arg + */ + Arg.isIn = function (val, values, name) { + // TypeScript enums have keys for **both** the name and the value of each enum member on the type itself. + if (!(val in values)) { + throw new Error("Unknown " + name + " value: " + val + "."); + } + }; + /** + * 验证url是否被微信支持 + */ + Arg.validationUrlIsSupportByWechat = function (url) { + if (!url) { + throw new Error("Url is undefined."); + } + else if (!/^(ws|wws):\/\//.test(url)) { + if (/^http/.test(url)) { + return url.replace(/^http/, "wx"); + } + throw new Error("error: instantiation [url](" + url + ") not supported by wechat miniprogram."); + } + else { + return url; + } + }; + return Arg; +}()); +export { Arg }; +/** + * 获取data details + * @param data origin data + * @param includeContent 是否导出上下文? + */ +export function getDataDetail(data, includeContent) { + var detail = ""; + if (isArrayBuffer(data)) { + detail = "Binary data of length " + data.byteLength; + if (includeContent) { + detail += ". Content: '" + formatArrayBuffer(data) + "'"; + } + } + else if (typeof data === "string") { + detail = "String data of length " + data.length; + if (includeContent) { + detail += ". Content: '" + data + "'"; + } + } + return detail; +} +/** + * 格式化 array buffer + * @private + */ +export function formatArrayBuffer(data) { + var view = new Uint8Array(data); + // Uint8Array.map only supports returning another Uint8Array? + var str = ""; + view.forEach(function (num) { + var pad = num < 16 ? "0" : ""; + str += "0x" + pad + num.toString(16) + " "; + }); + // Trim of trailing space. + return str.substr(0, str.length - 1); +} +// Also in signalr-protocol-msgpack/Utils.ts +/** + * 判断是不是 ArrayBuffer + * @private + */ +export function isArrayBuffer(val) { + return (val && + typeof ArrayBuffer !== "undefined" && + (val instanceof ArrayBuffer || + // Sometimes we get an ArrayBuffer that doesn't satisfy instanceof + (val.constructor && val.constructor.name === "ArrayBuffer"))); +} +/** + * 发送消息 + * @param logger 日志工具 + * @param transportName + * @param request - 注: 原版代码为 httpClient,这里使用 wx-request. + * @param url + * @param accessTokenFactory + * @param content + * @param logMessageContent + */ +export function sendMessage(logger, transportName, request, url, accessTokenFactory, content, logMessageContent) { + return __awaiter(this, void 0, void 0, function () { + var headers, token, responseType, response; + var _a; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + if (!accessTokenFactory) return [3 /*break*/, 2]; + return [4 /*yield*/, accessTokenFactory()]; + case 1: + token = _b.sent(); + if (token) { + headers = (_a = {}, + _a["Authorization"] = "Bearer " + token, + _a); + } + _b.label = 2; + case 2: + logger.log(LogLevel.Trace, "(" + transportName + " transport) sending data. " + getDataDetail(content, logMessageContent) + "."); + responseType = isArrayBuffer(content) ? ResponseType.ARRAY_BUFFER : ResponseType.TEXT; + return [4 /*yield*/, request.post(url, content, { + headers: headers, + responseType: responseType + })]; + case 3: + response = _b.sent(); + logger.log(LogLevel.Trace, "(" + transportName + " transport) request complete. Response status: " + response.statusCode + "."); + return [2 /*return*/]; + } + }); + }); +} +/** + * 创建一个 logger + * @private + */ +export function createLogger(logger) { + if (logger === undefined) { + return new ConsoleLogger(LogLevel.Information); + } + if (logger === null) { + return NullLogger.instance; + } + if (logger.log) { + return logger; + } + return new ConsoleLogger(logger); +} +/** + * 订阅接口实现 + * @private + */ +var Subject = /** @class */ (function () { + function Subject(cancelCallback) { + this.observers = []; + this.cancelCallback = cancelCallback; + } + Subject.prototype.next = function (item) { + for (var _i = 0, _a = this.observers; _i < _a.length; _i++) { + var observer = _a[_i]; + observer.next(item); + } + }; + Subject.prototype.error = function (err) { + for (var _i = 0, _a = this.observers; _i < _a.length; _i++) { + var observer = _a[_i]; + if (observer.error) { + observer.error(err); + } + } + }; + Subject.prototype.complete = function () { + for (var _i = 0, _a = this.observers; _i < _a.length; _i++) { + var observer = _a[_i]; + if (observer.complete) { + observer.complete(); + } + } + }; + Subject.prototype.subscribe = function (observer) { + this.observers.push(observer); + return new SubjectSubscription(this, observer); + }; + return Subject; +}()); +export { Subject }; +/** + * 主题订阅?? + * 应该时定制 断开流 的 实现吧. + * @private + */ +var SubjectSubscription = /** @class */ (function () { + function SubjectSubscription(subject, observer) { + this.subject = subject; + this.observer = observer; + } + SubjectSubscription.prototype.dispose = function () { + var index = this.subject.observers.indexOf(this.observer); + if (index > -1) { + this.subject.observers.splice(index, 1); + } + if (this.subject.observers.length === 0) { + this.subject.cancelCallback().catch(function (_) { }); + } + }; + return SubjectSubscription; +}()); +export { SubjectSubscription }; +/** + * console logger 内置实现 + * @private + */ +var ConsoleLogger = /** @class */ (function () { + /** + * 构造方法 定义 最小输出日志等级 + * @param {LogLevel} minimumLogLevel + * @memberof ConsoleLogger + */ + function ConsoleLogger(minimumLogLevel) { + this.minimumLogLevel = minimumLogLevel; + } + /** + * 日志输出 + * + * @param {LogLevel} logLevel + * @param {string} message + * @memberof ConsoleLogger + */ + ConsoleLogger.prototype.log = function () { + var msg = []; + for (var _i = 0; _i < arguments.length; _i++) { + msg[_i] = arguments[_i]; + } + var logLevel = LogLevel.Information; + for (var _a = 0, _b = arguments; _a < _b.length; _a++) { + var ll = _b[_a]; + if (Object.values(LogLevel).indexOf(ll) != -1) { + logLevel = ll; + break; + } + } + if (logLevel >= this.minimumLogLevel) { + switch (logLevel) { + case LogLevel.Critical: + case LogLevel.Error: + console.error.apply(console, __spreadArrays(["[" + new Date().toISOString() + "] " + LogLevel[logLevel] + " =>"], msg.slice(1, msg.length))); + break; + case LogLevel.Warning: + console.warn.apply(console, __spreadArrays(["[" + new Date().toISOString() + "] " + LogLevel[logLevel] + " =>"], msg)); + break; + case LogLevel.Information: + console.info.apply(console, __spreadArrays(["[" + new Date().toISOString() + "] " + LogLevel[logLevel] + " =>"], msg)); + break; + default: + // console.debug only goes to attached debuggers in Node, so we use console.log for Trace and Debug + console.log.apply(console, __spreadArrays(["[" + new Date().toISOString() + "] " + LogLevel[logLevel] + " =>"], msg)); + break; + } + } + }; + return ConsoleLogger; +}()); +export { ConsoleLogger }; diff --git a/miniprogram_npm/signalr-for-wx/WechatVersionDiff.js b/miniprogram_npm/signalr-for-wx/WechatVersionDiff.js new file mode 100644 index 0000000..5cec6f8 --- /dev/null +++ b/miniprogram_npm/signalr-for-wx/WechatVersionDiff.js @@ -0,0 +1,33 @@ +/** + * 小程序版本支持 + * @param minimumVersion 最小支持版本号 + */ +export var isVersionSupport = function (minimumVersion) { + // diff + var compareVersion = function (v1, v2) { + v1 = v1.split("."); + v2 = v2.split("."); + var len = Math.max(v1.length, v2.length); + while (v1.length < len) { + v1.push("0"); + } + while (v2.length < len) { + v2.push("0"); + } + for (var i = 0; i < len; i++) { + var num1 = parseInt(v1[i]); + var num2 = parseInt(v2[i]); + if (num1 > num2) { + return 1; + } + else if (num1 < num2) { + return -1; + } + } + return 0; + }; + // 获取当前小程序 版本号 + var SDKVersion = wx.getSystemInfoSync().SDKVersion; + // check + return compareVersion(SDKVersion, minimumVersion) >= 0; +}; diff --git a/miniprogram_npm/signalr-for-wx/WxSocketTransport.js b/miniprogram_npm/signalr-for-wx/WxSocketTransport.js new file mode 100644 index 0000000..908c636 --- /dev/null +++ b/miniprogram_npm/signalr-for-wx/WxSocketTransport.js @@ -0,0 +1,300 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +import { LogLevel } from "./ILogger"; +import { Arg, getDataDetail } from "./Utils"; +import { WxSocketReadyState } from "./Polyfills"; +import { isVersionSupport } from "./WechatVersionDiff"; +/** + * 微信 sosocket 数据传输 + * @description 整体重写了这部分websocket支持,逻辑这样看起来合理一些 + */ +var WxSocketTransport = /** @class */ (function () { + function WxSocketTransport(options) { + this.readyState = WxSocketReadyState.CONNECTING; + this.logger = options.logger; + this.accessTokenFactory = options.accessTokenFactory; + this.socketUrlFactory = options.socketUrlFactory; + this.logMessageContent = options.logMessageContent; + this.onreceive = null; + this.onclose = null; + this.allowReplaceSocket = options.allowReplaceSocket; + this.timeout = options.timeout ? options.timeout : 60 * 1000; + this.delayTime = options.delayTime ? options.delayTime : 100; + if (options.enableMessageQueue) { + this.enableMessageQueue = true; + this.messageQueue = []; + } + else { + this.enableMessageQueue = false; + } + if (options.reconnect) { + this.reconnect = { + enable: options.reconnect.enable == true ? true : false, + max: options.reconnect.max ? options.reconnect.max : 3, + val: 0 + }; + } + else { + this.reconnect = { + enable: false, + max: 3, + val: 0 + }; + } + } + WxSocketTransport.prototype.connect = function (options) { + return __awaiter(this, void 0, void 0, function () { + var replacedUrl, token; + var _this = this; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + // vali is exists + Arg.isRequired(options, "options"); + // vali url is support by wechat + Arg.validationUrlIsSupportByWechat(options.url); + this.connectOptions = options; // 连接参数缓存 + this.logger.log(LogLevel.Trace, "(WebSockets transport) Connecting."); + if (!this.socketUrlFactory) return [3 /*break*/, 2]; + return [4 /*yield*/, this.socketUrlFactory(options.url)]; + case 1: + replacedUrl = _a.sent(); + if (replacedUrl) { + options.url = replacedUrl; + } + return [3 /*break*/, 4]; + case 2: + if (!this.accessTokenFactory) return [3 /*break*/, 4]; + return [4 /*yield*/, this.accessTokenFactory()]; + case 3: + token = _a.sent(); + this.logger.log(LogLevel.Debug, "getted token:", token); + if (token) { + options.url += (options.url.indexOf("?") < 0 ? "?" : "&") + ("access_token=" + encodeURIComponent(token)); + } + _a.label = 4; + case 4: return [2 /*return*/, new Promise(function (resolve, reject) { + // 忽略url修正,因为传入错误url的话,将直接抛出异常 + options.url = options.url.replace(/^http/, "ws"); + // 这里执行的是连接操socket的逻辑 + var socketTask; + // 1.7.0 及以上版本,最多可以同时存在 5 个 WebSocket 连接, 以下版本,一个小程序同时只能有一个 WebSocket 连接,如果当前已存在一个 WebSocket 连接,会自动关闭该连接,并重新创建一个 WebSocket 连接 + var supportCount = isVersionSupport("1.7.0") ? 5 : 1; + if (supportCount <= WxSocketTransport.count && !_this.allowReplaceSocket) { + // 抛出异常, 并return + reject({ + errMsg: "Maximum connections|" + WxSocketTransport.count + }); + return; + } + else if (WxSocketTransport.count == 5) { + // 抛出异常, 并return + reject({ + errMsg: "Maximum connections|" + WxSocketTransport.count + }); + return; + } + if (!socketTask) { + socketTask = wx.connectSocket(__assign({ + // 传入 两个默认的 回调,当然也可以在 options 里面覆盖 使用自定义回调. + success: function (res) { + _this.logger.log(LogLevel.Debug, "wx.connectSocket():success"); + }, fail: function (res) { + _this.logger.log(LogLevel.Debug, "wx.connectSocket():fail"); + reject(res); + } }, options)); + } + // ! 因为小程序两种协议都支持,所以不需要指定特定的 binaryType + /** 连接成功处理 */ + socketTask.onOpen(function (result) { return __awaiter(_this, void 0, void 0, function () { + var _i, _a, msg; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + this.logger.log(LogLevel.Information, "websocket\u8FDE\u63A5\u5EFA\u7ACB " + (this.logMessageContent ? "wx api:[" + options.url + "]" : "")); + this.logger.log(LogLevel.Debug, "wx.connectSocket success message:", result); + WxSocketTransport.count += 1; + this.readyState = WxSocketReadyState.OPEN; + this.socketTask = socketTask; + // 等待回调执行完成后,再重新队列中消息 + return [4 /*yield*/, resolve()]; + case 1: + // 等待回调执行完成后,再重新队列中消息 + _b.sent(); + if (!(this.enableMessageQueue && this.messageQueue.length > 0)) return [3 /*break*/, 5]; + _i = 0, _a = this.messageQueue; + _b.label = 2; + case 2: + if (!(_i < _a.length)) return [3 /*break*/, 5]; + msg = _a[_i]; + this.logger.log(LogLevel.Debug, "\u63A8\u9001\u79BB\u7EBF\u6D88\u606F", this.logMessageContent ? msg : ""); + return [4 /*yield*/, this.send(msg)]; + case 3: + _b.sent(); + _b.label = 4; + case 4: + _i++; + return [3 /*break*/, 2]; + case 5: return [2 /*return*/]; + } + }); + }); }); + /** 建立连接出错处理 */ + socketTask.onError(function (res) { + _this.readyState = WxSocketReadyState.CLOSED; + reject(res); + }); + /** 接收到消息处理 */ + socketTask.onMessage(function (res) { + _this.logger.log(LogLevel.Trace, "(WebSockets transport) data received.", getDataDetail(res.data, _this.logMessageContent)); + if (_this.onreceive) { + _this.onreceive(res.data); + } + }); + socketTask.onClose(function (res) { return _this.close(res); }); + })]; + } + }); + }); + }; + /** 休眠 */ + WxSocketTransport.prototype.delay = function () { + var _this = this; + return new Promise(function (resolve) { + // ! 由于小程序机制,所以需要手工清理timer + var timer = setTimeout(function () { + clearTimeout(timer); + resolve(); + }, _this.delayTime); + }); + }; + /** 发送 */ + WxSocketTransport.prototype.send = function (data) { + return __awaiter(this, void 0, void 0, function () { + var loop; + var _this = this; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!(this.socketTask && this.readyState === WxSocketReadyState.OPEN)) return [3 /*break*/, 1]; + this.logger.log(LogLevel.Trace, "[WxSocket] \u63A8\u9001\u6570\u636E.", getDataDetail(data, this.logMessageContent)); + return [2 /*return*/, new Promise(function (resolve, reject) { + _this.socketTask.send({ + data: data, + success: function () { return resolve(); }, + fail: function () { return reject(); } + }); + })]; + case 1: + if (!this.enableMessageQueue) return [3 /*break*/, 5]; + this.messageQueue.push(data); + loop = 0; + _a.label = 2; + case 2: + if (!(this.socketTask && this.readyState !== WxSocketReadyState.OPEN)) return [3 /*break*/, 4]; + return [4 /*yield*/, this.delay()]; + case 3: + _a.sent(); + loop += this.delayTime; + if (loop >= this.timeout) { + // 超时设置 + return [2 /*return*/, Promise.reject({ + errMsg: "WebSocket connect timeout." + })]; + } + return [3 /*break*/, 2]; + case 4: + // 回调 + return [2 /*return*/, this.send(data)]; + case 5: return [2 /*return*/, Promise.reject({ + errMsg: "WebSocket is not in the OPEN state" + })]; + } + }); + }); + }; + /** 停止 */ + WxSocketTransport.prototype.stop = function (msg) { + var _this = this; + return new Promise(function (resolve, reject) { + if (_this.socketTask) { + _this.socketTask.close({ + code: 1000, + reason: "stop socket", + success: function (res) { return resolve(msg || res); }, + fail: function (res) { return reject(res); } + }); + } + }); + }; + /** + * 连接断开处理 + * @param res + */ + WxSocketTransport.prototype.close = function (res) { + // webSocket will be null if the transport did not start successfully + this.logger.log(LogLevel.Trace, "(WebSockets transport) socket closed."); + WxSocketTransport.count = WxSocketTransport.count > 0 ? WxSocketTransport.count - 1 : 0; + if (this.onclose) { + if (res && res.code !== 1000) { + this.onclose(new Error("WebSocket closed with status code: " + res.code + " (" + res.reason + ").")); + } + else { + this.onclose(); + } + } + }; + /** + * 静态变量 - 表示当前是否有正在连接中的socket + */ + WxSocketTransport.count = 0; + return WxSocketTransport; +}()); +export { WxSocketTransport }; diff --git a/miniprogram_npm/signalr-for-wx/index.js b/miniprogram_npm/signalr-for-wx/index.js new file mode 100644 index 0000000..39f0d5e --- /dev/null +++ b/miniprogram_npm/signalr-for-wx/index.js @@ -0,0 +1,24 @@ +// 版权所有(c).NET基金会。保留所有权利。 +// 在2.0版Apache许可下授权。有关许可证信息,请参见项目根目录中的License.txt。 +// 版本号模板 - builder 自动更新,无需手动 +/** The version of the SignalR client. */ +export var VERSION = "1.1.6"; +// 协议|类型参数 导出 +export { MessageType } from "./IHubProtocol"; +// json格式传输协议 +export { JsonHubProtocol } from "./JsonHubProtocol"; +export { HubConnectionBuilder } from "./HubConnectionBuilder"; +export { HubConnection, HubConnectionState } from "./HubConnection"; +// 微信最低版本支持检查 +export { isVersionSupport } from "./WechatVersionDiff"; +// 微信socket传输实现 +export { WxSocketTransport } from "./WxSocketTransport"; +// 微信 request 请求实现(封装 wx.request) +export { Request } from "./wx-request/index"; +export { RequestMethod, ResponseType } from "./wx-request/model"; +// Error 接口 +export { AbortError, HttpError, TimeoutError } from "./Errors"; +// logger 接口 +export { LogLevel } from "./ILogger"; +// Transport 接口 +export { HttpTransportType, TransferFormat } from "./ITransport"; diff --git a/miniprogram_npm/signalr-for-wx/wx-request/index.js b/miniprogram_npm/signalr-for-wx/wx-request/index.js new file mode 100644 index 0000000..a7cda3a --- /dev/null +++ b/miniprogram_npm/signalr-for-wx/wx-request/index.js @@ -0,0 +1,477 @@ +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +import { RequestMethod } from "./model/RequestMethod"; +import { ResponseType } from "./model/ResponseType"; +import { LogLevel } from "../ILogger"; +import { TimeoutError, HttpError } from "../Errors"; +import { NullLogger } from "../Loggers"; +/** + * 封装微信ajax请求工具 + * @author halo + */ +var Request = /** @class */ (function () { + /** + * Creates an instance of Request. + * 实例化配置 + * @param {*} [config] + * @memberof Request + */ + function Request(config, logger) { + if (config === void 0) { config = {}; } + // 写入配置 + if (wx) { + // Time: 继承 signalR logger. 日志统一维护 + this.logger = logger ? logger : new NullLogger(); + } + else { + throw new Error("当前运行环境不是微信运行环境"); + } + // custom wx request promise library. + this.setConfig(config); + } + /** + * merge config + * @param config + */ + Request.prototype.setConfig = function (config) { + if (config === void 0) { config = {}; } + // 合并默认配置和 + this.config = __assign({ baseUrl: "http://", headers: { "Content-Type": "application/json" }, forceEnableHttps: false, method: RequestMethod.GET, responseType: ResponseType.JSON, responseEncoding: "utf8", timeout: 60 * 1000, transformRequest: [], transformResponse: [] }, config); + // 请求头默认附加response 解析器 + if (!this.config.transformResponse) { + this.config.transformResponse = []; + } + this.logger.log(LogLevel.Information, "set config success."); + }; + /** + * 请求参数序列化 + * + * @param {RequestOptions} options + * @memberof Request + * + * @description 只支持普通get请求,和content-type = json 的 其他请求(post,put,delete,patch) + */ + Request.prototype.handleRequestOptions = function (options) { + return __awaiter(this, void 0, void 0, function () { + var _i, _a, fun, e_1; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + // 请求地址处理,对于非:// 请求,附加baseUrl + if (options.url && !/:\/\/.+?/.test(options.url)) { + options.url = ((options.config ? options.config.baseUrl : "") + "/" + options.url).replace(/([^:])(\/\/)/g, "$1/"); + } + this.logger.log(LogLevel.Trace, "checked request url"); + // https 处理 + if (options.config && options.config.forceEnableHttps) { + options.url = options.url.replace(/http:/, "https:"); + this.logger.log(LogLevel.Trace, "execute fix [request.config.forceEnableHttps] " + options.url); + } + // header 合并 + options.headers = Object.assign({}, options.config ? options.config.headers : {}, options.headers); + this.logger.log(LogLevel.Trace, "merge headers ", options.headers); + // 移除微信封锁参数 + delete options.headers["Referer"]; + this.logger.log(LogLevel.Trace, "try delete headers Referer."); + // 替换请求内的ResponseType + options.responseType = options.responseType + ? options.responseType + : options.config + ? options.config.responseType + : ResponseType.TEXT; + this.logger.log(LogLevel.Trace, "checked responseType [" + options.responseType + "]"); + if (!(options.config && options.config.transformRequest)) return [3 /*break*/, 6]; + this.logger.log(LogLevel.Trace, "execute transform request list. -result\n", options.config); + _i = 0, _a = options.config.transformRequest; + _b.label = 1; + case 1: + if (!(_i < _a.length)) return [3 /*break*/, 6]; + fun = _a[_i]; + _b.label = 2; + case 2: + _b.trys.push([2, 4, , 5]); + return [4 /*yield*/, fun(options)]; + case 3: + _b.sent(); + return [3 /*break*/, 5]; + case 4: + e_1 = _b.sent(); + throw e_1; + case 5: + _i++; + return [3 /*break*/, 1]; + case 6: + // debug print handled request options + this.logger.log(LogLevel.Debug, "handled request options \n", options); + return [2 /*return*/]; + } + }); + }); + }; + /** + * 验证响应结果,执行回调 + * + * @param {*} resolve + * @param {*} reject + * @param {*} response + * @memberof Request + */ + Request.prototype.handleResponse = function (response) { + return __awaiter(this, void 0, void 0, function () { + var _i, _a, fun, res_1; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + if (!(response.options.config && + response.options.config.responseType == "json" && + response.options.config.transformResponse)) return [3 /*break*/, 6]; + _i = 0, _a = response.options.config.transformResponse; + _b.label = 1; + case 1: + if (!(_i < _a.length)) return [3 /*break*/, 6]; + fun = _a[_i]; + _b.label = 2; + case 2: + _b.trys.push([2, 4, , 5]); + // handler response + return [4 /*yield*/, fun(response)]; + case 3: + // handler response + _b.sent(); + return [3 /*break*/, 5]; + case 4: + res_1 = _b.sent(); + this.logger.log(LogLevel.Trace, "execute transform request list. -result \n ", res_1); + throw res_1; + case 5: + _i++; + return [3 /*break*/, 1]; + case 6: + // debug print handled response context + this.logger.log(LogLevel.Debug, "handled response context \n", response); + return [2 /*return*/, Promise.resolve(response)]; + } + }); + }); + }; + /** + * 执行请求 + * + * @param {RequestOptions} [options={ + * url: this.config.baseUrl + * }] + * @returns {Promise} + * @memberof Request + */ + Request.prototype.executeRequest = function (options) { + var _this = this; + return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () { + var error_1, task; + var _this = this; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + this.logger.log(LogLevel.Trace, "execute request -options \n", options); + // 合并 baseConfig + options.config = options.config ? __assign(__assign({}, this.config), options.config) : __assign({}, this.config); + if (this.checkAbout(options.config, reject)) + return [2 /*return*/]; + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + // 序列化请求参数 + return [4 /*yield*/, this.handleRequestOptions(options)]; + case 2: + // 序列化请求参数 + _a.sent(); + return [3 /*break*/, 4]; + case 3: + error_1 = _a.sent(); + // 抛出异常. + return [2 /*return*/, reject(__assign({ data: null, header: null, statusCode: -1, options: options }, error_1))]; + case 4: + if (this.checkAbout(options.config, reject)) + return [2 /*return*/]; + // print fixed options + this.logger.log(LogLevel.Debug, "fixed options \n", options); + // execute request + this.logger.log(LogLevel.Trace, "invoke wx.request"); + task = wx.request({ + url: options.url, + data: options.data, + dataType: options.responseType, + header: options.headers, + method: options.method, + responseType: (function () { + switch (options.responseType) { + case "json": + case "text": + return "text"; + case "arraybuffer": + return "arraybuffer"; + } + })(), + success: function (res) { return __awaiter(_this, void 0, void 0, function () { + var data, header, statusCode, errMsg, responseOptions; + var _this = this; + return __generator(this, function (_a) { + if (this.checkAbout(options.config, reject)) + return [2 /*return*/]; + this.logger.log(LogLevel.Debug, "origin response context \n", res); + data = res.data, header = res.header, statusCode = res.statusCode, errMsg = res.errMsg; + responseOptions = { + data: data, + header: header, + statusCode: statusCode, + options: options, + errMsg: errMsg + }; + // 调用响应处理链(并返回结果) + this.handleResponse(responseOptions) + .then(function (res) { + // print debug + _this.logger.log(LogLevel.Debug, "handle response context is success. \n", res); + /** + * check and cache cookie (if has) | + * @description 这里因为 signalR的原因,内置了一个 cookies.js [library](https://github.com/jshttp/cookie/index.js) + * 略有改写,暂时将cookie 扔到内存中维护(毕竟就signalr使用,不考虑扔到 localStore 中占地方). + */ + if (options.config.cookie) + options.config.cookie.set(options.url, header); + // callback + resolve(res); + }) + .catch(function (res) { + // print log + _this.logger.log(LogLevel.Error, "handle response context is fail. \n ", res); + // ! 这里为了兼容 signalR的错误格式,抛出继承了HttpError异常. + var httpError = new HttpError(res.errMsg, res.statusCode); + // callback - 合并后,返回,可以被认定为 继承 HttpError对象. + reject(__assign(__assign({}, res), httpError)); + }); + return [2 /*return*/]; + }); + }); }, + fail: function (res) { + var responseOptions = null; + if (res && /request:fail socket time out timeout/.test(res.errMsg)) { + // ! 这里为了兼容 signalR的错误格式,抛出继承了TimeoutError异常. + responseOptions = __assign({ data: null, status: -1, errMsg: res.errMsg }, new TimeoutError(res.errMsg)); + } + else { + // ! 这里为了兼容 signalR的错误格式,抛出继承了HttpError异常. + responseOptions = __assign({ data: null, status: -1, errMsg: res.errMsg }, new HttpError(res.errMsg, 500)); + } + /** + * @date 2019年12月11日 13:14:25 + * ! 修复bug,wx.request fail 情况下, 未调用 response 处理链. + */ + // 调用响应处理链(并返回结果) + _this.handleResponse(responseOptions) + .then(function (res) { + // print debug + _this.logger.log(LogLevel.Debug, "handle response context is success. \n", res); + /** + * check and cache cookie (if has) | + * @description 这里因为 signalR的原因,内置了一个 cookies.js [library](https://github.com/jshttp/cookie/index.js) + * 略有改写,暂时将cookie 扔到内存中维护(毕竟就signalr使用,不考虑扔到 localStore 中占地方). + */ + if (options.config.cookie) + options.config.cookie.set(options.url, {}); + // callback + resolve(res); + }) + .catch(function (res) { + // print log + _this.logger.log(LogLevel.Error, "handle response context is fail. \n ", res); + // ! 这里为了兼容 signalR的错误格式,抛出继承了HttpError异常. + var httpError = new HttpError(res.errMsg, res.statusCode); + // callback - 合并后,返回,可以被认定为 继承 HttpError对象. + reject(__assign(__assign({}, res), httpError)); + }); + } + }); + // 监听 headers 变化 + task.onHeadersReceived(function () { + // 当检查到 about() 状态,中断请求 + if (_this.checkAbout(options.config, reject)) { + // 中断请求 + task.abort(); + return; + } + }); + return [2 /*return*/]; + } + }); + }); }); + }; + /** + * 检查中断 + * + * @memberof Request + */ + Request.prototype.checkAbout = function (options, reject) { + if (options.config && options.config.about) { + reject({ + data: null, + header: options.headers, + statusCode: 412, + options: options, + errMsg: "网络异常" // 直接自定义错误了. + }); + return true; + } + else { + return false; + } + }; + /** + * GET 请求 + * @description 封装调用 + * @param url 请求地址 + * @param data 请求参数 + * @param options 请求配置 + */ + Request.prototype.get = function (url, data, options) { + if (data === void 0) { data = {}; } + // print execute step + this.logger.log(LogLevel.Trace, "invoke request.get()"); + // merge config + var requestOptions = __assign(__assign({}, (function () { return (options ? options : {}); })()), { method: RequestMethod.GET, url: url, + data: data }); + // execute and response + return this.executeRequest(requestOptions); + }; + /** + * POST 请求 + * @description 封装调用 + * @param url 请求地址 + * @param data 请求参数 + * @param options 请求配置 + */ + Request.prototype.post = function (url, data, options) { + if (data === void 0) { data = {}; } + // print execute step + this.logger.log(LogLevel.Trace, "invoke request.post()"); + // merge config + var requestOptions = __assign(__assign({}, (function () { return (options ? options : {}); })()), { method: RequestMethod.POST, url: url, + data: data }); + // execute and response + return this.executeRequest(requestOptions); + }; + /** + * PUT 请求 + * @description 封装调用 + * @param url 请求地址 + * @param data 请求参数 + * @param options 请求配置 + */ + Request.prototype.put = function (url, data, options) { + if (data === void 0) { data = {}; } + // print execute step + this.logger.log(LogLevel.Trace, "invoke request.put()"); + // merge config + var requestOptions = __assign(__assign({}, (function () { return (options ? options : {}); })()), { method: RequestMethod.PUT, url: url, + data: data }); + // execute and response + return this.executeRequest(requestOptions); + }; + /** + * DELETE 请求 + * @description 封装调用 + * @param url 请求地址 + * @param data 请求参数 + * @param options 请求配置 + */ + Request.prototype.delete = function (url, data, options) { + if (data === void 0) { data = {}; } + // print execute step + this.logger.log(LogLevel.Trace, "invoke request.delete()"); + // merge config + var requestOptions = __assign(__assign({}, (function () { return (options ? options : {}); })()), { method: RequestMethod.DELETE, url: url, + data: data }); + // execute and response + return this.executeRequest(requestOptions); + }; + /** + * 多请求同步执行 + * @param taskQueue + */ + Request.prototype.all = function (taskQueue) { + // print execute step + this.logger.log(LogLevel.Trace, "invoke request.all()"); + // merge config + return Promise.all(taskQueue); + }; + /** + * 用于兼容 @aspnet/signalR 的 获取 cookie 方法 + * + * @description 这里用内存对象来维护一个 在线 cookies + * @param {string} url + * @returns + * @memberof Request + */ + Request.prototype.getCookieString = function (url) { + if (this.config && this.config.cookie) { + return this.config.cookie.origin(url); + } + else { + return ""; + } + }; + Request.prototype.cookie = function (url, key) { + if (this.config && this.config.cookie) { + return this.config.cookie.get(url, key); + } + else { + return ""; + } + }; + return Request; +}()); +export { Request }; diff --git a/miniprogram_npm/signalr-for-wx/wx-request/model.js b/miniprogram_npm/signalr-for-wx/wx-request/model.js new file mode 100644 index 0000000..88ca256 --- /dev/null +++ b/miniprogram_npm/signalr-for-wx/wx-request/model.js @@ -0,0 +1,2 @@ +export { RequestMethod } from "./model/RequestMethod"; +export { ResponseType } from "./model/ResponseType"; diff --git a/demos/radio/group/group.wxss b/miniprogram_npm/signalr-for-wx/wx-request/model/RequestConfig.js similarity index 100% rename from demos/radio/group/group.wxss rename to miniprogram_npm/signalr-for-wx/wx-request/model/RequestConfig.js diff --git a/miniprogram_npm/signalr-for-wx/wx-request/model/RequestMethod.js b/miniprogram_npm/signalr-for-wx/wx-request/model/RequestMethod.js new file mode 100644 index 0000000..9f89dfe --- /dev/null +++ b/miniprogram_npm/signalr-for-wx/wx-request/model/RequestMethod.js @@ -0,0 +1,10 @@ +/** + * 请求类型 + */ +export var RequestMethod; +(function (RequestMethod) { + RequestMethod["GET"] = "GET"; + RequestMethod["POST"] = "POST"; + RequestMethod["PUT"] = "PUT"; + RequestMethod["DELETE"] = "DELETE"; +})(RequestMethod || (RequestMethod = {})); diff --git a/pages/action-sheet/align/index.wxss b/miniprogram_npm/signalr-for-wx/wx-request/model/RequestOption.js similarity index 100% rename from pages/action-sheet/align/index.wxss rename to miniprogram_npm/signalr-for-wx/wx-request/model/RequestOption.js diff --git a/pages/action-sheet/grid/index.wxss b/miniprogram_npm/signalr-for-wx/wx-request/model/ResponseOptions.js similarity index 100% rename from pages/action-sheet/grid/index.wxss rename to miniprogram_npm/signalr-for-wx/wx-request/model/ResponseOptions.js diff --git a/miniprogram_npm/signalr-for-wx/wx-request/model/ResponseType.js b/miniprogram_npm/signalr-for-wx/wx-request/model/ResponseType.js new file mode 100644 index 0000000..4d0b601 --- /dev/null +++ b/miniprogram_npm/signalr-for-wx/wx-request/model/ResponseType.js @@ -0,0 +1,20 @@ +/** + * 响应数据类型 + * + * @interface ResponseType + */ +export var ResponseType; +(function (ResponseType) { + /** + * JSON 类型 + */ + ResponseType["JSON"] = "json"; + /** + * 文本类型(跳过返回数据处理链,直接返回) + */ + ResponseType["TEXT"] = "text"; + /** + * 二进制数据 + */ + ResponseType["ARRAY_BUFFER"] = "arraybuffer"; +})(ResponseType || (ResponseType = {})); diff --git a/miniprogram_npm/tdesign-miniprogram/.wechatide.ib.json b/miniprogram_npm/tdesign-miniprogram/.wechatide.ib.json new file mode 100644 index 0000000..461d4e1 --- /dev/null +++ b/miniprogram_npm/tdesign-miniprogram/.wechatide.ib.json @@ -0,0 +1,3895 @@ +{ + "key": "TDesign", + "label": "Tdesign", + "components": { + "t-action-sheet": { + "key": "t-action-sheet", + "label": "动作面板", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-actionsheet.png", + "properties": [ + { + "key": "cancelText", + "type": ["String"], + "desc": "设置取消按钮的文本", + "label": "" + }, + { + "key": "count", + "type": ["Number"], + "desc": "设置每页展示菜单的数量,仅当 type=grid 时有效", + "label": "" + }, + { + "key": "items", + "type": ["Array"], + "desc": "菜单项", + "label": "" + }, + { + "key": "showCancel", + "type": ["Boolean"], + "desc": "是否显示取消按钮", + "label": "" + }, + { + "key": "theme", + "type": ["String"], + "desc": "展示类型,列表和表格形式展示", + "label": "" + }, + { + "key": "visible", + "type": ["Boolean"], + "desc": "显示与隐藏", + "label": "" + } + ], + "events": [ + { + "key": "bind:cancel", + "desc": "点击取消按钮时触发", + "label": "" + }, + { + "key": "bind:close", + "desc": "关闭时触发", + "label": "" + }, + { + "key": "bind:selected", + "desc": "选择菜单项时触发", + "label": "" + } + ], + "tpl": "", + "path": "./action-sheet/action-sheet" + }, + "t-avatar-group": { + "key": "t-avatar-group", + "label": "头像组", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-avatar.png", + "properties": [ + { + "key": "cascading", + "type": ["String"], + "desc": "图片之间的层叠关系,可选值:左侧图片在上和右侧图片在上", + "label": "" + }, + { + "key": "collapseAvatar", + "type": ["String"], + "desc": "头像数量超出时,会出现一个头像折叠元素。该元素内容可自定义。默认为 `+N`。示例:`+5`,`...`, `更多`", + "label": "" + }, + { + "key": "max", + "type": ["Number"], + "desc": "能够同时显示的最多头像数量", + "label": "" + }, + { + "key": "size", + "type": ["String"], + "desc": "尺寸,示例值:small/medium/large/24px/38px 等。优先级低于 Avatar.size", + "label": "" + } + ], + "externalClasses": ["t-class", "t-class-image", "t-class-content"], + "tpl": "", + "require": { + "t-avatar": "./avatar/avatar" + }, + "path": "./avatar/avatar-group" + }, + "t-avatar": { + "key": "t-avatar", + "label": "头像", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-avatar.png", + "properties": [ + { + "key": "alt", + "type": ["String"], + "desc": "头像替换文本,仅当图片加载失败时有效", + "label": "" + }, + { + "key": "badgeProps", + "type": ["Object"], + "desc": "头像右上角提示信息,继承 Badge 组件的全部特性。如:小红点,或者数字", + "label": "" + }, + { + "key": "hideOnLoadFailed", + "type": ["Boolean"], + "desc": "加载失败时隐藏图片", + "label": "" + }, + { + "key": "icon", + "type": ["String"], + "desc": "图标", + "label": "" + }, + { + "key": "image", + "type": ["String"], + "desc": "图片地址", + "label": "" + }, + { + "key": "shape", + "type": ["String"], + "desc": "形状", + "label": "" + }, + { + "key": "size", + "type": ["String"], + "desc": "尺寸,示例值:small/medium/large/24px/38px 等,默认为 large", + "label": "" + } + ], + "externalClasses": ["t-class"], + "events": [ + { + "key": "bind:error", + "desc": "图片加载失败时触发", + "label": "" + } + ], + "tpl": "", + "path": "./avatar/avatar" + }, + "t-back-top": { + "key": "t-back-top", + "label": "回到顶部", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-backtop.png", + "properties": [ + { + "key": "fixed", + "type": ["Boolean"], + "desc": "是否绝对定位固定到屏幕右下方", + "label": "" + }, + { + "key": "icon", + "type": ["String"], + "desc": "图标", + "label": "" + }, + { + "key": "text", + "type": ["String"], + "desc": "文案", + "label": "" + }, + { + "key": "theme", + "type": ["String"], + "desc": "预设的样式类型", + "label": "" + } + ], + "externalClasses": ["t-class", "t-class-icon", "t-class-text"], + "events": [ + { + "key": "bind:to-top", + "desc": "点击触发", + "label": "" + } + ], + "tpl": "", + "path": "./back-top/back-top" + }, + "t-badge": { + "key": "t-badge", + "label": "徽标数", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-badge.png", + "properties": [ + { + "key": "color", + "type": ["String"], + "desc": "颜色", + "label": "" + }, + { + "key": "content", + "type": ["String"], + "desc": "徽标内容,示例:`content='自定义内容'`。也可以使用默认插槽定义", + "label": "" + }, + { + "key": "count", + "type": ["String", "Number"], + "desc": "徽标右上角内容。可以是数字,也可以是文字。如:'new'/3/99+。特殊:值为空表示使用插槽渲染", + "label": "" + }, + { + "key": "dot", + "type": ["Boolean"], + "desc": "是否为红点", + "label": "" + }, + { + "key": "maxCount", + "type": ["Number"], + "desc": "封顶的数字值", + "label": "" + }, + { + "key": "offset", + "type": ["Array"], + "desc": "设置状态点的位置偏移,示例:[-10, 20] 或 ['10em', '8rem']", + "label": "" + }, + { + "key": "shape", + "type": ["String"], + "desc": "形状", + "label": "" + }, + { + "key": "showZero", + "type": ["Boolean"], + "desc": "当数值为 0 时,是否展示徽标", + "label": "" + }, + { + "key": "size", + "type": ["String"], + "desc": "尺寸", + "label": "" + } + ], + "externalClasses": ["t-class", "t-class-content", "t-class-count"], + "tpl": "", + "path": "./badge/badge" + }, + "t-button": { + "key": "t-button", + "label": "按钮", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-button.png", + "properties": [ + { + "key": "block", + "type": ["Boolean"], + "desc": "是否为块级元素", + "label": "" + }, + { + "key": "content", + "type": ["String"], + "desc": "按钮内容", + "label": "" + }, + { + "key": "customDataset", + "type": ["Object"], + "desc": "自定义 dataset,可通过 event.currentTarget.dataset.custom 获取", + "label": "" + }, + { + "key": "disabled", + "type": ["Boolean"], + "desc": "是否禁用按钮", + "label": "" + }, + { + "key": "ghost", + "type": ["Boolean"], + "desc": "是否为幽灵按钮(镂空按钮)", + "label": "" + }, + { + "key": "icon", + "type": ["String"], + "desc": "图标名称", + "label": "" + }, + { + "key": "loading", + "type": ["Boolean"], + "desc": "是否显示为加载状态", + "label": "" + }, + { + "key": "shape", + "type": ["String"], + "desc": "按钮形状,有 4 种:长方形、正方形、圆角长方形、圆形", + "label": "" + }, + { + "key": "size", + "type": ["String"], + "desc": "组件尺寸", + "label": "" + }, + { + "key": "theme", + "type": ["String"], + "desc": "组件风格,依次为品牌色、危险色", + "label": "" + }, + { + "key": "type", + "type": ["String"], + "desc": "同小程序的 formType", + "label": "" + }, + { + "key": "variant", + "type": ["String"], + "desc": "按钮形式,基础、线框、文字", + "label": "" + } + ], + "externalClasses": ["t-class", "t-class-icon"], + "events": [ + { + "key": "bind:click", + "desc": "点击时触发", + "label": "" + } + ], + "tpl": "", + "path": "./button/button" + }, + "t-cell-group": { + "key": "t-cell-group", + "label": "单元格组", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-cell.png", + "properties": [ + { + "key": "bordered", + "type": ["Boolean"], + "desc": "是否显示组边框", + "label": "" + }, + { + "key": "title", + "type": ["String"], + "desc": "单元格组标题", + "label": "" + } + ], + "externalClasses": ["t-class"], + "tpl": "", + "require": { + "t-cell": "./cell/cell" + }, + "path": "./cell-group/cell-group" + }, + "t-cell": { + "key": "t-cell", + "label": "单元格", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-cell.png", + "properties": [ + { + "key": "align", + "type": ["String"], + "desc": "内容的对齐方式,默认居中对齐", + "label": "" + }, + { + "key": "arrow", + "type": ["Boolean"], + "desc": "是否显示右侧箭头", + "label": "" + }, + { + "key": "bordered", + "type": ["Boolean"], + "desc": "是否显示下边框", + "label": "" + }, + { + "key": "description", + "type": ["String"], + "desc": "下方内容描述", + "label": "" + }, + { + "key": "hover", + "type": ["Boolean"], + "desc": "是否开启点击反馈", + "label": "" + }, + { + "key": "image", + "type": ["String"], + "desc": "主图", + "label": "" + }, + { + "key": "jumpType", + "type": ["String"], + "desc": "链接跳转类型", + "label": "" + }, + { + "key": "leftIcon", + "type": ["String"], + "desc": "左侧图标,出现在单元格标题的左侧", + "label": "" + }, + { + "key": "note", + "type": ["String"], + "desc": "和标题同行的说明文字", + "label": "" + }, + { + "key": "required", + "type": ["Boolean"], + "desc": "是否显示表单必填星号", + "label": "" + }, + { + "key": "rightIcon", + "type": ["String"], + "desc": "最右侧图标", + "label": "" + }, + { + "key": "title", + "type": ["String"], + "desc": "标题", + "label": "" + }, + { + "key": "url", + "type": ["String"], + "desc": "点击后跳转链接地址。如果值为空,则表示不需要跳转", + "label": "" + } + ], + "externalClasses": [ + "t-class", + "t-class-title", + "t-class-note", + "t-class-description", + "t-class-thumb", + "t-class-hover", + "t-class-left", + "t-class-right" + ], + "events": [ + { + "key": "bind:click", + "desc": "右侧内容", + "label": "" + } + ], + "tpl": "", + "path": "./cell/cell" + }, + "t-check-tag": { + "key": "t-check-tag", + "label": "可选标签", + "icon": "", + "properties": [ + { + "key": "checked", + "type": ["Boolean"], + "desc": "标签选中的状态,默认风格(theme=default)才有选中态", + "label": "" + }, + { + "key": "closable", + "type": ["Boolean"], + "desc": "标签是否可关闭", + "label": "" + }, + { + "key": "content", + "type": ["String", "Number"], + "desc": "组件子元素", + "label": "" + }, + { + "key": "disabled", + "type": ["Boolean"], + "desc": "标签禁用态,失效标签不能触发事件。默认风格(theme=default)才有禁用态", + "label": "" + }, + { + "key": "icon", + "type": ["String"], + "desc": "标签中的图标,可自定义图标呈现", + "label": "" + }, + { + "key": "shape", + "type": ["String"], + "desc": "标签类型,有三种:方形、圆角方形、标记型", + "label": "" + }, + { + "key": "size", + "type": ["String"], + "desc": "标签尺寸", + "label": "" + } + ], + "events": [ + { + "key": "bind:change", + "desc": "组件子元素", + "label": "" + }, + { + "key": "bind:click", + "desc": "点击标签时触发", + "label": "" + } + ], + "tpl": "check tag", + "path": "./check-tag/check-tag" + }, + "t-checkbox-group": { + "key": "t-checkbox-group", + "label": "多选框组", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-checkbox.png", + "properties": [ + { + "key": "disabled", + "type": ["Boolean"], + "desc": "是否禁用组件", + "label": "" + }, + { + "key": "max", + "type": ["Number"], + "desc": "支持最多选中的数量", + "label": "" + }, + { + "key": "name", + "type": ["String"], + "desc": "统一设置内部复选框 HTML 属性", + "label": "" + }, + { + "key": "options", + "type": ["Array"], + "desc": "以配置形式设置子元素。示例1:`['北京', '上海']` ,示例2: `[{ label: '全选', checkAll: true }, { label: '上海', value: 'shanghai' }]`。checkAll 值为 true 表示当前选项为「全选选项」", + "label": "" + }, + { + "key": "value", + "type": ["Array"], + "desc": "选中值", + "label": "" + } + ], + "events": [ + { + "key": "bind:change", + "desc": "值变化时触发。`context.current` 表示当前变化的数据项,如果是全选则为空;`context.type` 表示引起选中数据变化的是选中或是取消选中,`context.option` 表示当前变化的数据项", + "label": "" + } + ], + "tpl": "", + "require": { + "t-checkbox": "./checkbox/checkbox" + }, + "path": "./checkbox-group/checkbox-group" + }, + "t-checkbox": { + "key": "t-checkbox", + "label": "多选框", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-checkbox.png", + "properties": [ + { + "key": "align", + "type": ["String"], + "desc": "多选框和内容相对位置", + "label": "" + }, + { + "key": "checkAll", + "type": ["Boolean"], + "desc": "用于标识是否为「全选选项」。单独使用无效,需在 CheckboxGroup 中使用", + "label": "" + }, + { + "key": "checked", + "type": ["Boolean"], + "desc": "是否选中", + "label": "" + }, + { + "key": "color", + "type": ["String"], + "desc": "多选框颜色", + "label": "" + }, + { + "key": "content", + "type": ["String"], + "desc": "多选框内容", + "label": "" + }, + { + "key": "contentDisabled", + "type": ["Boolean"], + "desc": "是否禁用组件内容(content)触发选中", + "label": "" + }, + { + "key": "disabled", + "type": ["Boolean"], + "desc": "是否禁用组件", + "label": "" + }, + { + "key": "icon", + "type": ["Array"], + "desc": "自定义选中图标和非选中图标。示例:[选中态图标地址,非选中态图标地址]", + "label": "" + }, + { + "key": "indeterminate", + "type": ["Boolean"], + "desc": "是否为半选", + "label": "" + }, + { + "key": "label", + "type": ["String"], + "desc": "主文案", + "label": "" + }, + { + "key": "maxContentRow", + "type": ["Number"], + "desc": "内容最大行数限制", + "label": "" + }, + { + "key": "maxLabelRow", + "type": ["Number"], + "desc": "主文案最大行数限制", + "label": "" + }, + { + "key": "name", + "type": ["String"], + "desc": "HTML 元素原生属性", + "label": "" + }, + { + "key": "readonly", + "type": ["Boolean"], + "desc": "只读状态", + "label": "" + }, + { + "key": "value", + "type": ["String", "Number"], + "desc": "多选框的值", + "label": "" + } + ], + "externalClasses": ["t-class", "t-class-icon", "t-class-label", "t-class-content", "t-class-border"], + "events": [ + { + "key": "bind:change", + "desc": "值变化时触发", + "label": "" + } + ], + "tpl": "", + "path": "./checkbox/checkbox" + }, + "t-collapse-panel": { + "key": "t-collapse-panel", + "label": "折叠面板", + "icon": "", + "properties": [ + { + "key": "content", + "type": ["String"], + "desc": "折叠面板内容", + "label": "" + }, + { + "key": "disabled", + "type": ["Boolean"], + "desc": "禁止当前面板展开,优先级大于 Collapse 的同名属性", + "label": "" + }, + { + "key": "expandIcon", + "type": ["Boolean"], + "desc": "当前折叠面板展开图标,优先级大于 Collapse 的同名属性", + "label": "" + }, + { + "key": "header", + "type": ["String"], + "desc": "面板头内容", + "label": "" + }, + { + "key": "headerRightContent", + "type": ["String"], + "desc": "面板头的右侧区域,一般用于呈现面板操作", + "label": "" + }, + { + "key": "value", + "type": ["String", "Number"], + "desc": "当前面板唯一标识,如果值为空则取当前面下标兜底作为唯一标识", + "label": "" + } + ], + "tpl": "此处可自定义内容", + "path": "./collapse/collapse-panel" + }, + "t-collapse": { + "key": "t-collapse", + "label": "折叠", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-collapse.png", + "properties": [ + { + "key": "defaultExpandAll", + "type": ["Boolean"], + "desc": "默认是否展开全部", + "label": "" + }, + { + "key": "disabled", + "type": ["Boolean"], + "desc": "是否禁用面板展开/收起操作", + "label": "" + }, + { + "key": "expandIcon", + "type": ["Boolean"], + "desc": "展开图标。值为 undefined 或 false 则不显示展开图标;值为 true 显示默认图标;值类型为函数,则表示完全自定义展开图标", + "label": "" + }, + { + "key": "expandMutex", + "type": ["Boolean"], + "desc": "每个面板互斥展开,每次只展开一个面板", + "label": "" + }, + { + "key": "value", + "type": ["Array"], + "desc": "展开的面板集合", + "label": "" + } + ], + "events": [ + { + "key": "bind:change", + "desc": "切换面板时触发,返回变化的值", + "label": "" + } + ], + "tpl": "此处可自定义内容", + "require": { + "t-collapse-panel": "./collapse/collapse-panel" + }, + "path": "./collapse/collapse" + }, + "t-date-time-picker": { + "key": "t-date-time-picker", + "label": "日期时间选择器", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-datetimepicker.png", + "properties": [ + { + "key": "cancelBtn", + "type": ["String"], + "desc": "取消按钮文字", + "label": "" + }, + { + "key": "confirmBtn", + "type": ["String"], + "desc": "确定按钮文字", + "label": "" + }, + { + "key": "end", + "type": ["String", "Number"], + "desc": "选择器的结束时间", + "label": "" + }, + { + "key": "footer", + "type": ["String"], + "desc": "底部内容", + "label": "" + }, + { + "key": "format", + "type": ["String"], + "desc": "用于格式化日期,[详细文档](https://day.js.org/docs/en/display/format)", + "label": "" + }, + { + "key": "header", + "type": ["Boolean"], + "desc": "头部内容。值为 true 显示空白头部,值为 false 不显示任何内容,值类型为 TNode 表示自定义头部内容", + "label": "" + }, + { + "key": "mode", + "type": ["String", "Array"], + "desc": "选择器模式,用于表示可以选择到哪一个层级。【示例一】year 或者 ['year'] 表示纯日期选择器,只能选择到年份,只显示年份。【示例二】'hour' 或 ['hour'] 表示纯时间选择器,只能选择到小时维度。【示例三】['year', 'month', 'date', 'hour', 'minute'] 表示,日期和时间 混合选择器,可以选择到具体哪一分钟,显示全部时间:年/月/日/时/分", + "label": "" + }, + { + "key": "showWeek", + "type": ["Boolean"], + "desc": "【开发中】是否在日期旁边显示周几(如周一,周二,周日等)", + "label": "" + }, + { + "key": "start", + "type": ["String", "Number"], + "desc": "选择器的开始时间", + "label": "" + }, + { + "key": "title", + "type": ["String"], + "desc": "标题", + "label": "" + }, + { + "key": "value", + "type": ["String", "Number"], + "desc": "选中值", + "label": "" + }, + { + "key": "visible", + "type": ["Boolean"], + "desc": "是否显示", + "label": "" + } + ], + "externalClasses": ["t-class", "t-class-confirm", "t-class-cancel", "t-class-title"], + "events": [ + { + "key": "bind:cancel", + "desc": "取消按钮点击时触发", + "label": "" + }, + { + "key": "bind:change", + "desc": "选中值发生变化时触发", + "label": "" + }, + { + "key": "bind:column-change", + "desc": "每一列选中数据变化时触发", + "label": "" + }, + { + "key": "bind:confirm", + "desc": "确认按钮点击时触发", + "label": "" + } + ], + "tpl": "", + "path": "./date-time-picker/date-time-picker" + }, + "t-dialog": { + "key": "t-dialog", + "label": "对话框", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-dialog.png", + "properties": [ + { + "key": "actions", + "type": ["Array"], + "desc": "操作栏", + "label": "" + }, + { + "key": "buttonLayout", + "type": ["String"], + "desc": "多按钮排列方式", + "label": "" + }, + { + "key": "cancelBtn", + "type": ["String", "Object"], + "desc": "取消按钮,可自定义。值为 null 则不显示取消按钮。值类型为字符串,则表示自定义按钮文本,值类型为 Object 则表示透传 Button 组件属性。使用 TNode 自定义按钮时,需自行控制取消事件", + "label": "" + }, + { + "key": "closeOnOverlayClick", + "type": ["Boolean"], + "desc": "点击蒙层时是否触发关闭事件", + "label": "" + }, + { + "key": "confirmBtn", + "type": ["String", "Object"], + "desc": "确认按钮。值为 null 则不显示确认按钮。值类型为字符串,则表示自定义按钮文本,值类型为 Object 则表示透传 Button 组件属性。使用 TNode 自定义按钮时,需自行控制确认事件", + "label": "" + }, + { + "key": "content", + "type": ["String"], + "desc": "内容", + "label": "" + }, + { + "key": "preventScrollThrough", + "type": ["Boolean"], + "desc": "防止滚动穿透", + "label": "" + }, + { + "key": "showInAttachedElement", + "type": ["Boolean"], + "desc": "【开发中】仅在挂载元素中显示抽屉,默认在浏览器可视区域显示。父元素需要有定位属性,如:position: relative", + "label": "" + }, + { + "key": "showOverlay", + "type": ["Boolean"], + "desc": "是否显示遮罩层", + "label": "" + }, + { + "key": "title", + "type": ["String"], + "desc": "标题", + "label": "" + }, + { + "key": "visible", + "type": ["Boolean"], + "desc": "控制对话框是否显示", + "label": "" + }, + { + "key": "zIndex", + "type": ["Number"], + "desc": "对话框层级,Web 侧样式默认为 2500,移动端和小程序样式默认为 1500", + "label": "" + } + ], + "externalClasses": ["t-class", "t-class-content", "t-class-confirm", "t-class-cancel"], + "events": [ + { + "key": "bind:cancel", + "desc": "如果“取消”按钮存在,则点击“取消”按钮时触发,同时触发关闭事件", + "label": "" + }, + { + "key": "bind:close", + "desc": "关闭事件,点击 取消按钮 或 点击蒙层 时触发", + "label": "" + }, + { + "key": "bind:overlay-click", + "desc": "如果蒙层存在,点击蒙层时触发", + "label": "" + } + ], + "tpl": "", + "path": "./dialog/dialog" + }, + "t-divider": { + "key": "t-divider", + "label": "分割线", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-divider.png", + "properties": [ + { + "key": "align", + "type": ["String"], + "desc": "文本位置(仅在水平分割线有效)", + "label": "" + }, + { + "key": "content", + "type": ["String"], + "desc": "子元素", + "label": "" + }, + { + "key": "dashed", + "type": ["Boolean"], + "desc": "是否虚线(仅在水平分割线有效)", + "label": "" + }, + { + "key": "layout", + "type": ["String"], + "desc": "分隔线类型有两种:水平和垂直", + "label": "" + }, + { + "key": "lineColor", + "type": ["String"], + "desc": "分隔线颜色", + "label": "" + } + ], + "externalClasses": ["t-class", "t-class-line", "t-class-content"], + "tpl": "", + "path": "./divider/divider" + }, + "t-drawer": { + "key": "t-drawer", + "label": "模态抽屉", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-drawer.png", + "properties": [ + { + "key": "closeOnOverlayClick", + "type": ["Boolean"], + "desc": "点击蒙层时是否触发抽屉关闭事件", + "label": "" + }, + { + "key": "destroyOnClose", + "type": ["Boolean"], + "desc": "抽屉关闭时是否销毁节点", + "label": "" + }, + { + "key": "items", + "type": ["Array"], + "desc": "抽屉里的列表项", + "label": "" + }, + { + "key": "placement", + "type": ["String"], + "desc": "抽屉方向", + "label": "" + }, + { + "key": "showOverlay", + "type": ["Boolean"], + "desc": "是否显示遮罩层", + "label": "" + }, + { + "key": "visible", + "type": ["Boolean"], + "desc": "组件是否可见", + "label": "" + }, + { + "key": "zIndex", + "type": ["Number"], + "desc": "抽屉层级,样式默认为 1500", + "label": "" + } + ], + "events": [ + { + "key": "bind:close", + "desc": "关闭事件,取消按钮点击时、关闭按钮点击时、点击蒙层时均会触发", + "label": "" + }, + { + "key": "bind:item-click", + "desc": "点击抽屉里的列表项", + "label": "" + }, + { + "key": "bind:overlay-click", + "desc": "如果蒙层存在,点击蒙层时触发", + "label": "" + } + ], + "tpl": "", + "path": "./drawer/drawer" + }, + "t-dropdown-item": { + "key": "t-dropdown-item", + "label": "下拉菜单子项", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-dropdownmenu.png", + "properties": [ + { + "key": "disabled", + "type": ["Boolean"], + "desc": "是否禁用", + "label": "" + }, + { + "key": "label", + "type": ["String"], + "desc": "标题", + "label": "" + }, + { + "key": "multiple", + "type": ["Boolean"], + "desc": "是否多选", + "label": "" + }, + { + "key": "options", + "type": ["Array"], + "desc": "选项数据", + "label": "" + } + ], + "tpl": "", + "path": "./dropdown-menu/dropdown-item" + }, + "t-dropdown-menu": { + "key": "t-dropdown-menu", + "label": "下拉菜单", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-dropdownmenu.png", + "properties": [ + { + "key": "activeColor", + "type": ["String"], + "desc": "【讨论中】菜单标题和选项的选中态颜色", + "label": "" + }, + { + "key": "closeOnClickOverlay", + "type": ["Boolean"], + "desc": "是否在点击遮罩层后关闭菜单", + "label": "" + }, + { + "key": "duration", + "type": ["String", "Number"], + "desc": "动画时长", + "label": "" + }, + { + "key": "showOverlay", + "type": ["Boolean"], + "desc": "是否显示遮罩层", + "label": "" + }, + { + "key": "zIndex", + "type": ["Number"], + "desc": "菜单栏 z-index 层级", + "label": "" + } + ], + "tpl": "", + "require": { + "t-dropdown-item": "./dropdown-menu/dropdown-item" + }, + "path": "./dropdown-menu/dropdown-menu" + }, + "t-empty": { + "key": "t-empty", + "label": "空状态", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-empty.png", + "properties": [ + { + "key": "action", + "type": ["String"], + "desc": "操作按钮", + "label": "" + }, + { + "key": "description", + "type": ["String"], + "desc": "描述文字", + "label": "" + }, + { + "key": "icon", + "type": ["String"], + "desc": "图标名称", + "label": "" + }, + { + "key": "image", + "type": ["String"], + "desc": "图片地址", + "label": "" + } + ], + "externalClasses": ["t-class", "t-class-description", "t-class-image", "t-class-actions"], + "tpl": "", + "path": "./empty/empty" + }, + "t-fab": { + "key": "t-fab", + "label": "悬浮按钮", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-fab.png", + "properties": [ + { + "key": "buttonProps", + "type": ["Object"], + "desc": "透传至 Button 组件", + "label": "" + }, + { + "key": "icon", + "type": ["String"], + "desc": "图标", + "label": "" + }, + { + "key": "style", + "type": ["String"], + "desc": "悬浮按钮的样式,常用于调整位置", + "label": "" + }, + { + "key": "text", + "type": ["String"], + "desc": "文本内容", + "label": "" + } + ], + "events": [ + { + "key": "bind:click", + "desc": "悬浮按钮点击事件", + "label": "" + } + ], + "tpl": "", + "path": "./fab/fab" + }, + "t-footer": { + "key": "t-footer", + "label": "布局-底部内容", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-footer.png", + "properties": [ + { + "key": "copyright", + "type": ["String"], + "desc": "版权信息,type 为`text`生效", + "label": "" + }, + { + "key": "logo", + "type": ["Object"], + "desc": "图标配置,type 为`logo`生效。`logo.icon` 表示图标链接地址,`logo.title` 表示标题文本,`logo.url` 表示链接跳转地址", + "label": "" + }, + { + "key": "textLinkList", + "type": ["Array"], + "desc": "链接列表,type 为`text`生效。name 表示链接名称, url 表示链接 page 路径,目前只支持小程序内部跳转,openType 表示跳转方式", + "label": "" + }, + { + "key": "theme", + "type": ["String"], + "desc": "页脚展示类型", + "label": "" + } + ], + "tpl": "", + "path": "./footer/footer" + }, + "t-grid-item": { + "key": "t-grid-item", + "label": "宫格子项", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-grid.png", + "properties": [ + { + "key": "badgeProps", + "type": ["Object"], + "desc": "头像右上角提示信息,继承 Badge 组件的全部特性。如:小红点,或者数字", + "label": "" + }, + { + "key": "description", + "type": ["String"], + "desc": "文本以外的更多描述,辅助信息。可以通过 Props 传入文本,也可以自定义标题节点", + "label": "" + }, + { + "key": "image", + "type": ["String"], + "desc": "图片,可以是图片地址,也可以自定义图片节点", + "label": "" + }, + { + "key": "jumpType", + "type": ["String"], + "desc": "链接跳转类型", + "label": "" + }, + { + "key": "layout", + "type": ["String"], + "desc": "内容布局方式", + "label": "" + }, + { + "key": "text", + "type": ["String"], + "desc": "文本,可以通过 Props 传入文本,也可以自定义标题节点", + "label": "" + }, + { + "key": "url", + "type": ["String"], + "desc": "点击后的跳转链接", + "label": "" + } + ], + "externalClasses": ["t-class", "t-class-image", "t-class-text", "t-class-description"], + "tpl": "", + "path": "./grid-item/grid-item" + }, + "t-grid": { + "key": "t-grid", + "label": "栅格", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-grid.png", + "properties": [ + { + "key": "align", + "type": ["String"], + "desc": "内容对齐方式", + "label": "" + }, + { + "key": "border", + "type": ["Boolean", "Object"], + "desc": "边框,默认不显示。值为 true 则显示默认边框,值类型为 object 则表示自定义边框样式", + "label": "" + }, + { + "key": "column", + "type": ["Number"], + "desc": "每一行的列数量", + "label": "" + }, + { + "key": "gutter", + "type": ["Number"], + "desc": "间隔大小", + "label": "" + }, + { + "key": "hover", + "type": ["Boolean"], + "desc": "是否开启点击反馈", + "label": "" + } + ], + "externalClasses": ["t-class"], + "tpl": "", + "require": { + "t-grid-item": "./grid-item/grid-item" + }, + "path": "./grid/grid" + }, + "t-icon": { + "key": "t-icon", + "label": "图标", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-icon.png", + "properties": [ + { + "key": "classPrefix", + "type": ["String"], + "desc": "自定义icon前缀", + "label": "" + }, + { + "key": "color", + "type": ["String"], + "desc": "图标颜色", + "label": "" + }, + { + "key": "style", + "type": ["String"], + "desc": "自定义样式", + "label": "" + }, + { + "key": "name", + "type": ["String"], + "desc": "图标名称", + "label": "" + }, + { + "key": "size", + "type": ["String", "Number"], + "desc": "图标名称", + "label": "" + } + ], + "tpl": "", + "path": "./icon/icon" + }, + "t-image": { + "key": "t-image", + "label": "图片", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-image.png", + "properties": [ + { + "key": "error", + "type": ["String"], + "desc": "加载失败时显示的内容。值为 `default` 则表示使用默认加载失败风格;值为空或者 `slot` 表示使用插槽渲染,插槽名称为 `error`;值为其他则表示普通文本内容,如“加载失败”", + "label": "" + }, + { + "key": "lazy", + "type": ["Boolean"], + "desc": "是否开启图片懒加载", + "label": "" + }, + { + "key": "loading", + "type": ["String"], + "desc": "加载态内容。值为 `default` 则表示使用默认加载中风格;值为空或者 `slot` 表示使用插槽渲染,插槽名称为 `loading`;值为其他则表示普通文本内容,如“加载中”", + "label": "" + }, + { + "key": "shape", + "type": ["String"], + "desc": "图片圆角类型", + "label": "" + }, + { + "key": "src", + "type": ["String"], + "desc": "图片链接", + "label": "" + } + ], + "externalClasses": ["t-class", "t-class-load"], + "events": [ + { + "key": "bind:error", + "desc": "图片加载失败时触发", + "label": "" + }, + { + "key": "bind:load", + "desc": "图片加载完成时触发", + "label": "" + } + ], + "tpl": "", + "path": "./image/image" + }, + "t-indexes": { + "key": "t-indexes", + "label": "索引", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-indexes.png", + "properties": [ + { + "key": "height", + "type": ["Number"], + "desc": "列表高度,未设置默认占满设备高度", + "label": "" + }, + { + "key": "list", + "type": ["Array"], + "desc": "索引列表的列表数据。每个元素包含三个子元素,index(string):索引值,例如1,2,3,...或A,B,C等;title(string): 索引标题,可不填将默认设为索引值;children(Array<{title: string}>): 子元素列表,title为子元素的展示文案。", + "label": "" + }, + { + "key": "sticky", + "type": ["Boolean"], + "desc": "索引是否吸顶,默认为true", + "label": "" + } + ], + "events": [ + { + "key": "bind:select", + "desc": "点击行元素时触发事件", + "label": "" + } + ], + "tpl": "", + "path": "./indexes/indexes" + }, + "t-input": { + "key": "t-input", + "label": "输入框", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-input.png", + "properties": [ + { + "key": "align", + "type": ["String"], + "desc": "文本内容位置,居左/居中/居右", + "label": "" + }, + { + "key": "borderless", + "type": ["Boolean"], + "desc": "【讨论中】是否开启无边框模式", + "label": "" + }, + { + "key": "clearable", + "type": ["Boolean"], + "desc": "是否可清空", + "label": "" + }, + { + "key": "disabled", + "type": ["Boolean"], + "desc": "是否禁用输入框", + "label": "" + }, + { + "key": "errorMessage", + "type": ["String"], + "desc": "错误提示文本,值为空不显示(废弃属性,如果需要,请更为使用 status 和 tips)", + "label": "" + }, + { + "key": "format", + "type": ["String"], + "desc": "【开发中】指定输入框展示值的格式", + "label": "" + }, + { + "key": "label", + "type": ["String"], + "desc": "左侧文本", + "label": "" + }, + { + "key": "maxcharacter", + "type": ["Number"], + "desc": "用户最多可以输入的字符个数,一个中文汉字表示两个字符长度。`maxcharacter` 和 `maxlength` 二选一使用", + "label": "" + }, + { + "key": "maxlength", + "type": ["Number"], + "desc": "用户最多可以输入的文本长度,一个中文等于一个计数长度。值小于等于 0 的时候,则表示不限制输入长度。`maxcharacter` 和 `maxlength` 二选一使用", + "label": "" + }, + { + "key": "placeholder", + "type": ["String"], + "desc": "占位符", + "label": "" + }, + { + "key": "prefixIcon", + "type": ["String"], + "desc": "组件前置图标,值为字符串则表示图标名称", + "label": "" + }, + { + "key": "readonly", + "type": ["Boolean"], + "desc": "只读状态", + "label": "" + }, + { + "key": "size", + "type": ["String"], + "desc": "输入框尺寸", + "label": "" + }, + { + "key": "status", + "type": ["String"], + "desc": "输入框状态", + "label": "" + }, + { + "key": "suffix", + "type": ["String"], + "desc": "后置图标前的后置内容", + "label": "" + }, + { + "key": "suffixIcon", + "type": ["String"], + "desc": "后置文本内容,值为字符串则表示图标名称", + "label": "" + }, + { + "key": "tips", + "type": ["String"], + "desc": "输入框下方提示文本,会根据不同的 `status` 呈现不同的样式", + "label": "" + }, + { + "key": "value", + "type": ["String", "Number"], + "desc": "输入框的值", + "label": "" + } + ], + "externalClasses": ["t-class", "t-class-input", "t-class-placeholder", "t-class-error-msg"], + "events": [ + { + "key": "bind:blur", + "desc": "失去焦点时触发", + "label": "" + }, + { + "key": "bind:change", + "desc": "输入框值发生变化时触发", + "label": "" + }, + { + "key": "bind:clear", + "desc": "清空按钮点击时触发", + "label": "" + }, + { + "key": "bind:enter", + "desc": "回车键按下时触发", + "label": "" + }, + { + "key": "bind:focus", + "desc": "获得焦点时触发", + "label": "" + } + ], + "tpl": "", + "path": "./input/input" + }, + "t-loading": { + "key": "t-loading", + "label": "加载中", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-loading.png", + "properties": [ + { + "key": "delay", + "type": ["Number"], + "desc": "延迟显示加载效果的时间,用于防止请求速度过快引起的加载闪烁,单位:毫秒", + "label": "" + }, + { + "key": "duration", + "type": ["Number"], + "desc": "加载动画执行完成一次的时间,单位:毫秒", + "label": "" + }, + { + "key": "indicator", + "type": ["Boolean"], + "desc": "是否显示加载指示符", + "label": "" + }, + { + "key": "inheritColor", + "type": ["Boolean"], + "desc": "是否继承父元素颜色", + "label": "" + }, + { + "key": "layout", + "type": ["String"], + "desc": "对齐方式", + "label": "" + }, + { + "key": "loading", + "type": ["Boolean"], + "desc": "是否处于加载状态", + "label": "" + }, + { + "key": "pause", + "type": ["Boolean"], + "desc": "是否暂停动画", + "label": "" + }, + { + "key": "progress", + "type": ["Number"], + "desc": "加载进度", + "label": "" + }, + { + "key": "reverse", + "type": ["Boolean"], + "desc": "加载动画是否反向", + "label": "" + }, + { + "key": "size", + "type": ["String"], + "desc": "尺寸,示例:40rpx/20px", + "label": "" + }, + { + "key": "text", + "type": ["String"], + "desc": "加载提示文案", + "label": "" + }, + { + "key": "theme", + "type": ["String"], + "desc": "加载组件类型", + "label": "" + } + ], + "externalClasses": ["t-class", "t-class-text", "t-class-indicator"], + "tpl": "", + "path": "./loading/loading" + }, + "t-message": { + "key": "t-message", + "label": "全局提醒", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-message.png", + "properties": [ + { + "key": "action", + "type": ["String"], + "desc": "操作", + "label": "" + }, + { + "key": "align", + "type": ["String"], + "desc": "文本对齐方式", + "label": "" + }, + { + "key": "closeBtn", + "type": ["String", "Boolean"], + "desc": "关闭按钮,可以自定义。值为 true 显示默认关闭按钮,值为 false 不显示关闭按钮。值类型为 string 则直接显示值,如:“关闭”。也可以完全自定义按钮", + "label": "" + }, + { + "key": "content", + "type": ["String"], + "desc": "用于自定义消息弹出内容", + "label": "" + }, + { + "key": "duration", + "type": ["Number"], + "desc": "消息内置计时器,计时到达时会触发 duration-end 事件。单位:毫秒。值为 0 则表示没有计时器。", + "label": "" + }, + { + "key": "icon", + "type": ["String", "Boolean"], + "desc": "消息提醒前面的图标。值为 true 则根据 theme 显示对应的图标,值为 false 则不显示图标。值为 'info' 或 'bell' 则显示组件内置图标。也可以完全自定义图标节点", + "label": "" + }, + { + "key": "marquee", + "type": ["Boolean", "Object"], + "desc": "跑马灯效果。speed 指速度控制;loop 指循环播放次数,值为 -1 表示循环播放,值为 0 表示不循环播放;delay 表示延迟多久开始播放", + "label": "" + }, + { + "key": "offset", + "type": ["Array"], + "desc": "相对于 placement 的偏移量,示例:[-10, 20] 或 ['10rpx', '8rpx']", + "label": "" + }, + { + "key": "theme", + "type": ["String"], + "desc": "消息组件风格", + "label": "" + }, + { + "key": "visible", + "type": ["Boolean"], + "desc": "是否显示,隐藏时默认销毁组件", + "label": "" + }, + { + "key": "zIndex", + "type": ["Number"], + "desc": "元素层级,样式默认为 5000", + "label": "" + } + ], + "externalClasses": ["t-class", "t-class-content", "t-class-icon", "t-class-action", "t-class-close-btn"], + "events": [ + { + "key": "bind:action-btn-click", + "desc": "当操作按钮存在时,用户点击操作按钮时触发", + "label": "" + }, + { + "key": "bind:close-btn-click", + "desc": "当关闭按钮存在时,用户点击关闭按钮触发", + "label": "" + }, + { + "key": "bind:duration-end", + "desc": "计时结束后触发", + "label": "" + } + ], + "tpl": "", + "path": "./message/message" + }, + "t-navbar": { + "key": "t-navbar", + "label": "导航条", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-navbar.png", + "properties": [ + { + "key": "animation", + "type": ["Boolean"], + "desc": "是否添加动画效果", + "label": "" + }, + { + "key": "background", + "type": ["String"], + "desc": "背景", + "label": "" + }, + { + "key": "delta", + "type": ["Number"], + "desc": "后退按钮后退层数,含义参考 [wx.navigateBack](https://developers.weixin.qq.com/miniprogram/dev/api/route/wx.navigateBack.html),特殊的,传入 0 不会发生执行 wx.navigateBack,只会触发一个 goback 事件供自行处理。", + "label": "" + }, + { + "key": "fixed", + "type": ["Boolean"], + "desc": "是否固定在顶部", + "label": "" + }, + { + "key": "homeIcon", + "type": ["String"], + "desc": "首页图标地址。值为 '' 或者 undefiend 则表示不显示返回图标,值为 'circle' 表示显示默认图标,值为 'slot' 表示使用插槽渲染,值为其他则表示图标地址", + "label": "" + }, + { + "key": "leftIcon", + "type": ["String"], + "desc": "左侧图标地址,值为 '' 或者 undefiend 则表示不显示返回图标,值为 'arrow-left' 表示显示返回图标,值为 'slot' 表示使用插槽渲染,值为其他则表示图标地址", + "label": "" + }, + { + "key": "title", + "type": ["String"], + "desc": "页面标题", + "label": "" + }, + { + "key": "titleMaxLength", + "type": ["Number"], + "desc": "标题文字最大长度,超出的范围使用 `...` 表示", + "label": "" + }, + { + "key": "visible", + "type": ["Boolean"], + "desc": "是否显示", + "label": "" + } + ], + "externalClasses": ["t-class", "t-class-title", "t-class-left-icon", "t-class-home-icon", "t-class-capsule"], + "events": [ + { + "key": "bind:complete", + "desc": "navigateBack 执行完成后触发(失败或成功均会触发)", + "label": "" + }, + { + "key": "bind:fail", + "desc": "navigateBack 执行失败后触发", + "label": "" + }, + { + "key": "bind:go-back", + "desc": "delta 值为 0 时,点击返回,触发该事件", + "label": "" + }, + { + "key": "bind:go-home", + "desc": "点击 Home 触发", + "label": "" + }, + { + "key": "bind:success", + "desc": "navigateBack 执行成功后触发", + "label": "" + } + ], + "tpl": "", + "path": "./navbar/navbar" + }, + "t-picker-item": { + "key": "t-picker-item", + "label": "选择器子项", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-picker.png", + "properties": [ + { + "key": "format", + "type": ["String"], + "desc": "格式化标签", + "label": "" + }, + { + "key": "options", + "type": ["Array"], + "desc": "数据源", + "label": "" + } + ], + "tpl": "", + "path": "./picker-item/picker-item" + }, + "t-picker": { + "key": "t-picker", + "label": "选择器", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-picker.png", + "properties": [ + { + "key": "cancelBtn", + "type": ["String", "Object"], + "desc": "取消按钮文字", + "label": "" + }, + { + "key": "confirmBtn", + "type": ["String", "Object"], + "desc": "确定按钮文字", + "label": "" + }, + { + "key": "footer", + "type": ["String"], + "desc": "底部内容", + "label": "" + }, + { + "key": "header", + "type": ["Boolean"], + "desc": "头部内容。值为 true 显示空白头部,值为 false 不显示任何内容,值类型为 TNode 表示自定义头部内容", + "label": "" + }, + { + "key": "title", + "type": ["String"], + "desc": "标题", + "label": "" + }, + { + "key": "value", + "type": ["Array"], + "desc": "选中值", + "label": "" + }, + { + "key": "visible", + "type": ["Boolean"], + "desc": "是否显示", + "label": "" + } + ], + "events": [ + { + "key": "bind:cancel", + "desc": "点击取消按钮时触发", + "label": "" + }, + { + "key": "bind:change", + "desc": "选中变化时候触发", + "label": "" + }, + { + "key": "bind:pick", + "desc": "任何一列选中都会触发,不同的列参数不同。`context.column` 表示第几列变化,`context.index` 表示变化那一列的选中项下标", + "label": "" + } + ], + "tpl": "", + "require": { + "t-picker-item": "./picker-item/picker-item" + }, + "path": "./picker/picker" + }, + "t-popup": { + "key": "t-popup", + "label": "气泡框", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-popup.png", + "properties": [ + { + "key": "closeBtn", + "type": ["Boolean"], + "desc": "关闭按钮,值类型为 Boolean 时表示是否显示关闭按钮。也可以自定义关闭按钮", + "label": "" + }, + { + "key": "closeOnOverlayClick", + "type": ["Boolean"], + "desc": "点击遮罩层是否关闭", + "label": "" + }, + { + "key": "content", + "type": ["String"], + "desc": "浮层里面的内容", + "label": "" + }, + { + "key": "placement", + "type": ["String"], + "desc": "浮层出现位置", + "label": "" + }, + { + "key": "preventScrollThrough", + "type": ["Boolean"], + "desc": "防止滚动穿透", + "label": "" + }, + { + "key": "showOverlay", + "type": ["Boolean"], + "desc": "是否显示遮罩层", + "label": "" + }, + { + "key": "transitionProps", + "type": ["Object"], + "desc": "动画效果定义", + "label": "" + }, + { + "key": "visible", + "type": ["Boolean"], + "desc": "是否显示浮层", + "label": "" + }, + { + "key": "zIndex", + "type": ["Number"], + "desc": "组件层级,Web 侧样式默认为 5500,移动端和小程序样式默认为 1500", + "label": "" + } + ], + "externalClasses": ["t-class", "t-class-overlay", "t-class-content"], + "events": [ + { + "key": "bind:visible-change", + "desc": "当浮层隐藏或显示时触发", + "label": "" + } + ], + "tpl": "", + "path": "./popup/popup" + }, + "t-progress": { + "key": "t-progress", + "label": "进度条", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-progress.png", + "properties": [ + { + "key": "color", + "type": ["String", "Object", "Array"], + "desc": "进度条颜色。示例:'#ED7B2F' 或 'orange' 或 `['#f00', '#0ff', '#f0f']` 或 `{ '0%': '#f00', '100%': '#0ff' }` 或 `{ from: '#000', to: '#000' }` 等", + "label": "" + }, + { + "key": "label", + "type": ["String", "Boolean"], + "desc": "进度百分比,可自定义", + "label": "" + }, + { + "key": "percentage", + "type": ["Number"], + "desc": "进度条百分比", + "label": "" + }, + { + "key": "size", + "type": ["String", "Number"], + "desc": "进度条尺寸,示例:small/medium/large/240。small 值为 72; medium 值为 112;large 值为 160", + "label": "" + }, + { + "key": "status", + "type": ["String"], + "desc": "进度条状态", + "label": "" + }, + { + "key": "strokeWidth", + "type": ["String", "Number"], + "desc": "进度条线宽。宽度数值不能超过 size 的一半,否则不能输出环形进度", + "label": "" + }, + { + "key": "theme", + "type": ["String"], + "desc": "进度条风格。值为 line,标签(label)显示在进度条右侧;值为 plump,标签(label)显示在进度条里面;值为 circle,标签(label)显示在进度条正中间", + "label": "" + }, + { + "key": "trackColor", + "type": ["String"], + "desc": "进度条未完成部分颜色", + "label": "" + } + ], + "tpl": "", + "path": "./progress/progress" + }, + "t-pull-down-refresh": { + "key": "t-pull-down-refresh", + "label": "下拉刷新", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-pulldownrefresh.png", + "properties": [ + { + "key": "loadingBarHeight", + "type": ["String", "Number"], + "desc": "加载中下拉高度,如果值为数字则单位是:'px'", + "label": "" + }, + { + "key": "loadingProps", + "type": ["Object"], + "desc": "加载loading样式", + "label": "" + }, + { + "key": "loadingTexts", + "type": ["Array"], + "desc": "提示语,组件内部默认值为 ['下拉刷新', '松手刷新', '正在刷新', '刷新完成']", + "label": "" + }, + { + "key": "maxBarHeight", + "type": ["String", "Number"], + "desc": "最大下拉高度,如果值为数字则单位是:'px'", + "label": "" + }, + { + "key": "refreshTimeout", + "type": ["Number"], + "desc": "刷新超时时间", + "label": "" + }, + { + "key": "value", + "type": ["Boolean"], + "desc": "组件状态,值为 `true` 表示下拉状态,值为 `false` 表示收起状态", + "label": "" + } + ], + "externalClasses": ["t-class", "t-class-loading", "t-class-text", "t-class-indicator"], + "events": [ + { + "key": "bind:change", + "desc": "下拉或收起时触发,用户手势往下滑动触发下拉状态,手势松开触发收起状态", + "label": "" + }, + { + "key": "bind:refresh", + "desc": "结束下拉时触发", + "label": "" + }, + { + "key": "bind:timeout", + "desc": "刷新超时触发", + "label": "" + } + ], + "tpl": "拖拽该区域演示 中间下拉刷新", + "path": "./pull-down-refresh/pull-down-refresh" + }, + "t-radio-group": { + "key": "t-radio-group", + "label": "单选框组", + "icon": "", + "properties": [ + { + "key": "disabled", + "type": ["Boolean"], + "desc": "是否禁用全部子单选框", + "label": "" + }, + { + "key": "name", + "type": ["String"], + "desc": "HTML 元素原生属性", + "label": "" + }, + { + "key": "options", + "type": ["Array"], + "desc": "单选组件按钮形式。RadioOption 数据类型为 string 或 number 时,表示 label 和 value 值相同", + "label": "" + }, + { + "key": "value", + "type": ["String", "Number", "Boolean"], + "desc": "选中的值", + "label": "" + } + ], + "events": [ + { + "key": "bind:change", + "desc": "选中值发生变化时触发", + "label": "" + } + ], + "tpl": "", + "require": { + "t-radio": "./radio/radio" + }, + "path": "./radio-group/radio-group" + }, + "t-radio": { + "key": "t-radio", + "label": "单选框", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-radio.png", + "properties": [ + { + "key": "align", + "type": ["String"], + "desc": "复选框和内容相对位置", + "label": "" + }, + { + "key": "allowUncheck", + "type": ["Boolean"], + "desc": "是否允许取消选中", + "label": "" + }, + { + "key": "checked", + "type": ["Boolean"], + "desc": "是否选中", + "label": "" + }, + { + "key": "color", + "type": ["String"], + "desc": "单选按钮颜色", + "label": "" + }, + { + "key": "content", + "type": ["String"], + "desc": "单选内容", + "label": "" + }, + { + "key": "contentDisabled", + "type": ["Boolean"], + "desc": "是否禁用组件内容(content)触发选中", + "label": "" + }, + { + "key": "disabled", + "type": ["Boolean"], + "desc": "是否为禁用态", + "label": "" + }, + { + "key": "icon", + "type": ["String", "Array"], + "desc": "自定义选中图标和非选中图标。示例:[选中态图标,非选中态图标]。值为 fill-circle 表示图标为填充型图标,值为 stroke-line 表示图标为描边型图标", + "label": "" + }, + { + "key": "label", + "type": ["String"], + "desc": "主文案", + "label": "" + }, + { + "key": "maxContentRow", + "type": ["Number"], + "desc": "内容最大行数限制", + "label": "" + }, + { + "key": "maxLabelRow", + "type": ["Number"], + "desc": "主文案最大行数限制", + "label": "" + }, + { + "key": "name", + "type": ["String"], + "desc": "HTML 元素原生属性", + "label": "" + }, + { + "key": "value", + "type": ["String", "Number", "Boolean"], + "desc": "单选按钮的值", + "label": "" + } + ], + "externalClasses": ["t-class", "t-class-icon", "t-class-label", "t-class-content", "t-class-border"], + "events": [ + { + "key": "bind:change", + "desc": "值变化时触发", + "label": "" + } + ], + "tpl": "", + "path": "./radio/radio" + }, + "t-rate": { + "key": "t-rate", + "label": "评分", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-rate.png", + "properties": [ + { + "key": "allowHalf", + "type": ["Boolean"], + "desc": "是否允许半选", + "label": "" + }, + { + "key": "color", + "type": ["String", "Array"], + "desc": "评分图标的颜色,样式中默认为 #ED7B2F。一个值表示设置选中高亮的五角星颜色,示例:[选中颜色]。数组则表示分别设置 选中高亮的五角星颜色 和 未选中暗灰的五角星颜色,[选中颜色,未选中颜色]。示例:['#ED7B2F', '#E3E6EB']", + "label": "" + }, + { + "key": "count", + "type": ["Number"], + "desc": "评分的数量", + "label": "" + }, + { + "key": "disabled", + "type": ["Boolean"], + "desc": "是否禁用评分", + "label": "" + }, + { + "key": "gap", + "type": ["Number"], + "desc": "评分图标的间距", + "label": "" + }, + { + "key": "showText", + "type": ["Boolean"], + "desc": "是否显示对应的辅助文字", + "label": "" + }, + { + "key": "size", + "type": ["String"], + "desc": "评分图标的大小,示例:`20`", + "label": "" + }, + { + "key": "texts", + "type": ["Array"], + "desc": "评分等级对应的辅助文字。组件内置默认值为:['极差', '失望', '一般', '满意', '惊喜']。自定义值示例:['1分', '2分', '3分', '4分', '5分']", + "label": "" + }, + { + "key": "value", + "type": ["Number"], + "desc": "选择评分的值", + "label": "" + }, + { + "key": "variant", + "type": ["String"], + "desc": "形状类型,有描边类型和填充类型两种", + "label": "" + } + ], + "events": [ + { + "key": "bind:change", + "desc": "评分数改变时触发", + "label": "" + } + ], + "tpl": "", + "path": "./rate/rate" + }, + "t-search": { + "key": "t-search", + "label": "搜索", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-search.png", + "properties": [ + { + "key": "action", + "type": ["String"], + "desc": "自定义右侧操作按钮文字", + "label": "" + }, + { + "key": "center", + "type": ["Boolean"], + "desc": "是否居中", + "label": "" + }, + { + "key": "disabled", + "type": ["Boolean"], + "desc": "是否禁用", + "label": "" + }, + { + "key": "focus", + "type": ["Boolean"], + "desc": "是否聚焦", + "label": "" + }, + { + "key": "label", + "type": ["String"], + "desc": "左侧文本", + "label": "" + }, + { + "key": "leftIcon", + "type": ["String"], + "desc": "左侧图标", + "label": "" + }, + { + "key": "placeholder", + "type": ["String"], + "desc": "占位符", + "label": "" + }, + { + "key": "rightIcon", + "type": ["String"], + "desc": "右侧图标", + "label": "" + }, + { + "key": "shape", + "type": ["String"], + "desc": "搜索框形状", + "label": "" + }, + { + "key": "value", + "type": ["String"], + "desc": "值", + "label": "" + } + ], + "externalClasses": [ + "t-class", + "t-class-input", + "t-class-input-container", + "t-class-cancel", + "t-class-left", + "t-class-right" + ], + "events": [ + { + "key": "bind:action-click", + "desc": "点击右侧操作按钮文字时触发", + "label": "" + }, + { + "key": "bind:blur", + "desc": "失去焦点时触发", + "label": "" + }, + { + "key": "bind:change", + "desc": "值发生变化时触发", + "label": "" + }, + { + "key": "bind:clear", + "desc": "点击清除时触发", + "label": "" + }, + { + "key": "bind:focus", + "desc": "聚焦时触发", + "label": "" + }, + { + "key": "bind:submit", + "desc": "提交时触发", + "label": "" + } + ], + "tpl": "", + "path": "./search/search" + }, + "t-skeleton": { + "key": "t-skeleton", + "label": "骨架屏", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-skeleton.png", + "properties": [ + { + "key": "animation", + "type": ["String"], + "desc": "动画效果,有「渐变加载动画」和「闪烁加载动画」两种。值为 'none' 则表示没有动画", + "label": "" + }, + { + "key": "delay", + "type": ["Number"], + "desc": "【开发中】延迟显示加载效果的时间,用于防止请求速度过快引起的加载闪烁,单位:毫秒", + "label": "" + }, + { + "key": "loading", + "type": ["Boolean"], + "desc": "是否为加载状态,如果是则显示骨架图,如果不是则显示加载完成的内容", + "label": "" + }, + { + "key": "rowCol", + "type": ["Array"], + "desc": "用于设置行列数量、宽度高度、间距等。【示例一】,`[1, 1, 2]` 表示输出三行骨架图,第一行一列,第二行一列,第三行两列。【示例二】,`[1, 1, { width: '100px' }]` 表示自定义第三行的宽度为 `100px`。【示例三】,`[1, 2, [{ width, height }, { width, height, marginLeft }]]` 表示第三行有两列,且自定义宽度、高度和间距", + "label": "" + }, + { + "key": "theme", + "type": ["String"], + "desc": "骨架图风格,有基础、头像组合等两大类", + "label": "" + } + ], + "externalClasses": ["t-class", "t-class-avatar", "t-class-image", "t-class-text"], + "tpl": "", + "path": "./skeleton/skeleton" + }, + "t-slider": { + "key": "t-slider", + "label": "滑块", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-slider.png", + "properties": [ + { + "key": "colors", + "type": ["Array"], + "desc": "颜色,[已选择, 未选择]", + "label": "" + }, + { + "key": "disabled", + "type": ["Boolean"], + "desc": "是否禁用组件", + "label": "" + }, + { + "key": "disabledColor", + "type": ["Array"], + "desc": "禁用状态滑动条的颜色,[已选, 未选]", + "label": "" + }, + { + "key": "label", + "type": ["String", "Boolean"], + "desc": "滑块当前值文本。
值为 true 显示默认文案;值为 false 不显示滑块当前值文本;
值为 `${value}%` 则表示组件会根据占位符渲染文案;
值类型为函数时,参数 `value` 标识滑块值,参数 `position=start` 表示范围滑块的起始值,参数 `position=end` 表示范围滑块的终点值", + "label": "" + }, + { + "key": "marks", + "type": ["Object", "Array"], + "desc": "刻度标记,示例:`[0, 10, 40, 200]` 或者 `{ 5: '5¥', 10: '10%' }`", + "label": "" + }, + { + "key": "max", + "type": ["Number"], + "desc": "滑块范围最大值", + "label": "" + }, + { + "key": "min", + "type": ["Number"], + "desc": "滑块范围最小值", + "label": "" + }, + { + "key": "range", + "type": ["Boolean"], + "desc": "双游标滑块", + "label": "" + }, + { + "key": "showExtremeValue", + "type": ["Boolean"], + "desc": "是否边界值", + "label": "" + }, + { + "key": "step", + "type": ["Number"], + "desc": "步长", + "label": "" + }, + { + "key": "value", + "type": ["Number", "Array"], + "desc": "滑块值", + "label": "" + } + ], + "externalClasses": ["t-class", "t-class-bar", "t-class-bar-active", "t-class-bar-disabled", "t-class-cursor"], + "events": [ + { + "key": "bind:change", + "desc": "滑块值变化时触发", + "label": "" + }, + { + "key": "bind:dragend", + "desc": "结束拖动时触发", + "label": "" + }, + { + "key": "bind:dragstart", + "desc": "开始拖动时触发", + "label": "" + } + ], + "tpl": "", + "path": "./slider/slider" + }, + "t-step-item": { + "key": "t-step-item", + "label": "步骤", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-steps.png", + "properties": [ + { + "key": "content", + "type": ["String"], + "desc": "步骤描述", + "label": "" + }, + { + "key": "icon", + "type": ["String"], + "desc": "图标。传入 slot 代表使用插槽,其他字符串代表使用内置图标", + "label": "" + }, + { + "key": "status", + "type": ["String"], + "desc": "当前步骤的状态", + "label": "" + }, + { + "key": "subStepItems", + "type": ["Array"], + "desc": "子步骤条,仅支持 layout = 'vertical' 时", + "label": "" + }, + { + "key": "title", + "type": ["String"], + "desc": "标题", + "label": "" + } + ], + "externalClasses": ["t-class", "t-class-content", "t-class-title", "t-class-description", "t-class-extra"], + "tpl": "", + "path": "./step-item/step-item" + }, + "t-stepper": { + "key": "t-stepper", + "label": "步进器", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-stepper.png", + "properties": [ + { + "key": "disabled", + "type": ["Boolean"], + "desc": "禁用全部操作", + "label": "" + }, + { + "key": "disableInput", + "type": ["Boolean"], + "desc": "禁用输入框", + "label": "" + }, + { + "key": "inputWidth", + "type": ["Number"], + "desc": "输入框宽度", + "label": "" + }, + { + "key": "max", + "type": ["Number"], + "desc": "最大值", + "label": "" + }, + { + "key": "min", + "type": ["Number"], + "desc": "最小值", + "label": "" + }, + { + "key": "step", + "type": ["Number"], + "desc": "步长", + "label": "" + }, + { + "key": "theme", + "type": ["String"], + "desc": "组件风格", + "label": "" + }, + { + "key": "value", + "type": ["String", "Number"], + "desc": "值", + "label": "" + } + ], + "externalClasses": ["t-class", "t-class-input", "t-class-add", "t-class-minus"], + "events": [ + { + "key": "bind:blur", + "desc": "输入框失去焦点时触发", + "label": "" + }, + { + "key": "bind:change", + "desc": "数值发生变更时触发", + "label": "" + }, + { + "key": "bind:overlimit", + "desc": "数值超出限制时触发", + "label": "" + } + ], + "tpl": "", + "path": "./stepper/stepper" + }, + "t-steps": { + "key": "t-steps", + "label": "步骤条", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-steps.png", + "properties": [ + { + "key": "current", + "type": ["String", "Number"], + "desc": "当前步骤,即整个步骤条进度。默认根据步骤下标判断步骤的完成状态,当前步骤为进行中,当前步骤之前的步骤为已完成,当前步骤之后的步骤为未开始。如果每个步骤没有设置 value,current 值为步骤长度则表示所有步骤已完成。如果每个步骤设置了自定义 value,则 current = 'FINISH' 表示所有状态完成", + "label": "" + }, + { + "key": "currentStatus", + "type": ["String"], + "desc": "用于控制 current 指向的步骤条的状态", + "label": "" + }, + { + "key": "layout", + "type": ["String"], + "desc": "步骤条方向,有两种:横向和纵向", + "label": "" + }, + { + "key": "readonly", + "type": ["Boolean"], + "desc": "只读状态", + "label": "" + }, + { + "key": "separator", + "type": ["String"], + "desc": "步骤条分割符", + "label": "" + }, + { + "key": "theme", + "type": ["String"], + "desc": "步骤条风格", + "label": "" + } + ], + "externalClasses": ["t-class"], + "events": [ + { + "key": "bind:change", + "desc": "当前步骤发生变化时触发", + "label": "" + } + ], + "tpl": "", + "require": { + "t-step-item": "./step-item/step-item" + }, + "path": "./steps/steps" + }, + "t-sticky": { + "key": "t-sticky", + "label": "吸顶容器", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-sticky.png", + "properties": [ + { + "key": "container", + "type": ["String"], + "desc": "函数返回容器对应的 NodesRef 节点,将对应节点指定为组件的外部容器,滚动时组件会始终保持在容器范围内,当组件即将超出容器底部时,会返回原位置。", + "label": "" + }, + { + "key": "disabled", + "type": ["Boolean"], + "desc": "是否禁用组件", + "label": "" + }, + { + "key": "offsetTop", + "type": ["String", "Number"], + "desc": "吸顶时与顶部的距离,单位`px`", + "label": "" + }, + { + "key": "zIndex", + "type": ["Number"], + "desc": "吸顶时的 z-index", + "label": "" + } + ], + "externalClasses": ["t-class"], + "events": [ + { + "key": "bind:scroll", + "desc": "滚动时触发,scrollTop: 距离顶部位置,isFixed: 是否吸顶", + "label": "" + } + ], + "tpl": "", + "path": "./sticky/sticky" + }, + "t-swipe-cell": { + "key": "t-swipe-cell", + "label": "滑动操作", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-swipecell.png", + "properties": [ + { + "key": "disabled", + "type": ["Boolean"], + "desc": "是否禁用滑动", + "label": "" + }, + { + "key": "expanded", + "type": ["String"], + "desc": "操作项是否呈现为打开态", + "label": "" + }, + { + "key": "left", + "type": ["Array"], + "desc": "左侧滑动操作项。所有行为同 `right`", + "label": "" + }, + { + "key": "right", + "type": ["Array"], + "desc": "右侧滑动操作项。有两种定义方式,一种是使用数组,二种是使用插槽。`right.text` 表示操作文本,`right.className` 表示操作项类名,`right.style` 表示操作项样式,`right.onClick` 表示点击操作项后执行的回调函数。示例:`[{ text: '删除', style: 'background-color: red', onClick: () => {} }]`", + "label": "" + } + ], + "events": [ + { + "key": "bind:click", + "desc": "操作项点击时触发(插槽写法组件不触发,业务侧自定义内容和事件)", + "label": "" + } + ], + "tpl": "删除", + "require": { + "t-cell": "./cell/cell" + }, + "path": "./swipe-cell/swipe-cell" + }, + "t-swiper": { + "key": "t-swiper", + "label": "轮播", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-swiper.png", + "properties": [ + { + "key": "animation", + "type": ["String"], + "desc": "轮播切换动画效果类型", + "label": "" + }, + { + "key": "autoplay", + "type": ["Boolean"], + "desc": "是否自动播放", + "label": "" + }, + { + "key": "current", + "type": ["Number"], + "desc": "当前轮播在哪一项(下标)", + "label": "" + }, + { + "key": "direction", + "type": ["String"], + "desc": "轮播滑动方向,包括横向滑动和纵向滑动两个方向", + "label": "" + }, + { + "key": "duration", + "type": ["Number"], + "desc": "滑动动画时长", + "label": "" + }, + { + "key": "height", + "type": ["Number"], + "desc": "当使用垂直方向滚动时的高度", + "label": "" + }, + { + "key": "interval", + "type": ["Number"], + "desc": "轮播间隔时间", + "label": "" + }, + { + "key": "loop", + "type": ["Boolean"], + "desc": "是否循环播放", + "label": "" + }, + { + "key": "navigation", + "type": ["Object"], + "desc": "导航器全部配置", + "label": "" + } + ], + "events": [ + { + "key": "bind:change", + "desc": "轮播切换时触发", + "label": "" + } + ], + "tpl": "", + "require": { + "t-swiper-item": "./swiper/swiper-item" + }, + "path": "./swiper/swiper" + }, + "t-switch": { + "key": "t-switch", + "label": "开关", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-switch.png", + "properties": [ + { + "key": "colors", + "type": ["Array"], + "desc": "自定义颜色,[打开时的颜色,关闭时的颜色]。组件默认颜色为 ['#0052d9', 'rgba(0, 0, 0, .26']。示例:[blue, gray]", + "label": "" + }, + { + "key": "customValue", + "type": ["Array"], + "desc": "开关内容,[打开时的值,关闭时的值]。默认为 [true, false]。示例:[1, 0]", + "label": "" + }, + { + "key": "disabled", + "type": ["Boolean"], + "desc": "是否禁用组件", + "label": "" + }, + { + "key": "label", + "type": ["String"], + "desc": "开关的标签", + "label": "" + }, + { + "key": "loading", + "type": ["Boolean"], + "desc": "是否处于加载中状态", + "label": "" + }, + { + "key": "size", + "type": ["String"], + "desc": "开关尺寸", + "label": "" + }, + { + "key": "value", + "type": ["String", "Number", "Boolean"], + "desc": "开关值", + "label": "" + } + ], + "events": [ + { + "key": "bind:change", + "desc": "数据发生变化时触发", + "label": "" + } + ], + "tpl": "", + "path": "./switch/switch" + }, + "t-tab-bar-item": { + "key": "t-tab-bar-item", + "label": "标签栏选项", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-tabbar.png", + "properties": [ + { + "key": "badgeProps", + "type": ["Object"], + "desc": "图标右上角提示信息", + "label": "" + }, + { + "key": "icon", + "type": ["String"], + "desc": "图标名称", + "label": "" + }, + { + "key": "subTabBar", + "type": ["Array"], + "desc": "二级菜单", + "label": "" + }, + { + "key": "value", + "type": ["String", "Number"], + "desc": "标识符", + "label": "" + } + ], + "tpl": "{{item.label}}", + "path": "./tab-bar-item/tab-bar-item" + }, + "t-tab-bar": { + "key": "t-tab-bar", + "label": "标签栏", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-tabbar.png", + "properties": [ + { + "key": "bordered", + "type": ["Boolean"], + "desc": "是否显示外边框", + "label": "" + }, + { + "key": "color", + "type": ["Array"], + "desc": "标签颜色设置。示例:[选中标签的颜色, 未选中的标签颜色]", + "label": "" + }, + { + "key": "fixed", + "type": ["Boolean"], + "desc": "是否固定在底部", + "label": "" + }, + { + "key": "safeAreaInsetBottom", + "type": ["Boolean"], + "desc": "是否为 iPhoneX 留出底部安全距离", + "label": "" + }, + { + "key": "split", + "type": ["Boolean"], + "desc": "是否需要分割线", + "label": "" + }, + { + "key": "value", + "type": ["String", "Number", "Array"], + "desc": "当前选中标签的索引", + "label": "" + } + ], + "externalClasses": ["t-class"], + "events": [ + { + "key": "bind:change", + "desc": "选中标签切换时触发", + "label": "" + } + ], + "tpl": "{{item.label}}", + "require": { + "t-tab-bar-item": "./tab-bar-item/tab-bar-item" + }, + "path": "./tab-bar/tab-bar" + }, + "t-tab-panel": { + "key": "t-tab-panel", + "label": "选项卡面板", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-tabs.png", + "properties": [ + { + "key": "destroyOnHide", + "type": ["Boolean"], + "desc": "选项卡内容隐藏时是否销毁", + "label": "" + }, + { + "key": "disabled", + "type": ["Boolean"], + "desc": "是否禁用当前选项卡", + "label": "" + }, + { + "key": "label", + "type": ["String"], + "desc": "选项卡名称", + "label": "" + }, + { + "key": "panel", + "type": ["String"], + "desc": "用于自定义选项卡面板内容", + "label": "" + }, + { + "key": "value", + "type": ["String", "Number"], + "desc": "选项卡的值,唯一标识", + "label": "" + } + ], + "tpl": "标签一内容", + "path": "./tab-panel/tab-panel" + }, + "t-tabs": { + "key": "t-tabs", + "label": "选项卡", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-tabs.png", + "properties": [ + { + "key": "animation", + "type": ["Object"], + "desc": "动画效果设置。其中 duration 表示动画时长", + "label": "" + }, + { + "key": "placement", + "type": ["String"], + "desc": "选项卡位置", + "label": "" + }, + { + "key": "showBottomLine", + "type": ["Boolean"], + "desc": "是否展示底部激活线条", + "label": "" + }, + { + "key": "stickyProps", + "type": ["Object"], + "desc": "是否支持吸顶", + "label": "" + }, + { + "key": "value", + "type": ["String", "Number"], + "desc": "激活的选项卡值", + "label": "" + } + ], + "externalClasses": ["t-class", "t-class-item", "t-class-active", "t-class-track"], + "events": [ + { + "key": "bind:change", + "desc": "激活的选项卡发生变化时触发", + "label": "" + } + ], + "tpl": "标签一内容标签二内容", + "require": { + "t-tab-panel": "./tab-panel/tab-panel" + }, + "path": "./tabs/tabs" + }, + "t-tag": { + "key": "t-tag", + "label": "标签", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-tag.png", + "properties": [ + { + "key": "closable", + "type": ["Boolean"], + "desc": "标签是否可关闭", + "label": "" + }, + { + "key": "disabled", + "type": ["Boolean"], + "desc": "标签禁用态,失效标签不能触发事件。默认风格(theme=default)才有禁用态", + "label": "" + }, + { + "key": "icon", + "type": ["String"], + "desc": "标签中的图标,可自定义图标呈现", + "label": "" + }, + { + "key": "maxWidth", + "type": ["String", "Number"], + "desc": "标签最大宽度,宽度超出后会出现省略号。示例:'50px' / 80", + "label": "" + }, + { + "key": "shape", + "type": ["String"], + "desc": "标签类型,有三种:方形、圆角方形、标记型", + "label": "" + }, + { + "key": "size", + "type": ["String"], + "desc": "标签尺寸", + "label": "" + }, + { + "key": "theme", + "type": ["String"], + "desc": "组件风格,用于描述组件不同的应用场景", + "label": "" + }, + { + "key": "variant", + "type": ["String"], + "desc": "标签风格变体", + "label": "" + } + ], + "externalClasses": ["t-class"], + "events": [ + { + "key": "bind:click", + "desc": "点击时触发", + "label": "" + }, + { + "key": "bind:close", + "desc": "如果关闭按钮存在,点击关闭按钮时触发", + "label": "" + } + ], + "tpl": "重要", + "path": "./tag/tag" + }, + "t-textarea": { + "key": "t-textarea", + "label": "文本输入框", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-textarea.png", + "properties": [ + { + "key": "adjustPosition", + "type": ["Boolean"], + "desc": "键盘弹起时,是否自动上推页面", + "label": "" + }, + { + "key": "autofocus", + "type": ["Boolean"], + "desc": "自动聚焦,拉起键盘", + "label": "" + }, + { + "key": "autosize", + "type": ["Boolean"], + "desc": "是否自动增高,值为 autosize 时,style.height 不生效", + "label": "" + }, + { + "key": "confirmHold", + "type": ["Boolean"], + "desc": "点击键盘右下角按钮时是否保持键盘不收起点", + "label": "" + }, + { + "key": "confirmType", + "type": ["String"], + "desc": "设置键盘右下角按钮的文字,仅在 type='text'时生效", + "label": "" + }, + { + "key": "disabled", + "type": ["Boolean"], + "desc": "是否禁用文本框", + "label": "" + }, + { + "key": "focus", + "type": ["Boolean"], + "desc": "自动聚焦", + "label": "" + }, + { + "key": "label", + "type": ["String"], + "desc": "左侧文本", + "label": "" + }, + { + "key": "maxcharacter", + "type": ["Number"], + "desc": "用户最多可以输入的字符个数,一个中文汉字表示两个字符长度", + "label": "" + }, + { + "key": "maxlength", + "type": ["Number"], + "desc": "用户最多可以输入的字符个数", + "label": "" + }, + { + "key": "placeholder", + "type": ["String"], + "desc": "占位符", + "label": "" + }, + { + "key": "value", + "type": ["String"], + "desc": "文本框值", + "label": "" + } + ], + "externalClasses": ["t-class", "t-class-textarea", "t-class-placeholder", "t-class-name"], + "events": [ + { + "key": "bind:blur", + "desc": "失去焦点时触发", + "label": "" + }, + { + "key": "bind:change", + "desc": "输入内容变化时触发", + "label": "" + }, + { + "key": "bind:enter", + "desc": "点击完成时触发", + "label": "" + }, + { + "key": "bind:focus", + "desc": "获得焦点时触发", + "label": "" + }, + { + "key": "bind:line-change", + "desc": "行高发生变化时触发", + "label": "" + } + ], + "tpl": "", + "path": "./textarea/textarea" + }, + "t-toast": { + "key": "t-toast", + "label": "轻提示", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-toast.png", + "properties": [ + { + "key": "direction", + "type": ["String"], + "desc": "图标排列方式", + "label": "" + }, + { + "key": "duration", + "type": ["Number"], + "desc": "弹窗显示毫秒数", + "label": "" + }, + { + "key": "icon", + "type": ["String"], + "desc": "自定义图标", + "label": "" + }, + { + "key": "message", + "type": ["String"], + "desc": "弹窗显示文字", + "label": "" + }, + { + "key": "overlayProps", + "type": ["Object"], + "desc": "遮罩层属性,透传至 Overlay", + "label": "" + }, + { + "key": "placement", + "type": ["String"], + "desc": "弹窗展示位置", + "label": "" + }, + { + "key": "preventScrollThrough", + "type": ["Boolean"], + "desc": "防止滚动穿透,即不允许点击和滚动", + "label": "" + }, + { + "key": "showOverlay", + "type": ["Boolean"], + "desc": "是否显示遮罩层", + "label": "" + }, + { + "key": "theme", + "type": ["String"], + "desc": "提示类型", + "label": "" + } + ], + "externalClasses": ["t-class"], + "tpl": "", + "path": "./toast/toast" + }, + "t-transition": { + "key": "t-transition", + "label": "动画", + "icon": "", + "properties": [ + { + "key": "appear", + "type": ["Boolean"], + "desc": "首次出现是否展示动画", + "label": "" + }, + { + "key": "customClass", + "type": ["String"], + "desc": "自定义容器类名", + "label": "" + }, + { + "key": "destoryOnClose", + "type": ["Boolean"], + "desc": "隐藏时是否销毁内容", + "label": "" + }, + { + "key": "duration", + "type": ["Number"], + "desc": "指定过渡时间", + "label": "" + }, + { + "key": "name", + "type": ["String"], + "desc": "过渡类名", + "label": "" + }, + { + "key": "visible", + "type": ["Boolean"], + "desc": "是否显示", + "label": "" + } + ], + "tpl": "", + "path": "./transition/transition" + }, + "t-upload": { + "key": "t-upload", + "label": "上传", + "icon": "https://tdesign.gtimg.com/site/miniprogram-doc/doc-upload.png", + "properties": [ + { + "key": "addContent", + "type": ["String"], + "desc": "添加按钮内容。值为空,使用默认图标渲染;值为 slot 则表示使用插槽渲染;其他值无效。", + "label": "" + }, + { + "key": "allowUploadDuplicateFile", + "type": ["Boolean"], + "desc": "是否允许重复上传相同文件名的文件", + "label": "" + }, + { + "key": "config", + "type": ["Object"], + "desc": "图片上传配置,视频上传配置,文件上传配置等,包含图片尺寸、图片来源、视频来源、视频拍摄最长时间等。更多细节查看小程序官网。[图片上传](https://developers.weixin.qq.com/miniprogram/dev/api/media/image/wx.chooseImage.html)。[视频上传](https://developers.weixin.qq.com/miniprogram/dev/api/media/video/wx.chooseVideo.html)", + "label": "" + }, + { + "key": "deleteBtn", + "type": ["String"], + "desc": "删除图标。值为空,使用默认图标渲染;值为 slot 则表示使用插槽渲染;其他值无效。", + "label": "" + }, + { + "key": "fileListDisplay", + "type": ["String"], + "desc": "用于完全自定义文件列表内容", + "label": "" + }, + { + "key": "files", + "type": ["Array"], + "desc": "已上传文件列表", + "label": "" + }, + { + "key": "gridConfig", + "type": ["Object"], + "desc": "upload组件每行上传图片列数以及图片的宽度和高度", + "label": "" + }, + { + "key": "gutter", + "type": ["Number"], + "desc": "预览窗格的 `gutter` 大小,单位 rpx", + "label": "" + }, + { + "key": "imageProps", + "type": ["Object"], + "desc": "透传 Image 组件全部属性", + "label": "" + }, + { + "key": "max", + "type": ["Number"], + "desc": "用于控制文件上传数量,值为 0 则不限制", + "label": "" + }, + { + "key": "mediaType", + "type": ["Array"], + "desc": "支持上传的文件类型,图片或视频", + "label": "" + }, + { + "key": "requestMethod", + "type": ["String"], + "desc": "自定义上传方法", + "label": "" + }, + { + "key": "sizeLimit", + "type": ["Number", "Object"], + "desc": "图片文件大小限制,单位 KB。可选单位有:`'B' | 'KB' | 'MB' | 'GB'`。示例一:`1000`。示例二:`{ size: 2, unit: 'MB', message: '图片大小不超过 {sizeLimit} MB' }`", + "label": "" + } + ], + "events": [ + { + "key": "bind:add", + "desc": "上传成功后触发,仅包含本次选择的照片;`url` 表示选定视频的临时文件路径 (本地路径)。`duration` 表示选定视频的时间长度。`size`选定视频的数据量大小。更多描述参考 wx.chooseMedia 小程序官网描述", + "label": "" + }, + { + "key": "bind:complete", + "desc": "上传成功或失败后触发", + "label": "" + }, + { + "key": "bind:fail", + "desc": "上传失败后触发", + "label": "" + }, + { + "key": "bind:remove", + "desc": "移除文件时触发", + "label": "" + }, + { + "key": "bind:select-change", + "desc": "选择文件或图片之后,上传之前,触发该事件。
`files` 表示之前已经上传完成的文件列表。
`currentSelectedFiles` 表示本次上传选中的文件列表", + "label": "" + }, + { + "key": "bind:success", + "desc": "上传成功后触发,包含所有上传的文件;`url` 表示选定视频的临时文件路径 (本地路径)。`duration` 表示选定视频的时间长度。`size`选定视频的数据量大小。更多描述参考 wx.chooseMedia 小程序官网描述", + "label": "" + } + ], + "tpl": "", + "path": "./upload/upload" + } + }, + "common": { + "properties": {}, + "events": {} + }, + "menu": [ + { + "key": "menu-basic", + "label": "基础", + "submenu": [ + { + "key": "subMenu-button", + "label": "Button 按钮", + "components": ["t-button"] + }, + { + "key": "subMenu-divider", + "label": "Divider 分割线", + "components": ["t-divider"] + }, + { + "key": "subMenu-fab", + "label": "Fab 悬浮按钮", + "components": ["t-fab"] + }, + { + "key": "subMenu-icon", + "label": "Icon 图标", + "components": ["t-icon"] + } + ] + }, + { + "key": "menu-nav", + "label": "导航", + "submenu": [ + { + "key": "subMenu-drawer", + "label": "Drawer 抽屉", + "components": ["t-drawer"] + }, + { + "key": "subMenu-indexes", + "label": "Indexes 索引", + "components": ["t-indexes"] + }, + { + "key": "subMenu-navbar", + "label": "Navbar 导航条", + "components": ["t-navbar"] + }, + { + "key": "subMenu-steps", + "label": "Steps 步骤条", + "components": ["t-steps"] + }, + { + "key": "subMenu-tabbar", + "label": "TabBar 标签栏", + "components": ["t-tab-bar"] + }, + { + "key": "subMenu-tabs", + "label": "Tabs 选项卡", + "components": ["t-tabs"] + } + ] + }, + { + "key": "menu-input", + "label": "输入", + "submenu": [ + { + "key": "subMenu-checkbox", + "label": "CheckBox 复选框", + "components": ["t-checkbox"] + }, + { + "key": "subMenu-dateTimePicker", + "label": "DateTimePicker 时间选择器", + "components": ["t-date-time-picker"] + }, + { + "key": "subMenu-input", + "label": "Input 输入框", + "components": ["t-input"] + }, + { + "key": "subMenu-picker", + "label": "Picker 选择器", + "components": ["t-picker"] + }, + { + "key": "subMenu-radio", + "label": "Radio 单选框", + "components": ["t-radio"] + }, + { + "key": "subMenu-rate", + "label": "Rate 评分", + "components": ["t-rate"] + }, + { + "key": "subMenu-search", + "label": "Search 搜索框", + "components": ["t-search"] + }, + { + "key": "subMenu-slider", + "label": "Slider 滑动选择器", + "components": ["t-slider"] + }, + { + "key": "subMenu-stepper", + "label": "Stepper 步进器", + "components": ["t-stepper"] + }, + { + "key": "subMenu-switch", + "label": "Switch 开关", + "components": ["t-switch"] + }, + { + "key": "subMenu-textarea", + "label": "Textarea 多行文本框", + "components": ["t-textarea"] + }, + { + "key": "subMenu-upload", + "label": "UpLoad 上传", + "components": ["t-upload"] + } + ] + }, + { + "key": "menu-data", + "label": "数据展示", + "submenu": [ + { + "key": "subMenu-avatar", + "label": "Avatar 头像", + "components": ["t-avatar"] + }, + { + "key": "subMenu-badge", + "label": "Badge 徽标", + "components": ["t-badge"] + }, + { + "key": "subMenu-cell", + "label": "Cell 单元格", + "components": ["t-cell"] + }, + { + "key": "subMenu-collapse", + "label": "Collapse 折叠面板", + "components": ["t-collapse"] + }, + { + "key": "subMenu-dropdown-menu", + "label": "DropdownMenu 下拉菜单", + "components": ["t-dropdown-menu"] + }, + { + "key": "subMenu-empty", + "label": "Empty 空状态", + "components": ["t-empty"] + }, + { + "key": "subMenu-footer", + "label": "Footer 页脚", + "components": ["t-footer"] + }, + { + "key": "subMenu-grid", + "label": "Grid 宫格", + "components": ["t-grid"] + }, + { + "key": "subMenu-image", + "label": "Image 图片", + "components": ["t-image"] + }, + { + "key": "subMenu-skeleton", + "label": "Skeleton 骨架屏", + "components": ["t-skeleton"] + }, + { + "key": "subMenu-sticky", + "label": "Sticky 吸顶容器", + "components": ["t-sticky"] + }, + { + "key": "subMenu-swiper", + "label": "Swiper 轮播图", + "components": ["t-swiper"] + }, + { + "key": "subMenu-tag", + "label": "Tag 标签", + "components": ["t-tag"] + } + ] + }, + { + "key": "menu-info", + "label": "消息提醒", + "submenu": [ + { + "key": "subMenu-actionsheet", + "label": "ActionSheet 动作面板", + "components": ["t-action-sheet"] + }, + { + "key": "subMenu-back-top", + "label": "BackTop 返回顶部", + "components": ["t-back-top"] + }, + { + "key": "subMenu-dialog", + "label": "Dialog 弹出框", + "components": ["t-dialog"] + }, + { + "key": "subMenu-loading", + "label": "Loading 加载", + "components": ["t-loading"] + }, + { + "key": "subMenu-message", + "label": "Message 消息通知", + "components": ["t-message"] + }, + { + "key": "subMenu-popup", + "label": "Popup 弹出层", + "components": ["t-popup"] + }, + { + "key": "subMenu-progress", + "label": "Progress 进度条", + "components": ["t-progress"] + }, + { + "key": "subMenu-pullDownRefresh", + "label": "PullDownRefresh 下拉刷新", + "components": ["t-pull-down-refresh"] + }, + { + "key": "subMenu-swipeCell", + "label": "SwipeCell 滑动操作", + "components": ["t-swipe-cell"] + }, + { + "key": "subMenu-toast", + "label": "Toast 轻提示", + "components": ["t-toast"] + } + ] + } + ] +} diff --git a/miniprogram_npm/tdesign-miniprogram/action-sheet/README.en-US.md b/miniprogram_npm/tdesign-miniprogram/action-sheet/README.en-US.md index 0c84067..c2e750e 100644 --- a/miniprogram_npm/tdesign-miniprogram/action-sheet/README.en-US.md +++ b/miniprogram_npm/tdesign-miniprogram/action-sheet/README.en-US.md @@ -1,17 +1,23 @@ :: BASE_DOC :: ## API + ### ActionSheet Props name | type | default | description | required -- | -- | -- | -- | -- -align | String | center | `0.29.0`。options:center/left | N +style | Object | - | CSS(Cascading Style Sheets) | N +custom-style | Object | - | CSS(Cascading Style Sheets),used to set style on virtual component | N +align | String | center | `0.29.0`。options: center/left | N cancel-text | String | - | \- | N count | Number | 8 | \- | N description | String | - | `0.29.0` | N -items | Array | - | required。Typescript:`Array` `interface ActionSheetItem {label: string; color?: string; disabled?: boolean }`。[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/action-sheet/type.ts) | Y +items | Array | - | required。Typescript:`Array` `interface ActionSheetItem {label: string; color?: string; disabled?: boolean;icon?: string;suffixIcon?: string; }`。[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/action-sheet/type.ts) | Y +popup-props | Object | {} | Typescript:`PopupProps`,[Popup API Documents](./popup?tab=api)。[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/action-sheet/type.ts) | N show-cancel | Boolean | true | \- | N -theme | String | list | options:list/grid | N +show-overlay | Boolean | true | \- | N +theme | String | list | options: list/grid | N +using-custom-navbar | Boolean | false | \- | N visible | Boolean | false | required | Y default-visible | Boolean | undefined | required。uncontrolled property | Y @@ -22,3 +28,25 @@ name | params | description cancel | \- | \- close | `(trigger: TriggerSource)` | [see more ts definition](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/action-sheet/type.ts)。
`type TriggerSource = 'overlay' \| 'command' \| 'select' `
selected | `(selected: ActionSheetItem \| string, index: number)` | \- +### ActionSheet External Classes + +className | Description +-- | -- +t-class | \- +t-class-cancel | \- +t-class-content | \- + +### CSS Variables + +The component provides the following CSS variables, which can be used to customize styles. +Name | Default Value | Description +-- | -- | -- +--td-action-sheet-border-color | @gray-color-1 | - +--td-action-sheet-border-radius | @radius-extra-large | - +--td-action-sheet-cancel-color | @font-gray-1 | - +--td-action-sheet-cancel-height | 96rpx | - +--td-action-sheet-color | @font-gray-1 | - +--td-action-sheet-description-color | @font-gray-3 | - +--td-action-sheet-list-item-disabled-color | @font-gray-4 | - +--td-action-sheet-list-item-height | 112rpx | - +--td-action-sheet-text-align | center | - \ No newline at end of file diff --git a/miniprogram_npm/tdesign-miniprogram/action-sheet/README.md b/miniprogram_npm/tdesign-miniprogram/action-sheet/README.md index 1ba2bab..97d176a 100644 --- a/miniprogram_npm/tdesign-miniprogram/action-sheet/README.md +++ b/miniprogram_npm/tdesign-miniprogram/action-sheet/README.md @@ -26,6 +26,12 @@ isComponent: true ## 代码演示 + 在开发者工具中预览效果 + +
+

Tips: 请确保开发者工具为打开状态。导入开发者工具后,依次执行:npm i > 构建npm包 > 勾选 "将JS编译成ES5"

+
+ ### 组件类型 列表型动作面板 @@ -83,20 +89,25 @@ handler.close(); ## API + ### ActionSheet Props -名称 | 类型 | 默认值 | 说明 | 必传 +名称 | 类型 | 默认值 | 描述 | 必传 -- | -- | -- | -- | -- +style | Object | - | 样式 | N +custom-style | Object | - | 样式,一般用于开启虚拟化组件节点场景 | N align | String | center | `0.29.0`。水平对齐方式。可选项:center/left | N cancel-text | String | - | 设置取消按钮的文本 | N count | Number | 8 | 设置每页展示菜单的数量,仅当 type=grid 时有效 | N description | String | - | `0.29.0`。动作面板描述文字 | N -items | Array | - | 必需。菜单项。TS 类型:`Array` `interface ActionSheetItem {label: string; color?: string; disabled?: boolean }`。[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/action-sheet/type.ts) | Y +items | Array | - | 必需。菜单项。TS 类型:`Array` `interface ActionSheetItem {label: string; color?: string; disabled?: boolean;icon?: string;suffixIcon?: string; }`。[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/action-sheet/type.ts) | Y +popup-props | Object | {} | popupProps透传。TS 类型:`PopupProps`,[Popup API Documents](./popup?tab=api)。[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/action-sheet/type.ts) | N show-cancel | Boolean | true | 是否显示取消按钮 | N +show-overlay | Boolean | true | 是否显示遮罩层 | N theme | String | list | 展示类型,列表和表格形式展示。可选项:list/grid | N +using-custom-navbar | Boolean | false | 是否使用了自定义导航栏 | N visible | Boolean | false | 必需。显示与隐藏 | Y default-visible | Boolean | undefined | 必需。显示与隐藏。非受控属性 | Y -external-classes | Array | - | 组件类名,用于设置组件外层元素类名。`['t-class', 't-class-content', 't-class-cancel']` | N ### ActionSheet Events @@ -105,3 +116,25 @@ external-classes | Array | - | 组件类名,用于设置组件外层元素类 cancel | \- | 点击取消按钮时触发 close | `(trigger: TriggerSource)` | 关闭时触发。[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/action-sheet/type.ts)。
`type TriggerSource = 'overlay' \| 'command' \| 'select' `
selected | `(selected: ActionSheetItem \| string, index: number)` | 选择菜单项时触发 +### ActionSheet External Classes + +类名 | 描述 +-- | -- +t-class | 根节点样式类 +t-class-cancel | 取消样式类 +t-class-content | 内容样式类 + +### CSS Variables + +组件提供了下列 CSS 变量,可用于自定义样式。 +名称 | 默认值 | 描述 +-- | -- | -- +--td-action-sheet-border-color | @gray-color-1 | - +--td-action-sheet-border-radius | @radius-extra-large | - +--td-action-sheet-cancel-color | @font-gray-1 | - +--td-action-sheet-cancel-height | 96rpx | - +--td-action-sheet-color | @font-gray-1 | - +--td-action-sheet-description-color | @font-gray-3 | - +--td-action-sheet-list-item-disabled-color | @font-gray-4 | - +--td-action-sheet-list-item-height | 112rpx | - +--td-action-sheet-text-align | center | - \ No newline at end of file diff --git a/miniprogram_npm/tdesign-miniprogram/action-sheet/action-sheet.d.ts b/miniprogram_npm/tdesign-miniprogram/action-sheet/action-sheet.d.ts index dd4d4bf..924dfe5 100644 --- a/miniprogram_npm/tdesign-miniprogram/action-sheet/action-sheet.d.ts +++ b/miniprogram_npm/tdesign-miniprogram/action-sheet/action-sheet.d.ts @@ -1,6 +1,7 @@ import { SuperComponent } from '../common/src/index'; export default class ActionSheet extends SuperComponent { static show: (options: import("./show").ActionSheetShowOption) => WechatMiniprogram.Component.TrivialInstance; + behaviors: string[]; externalClasses: string[]; properties: { align?: { @@ -22,22 +23,37 @@ export default class ActionSheet extends SuperComponent { items: { type: ArrayConstructor; value?: (string | import("./type").ActionSheetItem)[]; + required?: boolean; + }; + popupProps?: { + type: ObjectConstructor; + value?: import("../popup").TdPopupProps; }; showCancel?: { type: BooleanConstructor; value?: boolean; }; + showOverlay?: { + type: BooleanConstructor; + value?: boolean; + }; theme?: { type: StringConstructor; value?: "list" | "grid"; }; + usingCustomNavbar?: { + type: BooleanConstructor; + value?: boolean; + }; visible: { type: BooleanConstructor; value?: boolean; + required?: boolean; }; defaultVisible: { type: BooleanConstructor; value?: boolean; + required?: boolean; }; }; data: { @@ -45,6 +61,8 @@ export default class ActionSheet extends SuperComponent { classPrefix: string; gridThemeItems: any[]; currentSwiperIndex: number; + defaultPopUpProps: {}; + defaultPopUpzIndex: number; }; controlledProps: { key: string; diff --git a/miniprogram_npm/tdesign-miniprogram/action-sheet/action-sheet.js b/miniprogram_npm/tdesign-miniprogram/action-sheet/action-sheet.js index aa8ba4d..c20b865 100644 --- a/miniprogram_npm/tdesign-miniprogram/action-sheet/action-sheet.js +++ b/miniprogram_npm/tdesign-miniprogram/action-sheet/action-sheet.js @@ -9,11 +9,13 @@ import { SuperComponent, wxComponent } from '../common/src/index'; import config from '../common/config'; import { ActionSheetTheme, show } from './show'; import props from './props'; +import useCustomNavbar from '../mixins/using-custom-navbar'; const { prefix } = config; const name = `${prefix}-action-sheet`; let ActionSheet = class ActionSheet extends SuperComponent { constructor() { super(...arguments); + this.behaviors = [useCustomNavbar]; this.externalClasses = [`${prefix}-class`, `${prefix}-class-content`, `${prefix}-class-cancel`]; this.properties = Object.assign({}, props); this.data = { @@ -21,6 +23,8 @@ let ActionSheet = class ActionSheet extends SuperComponent { classPrefix: name, gridThemeItems: [], currentSwiperIndex: 0, + defaultPopUpProps: {}, + defaultPopUpzIndex: 11500, }; this.controlledProps = [ { @@ -73,12 +77,18 @@ let ActionSheet = class ActionSheet extends SuperComponent { const realIndex = isSwiperMode ? index + currentSwiperIndex * count : index; if (item) { this.triggerEvent('selected', { selected: item, index: realIndex }); - this.trigger('close', { trigger: 'select' }); - this._trigger('visible-change', { visible: false }); + if (!item.disabled) { + this.triggerEvent('close', { trigger: 'select' }); + this._trigger('visible-change', { visible: false }); + } } }, onCancel() { this.triggerEvent('cancel'); + if (this.autoClose) { + this.setData({ visible: false }); + this.autoClose = false; + } }, }; } diff --git a/miniprogram_npm/tdesign-miniprogram/action-sheet/action-sheet.json b/miniprogram_npm/tdesign-miniprogram/action-sheet/action-sheet.json index c1eb33e..70f0a29 100644 --- a/miniprogram_npm/tdesign-miniprogram/action-sheet/action-sheet.json +++ b/miniprogram_npm/tdesign-miniprogram/action-sheet/action-sheet.json @@ -1,10 +1,10 @@ { "component": true, + "styleIsolation": "apply-shared", "usingComponents": { "t-icon": "../icon/icon", "t-popup": "../popup/popup", "t-grid": "../grid/grid", - "t-grid-item": "../grid-item/grid-item", - "t-swiper-nav": "../swiper-nav/swiper-nav" + "t-grid-item": "../grid-item/grid-item" } } diff --git a/miniprogram_npm/tdesign-miniprogram/action-sheet/action-sheet.wxml b/miniprogram_npm/tdesign-miniprogram/action-sheet/action-sheet.wxml index bf8d757..3928217 100644 --- a/miniprogram_npm/tdesign-miniprogram/action-sheet/action-sheet.wxml +++ b/miniprogram_npm/tdesign-miniprogram/action-sheet/action-sheet.wxml @@ -4,7 +4,15 @@ - + - + - {{ cancelText }} + {{ cancelText || '取消' }} diff --git a/miniprogram_npm/tdesign-miniprogram/action-sheet/action-sheet.wxss b/miniprogram_npm/tdesign-miniprogram/action-sheet/action-sheet.wxss index e9ad6bb..c647d5a 100644 --- a/miniprogram_npm/tdesign-miniprogram/action-sheet/action-sheet.wxss +++ b/miniprogram_npm/tdesign-miniprogram/action-sheet/action-sheet.wxss @@ -26,7 +26,7 @@ transform: scale(1.5); } .t-action-sheet__content { - color: var(--td-action-sheet-color, var(--td-font-gray-1, rgba(0, 0, 0, 0.9))); + color: var(--td-action-sheet-color, var(--td-text-color-primary, var(--td-font-gray-1, rgba(0, 0, 0, 0.9)))); border-top-left-radius: var(--td-action-sheet-border-radius, var(--td-radius-extra-large, 24rpx)); border-top-right-radius: var(--td-action-sheet-border-radius, var(--td-radius-extra-large, 24rpx)); background-color: var(--td-bg-color-container, var(--td-font-white-1, #ffffff)); @@ -45,7 +45,7 @@ padding-bottom: 48rpx; } .t-action-sheet__description { - color: var(--td-action-sheet-description-color, var(--td-font-gray-3, rgba(0, 0, 0, 0.4))); + color: var(--td-action-sheet-description-color, var(--td-text-color-placeholder, var(--td-font-gray-3, rgba(0, 0, 0, 0.4)))); line-height: 44rpx; font-size: 28rpx; text-align: var(--td-action-sheet-text-align, center); @@ -63,7 +63,7 @@ bottom: 0; left: unset; right: unset; - background-color: var(--td-action-sheet-border-color, var(--td-gray-color-1, #f3f3f3)); + background-color: var(--td-action-sheet-border-color, var(--td-border-level-1-color, var(--td-gray-color-3, #e7e7e7))); } .t-action-sheet__description::after { height: 1px; @@ -93,7 +93,7 @@ bottom: 0; left: unset; right: unset; - background-color: var(--td-action-sheet-border-color, var(--td-gray-color-1, #f3f3f3)); + background-color: var(--td-action-sheet-border-color, var(--td-border-level-1-color, var(--td-gray-color-3, #e7e7e7))); } .t-action-sheet__list-item::after { height: 1px; @@ -111,7 +111,7 @@ left: 32rpx; } .t-action-sheet__list-item--disabled { - color: var(--td-action-sheet-list-item-disabled-color, var(--td-font-gray-4, rgba(0, 0, 0, 0.26))); + color: var(--td-action-sheet-list-item-disabled-color, var(--td-text-color-disabled, var(--td-font-gray-4, rgba(0, 0, 0, 0.26)))); } .t-action-sheet__list-item-text { font-size: var(--td-font-size-m, 32rpx); @@ -123,6 +123,9 @@ .t-action-sheet__list-item-icon { margin-right: 16rpx; } +.t-action-sheet__list-item-icon--suffix { + margin-left: auto; +} .t-action-sheet__swiper-wrap { margin-top: 8rpx; position: relative; @@ -132,16 +135,17 @@ } .t-action-sheet__gap-list { height: 16rpx; - background-color: var(--td-action-sheet-border-color, var(--td-gray-color-1, #f3f3f3)); + background-color: var(--td-action-sheet-gap-color, var(--td-bg-color-page, var(--td-gray-color-1, #f3f3f3))); } .t-action-sheet__gap-grid { height: 1rpx; - background-color: var(--td-action-sheet-border-color, var(--td-gray-color-1, #f3f3f3)); + background-color: var(--td-action-sheet-border-color, var(--td-border-level-1-color, var(--td-gray-color-3, #e7e7e7))); } .t-action-sheet__cancel { display: flex; align-items: center; justify-content: center; + color: var(--td-action-sheet-cancel-color, var(--td-text-color-primary, var(--td-font-gray-1, rgba(0, 0, 0, 0.9)))); height: var(--td-action-sheet-cancel-height, 96rpx); } .t-action-sheet__dots { @@ -163,7 +167,3 @@ .t-action-sheet__dots-item.t-is-active { background-color: #0052d9; } -.t-action-sheet__safe { - padding-bottom: constant(safe-area-inset-bottom); - padding-bottom: env(safe-area-inset-bottom); -} diff --git a/miniprogram_npm/tdesign-miniprogram/action-sheet/index.d.ts b/miniprogram_npm/tdesign-miniprogram/action-sheet/index.d.ts index de46874..5c41389 100644 --- a/miniprogram_npm/tdesign-miniprogram/action-sheet/index.d.ts +++ b/miniprogram_npm/tdesign-miniprogram/action-sheet/index.d.ts @@ -1,3 +1,8 @@ -import ActionSheet from './action-sheet'; -export * from './show'; -export default ActionSheet; +/// +import { ActionSheetItem, ActionSheetTheme, ActionSheetShowOption } from './show'; +export { ActionSheetItem, ActionSheetTheme, ActionSheetShowOption }; +declare const _default: { + show(options: ActionSheetShowOption): WechatMiniprogram.Component.TrivialInstance; + close(options: ActionSheetShowOption): void; +}; +export default _default; diff --git a/miniprogram_npm/tdesign-miniprogram/action-sheet/index.js b/miniprogram_npm/tdesign-miniprogram/action-sheet/index.js index de46874..7fcdd3c 100644 --- a/miniprogram_npm/tdesign-miniprogram/action-sheet/index.js +++ b/miniprogram_npm/tdesign-miniprogram/action-sheet/index.js @@ -1,3 +1,10 @@ -import ActionSheet from './action-sheet'; -export * from './show'; -export default ActionSheet; +import { show, close, ActionSheetTheme } from './show'; +export { ActionSheetTheme }; +export default { + show(options) { + return show(options); + }, + close(options) { + return close(options); + }, +}; diff --git a/miniprogram_npm/tdesign-miniprogram/action-sheet/props.js b/miniprogram_npm/tdesign-miniprogram/action-sheet/props.js index c89fa9e..5a86e41 100644 --- a/miniprogram_npm/tdesign-miniprogram/action-sheet/props.js +++ b/miniprogram_npm/tdesign-miniprogram/action-sheet/props.js @@ -5,7 +5,7 @@ const props = { }, cancelText: { type: String, - value: '取消', + value: '', }, count: { type: Number, @@ -17,22 +17,37 @@ const props = { }, items: { type: Array, + required: true, + }, + popupProps: { + type: Object, + value: {}, }, showCancel: { type: Boolean, value: true, }, + showOverlay: { + type: Boolean, + value: true, + }, theme: { type: String, value: 'list', }, + usingCustomNavbar: { + type: Boolean, + value: false, + }, visible: { type: Boolean, value: null, + required: true, }, defaultVisible: { type: Boolean, value: false, + required: true, }, }; export default props; diff --git a/miniprogram_npm/tdesign-miniprogram/action-sheet/show.d.ts b/miniprogram_npm/tdesign-miniprogram/action-sheet/show.d.ts index e0d8eae..824502a 100644 --- a/miniprogram_npm/tdesign-miniprogram/action-sheet/show.d.ts +++ b/miniprogram_npm/tdesign-miniprogram/action-sheet/show.d.ts @@ -12,13 +12,15 @@ export declare enum ActionSheetTheme { Grid = "grid" } interface ActionSheetProps { - visible: boolean; - items: Array; - defaultVisible?: boolean; + align: 'center' | 'left'; cancelText?: string; count?: number; + description: string; + items: Array; showCancel?: boolean; theme?: ActionSheetTheme; + visible: boolean; + defaultVisible?: boolean; } export interface ActionSheetShowOption extends Omit { context?: Context; diff --git a/miniprogram_npm/tdesign-miniprogram/action-sheet/template/grid.wxml b/miniprogram_npm/tdesign-miniprogram/action-sheet/template/grid.wxml index bdc595e..8f6f20d 100644 --- a/miniprogram_npm/tdesign-miniprogram/action-sheet/template/grid.wxml +++ b/miniprogram_npm/tdesign-miniprogram/action-sheet/template/grid.wxml @@ -8,9 +8,10 @@ wx:key="index" bind:tap="onSelect" data-index="{{index}}" - icon="{{item.icon}}" - text="{{item.label}}" - image="{{item.image}}" + icon="{{ { name: item.icon, color: item.color } }}" + text="{{item.label || ''}}" + image="{{item.image || ''}}" + style="--td-grid-item-text-color: {{item.color}}" > @@ -27,9 +28,10 @@ wx:key="index" data-index="{{index}}" bind:tap="onSelect" - icon="{{item.icon}}" - text="{{item.label}}" - image="{{item.image}}" + icon="{{ { name: item.icon, color: item.color } }}" + text="{{item.label || ''}}" + image="{{item.image || ''}}" + style="--td-grid-item-text-color: {{item.color}}" > diff --git a/miniprogram_npm/tdesign-miniprogram/action-sheet/template/list.wxml b/miniprogram_npm/tdesign-miniprogram/action-sheet/template/list.wxml index 37e5dcf..04f2e34 100644 --- a/miniprogram_npm/tdesign-miniprogram/action-sheet/template/list.wxml +++ b/miniprogram_npm/tdesign-miniprogram/action-sheet/template/list.wxml @@ -10,5 +10,11 @@ > {{item.label || item}} + diff --git a/miniprogram_npm/tdesign-miniprogram/action-sheet/type.d.ts b/miniprogram_npm/tdesign-miniprogram/action-sheet/type.d.ts index f77a8fb..3fb8bdc 100644 --- a/miniprogram_npm/tdesign-miniprogram/action-sheet/type.d.ts +++ b/miniprogram_npm/tdesign-miniprogram/action-sheet/type.d.ts @@ -1,3 +1,4 @@ +import { PopupProps } from '../popup/index'; export interface TdActionSheetProps { align?: { type: StringConstructor; @@ -18,26 +19,43 @@ export interface TdActionSheetProps { items: { type: ArrayConstructor; value?: Array; + required?: boolean; + }; + popupProps?: { + type: ObjectConstructor; + value?: PopupProps; }; showCancel?: { type: BooleanConstructor; value?: boolean; }; + showOverlay?: { + type: BooleanConstructor; + value?: boolean; + }; theme?: { type: StringConstructor; value?: 'list' | 'grid'; }; + usingCustomNavbar?: { + type: BooleanConstructor; + value?: boolean; + }; visible: { type: BooleanConstructor; value?: boolean; + required?: boolean; }; defaultVisible: { type: BooleanConstructor; value?: boolean; + required?: boolean; }; } export interface ActionSheetItem { label: string; color?: string; disabled?: boolean; + icon?: string; + suffixIcon?: string; } diff --git a/miniprogram_npm/tdesign-miniprogram/avatar-group/avatar-group.d.ts b/miniprogram_npm/tdesign-miniprogram/avatar-group/avatar-group.d.ts index c9f9ba6..e131442 100644 --- a/miniprogram_npm/tdesign-miniprogram/avatar-group/avatar-group.d.ts +++ b/miniprogram_npm/tdesign-miniprogram/avatar-group/avatar-group.d.ts @@ -23,6 +23,6 @@ export default class AvatarGroup extends SuperComponent { methods: { setClass(): void; handleMax(): void; - handleChildCascading(): void; + onCollapsedItemClick(e: WechatMiniprogram.CustomEvent): void; }; } diff --git a/miniprogram_npm/tdesign-miniprogram/avatar-group/avatar-group.js b/miniprogram_npm/tdesign-miniprogram/avatar-group/avatar-group.js index b1d4563..f85c574 100644 --- a/miniprogram_npm/tdesign-miniprogram/avatar-group/avatar-group.js +++ b/miniprogram_npm/tdesign-miniprogram/avatar-group/avatar-group.js @@ -38,7 +38,6 @@ let AvatarGroup = class AvatarGroup extends SuperComponent { length: this.$children.length, }); this.handleMax(); - this.handleChildCascading(); }, }; this.observers = { @@ -53,7 +52,8 @@ let AvatarGroup = class AvatarGroup extends SuperComponent { const classList = [ name, `${prefix}-class`, - `${name}-offset-${direction}-${size.indexOf('px') > -1 ? 'medium' : size}`, + `${name}-offset-${direction}`, + `${name}-offset-${direction}-${size.indexOf('px') > -1 ? 'medium' : size || 'medium'}`, ]; this.setData({ className: classList.join(' '), @@ -69,13 +69,8 @@ let AvatarGroup = class AvatarGroup extends SuperComponent { child.hide(); }); }, - handleChildCascading() { - if (this.properties.cascading === 'right-up') - return; - const defaultZIndex = 100; - this.$children.forEach((child, index) => { - child.updateCascading(defaultZIndex - index * 10); - }); + onCollapsedItemClick(e) { + this.triggerEvent('collapsed-item-click', e.detail); }, }; } diff --git a/miniprogram_npm/tdesign-miniprogram/avatar-group/avatar-group.json b/miniprogram_npm/tdesign-miniprogram/avatar-group/avatar-group.json index 9f58d25..9b5763d 100644 --- a/miniprogram_npm/tdesign-miniprogram/avatar-group/avatar-group.json +++ b/miniprogram_npm/tdesign-miniprogram/avatar-group/avatar-group.json @@ -1,5 +1,6 @@ { "component": true, + "styleIsolation": "shared", "usingComponents": { "t-avatar": "../avatar/avatar" } diff --git a/miniprogram_npm/tdesign-miniprogram/avatar-group/avatar-group.wxml b/miniprogram_npm/tdesign-miniprogram/avatar-group/avatar-group.wxml index 26929f2..1e2f6cd 100644 --- a/miniprogram_npm/tdesign-miniprogram/avatar-group/avatar-group.wxml +++ b/miniprogram_npm/tdesign-miniprogram/avatar-group/avatar-group.wxml @@ -7,11 +7,12 @@ - + {{collapseAvatar}} 在开发者工具中预览效果 + +
+

Tips: 请确保开发者工具为打开状态。导入开发者工具后,依次执行:npm i > 构建npm包 > 勾选 "将JS编译成ES5"

+
+ ### 头像类型 图片头像 @@ -55,33 +61,91 @@ isComponent: true {{ size }} ## API + ### Avatar Props -名称 | 类型 | 默认值 | 说明 | 必传 +名称 | 类型 | 默认值 | 描述 | 必传 -- | -- | -- | -- | -- +style | Object | - | 样式 | N +custom-style | Object | - | 样式,一般用于开启虚拟化组件节点场景 | N alt | String | - | 头像替换文本,仅当图片加载失败时有效 | N badge-props | Object | - | 头像右上角提示信息,继承 Badge 组件的全部特性。如:小红点,或者数字。TS 类型:`BadgeProps`,[Badge API Documents](./badge?tab=api)。[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/avatar/type.ts) | N bordered | Boolean | false | 已废弃。是否显示外边框 | N -external-classes | Array | - | 组件类名,用于设置组件外层元素类名。`['t-class', 't-class-image', 't-class-icon', 't-class-alt', 't-class-content']` | N hide-on-load-failed | Boolean | false | 加载失败时隐藏图片 | N icon | String / Object | - | 图标。值为字符串表示图标名称,值为 `Object` 类型,表示透传至 `icon`。 | N image | String | - | 图片地址 | N -image-props | Object | - | 透传至 Image 组件 | N -shape | String | circle | 形状。可选项:circle/round。TS 类型:`ShapeEnum ` `type ShapeEnum = 'circle' \| 'round'`。[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/avatar/type.ts) | N -size | String | medium | 尺寸,示例值:small/medium/large/24px/38px 等 | N +image-props | Object | - | 透传至 Image 组件。TS 类型:`ImageProps`,[Image API Documents](./image?tab=api)。[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/avatar/type.ts) | N +shape | String | - | 形状。优先级高于 AvatarGroup.shape 。Avatar 单独存在时,默认值为 circle。如果父组件 AvatarGroup 存在,默认值便由 AvatarGroup.shape 决定。可选项:circle/round。TS 类型:`ShapeEnum`。[通用类型定义](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N +size | String | - | 尺寸,示例值:small/medium/large/24px/38px 等。优先级高于 AvatarGroup.size 。Avatar 单独存在时,默认值为 medium。如果父组件 AvatarGroup 存在,默认值便由 AvatarGroup.size 决定 | N ### Avatar Events 名称 | 参数 | 描述 -- | -- | -- -error | \- | 图片加载失败时触发 +error | - | 图片加载失败时触发 + +### Avatar External Classes + +类名 | 描述 +-- | -- +t-class | 根节点样式类 +t-class-alt | 替代文本样式类 +t-class-content | 内容样式类 +t-class-icon | 图标样式类 +t-class-image | 图片样式类 + ### AvatarGroup Props -名称 | 类型 | 默认值 | 说明 | 必传 +名称 | 类型 | 默认值 | 描述 | 必传 -- | -- | -- | -- | -- +style | Object | - | 样式 | N +custom-style | Object | - | 样式,一般用于开启虚拟化组件节点场景 | N cascading | String | 'left-up' | 图片之间的层叠关系,可选值:左侧图片在上和右侧图片在上。可选项:left-up/right-up。TS 类型:`CascadingValue` `type CascadingValue = 'left-up' \| 'right-up'`。[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/avatar-group/type.ts) | N -collapse-avatar | String / Slot | - | 头像数量超出时,会出现一个头像折叠元素。该元素内容可自定义。默认为 `+N`。示例:`+5`,`...`, `更多` | N -external-classes | Array | - | 组件类名,用于设置组件外层元素类名。`['t-class', 't-class-image', 't-class-content']` | N +collapse-avatar | String / Slot | - | 头像数量超出时,会出现一个头像折叠元素。该元素内容可自定义。默认为 `+N`。示例:`+5`,`...`, `更多`。[通用类型定义](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N max | Number | - | 能够同时显示的最多头像数量 | N -size | String | medium | 尺寸,示例值:small/medium/large/24px/38px 等。优先级低于 Avatar.size | N +shape | String | - | 形状。优先级低于 Avatar.shape。可选项:circle/round。TS 类型:`ShapeEnum`。[通用类型定义](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N +size | String | - | 尺寸,示例值:small/medium/large/24px/38px 等。优先级低于 Avatar.size | N + +### AvatarGroup Events + +名称 | 参数 | 描述 +-- | -- | -- +collapsed-item-click | - | 点击头像折叠元素触发 + +### AvatarGroup External Classes + +类名 | 描述 +-- | -- +t-class | 根节点样式类 +t-class-content | 内容样式类 +t-class-image | 图片样式类 + +### CSS Variables + +组件提供了下列 CSS 变量,可用于自定义样式。 +名称 | 默认值 | 描述 +-- | -- | -- +--td-avatar-group-init-z-index | @avatar-group-init-zIndex) - @i | - +--td-avatar-group-line-spacing | 4rpx | - +--td-avatar-group-margin-left-large | -16rpx | - +--td-avatar-group-margin-left-medium | -16rpx | - +--td-avatar-group-margin-left-small | -16rpx | - +--td-avatar-bg-color | @brand-color-light-active | - +--td-avatar-border-color | #fff | - +--td-avatar-border-width-large | 6rpx | - +--td-avatar-border-width-medium | 4rpx | - +--td-avatar-border-width-small | 2rpx | - +--td-avatar-circle-border-radius | @radius-circle | - +--td-avatar-content-color | @brand-color | - +--td-avatar-icon-large-font-size | 64rpx | - +--td-avatar-icon-medium-font-size | 48rpx | - +--td-avatar-icon-small-font-size | 40rpx | - +--td-avatar-large-width | 128rpx | - +--td-avatar-margin-left | 0 | - +--td-avatar-medium-width | 96rpx | - +--td-avatar-round-border-radius | @radius-default | - +--td-avatar-small-width | 80rpx | - +--td-avatar-text-large-font-size | @font-size-xl | - +--td-avatar-text-medium-font-size | @font-size-m | - +--td-avatar-text-small-font-size | @font-size-base | - \ No newline at end of file diff --git a/miniprogram_npm/tdesign-miniprogram/avatar/avatar.d.ts b/miniprogram_npm/tdesign-miniprogram/avatar/avatar.d.ts index f25f03d..b4536dc 100644 --- a/miniprogram_npm/tdesign-miniprogram/avatar/avatar.d.ts +++ b/miniprogram_npm/tdesign-miniprogram/avatar/avatar.d.ts @@ -9,7 +9,6 @@ export default class Avatar extends SuperComponent { classPrefix: string; isShow: boolean; zIndex: number; - bordered: boolean; }; relations: RelationsOptions; observers: { @@ -17,7 +16,6 @@ export default class Avatar extends SuperComponent { }; methods: { hide(): void; - updateCascading(zIndex: any): void; onLoadError(e: WechatMiniprogram.CustomEvent): void; }; } diff --git a/miniprogram_npm/tdesign-miniprogram/avatar/avatar.js b/miniprogram_npm/tdesign-miniprogram/avatar/avatar.js index 29f7288..9f5c7c1 100644 --- a/miniprogram_npm/tdesign-miniprogram/avatar/avatar.js +++ b/miniprogram_npm/tdesign-miniprogram/avatar/avatar.js @@ -15,7 +15,6 @@ let Avatar = class Avatar extends SuperComponent { super(...arguments); this.options = { multipleSlots: true, - styleIsolation: 'apply-shared', }; this.externalClasses = [ `${prefix}-class`, @@ -30,16 +29,15 @@ let Avatar = class Avatar extends SuperComponent { classPrefix: name, isShow: true, zIndex: 0, - bordered: false, }; this.relations = { '../avatar-group/avatar-group': { type: 'ancestor', linked(parent) { - var _a; this.parent = parent; this.setData({ - size: (_a = this.data.size) !== null && _a !== void 0 ? _a : parent.data.size, + shape: this.data.shape || parent.data.shape || 'circle', + size: this.data.size || parent.data.size, bordered: true, }); }, @@ -57,9 +55,6 @@ let Avatar = class Avatar extends SuperComponent { isShow: false, }); }, - updateCascading(zIndex) { - this.setData({ zIndex }); - }, onLoadError(e) { if (this.properties.hideOnLoadFailed) { this.setData({ diff --git a/miniprogram_npm/tdesign-miniprogram/avatar/avatar.json b/miniprogram_npm/tdesign-miniprogram/avatar/avatar.json index 4461d94..15361c2 100644 --- a/miniprogram_npm/tdesign-miniprogram/avatar/avatar.json +++ b/miniprogram_npm/tdesign-miniprogram/avatar/avatar.json @@ -1,5 +1,6 @@ { "component": true, + "styleIsolation": "shared", "usingComponents": { "t-icon": "../icon/icon", "t-badge": "../badge/badge", diff --git a/miniprogram_npm/tdesign-miniprogram/avatar/avatar.wxml b/miniprogram_npm/tdesign-miniprogram/avatar/avatar.wxml index e908f5a..3f6e679 100644 --- a/miniprogram_npm/tdesign-miniprogram/avatar/avatar.wxml +++ b/miniprogram_npm/tdesign-miniprogram/avatar/avatar.wxml @@ -4,7 +4,7 @@ diff --git a/miniprogram_npm/tdesign-miniprogram/avatar/avatar.wxs b/miniprogram_npm/tdesign-miniprogram/avatar/avatar.wxs index d67e5d8..50476e4 100644 --- a/miniprogram_npm/tdesign-miniprogram/avatar/avatar.wxs +++ b/miniprogram_npm/tdesign-miniprogram/avatar/avatar.wxs @@ -18,9 +18,7 @@ module.exports = { } }, - getStyles: function (isShow, zIndex) { - var displayStyle = isShow ? '' : 'display: none;'; - var zIndexStyle = zIndex ? 'z-index:' + zIndex + ';' : ''; - return displayStyle + zIndexStyle; + getStyles: function (isShow) { + return isShow ? '' : 'display: none;'; }, }; diff --git a/miniprogram_npm/tdesign-miniprogram/avatar/avatar.wxss b/miniprogram_npm/tdesign-miniprogram/avatar/avatar.wxss index b1c3697..5d1b506 100644 --- a/miniprogram_npm/tdesign-miniprogram/avatar/avatar.wxss +++ b/miniprogram_npm/tdesign-miniprogram/avatar/avatar.wxss @@ -42,7 +42,7 @@ .t-avatar--large { width: var(--td-avatar-large-width, 128rpx); height: var(--td-avatar-large-width, 128rpx); - font-size: var(--td-avatar-text-large-font-size, 16px); + font-size: var(--td-avatar-text-large-font-size, var(--td-font-size-xl, 40rpx)); } .t-avatar--large .t-avatar__icon { font-size: var(--td-avatar-icon-large-font-size, 64rpx); @@ -50,7 +50,7 @@ .t-avatar--medium { width: var(--td-avatar-medium-width, 96rpx); height: var(--td-avatar-medium-width, 96rpx); - font-size: var(--td-avatar-text-medium-font-size, var(--td-font-size-base, 28rpx)); + font-size: var(--td-avatar-text-medium-font-size, var(--td-font-size-m, 32rpx)); } .t-avatar--medium .t-avatar__icon { font-size: var(--td-avatar-icon-medium-font-size, 48rpx); @@ -58,7 +58,7 @@ .t-avatar--small { width: var(--td-avatar-small-width, 80rpx); height: var(--td-avatar-small-width, 80rpx); - font-size: var(--td-avatar-text-small-font-size, var(--td-font-size-s, 24rpx)); + font-size: var(--td-avatar-text-small-font-size, var(--td-font-size-base, 28rpx)); } .t-avatar--small .t-avatar__icon { font-size: var(--td-avatar-icon-small-font-size, 40rpx); @@ -94,11 +94,11 @@ border-style: solid; } .t-avatar--border-small { - border-width: var(--td-avatar-border-width-small, 4rpx); + border-width: var(--td-avatar-border-width-small, 2rpx); } .t-avatar--border-medium { - border-width: var(--td-avatar-border-width-medium, 6rpx); + border-width: var(--td-avatar-border-width-medium, 4rpx); } .t-avatar--border-large { - border-width: var(--td-avatar-border-width-large, 8rpx); + border-width: var(--td-avatar-border-width-large, 6rpx); } diff --git a/miniprogram_npm/tdesign-miniprogram/avatar/props.js b/miniprogram_npm/tdesign-miniprogram/avatar/props.js index bd83025..9aba4c5 100644 --- a/miniprogram_npm/tdesign-miniprogram/avatar/props.js +++ b/miniprogram_npm/tdesign-miniprogram/avatar/props.js @@ -10,9 +10,6 @@ const props = { type: Boolean, value: false, }, - externalClasses: { - type: Array, - }, hideOnLoadFailed: { type: Boolean, value: false, @@ -29,11 +26,10 @@ const props = { }, shape: { type: String, - value: 'circle', }, size: { type: String, - value: 'medium', + value: '', }, }; export default props; diff --git a/miniprogram_npm/tdesign-miniprogram/avatar/type.d.ts b/miniprogram_npm/tdesign-miniprogram/avatar/type.d.ts index 07dfe75..79cac9d 100644 --- a/miniprogram_npm/tdesign-miniprogram/avatar/type.d.ts +++ b/miniprogram_npm/tdesign-miniprogram/avatar/type.d.ts @@ -1,4 +1,6 @@ import { BadgeProps } from '../badge/index'; +import { ImageProps } from '../image/index'; +import { ShapeEnum } from '../common/common'; export interface TdAvatarProps { alt?: { type: StringConstructor; @@ -12,14 +14,6 @@ export interface TdAvatarProps { type: BooleanConstructor; value?: boolean; }; - style?: { - type: StringConstructor; - value?: string; - }; - externalClasses?: { - type: ArrayConstructor; - value?: ['t-class', 't-class-image', 't-class-icon', 't-class-alt', 't-class-content']; - }; hideOnLoadFailed?: { type: BooleanConstructor; value?: boolean; @@ -34,7 +28,7 @@ export interface TdAvatarProps { }; imageProps?: { type: ObjectConstructor; - value?: object; + value?: ImageProps; }; shape?: { type: StringConstructor; @@ -45,4 +39,3 @@ export interface TdAvatarProps { value?: string; }; } -export declare type ShapeEnum = 'circle' | 'round'; diff --git a/miniprogram_npm/tdesign-miniprogram/back-top/README.en-US.md b/miniprogram_npm/tdesign-miniprogram/back-top/README.en-US.md index c75a4b5..558178c 100644 --- a/miniprogram_npm/tdesign-miniprogram/back-top/README.en-US.md +++ b/miniprogram_npm/tdesign-miniprogram/back-top/README.en-US.md @@ -6,14 +6,36 @@ name | type | default | description | required -- | -- | -- | -- | -- -external-classes | Array | - | `['t-class', 't-class-icon', 't-class-text']` | N +style | Object | - | CSS(Cascading Style Sheets) | N +custom-style | Object | - | CSS(Cascading Style Sheets),used to set style on virtual component | N fixed | Boolean | true | \- | N -icon | String / Boolean / Object / Slot | - | \- | N +icon | String / Boolean / Object / Slot | true | [see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N +scroll-top | Number | 0 | \- | N text | String | '' | \- | N -theme | String | round | options:round/half-round/round-dark/half-round-dark | N +theme | String | round | options: round/half-round/round-dark/half-round-dark | N +visibility-height | Number | 200 | \- | N ### BackTop Events name | params | description -- | -- | -- to-top | \- | \- +### BackTop External Classes + +className | Description +-- | -- +t-class | \- +t-class-icon | \- +t-class-text | \- + +### CSS Variables + +The component provides the following CSS variables, which can be used to customize styles. +Name | Default Value | Description +-- | -- | -- +--td-back-top-round-bg-color | @font-white-1 | - +--td-back-top-round-border-color | @component-border | - +--td-back-top-round-border-radius | @radius-circle | - +--td-back-top-round-color | @font-gray-1 | - +--td-back-top-round-dark-bg-color | @gray-color-14 | - +--td-back-top-round-dark-color | @font-white-1 | - \ No newline at end of file diff --git a/miniprogram_npm/tdesign-miniprogram/back-top/README.md b/miniprogram_npm/tdesign-miniprogram/back-top/README.md index 7e220e4..50b2c28 100644 --- a/miniprogram_npm/tdesign-miniprogram/back-top/README.md +++ b/miniprogram_npm/tdesign-miniprogram/back-top/README.md @@ -18,6 +18,13 @@ isComponent: true ## 代码演示 + 在开发者工具中预览效果 + +
+

Tips: 请确保开发者工具为打开状态。导入开发者工具后,依次执行:npm i > 构建npm包 > 勾选 "将JS编译成ES5"

+
+ + ### 基础返回顶部 @@ -25,18 +32,41 @@ isComponent: true {{ base }} ## API + ### BackTop Props -名称 | 类型 | 默认值 | 说明 | 必传 +名称 | 类型 | 默认值 | 描述 | 必传 -- | -- | -- | -- | -- -external-classes | Array | - | 组件类名,分别用于设置外层元素、图标、文本内容等元素类名。`['t-class', 't-class-icon', 't-class-text']` | N +style | Object | - | 样式 | N +custom-style | Object | - | 样式,一般用于开启虚拟化组件节点场景 | N fixed | Boolean | true | 是否绝对定位固定到屏幕右下方 | N -icon | String / Boolean / Object / Slot | true | 图标。值为 `false` 表示不显示图标。不传表示使用默认图标 `'backtop'` | N +icon | String / Boolean / Object / Slot | true | 图标。值为 `false` 表示不显示图标。不传表示使用默认图标 `'backtop'`。[通用类型定义](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N +scroll-top | Number | 0 | 页面滚动距离 | N text | String | '' | 文案 | N theme | String | round | 预设的样式类型。可选项:round/half-round/round-dark/half-round-dark | N +visibility-height | Number | 200 | 滚动高度达到此参数值才出现 | N ### BackTop Events 名称 | 参数 | 描述 -- | -- | -- to-top | \- | 点击触发 +### BackTop External Classes + +类名 | 描述 +-- | -- +t-class | 根节点样式类 +t-class-icon | 图标样式类 +t-class-text | 文本样式类 + +### CSS Variables + +组件提供了下列 CSS 变量,可用于自定义样式。 +名称 | 默认值 | 描述 +-- | -- | -- +--td-back-top-round-bg-color | @font-white-1 | - +--td-back-top-round-border-color | @component-border | - +--td-back-top-round-border-radius | @radius-circle | - +--td-back-top-round-color | @font-gray-1 | - +--td-back-top-round-dark-bg-color | @gray-color-14 | - +--td-back-top-round-dark-color | @font-white-1 | - \ No newline at end of file diff --git a/miniprogram_npm/tdesign-miniprogram/back-top/back-top.d.ts b/miniprogram_npm/tdesign-miniprogram/back-top/back-top.d.ts index 90e8f03..ced948c 100644 --- a/miniprogram_npm/tdesign-miniprogram/back-top/back-top.d.ts +++ b/miniprogram_npm/tdesign-miniprogram/back-top/back-top.d.ts @@ -10,9 +10,11 @@ export default class BackTop extends SuperComponent { prefix: string; classPrefix: string; _icon: any; + hidden: boolean; }; observers: { icon(): void; + scrollTop(value: number): void; }; lifetimes: { ready(): void; diff --git a/miniprogram_npm/tdesign-miniprogram/back-top/back-top.js b/miniprogram_npm/tdesign-miniprogram/back-top/back-top.js index 8c2ce59..a14d94c 100644 --- a/miniprogram_npm/tdesign-miniprogram/back-top/back-top.js +++ b/miniprogram_npm/tdesign-miniprogram/back-top/back-top.js @@ -27,11 +27,16 @@ let BackTop = class BackTop extends SuperComponent { prefix, classPrefix: name, _icon: null, + hidden: true, }; this.observers = { icon() { this.setIcon(); }, + scrollTop(value) { + const { visibilityHeight } = this.properties; + this.setData({ hidden: value < visibilityHeight }); + }, }; this.lifetimes = { ready() { @@ -50,6 +55,7 @@ let BackTop = class BackTop extends SuperComponent { this.triggerEvent('to-top'); if (this.$parent) { (_a = this.$parent) === null || _a === void 0 ? void 0 : _a.setScrollTop(0); + this.setData({ hidden: true }); } else { wx.pageScrollTo({ diff --git a/miniprogram_npm/tdesign-miniprogram/back-top/back-top.json b/miniprogram_npm/tdesign-miniprogram/back-top/back-top.json index 049940c..f783dae 100644 --- a/miniprogram_npm/tdesign-miniprogram/back-top/back-top.json +++ b/miniprogram_npm/tdesign-miniprogram/back-top/back-top.json @@ -1,5 +1,6 @@ { "component": true, + "styleIsolation": "apply-shared", "usingComponents": { "t-icon": "../icon/icon" } diff --git a/miniprogram_npm/tdesign-miniprogram/back-top/back-top.wxml b/miniprogram_npm/tdesign-miniprogram/back-top/back-top.wxml index 1d02278..3d119aa 100644 --- a/miniprogram_npm/tdesign-miniprogram/back-top/back-top.wxml +++ b/miniprogram_npm/tdesign-miniprogram/back-top/back-top.wxml @@ -6,6 +6,7 @@ class="class {{prefix}}-class {{_.cls(classPrefix, [['fixed', fixed], theme])}}" bindtap="toTop" aria-role="button" + hidden="{{hidden}}" > diff --git a/miniprogram_npm/tdesign-miniprogram/back-top/back-top.wxss b/miniprogram_npm/tdesign-miniprogram/back-top/back-top.wxss index 3ec2469..7907024 100644 --- a/miniprogram_npm/tdesign-miniprogram/back-top/back-top.wxss +++ b/miniprogram_npm/tdesign-miniprogram/back-top/back-top.wxss @@ -39,7 +39,7 @@ .t-back-top--fixed { position: fixed; right: var(--td-spacer, 16rpx); - bottom: var(--td-spacer-2, 32rpx); + bottom: calc(var(--td-spacer-2, 32rpx) + env(safe-area-inset-bottom)); } .t-back-top--round, .t-back-top--round-dark { @@ -49,20 +49,22 @@ } .t-back-top--round, .t-back-top--half-round { - color: var(--td-back-top-round-color, var(--td-font-gray-1, rgba(0, 0, 0, 0.9))); + color: var(--td-back-top-round-color, var(--td-text-color-primary, var(--td-font-gray-1, rgba(0, 0, 0, 0.9)))); border: 1rpx solid var(--td-back-top-round-border-color, var(--td-component-border, var(--td-gray-color-4, #dcdcdc))); - background-color: var(--td-back-top-round-bg-color, var(--td-font-white-1, #ffffff)); + background-color: var(--td-back-top-round-bg-color, var(--td-bg-color-container, var(--td-font-white-1, #ffffff))); } .t-back-top--round-dark, .t-back-top--half-round-dark { - color: var(--td-back-top-round-dark-color, var(--td-font-white-1, #ffffff)); - background-color: var(--td-back-top-round-dark-bg-color, var(--td-gray-color-14, #181818)); + color: var(--td-back-top-round-dark-color, var(--td-text-color-anti, var(--td-font-white-1, #ffffff))); + background-color: var(--td-back-top-round-dark-bg-color, var(--td-gray-color-13, #242424)); } .t-back-top--half-round, .t-back-top--half-round-dark { width: 120rpx; height: 80rpx; - border-radius: var(--td-back-top-half-round-border-radius, var(--td-radius-round, 999px)) 0 0 var(--td-back-top-half-round-border-radius, var(--td-radius-round, 999px)); + border-radius: 0; + border-top-left-radius: var(--td-back-top-half-round-border-radius, var(--td-radius-round, 999px)); + border-bottom-left-radius: var(--td-back-top-half-round-border-radius, var(--td-radius-round, 999px)); flex-direction: row; right: 0; } @@ -75,7 +77,7 @@ } .t-back-top__text--half-round, .t-back-top__text--half-round-dark { - width: 2em; + width: 48rpx; } .t-back-top__icon:not(:empty) + .t-back-top__text--half-round, .t-back-top__icon:not(:empty) + .t-back-top__text--half-round-dark { diff --git a/miniprogram_npm/tdesign-miniprogram/back-top/props.js b/miniprogram_npm/tdesign-miniprogram/back-top/props.js index 7becbe4..d6d8121 100644 --- a/miniprogram_npm/tdesign-miniprogram/back-top/props.js +++ b/miniprogram_npm/tdesign-miniprogram/back-top/props.js @@ -1,7 +1,4 @@ const props = { - externalClasses: { - type: Array, - }, fixed: { type: Boolean, value: true, @@ -10,6 +7,14 @@ const props = { type: null, value: true, }, + scrollTop: { + type: Number, + value: 0, + }, + style: { + type: String, + value: '', + }, text: { type: String, value: '', @@ -18,5 +23,9 @@ const props = { type: String, value: 'round', }, + visibilityHeight: { + type: Number, + value: 200, + }, }; export default props; diff --git a/miniprogram_npm/tdesign-miniprogram/back-top/type.d.ts b/miniprogram_npm/tdesign-miniprogram/back-top/type.d.ts index 45b6bae..9071651 100644 --- a/miniprogram_npm/tdesign-miniprogram/back-top/type.d.ts +++ b/miniprogram_npm/tdesign-miniprogram/back-top/type.d.ts @@ -1,19 +1,19 @@ export interface TdBackTopProps { - style?: { - type: StringConstructor; - value?: string; - }; - externalClasses?: { - type: ArrayConstructor; - value?: ['t-class', 't-class-icon', 't-class-text']; - }; fixed?: { type: BooleanConstructor; value?: boolean; }; icon?: { type: null; - value?: boolean | string | object; + value?: string | boolean | object; + }; + scrollTop?: { + type: NumberConstructor; + value?: number; + }; + style?: { + type: StringConstructor; + value?: string; }; text?: { type: StringConstructor; @@ -23,4 +23,8 @@ export interface TdBackTopProps { type: StringConstructor; value?: 'round' | 'half-round' | 'round-dark' | 'half-round-dark'; }; + visibilityHeight?: { + type: NumberConstructor; + value?: number; + }; } diff --git a/miniprogram_npm/tdesign-miniprogram/badge/README.en-US.md b/miniprogram_npm/tdesign-miniprogram/badge/README.en-US.md index f592805..05103dc 100644 --- a/miniprogram_npm/tdesign-miniprogram/badge/README.en-US.md +++ b/miniprogram_npm/tdesign-miniprogram/badge/README.en-US.md @@ -1,17 +1,45 @@ :: BASE_DOC :: ## API + ### Badge Props name | type | default | description | required -- | -- | -- | -- | -- +style | Object | - | CSS(Cascading Style Sheets) | N +custom-style | Object | - | CSS(Cascading Style Sheets),used to set style on virtual component | N color | String | - | \- | N content | String | - | \- | N -count | String / Number / Slot | 0 | \- | N +count | String / Number / Slot | 0 | [see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N dot | Boolean | false | \- | N -external-classes | Array | - | `['t-class', 't-class-content', 't-class-count']` | N max-count | Number | 99 | \- | N offset | Array | - | Typescript:`Array` | N -shape | String | circle | options:circle/round/ribbon/bubble | N +shape | String | circle | options: circle/square/bubble/ribbon | N show-zero | Boolean | false | \- | N -size | String | medium | options:small/medium | N +size | String | medium | options: medium/large | N +### Badge External Classes + +className | Description +-- | -- +t-class | \- +t-class-content | \- +t-class-count | \- + +### CSS Variables + +The component provides the following CSS variables, which can be used to customize styles. +Name | Default Value | Description +-- | -- | -- +--td-badge-basic-height | 32rpx | - +--td-badge-basic-padding | 8rpx | - +--td-badge-basic-width | 32rpx | - +--td-badge-bg-color | @error-color | - +--td-badge-border-radius | 4rpx | - +--td-badge-bubble-border-radius | 20rpx 20rpx 20rpx 1px | - +--td-badge-dot-size | 16rpx | - +--td-badge-font-size | @font-size-xs | - +--td-badge-font-weight | 600 | - +--td-badge-large-font-size | @font-size-s | - +--td-badge-large-height | 40rpx | - +--td-badge-large-padding | 10rpx | - +--td-badge-text-color | @font-white-1 | - \ No newline at end of file diff --git a/miniprogram_npm/tdesign-miniprogram/badge/README.md b/miniprogram_npm/tdesign-miniprogram/badge/README.md index 7d1bf08..a253b93 100644 --- a/miniprogram_npm/tdesign-miniprogram/badge/README.md +++ b/miniprogram_npm/tdesign-miniprogram/badge/README.md @@ -18,6 +18,12 @@ isComponent: true ## 代码演示 + 在开发者工具中预览效果 + +
+

Tips: 请确保开发者工具为打开状态。导入开发者工具后,依次执行:npm i > 构建npm包 > 勾选 "将JS编译成ES5"

+
+ ### 组件类型 {{ base }} @@ -30,18 +36,51 @@ isComponent: true {{ size }} +## FAQ + +### 如何处理由 ribbon 徽标溢出导致页面出现横向滚动? +角标溢出问题建议从父容器组件处理。如 #3063 ,可以给父容器 `cell` 组件添加 `overflow: hidden`,处理溢出造成页面出现横向滚动的问题。 + ## API + ### Badge Props -名称 | 类型 | 默认值 | 说明 | 必传 +名称 | 类型 | 默认值 | 描述 | 必传 -- | -- | -- | -- | -- +style | Object | - | 样式 | N +custom-style | Object | - | 样式,一般用于开启虚拟化组件节点场景 | N color | String | - | 颜色 | N content | String | - | 徽标内容,示例:`content='自定义内容'`。也可以使用默认插槽定义 | N -count | String / Number / Slot | 0 | 徽标右上角内容。可以是数字,也可以是文字。如:'new'/3/99+。特殊:值为空表示使用插槽渲染 | N +count | String / Number / Slot | 0 | 徽标右上角内容。可以是数字,也可以是文字。如:'new'/3/99+。特殊:值为空表示使用插槽渲染。[通用类型定义](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N dot | Boolean | false | 是否为红点 | N -external-classes | Array | - | 组件类名,分别用于设置外层元素、默认内容、右上角内容等元素类名。`['t-class', 't-class-content', 't-class-count']` | N max-count | Number | 99 | 封顶的数字值 | N offset | Array | - | 设置状态点的位置偏移,示例:[-10, 20] 或 ['10em', '8rem']。TS 类型:`Array` | N -shape | String | circle | 形状。可选项:circle/round/ribbon/bubble | N +shape | String | circle | 形状。可选项:circle/square/bubble/ribbon | N show-zero | Boolean | false | 当数值为 0 时,是否展示徽标 | N -size | String | medium | 尺寸。可选项:small/medium | N +size | String | medium | 尺寸。可选项:medium/large | N +### Badge External Classes + +类名 | 描述 +-- | -- +t-class | 根节点样式类 +t-class-content | 内容样式类 +t-class-count | 计数样式类 + +### CSS Variables + +组件提供了下列 CSS 变量,可用于自定义样式。 +名称 | 默认值 | 描述 +-- | -- | -- +--td-badge-basic-height | 32rpx | - +--td-badge-basic-padding | 8rpx | - +--td-badge-basic-width | 32rpx | - +--td-badge-bg-color | @error-color | - +--td-badge-border-radius | 4rpx | - +--td-badge-bubble-border-radius | 20rpx 20rpx 20rpx 1px | - +--td-badge-dot-size | 16rpx | - +--td-badge-font-size | @font-size-xs | - +--td-badge-font-weight | 600 | - +--td-badge-large-font-size | @font-size-s | - +--td-badge-large-height | 40rpx | - +--td-badge-large-padding | 10rpx | - +--td-badge-text-color | @font-white-1 | - \ No newline at end of file diff --git a/miniprogram_npm/tdesign-miniprogram/badge/badge.json b/miniprogram_npm/tdesign-miniprogram/badge/badge.json index a7a3e7a..4f0a3f0 100644 --- a/miniprogram_npm/tdesign-miniprogram/badge/badge.json +++ b/miniprogram_npm/tdesign-miniprogram/badge/badge.json @@ -1,5 +1,5 @@ { "component": true, + "styleIsolation": "apply-shared", "usingComponents": {} } - diff --git a/miniprogram_npm/tdesign-miniprogram/badge/badge.wxml b/miniprogram_npm/tdesign-miniprogram/badge/badge.wxml index 51fea40..abc57b7 100644 --- a/miniprogram_npm/tdesign-miniprogram/badge/badge.wxml +++ b/miniprogram_npm/tdesign-miniprogram/badge/badge.wxml @@ -1,6 +1,12 @@ + + {{content}}
diff --git a/miniprogram_npm/tdesign-miniprogram/badge/badge.wxs b/miniprogram_npm/tdesign-miniprogram/badge/badge.wxs index c2aaad9..b3064d8 100644 --- a/miniprogram_npm/tdesign-miniprogram/badge/badge.wxs +++ b/miniprogram_npm/tdesign-miniprogram/badge/badge.wxs @@ -26,7 +26,7 @@ var getBadgeStyles = function (props) { styleStr += 'background:' + props.color + ';'; } if (props.offset[0]) { - styleStr += 'right:' + (hasUnit(props.offset[0].toString()) ? props.offset[0] : props.offset[0] + 'px') + ';'; + styleStr += 'left: calc(100% + ' + (hasUnit(props.offset[0].toString()) ? props.offset[0] : props.offset[0] + 'px') + ');'; } if (props.offset[1]) { styleStr += 'top:' + (hasUnit(props.offset[1].toString()) ? props.offset[1] : props.offset[1] + 'px') + ';'; @@ -63,22 +63,8 @@ var isShowBadge = function (props) { return true; }; -var getBadgeAriaLabel = function (props) { - if (props.dot) { - return '有新的消息'; - } - if (isNaN(props.count) || isNaN(props.maxCount)) { - var str = '有' + props.count + '通知'; - return str; - } - var str1 = '有' + props.maxCount + '+条消息'; - var str2 = '有' + props.count + '条消息'; - return parseInt(props.count) > props.maxCount ? str1 : str2; -}; - module.exports.getBadgeValue = getBadgeValue; module.exports.getBadgeStyles = getBadgeStyles; module.exports.getBadgeOuterClass = getBadgeOuterClass; module.exports.getBadgeInnerClass = getBadgeInnerClass; -module.exports.getBadgeAriaLabel = getBadgeAriaLabel; module.exports.isShowBadge = isShowBadge; diff --git a/miniprogram_npm/tdesign-miniprogram/badge/badge.wxss b/miniprogram_npm/tdesign-miniprogram/badge/badge.wxss index 5d4ba33..5398f03 100644 --- a/miniprogram_npm/tdesign-miniprogram/badge/badge.wxss +++ b/miniprogram_npm/tdesign-miniprogram/badge/badge.wxss @@ -27,14 +27,14 @@ } .t-badge { position: relative; - display: inline-block; - vertical-align: top; + display: inline-flex; + align-items: start; } .t-badge--basic { z-index: 100; padding: 0 var(--td-badge-basic-padding, 8rpx); font-size: var(--td-badge-font-size, var(--td-font-size-xs, var(--td-font-size, 20rpx))); - color: var(--td-badge-text-color, var(--td-font-white-1, #ffffff)); + color: var(--td-badge-text-color, var(--td-text-color-anti, var(--td-font-white-1, #ffffff))); background-color: var(--td-badge-bg-color, var(--td-error-color, var(--td-error-color-6, #d54941))); text-align: center; height: var(--td-badge-basic-height, 32rpx); @@ -62,28 +62,28 @@ right: 0; } .t-badge--ribbon { + position: relative; display: inline-block; - transform: rotate(45deg); + transform-origin: center center; + transform: translate(calc(50% - var(--td-badge-basic-height, 32rpx) + 1rpx), calc(-50% + var(--td-badge-basic-height, 32rpx) - 1rpx)) rotate(45deg); border-radius: 0; } -.t-badge--ribbon::before { - content: ''; - position: absolute; - width: 0; - height: 0; - bottom: 0; - left: calc(-1 * var(--td-badge-basic-height, 32rpx) + 1rpx); - border-bottom: var(--td-badge-basic-height, 32rpx) solid var(--td-badge-bg-color, var(--td-error-color, var(--td-error-color-6, #d54941))); - border-left: var(--td-badge-basic-height, 32rpx) solid transparent; -} +.t-badge--ribbon::before, .t-badge--ribbon::after { content: ''; position: absolute; width: 0; height: 0; bottom: 0; - right: calc(-1 * var(--td-badge-basic-height, 32rpx) + 1rpx); border-bottom: var(--td-badge-basic-height, 32rpx) solid var(--td-badge-bg-color, var(--td-error-color, var(--td-error-color-6, #d54941))); + font-size: 0; +} +.t-badge--ribbon::before { + left: calc(-1 * var(--td-badge-basic-height, 32rpx) + 1rpx); + border-left: var(--td-badge-basic-height, 32rpx) solid transparent; +} +.t-badge--ribbon::after { + right: calc(-1 * var(--td-badge-basic-height, 32rpx) + 1rpx); border-right: var(--td-badge-basic-height, 32rpx) solid transparent; } .t-badge--bubble { @@ -100,12 +100,14 @@ border-radius: calc(var(--td-badge-large-height, 40rpx) / 2); } .t-badge__content:not(:empty) + .t-has-count { - transform: translate(50%, -50%); + transform-origin: center center; + transform: translate(-50%, -50%); position: absolute; - right: 0; + left: 100%; top: 0; } .t-badge__content-text { display: block; line-height: 48rpx; + color: var(--td-badge-content-text-color, var(--td-text-color-primary, var(--td-font-gray-1, rgba(0, 0, 0, 0.9)))); } diff --git a/miniprogram_npm/tdesign-miniprogram/badge/type.d.ts b/miniprogram_npm/tdesign-miniprogram/badge/type.d.ts index 30f00d0..2029271 100644 --- a/miniprogram_npm/tdesign-miniprogram/badge/type.d.ts +++ b/miniprogram_npm/tdesign-miniprogram/badge/type.d.ts @@ -11,10 +11,6 @@ export interface TdBadgeProps { type: null; value?: string | number; }; - style?: { - type: StringConstructor; - value?: string; - }; dot?: { type: BooleanConstructor; value?: boolean; @@ -33,7 +29,7 @@ export interface TdBadgeProps { }; shape?: { type: StringConstructor; - value?: 'circle' | 'round' | 'ribbon' | 'bubble'; + value?: 'circle' | 'square' | 'bubble' | 'ribbon'; }; showZero?: { type: BooleanConstructor; @@ -41,6 +37,6 @@ export interface TdBadgeProps { }; size?: { type: StringConstructor; - value?: 'small' | 'medium'; + value?: 'medium' | 'large'; }; } diff --git a/miniprogram_npm/tdesign-miniprogram/button/README.en-US.md b/miniprogram_npm/tdesign-miniprogram/button/README.en-US.md index ee2b1d7..fbd8440 100644 --- a/miniprogram_npm/tdesign-miniprogram/button/README.en-US.md +++ b/miniprogram_npm/tdesign-miniprogram/button/README.en-US.md @@ -1,46 +1,233 @@ -:: BASE_DOC :: +--- +title: Button +description: Buttons are used to open a closed-loop task, such as "delete" an object, "buy" an item, etc. +spline: base +isComponent: true +--- + + + + +## Usage + +For global import, configure it in `app.json` in the root directory of the miniprogram. For local import, configure it in `index.json` of the page or component that needs to be imported. + +```json +"usingComponents": { + "t-button": "tdesign-miniprogram/button/button" +} +``` + + +## Code Demo + +### 01 Component Type + +#### Basic Buttons + +{{ base }} + +#### Icon Button + +{{ icon-btn }} + +#### Ghost Button + +{{ ghost-btn }} + +#### Combination Button + +{{ group-btn }} + +#### Banner Button + +{{ block-btn }} + +### 02 Component State + +#### Buttons for different states + +{{ disabled }} + +### 03 Component Style + +#### Different sizes of buttons + +{{ size }} + +#### Different shaped buttons + +{{ shape }} + +#### Different color theme buttons + +{{ theme }} + + ## API + ### Button Props name | type | default | description | required -- | -- | -- | -- | -- +style | Object | - | CSS(Cascading Style Sheets) | N +custom-style | Object | - | CSS(Cascading Style Sheets),used to set style on virtual component | N +app-parameter | String | - | \- | N block | Boolean | false | make button to be a block-level element | N -content | String / Slot | - | button's children elements | N -custom-dataset | Object | - | Typescript:`any` | N -disabled | Boolean | false | disable the button, make it can not be clicked | N -external-classes | Array | - | `['t-class', 't-class-icon', 't-class-loading']` | N +content | String / Slot | - | button's children elements。[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N +custom-dataset | any | - | \- | N +disabled | Boolean | undefined | disable the button, make it can not be clicked | N ghost | Boolean | false | make background-color to be transparent | N -icon | String / Object | - | icon name | N -loading | Boolean | false | set button to be loading state | N -loading-props | Object | - | Typescript:`LoadingProps`,[Loading API Documents](./loading?tab=api)。[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/button/type.ts) | N -shape | String | rectangle | button shape。options:rectangle/square/round/circle | N -size | String | medium | a button has three size。options:small/medium/large。Typescript:`SizeEnum` | N -suffix | Slot | - | \- | N -theme | String | default | button theme。options:default/primary/danger | N -type | String | - | type of button element, same as formType of Miniprogram。options:submit/reset | N -variant | String | base | button variant。options:base/outline/text | N -open-type | String | - | options:contact/share/getPhoneNumber/getUserInfo/launchApp/openSetting/feedback/chooseAvatar | N -hover-stop-propagation | Boolean | false | \- | N +hover-class | String | - | \- | N hover-start-time | Number | 20 | \- | N hover-stay-time | Number | 70 | \- | N -lang | String | en | options:en/zh_CN/zh_TW | N -session-from | String | - | \- | N -send-message-title | String | 当前标题 | \- | N -send-message-path | String | 当前分享路径 | \- | N +hover-stop-propagation | Boolean | false | \- | N +icon | String / Object | - | icon name | N +lang | String | - | message language。options: en/zh_CN/zh_TW | N +loading | Boolean | false | set button to be loading state | N +loading-props | Object | - | Typescript:`LoadingProps`,[Loading API Documents](./loading?tab=api)。[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/button/type.ts) | N +open-type | String | - | open type of button, [Miniprogram Button](https://developers.weixin.qq.com/miniprogram/dev/component/button.html)。options: contact/share/getPhoneNumber/getUserInfo/launchApp/openSetting/feedback/chooseAvatar/agreePrivacyAuthorization | N +phone-number-no-quota-toast | Boolean | true | \- | N send-message-img | String | 截图 | \- | N -app-parameter | String | - | \- | N +send-message-path | String | 当前分享路径 | \- | N +send-message-title | String | 当前标题 | \- | N +session-from | String | - | \- | N +shape | String | rectangle | button shape。options: rectangle/square/round/circle | N show-message-card | Boolean | false | \- | N -bindgetuserinfo | Eventhandle | - | \- | N -bindcontact | Eventhandle | - | \- | N -bindgetphonenumber | Eventhandle | - | \- | N -binderror | Eventhandle | - | \- | N -bindopensetting | Eventhandle | - | \- | N -bindlaunchapp | Eventhandle | - | \- | N -bindchooseavatar | Eventhandle | - | \- | N +size | String | medium | a button has four size。options: extra-small/small/medium/large | N +suffix | Slot | - | [see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N +t-id | String | - | id | N +theme | String | default | button theme。options: default/primary/danger/light | N +type | String | - | type of button element, same as formType of Miniprogram。options: submit/reset | N +variant | String | base | variant of button。options: base/outline/dashed/text | N ### Button Events name | params | description -- | -- | -- -tap | `(e: MouseEvent)` | trigger on click +agreeprivacyauthorization | \- | \- +chooseavatar | \- | \- +click | `(e: MouseEvent)` | trigger on click +contact | \- | \- +createliveactivity | \- | \- +error | \- | \- +getphonenumber | \- | \- +getrealtimephonenumber | \- | \- +getuserinfo | \- | \- +launchapp | \- | \- +opensetting | \- | \- +tap | `event` | \- + +### Button External Classes + +className | Description +-- | -- +t-class | \- +t-class-icon | class name of icon +t-class-loading | class name of loading + +### CSS Variables + +The component provides the following CSS variables, which can be used to customize styles. +Name | Default Value | Description +-- | -- | -- +--td-button-border-radius | @radius-default | - +--td-button-border-width | 4rpx | - +--td-button-danger-active-bg-color | @error-color-7 | - +--td-button-danger-active-border-color | @error-color-7 | - +--td-button-danger-bg-color | @error-color | - +--td-button-danger-border-color | @error-color | - +--td-button-danger-color | @font-white-1 | - +--td-button-danger-dashed-border-color | @button-danger-dashed-color | - +--td-button-danger-dashed-color | @error-color | - +--td-button-danger-dashed-disabled-color | @button-danger-disabled-color | - +--td-button-danger-disabled-bg | @error-color-3 | - +--td-button-danger-disabled-border-color | @error-color-3 | - +--td-button-danger-disabled-color | @error-color-disabled | - +--td-button-danger-outline-active-bg-color | @bg-color-container-active | - +--td-button-danger-outline-active-border-color | @error-color-7 | - +--td-button-danger-outline-border-color | @button-danger-outline-color | - +--td-button-danger-outline-color | @error-color | - +--td-button-danger-outline-disabled-color | @error-color-3 | - +--td-button-danger-text-active-bg-color | @bg-color-container-active | - +--td-button-danger-text-color | @error-color | - +--td-button-danger-text-disabled-color | @button-danger-disabled-color | - +--td-button-default-active-bg-color | @bg-color-component-active | - +--td-button-default-active-border-color | @bg-color-component-active | - +--td-button-default-bg-color | @bg-color-component | - +--td-button-default-border-color | @bg-color-component | - +--td-button-default-color | @text-color-primary | - +--td-button-default-disabled-bg | @bg-color-component-disabled | - +--td-button-default-disabled-border-color | @bg-color-component-disabled | - +--td-button-default-disabled-color | @text-color-disabled | - +--td-button-default-outline-active-bg-color | @bg-color-container-active | - +--td-button-default-outline-active-border-color | @component-border | - +--td-button-default-outline-border-color | @component-border | - +--td-button-default-outline-color | @text-color-primary | - +--td-button-default-outline-disabled-color | @component-border | - +--td-button-default-text-active-bg-color | @bg-color-container-active | - +--td-button-extra-small-font-size | @font-size-base | - +--td-button-extra-small-height | 56rpx | - +--td-button-extra-small-icon-font-size | 36rpx | - +--td-button-extra-small-padding-horizontal | 16rpx | - +--td-button-font-weight | 600 | - +--td-button-ghost-border-color | @button-ghost-color | - +--td-button-ghost-color | @bg-color-container | - +--td-button-ghost-danger-border-color | @error-color | - +--td-button-ghost-danger-color | @error-color | - +--td-button-ghost-danger-hover-color | @error-color-active | - +--td-button-ghost-disabled-color | @font-white-4 | - +--td-button-ghost-hover-color | @font-white-2 | - +--td-button-ghost-primary-border-color | @brand-color | - +--td-button-ghost-primary-color | @brand-color | - +--td-button-ghost-primary-hover-color | @brand-color-active | - +--td-button-icon-border-radius | 8rpx | - +--td-button-icon-spacer | @spacer | - +--td-button-large-font-size | @font-size-m | - +--td-button-large-height | 96rpx | - +--td-button-large-icon-font-size | 48rpx | - +--td-button-large-padding-horizontal | 40rpx | - +--td-button-light-active-bg-color | @brand-color-light-active | - +--td-button-light-active-border-color | @brand-color-light-active | - +--td-button-light-bg-color | @brand-color-light | - +--td-button-light-border-color | @brand-color-light | - +--td-button-light-color | @brand-color | - +--td-button-light-disabled-bg | @brand-color-light | - +--td-button-light-disabled-border-color | @brand-color-light | - +--td-button-light-disabled-color | @brand-color-disabled | - +--td-button-light-outline-active-bg-color | @brand-color-light-active | - +--td-button-light-outline-active-border-color | @brand-color-active | - +--td-button-light-outline-bg-color | @brand-color-light | - +--td-button-light-outline-border-color | @button-light-outline-color | - +--td-button-light-outline-color | @brand-color | - +--td-button-light-outline-disabled-color | @brand-color-disabled | - +--td-button-light-text-active-bg-color | @bg-color-container-active | - +--td-button-light-text-color | @brand-color | - +--td-button-medium-font-size | @font-size-m | - +--td-button-medium-height | 80rpx | - +--td-button-medium-icon-font-size | 40rpx | - +--td-button-medium-padding-horizontal | 32rpx | - +--td-button-primary-active-bg-color | @brand-color-active | - +--td-button-primary-active-border-color | @brand-color-active | - +--td-button-primary-bg-color | @brand-color | - +--td-button-primary-border-color | @brand-color | - +--td-button-primary-color | @font-white-1 | - +--td-button-primary-dashed-border-color | @button-primary-dashed-color | - +--td-button-primary-dashed-color | @brand-color | - +--td-button-primary-dashed-disabled-color | @brand-color-disabled | - +--td-button-primary-disabled-bg | @brand-color-disabled | - +--td-button-primary-disabled-border-color | @brand-color-disabled | - +--td-button-primary-disabled-color | @font-white-1 | - +--td-button-primary-outline-active-bg-color | @bg-color-container-active | - +--td-button-primary-outline-active-border-color | @brand-color-active | - +--td-button-primary-outline-border-color | @button-primary-outline-color | - +--td-button-primary-outline-color | @brand-color | - +--td-button-primary-outline-disabled-color | @brand-color-disabled | - +--td-button-primary-text-active-bg-color | @bg-color-container-active | - +--td-button-primary-text-color | @brand-color | - +--td-button-primary-text-disabled-color | @brand-color-disabled | - +--td-button-small-font-size | @font-size-base | - +--td-button-small-height | 64rpx | - +--td-button-small-icon-font-size | 36rpx | - +--td-button-small-padding-horizontal | 24rpx | - \ No newline at end of file diff --git a/miniprogram_npm/tdesign-miniprogram/button/README.md b/miniprogram_npm/tdesign-miniprogram/button/README.md index f318844..ac4fc02 100644 --- a/miniprogram_npm/tdesign-miniprogram/button/README.md +++ b/miniprogram_npm/tdesign-miniprogram/button/README.md @@ -18,89 +18,218 @@ isComponent: true ## 代码演示 + 在开发者工具中预览效果 + +
+

Tips: 请确保开发者工具为打开状态。导入开发者工具后,依次执行:npm i > 构建npm包 > 勾选 "将JS编译成ES5"

+
+ + ### 01 组件类型 -基础按钮 +#### 基础按钮 {{ base }} -图标按钮 +#### 图标按钮 {{ icon-btn }} -幽灵按钮 +#### 幽灵按钮 {{ ghost-btn }} -组合按钮 +#### 组合按钮 {{ group-btn }} -通栏按钮 +#### 通栏按钮 {{ block-btn }} ### 02 组件状态 -按钮禁用态 +#### 按钮禁用态 {{ disabled }} ### 03 组件样式 -按钮尺寸 +#### 按钮尺寸 {{ size }} -按钮形状 +#### 按钮形状 {{ shape }} -按钮主题 +#### 按钮主题 {{ theme }} ## API + ### Button Props -名称 | 类型 | 默认值 | 说明 | 必传 +名称 | 类型 | 默认值 | 描述 | 必传 -- | -- | -- | -- | -- +style | Object | - | 样式 | N +custom-style | Object | - | 样式,一般用于开启虚拟化组件节点场景 | N +app-parameter | String | - | 打开 APP 时,向 APP 传递的参数,open-type=launchApp时有效 | N block | Boolean | false | 是否为块级元素 | N -content | String / Slot | - | 按钮内容 | N -custom-dataset | Object | - | 自定义 dataset,可通过 event.currentTarget.dataset.custom 获取。TS 类型:`any` | N -disabled | Boolean | false | 禁用状态 | N -external-classes | Array | - | 组件类名。`['t-class', 't-class-icon', 't-class-loading']` | N +content | String / Slot | - | 按钮内容。[通用类型定义](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N +custom-dataset | any | - | 自定义 dataset,可通过 event.currentTarget.dataset.custom 获取 | N +disabled | Boolean | undefined | 禁用状态。优先级:Button.disabled > Form.disabled | N ghost | Boolean | false | 是否为幽灵按钮(镂空按钮) | N -icon | String / Object | - | 图标名称。值为字符串表示图标名称,值为 `Object` 类型,表示透传至 `icon`。 | N -loading | Boolean | false | 是否显示为加载状态 | N -loading-props | Object | - | 透传至 Loading 组件。TS 类型:`LoadingProps`,[Loading API Documents](./loading?tab=api)。[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/button/type.ts) | N -shape | String | rectangle | 按钮形状,有 4 种:长方形、正方形、圆角长方形、圆形。可选项:rectangle/square/round/circle | N -size | String | medium | 组件尺寸。可选项:extra-small/small/medium/large。TS 类型:`SizeEnum` | N -suffix | Slot | - | 右侧内容,可用于定义右侧图标 | N -theme | String | default | 组件风格,依次为品牌色、危险色。可选项:default/primary/danger/light | N -type | String | - | 同小程序的 formType。可选项:submit/reset | N -variant | String | base | 按钮形式,基础、线框、文字。可选项:base/outline/dashed/text | N -open-type | String | - | 微信开放能力。
具体释义:
`contact` 打开客服会话,如果用户在会话中点击消息卡片后返回小程序,可以从 bindcontact 回调中获得具体信息,具体说明 (*小程序插件中不能使用*);
`share` 触发用户转发,使用前建议先阅读使用指引
`getPhoneNumber` 获取用户手机号,可以从 bindgetphonenumber 回调中获取到用户信息,具体说明 (*小程序插件中不能使用*);
`getUserInfo` 获取用户信息,可以从 bindgetuserinfo 回调中获取到用户信息 (*小程序插件中不能使用*);
`launchApp` 打开APP,可以通过 app-parameter 属性设定向 APP 传的参数具体说明
`openSetting` 打开授权设置页;
`feedback` 打开“意见反馈”页面,用户可提交反馈内容并上传日志,开发者可以登录小程序管理后台后进入左侧菜单“客服反馈”页面获取到反馈内容;
`chooseAvatar` 获取用户头像,可以从 bindchooseavatar 回调中获取到头像信息。
[小程序官方文档](https://developers.weixin.qq.com/miniprogram/dev/component/button.html)。可选项:contact/share/getPhoneNumber/getUserInfo/launchApp/openSetting/feedback/chooseAvatar | N -hover-stop-propagation | Boolean | false | 指定是否阻止本节点的祖先节点出现点击态 | N +hover-class | String | - | 指定按钮按下去的样式类,按钮不为加载或禁用状态时有效。当 `hover-class="none"` 时,没有点击态效果 | N hover-start-time | Number | 20 | 按住后多久出现点击态,单位毫秒 | N hover-stay-time | Number | 70 | 手指松开后点击态保留时间,单位毫秒 | N -lang | String | en | 指定返回用户信息的语言,zh_CN 简体中文,zh_TW 繁体中文,en 英文。。
具体释义:
`en` 英文;
`zh_CN` 简体中文;
`zh_TW` 繁体中文。
[小程序官方文档](https://developers.weixin.qq.com/miniprogram/dev/component/button.html)。可选项:en/zh_CN/zh_TW | N -session-from | String | - | 会话来源,open-type="contact"时有效 | N -send-message-title | String | 当前标题 | 会话内消息卡片标题,open-type="contact"时有效 | N -send-message-path | String | 当前分享路径 | 会话内消息卡片点击跳转小程序路径,open-type="contact"时有效 | N +hover-stop-propagation | Boolean | false | 指定是否阻止本节点的祖先节点出现点击态 | N +icon | String / Object | - | 图标名称。值为字符串表示图标名称,值为 `Object` 类型,表示透传至 `icon`。 | N +lang | String | - | 指定返回用户信息的语言,zh_CN 简体中文,zh_TW 繁体中文,en 英文。。
具体释义:
`en` 英文;
`zh_CN` 简体中文;
`zh_TW` 繁体中文。
[小程序官方文档](https://developers.weixin.qq.com/miniprogram/dev/component/button.html)。。可选项:en/zh_CN/zh_TW | N +loading | Boolean | false | 是否显示为加载状态 | N +loading-props | Object | - | 透传 Loading 组件全部属性。TS 类型:`LoadingProps`,[Loading API Documents](./loading?tab=api)。[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/button/type.ts) | N +open-type | String | - | 微信开放能力。
具体释义:
`contact` 打开客服会话,如果用户在会话中点击消息卡片后返回小程序,可以从 bindcontact 回调中获得具体信息,具体说明 (*小程序插件中不能使用*);
`share` 触发用户转发,使用前建议先阅读使用指引
`getPhoneNumber` 获取用户手机号,可以从 bindgetphonenumber 回调中获取到用户信息,具体说明 (*小程序插件中不能使用*);
`getUserInfo` 获取用户信息,可以从 bindgetuserinfo 回调中获取到用户信息 (*小程序插件中不能使用*);
`launchApp` 打开APP,可以通过 app-parameter 属性设定向 APP 传的参数具体说明
`openSetting` 打开授权设置页;
`feedback` 打开“意见反馈”页面,用户可提交反馈内容并上传日志,开发者可以登录小程序管理后台后进入左侧菜单“客服反馈”页面获取到反馈内容;
`chooseAvatar` 获取用户头像,可以从 bindchooseavatar 回调中获取到头像信息;
`agreePrivacyAuthorization`用户同意隐私协议按钮。用户点击一次此按钮后,所有隐私接口可以正常调用。可通过`bindagreeprivacyauthorization`监听用户同意隐私协议事件。隐私合规开发指南详情可见《小程序隐私协议开发指南》。
[小程序官方文档](https://developers.weixin.qq.com/miniprogram/dev/component/button.html)。。可选项:contact/share/getPhoneNumber/getUserInfo/launchApp/openSetting/feedback/chooseAvatar/agreePrivacyAuthorization | N +phone-number-no-quota-toast | Boolean | true | 原生按钮属性,当手机号快速验证或手机号实时验证额度用尽时,是否对用户展示“申请获取你的手机号,但该功能使用次数已达当前小程序上限,暂时无法使用”的提示,默认展示,open-type="getPhoneNumber" 或 open-type="getRealtimePhoneNumber" 时有效 | N send-message-img | String | 截图 | 会话内消息卡片图片,open-type="contact"时有效 | N -app-parameter | String | - | 打开 APP 时,向 APP 传递的参数,open-type=launchApp时有效 | N +send-message-path | String | 当前分享路径 | 会话内消息卡片点击跳转小程序路径,open-type="contact"时有效 | N +send-message-title | String | 当前标题 | 会话内消息卡片标题,open-type="contact"时有效 | N +session-from | String | - | 会话来源,open-type="contact"时有效 | N +shape | String | rectangle | 按钮形状,有 4 种:长方形、正方形、圆角长方形、圆形。可选项:rectangle/square/round/circle | N show-message-card | Boolean | false | 是否显示会话内消息卡片,设置此参数为 true,用户进入客服会话会在右下角显示"可能要发送的小程序"提示,用户点击后可以快速发送小程序消息,open-type="contact"时有效 | N -bindgetuserinfo | Eventhandle | - | 用户点击该按钮时,会返回获取到的用户信息,回调的 detail 数据与wx.getUserInfo返回的一致,open-type="getUserInfo"时有效 | N -bindcontact | Eventhandle | - | 客服消息回调,open-type="contact"时有效 | N -bindgetphonenumber | Eventhandle | - | 获取用户手机号回调,open-type=getPhoneNumber时有效 | N -binderror | Eventhandle | - | 当使用开放能力时,发生错误的回调,open-type=launchApp时有效 | N -bindopensetting | Eventhandle | - | 在打开授权设置页后回调,open-type=openSetting时有效 | N -bindlaunchapp | Eventhandle | - | 打开 APP 成功的回调,open-type=launchApp时有效 | N -bindchooseavatar | Eventhandle | - | 获取用户头像回调,open-type=chooseAvatar时有效 | N +size | String | medium | 组件尺寸。可选项:extra-small/small/medium/large | N +suffix | Slot | - | 右侧内容,可用于定义右侧图标。[通用类型定义](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N +t-id | String | - | 按钮标签id | N +theme | String | default | 组件风格,依次为品牌色、危险色。可选项:default/primary/danger/light | N +type | String | - | 同小程序的 formType。。可选项:submit/reset | N +variant | String | base | 按钮形式,基础、线框、虚线、文字。可选项:base/outline/dashed/text | N ### Button Events 名称 | 参数 | 描述 -- | -- | -- -tap | `event` | 点击时触发 +agreeprivacyauthorization | \- | 原生按钮属性,用户同意隐私协议事件回调,open-type=agreePrivacyAuthorization时有效 (Tips: 如果使用 onNeedPrivacyAuthorization 接口,需要在 bindagreeprivacyauthorization 触发后再调用 resolve({ event: "agree", buttonId })) +chooseavatar | \- | 原生按钮属性,获取用户头像回调,`open-type=chooseAvatar` 时有效。返回 `e.detail.avatarUrl` 为头像临时文件链接 +click | `(e: MouseEvent)` | 点击时触发 +contact | \- | 原生按钮属性,客服消息回调,`open-type="contact"` 时有效 +createliveactivity | \- | 新的一次性订阅消息下发机制回调,`open-type=liveActivity` 时有效 +error | \- | 原生按钮属性,当使用开放能力时,发生错误的回调,`open-type=launchApp` 时有效 +getphonenumber | \- | 原生按钮属性,手机号快速验证回调,open-type=getPhoneNumber时有效。Tips:在触发 bindgetphonenumber 回调后应立即隐藏手机号按钮组件,或置为 disabled 状态,避免用户重复授权手机号产生额外费用 +getrealtimephonenumber | \- | 原生按钮属性,手机号实时验证回调,open-type=getRealtimePhoneNumber 时有效。Tips:在触发 bindgetrealtimephonenumber 回调后应立即隐藏手机号按钮组件,或置为 disabled 状态,避免用户重复授权手机号产生额外费用 +getuserinfo | \- | 原生按钮属性,用户点击该按钮时,会返回获取到的用户信息,回调的detail数据与wx.getUserInfo返回的一致,open-type="getUserInfo"时有效 +launchapp | \- | 打开 APP 成功的回调,`open-type=launchApp` 时有效 +opensetting | \- | 原生按钮属性,在打开授权设置页后回调,open-type=openSetting时有效 +tap | `event` | 点击按钮,当按钮不为加载或禁用状态时触发 + +### Button External Classes + +类名 | 描述 +-- | -- +t-class | 根节点样式类 +t-class-icon | 图标样式类 +t-class-loading | 加载样式类 + +### CSS Variables + +组件提供了下列 CSS 变量,可用于自定义样式。 +名称 | 默认值 | 描述 +-- | -- | -- +--td-button-border-radius | @radius-default | - +--td-button-border-width | 4rpx | - +--td-button-danger-active-bg-color | @error-color-7 | - +--td-button-danger-active-border-color | @error-color-7 | - +--td-button-danger-bg-color | @error-color | - +--td-button-danger-border-color | @error-color | - +--td-button-danger-color | @font-white-1 | - +--td-button-danger-dashed-border-color | @button-danger-dashed-color | - +--td-button-danger-dashed-color | @error-color | - +--td-button-danger-dashed-disabled-color | @button-danger-disabled-color | - +--td-button-danger-disabled-bg | @error-color-3 | - +--td-button-danger-disabled-border-color | @error-color-3 | - +--td-button-danger-disabled-color | @error-color-disabled | - +--td-button-danger-outline-active-bg-color | @bg-color-container-active | - +--td-button-danger-outline-active-border-color | @error-color-7 | - +--td-button-danger-outline-border-color | @button-danger-outline-color | - +--td-button-danger-outline-color | @error-color | - +--td-button-danger-outline-disabled-color | @error-color-3 | - +--td-button-danger-text-active-bg-color | @bg-color-container-active | - +--td-button-danger-text-color | @error-color | - +--td-button-danger-text-disabled-color | @button-danger-disabled-color | - +--td-button-default-active-bg-color | @bg-color-component-active | - +--td-button-default-active-border-color | @bg-color-component-active | - +--td-button-default-bg-color | @bg-color-component | - +--td-button-default-border-color | @bg-color-component | - +--td-button-default-color | @text-color-primary | - +--td-button-default-disabled-bg | @bg-color-component-disabled | - +--td-button-default-disabled-border-color | @bg-color-component-disabled | - +--td-button-default-disabled-color | @text-color-disabled | - +--td-button-default-outline-active-bg-color | @bg-color-container-active | - +--td-button-default-outline-active-border-color | @component-border | - +--td-button-default-outline-border-color | @component-border | - +--td-button-default-outline-color | @text-color-primary | - +--td-button-default-outline-disabled-color | @component-border | - +--td-button-default-text-active-bg-color | @bg-color-container-active | - +--td-button-extra-small-font-size | @font-size-base | - +--td-button-extra-small-height | 56rpx | - +--td-button-extra-small-icon-font-size | 36rpx | - +--td-button-extra-small-padding-horizontal | 16rpx | - +--td-button-font-weight | 600 | - +--td-button-ghost-border-color | @button-ghost-color | - +--td-button-ghost-color | @bg-color-container | - +--td-button-ghost-danger-border-color | @error-color | - +--td-button-ghost-danger-color | @error-color | - +--td-button-ghost-danger-hover-color | @error-color-active | - +--td-button-ghost-disabled-color | @font-white-4 | - +--td-button-ghost-hover-color | @font-white-2 | - +--td-button-ghost-primary-border-color | @brand-color | - +--td-button-ghost-primary-color | @brand-color | - +--td-button-ghost-primary-hover-color | @brand-color-active | - +--td-button-icon-border-radius | 8rpx | - +--td-button-icon-spacer | @spacer | - +--td-button-large-font-size | @font-size-m | - +--td-button-large-height | 96rpx | - +--td-button-large-icon-font-size | 48rpx | - +--td-button-large-padding-horizontal | 40rpx | - +--td-button-light-active-bg-color | @brand-color-light-active | - +--td-button-light-active-border-color | @brand-color-light-active | - +--td-button-light-bg-color | @brand-color-light | - +--td-button-light-border-color | @brand-color-light | - +--td-button-light-color | @brand-color | - +--td-button-light-disabled-bg | @brand-color-light | - +--td-button-light-disabled-border-color | @brand-color-light | - +--td-button-light-disabled-color | @brand-color-disabled | - +--td-button-light-outline-active-bg-color | @brand-color-light-active | - +--td-button-light-outline-active-border-color | @brand-color-active | - +--td-button-light-outline-bg-color | @brand-color-light | - +--td-button-light-outline-border-color | @button-light-outline-color | - +--td-button-light-outline-color | @brand-color | - +--td-button-light-outline-disabled-color | @brand-color-disabled | - +--td-button-light-text-active-bg-color | @bg-color-container-active | - +--td-button-light-text-color | @brand-color | - +--td-button-medium-font-size | @font-size-m | - +--td-button-medium-height | 80rpx | - +--td-button-medium-icon-font-size | 40rpx | - +--td-button-medium-padding-horizontal | 32rpx | - +--td-button-primary-active-bg-color | @brand-color-active | - +--td-button-primary-active-border-color | @brand-color-active | - +--td-button-primary-bg-color | @brand-color | - +--td-button-primary-border-color | @brand-color | - +--td-button-primary-color | @font-white-1 | - +--td-button-primary-dashed-border-color | @button-primary-dashed-color | - +--td-button-primary-dashed-color | @brand-color | - +--td-button-primary-dashed-disabled-color | @brand-color-disabled | - +--td-button-primary-disabled-bg | @brand-color-disabled | - +--td-button-primary-disabled-border-color | @brand-color-disabled | - +--td-button-primary-disabled-color | @font-white-1 | - +--td-button-primary-outline-active-bg-color | @bg-color-container-active | - +--td-button-primary-outline-active-border-color | @brand-color-active | - +--td-button-primary-outline-border-color | @button-primary-outline-color | - +--td-button-primary-outline-color | @brand-color | - +--td-button-primary-outline-disabled-color | @brand-color-disabled | - +--td-button-primary-text-active-bg-color | @bg-color-container-active | - +--td-button-primary-text-color | @brand-color | - +--td-button-primary-text-disabled-color | @brand-color-disabled | - +--td-button-small-font-size | @font-size-base | - +--td-button-small-height | 64rpx | - +--td-button-small-icon-font-size | 36rpx | - +--td-button-small-padding-horizontal | 24rpx | - \ No newline at end of file diff --git a/miniprogram_npm/tdesign-miniprogram/button/button.d.ts b/miniprogram_npm/tdesign-miniprogram/button/button.d.ts index a55a5a2..4e88efd 100644 --- a/miniprogram_npm/tdesign-miniprogram/button/button.d.ts +++ b/miniprogram_npm/tdesign-miniprogram/button/button.d.ts @@ -6,13 +6,16 @@ export default class Button extends SuperComponent { externalClasses: string[]; behaviors: string[]; properties: TdButtonProps; + options: { + multipleSlots: boolean; + }; data: { prefix: string; className: string; classPrefix: string; }; observers: { - 'theme, size, plain, block, shape, disabled, loading'(): void; + 'theme, size, plain, block, shape, disabled, loading, variant'(): void; icon(icon: any): void; }; lifetimes: { @@ -27,6 +30,7 @@ export default class Button extends SuperComponent { opensetting(e: any): void; launchapp(e: any): void; chooseavatar(e: any): void; + agreeprivacyauthorization(e: any): void; handleTap(e: any): void; }; } diff --git a/miniprogram_npm/tdesign-miniprogram/button/button.js b/miniprogram_npm/tdesign-miniprogram/button/button.js index a457c41..5449818 100644 --- a/miniprogram_npm/tdesign-miniprogram/button/button.js +++ b/miniprogram_npm/tdesign-miniprogram/button/button.js @@ -8,7 +8,7 @@ import { SuperComponent, wxComponent } from '../common/src/index'; import config from '../common/config'; import props from './props'; import { canIUseFormFieldButton } from '../common/version'; -import { setIcon } from '../common/utils'; +import { calcIcon } from '../common/utils'; const { prefix } = config; const name = `${prefix}-button`; let Button = class Button extends SuperComponent { @@ -17,18 +17,22 @@ let Button = class Button extends SuperComponent { this.externalClasses = [`${prefix}-class`, `${prefix}-class-icon`, `${prefix}-class-loading`]; this.behaviors = canIUseFormFieldButton() ? ['wx://form-field-button'] : []; this.properties = props; + this.options = { + multipleSlots: true, + }; this.data = { prefix, className: '', classPrefix: name, }; this.observers = { - 'theme, size, plain, block, shape, disabled, loading'() { + 'theme, size, plain, block, shape, disabled, loading, variant'() { this.setClass(); }, icon(icon) { - const obj = setIcon('icon', icon, ''); - this.setData(Object.assign({}, obj)); + this.setData({ + _icon: calcIcon(icon, ''), + }); }, }; this.lifetimes = { @@ -80,8 +84,11 @@ let Button = class Button extends SuperComponent { chooseavatar(e) { this.triggerEvent('chooseavatar', e.detail); }, + agreeprivacyauthorization(e) { + this.triggerEvent('agreeprivacyauthorization', e.detail); + }, handleTap(e) { - if (this.data.disabled) + if (this.data.disabled || this.data.loading) return; this.triggerEvent('tap', e); }, diff --git a/miniprogram_npm/tdesign-miniprogram/button/button.json b/miniprogram_npm/tdesign-miniprogram/button/button.json index 708bd1b..a32e8cd 100644 --- a/miniprogram_npm/tdesign-miniprogram/button/button.json +++ b/miniprogram_npm/tdesign-miniprogram/button/button.json @@ -1,5 +1,6 @@ { "component": true, + "styleIsolation": "apply-shared", "usingComponents": { "t-icon": "../icon/icon", "t-loading": "../loading/loading" diff --git a/miniprogram_npm/tdesign-miniprogram/button/button.wxml b/miniprogram_npm/tdesign-miniprogram/button/button.wxml index b238985..895b227 100644 --- a/miniprogram_npm/tdesign-miniprogram/button/button.wxml +++ b/miniprogram_npm/tdesign-miniprogram/button/button.wxml @@ -2,17 +2,18 @@