wujingjing
2025-03-14 4e57cc40899cb6dcaeec1eda0a2325a74e44f9db
src/stores/chatRoom.ts
@@ -1,11 +1,15 @@
import { reject } from 'lodash-es';
import { computed, ref } from 'vue';
import { CreateHistoryGroup, GetHistoryGroups, getSectionList, getSelectSample, getUserTemplateList } from '../api/ai/chat';
import { PostLogin } from '../api/ai/user';
import { PingLogin } from '../api/system';
import { LOGIN_CLIENT, STORED_ACCOUNT_KEY, handleAfterLogin } from '../layout/component/login/login';
import type { ChatRoomItem } from '../layout/component/sidebar/components/types';
import { router } from '../router';
import { decrypt } from '../utils/cypto';
import emitter from '../utils/mitt';
import { gotoRoute } from '../utils/route';
import { Local } from '../utils/storage';
import { Local, LocalPlus } from '../utils/storage';
import { getCurrentPosition } from '../utils/brower';
/**
 * Room 关联的一些配置
@@ -61,7 +65,7 @@
/** @description 当前聊天室 groupType */
export const activeGroupType = computed({
   get: () => {
      const result = getRoomConfig(activeRoomId.value, 'activeGroupType') ?? '业务场景';
      const result = getRoomConfig(activeRoomId.value, 'activeGroupType') ?? groupTypeList.value.at(-1);
      return result;
   },
   set: (value) => {
@@ -120,7 +124,7 @@
export const getAllData = async () => {
   Promise.allSettled([getSectionList(), getSelectSample({}), getUserTemplateList()])
      .then((res) => {
         let [sectionList, selectSample, userTemplateList] = res;
         const [sectionList, selectSample, userTemplateList] = res;
         sceneGroupList.value = sectionList?.value?.groups ?? [];
         getSelectListSample(selectSample, userTemplateList);
      })
@@ -143,13 +147,13 @@
export const newChatRoomClick = async () => {
   const res = await CreateHistoryGroup({
      group_title: '新建对话开始',
      group_title: '新建对话',
   });
   const newRoom = {
      id: res.history_group_id,
      isInitial: true,
      title: '新建对话开始',
      title: '新建对话',
   };
   if (!chatRoomList.value) {
      chatRoomList.value = [newRoom];
@@ -238,3 +242,47 @@
      }
   });
};
export const pingLogin = async () => {
   // 5分钟
   const interval = 1000 * 60 * 5;
   // const interval = 1000 *2;
   const timer = setInterval(async () => {
      const res = await PingLogin();
      if (!res?.is_login) {
         clearInterval(timer);
      }
   }, interval);
   return timer;
};
/**
 * 自动登录,从本地获取登录信息
 * @returns
 */
export const autoLogin = async () => {
   const account = LocalPlus.get(STORED_ACCOUNT_KEY);
   if (!account) return;
   const accountInfo = decrypt(account);
   if (!accountInfo) return;
   const res: any = await PostLogin({
      user: accountInfo.username,
      pass: accountInfo.password,
      client: LOGIN_CLIENT,
   });
   if (!res.json_ok || !res.hswatersession) {
      return;
   }
   handleAfterLogin(res);
};
export const currentPosition = ref<Position>(null);
export const getGlobalPosition = () => {
   getCurrentPosition();
   setInterval(() => {
      getCurrentPosition();
   }, 1000 * 60 * 60);
};