From d9b0460bf20e428ae54da3c95f8acf1a78e6727b Mon Sep 17 00:00:00 2001
From: xixiibn5100 <1584914306@qq.com>
Date: Mon, 18 Nov 2024 20:05:09 +0800
Subject: [PATCH] perf(YXYBind): simplify yxy binding
---
src/components/Home/index.vue | 2 +-
src/pages/bind/YXY/index.vue | 118 ++++++++--------------------
src/services/api/apiList.ts | 5 +-
src/services/services/yxyService.ts | 24 +-----
4 files changed, 38 insertions(+), 111 deletions(-)
diff --git a/src/components/Home/index.vue b/src/components/Home/index.vue
index b7c1b318..29dd3c75 100644
--- a/src/components/Home/index.vue
+++ b/src/components/Home/index.vue
@@ -34,7 +34,7 @@
>
diff --git a/src/pages/bind/YXY/index.vue b/src/pages/bind/YXY/index.vue
index a470156f..5bac54b3 100644
--- a/src/pages/bind/YXY/index.vue
+++ b/src/pages/bind/YXY/index.vue
@@ -3,50 +3,17 @@ import { Card, WButton, WModal } from "@/components";
import { helpText } from "@/constants/copywriting";
import { YxyService } from "@/services";
import Taro from "@tarojs/taro";
-import { onMounted, ref } from "vue";
+import { ref } from "vue";
import { useRequest } from "@/hooks";
import store, { serviceStore } from "@/store";
-const phoneNumber = ref("");
-const graphCode = ref("");
+const phoneNumber = ref("");
const phoneCode = ref("");
const helpContent = helpText.bind.yxy;
const isShowHelp = ref(false);
const timeCounter = ref(0);
-// 获取图形验证码
-const {
- run: getGraphAPI,
- data: imageResponse,
- loading: imageLoading,
- error: imageError
-} = useRequest(YxyService.getGraph, {
- manual: true
-});
-
-const {
- run: sendGraphAuthCodeAPI
-} = useRequest(YxyService.sendGraphAuthCode, {
- manual: true,
- onSuccess: (res) => {
- if (res.data.code !== 1) {
- Taro.showToast({ title: res.data.msg, icon: "none" });
- getGraphAPI();
- } else {
- Taro.showToast({ title: "已发送验证码", icon: "success" });
- getGraphAPI();
- graphCode.value = "";
- timeCounter.value = 60;
- const timer = setInterval(() => {
- timeCounter.value--;
- if (timeCounter.value === 0)
- clearInterval(timer);
- }, 1000);
- }
- }
-});
-
const { run: loginYxyAPI } = useRequest(YxyService.loginYxy, {
manual: true,
onBefore: () => {
@@ -73,17 +40,26 @@ const { run: loginYxyAPI } = useRequest(YxyService.loginYxy, {
});
/**
- * 验证图形验证码,同时获取手机验证码
+ * 获取手机验证码
*/
-const handleSendGraphCode = () => {
+
+const handleSendPhoneCode = async () => {
if (timeCounter.value > 0) return;
- if (graphCode.value.length && phoneNumber.value.length)
- sendGraphAuthCodeAPI({
- captcha: graphCode.value,
- phoneNum: phoneNumber.value
- });
- else {
- Taro.showToast({ icon: "none", title: "请输入手机号和图形验证码" });
+ try {
+ const res = await YxyService.getPhoneCode({ phoneNum: phoneNumber.value });
+ if (res.data.code === 1) {
+ Taro.showToast({ icon: "success", title: "发送成功" });
+ timeCounter.value = 60;
+ const timer = setInterval(() => {
+ timeCounter.value--;
+ if (timeCounter.value === 0)
+ clearInterval(timer);
+ }, 1000);
+ } else {
+ Taro.showToast({ icon: "none", title: res.data.msg });
+ }
+ } catch (e: any) {
+ Taro.showToast({ icon: "none", title: e });
}
};
@@ -107,10 +83,6 @@ const handleClickTutorial = () => {
});
};
-onMounted(() => {
- getGraphAPI();
-});
-
@@ -124,41 +96,18 @@ onMounted(() => {
- 手机号
-
-
-
- 图片验证码
-
-
-
-
- 加载中...
-
-
- 点击重试
+ 手机号
+
+
+
+
+ 获取验证码
+
+
+ 重新发送({{ timeCounter }})
+
+
-
-
-
- 获取手机验证码
-
-
- 重新发送({{ timeCounter }})
-
-
手机验证码
@@ -168,10 +117,7 @@ onMounted(() => {
- 请先下载易校园app,注册并绑定浙工大校园卡,之后在此界面用同一手机号接收验证码即可完成注册
-
-
- tips:验证码获取存在一定的不稳定性,如果无法获取成功,请再不同时间段进行尝试
+ 请先下载易校园app,注册并绑定浙工大校园卡,之后在此界面用同一手机号接收验证码即可完成绑定
{
- return request(
- api.user.bind.yxy.getGraph, {
- method: "POST",
- header: { "Cookie": serviceStore.sessionID }
- }
- );
- };
-
- /**
- * 校验图形验证码
- * @returns
- */
- static sendGraphAuthCode = async (
- data: { captcha: string, phoneNum: string }
+ static getPhoneCode = async (
+ data: { phoneNum: string }
) => {
return request(
- api.user.bind.yxy.sendGraphAuthCode, {
+ api.user.bind.yxy.getPhoneCode, {
method: "POST",
header: {
"Cookie": serviceStore.sessionID
@@ -34,7 +17,6 @@ export default class YxyService {
data
});
};
-
/**
* 登录
* @param data