explanation.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import Vue from "vue";
  2. import { i18n } from "@/lang";
  3. import { explanationSave } from "@/api";
  4. import { $waiting } from "@/components/shared/loading";
  5. import { forEach } from "lodash";
  6. let vue = new Vue();
  7. export default {
  8. namespaced: true,
  9. state() {
  10. return {
  11. workExplanationList: [],
  12. };
  13. },
  14. getters: {
  15. workExplanationList: (state) => state.workExplanationList,
  16. },
  17. mutations: {
  18. setExplanationList(state, payload) {
  19. let { sceneList, workExplanationList } = payload;
  20. state.workExplanationList = workExplanationList;
  21. console.error("setExplanationList", sceneList, state.workExplanationList);
  22. sceneList.forEach((s_item, s_index) => {
  23. if (!state.workExplanationList.some((w_item) => s_item.id == w_item.navigationId || s_item.sid == w_item.navigationId)) {
  24. console.error(s_index, "不存在");
  25. state.workExplanationList.push({
  26. fodderId: null,
  27. audioName: "",
  28. audioUrl: "",
  29. openByDefault: true,
  30. navigationId: s_item.sid ? s_item.sid : s_item.id,
  31. playRepeat: true,
  32. });
  33. } else {
  34. // console.error(s_index, "存在");
  35. let idx = state.workExplanationList.findIndex((idx_item) => s_item.id == idx_item.navigationId || s_item.sid == idx_item.navigationId);
  36. // console.error("idx", idx, s_item.sid, s_item.id);
  37. if (idx >= 0 && s_item.sid && typeof s_item.id == "number") {
  38. // console.error(s_index, idx, "接口保存后的数据");
  39. state.workExplanationList[idx].navigationId = s_item.id;
  40. }
  41. }
  42. });
  43. state.workExplanationList.forEach((item, index) => {
  44. if (!sceneList.some((j_item) => item.navigationId == j_item.id || item.navigationId == j_item.sid)) {
  45. // console.error(index, "删除了");
  46. state.workExplanationList.splice(index, 1);
  47. }
  48. });
  49. console.error(state.workExplanationList);
  50. },
  51. setData(state, payload) {},
  52. },
  53. actions: {
  54. save({ commit, state, rootState }) {
  55. // console.error(rootState.base.baseInfo.workExplanationList);
  56. // let list = [];
  57. // if (rootState.base.sceneList.length != rootState.base.baseInfo.workExplanationList.length) {
  58. // list = rootState.base.baseInfo.workExplanationList.filter((item1) => rootState.base.sceneList.some((item2) => item2.id === item1.navigationId));
  59. // } else {
  60. // list = rootState.base.baseInfo.workExplanationList;
  61. // }
  62. console.error(state.workExplanationList);
  63. // $waiting.hide();
  64. // return;
  65. explanationSave(
  66. {
  67. list: state.workExplanationList,
  68. },
  69. () => {
  70. vue.$msg.success(i18n.t("gather.save_done"));
  71. $waiting.hide();
  72. this.commit("base/updateBaseInfo", { workExplanationList: state.workExplanationList });
  73. },
  74. () => {}
  75. );
  76. },
  77. },
  78. };