zhangzeli
2021-10-22 ac82481de1ed2421eddbbffc51e4ac6c34ccf61f
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
<style lang="less">
@import "./main.less";
</style>
 
<template>
  <div class="main" :class="{ 'main-hide-text': shrink }">
    <!-- 左侧菜单 -->
    <div
      :class="`sidebar-menu-content side-bar-menu-theme-${menuTheme}`"
      :style="{
        width: shrink ? '60px' : menuWidth + 'px',
        overflow: shrink ? 'visible' : 'auto',
      }"
    >
      <shrinkable-menu
        :shrink="shrink"
        @on-change="handleSubmenuChange"
        :theme="menuTheme"
        :before-push="beforePush"
        :menu-list="menuList"
      >
        <div slot="top" class="logo-content" v-if="showLogo || fixNav">
          <img
            v-show="
              !shrink && (menuTheme != 'light' || mainTheme == 'darkMode')
            "
            src="@/assets/logo-white.png"
          />
          <img
            v-show="!shrink && menuTheme == 'light' && mainTheme != 'darkMode'"
            src="@/assets/logo-black.png"
          />
          <img v-show="shrink" src="@/assets/logo-min.png" key="min-logo" />
        </div>
      </shrinkable-menu>
    </div>
    <!-- 右上顶部导航条 -->
    <div
      :class="`main-header-content fix-nav-${fixNav}`"
      :style="{
        paddingLeft: navPaddingLeft,
      }"
    >
      <div :class="`main-header header-theme-${navTheme}`">
        <div class="header-left">
          <!-- 固定图标 -->
          <div v-if="fixNav && showLogo" style="width: 220px" class="fix-logo">
            <img
              src="@/assets/logo-black.png"
              v-if="navTheme == 'light' && mainTheme != 'darkMode'"
            />
            <img src="@/assets/logo-white.png" key="max-logo" v-else />
          </div>
          <!-- 收缩图标 -->
          <div
            class="header-navicon-content header-action"
            @click="toggleClick"
            v-if="showFold"
          >
            <Icon
              custom="iconfont icon-menu-unfold"
              size="20"
              v-show="this.shrink"
            />
            <Icon
              custom="iconfont icon-menu-fold"
              size="20"
              v-show="!this.shrink"
            />
          </div>
          <div class="header-middle-content">
            <!-- 顶部菜单 -->
            <div v-if="navType == 1">
              <navMenu
                :theme="navTheme"
                :currNav="currNav"
                :navList="navList"
                @on-click="selectNav"
                :sliceNum="currSliceNum"
                :showIcon="showNavMenuIcon"
              />
            </div>
            <!-- 下拉菜单 -->
            <div v-if="navType == 2">
              <navApp
                currType="tabs"
                placement="bottom-start"
                :currNavTitle="currNavTitle"
                :currNav="currNav"
                :navList="navList"
                :type="navShowType"
                :theme="navTheme"
                @on-click="selectNav"
              />
            </div>
            <!-- 面包导航 -->
            <div class="main-breadcrumb" v-if="navType == 3">
              <breadcrumb-nav :theme="navTheme" :currentPath="currentPath" />
            </div>
          </div>
        </div>
        <!-- 顶部右侧按钮 -->
        <div class="header-right-content">
          <search :theme="navTheme" :type="searchType" v-if="showSearch" />
          <navApp
            :currNav="currNav"
            :navList="navList"
            :type="navShowType"
            @on-click="selectNav"
            v-if="navType == 3"
          />
          <full-screen v-model="isFullScreen" @on-change="fullscreenChange" />
          <language />
          <message-tip />
          <user />
          <theme />
        </div>
      </div>
    </div>
    <!-- Tags 标签 -->
    <div
      class="nav-tags"
      :style="{
        paddingLeft: shrink ? '60px' : menuWidth + 'px',
      }"
    >
      <tags-page-opened :pageTagsList="pageTagsList" v-if="showTags" />
    </div>
    <!-- 页面部分 -->
    <div
      class="single-page-content"
      :style="{
        left: shrink ? '60px' : menuWidth + 'px',
        top: showTags ? '100px' : '60px',
      }"
    >
      <div class="single-page">
        <keep-alive :include="cachePage">
          <router-view />
        </keep-alive>
      </div>
      <!-- 页面页脚 -->
      <div class="main-page-footer-content" v-if="showFooter">
        <Footer class="main-page-footer" />
      </div>
    </div>
    <!-- 全局加载动画 -->
    <circleLoading class="loading-position" v-show="loading" />
  </div>
