bindwechat.vue 8.8 KB

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