1
jhzh
2024-08-12 f1dc8f5a7f3a661ce19513a9ad47fe18e3e883ff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
<template>
  <el-dialog
    class="my_security"
    :title="$t('message.user.gugeyanzhengqi') + $t('message.user.bangding')"
    v-model="visible"
    :close-on-click-modal="false"
    @close="handClose"
    width="480px"
    center
  >
    <!-- QRCode -->
    <div class="code-box">
      <!-- 二维码 + 刷新 -->
      <div class="qr_code">
        <div class="code_img_wrapper">
          <img class="code-img" :src="google_auth_url" alt="QR code" />
        </div>
        <div>
          <i
            class="el-icon-refresh-right font-size24"
            style="color: rgb(29, 145, 255); margin-left: 8px"
            @click="refreshBtn"
          ></i>
        </div>
      </div>
 
      <!-- 秘钥 + 复制 -->
      <div class="label_top">
        <span>{{ google_auth_secret }}</span>
        <span
          :data-clipboard-text="google_auth_secret"
          class="copy-btn"
          @click="copyBtn"
          >{{ $t("message.user.fuzhi") }}</span
        >
      </div>
      <!-- 妥善保管 -->
      <div class="key_msg">({{ $t("message.user.chang15") }})</div>
    </div>
    <!-- 输入谷歌验证码 -->
    <div>
      <div class="label_light">{{ $t("message.user.gugeyanzhengma") }}</div>
      <security-code
        v-if="visible"
        @getGoogleCode="getGoogleCode"
      ></security-code>
    </div>
 
    <!-- 提示语句 -->
    <div class="illustrate">
      <div>
        <div>{{ $t("message.user.gugeyanzhengma") }}</div>
        <p>{{ $t("message.user.chang16") }}</p>
        <p>{{ $t("message.user.chang17") }}</p>
      </div>
      <div>
        <div>{{ $t("message.user.chang18") }}</div>
        <p>{{ $t("message.user.chang19") }}</p>
        <p>{{ $t("message.user.chang20") }}</p>
      </div>
    </div>
 
    <div class="bind_btn">
      <el-button type="primary" @click="confirmBtn">{{
        $t("message.user.bangding")
      }}</el-button>
    </div>
  </el-dialog>
</template>
 
<script>
import securityCode from "@/components/my/securityCode.vue";
import Axios2 from "@/api/my.js";
import Clipboard from "clipboard";
import { ElMessage } from "element-plus";
export default {
  emits: ["changeModalShow"],
  components: { securityCode },
  props: {
    isShowGoogle: {
      // 弹窗是否展示
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      google_auth_secret: "", //谷歌验证器密钥
      google_auth_url: "", //图片URL地址
      google_auth_bind: "", //是否已绑定:1/绑定;0/未绑定
      //验证码
      code: [],
    };
  },
  computed: {
    visible: {
      get() {
        return this.isShowGoogle;
      },
      set(val) {
        this.$emit("changeModalShow", false, "isShowGoogle");
      },
    },
  },
  mounted() {
    const sptoken = localStorage.getItem("spToken");
    if (sptoken) {
      this.getGoogleInfo();
    }
  },
  methods: {
    getGoogleCode(data) {
      this.code = data; //数组
    },
    //获取谷歌绑定的信息
    getGoogleInfo() {
      Axios2.getGoogleAuth().then((res) => {
        const { googleAuthSecret, googleAuthImg } = res.data;
        this.google_auth_secret = googleAuthSecret;
        this.google_auth_url = googleAuthImg;
      });
    },
    refreshBtn() {
      this.getGoogleInfo();
    },
    //绑定
    confirmBtn() {
      if (this.code.length === 6) {
        const paramsCode = this.code.join("");
        Axios2.bindGoogleAuth({
          secret: this.google_auth_secret,
          code: paramsCode,
        }).then((res) => {
          if (res.data?.google_auth_bind == true) {
            ElMessage.success(this.$t("message.user.bangdingchenggong"));
            this.$parent.getUserInfo();
            this.handClose();
          }
          // 后端会提示的
          // else {
          //   ElMessage.error(this.$t("message.user.yanzhengmacuowu_sxcxsm"));
          // }
        });
      } else {
        ElMessage.warning(this.$t("message.user.qsr_yanzhengma"));
      }
    },
    //复制密钥
    copyBtn() {
      const clipboard = new Clipboard(".copy-btn");
      clipboard.on("success", (e) => {
        ElMessage.success(this.$t("message.user.fuzhichenggong"));
        clipboard.destroy();
      });
      clipboard.on("error", (e) => {
        console.error("复制出错", e);
        clipboard.destroy();
      });
    },
    handClose() {
      this.visible = false;
      this.code = [];
    },
  },
};
</script>
 
<style scoped>
.code-box {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  border-bottom: 1px solid #eeeeee;
}
.qr_code {
  display: flex;
}
.code_img_wrapper {
  border: 1px solid #e5e5e5;
}
 
.code-img {
  width: 200px;
  height: 200px;
}
 
.label_light {
  margin-top: 30px;
  font-size: 14px;
}
 
.key_msg {
  color: #999999;
  margin-bottom: 30px;
}
 
.num-content {
  display: flex;
  margin-top: 15px;
}
 
.num-content > p {
  font-size: 15px;
  margin-right: 10px;
}
 
.input-num-style {
  width: 40px;
  height: 40px;
  border: 1px solid #e5e5e5;
  text-align: center;
  font-size: 16px;
  font-weight: bold;
  border-radius: 3px;
  margin-right: 15px;
}
/* 提示 */
.illustrate {
  background: #fafafa;
  padding: 15px;
  margin-top: 25px;
  border-radius: 3px;
}
 
.illustrate > div:nth-child(1) {
  margin-bottom: 30px;
}
 
.illustrate > div > p {
  color: #484d56;
  font-size: 12px;
  line-height: 26px;
}
 
.illustrate > div > div {
  color: #202123;
  font-size: 12px;
  line-height: 26px;
}
 
.copy-btn {
  color: rgb(29, 145, 255);
 
  /* width: 150px;
  height: 36px;
  line-height: 36px;
  text-align: center; */
  margin-left: 10px;
 
  cursor: pointer;
}
</style>