client initial commit
This commit is contained in:
parent
b5f98baa2b
commit
dd1547d7c2
70 changed files with 18446 additions and 0 deletions
246
Services/client/src/stores/tree-data.ts
Normal file
246
Services/client/src/stores/tree-data.ts
Normal file
|
|
@ -0,0 +1,246 @@
|
|||
import { ref } from 'vue'
|
||||
import { defineStore } from 'pinia'
|
||||
import { useLoader } from '@/stores/loader'
|
||||
import HttpService from '@/services/HttpService'
|
||||
|
||||
const axiosClient = HttpService.getAxiosClient()
|
||||
const apiEndpoint: string = import.meta.env.VITE_API_ENDPOINT
|
||||
|
||||
export interface EhrFolder {
|
||||
pathname: string
|
||||
name: string
|
||||
createdAt: string
|
||||
createdBy: string
|
||||
}
|
||||
|
||||
export interface EhrFile {
|
||||
pathname: string
|
||||
|
||||
fileName: string
|
||||
fileSize: string
|
||||
fileType: string
|
||||
|
||||
title: string
|
||||
description: string
|
||||
category: string[]
|
||||
keyword: string[]
|
||||
|
||||
updatedAt: string
|
||||
updatedBy: string
|
||||
createdAt: string
|
||||
createdBy: string
|
||||
}
|
||||
|
||||
export interface TreeDataFolder {
|
||||
pathname: string
|
||||
name: string
|
||||
status: boolean
|
||||
folder: TreeDataFolder[]
|
||||
file?: EhrFile[]
|
||||
}
|
||||
|
||||
export const useTreeDataStore = defineStore('changeCabinet', () => {
|
||||
const loader = useLoader()
|
||||
|
||||
const data = ref<TreeDataFolder[]>([])
|
||||
const currentFolder = ref<TreeDataFolder[]>([])
|
||||
const currentFile = ref<EhrFile[]>([])
|
||||
const currentPath = ref<string>('')
|
||||
const currentDept = ref<number>(0)
|
||||
|
||||
async function getCabinet() {
|
||||
const res = await axiosClient.get<EhrFolder[]>(`${apiEndpoint}cabinet`)
|
||||
|
||||
data.value = currentFolder.value = res.data.map((v) => ({
|
||||
...v,
|
||||
status: false,
|
||||
folder: [],
|
||||
}))
|
||||
}
|
||||
|
||||
async function getFolder(pathname: string, updateStatus = true) {
|
||||
loader.show()
|
||||
|
||||
const pathArray: string[] = pathname.split('/').filter(Boolean)
|
||||
|
||||
currentDept.value = pathArray.length
|
||||
|
||||
if (pathArray.length >= 4) {
|
||||
currentFolder.value = []
|
||||
|
||||
await getFile(pathname)
|
||||
|
||||
let current: (typeof data.value)[number] | undefined
|
||||
current = data.value.find((v) => v.name === pathArray[0])
|
||||
if (current && updateStatus) current.status = true
|
||||
current = current?.folder.find((v) => v.name === pathArray[1])
|
||||
if (current && updateStatus) current.status = true
|
||||
current = current?.folder.find((v) => v.name === pathArray[2])
|
||||
if (current && updateStatus) current.status = true
|
||||
current = current?.folder.find((v) => v.name === pathArray[3])
|
||||
if (current && updateStatus) current.status = true
|
||||
|
||||
return loader.hide()
|
||||
}
|
||||
|
||||
let requestPath = 'cabinet'
|
||||
if (pathArray.length >= 1) requestPath += `/${pathArray[0]}/drawer`
|
||||
if (pathArray.length >= 2) requestPath += `/${pathArray[1]}/folder`
|
||||
if (pathArray.length >= 3) requestPath += `/${pathArray[2]}/subfolder`
|
||||
|
||||
currentPath.value = pathname
|
||||
|
||||
const res = await axiosClient.get<EhrFolder[]>(
|
||||
`${apiEndpoint}${requestPath}`
|
||||
)
|
||||
|
||||
const list = res.data.map((v) => ({
|
||||
...v,
|
||||
status: false,
|
||||
folder: [],
|
||||
}))
|
||||
|
||||
let current: (typeof data.value)[number] | undefined
|
||||
|
||||
if (pathArray.length >= 1) {
|
||||
current = data.value.find((v) => v.name === pathArray[0])
|
||||
if (current && updateStatus) {
|
||||
current.status = true
|
||||
}
|
||||
}
|
||||
|
||||
if (pathArray.length >= 2) {
|
||||
current = current?.folder.find((v) => v.name === pathArray[1])
|
||||
if (current && updateStatus) {
|
||||
current.status = true
|
||||
}
|
||||
}
|
||||
if (pathArray.length >= 3) {
|
||||
current = current?.folder.find((v) => v.name === pathArray[2])
|
||||
if (current && updateStatus) {
|
||||
current.status = true
|
||||
}
|
||||
}
|
||||
|
||||
if (current) current.folder = list
|
||||
|
||||
currentFolder.value = list
|
||||
|
||||
await getFile(pathname)
|
||||
|
||||
return loader.hide()
|
||||
}
|
||||
|
||||
async function getFile(pathname: string) {
|
||||
loader.show()
|
||||
|
||||
const pathArray: string[] = pathname.split('/').filter(Boolean)
|
||||
|
||||
if (pathArray.length <= 2) {
|
||||
currentFile.value = []
|
||||
return loader.hide()
|
||||
}
|
||||
|
||||
let requestPath = `cabinet/${pathArray[0]}/drawer/${pathArray[1]}`
|
||||
if (pathArray.length >= 3) requestPath += `/folder/${pathArray[2]}`
|
||||
if (pathArray.length >= 4) requestPath += `/subfolder/${pathArray[3]}`
|
||||
requestPath += '/file'
|
||||
|
||||
const res = await axiosClient.get<EhrFile[]>(`${apiEndpoint}${requestPath}`)
|
||||
|
||||
currentFile.value = res.data
|
||||
|
||||
return loader.hide()
|
||||
}
|
||||
|
||||
async function createFolder(name: string | undefined) {
|
||||
loader.show()
|
||||
|
||||
if (!name) return loader.hide()
|
||||
|
||||
const pathArray: string[] = currentPath.value.split('/').filter(Boolean)
|
||||
let requestPath = 'cabinet'
|
||||
if (pathArray.length >= 1) requestPath += `/${pathArray[0]}/drawer`
|
||||
if (pathArray.length >= 2) requestPath += `/${pathArray[1]}/folder`
|
||||
if (pathArray.length >= 3) requestPath += `/${pathArray[2]}/subfolder`
|
||||
|
||||
await axiosClient.post(`${apiEndpoint}${requestPath}`, {
|
||||
name,
|
||||
})
|
||||
|
||||
if (currentDept.value === 0) await getCabinet()
|
||||
else await getFolder(currentPath.value)
|
||||
|
||||
return loader.hide()
|
||||
}
|
||||
|
||||
async function editFolder(name: string | undefined, pathname: string) {
|
||||
loader.show()
|
||||
|
||||
if (!name) return loader.hide()
|
||||
|
||||
const pathArray: string[] = pathname.split('/').filter(Boolean)
|
||||
|
||||
let requestPath = 'cabinet'
|
||||
if (pathArray.length >= 1) requestPath += `/${pathArray[0]}`
|
||||
if (pathArray.length >= 2) requestPath += `/drawer/${pathArray[1]}`
|
||||
if (pathArray.length >= 3) requestPath += `/folder/${pathArray[2]}`
|
||||
if (pathArray.length >= 4) requestPath += `/subfolder/${pathArray[3]}`
|
||||
|
||||
await axiosClient.put(`${apiEndpoint}${requestPath}`, {
|
||||
name: name,
|
||||
})
|
||||
|
||||
if (currentDept.value === 0) await getCabinet()
|
||||
else await getFolder(currentPath.value)
|
||||
|
||||
return loader.hide()
|
||||
}
|
||||
|
||||
async function deleteFolder(pathname: string) {
|
||||
loader.show()
|
||||
|
||||
const pathArray: string[] = pathname.split('/').filter(Boolean)
|
||||
|
||||
let requestPath = 'cabinet'
|
||||
if (pathArray.length >= 1) requestPath += `/${pathArray[0]}`
|
||||
if (pathArray.length >= 2) requestPath += `/drawer/${pathArray[1]}`
|
||||
if (pathArray.length >= 3) requestPath += `/folder/${pathArray[2]}`
|
||||
if (pathArray.length >= 4) requestPath += `/subfolder/${pathArray[3]}`
|
||||
|
||||
await axiosClient.delete(`${apiEndpoint}${requestPath}`)
|
||||
|
||||
if (currentDept.value === 0) await getCabinet()
|
||||
else await getFolder(currentPath.value)
|
||||
|
||||
return loader.hide()
|
||||
}
|
||||
|
||||
async function gotoParent() {
|
||||
const pathname = currentPath.value.split('/').filter(Boolean)
|
||||
|
||||
pathname.pop()
|
||||
|
||||
if (pathname.length === 0) {
|
||||
const cabinet = currentFolder.value.find((v) => v.status === true)
|
||||
if (cabinet) {
|
||||
cabinet.status = false
|
||||
}
|
||||
}
|
||||
|
||||
await getFolder(pathname.join('/') + '/')
|
||||
}
|
||||
|
||||
return {
|
||||
data,
|
||||
currentFolder,
|
||||
currentFile,
|
||||
currentDept,
|
||||
getCabinet,
|
||||
getFolder,
|
||||
gotoParent,
|
||||
createFolder,
|
||||
deleteFolder,
|
||||
editFolder,
|
||||
}
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue