bindwechat.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  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','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. this.$api.switchTabTo('/pages/tabBar/user/user')
  168. }
  169. }
  170. uni.removeStorageSync('LOGIN_REDIRECT_URL')
  171. }catch(error){
  172. this.$util.msg(error.msg, 2000)
  173. }
  174. },
  175. getVerificationCode(){//图形验证
  176. this.PublicService.GetImgVerifyCode().then(res => {
  177. this.imageCodeUrl = res.data.baseImage
  178. this.imageCodetoken = res.data.token
  179. })
  180. },
  181. getMobileCodeFn(){//获取手机验证码
  182. if( this.bindLinkPhone == ''){
  183. this.$util.msg('请输入手机号',2000)
  184. return
  185. }
  186. if(!this.$reg.isMobile(this.bindLinkPhone)){
  187. this.$util.msg('请输入正确的手机号',2000)
  188. return
  189. }
  190. if( this.imageCode == ''){
  191. this.$util.msg('请输入图形验证码',2000)
  192. return
  193. }
  194. let params = {
  195. mobile:this.bindLinkPhone,
  196. bindMobile:this.bindMobile,
  197. platformType:2,
  198. isCheckCaptcha:0,
  199. imgCode:this.imageCode,
  200. token:this.imageCodetoken,
  201. }
  202. this.isMobileDisabled = true
  203. this.PublicService.GetBindMobileCode(params)
  204. .then(res =>{
  205. const TIME_COUNT = 60
  206. this.$util.msg('验证短信已发送',2000)
  207. if (!this.codeTime) {
  208. this.count = TIME_COUNT
  209. this.isMobileDisabled = true
  210. this.codeTime = setInterval(() => {
  211. if (this.count > 1 && this.count <= TIME_COUNT) {
  212. this.count--
  213. this.mobileCodeText = this.count +'s重新发送'
  214. } else {
  215. this.isMobileDisabled = false
  216. clearInterval(this.codeTime)
  217. this.codeTime = null
  218. this.mobileCodeText = '获取验证码'
  219. }
  220. },1000)
  221. }
  222. })
  223. .catch( error =>{
  224. this.$util.msg(error.msg,2000)
  225. this.isMobileDisabled = false
  226. })
  227. },
  228. //关闭未授权用户授权提示弹窗
  229. hideModel(){
  230. this.isUserInfo = false
  231. }
  232. },
  233. async onShow() {
  234. const res = await this.$api.getStorage()
  235. this.unionId = res.unionId
  236. this.userId = res.userId
  237. this.bindMobile = res.bindMobile
  238. this.userIdentity = res.userIdentity
  239. console.log(this.unionId)
  240. }
  241. }
  242. </script>
  243. <style lang="scss">
  244. .login{
  245. width: 100%;
  246. height: auto;
  247. box-sizing: border-box;
  248. border-top: 1px solid #F7F7F7;
  249. .model-warp.none{
  250. display: none;
  251. }
  252. .model-warp.show{
  253. display: block;
  254. }
  255. .login-main{
  256. width: 100%;
  257. background: rgba(225, 86, 22, 0.1);
  258. display: flex;
  259. flex-direction: column;
  260. align-items: center;
  261. height: auto;
  262. padding: 20rpx 24rpx;
  263. margin: 24rpx 0 118rpx 0;
  264. box-sizing: border-box;
  265. .logo-text{
  266. font-size: 24rpx;
  267. line-height: 34rpx;
  268. color: $color-system;
  269. }
  270. }
  271. .login-container{
  272. width: 100%;
  273. height: auto;
  274. padding: 0 24rpx;
  275. box-sizing: border-box;
  276. }
  277. .login-form{
  278. width: 100%;
  279. height: auto;
  280. box-sizing: border-box;
  281. border-bottom: 1px solid #E1E1E1;
  282. &.none{
  283. border-bottom: none;
  284. }
  285. .login-input{
  286. width: 100%;
  287. height: 60rpx;
  288. padding: 20rpx 0;
  289. background: #FFFFFF;
  290. display: flex;
  291. flex-direction: column;
  292. align-items: center;
  293. &.code{
  294. width: 370rpx;
  295. float: left;
  296. margin-right: 20rpx;
  297. }
  298. &.btn{
  299. width: 220rpx;
  300. height: 64rpx;
  301. padding: 0;
  302. float: left;
  303. background: $btn-confirm;
  304. border-radius: 32rpx;
  305. margin-top: 15rpx;
  306. .input{
  307. width: 220rpx;
  308. height: 64rpx;
  309. line-height: 64rpx;
  310. padding: 0;
  311. border-radius: 32rpx;
  312. color: #FFFFFF;
  313. background: $btn-confirm;
  314. }
  315. &.disabled{
  316. background: #F7F7F7;
  317. .input{
  318. background: #F7F7F7;
  319. color: #999999;
  320. }
  321. }
  322. }
  323. &.img-btn{
  324. width: 300rpx;
  325. height: 64rpx;
  326. padding: 0;
  327. float: left;
  328. background: #FFFFFF;
  329. display: block;
  330. border-bottom: none;
  331. margin-top: 16rpx;
  332. .vscodeimg{
  333. width: 160rpx;
  334. height: 64rpx;
  335. float: left;
  336. display: flex;
  337. flex-direction: column;
  338. align-items: center;
  339. border-radius: 6rpx;
  340. image{
  341. width: 180rpx;
  342. height: 88rpx;
  343. border-radius: 6rpx;
  344. }
  345. }
  346. .vscod-refresh{
  347. width: 100rpx;
  348. float: right;
  349. height: 64rpx;
  350. .icon-shuaxin{
  351. font-size: 40rpx;
  352. color: #999999;
  353. display: block;
  354. float: left;
  355. height: 64rpx;
  356. line-height: 64rpx;
  357. }
  358. .ref-text{
  359. display: block;
  360. float: right;
  361. height: 64rpx;
  362. line-height: 64rpx;
  363. font-size: 24rpx;
  364. color: #999999;
  365. }
  366. }
  367. }
  368. .input{
  369. width: 100%;
  370. height: 100%;
  371. background: #FFFFFF;
  372. font-size: $font-size-28;
  373. line-height: 40rpx;
  374. color: #333333;
  375. border-radius: 14rpx;
  376. }
  377. }
  378. }
  379. .login-btn{
  380. width: 600rpx;
  381. height: 88rpx;
  382. border-radius: 44rpx;
  383. font-size: $font-size-28;
  384. line-height: 88rpx;
  385. color: #FFFFFF;
  386. margin: 0 auto;
  387. text-align: center;
  388. background: $btn-confirm;
  389. margin-top: 100rpx;
  390. }
  391. .model-authorization{
  392. width: 100%;
  393. height: 100%;
  394. position: fixed;
  395. top: 0;
  396. left: 0;
  397. z-index: 999;
  398. .authorization{
  399. width: 518rpx;
  400. height: 320rpx;
  401. position: absolute;
  402. background: rgba(255,255,255,.7);
  403. left: 0;
  404. right: 0;
  405. bottom: 0;
  406. top: 0;
  407. margin: auto;
  408. .to-btn{
  409. position: absolute;
  410. top: 0;
  411. left: 0;
  412. right: 0;
  413. bottom: 0;
  414. margin: auto;
  415. width: 70%;
  416. height: 88rpx;
  417. font-size: $font-size-28;
  418. line-height: 88rpx;
  419. color: #FFFFFF;
  420. text-align: center;
  421. border-radius: 44rpx;
  422. }
  423. }
  424. }
  425. }
  426. </style>