index.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { defineStore } from 'pinia';
  2. const appStore = defineStore('app', {
  3. state: () => ({
  4. // 场景列表
  5. list: [],
  6. //当前场景
  7. currentScene: {},
  8. //场景数据
  9. metadata: {},
  10. //当前一级分组
  11. currentCatalogRoot: {},
  12. //当前二级分组
  13. currentSecondary: {},
  14. //二级分组
  15. secondaryList: {},
  16. //当前场景分组
  17. currentScenesList: {},
  18. // 是否隐藏
  19. listIsShow: true
  20. }),
  21. getters: {},
  22. actions: {
  23. // 设置当前二级分组
  24. setCurrentSecondary(payload) {
  25. this.currentSecondary = payload;
  26. let arr = this.list.filter((item) => {
  27. return this.currentSecondary.id == item.category;
  28. });
  29. this.setCurrentScenesList(arr.sort((a, b) => a.weight - b.weight))
  30. },
  31. // 设置当前场景列表
  32. setCurrentScenesList(payload) {
  33. this.currentScenesList = payload;
  34. },
  35. // 设置当前一级分组
  36. setCurrentCatalogRoot(payload) {
  37. this.currentCatalogRoot = payload;
  38. let temp = [];
  39. payload.children &&
  40. payload.children.forEach((item) => {
  41. this.metadata.catalogs.forEach((sub) => {
  42. if (item == sub.id) {
  43. if (this.list.some(iii => iii.category == sub.id)) {
  44. temp.push(sub);
  45. }
  46. }
  47. });
  48. });
  49. this.setSecondaryList(temp)
  50. },
  51. // 设置当前二级分组列表
  52. setSecondaryList(payload) {
  53. this.secondaryList = payload
  54. if (payload.length > 0) {
  55. this.setCurrentSecondary(payload[0])
  56. }
  57. },
  58. // 设置currentScene为该层第一个(只有点击区域时候触发)
  59. setCurrentSceneFirst() {
  60. this.currentScene = this.currentScenesList[0]
  61. },
  62. // 设置列表是否显示
  63. setListIsShow (isShow) {
  64. this.listIsShow = isShow
  65. // 存放到本地,实现大场景代码的交互
  66. localStorage.setItem('listIsShow', isShow)
  67. }
  68. },
  69. });
  70. export default appStore;