1 |
- import api from"../../common/api/index";import store from"../../store/index";import Util from"../../common/utils/utils";Component({properties:{authType:{type:String,value:"",observer(t){const{authSettings:e}=this.data,a={code:e.codeAuthTips,phone:e.authTips,info:e.infoAuthTips}[t];this.setData({headText:a})}},authSettings:{type:Object,value:{}},channelId:{type:String,value:""},options:{type:Object,value:{}},infoFieldsModels:{type:Array,value:[],observer(t){const e=Array.from({length:t.length},(()=>""));let a=!1;t.forEach(((t,s)=>{"option"===t.type&&(e[s]=0),"mobile"===t.type&&(e[s]="mobile"),"Y"===t.sms&&(a=!0)})),this.setData({infoParams:e,needSms:a})}}},data:{headText:"",inputValue:"",optionIndex:0,infoImage:"",disable:!0,telephone:"",kaptcha:"",msg:"",infoParams:[],needSms:!1,imageId:"",smsBtnText:"点击获取",stopCount:!0,isCounting:!1},lifetimes:{attached(){store.get({"main.imageId":t=>{this.setData({imageId:t})}}),this.getInfoImage(),this.setData({stopCount:!1});const t=wx.getStorageSync("countValue");t>0&&this.smsCountDown(Date.now(),t,(t=>{this.setData({smsBtnText:`${t}秒`,disable:!0,isCounting:!0})}))},detached(){this.redirectTo=null}},methods:{hide(){this.triggerEvent("hideAuth",!1)},bindKeyInput(t){this.setData({inputValue:t.detail.value})},infoInput(t){const e=this.data.infoParams,a=t.target.dataset.index,s=t.detail.value;e[a]=s,this.setData({infoParams:e})},getInfoImage(){const{channelId:t,imageId:e}=this.data;this.setData({infoImage:`https://live.polyv.cn/kaptcha?channelId=${t}&imageId=${e}&id=${Date.now()}`})},authCheck(){const{authType:t}=this.data;switch(t){case"code":this.codeCheck();break;case"phone":this.phoneCheck();break;case"info":this.infoCheck()}},bindPickerChange(t){const e=t.detail.value,a=t.target.dataset.index,s=this.data.infoParams;s[a]=e,this.setData({infoParams:s})},telInput(t){const{kaptcha:e,isCounting:a}=this.data;this.setData({telephone:t.detail.value,disable:!0}),5===e.length&&11===t.detail.value.length&&this.setData({disable:a})},kaptchaInput(t){const{telephone:e,isCounting:a}=this.data;this.setData({kaptcha:t.detail.value,disable:!0}),11===e.length&&5===t.detail.value.length&&this.setData({disable:a})},msgInput(t){this.setData({msg:t.detail.value})},getInfoMsg(){const{channelId:t,telephone:e,kaptcha:a,imageId:s,isCounting:o}=this.data;o||(Util.isPhoneNO(e)?5===a.length?api.getMsg(t,{mobile:e,kaptcha:a,imageId:s}).then((t=>{200!==t.data.code?(this.toastShow("验证码错误"),this.getInfoImage(),this.setData({kaptcha:""})):(this.setData({stopCount:!1}),this.smsCountDown(Date.now(),18e4,(t=>{this.setData({smsBtnText:`${t}秒`,disable:!0,isCounting:!0})})))})):this.toastShow("请输入完整图片验证码"):this.toastShow("请输入正确的手机号"))},infoCheck(){const{channelId:t,telephone:e,msg:a}=this.data;let{infoParams:s}=this.data;const{userName:o,avatarUrl:n,openId:i,scene:h}=this.data.options;this.checkInfoParams(s)&&(s=this.updateSelectParams(s),api.checkChannelInfo({channelId:t,propValue1:"mobile"===s[0]?"":s[0],propValue2:"mobile"===s[1]?"":s[1],propValue3:"mobile"===s[2]?"":s[2],propValue4:"mobile"===s[3]?"":s[3],propValue5:"mobile"===s[4]?"":s[4],propValue6:"mobile"===s[5]?"":s[5],propValue7:"mobile"===s[6]?"":s[6],propValue8:"mobile"===s[7]?"":s[7],propValue9:"mobile"===s[8]?"":s[8],propValue10:"mobile"===s[9]?"":s[9],mobile:e||"",smsCode:a||""}).then((e=>{if(200!==e.data.code)this.toastShow(e.data.message);else{this.setData({smsBtnText:"点击获取",stopCount:!0,isCounting:!1}),e&&e.header&&e.header["Set-Cookie"]&&wx.setStorageSync("cookieKey",e.header["Set-Cookie"]);let a=o;e.data.data.nickname&&(a=e.data.data.nickname,store.set({"main.userName":a})),wx.setStorageSync("plvAuthType","info"),this.enterToWatch({channelId:t,name:a,avatarUrl:n,openId:i,scene:h})}})))},phoneCheck(){const{inputValue:t,channelId:e}=this.data,{avatarUrl:a,openId:s,scene:o}=this.data.options;""!==t?api.checkChannelPhone({channelId:e,phone:t,origin:"applet"}).then((t=>{if(200===t.data.code){t&&t.header&&t.header["Set-Cookie"]&&wx.setStorageSync("cookieKey",t.header["Set-Cookie"]);const{nickname:n,viewerId:i}=t.data.data;store.set({"main.userName":n}),wx.setStorageSync("plvAuthType","phone"),this.enterToWatch({channelId:e,name:n,avatarUrl:a,openId:s,viewerId:i,scene:o})}else this.toastShow("会员码错误")})):this.toastShow("会员码不能为空")},codeCheck(){const{inputValue:t,channelId:e}=this.data,{userName:a,avatarUrl:s,openId:o,scene:n}=this.data.options;""!==t?api.checkChannelCode({channelId:e,code:t}).then((t=>{if(200===t.data.code){t&&t.header&&t.header["Set-Cookie"]&&wx.setStorageSync("cookieKey",t.header["Set-Cookie"]);let i=a;t.data.data.nickname&&(i=t.data.data.nickname,store.set({"main.userName":i})),wx.setStorageSync("plvAuthType","code"),this.enterToWatch({channelId:e,name:i,avatarUrl:s,openId:o,scene:n})}else this.toastShow("验证码错误")})):this.toastShow("验证码不能为空")},checkInfoParams(t){let e=!0;return t.forEach((t=>{if(0===t||t||(e=!1,this.toastShow("请填写所有信息后提交")),"mobile"===t){const{telephone:t,msg:a,needSms:s}=this.data;t||(this.toastShow("请填写手机号"),e=!1),!a&&s&&(this.toastShow("短信验证码错误"),e=!1)}})),e},updateSelectParams(t){const e=t;return this.data.infoFieldsModels.forEach(((t,a)=>{"option"===t.type&&(e[a]=t.options[e[a]])})),e},smsCountDown(t,e,a){if(!a||!t||!e)return;const{stopCount:s}=this.data,o=Math.max(0,e-(Date.now()-t));if(o>0&&!s&&setTimeout((()=>this.smsCountDown(t,e,a)),1e3),o>0&&(wx.setStorageSync("countValue",o),a(Math.round(o/1e3))),0===o){wx.setStorageSync("countValue","");const{kaptcha:t,telephone:e}=this.data;this.setData({smsBtnText:"再次发送",isCounting:!1}),5===t.length&&11===e.length&&this.setData({disable:!1})}},enterToWatch(...t){"function"!=typeof this.redirectTo&&(this.redirectTo=Util.throttle((t=>{const{channelId:e,name:a,avatarUrl:s,openId:o,viewerId:n,scene:i}=t,h=n?`&viewerId=${n}`:"";let d="/pages/watch/watch";"vertical"===i&&(d="/pages/vertical/vertical"),wx.redirectTo({url:`${d}?channelId=${e}&userName=${a}&avatarUrl=${s}&openId=${o}${h}`})}))),this.redirectTo(...t)},previewImage(){const{qcodeImg:t}=this.data.authSettings;wx.previewImage({current:`https:${t}`,urls:[`https:${t}`]})},toastShow(t,e=2e3){wx.showToast({title:t,icon:"none",duration:e})}}});
|