diff --git a/docs/api/key.md b/docs/api/key.md index 657878c9a826203e692448df76d83f0b95e60237..471b81bbfc300c898a327ad157608cded4154e40 100644 --- a/docs/api/key.md +++ b/docs/api/key.md @@ -43,7 +43,7 @@ uni.onKeyboardHeightChange(res => { |App|H5|微信小程序|支付宝小程序|百度小程序|字节跳动小程序|QQ小程序| |:-:|:-:|:-:|:-:|:-:|:-:|:-:| -|HBuilderX 3.0.8+|x|基础库2.9.2+|x|x|x|x| +|HBuilderX 3.1.0+|x|基础库2.9.2+|x|x|x|x| **示例代码** diff --git a/docs/collocation/frame/lifecycle.md b/docs/collocation/frame/lifecycle.md index 029206c5e1ff745da38d15cb1c88d1dcb7d6f054..d66efba8f6137e7dd67bad52263567bb347ee3a6 100644 --- a/docs/collocation/frame/lifecycle.md +++ b/docs/collocation/frame/lifecycle.md @@ -42,7 +42,7 @@ |函数名|说明|平台差异说明|最低版本| |:-|:-|:-|:-| -|onInit|监听页面初始化,其参数同 onLoad 参数,为上个页面传递的数据,参数类型为 Object(用于页面传参),触发时机早于 onLoad|百度小程序|3.0.8+| +|onInit|监听页面初始化,其参数同 onLoad 参数,为上个页面传递的数据,参数类型为 Object(用于页面传参),触发时机早于 onLoad|百度小程序|3.1.0+| |onLoad|监听页面加载,其参数为上个页面传递的数据,参数类型为 Object(用于页面传参),参考[示例](/api/router?id=navigateto)||| |onShow|监听页面显示。页面每次出现在屏幕上都触发,包括从下级页面点返回露出当前页面||| |onReady|监听页面初次渲染完成。注意如果渲染速度快,会在页面进入动画完成前触发||| diff --git a/docs/component/input.md b/docs/component/input.md index 7ab195d67d2ebbc3e259ed39077869ad01b55144..be077ef4fbcdde97ccf54e852316e641ac81e881 100644 --- a/docs/component/input.md +++ b/docs/component/input.md @@ -28,7 +28,7 @@ |@focus|EventHandle||输入框聚焦时触发,event.detail = { value, height },height 为键盘高度|仅微信小程序、App(2.2.3+) 、QQ小程序支持 height| |@blur|EventHandle||输入框失去焦点时触发,event.detail = {value: value}|| |@confirm|EventHandle||点击完成按钮时触发,event.detail = {value: value}| | -|@keyboardheightchange|eventhandle||键盘高度发生变化的时候触发此事件,event.detail = {height: height, duration: duration}|微信小程序基础库2.7.0+、App 3.0.8+| +|@keyboardheightchange|eventhandle||键盘高度发生变化的时候触发此事件,event.detail = {height: height, duration: duration}|微信小程序基础库2.7.0+、App 3.1.0+| **Tips** diff --git a/docs/component/mp-weixin-plugin.md b/docs/component/mp-weixin-plugin.md index 0924e74f0aeaeb319a2e107953c80d81e51cc989..161b8a1be47d71b632d88bdeb57da90a5cefb1f7 100644 --- a/docs/component/mp-weixin-plugin.md +++ b/docs/component/mp-weixin-plugin.md @@ -74,7 +74,7 @@ } } -// 百度小程序 注意是 usingSwanComponents 不是 usingComponents(HBuilder 3.0.8+ 可以使写为 usingComponents) +// 百度小程序 注意是 usingSwanComponents 不是 usingComponents(HBuilder 3.1.0+ 可以使写为 usingComponents) { "path": "pages/index/index", "style": { diff --git a/docs/component/textarea.md b/docs/component/textarea.md index a1c0e9d40c38a2fa3a66cdcf0b39d37bb34bfab1..5cbd9468bf88ac680a8fd0bcb7baf815acea91c2 100644 --- a/docs/component/textarea.md +++ b/docs/component/textarea.md @@ -30,7 +30,7 @@ |@linechange|EventHandle||输入框行数变化时调用,event.detail = {height: 0, heightRpx: 0, lineCount: 0}|字节跳动小程序不支持,nvue ios暂不支持| |@input|EventHandle||当键盘输入时,触发 input 事件,event.detail = {value, cursor}, @input 处理函数的返回值并不会反映到 textarea 上|| |@confirm|EventHandle||点击完成时, 触发 confirm 事件,event.detail = {value: value}|微信小程序、百度小程序、QQ小程序| -|@keyboardheightchange|Eventhandle||键盘高度发生变化的时候触发此事件,event.detail = {height: height, duration: duration}|微信小程序基础库2.7.0+、App 3.0.8+| +|@keyboardheightchange|Eventhandle||键盘高度发生变化的时候触发此事件,event.detail = {height: height, duration: duration}|微信小程序基础库2.7.0+、App 3.1.0+| **confirm-type 有效值** diff --git a/docs/component/video.md b/docs/component/video.md index 362ad134da4aa0d8c5ddc89f4ec1b639768fd6e2..b767642f628e3d5372f9756b9ef927cda9cdfff4 100644 --- a/docs/component/video.md +++ b/docs/component/video.md @@ -35,8 +35,9 @@ |vslide-gesture-in-fullscreen|Boolean|true|在全屏模式下,是否开启亮度与音量调节手势|微信小程序| |ad-unit-id|String||视频前贴广告单元ID,更多详情可参考开放能力[视频前贴广告](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/ad/video-patch-ad.html)|微信小程序| |poster-for-crawler|String||用于给搜索等场景作为视频封面展示,建议使用无播放 icon 的视频封面图,只支持网络地址|微信小程序| -|codec|String|hardware|解码器选择,hardware:原生解码器,software:ffmpeg解码器|App 3.0.9+| -|http-cache|Boolean|true|是否对 http、https 链接,开启缓存|App 3.0.9+| +|codec|String|hardware|解码器选择,hardware:硬解码(硬解码可以增加解码算力,提高视频清晰度。部分硬件可能存在兼容性问题);software:ffmpeg 软解码;|App 3.1.0+| +|http-cache|Boolean|true|是否对 http、https 视频源开启本地缓存。缓存策略:开启了此开关的视频源,在视频播放时会在本地保存缓存文件,如果本地缓存池已超过100M,在进行缓存前会清空之前的缓存|App 3.1.0+| +|play-strategy|Number|0| 播放策略,0:默认策略;1:平滑播放模式(开启了此模式的视频源 会加大缓冲力度,采用open sl解码音频,避免音视频脱轨的问题,可能会降低首屏展现速度。 适用于在线播放高清视频的场景。);|App 3.1.0+| |@play|EventHandle||当开始/继续播放时触发play事件|字节跳动小程序不支持| |@pause|EventHandle||当暂停播放时触发 pause 事件|字节跳动小程序不支持| |@ended|EventHandle||当播放到末尾时触发 ended 事件|字节跳动小程序不支持| diff --git a/docs/hybrid.md b/docs/hybrid.md index aeb9dff9d11b4495449a9ffaff705b946ccc0ee3..d99a6336c2fbc38f5f0f361190ac7d43485aa7fa 100644 --- a/docs/hybrid.md +++ b/docs/hybrid.md @@ -14,7 +14,19 @@ - 方式1:把原生小程序转换为uni-app源码。有各种转换工具,[详见](translate.md) - 方式2:新建一个uni-app项目,把原生小程序的代码变成小程序组件,进而整合到uni-app项目下。uni-app支持使用小程序wxml组件,[参考](frame.md?id=小程序组件支持) -- 方式3:原生开发的小程序仍保留,部分新功能使用uni-app开发。这个场景有三方开发者提供了插件,[参考](https://ext.dcloud.net.cn/plugin?id=1560) +- 方式3:原生开发的小程序仍保留,部分新功能使用uni-app开发。 + * 官方提供了发行混合分包的功能 + + 在 HBuilderX 3.1.0+ 中点击发行小程序的菜单,勾选发行混合分包,填写分包目录名称,打包后,将对应目录文件拷贝至已有小程序中,需要自己补充原小程序app.json中的页面或分包配置 + + 在 cli 中,执行命令:`npm run build:mp-weixin -- --subpackage=sub1` 或 `yarn build:mp-weixin --subpackage=sub1` + + 注意: + + * 发行混合分包后,App.vue中的onLaunch,onShow等应用级别生命周期不再触发。 + * 开发时需要将资源(图片,css,js等)、页面的绝对路径调整为相对路径,否则打包到原生小程序中时,可能出现路径查找错误。 + * 需要自己把页面或分包配置添加到已有小程序的app.json中。 + * 目前支持微信小程序,百度小程序,支付宝小程序,字节跳动小程序,QQ小程序。 + + * 三方开发者插件,[参考](https://ext.dcloud.net.cn/plugin?id=1560) 如果想充分发挥uni-app的跨端特性,编译到各种其他小程序平台,建议使用方案1。 diff --git a/docs/nvue-css.md b/docs/nvue-css.md index d42771b8744766ce5ab279f01cef42f156fd40c7..a724ddd23d2398e753c054ad7af146b64867bb0e 100644 --- a/docs/nvue-css.md +++ b/docs/nvue-css.md @@ -8,7 +8,9 @@ - 在选择器方面支持的较少,只支持简单的```class="classA"```。 - class 进行绑定时只支持数组语法。 - 不支持媒体查询 -- 不支持复合样式,不支持简写 +- 不支持 class 以外的选择器 +- 不支持组合选择器(3.1.0+ 开始支持) +- 不支持简写样式(3.1.0+ 开始支持) - 不能在 style 中引入字体文件 - 布局不能使用百分比,如```width:100%```; - 有些web的css属性在nvue里无法支持,比如背景图。但可以使用image组件和层级来实现类似web中的背景效果。因为原生开发本身也没有web这种背景图概念 @@ -18,11 +20,20 @@ 下面有些正确和错误的写法示例对比: -- 选择器仅支持class 选择器 +- 选择器类型仅支持 class 选择器 ```css /* 错误 */ #id {} + + /* 正确 */ + .class {} +``` + +- 仅支持单个选择器(3.1.0+ 开始支持组合选择器) + +```css + /* 错误 */ .a .b .c {} .a > .b {} @@ -30,7 +41,7 @@ .class {} ``` -- 不支持简写 +- 不支持简写样式(3.1.0+ 开始支持更多简写样式) ```css /* 错误 */ diff --git a/docs/uniCloud/clientdb.md b/docs/uniCloud/clientdb.md index cd8516d46b86eb4127dcb9559291dbd86a3fbcc9..ee70ddae6786907831b95311ec8b9fcbafce65e2 100644 --- a/docs/uniCloud/clientdb.md +++ b/docs/uniCloud/clientdb.md @@ -588,7 +588,7 @@ db.collection('order,book') ### 对字段操作后返回@operator -自`HBuilderX 3.0.8`起,clientDB支持对字段进行一定的操作之后再返回,详细可用的方法列表请参考:[聚合操作符](uniCloud/clientdb.md?id=aggregate-operator) +自`HBuilderX 3.1.0`起,clientDB支持对字段进行一定的操作之后再返回,详细可用的方法列表请参考:[聚合操作符](uniCloud/clientdb.md?id=aggregate-operator) 例:数据表class内有以下数据 @@ -1146,7 +1146,7 @@ db.collection("department").get({ ### 分组统计@groupby -自`HBuilderX 3.0.8`起,clientDB支持分组对数据进行分组统计(groupBy) +自`HBuilderX 3.1.0`起,clientDB支持分组对数据进行分组统计(groupBy) 如果数据库`score`表为某次比赛统计的分数数据,每条记录为一个学生的分数 @@ -1384,7 +1384,7 @@ const res = await db.collection('score') distinct方法将按照field方法指定的字段进行去重(如果field内未指定_id,不会按照_id去重) -> `HBuilderX 3.0.8`+ +> `HBuilderX 3.1.0`+ ```js const res = await db.collection('table1') diff --git a/package.json b/package.json index 21767f4f0c0095a2a477eb71ff2a8dcbf8943e90..42efb2d6152b02075114b5b25fb416947189ca66 100644 --- a/package.json +++ b/package.json @@ -72,10 +72,13 @@ "jsdom": "^16.2.1", "jsdom-global": "^3.0.2", "jsonfile": "^6.0.1", + "mustache": "^4.1.0", + "recast": "^0.20.4", "rollup": "^2.6.1", "rollup-plugin-babel": "^4.4.0", "rollup-plugin-terser": "^5.3.0", "shell-exec": "^1.0.2", + "stricter-htmlparser2": "^3.9.6", "strip-json-comments": "^3.1.0", "vue": "^2.6.11", "vue-router": "^3.0.1", diff --git a/packages/uni-template-compiler/__tests__/compiler-extra.spec.js b/packages/uni-template-compiler/__tests__/compiler-extra.spec.js index 8cee04c31cc868b8a195ab382905670a436e8294..0e048c608ed3fc37baedff3ad1057f1f3085d1f9 100644 --- a/packages/uni-template-compiler/__tests__/compiler-extra.spec.js +++ b/packages/uni-template-compiler/__tests__/compiler-extra.spec.js @@ -27,6 +27,17 @@ describe('mp:compiler-extra', () => { } } ) + assertCodegen( + /* eslint-disable no-template-curly-in-string */ + '{{item}}', + '{{item}}', + 'with(this){}', { + filterModules: { + t: {}, + a: {} + } + } + ) }) it('generate scopeId', () => { diff --git a/packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js b/packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js index 43bc3a950ac0d77997062a32ccb1aa4cbf628181..d31ab3f31a3c02ab9fed5cadffc4918c6e0d6f7c 100644 --- a/packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js +++ b/packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js @@ -100,7 +100,11 @@ describe('mp:compiler-mp-alipay', () => { ) assertCodegen( '

