对接选课接口

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 fwqip: string = "yufangzc.com";
//打包服务器接口代理标识 //打包服务器接口代理标识
const SERVERAGENT: string = "/jzd-api"; const SERVERAGENT: string = "/jzd-api";
@ -6,11 +7,11 @@ const SERVERAGENT: string = "/jzd-api";
export const HOMEAGENT: string = ""; export const HOMEAGENT: string = "";
// 接口地址 // 接口地址
export const BASE_URL: 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地址 // WebSocket地址
export const BASE_WS_URL: string = `wss://${ip}`; 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 //存token的key
export const AUTH_KEY: string = "satoken"; export const AUTH_KEY: string = "satoken";
//token过期返回状态码 //token过期返回状态码

View File

@ -155,7 +155,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { navigateTo } from "@/utils/uniapp"; 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 { useUserStore } from "@/store/modules/user";
import { useDataStore } from "@/store/modules/data"; import { useDataStore } from "@/store/modules/data";
import { xkAddXkqdApi, xkListApi, xkXkqdApi } from "@/api/base/server"; import { xkAddXkqdApi, xkListApi, xkXkqdApi } from "@/api/base/server";
@ -201,6 +201,9 @@ const kcStatus = ref(false);
// //
const isEnrollmentEnded = ref(false); const isEnrollmentEnded = ref(false);
//
let pollTimer: number | null = null;
// //
function checkStudentEnrollmentApi(student: any): Promise<boolean> { function checkStudentEnrollmentApi(student: any): Promise<boolean> {
return new Promise((resolve, reject) => { 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) => { const checkInitialEnrollment = (currentStudent: any) => {
if (!currentStudent) return; if (!currentStudent) return;
@ -620,6 +700,8 @@ onBeforeUnmount(() => {
clearInterval(countdownTimer); clearInterval(countdownTimer);
countdownTimer = null; countdownTimer = null;
} }
stopPolling();
}); });
</script> </script>

View File

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