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

70 lines
1.7 KiB
TypeScript
Raw Normal View History

2023-11-02 01:56:14 +00:00
import { defineStore } from 'pinia'
import type { datasetData } from '@/api/type/dataset'
import type { UploadUserFile } from 'element-plus'
2023-11-24 11:02:52 +00:00
import datasetApi from '@/api/dataset'
2023-11-30 08:35:52 +00:00
import { type Ref } from 'vue'
2023-11-02 01:56:14 +00:00
export interface datasetStateTypes {
baseInfo: datasetData | null
2024-01-08 09:53:50 +00:00
webInfo: any
2023-11-02 01:56:14 +00:00
documentsFiles: UploadUserFile[]
}
const useDatasetStore = defineStore({
id: 'dataset',
state: (): datasetStateTypes => ({
baseInfo: null,
2024-01-08 09:53:50 +00:00
webInfo: null,
2023-11-02 01:56:14 +00:00
documentsFiles: []
}),
actions: {
2023-11-10 11:05:52 +00:00
saveBaseInfo(info: datasetData | null) {
2023-11-02 01:56:14 +00:00
this.baseInfo = info
},
2024-01-08 09:53:50 +00:00
saveWebInfo(info: any) {
this.webInfo = info
},
2023-11-02 01:56:14 +00:00
saveDocumentsFile(file: UploadUserFile[]) {
this.documentsFiles = file
2023-11-24 11:02:52 +00:00
},
2023-11-30 08:35:52 +00:00
async asyncGetAllDateset(loading?: Ref<boolean>) {
2023-11-24 11:02:52 +00:00
return new Promise((resolve, reject) => {
datasetApi
2023-11-30 08:35:52 +00:00
.getAllDateset(loading)
2023-11-24 11:02:52 +00:00
.then((data) => {
resolve(data)
})
.catch((error) => {
reject(error)
})
})
2024-01-10 09:44:05 +00:00
},
async asyncGetDatesetDetail(id: string, loading?: Ref<boolean>) {
return new Promise((resolve, reject) => {
datasetApi
.getDatesetDetail(id, loading)
.then((data) => {
resolve(data)
})
.catch((error) => {
reject(error)
})
})
},
async asyncSyncDateset(id: string, sync_type: string, loading?: Ref<boolean>) {
return new Promise((resolve, reject) => {
datasetApi
2024-01-16 09:22:51 +00:00
.putSyncWebDateset(id, sync_type, loading)
2024-01-10 09:44:05 +00:00
.then((data) => {
resolve(data)
})
.catch((error) => {
reject(error)
})
})
2023-11-02 01:56:14 +00:00
}
}
})
export default useDatasetStore