UnisKB/ui/src/stores/modules/application.ts

128 lines
3.6 KiB
TypeScript
Raw Normal View History

2025-06-10 07:03:47 +00:00
import { defineStore } from 'pinia'
import applicationApi from '@/api/application/application'
import applicationXpackApi from '@/api/application/application-xpack'
import { type Ref } from 'vue'
import { getBrowserLang } from '@/locales/index'
import useUserStore from './user'
const useApplicationStore = defineStore('application', {
state: () => ({
2025-07-03 04:26:20 +00:00
location: `${window.location.origin}${window.MaxKB.chatPrefix}/`,
2025-06-10 07:03:47 +00:00
}),
actions: {
async asyncGetAllApplication() {
return new Promise((resolve, reject) => {
2025-06-13 09:17:01 +00:00
// applicationApi
// .getAllAppilcation()
// .then((data) => {
// resolve(data)
// })
// .catch((error) => {
// reject(error)
// })
2025-06-10 07:03:47 +00:00
})
},
async asyncGetApplicationDetail(id: string, loading?: Ref<boolean>) {
return new Promise((resolve, reject) => {
applicationApi
.getApplicationDetail(id, loading)
.then((data) => {
resolve(data)
})
.catch((error) => {
reject(error)
})
})
},
async asyncGetAccessToken(id: string, loading?: Ref<boolean>) {
return new Promise((resolve, reject) => {
const user = useUserStore()
if (user.isEnterprise()) {
applicationXpackApi
.getAccessToken(id, loading)
.then((data) => {
resolve(data)
})
.catch((error) => {
reject(error)
})
} else {
applicationApi
.getAccessToken(id, loading)
.then((data) => {
resolve(data)
})
.catch((error) => {
reject(error)
})
}
})
},
async asyncGetAppProfile(loading?: Ref<boolean>) {
return new Promise((resolve, reject) => {
2025-06-13 13:56:01 +00:00
console.log('xxxx')
applicationApi
.getAppProfile(loading)
.then((res: any) => {
2025-06-13 13:56:01 +00:00
sessionStorage.setItem('language', res.data?.language || getBrowserLang())
resolve(res)
})
.catch((error: any) => {
2025-06-13 13:56:01 +00:00
reject(error)
})
2025-06-10 07:03:47 +00:00
})
},
async asyncAppAuthentication(
token: string,
loading?: Ref<boolean>,
authentication_value?: any,
) {
return new Promise((resolve, reject) => {
2025-06-13 13:56:01 +00:00
applicationApi
.postAppAuthentication(token, loading, authentication_value)
.then((res: any) => {
2025-06-13 13:56:01 +00:00
localStorage.setItem(`${token}-accessToken`, res.data)
sessionStorage.setItem(`${token}-accessToken`, res.data)
resolve(res)
})
.catch((error: any) => {
2025-06-13 13:56:01 +00:00
reject(error)
})
2025-06-10 07:03:47 +00:00
})
},
async refreshAccessToken(token: string) {
this.asyncAppAuthentication(token)
},
// 修改应用
async asyncPutApplication(id: string, data: any, loading?: Ref<boolean>) {
return new Promise((resolve, reject) => {
applicationApi
.putApplication(id, data, loading)
.then((data) => {
resolve(data)
})
.catch((error) => {
reject(error)
})
})
},
async validatePassword(id: string, password: string, loading?: Ref<boolean>) {
return new Promise((resolve, reject) => {
2025-06-13 09:17:01 +00:00
// applicationApi
// .validatePassword(id, password, loading)
// .then((data) => {
// resolve(data)
// })
// .catch((error) => {
// reject(error)
// })
2025-06-10 07:03:47 +00:00
})
},
},
})
export default useApplicationStore