v1
This commit is contained in:
51
src/stores/files.ts
Normal file
51
src/stores/files.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { ref, computed } from 'vue'
|
||||
import { defineStore } from 'pinia'
|
||||
import { api } from 'boot/axios'
|
||||
import { useProjectsStore } from 'stores/projects'
|
||||
import type { File } from 'types/File'
|
||||
|
||||
export const useFilesStore = defineStore('files', () => {
|
||||
|
||||
const files = ref<File[]>([])
|
||||
const isInit = ref<boolean>(false)
|
||||
|
||||
const projectsStore = useProjectsStore()
|
||||
const currentProjectId = computed(() => projectsStore.currentProjectId)
|
||||
|
||||
async function init () {
|
||||
const response = await api.get('/project/' + currentProjectId.value + '/file')
|
||||
const filesAPI = response.data.data
|
||||
files.value.push(...filesAPI)
|
||||
isInit.value = true
|
||||
}
|
||||
|
||||
function reset () {
|
||||
files.value = []
|
||||
isInit.value = false
|
||||
}
|
||||
|
||||
async function fileUrl (fileId: number) {
|
||||
const response = api.get('/project/' + currentProjectId.value + '/file/' + fileId)
|
||||
return (await response).data.data
|
||||
}
|
||||
|
||||
async function remove (fileId: number) {
|
||||
const response = api.delete('/project/' + currentProjectId.value + '/file/' + fileId)
|
||||
return (await response).data.data
|
||||
}
|
||||
|
||||
|
||||
function fileById (id: number) {
|
||||
return files.value.find(el =>el.id === id)
|
||||
}
|
||||
|
||||
return {
|
||||
files,
|
||||
isInit,
|
||||
init,
|
||||
reset,
|
||||
fileUrl,
|
||||
remove,
|
||||
fileById
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user