12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- import { defineStore } from 'pinia';
- const appStore = defineStore('app', {
- state: () => ({
- // 场景列表
- list: [],
- //当前场景
- currentScene: {},
- //场景数据
- metadata: {},
- //当前一级分组
- currentCatalogRoot: {},
- //当前二级分组
- currentSecondary: {},
- //二级分组
- secondaryList: {},
- //当前场景分组
- currentScenesList: {},
- // 是否隐藏
- listIsShow: true
- }),
- getters: {},
- actions: {
- // 设置当前二级分组
- setCurrentSecondary(payload) {
- this.currentSecondary = payload;
- let arr = this.list.filter((item) => {
- return this.currentSecondary.id == item.category;
- });
- this.setCurrentScenesList(arr.sort((a, b) => a.weight - b.weight))
- },
- // 设置当前场景列表
- setCurrentScenesList(payload) {
- this.currentScenesList = payload;
- },
- // 设置当前一级分组
- setCurrentCatalogRoot(payload) {
- this.currentCatalogRoot = payload;
- let temp = [];
- payload.children &&
- payload.children.forEach((item) => {
- this.metadata.catalogs.forEach((sub) => {
- if (item == sub.id) {
- if (this.list.some(iii => iii.category == sub.id)) {
- temp.push(sub);
- }
- }
- });
- });
- this.setSecondaryList(temp)
- },
- // 设置当前二级分组列表
- setSecondaryList(payload) {
- this.secondaryList = payload
- if (payload.length > 0) {
- this.setCurrentSecondary(payload[0])
- }
- },
- // 设置currentScene为该层第一个(只有点击区域时候触发)
- setCurrentSceneFirst() {
- this.currentScene = this.currentScenesList[0]
- },
- // 设置列表是否显示
- setListIsShow (isShow) {
- this.listIsShow = isShow
- // 存放到本地,实现大场景代码的交互
- localStorage.setItem('listIsShow', isShow)
- }
- },
- });
- export default appStore;
|