scanLogin.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <view class="scanLogin-v">
  3. <view class="scanLogin-icon">
  4. <view class="icon-ym icon-ym-pc"></view>
  5. </view>
  6. <view class="title">登录确认</view>
  7. <view class="tip">请确认是否本人操作</view>
  8. <view class="tip">并确保二维码来源安全</view>
  9. <view class="scanLogin-actions">
  10. <u-button class="buttom-btn" type="primary" @click="handelConfirmLogin" v-if="!expired">确认登录</u-button>
  11. <u-button class="buttom-btn" type="primary" @click="reScan" v-if="expired">重新扫码登录</u-button>
  12. <text class="goBackText" @click="goBack()">取消</text>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. import {
  18. setCodeCertificateStatus,
  19. confirmLogin
  20. } from '@/api/common.js'
  21. export default {
  22. data() {
  23. return {
  24. ticket: '',
  25. expired: false
  26. }
  27. },
  28. onLoad(option) {
  29. this.init(option.id || '')
  30. },
  31. methods: {
  32. init(ticket) {
  33. this.ticket = ticket
  34. this.expired = false
  35. setCodeCertificateStatus(ticket, '1')
  36. },
  37. goBack() {
  38. setCodeCertificateStatus(this.ticket, '-1').then(res => {
  39. uni.navigateBack()
  40. })
  41. },
  42. reScan() {
  43. uni.scanCode({
  44. success: res => {
  45. let url = ""
  46. if (this.isJSON(res.result.trim())) {
  47. const result = JSON.parse(res.result.trim())
  48. if (result.t === 'login') this.init(result.id || '')
  49. }
  50. }
  51. });
  52. },
  53. isJSON(str) {
  54. try {
  55. var obj = JSON.parse(str);
  56. if (typeof obj == 'object' && obj) {
  57. return true;
  58. } else {
  59. return false;
  60. }
  61. } catch (e) {
  62. return false;
  63. }
  64. },
  65. handelConfirmLogin() {
  66. confirmLogin(this.ticket).then(res => {
  67. if (res.data.status === -1) {
  68. uni.showToast({
  69. title: '二维码已失效,请重新扫码登录',
  70. icon: 'none'
  71. })
  72. this.expired = true
  73. return;
  74. }
  75. if (res.data.status === 2) {
  76. uni.showToast({
  77. title: '登录成功',
  78. icon: 'none',
  79. complete: () => {
  80. setTimeout(() => {
  81. uni.navigateBack()
  82. }, 1500)
  83. }
  84. })
  85. }
  86. })
  87. }
  88. }
  89. }
  90. </script>
  91. <style lang="scss">
  92. page {
  93. width: 100%;
  94. height: 100%;
  95. }
  96. .scanLogin-v {
  97. height: 100%;
  98. position: relative;
  99. text-align: center;
  100. padding-top: 160rpx;
  101. .scanLogin-icon {
  102. height: 140rpx;
  103. width: 140rpx;
  104. margin: 0 auto 64rpx;
  105. display: flex;
  106. justify-content: center;
  107. align-items: center;
  108. border-radius: 50%;
  109. border: 4rpx solid #2979ff;
  110. color: #2979ff;
  111. .icon-ym-pc {
  112. font-size: 80rpx;
  113. }
  114. }
  115. .title {
  116. font-size: 40rpx;
  117. font-weight: 600;
  118. line-height: 56rpx;
  119. margin-bottom: 30rpx;
  120. }
  121. .tip {
  122. font-size: 28rpx;
  123. color: #7E7E7E;
  124. line-height: 44rpx;
  125. }
  126. .scanLogin-actions {
  127. margin-top: 270rpx;
  128. padding: 0 64rpx;
  129. .buttom-btn {
  130. margin-bottom: 20rpx;
  131. }
  132. .goBackText {
  133. line-height: 80rpx;
  134. }
  135. }
  136. }
  137. </style>