From ee7de58ba49b9396b138a96de6ad56a9a2defc3b Mon Sep 17 00:00:00 2001 From: ywyonui Date: Mon, 21 Jul 2025 14:34:20 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E8=B0=83=E6=95=B4websocket=E7=9A=84?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=202=E3=80=81=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E7=9A=84=E5=80=92=E8=AE=A1=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/base/server.ts | 6 + src/pages/base/class-schedule/index.vue | 19 +- src/pages/base/course-selection/pay-wait.vue | 187 ++++++++++++++++++- src/pages/base/course-selection/payment.vue | 164 +++++++--------- src/store/modules/user.ts | 26 ++- 5 files changed, 293 insertions(+), 109 deletions(-) diff --git a/src/api/base/server.ts b/src/api/base/server.ts index 741e2c3..59676cc 100644 --- a/src/api/base/server.ts +++ b/src/api/base/server.ts @@ -101,6 +101,12 @@ export const xsKscjApi = async (params: any) => { export const jzXkQkjApi = async (params: any) => { return await post("/mobile/jz/xk/qk", params); }; +/** + * 家长获取抢课到期时间 + */ +export const jzGetQkExpiredTime = async (params: any) => { + return await get("/mobile/jz/xk/getQkExpiredTime", params); +}; /** * 家长发起缴费 */ diff --git a/src/pages/base/class-schedule/index.vue b/src/pages/base/class-schedule/index.vue index 89b79a8..ee78891 100644 --- a/src/pages/base/class-schedule/index.vue +++ b/src/pages/base/class-schedule/index.vue @@ -52,7 +52,7 @@ { active: zc.djz === curZc.djz }, ]" @click="selectWeek(zc)"> {{ zc.mc }} - 当前周 + 当前周 @@ -63,16 +63,27 @@ - + diff --git a/src/pages/base/course-selection/payment.vue b/src/pages/base/course-selection/payment.vue index 94f65b8..19f976e 100644 --- a/src/pages/base/course-selection/payment.vue +++ b/src/pages/base/course-selection/payment.vue @@ -6,17 +6,21 @@ 待支付 - + - - + - - + + + + + + + @@ -36,7 +40,7 @@ @@ -167,34 +162,17 @@ onUnmounted(() => { .payment-page { min-height: 100%; background-color: #f5f7fa; + display: flex; + flex-direction: column; + height: 100%; + overflow: hidden; } -.nav-bar { - display: flex; - align-items: center; - justify-content: space-between; - padding: 15px; - height: 44px; - background-color: #2879ff; - - .nav-left { - width: 40px; - height: 40px; - display: flex; - align-items: center; - } - - .nav-title { - font-size: 18px; - font-weight: 500; - color: #fff; - } - - .nav-right { - width: 40px; - display: flex; - justify-content: flex-end; - } +// 可滚动内容区域样式 +.scrollable-content { + flex: 1; + overflow-y: auto; + -webkit-overflow-scrolling: touch; // 增强iOS滚动体验 } .countdown-section { @@ -226,10 +204,10 @@ onUnmounted(() => { } .payment-footer { - position: fixed; + position: sticky; + bottom: 0; left: 0; right: 0; - bottom: 0; background-color: #fff; padding: 15px; box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05); diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index 8e3893e..ca9d3f6 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -2,12 +2,15 @@ import { defineStore } from "pinia"; import { authenticationApi, loginCode, loginPass, weChatLogin } from "@/api/system/login"; import { AUTH_KEY } from "@/config"; import { imagUrl } from "@/utils"; +import { useWebSocket } from '@/utils/webSocket/webSocket' interface UserState { userdata: any; curXs: any; token: string; - auth: string[] + auth: string[], + ws: any, + wsCallback: any } export const useUserStore = defineStore({ @@ -20,7 +23,9 @@ export const useUserStore = defineStore({ // token token: '', //用户注册信息 - auth: [] + auth: [], + ws: null, + wsCallback: (type: string, res: any) => {} }), getters: { getToken(): string { @@ -49,6 +54,9 @@ export const useUserStore = defineStore({ setAuth(data: string[]) { this.auth = data; }, + setWsCallback(callback: any) { + this.wsCallback = callback; + }, /** * @description: 验证码登录 */ @@ -99,6 +107,15 @@ export const useUserStore = defineStore({ if (value[AUTH_KEY]) { this.setToken(value[AUTH_KEY]) } + if (!this.ws) { + this.ws = useWebSocket(`/zhxy/webSocket/${value.userId}`, (type: string, res: any) => { + // 判断this.wsCallback是函数,调用 + if (typeof this.wsCallback === "function") { + this.wsCallback(type, res); + } + }); + this.ws.reconnect(); + } authenticationApi({ userId: value.userId }).then(({ result }) => { if (result) { this.setAuth(result) @@ -113,6 +130,11 @@ export const useUserStore = defineStore({ this.setUser('') this.setCurXs({}) this.setAuth([]) + if (this.ws) { + this.ws.closeConnect(); + this.ws = null; + } + this.wsCallback((type: string, res: any) => {}); }, }, persist: {