bindwechat.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. <template>
  2. <view class="container login">
  3. <view class="login-main">
  4. <text class="logo-text">您的微信尚未绑定机构账号,填写以下资料进行绑定后,您能通过微信快速登录。</text>
  5. </view>
  6. <view class="login-form clearfix">
  7. <view class="login-input">
  8. <input type="text"
  9. v-model="bindLinkName"
  10. maxlength="30"
  11. class="input"
  12. placeholder="请输入姓名"
  13. />
  14. </view>
  15. </view>
  16. <view class="login-form clearfix">
  17. <view class="login-input">
  18. <input type="number"
  19. v-model="bindLinkPhone"
  20. maxlength="11"
  21. class="input"
  22. placeholder="请输入手机号"
  23. />
  24. </view>
  25. </view>
  26. <view class="login-form clearfix">
  27. <view class="login-input code">
  28. <input type="text"
  29. v-model="imageCode"
  30. maxlength="4"
  31. class="input"
  32. placeholder="请输入右侧图形验证码"
  33. />
  34. </view>
  35. <view class="login-input img-btn">
  36. <view class="vscodeimg">
  37. <image :src="imageCodeUrl" mode=""></image>
  38. </view>
  39. <view class="vscod-refresh" @click.stop="getVerificationCode">
  40. <text class="iconfont icon-shuaxin"></text>
  41. <text class="ref-text">刷新</text>
  42. </view>
  43. </view>
  44. </view>
  45. <view class="login-form clearfix">
  46. <view class="login-input code">
  47. <input type="number"
  48. v-model="mobildeCode"
  49. maxlength="6"
  50. class="input"
  51. placeholder="请输入短信验证码"
  52. />
  53. </view>
  54. <view class="login-input btn" :class="[isMobileDisabled ? 'disabled' : '']" >
  55. <button type="button"
  56. @click.stop="getMobileCodeFn"
  57. :disabled="isMobileDisabled"
  58. class="input">
  59. {{ mobileCodeText }}
  60. </button>
  61. </view>
  62. </view>
  63. <view class="login-form clearfix">
  64. <view class="login-btn" @click="bindWechatInfo">绑定并登录</view>
  65. </view>
  66. </view>
  67. </template>
  68. <script>
  69. import { mapState,mapMutations } from 'vuex'
  70. import authorize from '@/common/config/authorize.js'
  71. import { bindingWechat } from "@/api/use.js"
  72. import { getImageCode, getbindWechatCode } from "@/api/utils.js"
  73. export default{
  74. data() {
  75. return{
  76. userID:'',
  77. bindMobile:'',
  78. bindLinkName:'', //用户姓名
  79. bindLinkPhone:'', //用户手机号
  80. mobildeCode:'', //手机验证码
  81. imageCode:'', //图形验证码
  82. imageCodeUrl:'', //图形验证码地址
  83. imageCodetoken:'', //图形校验token
  84. isMobileDisabled:false, //获取手机短信按钮
  85. count: '', //倒计时
  86. mobileCodeText: '获取验证码',
  87. codeTime: null,
  88. loginType:'', //跳转类型
  89. alertText:'',
  90. listType: '',
  91. listVal: '',
  92. detilType:'',
  93. id:'',//商品ID
  94. getOption:''
  95. }
  96. },
  97. onLoad(option) {
  98. let data = JSON.parse(option.data);
  99. this.codeType = option.codeType
  100. this.option = option
  101. this.loginType = data.type;
  102. this.id = data.id
  103. if(data.listType) {
  104. this.listType = data.listType;
  105. this.listVal = data.listVal;
  106. }
  107. this.getVerificationCode()
  108. },
  109. methods:{
  110. ...mapMutations(['login']),
  111. bindWechatInfo(){
  112. if( this.bindLinkName == ''){
  113. this.$util.msg('请输入姓名',2000)
  114. return
  115. }
  116. if( this.bindLinkPhone == ''){
  117. this.$util.msg('请输入手机号',2000)
  118. return
  119. }
  120. if(!this.$reg.isMobile(this.bindLinkPhone)){
  121. this.$util.msg('请输入正确的手机号',2000)
  122. return
  123. }
  124. if( this.mobildeCode == ''){
  125. this.$util.msg('请输入手机验证码',2000)
  126. return
  127. }
  128. if(!this.$reg.isMobileCode(this.mobildeCode)){
  129. this.$util.msg('验证码格式不正确',2000)
  130. return
  131. }
  132. this.bindingWechatLogin()
  133. },
  134. getVerificationCode(){//图形验证
  135. getImageCode().then(res => {
  136. this.imageCodeUrl = res.data.baseImage
  137. this.imageCodetoken = res.data.token
  138. })
  139. },
  140. getMobileCodeFn(){//获取手机验证码
  141. if( this.bindLinkPhone == ''){
  142. this.$util.msg('请输入手机号',2000);
  143. return
  144. }
  145. if(!this.$reg.isMobile(this.bindLinkPhone)){
  146. this.$util.msg('请输入正确的手机号',2000);
  147. return
  148. }
  149. if( this.imageCode == ''){
  150. this.$util.msg('请输入图形验证码',2000);
  151. return
  152. }
  153. let params = {
  154. mobile:this.bindLinkPhone,
  155. mobileOrEmail:this.bindMobile,
  156. platformType:2,
  157. imgCode:this.imageCode,
  158. token:this.imageCodetoken,
  159. }
  160. this.isMobileDisabled = true;
  161. getbindWechatCode(params).then(res =>{
  162. const TIME_COUNT = 60;
  163. this.$util.msg('验证短信已发送',2000)
  164.       if (!this.codeTime) {
  165.         this.count = TIME_COUNT;
  166. this.isMobileDisabled = true;
  167.         this.codeTime = setInterval(() => {
  168.         if (this.count > 1 && this.count <= TIME_COUNT) {
  169.           this.count--
  170.           this.mobileCodeText = this.count +'s重新发送'
  171.          } else {
  172.           this.isMobileDisabled = false;
  173.           clearInterval(this.codeTime)
  174.           this.codeTime = null
  175. this.mobileCodeText = '获取验证码'
  176.          }
  177.         },1000)
  178.        }
  179. }).catch( res =>{
  180. this.$util.msg(res.msg,2000)
  181. this.isMobileDisabled = false;
  182. this.getVerificationCode()
  183. })
  184. },
  185. bindingWechatLogin(){//获取用户基本信息登录
  186. wx.getUserInfo({
  187. success: res => {
  188. console.log('useInfo:',res.userInfo)
  189. this.isUserInfo = false;
  190. this.userInfo = res.userInfo;
  191. let params ={
  192. userID:this.userID,
  193. mobile:this.bindLinkPhone,
  194. linkName:this.bindLinkName,
  195. verificationCode:this.mobildeCode,
  196. nickName:res.userInfo.nickName,
  197. headimgurl:res.userInfo.avatarUrl,
  198. }
  199. bindingWechat(params).then(response =>{
  200. // this.login(response.data);
  201. uni.switchTab({
  202. url:'/pages/tabBar/user/user'
  203. })
  204. }).catch(response =>{
  205. this.$util.msg(response.msg,2000)
  206. })
  207. }
  208. })
  209. },
  210. goUserLogininit(){
  211. let url;
  212. if(this.loginType) {
  213. if(this.loginType=='detilType'){
  214. this.$api.redirectTo(`/pages/goods/product?id=${this.id}&page=2`);
  215. }else if(this.loginType=='search'){
  216. this.$api.redirectTo('/pages/search/search');
  217. }else if(this.loginType == 1){
  218. url ='/pages/tabBar/cart/cart'
  219. }else if(this.loginType == 4){
  220. url ='/pages/tabBar/user/user'
  221. }else {
  222. url ='/pages/tabBar/home/home'
  223. }
  224. } else if(this.listType) {
  225. this.$api.navToListPage({type:this.listType,value:this.listVal,lType:'4'});
  226. }
  227. },
  228. //关闭未授权用户授权提示弹窗
  229. hideModel(){
  230. this.isUserInfo = false;
  231. }
  232. },
  233. onShow() {
  234. this.$api.getStorage().then((resolve) => {
  235. this.userID = resolve.userID
  236. this.bindMobile = resolve.bindMobile
  237. })
  238. }
  239. }
  240. </script>
  241. <style lang="scss">
  242. .login{
  243. width: 100%;
  244. height: auto;
  245. border-top: 1px solid #F7F7F7;
  246. .model-warp.none{
  247. display: none;
  248. }
  249. .model-warp.show{
  250. display: block;
  251. }
  252. .login-main{
  253. width: 702rpx;
  254. background: rgba(225, 86, 22, 0.1);
  255. display: flex;
  256. flex-direction: column;
  257. align-items: center;
  258. height: 68rpx;
  259. padding: 20rpx 24rpx;
  260. margin: 24rpx 0 118rpx 0;
  261. .logo-text{
  262. font-size: 24rpx;
  263. line-height: 34rpx;
  264. color: $color-system;
  265. }
  266. }
  267. .login-form{
  268. width: 702rpx;
  269. height: auto;
  270. padding: 0 24rpx;
  271. .login-input{
  272. width: 654rpx;
  273. height: 40rpx;
  274. padding: 24rpx;
  275. margin-bottom: 20rpx;
  276. background: #F7F7F7;
  277. border-radius: 14rpx;
  278. display: flex;
  279. flex-direction: column;
  280. align-items: center;
  281. &.code{
  282. width: 370rpx;
  283. float: left;
  284. margin-right: 20rpx;
  285. }
  286. &.btn{
  287. width: 258rpx;
  288. height: 88rpx;
  289. padding: 0;
  290. float: left;
  291. background: $btn-confirm;
  292. .input{
  293. width: 258rpx;
  294. height: 88rpx;
  295. line-height: 88rpx;
  296. padding: 0;
  297. border-radius: 14rpx;
  298. color: #FFFFFF;
  299. background: $btn-confirm;
  300. }
  301. &.disabled{
  302. background: #F7F7F7;
  303. .input{
  304. background: #F7F7F7;
  305. color: #999999;
  306. }
  307. }
  308. }
  309. &.img-btn{
  310. width: 250rpx;
  311. height: 88rpx;
  312. padding: 0;
  313. float: left;
  314. background: #FFFFFF;
  315. display: block;
  316. .vscodeimg{
  317. width: 180rpx;
  318. height: 88rpx;
  319. float: left;
  320. display: flex;
  321. flex-direction: column;
  322. align-items: center;
  323. border-radius: 14rpx;
  324. image{
  325. width: 180rpx;
  326. height: 88rpx;
  327. border-radius: 14rpx;
  328. }
  329. }
  330. .vscod-refresh{
  331. width: 70rpx;
  332. float: right;
  333. display: flex;
  334. flex-direction: column;
  335. align-items: center;
  336. .icon-shuaxin{
  337. font-size: 48rpx;
  338. color: #333333;
  339. }
  340. .ref-text{
  341. font-size: 24rpx;
  342. color: #333333;
  343. }
  344. }
  345. }
  346. .input{
  347. width: 100%;
  348. height: 100%;
  349. background: #F7F7F7;
  350. font-size: $font-size-28;
  351. line-height: 40rpx;
  352. color: #333333;
  353. border-radius: 14rpx;
  354. }
  355. }
  356. }
  357. .login-btn{
  358. width: 702rpx;
  359. height: 88rpx;
  360. border-radius: 14rpx;
  361. font-size: $font-size-28;
  362. line-height: 88rpx;
  363. color: #FFFFFF;
  364. margin: 0 auto;
  365. text-align: center;
  366. background: $btn-confirm;
  367. margin-top: 100rpx;
  368. }
  369. .model-authorization{
  370. width: 100%;
  371. height: 100%;
  372. position: fixed;
  373. top: 0;
  374. left: 0;
  375. z-index: 999;
  376. .authorization{
  377. width: 518rpx;
  378. height: 320rpx;
  379. position: absolute;
  380. background: rgba(255,255,255,.7);
  381. left: 0;
  382. right: 0;
  383. bottom: 0;
  384. top: 0;
  385. margin: auto;
  386. .to-btn{
  387. position: absolute;
  388. top: 0;
  389. left: 0;
  390. right: 0;
  391. bottom: 0;
  392. margin: auto;
  393. width: 70%;
  394. height: 88rpx;
  395. font-size: $font-size-28;
  396. line-height: 88rpx;
  397. color: #FFFFFF;
  398. text-align: center;
  399. border-radius: 44rpx;
  400. }
  401. }
  402. }
  403. }
  404. </style>