bindOperator.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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. this.login(response.data)
  210. this.$api.switchTabTo('/pages/tabBar/home/home')
  211. }).catch(response =>{
  212. this.$util.msg(response.msg,2000)
  213. this.isUserInfo = false
  214. })
  215. }
  216. })
  217. }
  218. },
  219. onShow() {
  220. //查看此微信用户是否已经授权过
  221. authorize.getSetting().then(res =>{// console.log('是否已授权',res);//0:为取消授权 1:为已授权 2:为未操作
  222. if(res != 1){
  223. this.$api.navigateTo('/pages/authorization/authorization?type=3')
  224. }else{
  225. this.getCheekeyCode()
  226. }
  227. })
  228. }
  229. }
  230. </script>
  231. <style lang="scss">
  232. .login{
  233. width: 100%;
  234. height: auto;
  235. border-top: 1px solid #F7F7F7;
  236. padding-top: 100rpx;
  237. .login-foot{
  238. width: 702rpx;
  239. height: 88rpx;
  240. padding: 0 24rpx;
  241. margin-top: 30rpx;
  242. .foot-text{
  243. font-size: 24rpx;
  244. line-height: 44rpx;
  245. color:$text-color;
  246. }
  247. }
  248. .login-form{
  249. width: 702rpx;
  250. height: auto;
  251. padding: 0 24rpx;
  252. .login-input{
  253. width: 654rpx;
  254. height: 40rpx;
  255. padding: 24rpx;
  256. margin-bottom: 20rpx;
  257. background: #F7F7F7;
  258. border-radius: 14rpx;
  259. display: flex;
  260. flex-direction: column;
  261. align-items: center;
  262. &.code{
  263. width: 370rpx;
  264. float: left;
  265. margin-right: 20rpx;
  266. }
  267. &.btn{
  268. width: 258rpx;
  269. height: 88rpx;
  270. padding: 0;
  271. float: left;
  272. background: $btn-confirm;
  273. .input{
  274. width: 258rpx;
  275. height: 88rpx;
  276. line-height: 88rpx;
  277. padding: 0;
  278. border-radius: 14rpx;
  279. color: #FFFFFF;
  280. background: $btn-confirm;
  281. }
  282. &.disabled{
  283. background: #F7F7F7;
  284. .input{
  285. background: #F7F7F7;
  286. color: #999999;
  287. }
  288. }
  289. }
  290. &.img-btn{
  291. width: 250rpx;
  292. height: 88rpx;
  293. padding: 0;
  294. float: left;
  295. background: #FFFFFF;
  296. display: block;
  297. .vscodeimg{
  298. width: 180rpx;
  299. height: 88rpx;
  300. float: left;
  301. display: flex;
  302. flex-direction: column;
  303. align-items: center;
  304. border-radius: 14rpx;
  305. image{
  306. width: 180rpx;
  307. height: 88rpx;
  308. border-radius: 14rpx;
  309. }
  310. }
  311. .vscod-refresh{
  312. width: 70rpx;
  313. float: right;
  314. display: flex;
  315. flex-direction: column;
  316. align-items: center;
  317. .icon-shuaxin{
  318. font-size: 48rpx;
  319. color: #333333;
  320. }
  321. .ref-text{
  322. font-size: 24rpx;
  323. color: #333333;
  324. }
  325. }
  326. }
  327. .input{
  328. width: 100%;
  329. height: 100%;
  330. background: #F7F7F7;
  331. font-size: $font-size-28;
  332. line-height: 40rpx;
  333. color: #333333;
  334. border-radius: 14rpx;
  335. }
  336. }
  337. }
  338. .login-btn{
  339. width: 702rpx;
  340. height: 88rpx;
  341. border-radius: 14rpx;
  342. font-size: $font-size-28;
  343. line-height: 88rpx;
  344. color: #FFFFFF;
  345. margin: 0 auto;
  346. text-align: center;
  347. background: $btn-confirm;
  348. margin-top: 100rpx;
  349. }
  350. .model-authorization{
  351. width: 100%;
  352. height: 100%;
  353. position: fixed;
  354. top: 0;
  355. left: 0;
  356. z-index: 999;
  357. .authorization{
  358. width: 518rpx;
  359. height: 320rpx;
  360. position: absolute;
  361. background: rgba(255,255,255,.7);
  362. left: 0;
  363. right: 0;
  364. bottom: 0;
  365. top: 0;
  366. margin: auto;
  367. .to-btn{
  368. position: absolute;
  369. top: 0;
  370. left: 0;
  371. right: 0;
  372. bottom: 0;
  373. margin: auto;
  374. width: 70%;
  375. height: 88rpx;
  376. font-size: $font-size-28;
  377. line-height: 88rpx;
  378. color: #FFFFFF;
  379. text-align: center;
  380. border-radius: 44rpx;
  381. }
  382. }
  383. }
  384. }
  385. </style>