xiongzhu 2 tahun lalu
induk
melakukan
5be59d6878

+ 1 - 1
.env.org

@@ -11,4 +11,4 @@ VITE_GLOB_APP_PWA=false
 
 VITE_GLOB_APP_PUBLIC_PATH=/ui/
 
-VITE_ORG_MODE=false
+VITE_ORG_MODE=true

+ 1 - 0
.gitignore

@@ -11,6 +11,7 @@ node_modules
 .DS_Store
 dist
 dist-ssr
+dist-org
 coverage
 *.local
 

+ 1 - 0
package.json

@@ -13,6 +13,7 @@
   "scripts": {
     "dev": "vite",
     "build": "run-p type-check build-only",
+    "build:org": "run-p type-check 'build-only --mode org'",
     "preview": "vite preview",
     "build-only": "vite build",
     "type-check": "vue-tsc --noEmit",

+ 4 - 3
src/api/index.ts

@@ -21,6 +21,7 @@ export function fetchChatConfig<T = any>() {
 }
 
 export function fetchChatAPIProcess<T = any>(params: {
+    url?: string | null
     prompt: string
     options?: { conversationId?: string; parentMessageId?: string }
     signal?: GenericAbortSignal
@@ -46,7 +47,7 @@ export function fetchChatAPIProcess<T = any>(params: {
     // }
 
     return post<T>({
-        url: '/chat/chat-process1',
+        url: params.url || '/chat/chat-process1',
         data,
         signal: params.signal,
         onDownloadProgress: params.onDownloadProgress
@@ -205,8 +206,8 @@ export function fetchGetChatRole<T>(id: any) {
     })
 }
 
-export function fetchGetCompany<T>(id: any) {
+export function fetchGetCompany<T>() {
     return get<T>({
-        url: '/org/' + id
+        url: '/org/'
     })
 }

+ 3 - 8
src/router/permission.ts

@@ -5,17 +5,12 @@ import { useBasicLayout } from '@/hooks/useBasicLayout'
 
 export function setupPageGuard(router: Router) {
     router.beforeEach(async (to, from, next) => {
-        const userStore = useUserStore()
-        if (to.params.companyId) {
+        if (import.meta.env.VITE_ORG_MODE === 'true') {
             const companyStore = useCompanyStore()
-            await companyStore.getCompanyInfo(Number(to.params.companyId))
-            try {
-                await userStore.fetch()
-            } catch (error) {
-                /* empty */
-            }
+            await companyStore.getCompanyInfo( )
         }
         const { isMobile } = useBasicLayout()
+        const userStore = useUserStore()
         const userMemberStore = useUserMemberStore()
         if (!userStore.userInfo.id) {
             try {

+ 7 - 0
src/store/modules/auth/index.ts

@@ -52,6 +52,13 @@ export const useAuthStore = defineStore('auth-store', {
 
         async phoneLogin(phone: string | number, code: string | number, invitor?: string | number) {
             const data = await fetchPhoneLogin<any>(phone, code, invitor)
+            if (import.meta.env.VITE_ORG_MODE === 'true') {
+                const companyStore = useCompanyStore()
+                if (data.user.orgId !== companyStore.company.id) {
+                    throw new Error('该账号暂无权限登录')
+                }
+            }
+
             this.setToken(data.access_token)
         }
     }

+ 4 - 16
src/store/modules/company/index.ts

@@ -21,22 +21,10 @@ export const useCompanyStore = defineStore('company-store', {
         setCompanyInfo(company: Partial<CompanyInfo>) {
             this.company = { ...this.company, ...company }
         },
-        async getCompanyInfo(companyId: number | undefined | string) {
-            if (companyId === 0) {
-                this.setCompanyInfo({
-                    id: 0,
-                    name: '走马AI',
-                    assistantName: '走马AI助手'
-                })
-            } else {
-                await fetchGetCompany(companyId).then((res: any) => {
-                    this.setCompanyInfo({
-                        ...res,
-                        assistantName: res.company ? res.company : res.name + '助手',
-                        code: res.code || undefined
-                    })
-                })
-            }
+        async getCompanyInfo() {
+            await fetchGetCompany().then((res: any) => {
+                this.setCompanyInfo(res)
+            })
         }
     }
 })

+ 1 - 0
src/typings/env.d.ts

@@ -5,4 +5,5 @@ interface ImportMetaEnv {
     readonly VITE_APP_API_BASE_URL: string
     readonly VITE_GLOB_OPEN_LONG_REPLY: string
     readonly VITE_GLOB_APP_PWA: string
+    readonly VITE_ORG_MODE
 }

+ 3 - 1
src/views/chat/Chat.vue

@@ -80,7 +80,7 @@ function handleSubmit() {
             const inversions = dataSources.value.filter(item => {
                 return item.inversion
             })
-            if (inversions.length > 0 && inversions.length % 3 === 0) {
+            if (import.meta.env.VITE_ORG_MODE !== 'true' && inversions.length > 0 && inversions.length % 3 === 0) {
                 showVipTips.value = true
             }
         }
@@ -131,6 +131,7 @@ async function onConversation() {
         let lastText = ''
         const fetchChatAPIOnce = async () => {
             await fetchChatAPIProcess<Chat.ConversationResponse>({
+                url: (Number(company.value?.id) || 0) > 0 ? `/org/${company.value.id}/streamAsk` : null,
                 prompt: message,
                 options,
                 signal: controller.signal,
@@ -236,6 +237,7 @@ async function onRegenerate(index: number) {
         let lastText = ''
         const fetchChatAPIOnce = async () => {
             await fetchChatAPIProcess<Chat.ConversationResponse>({
+                url: (Number(company.value?.id) || 0) > 0 ? `/org/${company.value.id}/streamAsk` : null,
                 prompt: message,
                 options,
                 signal: controller.signal,

+ 1 - 0
vite.config.ts

@@ -74,6 +74,7 @@ export default defineConfig(env => {
             }
         },
         build: {
+            outDir: viteEnv.VITE_ORG_MODE === 'true' ? 'dist-org' : 'dist',
             reportCompressedSize: false,
             sourcemap: false,
             commonjsOptions: {