</template>
 
<script>
import shrinkableMenu from "./main-components/shrinkable-menu/shrinkable-menu.vue";
import tagsPageOpened from "./main-components/tags-page-opened.vue";
import breadcrumbNav from "./main-components/breadcrumb-nav.vue";
import navMenu from "./main-components/navMenu.vue";
import navApp from "./main-components/navApp.vue";
import search from "./main-components/search.vue";
import fullScreen from "./main-components/fullscreen.vue";
import language from "./main-components/language.vue";
import messageTip from "./main-components/message-tip.vue";
import user from "./main-components/user.vue";
import Footer from "./main-components/footer.vue";
import theme from "./main-components/theme.vue";
import circleLoading from "@/views/my-components/xboot/circle-loading.vue";
 
import util from "@/libs/util.js";
 
export default {
  components: {
    shrinkableMenu,
    tagsPageOpened,
    breadcrumbNav,
    navMenu,
    navApp,
    search,
    fullScreen,
    language,
    messageTip,
    user,
    Footer,
    theme,
    circleLoading,
  },
  data() {
    return {
      navPaddingLeft: this.menuWidth,
      searchType: "input",
      shrink: false,
      currSliceNum: this.sliceNum,
      currNav: "",
      isFullScreen: false,
    };
  },
  computed: {
    // 主题
    mainTheme() {
      return this.$store.state.theme.theme.mainTheme;
    },
    menuTheme() {
      return this.$store.state.theme.theme.menuTheme;
    },
    navTheme() {
      return this.$store.state.theme.theme.navTheme;
    },
    menuWidth() {
      return this.$store.state.theme.theme.menuWidth;
    },
    fixNav() {
      return this.$store.state.theme.theme.fixNav;
    },
    navType() {
      return this.$store.state.theme.theme.navType;
    },
    sliceNum() {
      return this.$store.state.theme.theme.sliceNum;
    },
    showTags() {
      return this.$store.state.theme.theme.showTags;
    },
    showNavMenuIcon() {
      return this.$store.state.theme.theme.showNavMenuIcon;
    },
    navShowType() {
      return this.$store.state.theme.theme.navShowType;
    },
    showFold() {
      return this.$store.state.theme.theme.showFold;
    },
    showLogo() {
      return this.$store.state.theme.theme.showLogo;
    },
    showSearch() {
      return this.$store.state.theme.theme.showSearch;
    },
    showFooter() {
      return this.$store.state.theme.theme.showFooter;
    },
    weakMode() {
      return this.$store.state.theme.theme.weakMode;
    },
    // 应用
    loading() {
      return this.$store.state.app.loading;
    },
    navList() {
      return this.$store.state.app.navList;
    },
    currNavTitle() {
      return this.$store.state.app.currNavTitle;
    },
    menuList() {
      return this.$store.state.app.menuList;
    },
    pageTagsList() {
      return this.$store.state.app.pageOpenedList; // 打开的页面的页面对象
    },
    currentPath() {
      return this.$store.state.app.currentPath; // 当前面包屑数组
    },
    cachePage() {
      return this.$store.state.app.cachePage;
    },
    lang() {
      return this.$store.state.app.lang;
    },
  },
  methods: {
    init() {
      this.changeFixNav();
      // 菜单
      let pathArr = util.setCurrentPath(this, this.$route.name);
      this.checkTag(this.$route.name);
    },
    getCurrNav() {
      // 读取选中顶部菜单名
      let currNav = this.getStore("currNav");
      if (currNav) {
        this.currNav = currNav;
      } else {
        // 默认第一个
        if (this.navList && this.navList.length > 0) {
          this.currNav = this.navList[0].name;
        }
      }
    },
    selectNav(name) {
      let flag = false;
      this.navList.forEach((e) => {
        if (e.name == name && e.isMenu == false) {
          flag = true;
          if (e.description == "direct") {
            window.location.href = e.url;
          } else if (e.description == "window") {
            window.open(e.url);
          } else if (e.description == "route") {
            this.$router.push({
              name: e.url,
            });
          }
        }
      });
      if (flag) {
        // 第三方站外链接 不作其他操作
        return;
      }
      // 缓存当前顶部菜单名
      this.currNav = name;
      this.setStore("currNav", name);
      this.$store.commit("setCurrNav", name);
      // 点击顶部菜单 回到首页
      if (this.$route.name != "home_index") {
        this.$router.push({
          name: "home_index",
        });
      }
      util.initRouter(this);
    },
    toggleClick() {
      this.shrink = !this.shrink;
      this.changeFixNav();
    },
    changeFixNav() {
      if (this.fixNav) {
        this.navPaddingLeft = "0px";
      } else {
        this.navPaddingLeft = this.shrink ? "60px" : this.menuWidth + "px";
      }
    },
    checkTag(name) {
      let openpageHasTag = this.pageTagsList.some((item) => {
        if (item.name == name) {
          return true;
        }
      });
      if (!openpageHasTag) {
        //  解决关闭当前标签后再点击回退按钮会退到当前页时没有标签的问题
        util.openNewPage(
          this,
          name,
          this.$route.params || {},
          this.$route.query || {}
        );
      }
    },
    handleSubmenuChange(val) {
      // console.log(val)
    },
    beforePush(name) {
      // console.log(name)
      return true;
    },
    fullscreenChange(isFullScreen) {
      // console.log(isFullScreen);
    },
    resize() {
      let currWidth = document.body.clientWidth;
 
      if (currWidth <= 1400 && currWidth > 1200) {
        this.currSliceNum = 3;
      } else if (currWidth <= 1200 && currWidth > 900) {
        this.currSliceNum = 2;
        this.shrink = true;
      } else if (currWidth <= 900) {
        this.currSliceNum = 1;
        this.shrink = true;
      } else {
        this.currSliceNum = this.sliceNum;
        this.shrink = false;
      }
 
      if (currWidth < 1325 && currWidth > 1200) {
        this.searchType = "icon";
      } else if (currWidth < 1000 && currWidth > 900) {
        this.searchType = "icon";
      } else if (currWidth < 835) {
        this.searchType = "icon";
      } else {
        this.searchType = "input";
      }
      this.changeFixNav();
    },
  },
  watch: {
    $route(to) {
      this.$store.commit("setCurrentPageName", to.name);
      let pathArr = util.setCurrentPath(this, to.name);
      this.checkTag(to.name);
    },
    lang() {
      util.setCurrentPath(this, this.$route.name); // 在切换语言时用于刷新面包屑
    },
    fixNav() {
      this.changeFixNav();
    },
    menuWidth() {
      this.changeFixNav();
    },
    navList() {
      setTimeout(() => {
        this.getCurrNav();
      }, 100);
    },
    sliceNum() {
      this.resize();
    },
  },
  created() {
    // 显示打开的页面的列表
    this.$store.commit("setOpenedList");
    this.init();
    this.resize();
    window.addEventListener("resize", () => {
      this.resize();
    });
    if (this.navList && this.navList.length > 0) {
      this.getCurrNav();
    }
  },
};
</script>