import Vue from "vue"; import { i18n } from "@/lang"; import { saveBaseWorkInfo } from "@/api"; import { deepClone, isSameObject } from "@/utils/other.js"; import { $waiting } from "@/components/shared/loading"; let vue = new Vue(); export default { namespaced: true, state() { return { sceneList: [], baseInfo: null, }; }, getters: { sceneList: (state) => { return state.sceneList; }, baseInfo: (state, getters, rootState, rootGetters) => { if (state?.baseInfo?.navigationTrees) { state.sceneList = []; state.baseInfo.navigationTrees.forEach((one_tree) => { if (one_tree.type == "group" && one_tree.children.length) { one_tree.children.forEach((two_tree) => { if (two_tree.type == "group" && two_tree.children.length) { two_tree.children.forEach((scene) => { state.sceneList.push(scene); }); } else if (two_tree.type == "pano" || two_tree.type == "4dkk") { state.sceneList.push(two_tree); } }); } }); } // console.error("11111", state.sceneList); // if (rootState.scene.currentScene) { // let currentScene = state.sceneList.find((item) => item.id == rootState.scene.currentScene.id || item.sid == rootState.scene.currentScene.id); // if (currentScene) { // this.commit("scene/setCurrentScene", currentScene); // } // } return state.baseInfo; }, }, mutations: { initDefaultData(state, payload) { let forArr = ["workCustomMaskList", "workVisualAngleList", "workExplanationList"]; // state.baseInfo.workVisualAngleList.forEach((item, index) => { // if (!state.sceneList.some((j_item) => item.navigationId == j_item.id || item.navigationId == j_item.sid)) { // console.error(index, "删除了"); // state.baseInfo.workVisualAngleList.splice(index, 1); // } // }); // setTimeout(() => { // console.error(state.sceneList); this.commit("screen/setVisualAngleList", { sceneList: state.sceneList, workVisualAngleList: state.baseInfo.workVisualAngleList }); this.commit("mask/setCustomMaskList", { sceneList: state.sceneList, workCustomMaskList: state.baseInfo.workCustomMaskList, workId: state.baseInfo.workId }); this.commit("explanation/setExplanationList", { sceneList: state.sceneList, workExplanationList: state.baseInfo.workExplanationList }); // }, 0); // if (state.sceneList.length) { // state.sceneList.forEach((item, index) => { // forArr.map((key) => { // let obj = {}; // state.baseInfo[key].forEach((key_item, key_index) => { // if (key == "workVisualAngleList" && item.id == key_item.navigationId || item.sid == key_item.navigationId ) { // key_item.icon = item.icon; // } // obj[key_item.navigationId] = key_item; // }); // if (obj[item.id]) { // console.error(key,1); // } else { // console.error(key,2); // switch (key) { // case "workCustomMaskList": // console.error("workCustomMaskList"); // state.baseInfo[key].push({ // data: { // earth: { // antidistorted: true, // fodderId: null, // icon: "", // isDelete: 0, // isShow: false, // navigationId: item.sid ? item.sid : item.id, // scale: 1, // type: "earth", // workId: state.baseInfo.workId, // }, // sky: { // antidistorted: true, // fodderId: null, // icon: "", // isDelete: 0, // isShow: true, // navigationId: item.sid ? item.sid : item.id, // scale: 1, // type: "sky", // workId: state.baseInfo.workId, // }, // }, // navigationId: item.sid ? item.sid : item.id, // }); // break; // case "workVisualAngleList": // state.baseInfo[key].push({ // hlookat: 0, // icon: item.icon, // // id: 0, // vlookat: 0, // vlookatmax: 90, // vlookatmin: -90, // workId: state.baseInfo.workId, // navigationId: item.sid ? item.sid : item.id, // }); // break; // case "workExplanationList": // console.error("workExplanationList"); // state.baseInfo[key].push({ // fodderId: null, // audioName: "", // audioUrl: "", // openByDefault: true, // navigationId: item.sid ? item.sid : item.id, // playRepeat: true, // }); // break; // } // } // // if (key == "workCustomMaskList") { // // let hasMask = false; // // state.baseInfo[key].forEach((mask_item, mask_index) => { // // if (mask_item.navigationId == item.id) { // // hasMask = true; // // } // // }); // // if (!hasMask) { // // state.baseInfo[key].push({ // // data: { // // earth: { // // antidistorted: true, // // fodderId: null, // // icon: "", // // isDelete: 0, // // isShow: false, // // navigationId: item.id, // // scale: 1, // // type: "earth", // // workId: state.baseInfo.workId, // // }, // // sky: { // // antidistorted: true, // // fodderId: null, // // icon: "", // // id: 7, // // isDelete: 0, // // isShow: true, // // navigationId: item.id, // // scale: 1, // // type: "sky", // // workId: state.baseInfo.workId, // // }, // // }, // // navigationId: item.id, // // }); // // } // // } // // if (key == "workVisualAngleList") { // // let hasVisual = false; // // state.baseInfo[key].forEach((visual_item, visual_index) => { // // if (visual_item.navigationId == item.id) { // // hasVisual = true; // // visual_item.icon = item.icon; // // } // // }); // // if (!hasVisual) { // // state.baseInfo[key].push({ // // hlookat: 0, // // icon: item.icon, // // // id: 0, // // vlookat: 0, // // vlookatmax: 90, // // vlookatmin: -90, // // workId: state.baseInfo.workId, // // navigationId: item.id, // // }); // // } // // } // // if(key=='workExplanationList'){ // // } // }); // }); // } // console.error(state.baseInfo["workVisualAngleList"]); }, initbaseInfo(state, payload) { // console.error('initbaseInfo') let data = { firstScene: null, workVisualAngleList: [], navigationTrees: [], workCustomMaskList: [], workId: "", work: { description: "", icon: "", id: "", isAuto: 0, name: "", password: "", }, workBackgroundMusic: null, workCoverType: { coverImageInWay: 0, coverImageOrder: "", coverImgBac: "", coverMo: "", coverMoLoc: "", coverPc: "", coverPcLoc: "", coverSelect: "img", coverVideoBac: "", coverVideoControl: 0, coverVideoInWay: 0, cover_mo_id: 0, cover_pc_id: 0, id: 0, imgColorSelec: "", isShowCover: 0, videoBacImg: "", videoColorSelec: "", videoMo: "", videoMoIcon: "", videoMoId: 0, videoMoLoc: "", videoPc: "", videoPcIcon: "", videoPcLoc: "", video_pc_id: 0, workId: "", }, workLogo: { id: 0, isLogo: 0, logo: "", logoChange: false, workId: "", }, workOpeningAnimation: { id: 0, isShowOpeningAnimation: false, openingAnimationType: 0, workId: "", }, workOpeningTip: { appIcon: "", appIconId: "", id: 0, isRemind: 0, pcIcon: "", pcIconId: "", remindTime: 0, workId: "", }, workCustomButtonList: [ { id: 0, isShow: 0, name: "", openMethod: "", type: "", value: "", workId: "", }, ], workExplanationList: [], workHotList: [], }; if (!state.baseInfo) { state.baseInfo = data; // state.baseInfo = {}; } for (let key in state.baseInfo) { if (state.baseInfo.hasOwnProperty(key)) { if (payload[key] == null) { state.baseInfo[key] = data[key]; } else { state.baseInfo[key] = payload[key]; } } } }, setData(state, payload) { // this.commit("base/initbaseInfo"); for (let key in payload) { if (state.baseInfo.hasOwnProperty(key)) { state.baseInfo[key] = payload[key]; } } }, updateBaseInfo(state, payload) { for (let key in payload) { state.baseInfo[key] = payload[key]; // if (key == "navigationTrees") { // console.error(state.sceneList); // } } }, }, actions: { save({ commit, state, rootState }) { // return new Promise((resolve,reject)=>{}) return new Promise((resolve, reject) => { saveBaseWorkInfo( state.baseInfo, (res) => { // vue.$msg.success(i18n.t("gather.save_done")); // document.title = this.info.name; document.title = state.baseInfo.work.name || i18n.t("gather.no_title"); $waiting.hide(); // this.getInfo(); // this.$store.commit("UpdateIsShowState", true); // this.commit("TakeInfoSnapShotAtSave"); resolve(res); }, (rej) => { reject(rej); } ); }); }, }, };