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问答 @@ -17,9 +17,9 @@ - + - Hi,我是{{ userInfo.mascotInfo?.mascotName || ''}} + {{ userInfo?'Hi,我是'+userInfo?.mascotInfo?.mascotName : 'Hi'}} 工作学习,我都能帮你! 试试他的能力 @@ -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年管理办法?', @@ -168,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) @@ -260,7 +262,7 @@ const pageTopPadding = computed(() => statusBarHeight + 'px') talkingList.value.push({ type: 'answer', isLoading: true, - id: _id+'loading' + id: _id + 'loading' }) scrollToBottomNow() return @@ -395,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({}) @@ -415,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 +500,6 @@ const pageTopPadding = computed(() => statusBarHeight + 'px') if (pages && pages.length > 1) { const page = pages[pages.length - 2]; if (page.route === 'pages/login/login') { - console.log('进来了'); if (pages.length == 2) { common.switchTab('/pages/index/index'); } else { @@ -494,38 +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(() => { + 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 8c59eaaf..ee0409af 100644 --- a/src/pages/me/index.vue +++ b/src/pages/me/index.vue @@ -1,570 +1,589 @@ - - - - - \ No newline at end of file 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 }} + +