acdr-ui/dist/build/mp-weixin/sheep/platform/provider/wechat/miniProgram.js

2 lines
2.7 KiB
JavaScript

"use strict";var e=(e,n,i)=>new Promise(((t,o)=>{var r=e=>{try{s(i.next(e))}catch(n){o(n)}},c=e=>{try{s(i.throw(e))}catch(n){o(n)}},s=e=>e.done?t(e.value):Promise.resolve(e.value).then(r,c);s((i=i.apply(e,n)).next())}));const n=require("../../../../common/vendor.js"),i=require("../../../api/member/auth.js"),t=require("../../../api/member/social.js"),o=require("../../../api/member/user.js"),r=34;let c=[];function s(e){n.index.setStorageSync("openid",e)}function l(){return e(this,null,(function*(){const{code:e,data:n}=yield t.SocialApi.getSocialUser(r);if(0===e)return n}))}const d=(i=!0)=>e(exports,null,(function*(){if(n.index.canIUse("getUpdateManager")){const e=n.index.getUpdateManager();e.onCheckForUpdate((function(t){t.hasUpdate?(e.onUpdateReady((function(){n.index.showModal({title:"更新提示",content:"新版本已经准备好,是否重启应用?",success:function(n){n.confirm&&e.applyUpdate()}})})),e.onUpdateFailed((function(){}))):i||n.index.showModal({title:"当前为最新版本",showCancel:!1})}))}}));const u={load:function(){d(),function(){e(this,null,(function*(){const{code:e,data:n}=yield t.SocialApi.getSubscribeTemplateList();0===e&&(c=n)}))}()},login:()=>e(exports,null,(function*(){return new Promise(((t,o)=>e(exports,null,(function*(){const e=yield n.index.login();if("login:ok"!==e.errMsg)return t(!1);const o=yield i.AuthUtil.socialLogin(r,e.code,"default");return 0===o.code?(s(o.data.openid),t(!0)):t(!1)}))))})),bind:()=>new Promise(((i,o)=>e(exports,null,(function*(){const e=yield n.index.login();if("login:ok"!==e.errMsg)return i(!1);const o=yield t.SocialApi.socialBind(r,e.code,"default");return 0===o.code?(s(o.data),i(!0)):i(!1)})))),unbind:n=>e(exports,null,(function*(){const{code:e}=yield t.SocialApi.socialUnbind(r,n);return 0===e})),bindUserPhoneNumber:n=>new Promise(((i,t)=>e(exports,null,(function*(){const{code:e}=yield o.UserApi.updateUserMobileByWeixin(n.code);0===e&&i(!0),i(!1)})))),mobileLogin:t=>e(exports,null,(function*(){return new Promise(((o,r)=>e(exports,null,(function*(){if("getPhoneNumber:ok"!==t.errMsg)return o(!1);const e=yield n.index.login();if("login:ok"!==e.errMsg)return o(!1);const r=yield i.AuthUtil.weixinMiniAppLogin(t.code,e.code,"default");return 0===r.code?(s(r.data.openid),o(!0)):o(!1)}))))})),getInfo:l,getOpenid:function(i=!1){return e(this,null,(function*(){let e=n.index.getStorageSync("openid");if(!e&&i){const n=yield l();n&&n.openid&&(e=n.openid,s(e))}return e}))},subscribeMessage:function(e,i=void 0){const t=[];if("string"==typeof e){const n=c.find((n=>n.title.includes(e)));n&&t.push(n.id)}"object"==typeof e&&e.forEach((e=>{const n=c.find((n=>n.title.includes(e)));n&&t.push(n.id)})),0!==t.length&&n.index.requestSubscribeMessage({tmplIds:t,success:()=>{i&&i()},fail:e=>{}})},checkUpdate:d};exports.service=u;