bindOperator.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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. authorize.getUserInfo('weixin').then(res =>{
  102. userInfoLogin({code:wechatcode}).then(response =>{
  103. this.login(response.data)
  104. uni.setStorageSync('token',response.data.token)
  105. uni.removeStorageSync('sessionid')
  106. uni.setStorageSync('sessionid','JSESSIONID='+response.data.sessionId)
  107. this.$store.commit('updateStatus',response.data)
  108. if(response.data.userIdentity ==1){
  109. this.$api.navigateTo('/market/pages/index/index')
  110. }else{
  111. this.$api.switchTabTo('/pages/tabBar/home/home')
  112. }
  113. }).catch(response =>{
  114. this.logout()
  115. this.isUserInfo = true
  116. uni.removeStorageSync('sessionid')
  117. uni.setStorageSync('sessionid','JSESSIONID='+response.data)
  118. this.$store.commit('updateStatus',response.data)
  119. })
  120. })
  121. })
  122. },
  123. bindWechatInfo(){
  124. if( this.bindLinkName == ''){
  125. this.$util.msg('请输入姓名',2000)
  126. return
  127. }
  128. if( this.bindMobile == ''){
  129. this.$util.msg('请输入手机号',2000)
  130. return
  131. }
  132. if(!this.$reg.isMobile(this.bindMobile)){
  133. this.$util.msg('请输入正确的手机号',2000)
  134. return
  135. }
  136. if( this.mobildeCode == ''){
  137. this.$util.msg('请输入手机验证码',2000)
  138. return
  139. }
  140. if(!this.$reg.isMobileCode(this.mobildeCode)){
  141. this.$util.msg('验证码格式不正确',2000)
  142. return
  143. }
  144. this.bindingWechatLogin()
  145. },
  146. getVerificationCode(){//图形验证
  147. getImageCode().then(res => {
  148. this.imageCodeUrl = res.data.baseImage
  149. this.imageCodetoken = res.data.token
  150. })
  151. },
  152. getMobileCodeFn(){//获取手机验证码
  153. if( this.bindMobile == ''){
  154. this.$util.msg('请输入手机号',2000);
  155. return
  156. }
  157. if(!this.$reg.isMobile(this.bindMobile)){
  158. this.$util.msg('请输入正确的手机号',2000);
  159. return
  160. }
  161. if( this.imageCode == ''){
  162. this.$util.msg('请输入图形验证码',2000);
  163. return
  164. }
  165. let params = {
  166. userId:uni.getStorageSync('bind_id'),
  167. mobile:this.bindMobile,
  168. platformType:2,
  169. imgCode:this.imageCode,
  170. token:this.imageCodetoken,
  171. }
  172. this.isMobileDisabled = true;
  173. getbindOperatorCode(params).then(res =>{
  174. const TIME_COUNT = 60;
  175. this.$util.msg('验证短信已发送',2000)
  176.       if (!this.codeTime) {
  177.         this.count = TIME_COUNT;
  178. this.isMobileDisabled = true;
  179.         this.codeTime = setInterval(() => {
  180.         if (this.count > 1 && this.count <= TIME_COUNT) {
  181.           this.count--
  182.           this.mobileCodeText = this.count +'s重新发送'
  183.          } else {
  184.           this.isMobileDisabled = false;
  185.           clearInterval(this.codeTime)
  186.           this.codeTime = null
  187. this.mobileCodeText = '获取验证码'
  188.          }
  189.         },1000)
  190.        }
  191. }).catch( res =>{
  192. this.$util.msg(res.msg,2000)
  193. this.isMobileDisabled = false;
  194. })
  195. },
  196. bindingWechatLogin(){//获取用户基本信息登录
  197. wx.getUserInfo({
  198. success: res => {
  199. this.wxUserInfo = res.userInfo;
  200. let params ={
  201. userID: uni.getStorageSync('bind_id'),
  202. mobile: this.bindMobile,
  203. linkName: this.bindLinkName,
  204. verificationCode: this.mobildeCode,
  205. nickName: this.wxUserInfo.nickName,
  206. headimgurl: this.wxUserInfo.avatarUrl,
  207. }
  208. sellerBindingOperation(params).then(response =>{
  209. if(response.code == 0){
  210. this.login(response.data);
  211. this.$api.switchTabTo('/pages/tabBar/home/home')
  212. }else if(response.code == 4){
  213. this.login(response.data)
  214. this.$api.navigateTo(`/pages/login/bindemail?pathType=1`)
  215. }else{
  216. this.$util.msg(response.msg,2000)
  217. }
  218. })
  219. }
  220. })
  221. }
  222. },
  223. onShow() {
  224. //查看此微信用户是否已经授权过
  225. authorize.getSetting().then(res =>{// console.log('是否已授权',res);//0:为取消授权 1:为已授权 2:为未操作
  226. if(res != 1){
  227. this.$api.navigateTo('/pages/authorization/authorization?type=3')
  228. }else{
  229. this.getCheekeyCode()
  230. }
  231. })
  232. }
  233. }
  234. </script>
  235. <style lang="scss">
  236. .login{
  237. width: 100%;
  238. height: auto;
  239. border-top: 1px solid #F7F7F7;
  240. padding-top: 100rpx;
  241. .login-foot{
  242. width: 702rpx;
  243. height: 88rpx;
  244. padding: 0 24rpx;
  245. margin-top: 30rpx;
  246. .foot-text{
  247. font-size: 24rpx;
  248. line-height: 44rpx;
  249. color:$text-color;
  250. }
  251. }
  252. .login-form{
  253. width: 702rpx;
  254. height: auto;
  255. padding: 0 24rpx;
  256. .login-input{
  257. width: 654rpx;
  258. height: 40rpx;
  259. padding: 24rpx;
  260. margin-bottom: 20rpx;
  261. background: #F7F7F7;
  262. border-radius: 14rpx;
  263. display: flex;
  264. flex-direction: column;
  265. align-items: center;
  266. &.code{
  267. width: 370rpx;
  268. float: left;
  269. margin-right: 20rpx;
  270. }
  271. &.btn{
  272. width: 258rpx;
  273. height: 88rpx;
  274. padding: 0;
  275. float: left;
  276. background: $btn-confirm;
  277. .input{
  278. width: 258rpx;
  279. height: 88rpx;
  280. line-height: 88rpx;
  281. padding: 0;
  282. border-radius: 14rpx;
  283. color: #FFFFFF;
  284. background: $btn-confirm;
  285. }
  286. &.disabled{
  287. background: #F7F7F7;
  288. .input{
  289. background: #F7F7F7;
  290. color: #999999;
  291. }
  292. }
  293. }
  294. &.img-btn{
  295. width: 250rpx;
  296. height: 88rpx;
  297. padding: 0;
  298. float: left;
  299. background: #FFFFFF;
  300. display: block;
  301. .vscodeimg{
  302. width: 180rpx;
  303. height: 88rpx;
  304. float: left;
  305. display: flex;
  306. flex-direction: column;
  307. align-items: center;
  308. border-radius: 14rpx;
  309. image{
  310. width: 180rpx;
  311. height: 88rpx;
  312. border-radius: 14rpx;
  313. }
  314. }
  315. .vscod-refresh{
  316. width: 70rpx;
  317. float: right;
  318. display: flex;
  319. flex-direction: column;
  320. align-items: center;
  321. .icon-shuaxin{
  322. font-size: 48rpx;
  323. color: #333333;
  324. }
  325. .ref-text{
  326. font-size: 24rpx;
  327. color: #333333;
  328. }
  329. }
  330. }
  331. .input{
  332. width: 100%;
  333. height: 100%;
  334. background: #F7F7F7;
  335. font-size: $font-size-28;
  336. line-height: 40rpx;
  337. color: #333333;
  338. border-radius: 14rpx;
  339. }
  340. }
  341. }
  342. .login-btn{
  343. width: 702rpx;
  344. height: 88rpx;
  345. border-radius: 14rpx;
  346. font-size: $font-size-28;
  347. line-height: 88rpx;
  348. color: #FFFFFF;
  349. margin: 0 auto;
  350. text-align: center;
  351. background: $btn-confirm;
  352. margin-top: 100rpx;
  353. }
  354. .model-authorization{
  355. width: 100%;
  356. height: 100%;
  357. position: fixed;
  358. top: 0;
  359. left: 0;
  360. z-index: 999;
  361. .authorization{
  362. width: 518rpx;
  363. height: 320rpx;
  364. position: absolute;
  365. background: rgba(255,255,255,.7);
  366. left: 0;
  367. right: 0;
  368. bottom: 0;
  369. top: 0;
  370. margin: auto;
  371. .to-btn{
  372. position: absolute;
  373. top: 0;
  374. left: 0;
  375. right: 0;
  376. bottom: 0;
  377. margin: auto;
  378. width: 70%;
  379. height: 88rpx;
  380. font-size: $font-size-28;
  381. line-height: 88rpx;
  382. color: #FFFFFF;
  383. text-align: center;
  384. border-radius: 44rpx;
  385. }
  386. }
  387. }
  388. }
  389. </style>