5

', - '5' + '5' + ) + assertCodegen( + '

52

', + '52' ) assertCodegen( '
6
', @@ -123,6 +127,10 @@ describe('mp:compiler-mp-alipay', () => { '

9

', '9' ) + assertCodegen( + '

10

', + '10' + ) }) it('generate getPhoneNumber', () => { diff --git a/packages/uni-template-compiler/__tests__/compiler-mp-toutiao.spec.js b/packages/uni-template-compiler/__tests__/compiler-mp-toutiao.spec.js index 92a6c8d95f7977250b6d6fc945f7f3d17cef67bb..0b525b795edb36a52768bc4ea9c14f8d2755f785 100644 --- a/packages/uni-template-compiler/__tests__/compiler-mp-toutiao.spec.js +++ b/packages/uni-template-compiler/__tests__/compiler-mp-toutiao.spec.js @@ -48,7 +48,11 @@ describe('mp:compiler-mp-toutiao', () => { ) assertCodegen( '

5

', - '5' + '5' + ) + assertCodegen( + '

52

', + '52' ) assertCodegen( '
6
', @@ -71,6 +75,10 @@ describe('mp:compiler-mp-toutiao', () => { '

9

', '9' ) + assertCodegen( + '

10

', + '10' + ) }) it('generate v-show directive', () => { diff --git a/packages/uni-template-compiler/lib/script/traverse/render-list.js b/packages/uni-template-compiler/lib/script/traverse/render-list.js index f96098b57a3aa2f4199a17da8ea821780918ea01..a9f3b7c55e28a6f47e47735f8594b57042dd9e93 100644 --- a/packages/uni-template-compiler/lib/script/traverse/render-list.js +++ b/packages/uni-template-compiler/lib/script/traverse/render-list.js @@ -16,7 +16,8 @@ const { traverseKey, processMemberExpression, getForIndexIdentifier, - isSimpleObjectExpression + isSimpleObjectExpression, + traverseFilter } = require('../../util') const getMemberExpr = require('./member-expr') @@ -185,7 +186,7 @@ module.exports = function traverseRenderList (path, state) { } }) } - } else if (forPath.isCallExpression() || (forPath.isObjectExpression() && !isSimpleObjectExpression(forPath.node))) { + } else if ((forPath.isCallExpression() && !traverseFilter(forPath.node.callee, state)) || (forPath.isObjectExpression() && !isSimpleObjectExpression(forPath.node))) { forPath.replaceWith(getMemberExpr(forPath, IDENTIFIER_FOR, forPath.node, forState)) } else { forPath.traverse(require('./visitor'), forState) diff --git a/packages/vue-cli-plugin-uni/packages/uni-cloud/dist/index.js b/packages/vue-cli-plugin-uni/packages/uni-cloud/dist/index.js index 40a6925e3d8eb596fade074afee306222b910dbd..1bb2d12cec855bc5a2bbf84b35409b2e5d5472e2 100644 --- a/packages/vue-cli-plugin-uni/packages/uni-cloud/dist/index.js +++ b/packages/vue-cli-plugin-uni/packages/uni-cloud/dist/index.js @@ -1 +1 @@ -var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function n(e,t,n){return e(n={path:t,exports:{},require:function(e,t){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==t&&n.path)}},n.exports),n.exports}var r=n((function(e,t){var n;e.exports=(n=n||function(e,t){var n=Object.create||function(){function e(){}return function(t){var n;return e.prototype=t,n=new e,e.prototype=null,n}}(),r={},o=r.lib={},s=o.Base={extend:function(e){var t=n(this);return e&&t.mixIn(e),t.hasOwnProperty("init")&&this.init!==t.init||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=o.WordArray=s.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||c).stringify(this)},concat:function(e){var t=this.words,n=e.words,r=this.sigBytes,o=e.sigBytes;if(this.clamp(),r%4)for(var s=0;s>>2]>>>24-s%4*8&255;t[r+s>>>2]|=i<<24-(r+s)%4*8}else for(s=0;s>>2]=n[s>>>2];return this.sigBytes+=o,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=s.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n,r=[],o=function(t){t=t;var n=987654321,r=4294967295;return function(){var o=((n=36969*(65535&n)+(n>>16)&r)<<16)+(t=18e3*(65535&t)+(t>>16)&r)&r;return o/=4294967296,(o+=.5)*(e.random()>.5?1:-1)}},s=0;s>>2]>>>24-o%4*8&255;r.push((s>>>4).toString(16)),r.push((15&s).toString(16))}return r.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r>>3]|=parseInt(e.substr(r,2),16)<<24-r%8*4;return new i.init(n,t/2)}},u=a.Latin1={stringify:function(e){for(var t=e.words,n=e.sigBytes,r=[],o=0;o>>2]>>>24-o%4*8&255;r.push(String.fromCharCode(s))}return r.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r>>2]|=(255&e.charCodeAt(r))<<24-r%4*8;return new i.init(n,t)}},l=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(u.stringify(e)))}catch(e){throw new Error("Malformed UTF-8 data")}},parse:function(e){return u.parse(unescape(encodeURIComponent(e)))}},h=o.BufferedBlockAlgorithm=s.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,r=n.words,o=n.sigBytes,s=this.blockSize,a=o/(4*s),c=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*s,u=e.min(4*c,o);if(c){for(var l=0;l>>24)|4278255360&(o<<24|o>>>8)}var s=this._hash.words,i=e[t+0],c=e[t+1],p=e[t+2],d=e[t+3],g=e[t+4],y=e[t+5],v=e[t+6],_=e[t+7],m=e[t+8],b=e[t+9],w=e[t+10],S=e[t+11],E=e[t+12],T=e[t+13],O=e[t+14],k=e[t+15],A=s[0],P=s[1],I=s[2],N=s[3];A=u(A,P,I,N,i,7,a[0]),N=u(N,A,P,I,c,12,a[1]),I=u(I,N,A,P,p,17,a[2]),P=u(P,I,N,A,d,22,a[3]),A=u(A,P,I,N,g,7,a[4]),N=u(N,A,P,I,y,12,a[5]),I=u(I,N,A,P,v,17,a[6]),P=u(P,I,N,A,_,22,a[7]),A=u(A,P,I,N,m,7,a[8]),N=u(N,A,P,I,b,12,a[9]),I=u(I,N,A,P,w,17,a[10]),P=u(P,I,N,A,S,22,a[11]),A=u(A,P,I,N,E,7,a[12]),N=u(N,A,P,I,T,12,a[13]),I=u(I,N,A,P,O,17,a[14]),A=l(A,P=u(P,I,N,A,k,22,a[15]),I,N,c,5,a[16]),N=l(N,A,P,I,v,9,a[17]),I=l(I,N,A,P,S,14,a[18]),P=l(P,I,N,A,i,20,a[19]),A=l(A,P,I,N,y,5,a[20]),N=l(N,A,P,I,w,9,a[21]),I=l(I,N,A,P,k,14,a[22]),P=l(P,I,N,A,g,20,a[23]),A=l(A,P,I,N,b,5,a[24]),N=l(N,A,P,I,O,9,a[25]),I=l(I,N,A,P,d,14,a[26]),P=l(P,I,N,A,m,20,a[27]),A=l(A,P,I,N,T,5,a[28]),N=l(N,A,P,I,p,9,a[29]),I=l(I,N,A,P,_,14,a[30]),A=h(A,P=l(P,I,N,A,E,20,a[31]),I,N,y,4,a[32]),N=h(N,A,P,I,m,11,a[33]),I=h(I,N,A,P,S,16,a[34]),P=h(P,I,N,A,O,23,a[35]),A=h(A,P,I,N,c,4,a[36]),N=h(N,A,P,I,g,11,a[37]),I=h(I,N,A,P,_,16,a[38]),P=h(P,I,N,A,w,23,a[39]),A=h(A,P,I,N,T,4,a[40]),N=h(N,A,P,I,i,11,a[41]),I=h(I,N,A,P,d,16,a[42]),P=h(P,I,N,A,v,23,a[43]),A=h(A,P,I,N,b,4,a[44]),N=h(N,A,P,I,E,11,a[45]),I=h(I,N,A,P,k,16,a[46]),A=f(A,P=h(P,I,N,A,p,23,a[47]),I,N,i,6,a[48]),N=f(N,A,P,I,_,10,a[49]),I=f(I,N,A,P,O,15,a[50]),P=f(P,I,N,A,y,21,a[51]),A=f(A,P,I,N,E,6,a[52]),N=f(N,A,P,I,d,10,a[53]),I=f(I,N,A,P,w,15,a[54]),P=f(P,I,N,A,c,21,a[55]),A=f(A,P,I,N,m,6,a[56]),N=f(N,A,P,I,k,10,a[57]),I=f(I,N,A,P,v,15,a[58]),P=f(P,I,N,A,T,21,a[59]),A=f(A,P,I,N,g,6,a[60]),N=f(N,A,P,I,S,10,a[61]),I=f(I,N,A,P,p,15,a[62]),P=f(P,I,N,A,b,21,a[63]),s[0]=s[0]+A|0,s[1]=s[1]+P|0,s[2]=s[2]+I|0,s[3]=s[3]+N|0},_doFinalize:function(){var t=this._data,n=t.words,r=8*this._nDataBytes,o=8*t.sigBytes;n[o>>>5]|=128<<24-o%32;var s=e.floor(r/4294967296),i=r;n[15+(o+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),n[14+(o+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),t.sigBytes=4*(n.length+1),this._process();for(var a=this._hash,c=a.words,u=0;u<4;u++){var l=c[u];c[u]=16711935&(l<<8|l>>>24)|4278255360&(l<<24|l>>>8)}return a},clone:function(){var e=s.clone.call(this);return e._hash=this._hash.clone(),e}});function u(e,t,n,r,o,s,i){var a=e+(t&n|~t&r)+o+i;return(a<>>32-s)+t}function l(e,t,n,r,o,s,i){var a=e+(t&r|n&~r)+o+i;return(a<>>32-s)+t}function h(e,t,n,r,o,s,i){var a=e+(t^n^r)+o+i;return(a<>>32-s)+t}function f(e,t,n,r,o,s,i){var a=e+(n^(t|~r))+o+i;return(a<>>32-s)+t}t.MD5=s._createHelper(c),t.HmacMD5=s._createHmacHelper(c)}(Math),n.MD5)})),n((function(e,t){var n,o,s;e.exports=(o=(n=r).lib.Base,s=n.enc.Utf8,void(n.algo.HMAC=o.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=s.parse(t));var n=e.blockSize,r=4*n;t.sigBytes>r&&(t=e.finalize(t)),t.clamp();for(var o=this._oKey=t.clone(),i=this._iKey=t.clone(),a=o.words,c=i.words,u=0;u{t.success&&t.success(e),t.complete&&t.complete(e)},e=>{t.fail&&t.fail(e),t.complete&&t.complete(e)})}}class i extends Error{constructor(e){super(e.message),this.errMsg=e.message||"",Object.defineProperties(this,{code:{get:()=>e.code},requestId:{get:()=>e.requestId},message:{get(){return this.errMsg},set(e){this.errMsg=e}}})}}let a;try{a=require("uni-stat-config").default||require("uni-stat-config")}catch(e){a={appid:""}}let c,u;function l(e=8){let t="";for(;t.length{t(Object.assign(e,{complete(e){e||(e={}),"h5"===process.env.VUE_APP_PLATFORM&&"development"===process.env.NODE_ENV&&e.errMsg&&0===e.errMsg.indexOf("request:fail")&&console.warn("发布H5,需要在uniCloud后台操作,绑定安全域名,否则会因为跨域问题而无法访问。教程参考:https://uniapp.dcloud.io/uniCloud/quickstart?id=useinh5");const t=e.data&&e.data.header&&e.data.header["x-serverless-request-id"]||e.header&&e.header["request-id"];if(!e.statusCode||e.statusCode>=400)return r(new i({code:"SYS_ERR",message:e.errMsg||"request:fail",requestId:t}));const o=e.data;if(o.error)return r(new i({code:o.error.code,message:o.error.message,requestId:t}));o.result=o.data,o.requestId=t,delete o.data,n(o)}}))})}};const y={request:e=>uni.request(e),uploadFile:e=>uni.uploadFile(e),setStorageSync:(e,t)=>uni.setStorageSync(e,t),getStorageSync:e=>uni.getStorageSync(e),removeStorageSync:e=>uni.removeStorageSync(e),clearStorageSync:()=>uni.clearStorageSync()};class v{constructor(e){["spaceId","clientSecret"].forEach(t=>{if(!Object.prototype.hasOwnProperty.call(e,t))throw new Error("缺少参数"+t)}),this.config=Object.assign({},{endpoint:"https://api.bspapp.com"},e),this.config.provider="aliyun",this.config.requestUrl=this.config.endpoint+"/client",this.config.envType=this.config.envType||"public",this.config.accessTokenKey="access_token_"+this.config.spaceId,this.adapter=y}get hasAccessToken(){return!!this.accessToken}setAccessToken(e){this.accessToken=e}requestWrapped(e){return g.wrappedRequest(e,this.adapter.request)}requestAuth(e){return this.requestWrapped(e)}request(e,t){return this.hasAccessToken?t?this.requestWrapped(e):this.requestWrapped(e).catch(t=>new Promise((e,n)=>{!t||"GATEWAY_INVALID_TOKEN"!==t.code&&"InvalidParameter.InvalidToken"!==t.code?n(t):e()}).then(()=>this.getAccessToken()).then(()=>{const t=this.rebuildRequest(e);return this.request(t,!0)})):this.getAccessToken().then(()=>{const t=this.rebuildRequest(e);return this.request(t,!0)})}rebuildRequest(e){const t=Object.assign({},e);return t.data.token=this.accessToken,t.header["x-basement-token"]=this.accessToken,t.header["x-serverless-sign"]=g.sign(t.data,this.config.clientSecret),t}setupRequest(e,t){const n=Object.assign({},e,{spaceId:this.config.spaceId,timestamp:Date.now()}),r={"Content-Type":"application/json"};return"auth"!==t&&(n.token=this.accessToken,r["x-basement-token"]=this.accessToken),r["x-serverless-sign"]=g.sign(n,this.config.clientSecret),{url:this.config.requestUrl,method:"POST",data:n,dataType:"json",header:r}}getAccessToken(){return this.requestAuth(this.setupRequest({method:"serverless.auth.user.anonymousAuthorize",params:"{}"},"auth")).then(e=>new Promise((t,n)=>{e.result&&e.result.accessToken?(this.setAccessToken(e.result.accessToken),t(this.accessToken)):n(new i({code:"AUTH_FAILED",message:"获取accessToken失败"}))}))}authorize(){this.getAccessToken()}callFunction(e){const t={method:"serverless.function.runtime.invoke",params:JSON.stringify({functionTarget:e.name,functionArgs:e.data||{}})};return this.request(this.setupRequest(t))}getOSSUploadOptionsFromPath(e){const t={method:"serverless.file.resource.generateProximalSign",params:JSON.stringify(e)};return this.request(this.setupRequest(t))}uploadFileToOSS({url:e,formData:t,name:n,filePath:r,fileType:o,onUploadProgress:s}){return new Promise((a,c)=>{const u=this.adapter.uploadFile({url:e,formData:t,name:n,filePath:r,fileType:o,header:{"X-OSS-server-side-encrpytion":"AES256"},success(e){e&&e.statusCode<400?a(e):c(new i({code:"UPLOAD_FAILED",message:"文件上传失败"}))},fail(e){c(e)}});"function"==typeof s&&u&&"function"==typeof u.onProgressUpdate&&u.onProgressUpdate(e=>{s({loaded:e.totalBytesSent,total:e.totalBytesExpectedToSend})})})}reportOSSUpload(e){const t={method:"serverless.file.resource.report",params:JSON.stringify(e)};return this.request(this.setupRequest(t))}uploadFile({filePath:e,cloudPath:t,fileType:n="image",onUploadProgress:r,config:o}){if(!t)throw new i({code:"CLOUDPATH_REQUIRED",message:"cloudPath不可为空"});const s=o&&o.envType||this.config.envType;let a,c;return this.getOSSUploadOptionsFromPath({env:s,filename:t}).then(t=>{const o=t.result;a=o.id,c="https://"+o.cdnDomain+"/"+o.ossPath;const s={url:"https://"+o.host,formData:{"Cache-Control":"max-age=2592000","Content-Disposition":"attachment",OSSAccessKeyId:o.accessKeyId,Signature:o.signature,host:o.host,id:a,key:o.ossPath,policy:o.policy,success_action_status:200},fileName:"file",name:"file",filePath:e,fileType:n};return this.uploadFileToOSS(Object.assign({},s,{onUploadProgress:r}))}).then(()=>this.reportOSSUpload({id:a})).then(t=>new Promise((n,r)=>{t.success?n({success:!0,filePath:e,fileID:c}):r(new i({code:"UPLOAD_FAILED",message:"文件上传失败"}))}))}deleteFile({fileList:e}){const t={method:"serverless.file.resource.delete",params:JSON.stringify({id:e[0]})};return this.request(this.setupRequest(t))}getTempFileURL({fileList:e}){return new Promise((t,n)=>{t({fileList:e.map(e=>({fileID:e,tempFileURL:e}))})})}}const _={init(e){const t=new v(e);["deleteFile, getTempFileURL"].forEach(e=>{t[e]=s(t[e]).bind(t)});const n={signInAnonymously:function(){return t.authorize()},getLoginState:function(){return Promise.resolve(!1)}};return t.auth=function(){return n},t.constomAuth=t.auth,t}};var m,b,w=n((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.getQuery=function(e,t){if("undefined"==typeof window)return!1;var n=t||window.location.search,r=new RegExp("(^|&)"+e+"=([^&]*)(&|$)"),o=n.substr(n.indexOf("?")+1).match(r);return null!=o?o[2]:""},t.getHash=function(e){var t=window.location.hash.match(new RegExp("[#?&/]"+e+"=([^&#]*)"));return t?t[1]:""},t.removeParam=function(e,t){var n=t.split("?")[0],r=[],o=-1!==t.indexOf("?")?t.split("?")[1]:"";if(""!==o){for(var s=(r=o.split("&")).length-1;s>=0;s-=1)r[s].split("=")[0]===e&&r.splice(s,1);n=n+"?"+r.join("&")}return n},t.createPromiseCallback=function(){var e;if(!Promise){(e=function(){}).promise={};var t=function(){throw new Error('Your Node runtime does support ES6 Promises. Set "global.Promise" to your preferred implementation of promises.')};return Object.defineProperty(e.promise,"then",{get:t}),Object.defineProperty(e.promise,"catch",{get:t}),e}var n=new Promise((function(t,n){e=function(e,r){return e?n(e):t(r)}}));return e.promise=n,e},t.getWeixinCode=function(){return t.getQuery("code")||t.getHash("code")},t.getMiniAppCode=function(){return new Promise((function(e,t){wx.login({success:function(t){e(t.code)},fail:function(e){t(e)}})}))},t.isArray=function(e){return"[object Array]"===Object.prototype.toString.call(e)},t.isString=function(e){return"string"==typeof e},t.isUndefined=function(e){return void 0===e},t.isInstanceOf=function(e,t){return e instanceof t},t.isFormData=function(e){return"[object FormData]"===Object.prototype.toString.call(e)},t.genSeqId=function(){return Math.random().toString(16).slice(2)},t.getArgNames=function(e){var t=e.toString();return t.slice(t.indexOf("(")+1,t.indexOf(")")).match(/([^\s,]+)/g)},t.formatUrl=function(e,t,n){void 0===n&&(n={});var r=/\?/.test(t),o="";for(var s in n)""===o?!r&&(t+="?"):o+="&",o+=s+"="+encodeURIComponent(n[s]);return/^http(s)?\:\/\//.test(t+=o)?t:""+e+t}})),S="dist/index.js",E="./dist/index.d.ts",T={build:"npm run tsc && webpack",tsc:"tsc -p tsconfig.json","tsc:w":"tsc -p tsconfig.json -w",test:"jest --verbose false -i",e2e:'NODE_ENV=e2e webpack && jest --config="./jest.e2e.config.js" --verbose false -i "e2e"',start:"webpack-dev-server --hot --open",eslint:'eslint "./**/*.js" "./**/*.ts"',"eslint-fix":'eslint --fix "./**/*.js" "./**/*.ts"',test_web:"npm run tsc && webpack-dev-server --devtool eval-source-map --progress --colors --hot --inline --content-base ./dist --host jimmytest-088bef.tcb.qcloud.la --port 80 --disableHostCheck true --mode development --config webpack.test.js"},O={type:"git",url:"https://github.com/TencentCloudBase/tcb-js-sdk"},k=["tcb","js-sdk"],A={"@cloudbase/adapter-interface":"^0.2.0","@cloudbase/adapter-wx_mp":"^0.2.1","@cloudbase/database":"^0.9.8"},P={"@babel/core":"^7.6.2","@babel/plugin-proposal-class-properties":"^7.5.5","@babel/plugin-proposal-object-rest-spread":"^7.6.2","@babel/plugin-transform-runtime":"^7.6.2","@babel/preset-env":"^7.6.2","@babel/preset-typescript":"^7.6.0","@babel/runtime":"^7.6.2","@types/jest":"^23.1.4","@types/node":"^10.14.4","@types/superagent":"^4.1.4",axios:"^0.19.0","babel-eslint":"^10.0.1","babel-loader":"^8.0.6","babel-polyfill":"^6.26.0",eslint:"^5.16.0","eslint-config-alloy":"^1.4.2","eslint-config-prettier":"^4.1.0","eslint-plugin-prettier":"^3.0.1","eslint-plugin-typescript":"^1.0.0-rc.3",express:"^4.17.1",husky:"^3.1.0",jest:"^24.7.1","jest-puppeteer":"^4.3.0","lint-staged":"^9.5.0","power-assert":"^1.6.1",puppeteer:"^1.20.0","serve-static":"^1.14.1","ts-jest":"^23.10.4","ts-loader":"^6.2.1",typescript:"^3.4.3","typescript-eslint-parser":"^22.0.0",webpack:"^4.41.3","webpack-bundle-analyzer":"^3.4.1","webpack-cli":"^3.3.0","webpack-dev-server":"^3.3.1","webpack-merge":"^4.2.2","webpack-visualizer-plugin":"^0.1.11"},I={hooks:{"pre-commit":"lint-staged"}},N={name:"tcb-js-sdk",version:"1.3.5",description:"js sdk for tcb",main:S,types:E,scripts:T,repository:O,keywords:k,author:"jimmyjzhang",license:"ISC",dependencies:A,devDependencies:P,husky:I,"lint-staged":{"*.{js,ts}":["eslint --fix","git add"]}},C=(m=Object.freeze({__proto__:null,name:"tcb-js-sdk",version:"1.3.5",description:"js sdk for tcb",main:S,types:E,scripts:T,repository:O,keywords:k,author:"jimmyjzhang",license:"ISC",dependencies:A,devDependencies:P,husky:I,default:N}))&&m.default||m,x=n((function(t,n){var r=e&&e.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t};Object.defineProperty(n,"__esModule",{value:!0});var o=r(C);n.SDK_VERISON=o.version,n.ACCESS_TOKEN="access_token",n.ACCESS_TOKEN_Expire="access_token_expire",n.REFRESH_TOKEN="refresh_token",n.ANONYMOUS_UUID="anonymous_uuid",n.LOGIN_TYPE_KEY="login_type",n.protocol="undefined"!=typeof location&&"http:"===location.protocol?"http:":"https:",n.BASE_URL="e2e"===process.env.NODE_ENV&&"pre"===process.env.END_POINT?"//tcb-pre.tencentcloudapi.com/web":"//tcb-api.tencentcloudapi.com/web"}));!function(e){e.local="local",e.none="none",e.session="session"}(b||(b={}));var R=function(){},D=function(){};var U=Object.freeze({__proto__:null,get StorageType(){return b},AbstractSDKRequest:R,AbstractStorage:D,formatUrl:function(e,t,n){void 0===n&&(n={});var r=/\?/.test(t),o="";for(var s in n)""===o?!r&&(t+="?"):o+="&",o+=s+"="+encodeURIComponent(n[s]);return/^http(s)?\:\/\//.test(t+=o)?t:""+e+t}}),q=n((function(t,n){var r,o=e&&e.__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)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),s=e&&e.__assign||function(){return(s=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]=0?JSON.parse(n).content:""},e.prototype.removeStore=function(e){this.storageClass.removeItem(e)},e}();n.Cache=s;var i=function(e){function t(){var t=e.call(this)||this;return j.Adapter.adapter.root.tcbObject||(j.Adapter.adapter.root.tcbObject={}),t}return o(t,e),t.prototype.setItem=function(e,t){j.Adapter.adapter.root.tcbObject[e]=t},t.prototype.getItem=function(e){return j.Adapter.adapter.root.tcbObject[e]},t.prototype.removeItem=function(e){delete j.Adapter.adapter.root.tcbObject[e]},t.prototype.clear=function(){delete j.Adapter.adapter.root.tcbObject},t}(U.AbstractStorage)})),M=n((function(t,n){var r,o=e&&e.__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)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),s=e&&e.__spreadArrays||function(){for(var e=0,t=0,n=arguments.length;t0},e}();n.IEventEmitter=c;var u=new c;n.addEventListener=function(e,t){u.on(e,t)},n.activateEvent=function(e,t){void 0===t&&(t={}),u.fire(e,t)},n.removeEventListener=function(e,t){u.off(e,t)},n.EVENTS={LOGIN_STATE_CHANGED:"loginStateChanged",LOGIN_STATE_EXPIRE:"loginStateExpire",LOGIN_TYPE_CHANGE:"loginTypeChanged",ANONYMOUS_CONVERTED:"anonymousConverted",REFRESH_ACCESS_TOKEN:"refreshAccessToken"}})),F=n((function(t,n){var r=e&&e.__assign||function(){return(r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]Date.now())return[2,{credential:{accessToken:e,refreshToken:this.cache.getStore(this.refreshTokenKey)}}];this.cache.removeStore(this.accessTokenKey),this.cache.removeStore(this.accessTokenExpireKey)}if(!1===Object.values(c).includes(c[this.scope]))throw new Error("错误的scope类型");return j.Adapter.runtime!==j.RUNTIME.WX_MP?[3,2]:[4,l.getMiniAppCode()];case 1:return n=i.sent(),[3,4];case 2:return[4,l.getWeixinCode()];case 3:if(!(n=i.sent()))return[2,this.redirect()];i.label=4;case 4:return r=function(e){switch(e){case c.snsapi_login:return"WECHAT-OPEN";default:return"WECHAT-PUBLIC"}}(this.scope),[4,this.getRefreshTokenByWXCode(this.appid,r,n)];case 5:return o=i.sent(),s=o.refreshToken,this.cache.setStore(this.refreshTokenKey,s),o.accessToken&&this.cache.setStore(this.accessTokenKey,o.accessToken),o.accessTokenExpire&&this.cache.setStore(this.accessTokenExpireKey,o.accessTokenExpire+Date.now()),M.activateEvent(M.EVENTS.LOGIN_STATE_CHANGED),M.activateEvent(M.EVENTS.LOGIN_TYPE_CHANGE,h.LOGINTYPE.WECHAT),[2,{credential:{refreshToken:s}}]}}))}))},t.prototype.redirect=function(){var e=l.removeParam("code",location.href);e=l.removeParam("state",e),e=encodeURIComponent(e);var t="//open.weixin.qq.com/connect/oauth2/authorize";"snsapi_login"===this.scope&&(t="//open.weixin.qq.com/connect/qrconnect"),"redirect"===u[this.loginMode]&&(location.href=t+"?appid="+this.appid+"&redirect_uri="+e+"&response_type=code&scope="+this.scope+"&state="+this.state+"#wechat_redirect")},t}(h.default);n.default=p})),H=n((function(t,n){var r,o=e&&e.__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)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),s=e&&e.__assign||function(){return(s=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]{y.request({url:W("https:",t),data:n,method:"POST",header:r,success(t){e(t)},fail(e){o(e)}})})}upload(e){return new Promise((t,n)=>{const{url:r,file:o,data:s,headers:i,fileType:a}=e,c=y.uploadFile({url:W("https:",r),name:"file",formData:Object.assign({},s),filePath:o,fileType:a,header:i,success(e){const n={statusCode:e.statusCode,data:e.data||{}};200===e.statusCode&&s.success_action_status&&(n.statusCode=parseInt(s.success_action_status,10)),t(n)},fail(e){"mp-alipay"===process.env.VUE_APP_PLATFORM&&"development"===process.env.NODE_ENV&&console.warn("支付宝小程序开发工具上传腾讯云时无法准确判断是否上传成功,请使用真机测试"),n(new Error(e.errMsg||"uploadFile:fail"))}});"function"==typeof e.onUploadProgress&&c&&"function"==typeof c.onProgressUpdate&&c.onProgressUpdate(t=>{e.onUploadProgress({loaded:t.totalBytesSent,total:t.totalBytesExpectedToSend})})})}}const J={setItem(e,t){y.setStorageSync(e,t)},getItem:e=>y.getStorageSync(e),removeItem(e){y.removeStorageSync(e)},clear(){y.clearStorageSync()}};const X={genAdapter:function(){return{root:{},reqClass:z,localStorage:J,primaryStorage:"local"}},isMatch:function(){return!0},runtime:"uni_app"};$.useAdapters(X);const Q=$,Z=Q.init;Q.init=function(e){e.env=e.spaceId;const t=Z.call(this,e);t.config.provider="tencent",t.config.spaceId=e.spaceId;const n=t.auth;t.auth=function(e){const t=n.call(this,e);return["linkAndRetrieveDataWithTicket","signInAnonymously","signOut","getAccessToken","getLoginState","signInWithTicket","getUserInfo"].forEach(e=>{t[e]=s(t[e]).bind(t)}),t},t.customAuth=t.auth;return["deleteFile","getTempFileURL","downloadFile"].forEach(e=>{t[e]=s(t[e]).bind(t)}),t};let ee,te,ne,re;function oe({name:e,data:t}){const{localAddress:n,localPort:r}=this,o={aliyun:"aliyun",tencent:"tcb"}[this.config.provider],s=this.config.spaceId,a=`http://${n}:${r}/system/check-function`,c=`http://${n}:${r}/cloudfunctions/${e}`;return new Promise((t,n)=>{y.request({method:"POST",url:a,data:{name:e,platform:process.env.VUE_APP_PLATFORM,provider:o,spaceId:s},timeout:3e3,success(e){t(e)},fail(){t({data:{code:"NETWORK_ERROR",message:"连接本地调试服务失败,请检查客户端是否和主机在同一局域网下,自动切换为已部署的云函数。"}})}})}).then(({data:e}={})=>{const{code:t,message:n}=e||{};return{code:0===t?0:t||"SYS_ERR",message:n||"SYS_ERR"}}).then(({code:n,message:r})=>{if(0!==n){switch(n){case"MODULE_ENCRYPTED":console.error(`此云函数(${e})依赖加密公共模块不可本地调试,自动切换为云端已部署的云函数`);break;case"FUNCTION_ENCRYPTED":console.error(`此云函数(${e})已加密不可本地调试,自动切换为云端已部署的云函数`);break;case"ACTION_ENCRYPTED":console.error(r||"需要访问加密的uni-clientDB-action,自动切换为云端环境");break;case"NETWORK_ERROR":{const e="连接本地调试服务失败,请检查客户端是否和主机在同一局域网下";throw console.error(e),new Error(e)}case"SWITCH_TO_CLOUD":break;default:{const e=`检测本地调试服务出现错误:${r},请检查网络环境或重启客户端再试`;throw console.error(e),new Error(e)}}return this.originCallFunction({name:e,data:t})}return new Promise((n,r)=>{ee||(ee=h(),te=d());const a=e,u=s,l={tencent:"t",aliyun:"a"}[this.config.provider],f=Object.assign({},te,{fn:a,sid:u,pvd:l}),p={...t,clientInfo:ee,uniCloudClientInfo:encodeURIComponent(JSON.stringify(f))},g=y.getStorageSync("uni_id_token")||y.getStorageSync("uniIdToken");g&&(p.uniIdToken=g);{const{uuid:e}=uni.getSystemInfoSync();p.uniCloudUuid=e}y.request({method:"POST",url:c,data:{provider:o,platform:process.env.VUE_APP_PLATFORM,param:p},success:({statusCode:e,data:t}={})=>!e||e>=400?r(new i({code:t.code||"SYS_ERR",message:t.message||"request:fail"})):n({result:t}),fail(e){r(new i({code:e.code||e.errCode||"SYS_ERR",message:e.message||e.errMsg||"request:fail"}))}})})})}function se(e){ne||(ne=h(),re=d());const t=JSON.parse(JSON.stringify(e.data||{})),n=e.name,r=this.config.spaceId,o={tencent:"t",aliyun:"a"}[this.config.provider],s=Object.assign({},re,{fn:n,sid:r,pvd:o});if(Object.assign(t,{clientInfo:ne,uniCloudClientInfo:encodeURIComponent(JSON.stringify(s))}),!t.uniIdToken){const e=y.getStorageSync("uni_id_token")||y.getStorageSync("uniIdToken");e&&(t.uniIdToken=e)}{const{uuid:e}=uni.getSystemInfoSync();t.uniCloudUuid=e}return e.data=t,e}function ie(e){const t=e.callFunction;e.callFunction=function(e){let n;return n=this.isReady?Promise.resolve():this.initUniCloud,n.then(()=>{const n=se.call(this,e),r={aliyun:"aliyun",tencent:"tcb"}[this.config.provider];return new Promise((o,s)=>{t.call(this,n).then(t=>{if(this.config.useDebugFunction&&t&&t.requestId){const n=JSON.stringify({spaceId:this.config.spaceId,functionName:e.name,requestId:t.requestId});console.log(`[${r}-request]${n}[/${r}-request]`)}o(t)}).catch(t=>{if(this.config.useDebugFunction&&t&&t.requestId){const n=JSON.stringify({spaceId:this.config.spaceId,functionName:e.name,requestId:t.requestId});console.log(`[${r}-request]${n}[/${r}-request]`)}t&&t.message&&(t.message=`[${e.name}]: ${t.message}`),s(t)})})})};const n=e.callFunction;e.originCallFunction=e.callFunction,e.callFunction=function(t){return s((function(t){let r;return r=e.isReady?Promise.resolve():e.initUniCloud,r.then(()=>"development"===process.env.NODE_ENV&&e.debugInfo&&!e.debugInfo.forceRemote&&process.env.UNI_CLOUD_PROVIDER?oe.call(this,t):n.call(this,t))})).call(this,t)}}const ae=Symbol("CLIENT_DB_INTERNAL");function ce(e,t){return e.then="DoNotReturnProxyWithAFunctionNamedThen",e._internalType=ae,new Proxy(e,{get:(e,n,r)=>function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}(e,n)||e[n]||"string"!=typeof n?e[n]:t.get(e,n,r)})}class ue extends Error{constructor(e,t){super(e),this.code=t}}function le(e){switch(t=e,Object.prototype.toString.call(t).slice(8,-1).toLowerCase()){case"array":return e.map(e=>le(e));case"object":return e._internalType===ae||Object.keys(e).forEach(t=>{e[t]=le(e[t])}),e;case"regexp":return{$regexp:{source:e.source,flags:e.flags}};case"date":return{$date:e.toISOString()};default:return e}var t}function he(){const e=y.getStorageSync("uni_id_token")||"",t=e.split(".");if(e&&3!==t.length)return{uid:null,role:[],permission:[]};let n;try{n=JSON.parse((r=e[1],decodeURIComponent(atob(r).split("").map((function(e){return"%"+("00"+e.charCodeAt(0).toString(16)).slice(-2)})).join(""))))}catch(e){throw new Error("获取当前用户信息出错,详细错误信息为:"+e.message)}var r;return n}async function fe(e,t){const n=`http://${e}:${t}/system/ping`;try{const e=await(r={url:n,timeout:500},new Promise((e,t)=>{y.request({...r,success(t){e(t)},fail(e){t(e)}})}));return!(!e.data||0!==e.data.code)}catch(e){return!1}var r}let pe=new class{init(e){let t={};const n=!1!==e.debugFunction&&"development"===process.env.NODE_ENV&&("h5"===process.env.VUE_APP_PLATFORM&&navigator.userAgent.indexOf("HBuilderX")>0||"app-plus"===process.env.VUE_APP_PLATFORM);switch(e.provider){case"tencent":t=Q.init(Object.assign(e,{useDebugFunction:n}));break;case"aliyun":t=_.init(Object.assign(e,{useDebugFunction:n}));break;default:throw new Error("未提供正确的provider参数")}const r=process.env.UNICLOUD_DEBUG;"development"===process.env.NODE_ENV&&r&&!r.code&&(t.debugInfo=r),t.isReady=!1;const o=t.auth();return t.initUniCloud=o.getLoginState().then(e=>e?Promise.resolve():o.signInAnonymously()).then(()=>{if("development"===process.env.NODE_ENV&&t.debugInfo){const{address:e,servePort:n}=t.debugInfo;return async function(e,t){let n;for(let r=0;r{if(e)t.localAddress=e,t.localPort=n;else if(t.debugInfo){const e="app-plus"===process.env.VUE_APP_PLATFORM?"error":"warn",n=console[e];"remote"===t.debugInfo.initialLaunchType?(t.debugInfo.forceRemote=!0,n("当前客户端和HBuilderX不在同一局域网下(或其他网络原因无法连接HBuilderX),uniCloud本地调试服务不对当前客户端生效。\n- 如果不使用uniCloud本地调试服务,请直接忽略此信息。\n- 如需使用uniCloud本地调试服务,请将客户端与主机连接到同一局域网下并重新运行到客户端。\n- 如果在HBuilderX开启的状态下切换过网络环境,请重启HBuilderX后再试")):n("无法连接uniCloud本地调试服务,请检查当前客户端是否与主机在同一局域网下。\n- 如需使用uniCloud本地调试服务,请将客户端与主机连接到同一局域网下并重新运行到客户端。\n- 如果在HBuilderX开启的状态下切换过网络环境,请重启HBuilderX后再试")}}).then(()=>new Promise(e=>{"quickapp-native"===process.env.VUE_APP_PLATFORM?(u="android",uni.getStorage({key:"__DC_CLOUD_UUID",success(t){c=t.data?t.data:l(32),e()}})):setTimeout(()=>{u=uni.getSystemInfoSync().platform,c=uni.getStorageSync("__DC_CLOUD_UUID")||l(32),e()},0)})).then(()=>{t.isReady=!0}),ie(t),function(e){const t=e.uploadFile;e.uploadFile=function(e){let n;return n=this.isReady?Promise.resolve():this.initUniCloud,n.then(()=>t.call(this,e))};const n=e.uploadFile;e.uploadFile=function(e){return s(n).call(this,e)}}(t),function(e){e.database=function(){if(this._database)return this._database;const t={},n={};class r{constructor(e,t,n){this.content=e,this.prevStage=t,this.actionName=n}toJSON(){let e=this;const t=[e.content];for(;e.prevStage;)e=e.prevStage,t.push(e.content);return{$db:t.reverse().map(e=>({$method:e.$method,$param:e.$param}))}}get useAggregate(){let e=this,t=!1;for(;e.prevStage;){e=e.prevStage;const n=e.content.$method;if("aggregate"===n||"pipeline"===n){t=!0;break}}return t}get count(){if(!this.useAggregate)return function(){return this._send("count",Array.from(arguments))};const e=this;return function(){return i({$method:"count",$param:le(Array.from(arguments))},e,e.actionName)}}get(){return this._send("get",Array.from(arguments))}add(){return this._send("add",Array.from(arguments))}remove(){return this._send("remove",Array.from(arguments))}update(){return this._send("update",Array.from(arguments))}end(){return this._send("end",Array.from(arguments))}set(){throw new Error("客户端禁止使用set方法")}_send(r,o){const s=this.toJSON();return s.$db.push({$method:r,$param:o}),e.callFunction({name:"DCloud-clientDB",data:{action:this.actionName,command:s}}).then(e=>{const{code:r,message:o,token:s,tokenExpired:i}=e.result;return r?Promise.reject(new ue(o,r)):(s&&i&&t.refreshToken&&t.refreshToken.forEach(e=>{e({token:s,tokenExpired:i})}),s&&i&&n.refreshToken&&n.refreshToken.forEach(e=>{e({token:s,tokenExpired:i})}),Promise.resolve(e))}).catch(e=>{const t=new ue(e.message,e.code||"SYSTEM_ERROR");return n.error&&n.error.forEach(e=>{e(t)}),/fc_function_not_found|FUNCTION_NOT_FOUND/g.test(e.message)&&console.warn("clientDB未初始化,请在web控制台保存一次schema以开启clientDB"),Promise.reject(e)})}}const o=["db.Geo","db.command","command.aggregate"];function s(e,t){return o.indexOf(`${e}.${t}`)>-1}function i(e,t,n){return ce(new r(e,t,n),{get(e,t){let r="db";return e&&e.content&&(r=e.content.$method),s(r,t)?i({$method:t},e,n):function(){return i({$method:t,$param:le(Array.from(arguments))},e,n)}}})}function a({path:e,method:t}){return class{constructor(){this.param=Array.from(arguments)}toJSON(){return{$newDb:[...e.map(e=>({$method:e})),{$method:t,$param:this.param}]}}}}const c={auth:{on:(e,n)=>{t[e]=t[e]||[],t[e].indexOf(n)>-1||t[e].push(n)},off:(e,n)=>{t[e]=t[e]||[];const r=t[e].indexOf(n);-1!==r&&t[e].splice(r,1)}},on:(e,t)=>{n[e]=n[e]||[],n[e].indexOf(t)>-1||n[e].push(t)},off:(e,t)=>{n[e]=n[e]||[];const r=n[e].indexOf(t);-1!==r&&n[e].splice(r,1)},env:ce({},{get:(e,t)=>({$env:t})}),action:e=>ce({},{get:(t,n)=>s("db",n)?i({$method:n},null,e):function(){return i({$method:n,$param:le(Array.from(arguments))},null,e)}}),Geo:ce({},{get:(e,t)=>a({path:["Geo"],method:t})}),getCloudEnv:function(e){if("string"!=typeof e||!e.trim())throw new Error("getCloudEnv参数错误");return{$env:e.replace("$cloudEnv_","")}},get serverDate(){return a({path:[],method:"serverDate"})},get RegExp(){return a({path:[],method:"RegExp"})}},u=ce(c,{get:(e,t)=>s("db",t)?i({$method:t}):function(){return i({$method:t,$param:le(Array.from(arguments))})}});return this._database=u,u}}(t),function(e){e.getCurrentUserInfo=he}(t),t.init=this.init,t}};{let e={};if(1===process.env.UNI_CLOUD_PROVIDER.length)e=process.env.UNI_CLOUD_PROVIDER[0],pe=pe.init(e);else{const e=["auth","callFunction","uploadFile","deleteFile","getTempFileURL","downloadFile","database","getCurrentUSerInfo"],t=process.env.UNI_CLOUD_PROVIDER.length>0?"应用有多个服务空间,请通过uniCloud.init方法指定要使用的服务空间":"应用未关联服务空间,请在cloudfunctions目录右键关联服务空间";e.forEach(e=>{pe[e]=function(){return console.error(t),Promise.reject(new i({code:"SYS_ERR",message:t}))}})}Object.assign(pe,{get mixinDatacom(){return e=pe,{props:{localdata:{type:Array,default:()=>[]},options:{type:[Object,Array],default:()=>({})},collection:{type:String,default:""},action:{type:String,default:""},field:{type:String,default:""},orderby:{type:String,default:""},where:{type:[String,Object],default:""},pageData:{type:String,default:"add"},pageCurrent:{type:Number,default:1},pageSize:{type:Number,default:20},getcount:{type:[Boolean,String],default:!1},gettree:{type:[Boolean,String],default:!1},gettreepath:{type:[Boolean,String],default:!1},startwith:{type:String,default:""},limitlevel:{type:Number,default:10},groupby:{type:String,default:""},groupField:{type:String,default:""},distinct:{type:[Boolean,String],default:!1},manual:{type:Boolean,default:!1}},data:()=>({mixinDatacomLoading:!1,mixinDatacomHasMore:!1,mixinDatacomResData:[],mixinDatacomErrorMessage:"",mixinDatacomPage:{}}),created(){this.mixinDatacomPage={current:this.pageCurrent,size:this.pageSize,count:0},this.$watch(()=>{var e=[];return["pageCurrent","pageSize","collection","action","field","orderby","where","getont","getcount","gettree","groupby","groupField","distinct"].forEach(t=>{e.push(this[t])}),e},(e,t)=>{let n=!1;const r=[];for(let o=2;o{this.mixinDatacomLoading=!1;const{data:r,count:o}=n.result;this.getcount&&(this.mixinDatacomPage.count=o),this.mixinDatacomHasMore=r.length{this.mixinDatacomLoading=!1,this.mixinDatacomErrorMessage=e,n&&n(e)}))},mixinDatacomGet(t={}){let n=e.database();const r=t.action||this.action;r&&(n=n.action(r));const o=t.collection||this.collection;n=n.collection(o);const s=t.where||this.where;s&&Object.keys(s).length&&(n=n.where(s));const i=t.field||this.field;i&&(n=n.field(i));const a=t.groupby||this.groupby;a&&(n=n.groupby(a));const c=t.groupField||this.groupField;c&&(n=n.groupField(c)),!0===(void 0!==t.distinct?t.distinct:this.distinct)&&(n=n.distinct());const u=t.orderby||this.orderby;u&&(n=n.orderBy(u));const l=void 0!==t.pageCurrent?t.pageCurrent:this.mixinDatacomPage.current,h=void 0!==t.pageSize?t.pageSize:this.mixinDatacomPage.size,f=void 0!==t.getcount?t.getcount:this.getcount,p=void 0!==t.gettree?t.gettree:this.gettree,d=void 0!==t.gettreepath?t.gettreepath:this.gettreepath,g=void 0!==t.limitlevel?t.limitlevel:this.limitlevel,y=void 0!==t.startwith?t.startwith:this.startwith,v={getCount:f};return p&&(v.getTree={limitLevel:g,startWith:y}),d&&(v.getTreePath=d),n=n.skip(h*(l-1)).limit(h).get(v),n}}};var e}})}var de=pe;export default de; +var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function n(e,t,n){return e(n={path:t,exports:{},require:function(e,t){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==t&&n.path)}},n.exports),n.exports}var r=n((function(e,t){var n;e.exports=(n=n||function(e,t){var n=Object.create||function(){function e(){}return function(t){var n;return e.prototype=t,n=new e,e.prototype=null,n}}(),r={},o=r.lib={},s=o.Base={extend:function(e){var t=n(this);return e&&t.mixIn(e),t.hasOwnProperty("init")&&this.init!==t.init||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=o.WordArray=s.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||c).stringify(this)},concat:function(e){var t=this.words,n=e.words,r=this.sigBytes,o=e.sigBytes;if(this.clamp(),r%4)for(var s=0;s>>2]>>>24-s%4*8&255;t[r+s>>>2]|=i<<24-(r+s)%4*8}else for(s=0;s>>2]=n[s>>>2];return this.sigBytes+=o,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=s.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n,r=[],o=function(t){t=t;var n=987654321,r=4294967295;return function(){var o=((n=36969*(65535&n)+(n>>16)&r)<<16)+(t=18e3*(65535&t)+(t>>16)&r)&r;return o/=4294967296,(o+=.5)*(e.random()>.5?1:-1)}},s=0;s>>2]>>>24-o%4*8&255;r.push((s>>>4).toString(16)),r.push((15&s).toString(16))}return r.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r>>3]|=parseInt(e.substr(r,2),16)<<24-r%8*4;return new i.init(n,t/2)}},u=a.Latin1={stringify:function(e){for(var t=e.words,n=e.sigBytes,r=[],o=0;o>>2]>>>24-o%4*8&255;r.push(String.fromCharCode(s))}return r.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r>>2]|=(255&e.charCodeAt(r))<<24-r%4*8;return new i.init(n,t)}},l=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(u.stringify(e)))}catch(e){throw new Error("Malformed UTF-8 data")}},parse:function(e){return u.parse(unescape(encodeURIComponent(e)))}},h=o.BufferedBlockAlgorithm=s.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,r=n.words,o=n.sigBytes,s=this.blockSize,a=o/(4*s),c=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*s,u=e.min(4*c,o);if(c){for(var l=0;l>>24)|4278255360&(o<<24|o>>>8)}var s=this._hash.words,i=e[t+0],c=e[t+1],f=e[t+2],d=e[t+3],g=e[t+4],y=e[t+5],m=e[t+6],v=e[t+7],_=e[t+8],b=e[t+9],w=e[t+10],S=e[t+11],T=e[t+12],E=e[t+13],O=e[t+14],k=e[t+15],A=s[0],P=s[1],I=s[2],N=s[3];A=u(A,P,I,N,i,7,a[0]),N=u(N,A,P,I,c,12,a[1]),I=u(I,N,A,P,f,17,a[2]),P=u(P,I,N,A,d,22,a[3]),A=u(A,P,I,N,g,7,a[4]),N=u(N,A,P,I,y,12,a[5]),I=u(I,N,A,P,m,17,a[6]),P=u(P,I,N,A,v,22,a[7]),A=u(A,P,I,N,_,7,a[8]),N=u(N,A,P,I,b,12,a[9]),I=u(I,N,A,P,w,17,a[10]),P=u(P,I,N,A,S,22,a[11]),A=u(A,P,I,N,T,7,a[12]),N=u(N,A,P,I,E,12,a[13]),I=u(I,N,A,P,O,17,a[14]),A=l(A,P=u(P,I,N,A,k,22,a[15]),I,N,c,5,a[16]),N=l(N,A,P,I,m,9,a[17]),I=l(I,N,A,P,S,14,a[18]),P=l(P,I,N,A,i,20,a[19]),A=l(A,P,I,N,y,5,a[20]),N=l(N,A,P,I,w,9,a[21]),I=l(I,N,A,P,k,14,a[22]),P=l(P,I,N,A,g,20,a[23]),A=l(A,P,I,N,b,5,a[24]),N=l(N,A,P,I,O,9,a[25]),I=l(I,N,A,P,d,14,a[26]),P=l(P,I,N,A,_,20,a[27]),A=l(A,P,I,N,E,5,a[28]),N=l(N,A,P,I,f,9,a[29]),I=l(I,N,A,P,v,14,a[30]),A=h(A,P=l(P,I,N,A,T,20,a[31]),I,N,y,4,a[32]),N=h(N,A,P,I,_,11,a[33]),I=h(I,N,A,P,S,16,a[34]),P=h(P,I,N,A,O,23,a[35]),A=h(A,P,I,N,c,4,a[36]),N=h(N,A,P,I,g,11,a[37]),I=h(I,N,A,P,v,16,a[38]),P=h(P,I,N,A,w,23,a[39]),A=h(A,P,I,N,E,4,a[40]),N=h(N,A,P,I,i,11,a[41]),I=h(I,N,A,P,d,16,a[42]),P=h(P,I,N,A,m,23,a[43]),A=h(A,P,I,N,b,4,a[44]),N=h(N,A,P,I,T,11,a[45]),I=h(I,N,A,P,k,16,a[46]),A=p(A,P=h(P,I,N,A,f,23,a[47]),I,N,i,6,a[48]),N=p(N,A,P,I,v,10,a[49]),I=p(I,N,A,P,O,15,a[50]),P=p(P,I,N,A,y,21,a[51]),A=p(A,P,I,N,T,6,a[52]),N=p(N,A,P,I,d,10,a[53]),I=p(I,N,A,P,w,15,a[54]),P=p(P,I,N,A,c,21,a[55]),A=p(A,P,I,N,_,6,a[56]),N=p(N,A,P,I,k,10,a[57]),I=p(I,N,A,P,m,15,a[58]),P=p(P,I,N,A,E,21,a[59]),A=p(A,P,I,N,g,6,a[60]),N=p(N,A,P,I,S,10,a[61]),I=p(I,N,A,P,f,15,a[62]),P=p(P,I,N,A,b,21,a[63]),s[0]=s[0]+A|0,s[1]=s[1]+P|0,s[2]=s[2]+I|0,s[3]=s[3]+N|0},_doFinalize:function(){var t=this._data,n=t.words,r=8*this._nDataBytes,o=8*t.sigBytes;n[o>>>5]|=128<<24-o%32;var s=e.floor(r/4294967296),i=r;n[15+(o+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),n[14+(o+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),t.sigBytes=4*(n.length+1),this._process();for(var a=this._hash,c=a.words,u=0;u<4;u++){var l=c[u];c[u]=16711935&(l<<8|l>>>24)|4278255360&(l<<24|l>>>8)}return a},clone:function(){var e=s.clone.call(this);return e._hash=this._hash.clone(),e}});function u(e,t,n,r,o,s,i){var a=e+(t&n|~t&r)+o+i;return(a<>>32-s)+t}function l(e,t,n,r,o,s,i){var a=e+(t&r|n&~r)+o+i;return(a<>>32-s)+t}function h(e,t,n,r,o,s,i){var a=e+(t^n^r)+o+i;return(a<>>32-s)+t}function p(e,t,n,r,o,s,i){var a=e+(n^(t|~r))+o+i;return(a<>>32-s)+t}t.MD5=s._createHelper(c),t.HmacMD5=s._createHmacHelper(c)}(Math),n.MD5)})),n((function(e,t){var n,o,s;e.exports=(o=(n=r).lib.Base,s=n.enc.Utf8,void(n.algo.HMAC=o.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=s.parse(t));var n=e.blockSize,r=4*n;t.sigBytes>r&&(t=e.finalize(t)),t.clamp();for(var o=this._oKey=t.clone(),i=this._iKey=t.clone(),a=o.words,c=i.words,u=0;u{t.success&&t.success(e),t.complete&&t.complete(e)},e=>{t.fail&&t.fail(e),t.complete&&t.complete(e)})}}class i extends Error{constructor(e){super(e.message),this.errMsg=e.message||"",Object.defineProperties(this,{code:{get:()=>e.code},requestId:{get:()=>e.requestId},message:{get(){return this.errMsg},set(e){this.errMsg=e}}})}}let a;try{a=require("uni-stat-config").default||require("uni-stat-config")}catch(e){a={appid:""}}let c,u;function l(e=8){let t="";for(;t.length{t(Object.assign(e,{complete(e){e||(e={}),"h5"===process.env.VUE_APP_PLATFORM&&"development"===process.env.NODE_ENV&&e.errMsg&&0===e.errMsg.indexOf("request:fail")&&console.warn("发布H5,需要在uniCloud后台操作,绑定安全域名,否则会因为跨域问题而无法访问。教程参考:https://uniapp.dcloud.io/uniCloud/quickstart?id=useinh5");const t=e.data&&e.data.header&&e.data.header["x-serverless-request-id"]||e.header&&e.header["request-id"];if(!e.statusCode||e.statusCode>=400)return r(new i({code:"SYS_ERR",message:e.errMsg||"request:fail",requestId:t}));const o=e.data;if(o.error)return r(new i({code:o.error.code,message:o.error.message,requestId:t}));o.result=o.data,o.requestId=t,delete o.data,n(o)}}))})}};const y={request:e=>uni.request(e),uploadFile:e=>uni.uploadFile(e),setStorageSync:(e,t)=>uni.setStorageSync(e,t),getStorageSync:e=>uni.getStorageSync(e),removeStorageSync:e=>uni.removeStorageSync(e),clearStorageSync:()=>uni.clearStorageSync()};class m{constructor(e){["spaceId","clientSecret"].forEach(t=>{if(!Object.prototype.hasOwnProperty.call(e,t))throw new Error("缺少参数"+t)}),this.config=Object.assign({},{endpoint:"https://api.bspapp.com"},e),this.config.provider="aliyun",this.config.requestUrl=this.config.endpoint+"/client",this.config.envType=this.config.envType||"public",this.config.accessTokenKey="access_token_"+this.config.spaceId,this.adapter=y}get hasAccessToken(){return!!this.accessToken}setAccessToken(e){this.accessToken=e}requestWrapped(e){return g.wrappedRequest(e,this.adapter.request)}requestAuth(e){return this.requestWrapped(e)}request(e,t){return this.hasAccessToken?t?this.requestWrapped(e):this.requestWrapped(e).catch(t=>new Promise((e,n)=>{!t||"GATEWAY_INVALID_TOKEN"!==t.code&&"InvalidParameter.InvalidToken"!==t.code?n(t):e()}).then(()=>this.getAccessToken()).then(()=>{const t=this.rebuildRequest(e);return this.request(t,!0)})):this.getAccessToken().then(()=>{const t=this.rebuildRequest(e);return this.request(t,!0)})}rebuildRequest(e){const t=Object.assign({},e);return t.data.token=this.accessToken,t.header["x-basement-token"]=this.accessToken,t.header["x-serverless-sign"]=g.sign(t.data,this.config.clientSecret),t}setupRequest(e,t){const n=Object.assign({},e,{spaceId:this.config.spaceId,timestamp:Date.now()}),r={"Content-Type":"application/json"};return"auth"!==t&&(n.token=this.accessToken,r["x-basement-token"]=this.accessToken),r["x-serverless-sign"]=g.sign(n,this.config.clientSecret),{url:this.config.requestUrl,method:"POST",data:n,dataType:"json",header:r}}getAccessToken(){return this.requestAuth(this.setupRequest({method:"serverless.auth.user.anonymousAuthorize",params:"{}"},"auth")).then(e=>new Promise((t,n)=>{e.result&&e.result.accessToken?(this.setAccessToken(e.result.accessToken),t(this.accessToken)):n(new i({code:"AUTH_FAILED",message:"获取accessToken失败"}))}))}authorize(){this.getAccessToken()}callFunction(e){const t={method:"serverless.function.runtime.invoke",params:JSON.stringify({functionTarget:e.name,functionArgs:e.data||{}})};return this.request(this.setupRequest(t))}getOSSUploadOptionsFromPath(e){const t={method:"serverless.file.resource.generateProximalSign",params:JSON.stringify(e)};return this.request(this.setupRequest(t))}uploadFileToOSS({url:e,formData:t,name:n,filePath:r,fileType:o,onUploadProgress:s}){return new Promise((a,c)=>{const u=this.adapter.uploadFile({url:e,formData:t,name:n,filePath:r,fileType:o,header:{"X-OSS-server-side-encrpytion":"AES256"},success(e){e&&e.statusCode<400?a(e):c(new i({code:"UPLOAD_FAILED",message:"文件上传失败"}))},fail(e){c(e)}});"function"==typeof s&&u&&"function"==typeof u.onProgressUpdate&&u.onProgressUpdate(e=>{s({loaded:e.totalBytesSent,total:e.totalBytesExpectedToSend})})})}reportOSSUpload(e){const t={method:"serverless.file.resource.report",params:JSON.stringify(e)};return this.request(this.setupRequest(t))}uploadFile({filePath:e,cloudPath:t,fileType:n="image",onUploadProgress:r,config:o}){if(!t)throw new i({code:"CLOUDPATH_REQUIRED",message:"cloudPath不可为空"});const s=o&&o.envType||this.config.envType;let a,c;return this.getOSSUploadOptionsFromPath({env:s,filename:t}).then(t=>{const o=t.result;a=o.id,c="https://"+o.cdnDomain+"/"+o.ossPath;const s={url:"https://"+o.host,formData:{"Cache-Control":"max-age=2592000","Content-Disposition":"attachment",OSSAccessKeyId:o.accessKeyId,Signature:o.signature,host:o.host,id:a,key:o.ossPath,policy:o.policy,success_action_status:200},fileName:"file",name:"file",filePath:e,fileType:n};return this.uploadFileToOSS(Object.assign({},s,{onUploadProgress:r}))}).then(()=>this.reportOSSUpload({id:a})).then(t=>new Promise((n,r)=>{t.success?n({success:!0,filePath:e,fileID:c}):r(new i({code:"UPLOAD_FAILED",message:"文件上传失败"}))}))}deleteFile({fileList:e}){const t={method:"serverless.file.resource.delete",params:JSON.stringify({id:e[0]})};return this.request(this.setupRequest(t))}getTempFileURL({fileList:e}={}){return new Promise((t,n)=>{Array.isArray(e)&&0!==e.length||n(new i({code:"INVALID_PARAM",message:"fileList的元素必须是非空的字符串"})),t({fileList:e.map(e=>({fileID:e,tempFileURL:e}))})})}}const v={init(e){const t=new m(e);["deleteFile","getTempFileURL"].forEach(e=>{t[e]=s(t[e]).bind(t)});const n={signInAnonymously:function(){return t.authorize()},getLoginState:function(){return Promise.resolve(!1)}};return t.auth=function(){return n},t.customAuth=t.auth,t}};var _,b,w=n((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.getQuery=function(e,t){if("undefined"==typeof window)return!1;var n=t||window.location.search,r=new RegExp("(^|&)"+e+"=([^&]*)(&|$)"),o=n.substr(n.indexOf("?")+1).match(r);return null!=o?o[2]:""},t.getHash=function(e){var t=window.location.hash.match(new RegExp("[#?&/]"+e+"=([^&#]*)"));return t?t[1]:""},t.removeParam=function(e,t){var n=t.split("?")[0],r=[],o=-1!==t.indexOf("?")?t.split("?")[1]:"";if(""!==o){for(var s=(r=o.split("&")).length-1;s>=0;s-=1)r[s].split("=")[0]===e&&r.splice(s,1);n=n+"?"+r.join("&")}return n},t.createPromiseCallback=function(){var e;if(!Promise){(e=function(){}).promise={};var t=function(){throw new Error('Your Node runtime does support ES6 Promises. Set "global.Promise" to your preferred implementation of promises.')};return Object.defineProperty(e.promise,"then",{get:t}),Object.defineProperty(e.promise,"catch",{get:t}),e}var n=new Promise((function(t,n){e=function(e,r){return e?n(e):t(r)}}));return e.promise=n,e},t.getWeixinCode=function(){return t.getQuery("code")||t.getHash("code")},t.getMiniAppCode=function(){return new Promise((function(e,t){wx.login({success:function(t){e(t.code)},fail:function(e){t(e)}})}))},t.isArray=function(e){return"[object Array]"===Object.prototype.toString.call(e)},t.isString=function(e){return"string"==typeof e},t.isUndefined=function(e){return void 0===e},t.isInstanceOf=function(e,t){return e instanceof t},t.isFormData=function(e){return"[object FormData]"===Object.prototype.toString.call(e)},t.genSeqId=function(){return Math.random().toString(16).slice(2)},t.getArgNames=function(e){var t=e.toString();return t.slice(t.indexOf("(")+1,t.indexOf(")")).match(/([^\s,]+)/g)},t.formatUrl=function(e,t,n){void 0===n&&(n={});var r=/\?/.test(t),o="";for(var s in n)""===o?!r&&(t+="?"):o+="&",o+=s+"="+encodeURIComponent(n[s]);return/^http(s)?\:\/\//.test(t+=o)?t:""+e+t}})),S="dist/index.js",T="./dist/index.d.ts",E={build:"npm run tsc && webpack",tsc:"tsc -p tsconfig.json","tsc:w":"tsc -p tsconfig.json -w",test:"jest --verbose false -i",e2e:'NODE_ENV=e2e webpack && jest --config="./jest.e2e.config.js" --verbose false -i "e2e"',start:"webpack-dev-server --hot --open",eslint:'eslint "./**/*.js" "./**/*.ts"',"eslint-fix":'eslint --fix "./**/*.js" "./**/*.ts"',test_web:"npm run tsc && webpack-dev-server --devtool eval-source-map --progress --colors --hot --inline --content-base ./dist --host jimmytest-088bef.tcb.qcloud.la --port 80 --disableHostCheck true --mode development --config webpack.test.js"},O={type:"git",url:"https://github.com/TencentCloudBase/tcb-js-sdk"},k=["tcb","js-sdk"],A={"@cloudbase/adapter-interface":"^0.2.0","@cloudbase/adapter-wx_mp":"^0.2.1","@cloudbase/database":"^0.9.8"},P={"@babel/core":"^7.6.2","@babel/plugin-proposal-class-properties":"^7.5.5","@babel/plugin-proposal-object-rest-spread":"^7.6.2","@babel/plugin-transform-runtime":"^7.6.2","@babel/preset-env":"^7.6.2","@babel/preset-typescript":"^7.6.0","@babel/runtime":"^7.6.2","@types/jest":"^23.1.4","@types/node":"^10.14.4","@types/superagent":"^4.1.4",axios:"^0.19.0","babel-eslint":"^10.0.1","babel-loader":"^8.0.6","babel-polyfill":"^6.26.0",eslint:"^5.16.0","eslint-config-alloy":"^1.4.2","eslint-config-prettier":"^4.1.0","eslint-plugin-prettier":"^3.0.1","eslint-plugin-typescript":"^1.0.0-rc.3",express:"^4.17.1",husky:"^3.1.0",jest:"^24.7.1","jest-puppeteer":"^4.3.0","lint-staged":"^9.5.0","power-assert":"^1.6.1",puppeteer:"^1.20.0","serve-static":"^1.14.1","ts-jest":"^23.10.4","ts-loader":"^6.2.1",typescript:"^3.4.3","typescript-eslint-parser":"^22.0.0",webpack:"^4.41.3","webpack-bundle-analyzer":"^3.4.1","webpack-cli":"^3.3.0","webpack-dev-server":"^3.3.1","webpack-merge":"^4.2.2","webpack-visualizer-plugin":"^0.1.11"},I={hooks:{"pre-commit":"lint-staged"}},N={name:"tcb-js-sdk",version:"1.3.5",description:"js sdk for tcb",main:S,types:T,scripts:E,repository:O,keywords:k,author:"jimmyjzhang",license:"ISC",dependencies:A,devDependencies:P,husky:I,"lint-staged":{"*.{js,ts}":["eslint --fix","git add"]}},x=(_=Object.freeze({__proto__:null,name:"tcb-js-sdk",version:"1.3.5",description:"js sdk for tcb",main:S,types:T,scripts:E,repository:O,keywords:k,author:"jimmyjzhang",license:"ISC",dependencies:A,devDependencies:P,husky:I,default:N}))&&_.default||_,C=n((function(t,n){var r=e&&e.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t};Object.defineProperty(n,"__esModule",{value:!0});var o=r(x);n.SDK_VERISON=o.version,n.ACCESS_TOKEN="access_token",n.ACCESS_TOKEN_Expire="access_token_expire",n.REFRESH_TOKEN="refresh_token",n.ANONYMOUS_UUID="anonymous_uuid",n.LOGIN_TYPE_KEY="login_type",n.protocol="undefined"!=typeof location&&"http:"===location.protocol?"http:":"https:",n.BASE_URL="e2e"===process.env.NODE_ENV&&"pre"===process.env.END_POINT?"//tcb-pre.tencentcloudapi.com/web":"//tcb-api.tencentcloudapi.com/web"}));!function(e){e.local="local",e.none="none",e.session="session"}(b||(b={}));var R=function(){},D=function(){};var U=Object.freeze({__proto__:null,get StorageType(){return b},AbstractSDKRequest:R,AbstractStorage:D,formatUrl:function(e,t,n){void 0===n&&(n={});var r=/\?/.test(t),o="";for(var s in n)""===o?!r&&(t+="?"):o+="&",o+=s+"="+encodeURIComponent(n[s]);return/^http(s)?\:\/\//.test(t+=o)?t:""+e+t}}),j=n((function(t,n){var r,o=e&&e.__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)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),s=e&&e.__assign||function(){return(s=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]=0?JSON.parse(n).content:""},e.prototype.removeStore=function(e){this.storageClass.removeItem(e)},e}();n.Cache=s;var i=function(e){function t(){var t=e.call(this)||this;return q.Adapter.adapter.root.tcbObject||(q.Adapter.adapter.root.tcbObject={}),t}return o(t,e),t.prototype.setItem=function(e,t){q.Adapter.adapter.root.tcbObject[e]=t},t.prototype.getItem=function(e){return q.Adapter.adapter.root.tcbObject[e]},t.prototype.removeItem=function(e){delete q.Adapter.adapter.root.tcbObject[e]},t.prototype.clear=function(){delete q.Adapter.adapter.root.tcbObject},t}(U.AbstractStorage)})),F=n((function(t,n){var r,o=e&&e.__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)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),s=e&&e.__spreadArrays||function(){for(var e=0,t=0,n=arguments.length;t0},e}();n.IEventEmitter=c;var u=new c;n.addEventListener=function(e,t){u.on(e,t)},n.activateEvent=function(e,t){void 0===t&&(t={}),u.fire(e,t)},n.removeEventListener=function(e,t){u.off(e,t)},n.EVENTS={LOGIN_STATE_CHANGED:"loginStateChanged",LOGIN_STATE_EXPIRE:"loginStateExpire",LOGIN_TYPE_CHANGE:"loginTypeChanged",ANONYMOUS_CONVERTED:"anonymousConverted",REFRESH_ACCESS_TOKEN:"refreshAccessToken"}})),M=n((function(t,n){var r=e&&e.__assign||function(){return(r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]Date.now())return[2,{credential:{accessToken:e,refreshToken:this.cache.getStore(this.refreshTokenKey)}}];this.cache.removeStore(this.accessTokenKey),this.cache.removeStore(this.accessTokenExpireKey)}if(!1===Object.values(c).includes(c[this.scope]))throw new Error("错误的scope类型");return q.Adapter.runtime!==q.RUNTIME.WX_MP?[3,2]:[4,l.getMiniAppCode()];case 1:return n=i.sent(),[3,4];case 2:return[4,l.getWeixinCode()];case 3:if(!(n=i.sent()))return[2,this.redirect()];i.label=4;case 4:return r=function(e){switch(e){case c.snsapi_login:return"WECHAT-OPEN";default:return"WECHAT-PUBLIC"}}(this.scope),[4,this.getRefreshTokenByWXCode(this.appid,r,n)];case 5:return o=i.sent(),s=o.refreshToken,this.cache.setStore(this.refreshTokenKey,s),o.accessToken&&this.cache.setStore(this.accessTokenKey,o.accessToken),o.accessTokenExpire&&this.cache.setStore(this.accessTokenExpireKey,o.accessTokenExpire+Date.now()),F.activateEvent(F.EVENTS.LOGIN_STATE_CHANGED),F.activateEvent(F.EVENTS.LOGIN_TYPE_CHANGE,h.LOGINTYPE.WECHAT),[2,{credential:{refreshToken:s}}]}}))}))},t.prototype.redirect=function(){var e=l.removeParam("code",location.href);e=l.removeParam("state",e),e=encodeURIComponent(e);var t="//open.weixin.qq.com/connect/oauth2/authorize";"snsapi_login"===this.scope&&(t="//open.weixin.qq.com/connect/qrconnect"),"redirect"===u[this.loginMode]&&(location.href=t+"?appid="+this.appid+"&redirect_uri="+e+"&response_type=code&scope="+this.scope+"&state="+this.state+"#wechat_redirect")},t}(h.default);n.default=f})),H=n((function(t,n){var r,o=e&&e.__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)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),s=e&&e.__assign||function(){return(s=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]{y.request({url:z("https:",t),data:n,method:"POST",header:r,success(t){e(t)},fail(e){o(e)}})})}upload(e){return new Promise((t,n)=>{const{url:r,file:o,data:s,headers:i,fileType:a}=e,c=y.uploadFile({url:z("https:",r),name:"file",formData:Object.assign({},s),filePath:o,fileType:a,header:i,success(e){const n={statusCode:e.statusCode,data:e.data||{}};200===e.statusCode&&s.success_action_status&&(n.statusCode=parseInt(s.success_action_status,10)),t(n)},fail(e){"mp-alipay"===process.env.VUE_APP_PLATFORM&&"development"===process.env.NODE_ENV&&console.warn("支付宝小程序开发工具上传腾讯云时无法准确判断是否上传成功,请使用真机测试"),n(new Error(e.errMsg||"uploadFile:fail"))}});"function"==typeof e.onUploadProgress&&c&&"function"==typeof c.onProgressUpdate&&c.onProgressUpdate(t=>{e.onUploadProgress({loaded:t.totalBytesSent,total:t.totalBytesExpectedToSend})})})}}const J={setItem(e,t){y.setStorageSync(e,t)},getItem:e=>y.getStorageSync(e),removeItem(e){y.removeStorageSync(e)},clear(){y.clearStorageSync()}};const X={genAdapter:function(){return{root:{},reqClass:W,localStorage:J,primaryStorage:"local"}},isMatch:function(){return!0},runtime:"uni_app"};$.useAdapters(X);const Q=$,Z=Q.init;Q.init=function(e){e.env=e.spaceId;const t=Z.call(this,e);t.config.provider="tencent",t.config.spaceId=e.spaceId;const n=t.auth;t.auth=function(e){const t=n.call(this,e);return["linkAndRetrieveDataWithTicket","signInAnonymously","signOut","getAccessToken","getLoginState","signInWithTicket","getUserInfo"].forEach(e=>{t[e]=s(t[e]).bind(t)}),t},t.customAuth=t.auth;return["deleteFile","getTempFileURL","downloadFile"].forEach(e=>{t[e]=s(t[e]).bind(t)}),t};let ee,te,ne,re;function oe({name:e,data:t}){const{localAddress:n,localPort:r}=this,o={aliyun:"aliyun",tencent:"tcb"}[this.config.provider],s=this.config.spaceId,a=`http://${n}:${r}/system/check-function`,c=`http://${n}:${r}/cloudfunctions/${e}`;return new Promise((t,n)=>{y.request({method:"POST",url:a,data:{name:e,platform:process.env.VUE_APP_PLATFORM,provider:o,spaceId:s},timeout:3e3,success(e){t(e)},fail(){t({data:{code:"NETWORK_ERROR",message:"连接本地调试服务失败,请检查客户端是否和主机在同一局域网下,自动切换为已部署的云函数。"}})}})}).then(({data:e}={})=>{const{code:t,message:n}=e||{};return{code:0===t?0:t||"SYS_ERR",message:n||"SYS_ERR"}}).then(({code:n,message:r})=>{if(0!==n){switch(n){case"MODULE_ENCRYPTED":console.error(`此云函数(${e})依赖加密公共模块不可本地调试,自动切换为云端已部署的云函数`);break;case"FUNCTION_ENCRYPTED":console.error(`此云函数(${e})已加密不可本地调试,自动切换为云端已部署的云函数`);break;case"ACTION_ENCRYPTED":console.error(r||"需要访问加密的uni-clientDB-action,自动切换为云端环境");break;case"NETWORK_ERROR":{const e="连接本地调试服务失败,请检查客户端是否和主机在同一局域网下";throw console.error(e),new Error(e)}case"SWITCH_TO_CLOUD":break;default:{const e=`检测本地调试服务出现错误:${r},请检查网络环境或重启客户端再试`;throw console.error(e),new Error(e)}}return this.originCallFunction({name:e,data:t})}return new Promise((n,r)=>{ee||(ee=h(),te=d());const a=e,u=s,l={tencent:"t",aliyun:"a"}[this.config.provider],p=Object.assign({},te,{fn:a,sid:u,pvd:l}),f={...t,clientInfo:ee,uniCloudClientInfo:encodeURIComponent(JSON.stringify(p))},g=y.getStorageSync("uni_id_token")||y.getStorageSync("uniIdToken");g&&(f.uniIdToken=g);{const{uuid:e}=uni.getSystemInfoSync();f.uniCloudUuid=e}y.request({method:"POST",url:c,data:{provider:o,platform:process.env.VUE_APP_PLATFORM,param:f},success:({statusCode:e,data:t}={})=>!e||e>=400?r(new i({code:t.code||"SYS_ERR",message:t.message||"request:fail"})):n({result:t}),fail(e){r(new i({code:e.code||e.errCode||"SYS_ERR",message:e.message||e.errMsg||"request:fail"}))}})})})}function se(e){ne||(ne=h(),re=d());const t=JSON.parse(JSON.stringify(e.data||{})),n=e.name,r=this.config.spaceId,o={tencent:"t",aliyun:"a"}[this.config.provider],s=Object.assign({},re,{fn:n,sid:r,pvd:o});if(Object.assign(t,{clientInfo:ne,uniCloudClientInfo:encodeURIComponent(JSON.stringify(s))}),!t.uniIdToken){const e=y.getStorageSync("uni_id_token")||y.getStorageSync("uniIdToken");e&&(t.uniIdToken=e)}{const{uuid:e}=uni.getSystemInfoSync();t.uniCloudUuid=e}return e.data=t,e}function ie(e){const t=e.callFunction;e.callFunction=function(e){let n;return n=this.isReady?Promise.resolve():this.initUniCloud,n.then(()=>{const n=se.call(this,e),r={aliyun:"aliyun",tencent:"tcb"}[this.config.provider];return new Promise((o,s)=>{t.call(this,n).then(t=>{if(this.config.useDebugFunction&&t&&t.requestId){const n=JSON.stringify({spaceId:this.config.spaceId,functionName:e.name,requestId:t.requestId});console.log(`[${r}-request]${n}[/${r}-request]`)}o(t)}).catch(t=>{if(this.config.useDebugFunction&&t&&t.requestId){const n=JSON.stringify({spaceId:this.config.spaceId,functionName:e.name,requestId:t.requestId});console.log(`[${r}-request]${n}[/${r}-request]`)}t&&t.message&&(t.message=`[${e.name}]: ${t.message}`),s(t)})})})};const n=e.callFunction;e.originCallFunction=e.callFunction,e.callFunction=function(t){return s((function(t){let r;return r=e.isReady?Promise.resolve():e.initUniCloud,r.then(()=>"development"===process.env.NODE_ENV&&e.debugInfo&&!e.debugInfo.forceRemote&&process.env.UNI_CLOUD_PROVIDER?oe.call(this,t):n.call(this,t))})).call(this,t)}}const ae=Symbol("CLIENT_DB_INTERNAL");function ce(e,t){return e.then="DoNotReturnProxyWithAFunctionNamedThen",e._internalType=ae,new Proxy(e,{get:(e,n,r)=>function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}(e,n)||e[n]||"string"!=typeof n?e[n]:t.get(e,n,r)})}class ue extends Error{constructor(e,t){super(e),this.code=t}}function le(e){switch(t=e,Object.prototype.toString.call(t).slice(8,-1).toLowerCase()){case"array":return e.map(e=>le(e));case"object":return e._internalType===ae||Object.keys(e).forEach(t=>{e[t]=le(e[t])}),e;case"regexp":return{$regexp:{source:e.source,flags:e.flags}};case"date":return{$date:e.toISOString()};default:return e}var t}function he(){const e=y.getStorageSync("uni_id_token")||"",t=e.split(".");if(!e||3!==t.length)return{uid:null,role:[],permission:[]};let n;try{n=JSON.parse((r=e[1],decodeURIComponent(atob(r).split("").map((function(e){return"%"+("00"+e.charCodeAt(0).toString(16)).slice(-2)})).join(""))))}catch(e){throw new Error("获取当前用户信息出错,详细错误信息为:"+e.message)}var r;return n}var pe=t(n((function(e,t){Object.defineProperty(t,"__esModule",{value:!0});const n="chooseAndUploadFile:fail";function r(e,t){return e.tempFiles.forEach((e,n)=>{e.name||(e.name=e.path.substring(e.path.lastIndexOf("/")+1)),t&&(e.fileType=t),e.cloudPath=Date.now()+"_"+n+e.name.substring(e.name.lastIndexOf("."))}),e.tempFilePaths||(e.tempFilePaths=e.tempFiles.map(e=>e.path)),e}function o(e,t,{onChooseFile:n,onUploadProgress:r}){return t.then(e=>{if(n){const t=n(e);if(void 0!==t)return Promise.resolve(t).then(t=>void 0===t?e:t)}return e}).then(t=>!1===t?{errMsg:"chooseAndUploadFile:ok",tempFilePaths:[],tempFiles:[]}:function(e,t,n=5,r){(t=Object.assign({},t)).errMsg="chooseAndUploadFile:ok";const o=t.tempFiles,s=o.length;let i=0;return new Promise(a=>{for(;i=s)return void(!o.find(e=>!e.url&&!e.errMsg)&&a(t));const u=o[n];e.uploadFile({filePath:u.path,cloudPath:u.cloudPath,fileType:u.fileType,onUploadProgress(e){e.index=n,e.tempFile=u,e.tempFilePath=u.path,r&&r(e)}}).then(e=>{u.url=e.fileID,n{u.errMsg=e.errMsg||e.message,n{uni.chooseImage({count:t,sizeType:o,sourceType:s,extension:i,success(t){e(r(t,"image"))},fail(e){a({errMsg:e.errMsg.replace("chooseImage:fail",n)})}})})}(t),t):"video"===t.type?o(e,function(e){const{camera:t,compressed:o,maxDuration:s,sourceType:i,extension:a}=e;return new Promise((e,c)=>{uni.chooseVideo({camera:t,compressed:o,maxDuration:s,sourceType:i,extension:a,success(t){const{tempFilePath:n,duration:o,size:s,height:i,width:a}=t;e(r({errMsg:"chooseVideo:ok",tempFilePaths:[n],tempFiles:[{name:t.tempFile&&t.tempFile.name||"",path:n,size:s,type:t.tempFile&&t.tempFile.type||"",width:a,height:i,duration:o,fileType:"video",cloudPath:""}]},"video"))},fail(e){c({errMsg:e.errMsg.replace("chooseVideo:fail",n)})}})})}(t),t):o(e,function(e){const{count:t,extension:o}=e;return new Promise((e,s)=>{let i=uni.chooseFile;if("undefined"!=typeof wx&&"function"==typeof wx.chooseMessageFile&&(i=wx.chooseMessageFile),"function"!=typeof i)return s({errMsg:n+" 请指定 type 类型,该平台仅支持选择 image 或 video。"});i({type:"all",count:t,extension:o,success(t){e(r(t))},fail(e){s({errMsg:e.errMsg.replace("chooseFile:fail",n)})}})})}(t),t)}}})));async function fe(e,t){const n=`http://${e}:${t}/system/ping`;try{const e=await(r={url:n,timeout:500},new Promise((e,t)=>{y.request({...r,success(t){e(t)},fail(e){t(e)}})}));return!(!e.data||0!==e.data.code)}catch(e){return!1}var r}let de=new class{init(e){let t={};const n=!1!==e.debugFunction&&"development"===process.env.NODE_ENV&&("h5"===process.env.VUE_APP_PLATFORM&&navigator.userAgent.indexOf("HBuilderX")>0||"app-plus"===process.env.VUE_APP_PLATFORM);switch(e.provider){case"tencent":t=Q.init(Object.assign(e,{useDebugFunction:n}));break;case"aliyun":t=v.init(Object.assign(e,{useDebugFunction:n}));break;default:throw new Error("未提供正确的provider参数")}const r=process.env.UNICLOUD_DEBUG;"development"===process.env.NODE_ENV&&r&&!r.code&&(t.debugInfo=r),t.isReady=!1;const o=t.auth();return t.initUniCloud=o.getLoginState().then(e=>e?Promise.resolve():o.signInAnonymously()).then(()=>{if("development"===process.env.NODE_ENV&&t.debugInfo){const{address:e,servePort:n}=t.debugInfo;return async function(e,t){let n;for(let r=0;r{if(e)t.localAddress=e,t.localPort=n;else if(t.debugInfo){const e="app-plus"===process.env.VUE_APP_PLATFORM?"error":"warn",n=console[e];"remote"===t.debugInfo.initialLaunchType?(t.debugInfo.forceRemote=!0,n("当前客户端和HBuilderX不在同一局域网下(或其他网络原因无法连接HBuilderX),uniCloud本地调试服务不对当前客户端生效。\n- 如果不使用uniCloud本地调试服务,请直接忽略此信息。\n- 如需使用uniCloud本地调试服务,请将客户端与主机连接到同一局域网下并重新运行到客户端。\n- 如果在HBuilderX开启的状态下切换过网络环境,请重启HBuilderX后再试")):n("无法连接uniCloud本地调试服务,请检查当前客户端是否与主机在同一局域网下。\n- 如需使用uniCloud本地调试服务,请将客户端与主机连接到同一局域网下并重新运行到客户端。\n- 如果在HBuilderX开启的状态下切换过网络环境,请重启HBuilderX后再试")}}).then(()=>new Promise(e=>{"quickapp-native"===process.env.VUE_APP_PLATFORM?(u="android",uni.getStorage({key:"__DC_CLOUD_UUID",success(t){c=t.data?t.data:l(32),e()}})):setTimeout(()=>{u=uni.getSystemInfoSync().platform,c=uni.getStorageSync("__DC_CLOUD_UUID")||l(32),e()},0)})).then(()=>{t.isReady=!0}),ie(t),function(e){const t=e.uploadFile;e.uploadFile=function(e){let n;return n=this.isReady?Promise.resolve():this.initUniCloud,n.then(()=>t.call(this,e))};const n=e.uploadFile;e.uploadFile=function(e){return s(n).call(this,e)}}(t),function(e){e.database=function(){if(this._database)return this._database;const t={},n={};class r{constructor(e,t,n){this.content=e,this.prevStage=t,this.actionName=n}toJSON(){let e=this;const t=[e.content];for(;e.prevStage;)e=e.prevStage,t.push(e.content);return{$db:t.reverse().map(e=>({$method:e.$method,$param:e.$param}))}}get useAggregate(){let e=this,t=!1;for(;e.prevStage;){e=e.prevStage;const n=e.content.$method;if("aggregate"===n||"pipeline"===n){t=!0;break}}return t}get count(){if(!this.useAggregate)return function(){return this._send("count",Array.from(arguments))};const e=this;return function(){return i({$method:"count",$param:le(Array.from(arguments))},e,e.actionName)}}get(){return this._send("get",Array.from(arguments))}add(){return this._send("add",Array.from(arguments))}remove(){return this._send("remove",Array.from(arguments))}update(){return this._send("update",Array.from(arguments))}end(){return this._send("end",Array.from(arguments))}set(){throw new Error("客户端禁止使用set方法")}_send(r,o){const s=this.toJSON();return s.$db.push({$method:r,$param:o}),e.callFunction({name:"DCloud-clientDB",data:{action:this.actionName,command:s}}).then(e=>{const{code:r,message:o,token:s,tokenExpired:i}=e.result;return r?Promise.reject(new ue(o,r)):(s&&i&&t.refreshToken&&t.refreshToken.forEach(e=>{e({token:s,tokenExpired:i})}),s&&i&&n.refreshToken&&n.refreshToken.forEach(e=>{e({token:s,tokenExpired:i})}),Promise.resolve(e))}).catch(e=>{const t=new ue(e.message,e.code||"SYSTEM_ERROR");return n.error&&n.error.forEach(e=>{e(t)}),/fc_function_not_found|FUNCTION_NOT_FOUND/g.test(e.message)&&console.warn("clientDB未初始化,请在web控制台保存一次schema以开启clientDB"),Promise.reject(e)})}}const o=["db.Geo","db.command","command.aggregate"];function s(e,t){return o.indexOf(`${e}.${t}`)>-1}function i(e,t,n){return ce(new r(e,t,n),{get(e,t){let r="db";return e&&e.content&&(r=e.content.$method),s(r,t)?i({$method:t},e,n):function(){return i({$method:t,$param:le(Array.from(arguments))},e,n)}}})}function a({path:e,method:t}){return class{constructor(){this.param=Array.from(arguments)}toJSON(){return{$newDb:[...e.map(e=>({$method:e})),{$method:t,$param:this.param}]}}}}const c={auth:{on:(e,n)=>{t[e]=t[e]||[],t[e].indexOf(n)>-1||t[e].push(n)},off:(e,n)=>{t[e]=t[e]||[];const r=t[e].indexOf(n);-1!==r&&t[e].splice(r,1)}},on:(e,t)=>{n[e]=n[e]||[],n[e].indexOf(t)>-1||n[e].push(t)},off:(e,t)=>{n[e]=n[e]||[];const r=n[e].indexOf(t);-1!==r&&n[e].splice(r,1)},env:ce({},{get:(e,t)=>({$env:t})}),action:e=>ce({},{get:(t,n)=>s("db",n)?i({$method:n},null,e):function(){return i({$method:n,$param:le(Array.from(arguments))},null,e)}}),Geo:ce({},{get:(e,t)=>a({path:["Geo"],method:t})}),getCloudEnv:function(e){if("string"!=typeof e||!e.trim())throw new Error("getCloudEnv参数错误");return{$env:e.replace("$cloudEnv_","")}},get serverDate(){return a({path:[],method:"serverDate"})},get RegExp(){return a({path:[],method:"RegExp"})}},u=ce(c,{get:(e,t)=>s("db",t)?i({$method:t}):function(){return i({$method:t,$param:le(Array.from(arguments))})}});return this._database=u,u}}(t),function(e){e.getCurrentUserInfo=he,e.chooseAndUploadFile=pe.initChooseAndUploadFile(e)}(t),t.init=this.init,t}};{let e={};if(1===process.env.UNI_CLOUD_PROVIDER.length)e=process.env.UNI_CLOUD_PROVIDER[0],de=de.init(e);else{const e=["auth","callFunction","uploadFile","deleteFile","getTempFileURL","downloadFile","database","getCurrentUSerInfo"],t=process.env.UNI_CLOUD_PROVIDER.length>0?"应用有多个服务空间,请通过uniCloud.init方法指定要使用的服务空间":"应用未关联服务空间,请在cloudfunctions目录右键关联服务空间";e.forEach(e=>{de[e]=function(){return console.error(t),Promise.reject(new i({code:"SYS_ERR",message:t}))}})}Object.assign(de,{get mixinDatacom(){return e=de,{props:{localdata:{type:Array,default:()=>[]},options:{type:[Object,Array],default:()=>({})},collection:{type:String,default:""},action:{type:String,default:""},field:{type:String,default:""},orderby:{type:String,default:""},where:{type:[String,Object],default:""},pageData:{type:String,default:"add"},pageCurrent:{type:Number,default:1},pageSize:{type:Number,default:20},getcount:{type:[Boolean,String],default:!1},gettree:{type:[Boolean,String],default:!1},gettreepath:{type:[Boolean,String],default:!1},startwith:{type:String,default:""},limitlevel:{type:Number,default:10},groupby:{type:String,default:""},groupField:{type:String,default:""},distinct:{type:[Boolean,String],default:!1},manual:{type:Boolean,default:!1}},data:()=>({mixinDatacomLoading:!1,mixinDatacomHasMore:!1,mixinDatacomResData:[],mixinDatacomErrorMessage:"",mixinDatacomPage:{}}),created(){this.mixinDatacomPage={current:this.pageCurrent,size:this.pageSize,count:0},this.$watch(()=>{var e=[];return["pageCurrent","pageSize","localdata","collection","action","field","orderby","where","getont","getcount","gettree","groupby","groupField","distinct"].forEach(t=>{e.push(this[t])}),e},(e,t)=>{let n=!1;const r=[];for(let o=2;o{this.mixinDatacomLoading=!1;const{data:r,count:o}=n.result;this.getcount&&(this.mixinDatacomPage.count=o),this.mixinDatacomHasMore=r.length{this.mixinDatacomLoading=!1,this.mixinDatacomErrorMessage=e,n&&n(e)}))},mixinDatacomGet(t={}){let n=e.database();const r=t.action||this.action;r&&(n=n.action(r));const o=t.collection||this.collection;n=n.collection(o);const s=t.where||this.where;s&&Object.keys(s).length&&(n=n.where(s));const i=t.field||this.field;i&&(n=n.field(i));const a=t.groupby||this.groupby;a&&(n=n.groupBy(a));const c=t.groupField||this.groupField;c&&(n=n.groupField(c)),!0===(void 0!==t.distinct?t.distinct:this.distinct)&&(n=n.distinct());const u=t.orderby||this.orderby;u&&(n=n.orderBy(u));const l=void 0!==t.pageCurrent?t.pageCurrent:this.mixinDatacomPage.current,h=void 0!==t.pageSize?t.pageSize:this.mixinDatacomPage.size,p=void 0!==t.getcount?t.getcount:this.getcount,f=void 0!==t.gettree?t.gettree:this.gettree,d=void 0!==t.gettreepath?t.gettreepath:this.gettreepath,g={getCount:p},y={limitLevel:void 0!==t.limitlevel?t.limitlevel:this.limitlevel,startWith:void 0!==t.startwith?t.startwith:this.startwith};return f&&(g.getTree=y),d&&(g.getTreePath=y),n=n.skip(h*(l-1)).limit(h).get(g),n}}};var e}})}var ge=de;export default ge; diff --git a/src/core/view/components/canvas/index.vue b/src/core/view/components/canvas/index.vue index 3167fa0035bc59ee66d873ac4f4849039d3d2953..d553daf22b06985e4d8789d73dff14eed13e24cb 100644 --- a/src/core/view/components/canvas/index.vue +++ b/src/core/view/components/canvas/index.vue @@ -4,10 +4,10 @@ :disable-scroll="disableScroll" v-on="_listeners" > -
@@ -311,9 +311,13 @@ export default { image.ready = true } - // 安卓 WebView 本地路径 - if (__PLATFORM__ === 'app-plus' && navigator.vendor === 'Google Inc.' && src.indexOf('file://') === 0) { - image.crossOrigin = 'anonymous' + // 安卓 WebView 除本地路径无跨域问题 + if (__PLATFORM__ === 'app-plus' && navigator.vendor === 'Google Inc.') { + if (src.indexOf('file://') === 0) { + image.crossOrigin = 'anonymous' + } + image.src = src + return } getSameOriginUrl(src).then(src => { image.src = src diff --git a/src/platforms/app-plus/helpers/file.js b/src/platforms/app-plus/helpers/file.js index 7f464af4fec989577e65a3cac8fec31b1a97f209..0cf1b9df7e676a30e832b98c8b3f100ed03c1ecb 100644 --- a/src/platforms/app-plus/helpers/file.js +++ b/src/platforms/app-plus/helpers/file.js @@ -48,6 +48,6 @@ export function getSameOriginUrl (url) { if (window.webkit && window.webkit.messageHandlers) { return getBase64(url) } - return url + return plus.io.convertLocalFileSystemURL(url) }) } diff --git a/src/platforms/app-plus/view/components/video/index.vue b/src/platforms/app-plus/view/components/video/index.vue index 22866c1d26e1e92170e65c8dc04a9dc313d03b22..f2b633adbbdcfb13cc55fb660096d9e0347ea82a 100644 --- a/src/platforms/app-plus/view/components/video/index.vue +++ b/src/platforms/app-plus/view/components/video/index.vue @@ -1,8 +1,8 @@