bindwechat.vue 11 KB

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