123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- import { useI18n, i18n, getLocale } from "@/i18n";
- /**
- * 兼容自定主义按键为中文的处理器
- */
- const covertCustomButton = (data) => {
- return data.map((item) => {
- if ("type" in item) {
- if (item.type == "链接") item.type = "link";
- if (item.type == "电话") item.type = "phone";
- }
- if ("openMethod" in item) {
- if (item.openMethod == "弹出层打开") item.openMethod = "_self";
- if (item.openMethod == "新窗口打开") item.openMethod = "_target";
- }
- // console.log('当前转换数据!', item);
- return item;
- });
- };
- export default {
- namespaced: true,
- state() {
- return {
- // 场景列表
- list: [],
- //当前场景
- currentScene: {},
- //访问密码
- password: "",
- //场景数据
- metadata: {},
- //当前一级分组
- currentCatalogRoot: {},
- //当前二级分组
- currentSecondary: {},
- //二级分组
- secondaryList: {},
- //当前场景分组
- currentScenesList: {},
- //当时场景的版本
- fdkkCurrentVersion: "v4",
- // 存在开场动作并动作完成的flag
- isDoneforCover: false,
- currentSecondId: null,
- currentRootId: null,
- };
- },
- getters: {
- list: (state) => state.list,
- secondaryList: (state) => state.secondaryList,
- currentCatalogRoot: (state) => state.currentCatalogRoot,
- currentScenesList: (state) => state.currentScenesList,
- currentSecondId: (state) => state.currentSecondId,
- currentRootId: (state) => state.currentRootId,
- currentSecondary: (state) => state.currentSecondary,
- currentScene: (state) => state.currentScene,
- fdkkCurrentVersion: (state) => state.fdkkCurrentVersion,
- password: (state) => state.password,
- metadata: (state) => state.metadata,
- fdkkBGM: (state) => state.fdkkBGM,
- isDoneforCover: (state) => state.isDoneforCover,
- customLink: (state, getters, rootState, rootGetters) => {
- let metadata = getters.metadata;
- if (metadata.customButton) {
- let temp = JSON.parse(JSON.stringify(metadata.customButton));
- const res = covertCustomButton(temp);
- return res.find((item) => item.type == "link");
- }
- return {};
- },
- customTelephone: (state, getters, rootState, rootGetters) => {
- let metadata = getters.metadata;
- if (metadata.customButton) {
- // console.log(metadata.customButton);
- let temp = JSON.parse(JSON.stringify(metadata.customButton));
- const res = covertCustomButton(temp);
- return temp.find((item) => item.type == "phone");
- }
- return {};
- },
- musicURL: (state, getters, rootState, rootGetters) => {
- let metadata = getters.metadata;
- if (metadata.backgroundMusic && metadata.backgroundMusic.id) {
- return metadata.backgroundMusic.ossPath;
- }
- return null;
- },
- earthMask: (state, getters) => {
- const { earth } = getters.currentScene.customMask;
- return earth || null;
- },
- skyMask: (state, getters) => {
- const { sky } = getters.currentScene.customMask;
- return sky || null;
- },
- },
- mutations: {
- setData(state, payload) {
- for (let key in payload) {
- state[key] = payload[key];
- }
- },
- setScenes(state, payload) {
- state.list = payload;
- },
- setPassword(state, payload) {
- state.password = payload;
- },
- setFdkkCurrentVersion(state, payload) {
- state.fdkkCurrentVersion = payload;
- },
- // 设置当前场景
- setCurrentScene(state, payload) {
- if (payload.someData) {
- try {
- // someData旧数据有可能是字符串,要parse一下
- payload.someData = typeof payload.someData == "string" ? JSON.parse(payload.someData) : payload.someData;
- } catch (error) {}
- }
- state.currentScene = payload;
- this.commit("fdkk/setReset");
- },
- // 设置当前二级分组
- setCurrentSecondary(state, payload) {
- state.currentSecondary = payload;
- let arr = state.list.filter((item) => {
- return state.currentSecondary.id == item.category;
- });
- this.commit(
- "scene/setCurrentScenesList",
- arr.sort((a, b) => a.weight - b.weight)
- );
- },
- // 设置当前场景列表
- setCurrentScenesList(state, payload) {
- state.currentScenesList = payload;
- },
- // 设置当前一级分组
- setCurrentCatalogRoot(state, payload) {
- state.currentCatalogRoot = payload;
- let temp = [];
- payload.children &&
- payload.children.forEach((item) => {
- state.metadata.catalogs.forEach((sub) => {
- if (item == sub.id) {
- if (state.list.some((iii) => iii.category == sub.id)) {
- temp.push(sub);
- }
- }
- });
- });
- this.commit("scene/setSecondaryList", temp);
- },
- // 设置当前二级分组列表
- setSecondaryList(state, payload) {
- state.secondaryList = payload;
- if (payload.length > 0) {
- this.commit("scene/setCurrentSecondary", payload[0]);
- }
- },
- setMetaData(state, payload) {
- state.metadata = payload;
- document.title = payload.work.name;
- document.querySelector('meta[name="description"]').setAttribute("content", payload.work.description.replace(/<\/?[^>]+(>|$)/g, ""));
- document.querySelector('meta[name="cover"]').setAttribute("content", payload.work.icon);
- },
- setDoneforCover(state, payload) {
- state.isDoneforCover = payload;
- },
- },
- };
|