bindOperator.vue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. <template>
  2. <view class="container login" v-if="isUserInfo">
  3. <view class="login-form clearfix">
  4. <view class="login-input">
  5. <input type="text"
  6. v-model="bindLinkName"
  7. maxlength="30"
  8. class="input"
  9. placeholder="请输入姓名"
  10. />
  11. </view>
  12. </view>
  13. <view class="login-form clearfix">
  14. <view class="login-input">
  15. <input type="number"
  16. v-model="bindMobile"
  17. maxlength="11"
  18. class="input"
  19. placeholder="请输入手机号"
  20. />
  21. </view>
  22. </view>
  23. <view class="login-form clearfix">
  24. <view class="login-input code">
  25. <input type="text"
  26. v-model="imageCode"
  27. maxlength="4"
  28. class="input"
  29. placeholder="请输入右侧图形验证码"
  30. />
  31. </view>
  32. <view class="login-input img-btn">
  33. <view class="vscodeimg">
  34. <image :src="imageCodeUrl" mode=""></image>
  35. </view>
  36. <view class="vscod-refresh" @click.stop="getVerificationCode">
  37. <text class="iconfont icon-shuaxin"></text>
  38. <text class="ref-text">刷新</text>
  39. </view>
  40. </view>
  41. </view>
  42. <view class="login-form clearfix">
  43. <view class="login-input code">
  44. <input type="number"
  45. v-model="mobildeCode"
  46. maxlength="6"
  47. class="input"
  48. placeholder="请输入短信验证码"
  49. />
  50. </view>
  51. <view class="login-input btn" :class="[isMobileDisabled ? 'disabled' : '']" >
  52. <button type="button"
  53. @click.stop="getMobileCodeFn"
  54. :disabled="isMobileDisabled"
  55. class="input">
  56. {{ mobileCodeText }}
  57. </button>
  58. </view>
  59. </view>
  60. <view class="login-form clearfix">
  61. <view class="login-btn" @click="bindWechatInfo">绑定并登录</view>
  62. </view>
  63. <view class="login-foot">
  64. <text class="foot-text">本操作会绑定您的微信,绑定后您可使用微信直接登录【采美采购商城】小程序。</text>
  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 { userInfoLogin } from "@/api/use.js"
  73. import { getImageCode, getbindOperatorCode } from "@/api/utils.js"
  74. import { sellerBindingOperation } from "@/api/seller.js"
  75. export default{
  76. data() {
  77. return{
  78. wxUserInfo:'', //储存用户微信信息
  79. bindLinkName:'', //用户姓名
  80. bindMobile:'', //用户手机号
  81. mobildeCode:'', //手机验证码
  82. imageCode:'', //图形验证码
  83. imageCodeUrl:'', //图形验证码地址
  84. imageCodetoken:'', //图形校验token
  85. isMobileDisabled:false, //获取手机短信按钮
  86. count: '', //倒计时
  87. mobileCodeText: '获取验证码',
  88. codeTime: null,
  89. isUserInfo:false
  90. }
  91. },
  92. onLoad(option) {
  93. uni.setStorageSync('bind_id', option.userID);
  94. this.getVerificationCode()
  95. },
  96. methods:{
  97. ...mapMutations(['login','logout']),
  98. getCheekeyCode(){// 根据微信的code获取用户登录状态:1已登录过 -1未登录过
  99. authorize.getCode('weixin').then(wechatcode =>{
  100. // 根据微信的code获取用户登录状态:1已登录过 -1未登录过
  101. userInfoLogin({code:wechatcode}).then(response =>{
  102. this.login(response.data)
  103. uni.setStorageSync('token',response.data.token)
  104. uni.removeStorageSync('sessionid')
  105. uni.setStorageSync('sessionid','JSESSIONID='+response.data.sessionId)
  106. this.$store.commit('updateStatus',response.data)
  107. if(response.data.userIdentity ==1){
  108. this.$api.navigateTo('/market/pages/index/index')
  109. }else{
  110. this.$api.navigateTo('/pages/tabBar/home/home')
  111. }
  112. }).catch(response =>{
  113. this.logout()
  114. this.isUserInfo = true
  115. uni.removeStorageSync('sessionid')
  116. uni.setStorageSync('sessionid','JSESSIONID='+response.data)
  117. this.$store.commit('updateStatus',response.data)
  118. })
  119. })
  120. },
  121. bindWechatInfo(){
  122. if( this.bindLinkName == ''){
  123. this.$util.msg('请输入姓名',2000)
  124. return
  125. }
  126. if( this.bindMobile == ''){
  127. this.$util.msg('请输入手机号',2000)
  128. return
  129. }
  130. if(!this.$reg.isMobile(this.bindMobile)){
  131. this.$util.msg('请输入正确的手机号',2000)
  132. return
  133. }
  134. if( this.mobildeCode == ''){
  135. this.$util.msg('请输入手机验证码',2000)
  136. return
  137. }
  138. if(!this.$reg.isMobileCode(this.mobildeCode)){
  139. this.$util.msg('验证码格式不正确',2000)
  140. return
  141. }
  142. this.bindingWechatLogin()
  143. },
  144. getVerificationCode(){//图形验证
  145. getImageCode().then(res => {
  146. this.imageCodeUrl = res.data.baseImage
  147. this.imageCodetoken = res.data.token
  148. })
  149. },
  150. getMobileCodeFn(){//获取手机验证码
  151. if( this.bindMobile == ''){
  152. this.$util.msg('请输入手机号',2000);
  153. return
  154. }
  155. if(!this.$reg.isMobile(this.bindMobile)){
  156. this.$util.msg('请输入正确的手机号',2000);
  157. return
  158. }
  159. if( this.imageCode == ''){
  160. this.$util.msg('请输入图形验证码',2000);
  161. return
  162. }
  163. let params = {
  164. userId:uni.getStorageSync('bind_id'),
  165. mobile:this.bindMobile,
  166. platformType:2,
  167. imgCode:this.imageCode,
  168. token:this.imageCodetoken,
  169. }
  170. this.isMobileDisabled = true;
  171. getbindOperatorCode(params).then(res =>{
  172. const TIME_COUNT = 60;
  173. this.$util.msg('验证短信已发送',2000)
  174.       if (!this.codeTime) {
  175.         this.count = TIME_COUNT;
  176. this.isMobileDisabled = true;
  177.         this.codeTime = setInterval(() => {
  178.         if (this.count > 1 && this.count <= TIME_COUNT) {
  179.           this.count--
  180.           this.mobileCodeText = this.count +'s重新发送'
  181.          } else {
  182.           this.isMobileDisabled = false;
  183.           clearInterval(this.codeTime)
  184.           this.codeTime = null
  185. this.mobileCodeText = '获取验证码'
  186.          }
  187.         },1000)
  188.        }
  189. }).catch( res =>{
  190. this.$util.msg(res.msg,2000)
  191. this.isMobileDisabled = false;
  192. })
  193. },
  194. bindingWechatLogin(){//获取用户基本信息登录
  195. wx.getUserInfo({
  196. success: res => {
  197. this.wxUserInfo = res.userInfo;
  198. let params ={
  199. userID: uni.getStorageSync('bind_id'),
  200. mobile: this.bindMobile,
  201. linkName: this.bindLinkName,
  202. verificationCode: this.mobildeCode,
  203. nickName: this.wxUserInfo.nickName,
  204. headimgurl: this.wxUserInfo.avatarUrl,
  205. }
  206. sellerBindingOperation(params).then(response =>{
  207. if(response.code == 0){
  208. this.login(response.data);
  209. this.$api.switchTabTo('/pages/tabBar/user/user')
  210. }else if(response.code == 4){
  211. this.login(response.data)
  212. this.$api.navigateTo(`/pages/login/bindemail?pathType=1`)
  213. }else{
  214. this.$util.msg(response.msg,2000)
  215. }
  216. })
  217. }
  218. })
  219. }
  220. },
  221. onShow() {
  222. //查看此微信用户是否已经授权过
  223. authorize.getSetting().then(res =>{// console.log('是否已授权',res);//0:为取消授权 1:为已授权 2:为未操作
  224. if(res != 1){
  225. this.$api.navigateTo('/pages/authorization/authorization?type=3')
  226. }else{
  227. this.getCheekeyCode()
  228. }
  229. })
  230. }
  231. }
  232. </script>
  233. <style lang="scss">
  234. .login{
  235. width: 100%;
  236. height: auto;
  237. border-top: 1px solid #F7F7F7;
  238. padding-top: 100rpx;
  239. .login-foot{
  240. width: 702rpx;
  241. height: 88rpx;
  242. padding: 0 24rpx;
  243. margin-top: 30rpx;
  244. .foot-text{
  245. font-size: 24rpx;
  246. line-height: 44rpx;
  247. color:$text-color;
  248. }
  249. }
  250. .login-form{
  251. width: 702rpx;
  252. height: auto;
  253. padding: 0 24rpx;
  254. .login-input{
  255. width: 654rpx;
  256. height: 40rpx;
  257. padding: 24rpx;
  258. margin-bottom: 20rpx;
  259. background: #F7F7F7;
  260. border-radius: 14rpx;
  261. display: flex;
  262. flex-direction: column;
  263. align-items: center;
  264. &.code{
  265. width: 370rpx;
  266. float: left;
  267. margin-right: 20rpx;
  268. }
  269. &.btn{
  270. width: 258rpx;
  271. height: 88rpx;
  272. padding: 0;
  273. float: left;
  274. background: $btn-confirm;
  275. .input{
  276. width: 258rpx;
  277. height: 88rpx;
  278. line-height: 88rpx;
  279. padding: 0;
  280. border-radius: 14rpx;
  281. color: #FFFFFF;
  282. background: $btn-confirm;
  283. }
  284. &.disabled{
  285. background: #F7F7F7;
  286. .input{
  287. background: #F7F7F7;
  288. color: #999999;
  289. }
  290. }
  291. }
  292. &.img-btn{
  293. width: 250rpx;
  294. height: 88rpx;
  295. padding: 0;
  296. float: left;
  297. background: #FFFFFF;
  298. display: block;
  299. .vscodeimg{
  300. width: 180rpx;
  301. height: 88rpx;
  302. float: left;
  303. display: flex;
  304. flex-direction: column;
  305. align-items: center;
  306. border-radius: 14rpx;
  307. image{
  308. width: 180rpx;
  309. height: 88rpx;
  310. border-radius: 14rpx;
  311. }
  312. }
  313. .vscod-refresh{
  314. width: 70rpx;
  315. float: right;
  316. display: flex;
  317. flex-direction: column;
  318. align-items: center;
  319. .icon-shuaxin{
  320. font-size: 48rpx;
  321. color: #333333;
  322. }
  323. .ref-text{
  324. font-size: 24rpx;
  325. color: #333333;
  326. }
  327. }
  328. }
  329. .input{
  330. width: 100%;
  331. height: 100%;
  332. background: #F7F7F7;
  333. font-size: $font-size-28;
  334. line-height: 40rpx;
  335. color: #333333;
  336. border-radius: 14rpx;
  337. }
  338. }
  339. }
  340. .login-btn{
  341. width: 702rpx;
  342. height: 88rpx;
  343. border-radius: 14rpx;
  344. font-size: $font-size-28;
  345. line-height: 88rpx;
  346. color: #FFFFFF;
  347. margin: 0 auto;
  348. text-align: center;
  349. background: $btn-confirm;
  350. margin-top: 100rpx;
  351. }
  352. .model-authorization{
  353. width: 100%;
  354. height: 100%;
  355. position: fixed;
  356. top: 0;
  357. left: 0;
  358. z-index: 999;
  359. .authorization{
  360. width: 518rpx;
  361. height: 320rpx;
  362. position: absolute;
  363. background: rgba(255,255,255,.7);
  364. left: 0;
  365. right: 0;
  366. bottom: 0;
  367. top: 0;
  368. margin: auto;
  369. .to-btn{
  370. position: absolute;
  371. top: 0;
  372. left: 0;
  373. right: 0;
  374. bottom: 0;
  375. margin: auto;
  376. width: 70%;
  377. height: 88rpx;
  378. font-size: $font-size-28;
  379. line-height: 88rpx;
  380. color: #FFFFFF;
  381. text-align: center;
  382. border-radius: 44rpx;
  383. }
  384. }
  385. }
  386. }
  387. </style>