index.vue 8.7 KB
Newer Older
Mr.奇淼('s avatar
Mr.奇淼( 已提交
1
<template>
L
liuyang 已提交
2
  <el-container class="layout-cont">
3 4
    <el-container :class="[isSider?'openside':'hideside',isMobile ? 'mobile': '']">
      <el-row :class="[isShadowBg?'shadowBg':'']" @click="changeShadow()" />
Mr.奇淼('s avatar
Mr.奇淼( 已提交
5
      <el-aside class="main-cont main-left">
6
        <div class="tilte" :style="{background: backgroundColor}">
7
          <img alt class="logoimg" :src="$GIN_VUE_ADMIN.appLogo">
8
          <h2 v-if="isSider" class="tit-text" :style="{color:textColor}">{{ $GIN_VUE_ADMIN.appName }}</h2>
9
        </div>
10
        <Aside class="aside" />
Mr.奇淼('s avatar
Mr.奇淼( 已提交
11
      </el-aside>
12
      <!-- 分块滑动功能 -->
Mr.奇淼('s avatar
Mr.奇淼( 已提交
13
      <el-main class="main-cont main-right">
Mr.奇淼('s avatar
Mr.奇淼( 已提交
14
        <transition :duration="{ enter: 800, leave: 100 }" mode="out-in" name="el-fade-in-linear">
Mr.奇淼('s avatar
Mr.奇淼( 已提交
15
          <div
16
            :style="{width: `calc(100% - ${isMobile?'0px':isCollapse?'54px':'220px'})`}"
17
            class="topfix"
Mr.奇淼('s avatar
Mr.奇淼( 已提交
18
          >
何秀钢 已提交
19
            <el-row>
20
              <!-- :xs="8" :sm="6" :md="4" :lg="3" :xl="1" -->
21 22 23
              <el-col>
                <el-header class="header-cont">
                  <el-row class="pd-0">
Mr.奇淼('s avatar
Mr.奇淼( 已提交
24
                    <el-col :xs="2" :lg="1" :md="1" :sm="1" :xl="1" style="z-index:100">
25 26 27 28 29
                      <div class="menu-total" @click="totalCollapse">
                        <i v-if="isCollapse" class="el-icon-s-unfold" />
                        <i v-else class="el-icon-s-fold" />
                      </div>
                    </el-col>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
30 31
                    <el-col :xs="10" :lg="14" :md="14" :sm="9" :xl="14" :pull="1">
                      <el-breadcrumb class="breadcrumb">
32
                        <el-breadcrumb-item
33
                          v-for="item in matched.slice(1,matched.length)"
34 35 36 37 38
                          :key="item.path"
                        >{{ item.meta.title }}</el-breadcrumb-item>
                      </el-breadcrumb>
                    </el-col>
                    <el-col :xs="12" :lg="9" :md="9" :sm="14" :xl="9">
Mr.奇淼('s avatar
Mr.奇淼( 已提交
39
                      <div class="right-box">
40
                        <Search />
41
                        <Screenfull class="screenfull" :style="{cursor:'pointer'}" />
42
                        <el-dropdown>
43
                          <div class="dp-flex justify-content-center align-items height-full width-full">
44 45 46 47
                            <span class="header-avatar" style="cursor: pointer">
                              <CustomPic />
                              <span style="margin-left: 5px">{{ userInfo.nickName }}</span>
                              <i class="el-icon-arrow-down" />
48
                            </span>
49 50 51 52
                          </div>
                          <template #dropdown>
                            <el-dropdown-menu class="dropdown-group">
                              <el-dropdown-item>
53 54 55
                                <span style="font-weight: 600;">
                                  当前角色:{{ userInfo.authority.authorityName }}
                                </span>
56 57
                              </el-dropdown-item>
                              <template v-if="userInfo.authorities">
58 59 60 61
                                <el-dropdown-item v-for="item in userInfo.authorities.filter(i=>i.authorityId!==userInfo.authorityId)" :key="item.authorityId" @click="changeUserAuth(item.authorityId)">
                                  <span>
                                    切换为:{{ item.authorityName }}
                                  </span>
62 63 64 65 66 67 68 69 70 71 72 73
                                </el-dropdown-item>
                              </template>
                              <el-dropdown-item icon="el-icon-s-custom" @click="toPerson">个人信息</el-dropdown-item>
                              <el-dropdown-item icon="el-icon-table-lamp" @click="LoginOut">登 出</el-dropdown-item>
                            </el-dropdown-menu>
                          </template>
                        </el-dropdown>
                      </div>
                    </el-col>
                  </el-row>
                </el-header>
              </el-col>
何秀钢 已提交
74
            </el-row>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
75
            <!-- 当前面包屑用路由自动生成可根据需求修改 -->
76 77
            <!--
            :to="{ path: item.path }" 暂时注释不用-->
78
            <HistoryComponent ref="layoutHistoryComponent" />
79 80
          </div>
        </transition>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
81
        <router-view v-if="reloadFlag" v-slot="{ Component }" v-loading="loadingFlag" element-loading-text="正在加载中" class="admin-box">
82
          <transition mode="out-in" name="el-fade-in-linear">
Mr.奇淼('s avatar
Mr.奇淼( 已提交
83
            <keep-alive :include="$store.getters['router/keepAliveRouters']">
84 85 86 87
              <component :is="Component" />
            </keep-alive>
          </transition>
        </router-view>
何秀钢 已提交
88
        <BottomInfo />
D
Devil 已提交
89
        <setting />
90 91
      </el-main>
    </el-container>
92

Mr.奇淼('s avatar
Mr.奇淼( 已提交
93
  </el-container>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
94 95 96
</template>

<script>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
97 98 99 100 101
import Aside from '@/view/layout/aside/index.vue'
import HistoryComponent from '@/view/layout/aside/historyComponent/history.vue'
import Screenfull from '@/view/layout/screenfull/index.vue'
import Search from '@/view/layout/search/search.vue'
import BottomInfo from '@/view/layout/bottomInfo/bottomInfo.vue'
102
import { mapGetters, mapActions } from 'vuex'
Mr.奇淼('s avatar
Mr.奇淼( 已提交
103 104
import CustomPic from '@/components/customPic/index.vue'
import Setting from './setting/index.vue'
105
import { setUserAuthority } from '@/api/user'
106
import { emitter } from '@/utils/bus.js'
Mr.奇淼('s avatar
Mr.奇淼( 已提交
107
export default {
108
  name: 'Layout',
何秀钢 已提交
109 110 111 112 113 114
  components: {
    Aside,
    HistoryComponent,
    Screenfull,
    Search,
    BottomInfo,
D
Devil 已提交
115 116
    CustomPic,
    Setting
何秀钢 已提交
117
  },
118 119
  data() {
    return {
120
      show: false,
J
导航  
jinlan.du 已提交
121 122 123
      isCollapse: false,
      isSider: true,
      isMobile: false,
L
liuyang 已提交
124
      isShadowBg: false,
何秀钢 已提交
125 126
      loadingFlag: false,
      reloadFlag: true,
127 128
      value: ''
    }
Mr.奇淼('s avatar
Mr.奇淼( 已提交
129
  },
130
  computed: {
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
    ...mapGetters('user', ['userInfo', 'sideMode', 'baseColor']),
    textColor() {
      if (this.$store.getters['user/sideMode'] === 'dark') {
        return '#fff'
      } else if (this.$store.getters['user/sideMode'] === 'light') {
        return '#191a23'
      } else {
        return this.baseColor
      }
    },
    backgroundColor() {
      if (this.sideMode === 'dark') {
        return '#191a23'
      } else if (this.sideMode === 'light') {
        return '#fff'
      } else {
        return this.sideMode
      }
    },
150
    title() {
151
      return this.$route.meta.title || '当前页面'
152
    },
153
    matched() {
154
      return this.$route.matched
155
    }
J
导航  
jinlan.du 已提交
156
  },
Mr.奇淼('s avatar
Mr.奇淼( 已提交
157
  created() {
何秀钢 已提交
158
    const screenWidth = document.body.clientWidth
Mr.奇淼('s avatar
Mr.奇淼( 已提交
159
    if (screenWidth < 1000) {
160 161 162
      this.isMobile = true
      this.isSider = false
      this.isCollapse = true
Mr.奇淼('s avatar
Mr.奇淼( 已提交
163
    } else if (screenWidth >= 1000 && screenWidth < 1200) {
164 165 166
      this.isMobile = false
      this.isSider = false
      this.isCollapse = true
Mr.奇淼('s avatar
Mr.奇淼( 已提交
167
    } else {
168 169 170
      this.isMobile = false
      this.isSider = true
      this.isCollapse = false
Mr.奇淼('s avatar
Mr.奇淼( 已提交
171
    }
Mr.奇淼('s avatar
Mr.奇淼( 已提交
172 173
  },
  mounted() {
174 175 176 177
    emitter.emit('collapse', this.isCollapse)
    emitter.emit('mobile', this.isMobile)
    emitter.on('reload', this.reload)
    emitter.on('showLoading', () => {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
178 179
      this.loadingFlag = true
    })
180
    emitter.on('closeLoading', () => {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
181 182
      this.loadingFlag = false
    })
L
liuyang 已提交
183 184
    window.onresize = () => {
      return (() => {
何秀钢 已提交
185
        const screenWidth = document.body.clientWidth
Mr.奇淼('s avatar
Mr.奇淼( 已提交
186
        if (screenWidth < 1000) {
187 188 189
          this.isMobile = true
          this.isSider = false
          this.isCollapse = true
Mr.奇淼('s avatar
Mr.奇淼( 已提交
190
        } else if (screenWidth >= 1000 && screenWidth < 1200) {
191 192 193
          this.isMobile = false
          this.isSider = false
          this.isCollapse = true
L
liuyang 已提交
194
        } else {
195 196 197
          this.isMobile = false
          this.isSider = true
          this.isCollapse = false
L
liuyang 已提交
198
        }
199 200
        emitter.emit('collapse', this.isCollapse)
        emitter.emit('mobile', this.isMobile)
201 202
      })()
    }
何秀钢 已提交
203 204
  },
  methods: {
205 206 207 208 209 210
    ...mapActions('user', ['LoginOut', 'GetUserInfo']),
    async changeUserAuth(id) {
      const res = await setUserAuthority({
        authorityId: id
      })
      if (res.code === 0) {
211
        emitter.emit('closeAllPage')
212 213 214
        setTimeout(() => {
          window.location.reload()
        }, 1)
215 216
      }
    },
何秀钢 已提交
217 218 219 220 221 222 223 224 225 226
    reload() {
      this.reloadFlag = false
      this.$nextTick(() => {
        this.reloadFlag = true
      })
    },
    totalCollapse() {
      this.isCollapse = !this.isCollapse
      this.isSider = !this.isCollapse
      this.isShadowBg = !this.isCollapse
227
      emitter.emit('collapse', this.isCollapse)
何秀钢 已提交
228 229 230 231 232 233 234 235 236
    },
    toPerson() {
      this.$router.push({ name: 'person' })
    },
    changeShadow() {
      this.isShadowBg = !this.isShadowBg
      this.isSider = !!this.isCollapse
      this.totalCollapse()
    }
Mr.奇淼('s avatar
Mr.奇淼( 已提交
237
  }
238
}
Mr.奇淼('s avatar
Mr.奇淼( 已提交
239
</script>
何秀钢 已提交
240

241 242
<style lang="scss">
@import '@/style/mobile.scss';
1
1319612909 已提交
243

244
.dark{
D
Devil 已提交
245 246 247
  background-color: #191a23 !important;
  color: #fff !important;
}
248
.light{
D
Devil 已提交
249 250 251
  background-color: #fff !important;
  color: #000 !important;
}
K
klausY 已提交
252
</style>