对接选课接口
This commit is contained in:
parent
8e709572b3
commit
73bf023565
@ -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过期返回状态码
|
||||||
|
|||||||
@ -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>
|
||||||
|
|
||||||
|
|||||||
@ -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,26 +36,23 @@ 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) => {
|
if (res.resultCode == 1) {
|
||||||
if (res.resultCode == 1) {
|
if (res.result) {
|
||||||
if (res.result) {
|
afterLoginAction(res.result);
|
||||||
afterLoginAction(res.result);
|
toHome(data);
|
||||||
toHome(data);
|
} else {
|
||||||
} else {
|
uni.reLaunch({
|
||||||
uni.reLaunch({
|
url: "/pages/base/parentRegister/index",
|
||||||
url: "/pages/base/parentRegister/index",
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
.catch((err) => {});
|
})
|
||||||
}
|
.catch((err) => {});
|
||||||
} else {
|
|
||||||
toHome(data);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user