bindwechat.vue 10 KB

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