123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- import { defineStore } from 'pinia'
- import {
- fetchProject,
- uploadProjectBimScene,
- relaceProjectScenes,
- SceneType,
- deleteProject,
- finishProject,
- updateProject,
- deleteProjectBimScene,
- BimStatus,
- deleteProjectScene,
- updateProjectBimSceneName
- } from '@/api'
- import type {
- Project,
- Scene,
- BimUploadData,
- UpdateProjectData,
- Bim
- } from '@/api'
- export const BinType = Symbol('bin')
- export const binTypeDesc = 'bin'
- export type { Project, BimUploadData, Bim }
- export type ProjectScene = Omit<Scene, 'type' | 'num' | 'status'> &
- (
- | {
- type: Scene['type']
- status: Scene['status']
- num: Scene['num']
- }
- | {
- type: typeof BinType
- status: BimStatus
- }
- )
- export type SelectTypeScenes = {
- [SceneType.SWKJ]: Scene['num'][]
- [SceneType.SWKK]: Scene['num'][]
- [SceneType.SWSS]: Scene['num'][]
- }
- type CurrentState = null | Project
- export const useProject = defineStore('project', {
- state: () => ({
- current: null as CurrentState
- }),
- getters: {
- scenes: state => {
- const scenes: ProjectScene[] = state.current?.sceneList || []
- const bimData = state.current?.bimData
- if (bimData) {
- return [
- {
- id: bimData.bimId,
- name: bimData.bimName,
- title: bimData.bimName,
- sceneName: bimData.bimName,
- thumb: bimData.bimOssFilePath,
- createTime: bimData.createTime,
- type: BinType,
- status: bimData.bimStatus,
- phone: ''
- },
- ...scenes
- ]
- } else {
- return scenes
- }
- },
- isSelf: state => (id?: Project['projectId']) =>
- state.current?.projectId === id
- },
- actions: {
- async setCurrent(id: Project['projectId']) {
- this.current = await fetchProject(id)
- },
- async updateCurrent(id?: Project['projectId']) {
- if ((id = id || this.current?.projectId)) {
- this.isSelf(id) && (await this.setCurrent(id))
- }
- },
- async delete(id?: Project['projectId']) {
- if ((id = id || this.current?.projectId)) {
- await deleteProject(id)
- await this.updateCurrent(id)
- }
- },
- async update(data: PartialPart<UpdateProjectData, 'projectId'>) {
- const id = data.projectId || this.current?.projectId
- if (id) {
- await updateProject({
- ...data,
- projectId: id
- })
- await this.updateCurrent(id)
- }
- },
- async finish(id?: Project['projectId']) {
- if ((id = id || this.current?.projectId)) {
- await finishProject(id)
- await this.updateCurrent(id)
- }
- },
- async addBim(data: BimUploadData, id?: Project['projectId']) {
- if ((id = id || this.current?.projectId)) {
- await uploadProjectBimScene(id, data)
- await this.updateCurrent(id)
- }
- },
- async updateBimName(bimName: Bim['bimName'], bimId?: Bim['bimId']) {
- if ((bimId = bimId || this.current?.bimData?.bimId)) {
- await updateProjectBimSceneName({ bimId, bimName })
- this.current?.bimData?.bimId === bimId && (await this.updateCurrent())
- }
- },
- async deleteBim(bimId?: Bim['bimId']) {
- if ((bimId = bimId || this.current?.bimData?.bimId)) {
- await deleteProjectBimScene(bimId)
- this.current?.bimData?.bimId === bimId && (await this.updateCurrent())
- }
- },
- async replaceScenes(
- typeScenes: SelectTypeScenes,
- id?: Project['projectId']
- ) {
- if ((id = id || this.current?.projectId)) {
- const sceneNumParam = Object.entries(typeScenes).map(
- ([type, nums]) => ({
- type: Number(type) as SceneType,
- numList: nums
- })
- )
- await relaceProjectScenes({ id, sceneNumParam })
- await this.updateCurrent(id)
- }
- },
- async deleteScene(num: Scene['num'], id?: Project['projectId']) {
- if ((id = id || this.current?.projectId)) {
- await deleteProjectScene({ projectId: id, num })
- await this.updateCurrent(id)
- }
- }
- }
- })
- export {
- ProjectStatus,
- ProjectStatusDesc,
- BimStatus,
- BimStatusDesc
- } from '@/api'
|