google.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <v-page>
  3. <v-header :title="`${user.google_token?$t('safe.a0'):''} ${$t('safe.b9')}`"></v-header>
  4. <!-- 未绑定的第一步-->
  5. <main v-show="step==1&&!user.google_token" class="layout-main bg-panel-4 p-t-md">
  6. <view
  7. class="p-x-md p-y-xs bg-theme-1-transparent color-theme-1 fn-sm"
  8. >{{$t('safe.c0')}}</view>
  9. <!-- 二维码 -->
  10. <view class="row p-md fn-center code-box">
  11. <v-qr class="v-qr" :text="googleToken.qrcode_url"></v-qr>
  12. <view class="m-y-md color-light">{{googleToken.secret}}</view>
  13. <view class="color-theme-1" @click="$copy(googleToken.secret)">{{$t('safe.c1')}}</view>
  14. </view>
  15. </main>
  16. <view v-show="step==1&&!user.google_token" class="p-md bg-panel-4">
  17. <p class="d-flex m-b-xs">
  18. <van-checkbox v-model="checkToken" class="m-r-xs" icon-size="15px" checked-color="#f05319"></van-checkbox>{{$t('safe.c2')}}
  19. </p>
  20. <v-button class="w-max" block :disabled="!checkToken" type="primary" @click="step++">{{$t('safe.c3')}}</v-button>
  21. </view>
  22. <!-- 未绑定的第二步或者未绑定 -->
  23. <main
  24. v-show="step==2||user.google_token"
  25. class="layout-main bg-panel-4 m-t-md"
  26. >
  27. <view class="form-item border-b p-md" v-if="user.phone_status==1">
  28. <view class="label m-b-xs">{{$t('safe.c4')}}</view>
  29. <view class="input color-light">
  30. <v-input v-model="form.sms_code" :placeholder="$t('safe.a6')">
  31. <template #right>
  32. <v-code url="/user/getCode" :data="{type:1}" />
  33. </template>
  34. </v-input>
  35. </view>
  36. </view>
  37. <view class="form-item border-b p-md" v-if="user.email_status==1">
  38. <view class="label m-b-xs">{{$t('safe.a5')}}</view>
  39. <view class="input color-light">
  40. <v-input v-model="form.email_code" :placeholder="$t('safe.a6')">
  41. <template #right>
  42. <v-code url="/user/getCode" :data="{type:2}" />
  43. </template>
  44. </v-input>
  45. </view>
  46. </view>
  47. <view class="form-item border-b p-md">
  48. <view class="label m-b-xs">{{$t('safe.b9')}}</view>
  49. <view class="input color-light">
  50. <v-input v-model="form.google_code" :placeholder="$t('safe.a6')"></v-input>
  51. </view>
  52. </view>
  53. </main>
  54. <view v-show="step==2" class="p-md bg-panel-4">
  55. <v-button class="w-max" block type="theme" ref="btn" @click="bindGoogle">{{$t('safe.c6')}}</v-button>
  56. </view>
  57. <!-- 解绑 -->
  58. <view v-show="user.google_token" class="p-md bg-panel-4">
  59. <v-button class="w-max" block type="theme" ref="btn1" @click="unBindGoogle">{{$t('safe.a0')}}</v-button>
  60. </view>
  61. <van-toast id="van-toast" />
  62. </v-page>
  63. </template>
  64. <script>
  65. import { mapState, mapActions } from "vuex";
  66. import Setting from "@/api/setting";
  67. export default {
  68. data() {
  69. return {
  70. step: 1,
  71. checkToken: false,
  72. googleToken: {},
  73. form: {
  74. google_token: "",
  75. google_code: "",
  76. sms_code: "",
  77. email_code: "",
  78. },
  79. };
  80. },
  81. computed: {
  82. ...mapState({
  83. user: "user",
  84. }),
  85. },
  86. methods: {
  87. ...mapActions({
  88. setUserInfo: "setUserInfo",
  89. }),
  90. // 获取googleToken
  91. getToken() {
  92. Setting.getGoogleToken()
  93. .then((res) => {
  94. this.googleToken = res.data;
  95. })
  96. .catch(() => {});
  97. },
  98. // 绑定谷歌
  99. bindGoogle() {
  100. this.form.google_token = this.googleToken.secret;
  101. if(!this.form.google_code){
  102. return this.$toast(this.$t('safe.a6'))
  103. }
  104. Setting.bindGoogleToken(this.form, { btn: this.$refs.btn })
  105. .then(() => {
  106. // 绑定成功
  107. this.step =1
  108. this.$back(-1);
  109. this.setUserInfo();
  110. this.$toast.success(this.$t('safe.a9'));
  111. })
  112. .catch(() => {});
  113. },
  114. // 解除绑定
  115. unBindGoogle() {
  116. Setting.unbindGoogleToken(this.form, { btn: this.$refs.btn1 })
  117. .then(() => {
  118. // 绑定成功
  119. this.$back();
  120. this.setUserInfo();
  121. this.$toast.success(this.$t('safe.a8'));
  122. })
  123. .catch(() => {});
  124. },
  125. },
  126. created() {
  127. if (!this.user.google_token) this.getToken();
  128. },
  129. beforeRouteLeave(to, from, next) {
  130. if (this.step != 1) {
  131. this.step--;
  132. next(false);
  133. } else {
  134. next();
  135. }
  136. },
  137. };
  138. </script>
  139. <style lang="scss" scoped>
  140. .v-qr {
  141. width: 150px;
  142. height: 150px;
  143. margin: 0 auto;
  144. border: 4px solid $white;
  145. box-sizing: border-box;
  146. }
  147. </style>