wangyanshen
2023-01-09 695c5a332e4bf10b6b93c9973e1634730b4a60df
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<template>
  <a-layout id="components-layout-demo-top-side" class="basiclayoutbox">
    <global-header :menus="menus"  />
    <a-layout-content :style="{ padding: 0, height: mainHeight + 'px' }">
      <a-layout style="padding: 0; background: #fff; height: 100%">
        <side-menu
          style="background: #fff; height: 100%; overflow: auto"
          mode="inline"
          :menus="menus"
          :theme="'light'"
          :collapsed="collapsed"
          :collapsible="true"
        ></side-menu>
        <a-layout-content
          :style="{ padding: '0', minHeight: '280px', height: '100%' }"
        >
          <div style="display: flex; just-content: flex-start">
            <div
              style="
                width: 40px;
                text-align: center;
                height: 40px;
                line-height: 40px;
                font-size: 25px;
              "
            >
              <a-icon
                class="trigger"
                :type="collapsed ? 'menu-fold' : 'menu-unfold'"
                @click="toggle"
              />
            </div>
            <multi-tab
              style="flex: 1; margin-left: 0"
              class="tabbox"
            ></multi-tab>
          </div>
 
          <div
            :style="{
              padding: '10px',
              height: mainHeight - 42 + 'px',
              overflow: 'auto',
              position: 'relative',
              backgroundColor:'#F1F2F6',
            }"
          >
            <transition name="page-transition">
              <route-view />
            </transition>
          </div>
        </a-layout-content>
      </a-layout>
    </a-layout-content>
 
    <global-footer />
  </a-layout>
</template>
 
<script>
import { triggerWindowResizeEvent } from "@/utils/util";
import { mapState, mapGetters, mapActions } from "vuex";
import { mixin, mixinDevice } from "@/utils/mixin";
import RouteView from "./RouteView";
 
import SideMenu from "@/components/Menu/SideMenu";
import GlobalHeader from "@/components/GlobalHeader";
import MultiTab from "@/components/MultiTab";
import GlobalFooter from "@/components/GlobalFooter";
 
const listToTree = (list, tree, parentId) => {
  list.forEach((item) => {
    // 判断是否为父级菜单
    // eslint-disable-next-line eqeqeq
    if (item.pid == parentId) {
      const child = {
        ...item,
        key: item.key || item.name,
        children: [],
      };
      // 迭代 list, 找到当前菜单相符合的所有子菜单
      listToTree(list, child.children, item.id);
      // 删掉不存在 children 值的属性
      if (child.children.length <= 0) {
        delete child.children;
      }
      // 加入到树中
      tree.push(child);
    }
  });
};
 
export default {
  name: "BasicLayout",
  mixins: [mixin, mixinDevice],
  components: {
    RouteView,
    SideMenu,
    GlobalHeader,
    GlobalFooter,
    MultiTab,
  },
  data() {
    return {
      collapsed: false,
      menus: [],
      mainHeight: 280,
      collapsed: true,
    };
  },
  computed: {
    ...mapGetters(["userInfo"]),
    ...mapState({
      moduleCode: (state) => state.user.moduleCode,
    }),
    contentPaddingLeft() {
      if (!this.fixSidebar || this.isMobile()) {
        return "0";
      }
      if (this.sidebarOpened) {
        return "230px";
      }
      return "80px";
    },
  },
  watch: {
    sidebarOpened(val) {
      this.collapsed = !val;
    },
    /**模块变化 */
    moduleCode(val) {
      this.setMenus();
    },
  },
  created() {
    this.setMenus();
    this.collapsed = !this.sidebarOpened;
  },
  mounted() {
    const userAgent = navigator.userAgent;
    if (userAgent.indexOf("Edge") > -1) {
      this.$nextTick(() => {
        this.collapsed = !this.collapsed;
        setTimeout(() => {
          this.collapsed = !this.collapsed;
        }, 16);
      });
    }
    //basiclayoutbox
    this.$nextTick(() => {
      let headerheight = 0;
      let footerheight = 0;
      if (document.querySelector(".headerbox")) {
        headerheight = document.querySelector(".headerbox").clientHeight;
      }
      if (document.querySelector(".footerbox")) {
        footerheight = document.querySelector(".footerbox").clientHeight;
      }
      this.mainHeight =
        document.body.clientHeight - headerheight - footerheight;
    });
 
    window.addEventListener("resize", () => {
      this.$nextTick(() => {
        let headerheight = 0;
        let footerheight = 0;
        if (document.querySelector(".headerbox")) {
          headerheight = document.querySelector(".headerbox").clientHeight;
        }
        if (document.querySelector(".footerbox")) {
          footerheight = document.querySelector(".footerbox").clientHeight;
        }
        this.mainHeight =
          document.body.clientHeight - headerheight - footerheight;
      });
    });
  },
  methods: {
    ...mapActions(["setSidebar"]),
    /**设置左侧菜单导航 */
    setMenus() {
      let data = this.userInfo.menus.filter((x) => {
        x.hidden = true;
        if (x.application == this.moduleCode) {
          x.hidden = false;
        }
        return x.application == this.moduleCode;
      });
      let treedata = [];
      listToTree(data, treedata, 0);
 
      this.menus = treedata || [];
    },
 
    toggle() {
      this.collapsed = !this.collapsed;
      this.setSidebar(!this.collapsed);
      triggerWindowResizeEvent();
    },
    paddingCalc() {
      let left = "";
      if (this.sidebarOpened) {
        left = this.isDesktop() ? "230px" : "80px";
      } else {
        left = (this.isMobile() && "0") || (this.fixSidebar && "80px") || "0";
      }
      return left;
    },
    menuSelect() {},
    drawerClose() {
      this.collapsed = false;
    },
  },
};
</script>
 
 
<style scoped>
.basiclayoutbox {
  height: 100%;
}
</style>
<style>
</style>