From 73a914bb2aabd63533e0954eaaad7b00c743ac4b Mon Sep 17 00:00:00 2001 From: yangyin <1850366751@qq.com> Date: 星期四, 18 七月 2024 14:01:26 +0800 Subject: [PATCH] Merge branch 'master' of http://47.103.154.90:83/r/WI/Web.V1.0 --- src/api/ai/chat.ts | 14 ++++--- src/api/ai/user.ts | 21 ++++------ src/views/project/ch/home/component/waterRight/top.vue | 4 ++ src/components/chat/Chat.vue | 2 src/utils/request.ts | 43 +++++++++++++++------ src/views/project/ch/home/Home.vue | 13 +----- src/layout/component/header/Header.vue | 4 +- 7 files changed, 56 insertions(+), 45 deletions(-) diff --git a/src/api/ai/chat.ts b/src/api/ai/chat.ts index 6f72b8a..aa7d9f8 100644 --- a/src/api/ai/chat.ts +++ b/src/api/ai/chat.ts @@ -1,5 +1,8 @@ import request from '/@/utils/request'; import { toFormData } from '/@/utils/util'; +const GET_SECTION_SAMPLE_API = '/section/get_section_sample'; +const GET_SECTION_A_LIST_API = '/section/get_section_a_list'; +export const NO_AUTH_API_LIST = [GET_SECTION_SAMPLE_API, GET_SECTION_A_LIST_API]; //#region ====================== knowledge ====================== @@ -108,7 +111,7 @@ */ export const getSectionList = async (req: any = request) => { return req({ - url: '/section/get_section_a_list', + url: GET_SECTION_A_LIST_API, method: 'POST', }); }; @@ -183,7 +186,7 @@ // 鑾峰彇AI瀵硅瘽娴嬭瘯渚嬪瓙鍒楄〃 export const getSelectSample = async (params, req: any = request) => { return req({ - url: '/section/get_section_sample', + url: GET_SECTION_SAMPLE_API, method: 'POST', data: params, headers: { @@ -269,9 +272,9 @@ /** * 鏌ヨ闂杩涘害 - * @param params - * @param req - * @returns + * @param params + * @param req + * @returns */ export const getQuestionProcess = async (params, req: any = request) => { return req({ @@ -294,4 +297,3 @@ }, }); }; - diff --git a/src/api/ai/user.ts b/src/api/ai/user.ts index 6b14b4f..a3bbf3b 100644 --- a/src/api/ai/user.ts +++ b/src/api/ai/user.ts @@ -1,31 +1,26 @@ import request from '/@/utils/request'; import { toFormData } from '/@/utils/util'; - +export const LOGIN_URL = '/login'; /** * @summary description */ export const PostLogin = async (params, req: any = request) => { return req({ - url: '/login', + url: LOGIN_URL, method: 'POST', data: params, - headers: { + headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, }); }; - - - - - /** * @summary description */ -export const PostLogout = async ( req:any = request) => { - return req({ - url: "/logout", - method: "POST", - }); +export const PostLogout = async (req: any = request) => { + return req({ + url: '/logout', + method: 'POST', + }); }; diff --git a/src/components/chat/Chat.vue b/src/components/chat/Chat.vue index cf71224..8783ac6 100644 --- a/src/components/chat/Chat.vue +++ b/src/components/chat/Chat.vue @@ -50,7 +50,7 @@ </div> </div> - <Loding v-else class="w-12" :process="process" /> + <Loding v-else class="w-fit" :process="process" /> </div> </div> <div v-if="showAskMore" class="ml-4 mt-5 text-sm"> diff --git a/src/layout/component/header/Header.vue b/src/layout/component/header/Header.vue index 98aab50..23f5564 100644 --- a/src/layout/component/header/Header.vue +++ b/src/layout/component/header/Header.vue @@ -70,10 +70,10 @@ const getSystemNotify = async () => { const res = await systemNotifyList(); - res.messages.forEach((element) => { + res.messages?.forEach((element) => { element.notify_time = element.notify_time.slice(0, 10); }); - state.announcementList = res.messages.sort(sortData).slice(0, 5); + state.announcementList = res.messages?.sort(sortData).slice(0, 5) ??[]; }; const routerMeta = computed(() => router.currentRoute.value.meta); const handleAnnouncementClick = () => { diff --git a/src/utils/request.ts b/src/utils/request.ts index f487bbf..a8f78b5 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -5,6 +5,8 @@ import { debounce } from './util'; import { AUTH_URL, MAIN_URL, SECONDARY_URL } from '/@/constants'; import { Local, LoginInfo, Session } from '/@/utils/storage'; +import { LOGIN_URL } from '../api/ai/user'; +import { NO_AUTH_API_LIST } from '../api/ai/chat'; // import JSONbig from 'json-bigint'; //#region ====================== 鍚庣 res.err_code ====================== @@ -18,28 +20,41 @@ } //#endregion -const handleNoAuth = debounce(() => { +const emitNoAuth = () => { emitter.emit('logout'); emitter.emit('openLoginDlg'); +}; + +export const handleNormalAuth = () => { + const accessSession = Local.get(accessSessionKey); + if (!accessSession) { + emitter.emit('logout'); + emitter.emit('openLoginDlg'); + } + return !!accessSession; +}; + +const handleNoAuth = debounce(() => { + emitNoAuth(); }); -const loginUrl = '/login'; const initRequestInterceptor = (request: AxiosInstance) => { // 娣诲姞璇锋眰鎷︽埅鍣� request.interceptors.request.use( (config) => { // 鑾峰彇鏈湴鐨� token const accessSession = Local.get(accessSessionKey); - - if (accessSession) { - // 灏� token 娣诲姞鍒拌姹傛姤鏂囧ご涓� - config.headers['hswatersession'] = accessSession; - } else { - if (config.url !== loginUrl) { - handleNoAuth(config.url); - - throw '鏉冮檺楠岃瘉澶辫触'; + if (!NO_AUTH_API_LIST.includes(config.url)) { + if (accessSession) { + // 灏� token 娣诲姞鍒拌姹傛姤鏂囧ご涓� + config.headers['hswatersession'] = accessSession; + } else { + if (config.url !== LOGIN_URL) { + handleNoAuth(config.url); + throw '鏉冮檺楠岃瘉澶辫触'; + } } } + return config; }, (error) => { @@ -73,7 +88,7 @@ if (!serveData.json_ok) { switch (serveData?.err_code) { case ErrorCode.Auth: - if (res.config.url !== loginUrl) { + if (res.config.url !== LOGIN_URL) { handleNoAuth(); throw '鏉冮檺楠岃瘉澶辫触'; } @@ -87,6 +102,10 @@ return res.data; }, (error) => { + if (typeof error === 'string') { + // ElMessage.error(error); + return Promise.reject(error); + } // 澶勭悊鍝嶅簲閿欒 if (error.response) { if (error.response.status === 401) { diff --git a/src/views/project/ch/home/Home.vue b/src/views/project/ch/home/Home.vue index ca6b1cb..54b6a77 100644 --- a/src/views/project/ch/home/Home.vue +++ b/src/views/project/ch/home/Home.vue @@ -8,13 +8,8 @@ <div class="flex items-center flex-column mt-20"> <div class="flex items-center flex-column"> <waterTop /> - <div v-if="isLoginStatus"> - <waterCenter /> - <waterBottom /> - </div> - <div v-else> - <el-empty></el-empty> - </div> + <waterCenter /> + <waterBottom /> </div> </div> </div> @@ -31,13 +26,9 @@ </template> <script setup lang="ts"> -import { ref } from 'vue'; import waterBottom from './component/waterRight/bottom.vue'; import waterCenter from './component/waterRight/center.vue'; import waterTop from './component/waterRight/top.vue'; -import { accessSessionKey } from '/@/utils/request'; -import { Local } from '/@/utils/storage'; -const isLoginStatus = ref(!!Local.get(accessSessionKey)); </script> <style scoped lang="scss"> .pc-chat_room { diff --git a/src/views/project/ch/home/component/waterRight/top.vue b/src/views/project/ch/home/component/waterRight/top.vue index 298e64f..9f4e757 100644 --- a/src/views/project/ch/home/component/waterRight/top.vue +++ b/src/views/project/ch/home/component/waterRight/top.vue @@ -28,6 +28,7 @@ import router from '/@/router'; import { activeChatRoom, activeLLMId, activeSectionAId } from '/@/stores/chatRoom'; import emitter from '/@/utils/mitt'; +import { handleNormalAuth } from '/@/utils/request'; const emits = defineEmits(['sendClick']); const inputValue = ref('浣犳槸璋侊紵'); @@ -37,6 +38,9 @@ ElMessage.warning('璇烽�夋嫨搴旂敤鍦烘櫙'); return; } + if (!handleNormalAuth()) { + return; + } const res = await setHistoryGroupTitle({ history_group_id: activeChatRoom.value.id, -- Gitblit v1.9.3