对接选课接口

This commit is contained in:
Net 2025-05-18 11:51:50 +08:00
parent 8e709572b3
commit 73bf023565
3 changed files with 104 additions and 25 deletions

View File

@ -1,4 +1,5 @@
const ip: string = "119.29.194.155:8893";
// const ip: string = "119.29.194.155:8893";
const ip: string = "yufangzc.com";
const fwqip: string = "yufangzc.com";
//打包服务器接口代理标识
const SERVERAGENT: string = "/jzd-api";
@ -6,11 +7,11 @@ const SERVERAGENT: string = "/jzd-api";
export const HOMEAGENT: string = "";
// 接口地址
export const BASE_URL: string =
process.env.NODE_ENV == "development" ? `http://${ip}/zhxy` : SERVERAGENT;
process.env.NODE_ENV == "development" ? `https://${ip}/zhxy` : SERVERAGENT;
// WebSocket地址
export const BASE_WS_URL: string = `wss://${ip}`;
//图片地址
export const BASE_IMAGE_URL: string = process.env.NODE_ENV == "development" ? `http://${ip}` : `https://${fwqip}`;
export const BASE_IMAGE_URL: string = process.env.NODE_ENV == "development" ? `https://${ip}` : `https://${fwqip}`;
//存token的key
export const AUTH_KEY: string = "satoken";
//token过期返回状态码

View File

@ -155,7 +155,7 @@
<script setup lang="ts">
import { navigateTo } from "@/utils/uniapp";
import { ref, computed, reactive, onBeforeUnmount, watch } from "vue";
import { ref, computed, reactive, onBeforeUnmount, watch, onMounted } from "vue";
import { useUserStore } from "@/store/modules/user";
import { useDataStore } from "@/store/modules/data";
import { xkAddXkqdApi, xkListApi, xkXkqdApi } from "@/api/base/server";
@ -201,6 +201,9 @@ const kcStatus = ref(false);
//
const isEnrollmentEnded = ref(false);
//
let pollTimer: number | null = null;
//
function checkStudentEnrollmentApi(student: any): Promise<boolean> {
return new Promise((resolve, reject) => {
@ -234,6 +237,83 @@ function checkStudentEnrollmentApi(student: any): Promise<boolean> {
});
}
//
const pollEnrollmentCount = () => {
//
// getEnrollmentCountApi
/*
getEnrollmentCountApi().then(res => {
if (res && res.resultCode === 1 && Array.isArray(res.result)) {
updateEnrollmentCount(res.result);
}
}).catch(error => {
console.error('获取报名人数失败:', error);
});
*/
// TODO:
// console.log('');
//
const mockData = [
{ id: '111B98397A08E8DA20D', ybmr: 10 },
{ id: '74ECFE7249A54FE9B98397A08E8DA20D', ybmr: 15 }
];
//
updateEnrollmentCount(mockData);
};
//
const updateEnrollmentCount = (data: Array<{id: string, ybmr: number}>) => {
if (!Array.isArray(courseListData.value) || courseListData.value.length === 0) return;
let hasUpdates = false;
courseListData.value.forEach(course => {
const newCount = data.find(item => item.id === course.id);
if (newCount && course.ybmr !== newCount.ybmr) {
course.ybmr = newCount.ybmr;
hasUpdates = true;
}
});
//
if (hasUpdates) {
courseListData.value = [...courseListData.value];
}
};
//
const startPolling = (interval = 5000) => {
//
stopPolling();
//
pollEnrollmentCount();
//
pollTimer = setInterval(pollEnrollmentCount, interval) as unknown as number;
};
//
const stopPolling = () => {
if (pollTimer) {
clearInterval(pollTimer);
pollTimer = null;
}
};
//
onMounted(() => {
//
watch(courseListData, (newVal) => {
if (newVal.length > 0 && !pollTimer) {
startPolling();
}
});
});
//
const checkInitialEnrollment = (currentStudent: any) => {
if (!currentStudent) return;
@ -620,6 +700,8 @@ onBeforeUnmount(() => {
clearInterval(countdownTimer);
countdownTimer = null;
}
stopPolling();
});
</script>

View File

@ -19,9 +19,8 @@ import { useUserStore } from "@/store/modules/user";
import { checkOpenId } from "@/api/system/login";
import { isTabBar } from "@/utils/uniapp";
const { setGlobal, getGlobal } = useDataStore();
const { afterLoginAction, getToken } = useUserStore();
const { setFile, getFile } = useDataStore();
const { setGlobal } = useDataStore();
const { afterLoginAction } = useUserStore();
const isShow = ref(true);
function toHome(data: any) {
@ -37,26 +36,23 @@ function toHome(data: any) {
}
onLoad(async (data: any) => {
console.log(data);
setGlobal(data);
if (!getToken) {
if (data && data.openId) {
checkOpenId({ openId: data.openId, appCode: "JZ" })
.then(async (res) => {
if (res.resultCode == 1) {
if (res.result) {
afterLoginAction(res.result);
toHome(data);
} else {
uni.reLaunch({
url: "/pages/base/parentRegister/index",
});
}
if (data && data.openId) {
checkOpenId({ openId: data.openId, appCode: "JZ" })
.then(async (res) => {
if (res.resultCode == 1) {
if (res.result) {
afterLoginAction(res.result);
toHome(data);
} else {
uni.reLaunch({
url: "/pages/base/parentRegister/index",
});
}
})
.catch((err) => {});
}
} else {
toHome(data);
}
})
.catch((err) => {});
}
});
</script>