bindOperator.vue 10 KB

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