|
@@ -1,5 +1,5 @@
|
|
|
import { ref } from 'vue'
|
|
|
-import { createTemploraryID, isTemploraryID } from './sys'
|
|
|
+import { createTemploraryID } from './sys'
|
|
|
import { autoSetModeCallback } from './sys'
|
|
|
import {
|
|
|
fetchGuides,
|
|
@@ -17,71 +17,34 @@ import {
|
|
|
recoverStoreItems
|
|
|
} from '@/utils'
|
|
|
|
|
|
-import type { GuidePath as SGuidePath, Guide as SGuide } from '@/api'
|
|
|
+import type { Guide as SGuide } from '@/api'
|
|
|
|
|
|
-export type GuidePath = LocalMode<SGuidePath, 'cover'>
|
|
|
-export type GuidePaths = GuidePath[]
|
|
|
-export type Guide = Omit<LocalMode<SGuide, 'cover'>, 'paths'> & { paths: GuidePaths }
|
|
|
+export type Guide = LocalMode<SGuide, 'cover'>
|
|
|
export type Guides = Guide[]
|
|
|
|
|
|
-
|
|
|
export const guides = ref<Guides>([])
|
|
|
|
|
|
export const createGuide = (guide: Partial<Guide> = {}): Guide => ({
|
|
|
id: createTemploraryID(),
|
|
|
title: `路径${guides.value.length + 1}`,
|
|
|
cover: '',
|
|
|
- paths: [],
|
|
|
...guide
|
|
|
})
|
|
|
|
|
|
-export const createGuidePath = (path: Partial<GuidePath> = {}): GuidePath => ({
|
|
|
- id: createTemploraryID(),
|
|
|
- cover: '',
|
|
|
- time: 1,
|
|
|
- speed: 1,
|
|
|
- position: {x: 0, y: 0, z: 0},
|
|
|
- target: {x: 0, y: 0, z: 0},
|
|
|
- ...path
|
|
|
-})
|
|
|
-
|
|
|
-
|
|
|
let bcGuides: Guides = []
|
|
|
export const getBackupGuides = () => bcGuides
|
|
|
export const backupGuides = () => {
|
|
|
- bcGuides = guides.value.map(guide => ({
|
|
|
- ...guide,
|
|
|
- paths: guide.paths.map(path => ({...path}))
|
|
|
- }))
|
|
|
+ bcGuides = guides.value.map(guide => ({...guide }))
|
|
|
}
|
|
|
|
|
|
export const transformGuide = async (guide: Guide): Promise<SGuide> => {
|
|
|
- let guideCover: string = ''
|
|
|
- const pathsCover: string[] = []
|
|
|
-
|
|
|
- const uploadGuideCover = uploadFile(guide.cover)
|
|
|
- .then(cover => guideCover = cover)
|
|
|
- const uploadPathsCver = guide.paths.map((path, index) =>
|
|
|
- uploadFile(path.cover)
|
|
|
- .then(cover => pathsCover[index] = cover)
|
|
|
- )
|
|
|
-
|
|
|
- await Promise.all([uploadGuideCover, ...uploadPathsCver])
|
|
|
- return {
|
|
|
- ...guide,
|
|
|
- paths: guide.paths.map((path, i) => ({...path, cover: pathsCover[i]})),
|
|
|
- cover: guideCover
|
|
|
- }
|
|
|
+ const guideCover = await uploadFile(guide.cover)
|
|
|
+ return { ...guide, cover: guideCover }
|
|
|
}
|
|
|
|
|
|
export const recoverGuides = recoverStoreItems(guides, getBackupGuides)
|
|
|
export const addGuide = addStoreItem(guides, postAddGuide, transformGuide)
|
|
|
-export const updateGuide = updateStoreItem(guides, (guide) => {
|
|
|
- return postUpdateGuide({
|
|
|
- ...guide,
|
|
|
- paths: guide.paths.map(path => ({...path, id: isTemploraryID(path.id) ? undefined : path.id})) as any
|
|
|
- })
|
|
|
-}, transformGuide)
|
|
|
+export const updateGuide = updateStoreItem(guides, postUpdateGuide, transformGuide)
|
|
|
export const deleteGuide = deleteStoreItem(guides, guide => postDeleteGuide(guide.id))
|
|
|
export const initialGuides = fetchStoreItems(guides, fetchGuides, backupGuides)
|
|
|
export const saveGuides = saveStoreItems(
|