bindwechat.vue 11 KB

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