bill 3 سال پیش
والد
کامیت
b381ee425c

+ 0 - 2
src/api/constant.ts

@@ -1,5 +1,3 @@
-import { params } from '@/env'
-
 export enum ResCode {
   TOKEN_INVALID = 4008,
   SUCCESS = 0

+ 69 - 0
src/api/guide-path.ts

@@ -0,0 +1,69 @@
+import axios from './instance'
+import { params } from '@/env'
+import { 
+  GUIDE_PATH_LIST,
+  INSERT_GUIDE_PATH,
+  UPDATE_GUIDE_PATH,
+  DELETE_GUIDE_PATH,
+} from './constant'
+
+import type { Guide } from './guide'
+
+interface ServiceGuidePath {
+  guidePathId: number,
+  guideId: number,
+  position: string
+  target: string
+  time: number
+  speed: number
+  cover: string
+}
+
+export interface GuidePath {
+  id: string,
+  guideId: Guide['id'],
+  position: SceneLocalPos
+  target: SceneLocalPos
+  time: number
+  speed: number
+  cover: string
+}
+
+export type GuidePaths = GuidePath[]
+
+const serviceToLocal = (servicePath: ServiceGuidePath): GuidePath => ({
+  ...servicePath,
+  guideId: servicePath.guideId.toString(),
+  target: JSON.parse(servicePath.target),
+  position: JSON.parse(servicePath.position),
+  id: servicePath.guidePathId.toString(),
+})
+
+const localToService = (path: GuidePath): ServiceGuidePath => ({
+  ...path,
+  guideId: Number(path.guideId),
+  target: JSON.stringify(path.target),
+  position: JSON.stringify(path.position),
+  guidePathId: Number(path.id),
+})
+
+export const fetchGuidePaths = async (guideId: Guide['id']) => {
+  const guides = await axios.get<ServiceGuidePath[]>(GUIDE_PATH_LIST, { params: { guideId: guideId } })
+  return guides.map(serviceToLocal)
+}
+
+export const postAddGuidePath = async (path: GuidePath) => {
+  const addData = { ...localToService(path), caseId: params.caseId, fusionGuideId: undefined }
+   const serviceData = await axios.post<ServiceGuidePath>(INSERT_GUIDE_PATH, addData)
+   return serviceToLocal(serviceData)
+}
+
+export const postUpdateGuidePath = async (guide: GuidePath) => {
+  return axios.post<undefined>(UPDATE_GUIDE_PATH, { ...localToService(guide)})
+}
+
+export const postDeleteGuidePath = (id: GuidePath['id']) => {
+  return axios.post<undefined>(DELETE_GUIDE_PATH, { fusionGuideId: Number(id) })
+}
+
+  

+ 6 - 43
src/api/guide.ts

@@ -7,74 +7,37 @@ import {
   DELETE_GUIDE,
 } from './constant'
 
-
- interface ServiceGuidePath {
-  id: number,
-  position: SceneLocalPos
-  target: SceneLocalPos
-  time: number
-  speed: number
-  cover: string
-}
-
 interface ServiceGuide {
-  id: number
+  fusionGuideId: number
   cover: string
   title: string
-  paths: {
-    id: number,
-    position: SceneLocalPos
-    target: SceneLocalPos
-    time: number
-    speed: number
-    cover: string
-  }[]
-}
-export interface GuidePath {
-  id: string,
-  position: SceneLocalPos
-  target: SceneLocalPos
-  time: number
-  speed: number
-  cover: string
 }
 
 export interface Guide {
   id: string
   cover: string
   title: string
-  paths: GuidePath[]
 }
 
 export type Guides = Guide[]
-export type GuidePaths = GuidePath[]
 
 const serviceToLocal = (serviceGuide: ServiceGuide): Guide => ({
   ...serviceGuide,
-  id: serviceGuide.id.toString(),
-  paths: serviceGuide.paths.map(path => ({...path, id: path.id.toString()}))
+  id: serviceGuide.fusionGuideId.toString(),
 })
 
 const localToService = (guide: Guide): ServiceGuide => ({
   ...guide,
-  id: Number(guide.id),
-  paths: guide.paths.map(path => ({...path, id: Number(path.id)}))
+  fusionGuideId: Number(guide.id),
 })
 
-
 export const fetchGuides = async () => {
-  const guides = await axios.post<ServiceGuide[]>(GUIDE_LIST, {})
+  const guides = await axios.get<ServiceGuide[]>(GUIDE_LIST, { params: { caseId: params.caseId } })
   return guides.map(serviceToLocal)
 }
 
-
 export const postAddGuide = async (guide: Guide) => {
-  const addData = {
-    ...guide,
-    fusionId: params.fushId,
-    id: undefined,
-    paths: guide.paths.map(path => ({...path, id: undefined}))
-   }
+  const addData = { ...localToService(guide), caseId: params.caseId, fusionGuideId: undefined }
    const serviceData = await axios.post<ServiceGuide>(INSERT_GUIDE, addData)
    return serviceToLocal(serviceData)
 }
@@ -84,7 +47,7 @@ export const postUpdateGuide = async (guide: Guide) => {
 }
 
 export const postDeleteGuide = (id: Guide['id']) => {
-  return axios.post<undefined>(DELETE_GUIDE, { ids: [id.toString()] })
+  return axios.post<undefined>(DELETE_GUIDE, { fusionGuideId: Number(id) })
 }
 
   

+ 2 - 1
src/api/index.ts

@@ -26,4 +26,5 @@ export * from './tagging'
 export * from './tagging-style'
 export * from './tagging-position'
 export * from './guide'
-export * from './sys'
+export * from './guide-path'
+export * from './sys'

+ 6 - 6
src/api/tagging-position.ts

@@ -10,7 +10,7 @@ import type { FuseModel } from './fuse-model'
 import type { Tagging } from './tagging'
 
 interface ServicePosition {
-  "id": number,
+  "tagPointId": number,
   "tagId": number,
   "modelId": number
   "tagPoint": string,
@@ -27,14 +27,14 @@ export type TaggingPositions = TaggingPosition[]
 
 
 const serviceToLocal = (position: ServicePosition, taggingId?: Tagging['id']): TaggingPosition => ({
-  id: position.id.toString(),
-  modelId: position.modelId.toString(),
+  id: position.tagPointId.toString(),
+  modelId: position.modelId ? position.modelId.toString() : '123123',
   taggingId: taggingId || position.tagId.toString(),
   localPos: JSON.parse(position.tagPoint)
 })
 
-const localToService = (position: TaggingPosition, update = false): PartialProps<ServicePosition, 'id'> => ({
-  "id": update ? Number(position.id) : undefined,
+const localToService = (position: TaggingPosition, update = false): PartialProps<ServicePosition, 'tagPointId'> => ({
+  "tagPointId": update ? Number(position.id) : undefined,
   "tagId": Number(position.taggingId),
   "modelId": Number(position.modelId),
   "tagPoint": JSON.stringify(position.localPos),
@@ -42,7 +42,7 @@ const localToService = (position: TaggingPosition, update = false): PartialProps
 
 
 export const fetchTaggingPositions = async (taggingId: Tagging['id']) => {
-  const positions = await axios.post<ServicePosition[]>(`${TAGGING_POINT_LIST}${taggingId}`, {})
+  const positions = await axios.get<ServicePosition[]>(`${TAGGING_POINT_LIST}`, {params: { tagId: taggingId } })
   return positions.map(position => serviceToLocal(position, taggingId))
 }
 

+ 1 - 1
src/sdk/sdk.ts

@@ -1,7 +1,7 @@
 import cover from './cover'
 import { loadLib } from '@/utils'
 
-import type { FuseModelAttrs, FuseModel, GuidePath, GuidePaths } from '@/store'
+import type { FuseModelAttrs, FuseModel, GuidePath } from '@/store'
 import type { Emitter } from 'mitt'
 
 

+ 77 - 0
src/store/guide-path.ts

@@ -0,0 +1,77 @@
+import { ref } from 'vue'
+import { autoSetModeCallback, createTemploraryID } from './sys'
+import { 
+  fetchGuidePaths,
+  postAddGuidePath,
+  postUpdateGuidePath,
+  postDeleteGuidePath,
+  uploadFile,
+} from '@/api'
+import { 
+  deleteStoreItem, 
+  addStoreItem, 
+  updateStoreItem, 
+  saveStoreItems,
+  recoverStoreItems
+} from '@/utils'
+
+import type { GuidePath as SGuidePath } from '@/api'
+import type { Guide } from './guide'
+
+export type GuidePath = LocalMode<SGuidePath, 'cover'>
+export type GuidePaths = GuidePath[]
+
+
+export const guidePaths = ref<GuidePaths>([])
+export const getGuidePaths = (guide: Guide) => 
+  guidePaths.value.filter(path => path.guideId === guide.id)
+
+export const createGuidePath = (path: Partial<GuidePath> = {}): GuidePath => ({
+  id: createTemploraryID(),
+  guideId: '',
+  cover: '',
+  time: 1,
+  speed: 1,
+  position: {x: 0, y: 0, z: 0},
+  target: {x: 0, y: 0, z: 0},
+  ...path
+})
+
+
+let bcPaths: GuidePaths = []
+export const getBackupGuidePaths = () => bcPaths
+export const backupGuidePaths = () => {
+  bcPaths = guidePaths.value.map(path => ({ ...path }))
+}
+
+export const transformGuidePath = async (path: GuidePath): Promise<SGuidePath> => {
+  const cover: string = await uploadFile(path.cover)
+  return { ...path, cover }
+}
+
+export const recoverGuidePaths = recoverStoreItems(guidePaths, getBackupGuidePaths)
+export const addGuidePath = addStoreItem(guidePaths, postAddGuidePath, transformGuidePath)
+export const updateGuidePath = updateStoreItem(guidePaths, postUpdateGuidePath, transformGuidePath)
+export const deleteGuidePath = deleteStoreItem(guidePaths, path => postDeleteGuidePath(path.id))
+export const initialGuidePathsByGuide = async (guide: Guide) => {
+  const paths = await fetchGuidePaths(guide.id)
+  guidePaths.value = guidePaths.value
+    .filter(path => path.guideId !== guide.id)
+    .concat(paths)
+  backupGuidePaths()
+}
+
+export const saveGuidePaths = saveStoreItems(
+  guidePaths,
+  getBackupGuidePaths,
+  {
+    add: addGuidePath,
+    update: updateGuidePath,
+    delete: deleteGuidePath,
+  }
+)
+export const autoSaveGuidePaths = autoSetModeCallback(guidePaths, {
+  backup: backupGuidePaths,
+  recovery: recoverGuidePaths,
+  save: saveGuidePaths,
+})

+ 7 - 44
src/store/guide.ts

@@ -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(

+ 2 - 1
src/store/index.ts

@@ -14,7 +14,7 @@ export const initialStore = async () => {
     initialFuseModels(),
     initialTaggingStyles(),
     initialTaggings(),
-    // initialGuides()
+    initialGuides()
   ])
   try {
     loaded.value = true
@@ -32,4 +32,5 @@ export * from './fuse-model'
 export * from './tagging'
 export * from './tagging-style'
 export * from './guide'
+export * from './guide-path'
 export * from './tagging-positions'

+ 3 - 1
src/store/tagging-positions.ts

@@ -42,7 +42,9 @@ export const backupTaggingPositions = () => {
 
 export const initTaggingPositionsByTagging = async (tagging: Tagging) => {
   const positions = await fetchTaggingPositions(tagging.id)
-  taggingPositions.value.push(...positions)
+  taggingPositions.value = taggingPositions.value
+    .filter(position => position.taggingId !== tagging.id)
+    .concat(positions)
   backupTaggingPositions()
 }
 

+ 1 - 1
src/store/tagging.ts

@@ -86,7 +86,7 @@ export const updateTagging = updateStoreItem(taggings, postUpdateTagging, transf
 export const deleteTagging = deleteStoreItem(taggings, tagging => postDeleteTagging(tagging.id))
 export const initialTaggings = fetchStoreItems(taggings, async () => {
   const taggings = await fetchTaggings()
-  // await Promise.all(taggings.map(initTaggingPositionsByTagging))
+  await Promise.all(taggings.map(initTaggingPositionsByTagging))
   return taggings
 }, backupTaggings)
 export const saveTaggings = saveStoreItems(

+ 3 - 6
src/views/guide/edit-paths.vue

@@ -85,7 +85,7 @@
 <script setup lang="ts">
 import { loadPack, togetherCallback, getFileUrl, asyncTimeout } from '@/utils'
 import { sdk, playSceneGuide, pauseSceneGuide, isScenePlayIng } from '@/sdk'
-import { createGuidePath, isTemploraryID, useAutoSetMode, guides } from '@/store'
+import { createGuidePath, isTemploraryID, useAutoSetMode, guides, getGuidePaths } from '@/store'
 import { Dialog, Message } from 'bill/index'
 import { useViewStack } from '@/hook'
 import { nextTick, ref, toRaw, watchEffect } from 'vue'
@@ -95,7 +95,7 @@ import type { Guide, GuidePaths, GuidePath } from '@/store'
 import type { CalcPathProps } from '@/sdk'
 
 const props = defineProps< { data: Guide }>()
-const paths = ref<GuidePaths>([...props.data.paths])
+const paths = ref<GuidePaths>(getGuidePaths(props.data))
 const current = ref<GuidePath>(paths.value[0])
 
 const updatePathInfo = (index: number, calcInfo: CalcPathProps[1]) => {
@@ -122,7 +122,6 @@ useAutoSetMode(paths, {
       Dialog.alert('无法保存空路径导览!')
       throw '无法保存空路径导览!'
     }
-    props.data.paths = paths.value
     props.data.cover = paths.value[0].cover
     if (isTemploraryID(props.data.id)) {
       guides.value.push(props.data)
@@ -165,9 +164,7 @@ const deletePath = async (path: GuidePath, fore: boolean = false) => {
 
 const deleteAll = async () => {
   if (await Dialog.confirm('确定要清空画面吗?')) {
-    while (paths.value.length) {
-      deletePath(paths.value[0], true)
-    }
+    paths.value.length = 0
     current.value = paths.value[0]
   }
 }

+ 2 - 2
src/views/guide/index.vue

@@ -13,7 +13,7 @@
         v-for="guide in guides" 
         :key="guide.id" 
         :guide="guide" 
-        @play="playSceneGuide(guide.paths)"
+        @play="playSceneGuide(getGuidePaths(guide))"
         @edit="edit(guide)"
         @delete="deleteGuide(guide)"
       />
@@ -27,7 +27,7 @@
 
 <script lang="ts" setup>
 import { RightFillPano } from '@/layout'
-import { guides, Guide, createGuide, enterEdit, sysBus, autoSaveGuides } from '@/store'
+import { guides, Guide, createGuide, enterEdit, sysBus, autoSaveGuides, getGuidePaths } from '@/store'
 import { ref } from 'vue';
 import GuideSign from './sign.vue'
 import EditPaths from './edit-paths.vue'

+ 5 - 4
src/views/guide/sign.vue

@@ -7,7 +7,7 @@
           type="preview" 
           class="icon" 
           ctrl 
-          @click="emit('play')" v-if="guide.paths.length" 
+          @click="emit('play')" v-if="paths.length" 
         />
       </div>
       <div>
@@ -25,12 +25,12 @@
 </template>
 
 <script setup lang="ts">
-import { Guide } from '@/store'
+import { Guide, getGuidePaths } from '@/store'
 import { getFileUrl } from '@/utils'
 import { getResource } from '@/env'
+import { computed } from 'vue';
 
-
-defineProps<{ guide: Guide }>()
+const props = defineProps<{ guide: Guide }>()
 const emit = defineEmits<{ 
   (e: 'delete'): void 
   (e: 'play'): void 
@@ -45,6 +45,7 @@ const actions = {
   edit: () => emit('edit'),
   delete: () => emit('delete')
 }
+const paths = computed(() => getGuidePaths(props.guide))
 
 </script>
 

+ 3 - 3
src/views/merge/index.vue

@@ -50,9 +50,9 @@ useViewStack(() => {
   active.value = true
   return () => active.value = false
 })
-const opacityOption = { min: 0.01, max: 1, step: 0.01, }
-const bottomOption = { min: 1, max: 100, step: 1, }
-const scaleOption = { min: 0.01, max: 1, step: 0.01, }
+const opacityOption = { min: 0, max: 100, step: 0.01, ctrl: false }
+const bottomOption = { min: -30, max: 70, step: 0.1, ctrl: false }
+const scaleOption = { min: 0, max: 200, step: 0.01, ctrl: false }
 const actionItems: ActionsProps['items'] = [
   {
     icon: 'move',