before store
This commit is contained in:
@@ -2,19 +2,19 @@ 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'
|
||||
import type { FileLink } from 'types/FileLink'
|
||||
|
||||
export const useFilesStore = defineStore('files', () => {
|
||||
|
||||
const files = ref<File[]>([])
|
||||
const files = ref<FileLink[]>([])
|
||||
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
|
||||
const { data } = await api.get('/project/' + currentProjectId.value + '/file')
|
||||
const filesAPI = data.data
|
||||
files.value.push(...filesAPI)
|
||||
isInit.value = true
|
||||
}
|
||||
@@ -34,6 +34,7 @@ export const useFilesStore = defineStore('files', () => {
|
||||
return (await response).data.data
|
||||
}
|
||||
|
||||
const getFiles = computed(() => files.value)
|
||||
|
||||
function fileById (id: number) {
|
||||
return files.value.find(el =>el.id === id)
|
||||
@@ -46,6 +47,7 @@ export const useFilesStore = defineStore('files', () => {
|
||||
reset,
|
||||
fileUrl,
|
||||
remove,
|
||||
getFiles,
|
||||
fileById
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user