index.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <template>
  2. <view class="scan_login">
  3. <view class="head">
  4. <image :src="userInfo.avatar" mode=""></image>
  5. <view class="big">{{userInfo.nickname}}</view>
  6. <view class="small">{{$t(`点击授权登录您的客服工作台`)}}</view>
  7. <view class="sub_btn btn" @click="scanLogin">{{$t(`授权登录`)}}</view>
  8. <view class="out btn" @click="closePage">{{$t(`取消`)}}</view>
  9. </view>
  10. </view>
  11. </template>
  12. <script>
  13. import {
  14. getUserInfo,
  15. } from '@/api/user.js';
  16. import { codeStauts,kefuScanLogin } from '@/api/kefu.js'
  17. export default{
  18. name:'scan_login',
  19. data(){
  20. return {
  21. code:'',
  22. userInfo:{}
  23. }
  24. },
  25. onLoad(optios) {
  26. this.code = optios.key
  27. this.codeStauts()
  28. this.getUserInfo()
  29. },
  30. methods:{
  31. codeStauts(){
  32. codeStauts({
  33. code:this.code
  34. }).then(res=>{
  35. }).catch(error=>{
  36. this.openModel(error)
  37. })
  38. },
  39. // 确认
  40. scanLogin(){
  41. if(this.code){
  42. kefuScanLogin({
  43. code:this.code
  44. }).then(res=>{
  45. uni.showToast({
  46. title:res.msg,
  47. icon:'success'
  48. })
  49. setTimeout(res=>{
  50. WeixinJSBridge.call('closeWindow');
  51. },2000)
  52. }).catch(error=>{
  53. this.openModel(error)
  54. })
  55. }else{
  56. this.openModel(this.$t(`没有登录的code,请重新扫码`))
  57. }
  58. },
  59. openModel(data){
  60. uni.showModal({
  61. title: this.$t(`提示`),
  62. content:data,
  63. success: function (res) {
  64. if (res.confirm) {
  65. WeixinJSBridge.call('closeWindow');
  66. } else if (res.cancel) {
  67. console.log(this.$t(`用户点击取消`));
  68. }
  69. }
  70. })
  71. },
  72. closePage(){
  73. WeixinJSBridge.call('closeWindow');
  74. },
  75. // 获取用户信息
  76. getUserInfo(){
  77. getUserInfo().then(res=>{
  78. this.userInfo = res.data
  79. })
  80. }
  81. }
  82. }
  83. </script>
  84. <style lang="stylus">
  85. page{
  86. height: 100%;
  87. background: #fff;
  88. }
  89. .scan_login
  90. .head
  91. display flex
  92. flex-direction column
  93. align-items center
  94. padding-top 96rpx
  95. image
  96. width 178rpx
  97. height 178rpx
  98. border-radius 50%
  99. .big
  100. margin 20rpx 0 10rpx
  101. font-size 32rpx
  102. color #282828
  103. .small
  104. color #9f9f9f
  105. font-size 28rpx
  106. .btn
  107. display flex
  108. align-items center
  109. justify-content center
  110. width 594rpx
  111. height 86rpx
  112. margin 28rpx auto 0
  113. font-size 30rpx
  114. color #fff
  115. border-radius 43rpx
  116. background: linear-gradient(90deg, #3875EA 0%, #1890FC 100%);
  117. &.out
  118. border 1px solid #3875EA
  119. background none
  120. color #3875EA
  121. &.sub_btn
  122. margin-top 96rpx
  123. </style>