From 5dea906103fd7661d7560b5461d0bd2f3dfd8a4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=B9=E6=9E=9C=E7=94=B5=E8=84=91?= Date: Fri, 1 Aug 2025 09:02:38 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E9=A6=96?= =?UTF-8?q?=E9=A1=B5=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/index/dialog.vue | 12 +- src/pages/index/index.vue | 86 +-- src/pages/me/index.vue | 1156 ++++++++++++++++++------------------ 3 files changed, 646 insertions(+), 608 deletions(-) diff --git a/src/pages/index/dialog.vue b/src/pages/index/dialog.vue index 8e7adda2..3b194e87 100644 --- a/src/pages/index/dialog.vue +++ b/src/pages/index/dialog.vue @@ -17,9 +17,9 @@ - + - Hi,我是{{ userInfo.mascotInfo?.mascotName || ''}} + {{ userInfo?'Hi,我是'+userInfo?.mascotInfo?.mascotName : 'Hi'}} 工作学习,我都能帮你! 试试他的能力 @@ -93,7 +93,8 @@ onMounted, watch, nextTick, - computed + computed, + onActivated } from 'vue' import common from '@/common/common'; import TouchBtn from '@/pages/course/components/touchBtn.vue' @@ -481,8 +482,7 @@ const pageTopPadding = computed(() => statusBarHeight + 'px') const pages = getCurrentPages(); if (pages && pages.length > 1) { const page = pages[pages.length - 2]; - if (page.route === 'pages/login/login') { - console.log('进来了'); + if (page.route === 'pages/login/login') {ß if (pages.length == 2) { common.switchTab('/pages/index/index'); } else { @@ -502,9 +502,11 @@ const pageTopPadding = computed(() => statusBarHeight + 'px') }) } onMounted(() => { + console.log('onMounted'); getQuestionList() initsocketTask() }) + onHide(() => { // if(watchFlag.value === 1) return // // 停止获取 diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue index f68a2b2b..34978e9f 100644 --- a/src/pages/index/index.vue +++ b/src/pages/index/index.vue @@ -305,54 +305,67 @@ const recommend_class_list = ref([...init_class_data]) const mascotInfo = ref({}) const statistics_data = reactive({ - 'stdtTmLen': 0, // 学习 - 'accmPracticeCnt': 0, // 训练 - 'accmExamCnt': 0, // 考试 - 'startStdtTmLen': 0, // 起始学习 - 'startAccmPracticeCnt': 0, // 起始训练 - 'startAccmExamCnt': 0, // 起始考试 - 'request_time': 0, // 上次请求时间 - "init": function() { // 初始化统计数据 - const index_statistics_data = common.getValue('index_statistics_data') // 获取缓存 + stdtTmLen: 0, // 学习 + accmPracticeCnt: 0, // 训练 + accmExamCnt: 0, // 考试 + startStdtTmLen: 0, // 起始学习 + startAccmPracticeCnt: 0, // 起始训练 + startAccmExamCnt: 0, // 起始考试 + request_time: 0, // 上次请求时间 + init: function() { // 初始化统计数据 + const index_statistics_data = common.getValue('statistics_data') // 获取缓存 if (index_statistics_data) { this.stdtTmLen = index_statistics_data.stdtTmLen; this.accmPracticeCnt = index_statistics_data.accmPracticeCnt; this.accmExamCnt = index_statistics_data.accmExamCnt; } }, - "get_statistics_data": async function() { + get_statistics_data: async function() { try { const time_now = Date.now(); - if (time_now - this.request_time > 300 * 1000) { + let statistics_data = common.getValue('statistics_data') || {}; + if (time_now - this.request_time > 300) { this.request_time = time_now; // 获取最新数据 const res = await getStatisticsData(); - common.setValue('index_statistics_data', res.body) - const stdtTmLen = res.body.stdtTmLen - const accmPracticeCnt = res.body.accmPracticeCnt - const accmExamCnt = res.body.accmExamCnt - if (stdtTmLen != this.stdtTmLen) { - this.startStdtTmLen = this.stdtTmLen - this.stdtTmLen = stdtTmLen - stdtTmLenRef.value.start() + if (res && res.body) { + // 合并新数据与缓存数据,确保只更新有效字段 + statistics_data = { + ...statistics_data, + stdtTmLen: res.body.stdtTmLen || 0, + accmPracticeCnt: res.body.accmPracticeCnt || 0, + accmExamCnt: res.body.accmExamCnt || 0 + }; + + common.setValue('statistics_data', statistics_data); } - if (accmPracticeCnt != this.accmPracticeCnt) { - this.startAccmPracticeCnt = this.accmPracticeCnt - this.accmPracticeCnt = accmPracticeCnt - accmPracticeCntRef.value.start() - } - if (accmExamCnt != this.accmExamCnt) { - this.startAccmExamCnt = this.accmExamCnt - this.accmExamCnt = accmExamCnt - accmExamCntRef.value.start() - } - - console.log('统计数据已更新'); - } else { - console.log('时间没到无需更新'); } + + // 解构赋值获取最新值 + const { + accmExamCnt = 0, accmPracticeCnt = 0, stdtTmLen = 0 + } = statistics_data; + + // 更新数据并触发动画 + if (stdtTmLen !== this.stdtTmLen) { + this.startStdtTmLen = this.stdtTmLen + this.stdtTmLen = stdtTmLen + stdtTmLenRef.value.start() + } + if (accmPracticeCnt !== this.accmPracticeCnt) { + this.startAccmPracticeCnt = this.accmPracticeCnt + this.accmPracticeCnt = accmPracticeCnt + accmPracticeCntRef.value.start() + } + if (accmExamCnt !== this.accmExamCnt) { + this.startAccmExamCnt = this.accmExamCnt + this.accmExamCnt = accmExamCnt + accmExamCntRef.value.start() + } + } catch (error) { - console.log('获取统计数据失败:', error); + console.error('获取统计数据失败:', error); + // 可以在这里添加更多的错误处理逻辑,比如显示错误提示 } } }); @@ -386,6 +399,11 @@ animationType: 'slide-in-bottom' }) } + onLoad(() => { + statistics_data['init'](); // 初始化数据 + // 检测如果没设置吉祥物,跳转到吉祥物界面 + + }) onShow(() => { if (!common.isLogin()) { common.navigateTo('/pages/login/login') diff --git a/src/pages/me/index.vue b/src/pages/me/index.vue index 8c59eaaf..cbde97b9 100644 --- a/src/pages/me/index.vue +++ b/src/pages/me/index.vue @@ -1,570 +1,588 @@ - - - - - \ No newline at end of file From a061244a4826bd1c17505330b7000b266e5bbc0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=B0=E5=B2=A9?= Date: Fri, 1 Aug 2025 15:14:01 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8DBUG,1.=E5=BD=93=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E8=AE=BE=E7=BD=AE=E5=90=89=E7=A5=A5=E7=89=A9=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E5=BC=BA=E5=88=B6=E9=80=80=E5=87=BA=EF=BC=8C=E4=B9=9F?= =?UTF-8?q?=E8=83=BD=E9=87=8D=E6=96=B0=E5=9B=9E=E5=88=B0=E5=90=89=E7=A5=A5?= =?UTF-8?q?=E7=89=A9=E8=AE=BE=E7=BD=AE=E4=B9=9F=E3=80=822.=E6=94=B9AI?= =?UTF-8?q?=E9=97=AE=E7=AD=94=E9=A1=B5=E4=B8=BA=E8=B5=B7=E5=A7=8B=E9=A1=B5?= =?UTF-8?q?=EF=BC=8C=E8=AF=A6=E7=BB=86=E4=BC=98=E5=8C=96=E4=BA=86=E4=BB=8E?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E9=A1=B5=E5=88=B0AI=E9=97=AE=E7=AD=94?= =?UTF-8?q?=E9=A1=B5=E7=9A=84=E9=80=BB=E8=BE=91=EF=BC=8C=E8=AF=A6=E7=BB=86?= =?UTF-8?q?=E7=9A=84=E4=BC=98=E5=8C=96=E4=BA=86=E4=BB=8E=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E5=88=B0AI=E9=97=AE=E7=AD=94=E9=A1=B5=E7=9A=84=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E3=80=823=E3=80=82=E6=94=B9=E4=BA=86wensocket?= =?UTF-8?q?=E7=9A=84=E5=85=A8=E5=B1=80=E5=BC=B9=E5=87=BA=E6=A1=86=E8=B7=B3?= =?UTF-8?q?=E8=BD=AC=E5=88=B0=E7=99=BB=E5=BD=95=E9=A1=B5=E7=9A=84=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 1 + src/api/request.js | 27 +- src/api/socket.js | 6 +- src/common/common.js | 36 +- src/common/mascot.js | 38 +- src/pages.json | 3 +- src/pages/courseDetail/components/comment.vue | 2 +- src/pages/index/dialog.vue | 98 ++-- src/pages/index/index.vue | 26 +- src/pages/login/login.vue | 470 +++++++++--------- src/pages/me/index.vue | 5 +- src/pages/search/search.vue | 14 +- src/pagesOther.json | 3 +- 13 files changed, 412 insertions(+), 317 deletions(-) diff --git a/src/App.vue b/src/App.vue index 39a9f809..6c54579d 100644 --- a/src/App.vue +++ b/src/App.vue @@ -7,6 +7,7 @@ export default { animationType: 'slide-in-bottom' }); }) + // console.log('预加载'); }, onShow: function () { // console.log('App Show') diff --git a/src/api/request.js b/src/api/request.js index 201569e6..d78bf0f1 100644 --- a/src/api/request.js +++ b/src/api/request.js @@ -17,7 +17,7 @@ export const get_base_url = url => { return baseUrl // #endif // #ifdef APP-PLUS - return ENV.VITE_APP_BASE_API_Url + return ENV.VITE_APP_BASE_API_Url // #endif } else { // 其他环境,包括生产环境,sit环境,uat环境 return ENV.VITE_APP_BASE_API_Url @@ -32,15 +32,28 @@ export const REQUES_ERROR_CODES = { // 去登录弹窗状态 let no_login_show_modal_state = false // 去登录方法 -export const goto_login_fun = () => { +export const goto_login_fun = (from = 'http') => { if (no_login_show_modal_state) return; no_login_show_modal_state = true + let page_route = '' + const pages = getCurrentPages(); + if (pages.length >= 1) { + const page = pages[pages.length - 1]; + page_route = page.route + } + if (page_route === 'pages/login/login') return; common.hideLoading() - common.show('未登录', '现在去登录').then(() => { + common.show('未登录', '现在去登录', false).then(() => { common.navigateTo('/pages/login/login') + if (from === 'socket' && page_route !== '') { + common.redirectTo('/pages/login/login?path=' + page_route) + } else { + common.navigateTo('/pages/login/login') + } + }).finally(() => { no_login_show_modal_state = false - }) + }) } export default function request({ @@ -73,7 +86,7 @@ export default function request({ data: data, method: method, header: headers_base, - timeout:timeout, + timeout: timeout, success: (response) => { if (isStream) { // 流式传输,直接返回 return resolve(response); @@ -83,8 +96,8 @@ export default function request({ const res = response.data if (res?.rtnCode === '0000') { return resolve(res) - }else{ - if(toastErrors){ + } else { + if (toastErrors) { common.msg(res?.message) } } diff --git a/src/api/socket.js b/src/api/socket.js index 9d7427f5..03bb31f0 100644 --- a/src/api/socket.js +++ b/src/api/socket.js @@ -69,13 +69,13 @@ export default class WebSocketUtil { clearInterval(this.reconnectTimer); this.reconnectTimer = null this.close() - goto_login_fun(); + goto_login_fun('socket'); return } }else{ clearInterval(this.reconnectTimer); // 清除重连计时器 this.reconnectTimer = null - goto_login_fun(); + goto_login_fun('socket'); return } this.triggerEvent('message', res); // 触发消息接收事件 @@ -224,7 +224,7 @@ export default class WebSocketUtil { this.triggerEvent('error', new Error('达到最大重连次数')); this.reconnectTimer = null this.close() - goto_login_fun() + goto_login_fun('socket') } } diff --git a/src/common/common.js b/src/common/common.js index 665d1ade..9628f88f 100644 --- a/src/common/common.js +++ b/src/common/common.js @@ -62,11 +62,36 @@ const loading = (title = '加载中', mask = true) => uni.showLoading({ }) const hideLoading = () => uni.hideLoading() + +// 防抖工具函数 +function debounce(fn, wait = 300) { + let isLocked = false; // 锁定状态标记 + return function(...args) { + // 如果处于锁定状态,直接返回不执行 + if (isLocked) { + return; + } + // 执行函数 + fn.apply(this, args); + + // 锁定,防止再次执行 + isLocked = true; + + // 等待指定时间后解锁 + setTimeout(() => { + isLocked = false; + }, wait); + }; +} + // 保留当前页面,跳转到应用内的某个页面,使用uni.navigateBack可以返回到原页面。 -const navigateTo = (url, data = {}) => uni.navigateTo({ - url: url, - ...data -}); +const navigateTo = debounce(function(url, data = {}) { + uni.navigateTo({ + url: url, + ...data + }); +}) + // 关闭所有页面,打开到应用内的某个页面。 const reLaunch = url => { uni.reLaunch({ @@ -80,9 +105,10 @@ const switchTab = url => { }); } // 关闭当前页面,返回上一页面或多级页面。可通过 getCurrentPages() 获取当前的页面栈,决定需要返回几层。 -const navigateBack = (delta = 1, fun = () => {}) => { +const navigateBack = (delta = 1, fun = () => {}, data = {}) => { uni.navigateBack({ delta: delta, + ...data, success() { fun() } diff --git a/src/common/mascot.js b/src/common/mascot.js index ac78daa5..1adf0390 100644 --- a/src/common/mascot.js +++ b/src/common/mascot.js @@ -1,30 +1,28 @@ // 设置科技鹿 -import {getUserInfo} from "@/common/common.js" +import { + getUserInfo +} from "@/common/common.js" import common from "@/common/common.js" export const setMascot = () => { - // const mascotState = common.getValue('mascotState') || false const mascotState = false - // console.log('设置科技鹿', mascotState); if (!mascotState) { - - try{ + try { const userInfo = getUserInfo() const mascotInfo = userInfo?.mascotInfo - console.log('设置科技鹿', mascotInfo); - uni.setTabBarStyle({ - midButton: { - iconPath: "/static/images/icon/fawn-" + (mascotInfo?.mascotNo || '1') + ".png", - width: "86px", - height: "86px", - iconWidth: "90px" - }, - success: () => { - common.setValue('mascotState', true) - } - }) - } catch(e){ - - } + if (mascotInfo) { + uni.setTabBarStyle({ + midButton: { + iconPath: "/static/images/icon/fawn-" + (mascotInfo?.mascotNo || '1') + ".png", + width: "86px", + height: "86px", + iconWidth: "90px" + }, + success: () => { + common.setValue('mascotState', true) + } + }) + } + } catch (e) {} } return mascotState } \ No newline at end of file diff --git a/src/pages.json b/src/pages.json index eec33217..9069a2c4 100644 --- a/src/pages.json +++ b/src/pages.json @@ -5,7 +5,8 @@ "style": { "navigationBarTitleText": "AI问答", "app-plus": { - "titleNView": false + "titleNView": false, + "animationType": "fade-in" } } }, diff --git a/src/pages/courseDetail/components/comment.vue b/src/pages/courseDetail/components/comment.vue index a2ddf35e..8493088d 100644 --- a/src/pages/courseDetail/components/comment.vue +++ b/src/pages/courseDetail/components/comment.vue @@ -70,7 +70,7 @@ 这里什么都没有 - + - + AI问答 @@ -28,7 +28,8 @@ {{questionList[item-1].hotContent}} + @click="sendText(questionList[item-1].hotContent)">{{questionList[item-1].hotContent}} + statusBarHeight + 'px') + const pageTopPadding = computed(() => statusBarHeight + 'px') const socketStore = useSocketStore() const { SocketObj } = storeToRefs(socketStore) - const userInfo = computed(() => getUserInfo()) - console.log('userInfoxxx', getUserInfo()); + + const userInfo = ref(getUserInfo()) const questionList = ref([ // '对公小程序开户流程?', // '厅堂服务经理2025年管理办法?', @@ -169,7 +170,7 @@ const pageTopPadding = computed(() => statusBarHeight + 'px') const reqBatch = ref('') const seqNo = ref('') const mascotId = computed(() => { - return unref(userInfo).mascotInfo?.mascotId || 'Tst00001' + return unref(userInfo)?.mascotInfo?.mascotId || 'Tst00001' }) const answerText = ref('') const answerIsOver = ref(true) @@ -261,7 +262,7 @@ const pageTopPadding = computed(() => statusBarHeight + 'px') talkingList.value.push({ type: 'answer', isLoading: true, - id: _id+'loading' + id: _id + 'loading' }) scrollToBottomNow() return @@ -396,7 +397,24 @@ const pageTopPadding = computed(() => statusBarHeight + 'px') } } const scrolltolower = () => { - common.switchTab('/pages/index/index') + const pages = getCurrentPages(); + const pageCount = pages?.length || 0; + // 处理页面数量不足的情况,此为调试时候异常情况 + if (pageCount <= 1) { + common.switchTab('/pages/index/index'); + return; + } + const prevPage = pages[pageCount - 2]; // 获取上一页实例并验证 + // 根据上一页路由决定跳转方式 + if (prevPage.route === 'pages/login/login') { + // 登录页特殊处理,如果刚好等于2说明书刚启动,里面只有登录页和当前页,这样直接返回老首页 + pageCount === 2 ? + common.switchTab('/pages/index/index') : + common.navigateBack(2); + } else { + // 普通页面返回上一页 + common.navigateBack(); + } } const touchBtnCallBack = ref(null) const askData = ref({}) @@ -416,7 +434,6 @@ const pageTopPadding = computed(() => statusBarHeight + 'px') isLoading: true }) scrollToBottomNow() - console.log(voicePath, 111111111) commonUploadVoiceFile(voicePath, '/traask/traAskchat/voiceTrans', {}).then(res => { let _res = JSON.parse(res.data) if (_res.rtnCode === '0000') { @@ -482,7 +499,7 @@ const pageTopPadding = computed(() => statusBarHeight + 'px') const pages = getCurrentPages(); if (pages && pages.length > 1) { const page = pages[pages.length - 2]; - if (page.route === 'pages/login/login') {ß + if (page.route === 'pages/login/login') { if (pages.length == 2) { common.switchTab('/pages/index/index'); } else { @@ -494,40 +511,49 @@ const pageTopPadding = computed(() => statusBarHeight + 'px') } return false }); - + const getQuestionList = () => { - queryHotQuestionApi().then(res=> { + queryHotQuestionApi().then(res => { console.log(res) questionList.value = res.body }) } - onMounted(() => { - console.log('onMounted'); + const loadData = async () => { + userInfo.value = getUserInfo(); getQuestionList() initsocketTask() + }; + onLoad(() => { + if (!common.isLogin()) { + common.navigateTo('/pages/login/login') + return + } + // 判断下如果没有设置吉祥物就跳转到吉祥物页面 + if(userInfo.value?.mascotInfo.mascotId === null) { //说明这人在上次选吉祥物的时候退出了,没有选到吉祥物 + common.redirectTo('/pages/mascot/mascot_select_list'); + return + } }) - + onMounted(() => { + loadData() + }) + + const refreshData = () => { + loadData(); + }; onHide(() => { - // if(watchFlag.value === 1) return - // // 停止获取 - // sendMessage({ - // "commond" : 'ASK-STOP', - // "body" : { - // reqBatch: reqBatch.value, - // seqNo: seqNo.value, - // } - // }) - // socketStore?.closeSocket() + }) onShow(() => { - if (watchFlag.value === 1) return - // initsocketTask() - + }) onUnload(() => { watchFlag.value = 1 socketStore?.closeSocket() }) + defineExpose({ + refreshData + }); + \ No newline at end of file diff --git a/src/pages/me/index.vue b/src/pages/me/index.vue index cbde97b9..ee0409af 100644 --- a/src/pages/me/index.vue +++ b/src/pages/me/index.vue @@ -29,14 +29,15 @@ + - + diff --git a/src/pages/search/search.vue b/src/pages/search/search.vue index 1f7fecd7..63adc9c0 100644 --- a/src/pages/search/search.vue +++ b/src/pages/search/search.vue @@ -44,13 +44,14 @@ - - - - - {{ item }} + + + + {{ item }} + +