bindwechat.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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 wxLogin from "@/common/config/wxLogin.js"
  72. import { bindingWechat } from "@/api/use.js"
  73. import { getImageCode, getbindWechatCode } from "@/api/utils.js"
  74. export default{
  75. data() {
  76. return{
  77. userID:'',
  78. bindMobile:'',
  79. bindLinkName:'', //用户姓名
  80. bindLinkPhone:'', //用户手机号
  81. mobildeCode:'', //手机验证码
  82. imageCode:'', //图形验证码
  83. imageCodeUrl:'', //图形验证码地址
  84. imageCodetoken:'', //图形校验token
  85. isMobileDisabled:false, //获取手机短信按钮
  86. count: '', //倒计时
  87. mobileCodeText: '获取验证码',
  88. codeTime: null,
  89. loginType:'', //跳转类型
  90. alertText:'',
  91. listType: '',
  92. listVal: '',
  93. detilType:'',
  94. id:'',//商品ID
  95. getOption:''
  96. }
  97. },
  98. onLoad(option) {
  99. let data = JSON.parse(option.data);
  100. this.codeType = option.codeType
  101. this.option = option
  102. this.loginType = data.type;
  103. this.id = data.id
  104. if(data.listType) {
  105. this.listType = data.listType;
  106. this.listVal = data.listVal;
  107. }
  108. this.getVerificationCode()
  109. },
  110. methods:{
  111. ...mapMutations(['login']),
  112. bindWechatInfo(){
  113. if( this.bindLinkName == ''){
  114. this.$util.msg('请输入姓名',2000)
  115. return
  116. }
  117. if( this.bindLinkPhone == ''){
  118. this.$util.msg('请输入手机号',2000)
  119. return
  120. }
  121. if(!this.$reg.isMobile(this.bindLinkPhone)){
  122. this.$util.msg('请输入正确的手机号',2000)
  123. return
  124. }
  125. if( this.mobildeCode == ''){
  126. this.$util.msg('请输入手机验证码',2000)
  127. return
  128. }
  129. if(!this.$reg.isMobileCode(this.mobildeCode)){
  130. this.$util.msg('验证码格式不正确',2000)
  131. return
  132. }
  133. this.bindingWechatLogin()
  134. },
  135. getVerificationCode(){//图形验证
  136. getImageCode().then(res => {
  137. this.imageCodeUrl = res.data.baseImage
  138. this.imageCodetoken = res.data.token
  139. })
  140. },
  141. getMobileCodeFn(){//获取手机验证码
  142. if( this.bindLinkPhone == ''){
  143. this.$util.msg('请输入手机号',2000);
  144. return
  145. }
  146. if(!this.$reg.isMobile(this.bindLinkPhone)){
  147. this.$util.msg('请输入正确的手机号',2000);
  148. return
  149. }
  150. if( this.imageCode == ''){
  151. this.$util.msg('请输入图形验证码',2000);
  152. return
  153. }
  154. let params = {
  155. mobile:this.bindLinkPhone,
  156. mobileOrEmail:this.bindMobile,
  157. platformType:2,
  158. imgCode:this.imageCode,
  159. token:this.imageCodetoken,
  160. }
  161. this.isMobileDisabled = true;
  162. getbindWechatCode(params).then(res =>{
  163. const TIME_COUNT = 60;
  164. this.$util.msg('验证短信已发送',2000)
  165.       if (!this.codeTime) {
  166.         this.count = TIME_COUNT;
  167. this.isMobileDisabled = true;
  168.         this.codeTime = setInterval(() => {
  169.         if (this.count > 1 && this.count <= TIME_COUNT) {
  170.           this.count--
  171.           this.mobileCodeText = this.count +'s重新发送'
  172.          } else {
  173.           this.isMobileDisabled = false;
  174.           clearInterval(this.codeTime)
  175.           this.codeTime = null
  176. this.mobileCodeText = '获取验证码'
  177.          }
  178.         },1000)
  179.        }
  180. }).catch( error =>{
  181. this.$util.msg(error.msg,2000)
  182. this.isMobileDisabled = false;
  183. })
  184. },
  185. bindingWechatLogin(){//获取用户基本信息登录
  186. wx.getUserInfo({
  187. success: res => {
  188. this.isUserInfo = false;
  189. this.userInfo = res.userInfo;
  190. let params ={
  191. userID:this.userID,
  192. mobile:this.bindLinkPhone,
  193. linkName:this.bindLinkName,
  194. verificationCode:this.mobildeCode,
  195. nickName:res.userInfo.nickName,
  196. headimgurl:res.userInfo.avatarUrl,
  197. }
  198. bindingWechat(params).then(response =>{
  199. wxLogin.wxLoginAuthorize()
  200. this.$api.switchTabTo('/pages/tabBar/user/user')
  201. }).catch(error =>{
  202. this.$util.msg(error.msg,2000)
  203. })
  204. }
  205. })
  206. },
  207. //关闭未授权用户授权提示弹窗
  208. hideModel(){
  209. this.isUserInfo = false;
  210. }
  211. },
  212. onShow() {
  213. this.$api.getStorage().then((resolve) => {
  214. this.userID = resolve.userID
  215. this.bindMobile = resolve.bindMobile
  216. })
  217. }
  218. }
  219. </script>
  220. <style lang="scss">
  221. .login{
  222. width: 100%;
  223. height: auto;
  224. border-top: 1px solid #F7F7F7;
  225. .model-warp.none{
  226. display: none;
  227. }
  228. .model-warp.show{
  229. display: block;
  230. }
  231. .login-main{
  232. width: 702rpx;
  233. background: rgba(225, 86, 22, 0.1);
  234. display: flex;
  235. flex-direction: column;
  236. align-items: center;
  237. height: 68rpx;
  238. padding: 20rpx 24rpx;
  239. margin: 24rpx 0 118rpx 0;
  240. .logo-text{
  241. font-size: 24rpx;
  242. line-height: 34rpx;
  243. color: $color-system;
  244. }
  245. }
  246. .login-form{
  247. width: 702rpx;
  248. height: auto;
  249. padding: 0 24rpx;
  250. .login-input{
  251. width: 654rpx;
  252. height: 40rpx;
  253. padding: 24rpx;
  254. margin-bottom: 20rpx;
  255. background: #F7F7F7;
  256. border-radius: 14rpx;
  257. display: flex;
  258. flex-direction: column;
  259. align-items: center;
  260. &.code{
  261. width: 370rpx;
  262. float: left;
  263. margin-right: 20rpx;
  264. }
  265. &.btn{
  266. width: 258rpx;
  267. height: 88rpx;
  268. padding: 0;
  269. float: left;
  270. background: $btn-confirm;
  271. .input{
  272. width: 258rpx;
  273. height: 88rpx;
  274. line-height: 88rpx;
  275. padding: 0;
  276. border-radius: 14rpx;
  277. color: #FFFFFF;
  278. background: $btn-confirm;
  279. }
  280. &.disabled{
  281. background: #F7F7F7;
  282. .input{
  283. background: #F7F7F7;
  284. color: #999999;
  285. }
  286. }
  287. }
  288. &.img-btn{
  289. width: 250rpx;
  290. height: 88rpx;
  291. padding: 0;
  292. float: left;
  293. background: #FFFFFF;
  294. display: block;
  295. .vscodeimg{
  296. width: 180rpx;
  297. height: 88rpx;
  298. float: left;
  299. display: flex;
  300. flex-direction: column;
  301. align-items: center;
  302. border-radius: 14rpx;
  303. image{
  304. width: 180rpx;
  305. height: 88rpx;
  306. border-radius: 14rpx;
  307. }
  308. }
  309. .vscod-refresh{
  310. width: 70rpx;
  311. float: right;
  312. display: flex;
  313. flex-direction: column;
  314. align-items: center;
  315. .icon-shuaxin{
  316. font-size: 48rpx;
  317. color: #333333;
  318. }
  319. .ref-text{
  320. font-size: 24rpx;
  321. color: #333333;
  322. }
  323. }
  324. }
  325. .input{
  326. width: 100%;
  327. height: 100%;
  328. background: #F7F7F7;
  329. font-size: $font-size-28;
  330. line-height: 40rpx;
  331. color: #333333;
  332. border-radius: 14rpx;
  333. }
  334. }
  335. }
  336. .login-btn{
  337. width: 702rpx;
  338. height: 88rpx;
  339. border-radius: 14rpx;
  340. font-size: $font-size-28;
  341. line-height: 88rpx;
  342. color: #FFFFFF;
  343. margin: 0 auto;
  344. text-align: center;
  345. background: $btn-confirm;
  346. margin-top: 100rpx;
  347. }
  348. .model-authorization{
  349. width: 100%;
  350. height: 100%;
  351. position: fixed;
  352. top: 0;
  353. left: 0;
  354. z-index: 999;
  355. .authorization{
  356. width: 518rpx;
  357. height: 320rpx;
  358. position: absolute;
  359. background: rgba(255,255,255,.7);
  360. left: 0;
  361. right: 0;
  362. bottom: 0;
  363. top: 0;
  364. margin: auto;
  365. .to-btn{
  366. position: absolute;
  367. top: 0;
  368. left: 0;
  369. right: 0;
  370. bottom: 0;
  371. margin: auto;
  372. width: 70%;
  373. height: 88rpx;
  374. font-size: $font-size-28;
  375. line-height: 88rpx;
  376. color: #FFFFFF;
  377. text-align: center;
  378. border-radius: 44rpx;
  379. }
  380. }
  381. }
  382. }
  383. </style>