dcc
2024-06-13 cfdf967764dc6747a7b414b33fb993aeede1294d
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
<!-- 图片验证组件 -->
<template>
  <el-dialog
    :title="t('message.home.tupianyanzheng')"
    v-model="isShow"
    width="380px"
    :before-close="handleClose"
    center
  >
    <slide-verify
      ref="slideblockRef"
      @again="onAgain"
      @fulfilled="onFulfilled"
      @success="onSuccess"
      @fail="onFail"
      @refresh="onRefresh"
      :slider-text="text"
      :accuracy="accuracy"
    ></slide-verify>
  </el-dialog>
</template>
 
<script setup>
import Axios from "@/api/login.js";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
import { ElMessage } from "element-plus";
import SlideVerify from "vue3-slide-verify";
import { useUserStore } from "@/store/user";
import { setStorage } from "@/utils/index";
 
const { t } = useI18n();
const router = useRouter();
const userStore = useUserStore();
const isShow = ref(false);
const registObj = ref({});
const slideblockRef = ref();
const text = t("message.home.xiangyouhuadong");
const accuracy = 5;
const msg = ref("");
 
const isShowFunc = (data, params) => {
  if (Object.keys(params).length > 0) {
    registObj.value = params;
  }
  isShow.value = true;
  slideblockRef.value?.refresh();
};
 
const handleClose = () => {
  isShow.value = false;
};
 
const onSuccess = () => {
  ElMessage.success(t("message.home.tupianyanzhengtongguo"));
  if (Object.keys(registObj.value).length > 0) {
    Axios.accountRegister({ ...registObj.value }).then((res) => {
      if (res.code == "0") {
        ElMessage.success(t("message.home.zhucechenggong"));
        setStorage("spToken", res.data.token);
        setStorage("username", res.data.username);
        userStore.updateUserInfo(res.data);
        router.push("/idSet");
      } else {
        isShow.value = !isShow.value;
      }
    });
  }
};
 
const onFulfilled = () => {};
const onRefresh = () => {};
const onFail = () => {
  ElMessage.error(t("message.home.yanzhengbutonguo"));
  msg.value = t("message.home.yanzhengbutonguo");
};
 
const onAgain = () => {
  ElMessage.error(t("message.home.yanzhengbutonguo"));
  msg.value = "try again";
  // 刷新
  slideblockRef.value?.refresh();
};
 
defineExpose({
  isShowFunc,
}); //在语法糖里面需要把函数暴露出去
</script>