12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- import Vue from "vue";
- import { i18n } from "@/lang";
- import { explanationSave } from "@/api";
- import { $waiting } from "@/components/shared/loading";
- import { forEach } from "lodash";
- let vue = new Vue();
- export default {
- namespaced: true,
- state() {
- return {
- workExplanationList: [],
- };
- },
- getters: {
- workExplanationList: (state) => state.workExplanationList,
- },
- mutations: {
- setExplanationList(state, payload) {
- let { sceneList, workExplanationList } = payload;
- state.workExplanationList = workExplanationList;
- console.error("setExplanationList", sceneList, state.workExplanationList);
- sceneList.forEach((s_item, s_index) => {
- if (!state.workExplanationList.some((w_item) => s_item.id == w_item.navigationId || s_item.sid == w_item.navigationId)) {
- console.error(s_index, "不存在");
- state.workExplanationList.push({
- fodderId: null,
- audioName: "",
- audioUrl: "",
- openByDefault: true,
- navigationId: s_item.sid ? s_item.sid : s_item.id,
- playRepeat: true,
- });
- } else {
- // console.error(s_index, "存在");
- let idx = state.workExplanationList.findIndex((idx_item) => s_item.id == idx_item.navigationId || s_item.sid == idx_item.navigationId);
- // console.error("idx", idx, s_item.sid, s_item.id);
- if (idx >= 0 && s_item.sid && typeof s_item.id == "number") {
- // console.error(s_index, idx, "接口保存后的数据");
- state.workExplanationList[idx].navigationId = s_item.id;
- }
- }
- });
- state.workExplanationList.forEach((item, index) => {
- if (!sceneList.some((j_item) => item.navigationId == j_item.id || item.navigationId == j_item.sid)) {
- // console.error(index, "删除了");
- state.workExplanationList.splice(index, 1);
- }
- });
- console.error(state.workExplanationList);
- },
- setData(state, payload) {},
- },
- actions: {
- save({ commit, state, rootState }) {
- // console.error(rootState.base.baseInfo.workExplanationList);
- // let list = [];
- // if (rootState.base.sceneList.length != rootState.base.baseInfo.workExplanationList.length) {
- // list = rootState.base.baseInfo.workExplanationList.filter((item1) => rootState.base.sceneList.some((item2) => item2.id === item1.navigationId));
- // } else {
- // list = rootState.base.baseInfo.workExplanationList;
- // }
- console.error(state.workExplanationList);
- // $waiting.hide();
- // return;
- explanationSave(
- {
- list: state.workExplanationList,
- },
- () => {
- vue.$msg.success(i18n.t("gather.save_done"));
- $waiting.hide();
- this.commit("base/updateBaseInfo", { workExplanationList: state.workExplanationList });
- },
- () => {}
- );
- },
- },
- };
|