index.vue 8.1 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
                      <div class="menu-total" @click="totalCollapse">
P
piexlmax 已提交
26 27 28 29
                        <el-icon v-if="isCollapse" size="24"><expand /></el-icon>
                        <el-icon v-else size="24">
                          <fold />
                        </el-icon>
30 31
                      </div>
                    </el-col>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
32 33
                    <el-col :xs="10" :lg="14" :md="14" :sm="9" :xl="14" :pull="1">
                      <el-breadcrumb class="breadcrumb">
34
                        <el-breadcrumb-item
35
                          v-for="item in matched.slice(1,matched.length)"
36 37 38 39 40
                          :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.奇淼( 已提交
41
                      <div class="right-box">
42 43
                        <Search />
                        <el-dropdown>
44
                          <div class="dp-flex justify-content-center align-items height-full width-full">
45 46 47
                            <span class="header-avatar" style="cursor: pointer">
                              <CustomPic />
                              <span style="margin-left: 5px">{{ userInfo.nickName }}</span>
P
piexlmax 已提交
48 49 50
                              <el-icon>
                                <arrow-down />
                              </el-icon>
51
                            </span>
52 53 54 55
                          </div>
                          <template #dropdown>
                            <el-dropdown-menu class="dropdown-group">
                              <el-dropdown-item>
56 57 58
                                <span style="font-weight: 600;">
                                  当前角色:{{ userInfo.authority.authorityName }}
                                </span>
59 60
                              </el-dropdown-item>
                              <template v-if="userInfo.authorities">
61 62 63 64
                                <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>
65 66
                                </el-dropdown-item>
                              </template>
P
piexlmax 已提交
67 68
                              <el-dropdown-item icon="avatar" @click="toPerson">个人信息</el-dropdown-item>
                              <el-dropdown-item icon="reading-lamp" @click="LoginOut">登 出</el-dropdown-item>
69 70 71 72 73 74 75 76
                            </el-dropdown-menu>
                          </template>
                        </el-dropdown>
                      </div>
                    </el-col>
                  </el-row>
                </el-header>
              </el-col>
何秀钢 已提交
77
            </el-row>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
78
            <!-- 当前面包屑用路由自动生成可根据需求修改 -->
79 80
            <!--
            :to="{ path: item.path }" 暂时注释不用-->
81
            <HistoryComponent ref="layoutHistoryComponent" />
82 83
          </div>
        </transition>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
84
        <router-view v-if="reloadFlag" v-slot="{ Component }" v-loading="loadingFlag" element-loading-text="正在加载中" class="admin-box">
85
          <transition mode="out-in" name="el-fade-in-linear">
Mr.奇淼('s avatar
Mr.奇淼( 已提交
86
            <keep-alive :include="$store.getters['router/keepAliveRouters']">
87 88 89 90
              <component :is="Component" />
            </keep-alive>
          </transition>
        </router-view>
何秀钢 已提交
91
        <BottomInfo />
D
Devil 已提交
92
        <setting />
93 94
      </el-main>
    </el-container>
95

Mr.奇淼('s avatar
Mr.奇淼( 已提交
96
  </el-container>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
97 98 99
</template>

<script>
100 101 102 103 104 105
export default {
  name: 'Layout',
}
</script>

<script setup>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
106 107 108 109 110 111
import Aside from '@/view/layout/aside/index.vue'
import HistoryComponent from '@/view/layout/aside/historyComponent/history.vue'
import Search from '@/view/layout/search/search.vue'
import BottomInfo from '@/view/layout/bottomInfo/bottomInfo.vue'
import CustomPic from '@/components/customPic/index.vue'
import Setting from './setting/index.vue'
112
import { useStore } from 'vuex'
113
import { setUserAuthority } from '@/api/user'
114
import { emitter } from '@/utils/bus.js'
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
import { computed, ref, onMounted, nextTick } from 'vue'
import { useRouter, useRoute } from 'vue-router'

const store = useStore()
const router = useRouter()
const route = useRoute()

// 三种窗口适配
const isCollapse = ref(false)
const isSider = ref(true)
const isMobile = ref(false)
const initPage = () => {
  const screenWidth = document.body.clientWidth
  if (screenWidth < 1000) {
    isMobile.value = true
    isSider.value = false
    isCollapse.value = true
  } else if (screenWidth >= 1000 && screenWidth < 1200) {
    isMobile.value = false
    isSider.value = false
    isCollapse.value = true
  } else {
    isMobile.value = false
    isSider.value = true
    isCollapse.value = false
  }
}

initPage()

const loadingFlag = ref(false)
onMounted(() => {
  // 挂载一些通用的事件
  emitter.emit('collapse', isCollapse.value)
  emitter.emit('mobile', isMobile.value)
  emitter.on('reload', reload)
  emitter.on('showLoading', () => {
    loadingFlag.value = true
  })
  emitter.on('closeLoading', () => {
    loadingFlag.value = false
  })
  window.onresize = () => {
    return (() => {
      initPage()
      emitter.emit('collapse', isCollapse.value)
      emitter.emit('mobile', isMobile.value)
    })()
  }
})

const userInfo = computed(() => store.getters['user/userInfo'])
const sideMode = computed(() => store.getters['user/sideMode'])
const baseColor = computed(() => store.getters['user/baseColor'])
const textColor = computed(() => {
  if (sideMode === 'dark') {
    return '#fff'
  } else if (sideMode === 'light') {
    return '#191a23'
  } else {
    return baseColor.value
Mr.奇淼('s avatar
Mr.奇淼( 已提交
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
})

const backgroundColor = computed(() => {
  if (sideMode === 'dark') {
    return '#191a23'
  } else if (sideMode === 'light') {
    return '#fff'
  } else {
    return sideMode.value
  }
})

const matched = computed(() => route.matched)

const LoginOut = () => {
  store.dispatch('user/LoginOut')
}

const changeUserAuth = async(id) => {
  const res = await setUserAuthority({
    authorityId: id
  })
  if (res.code === 0) {
    emitter.emit('closeAllPage')
    setTimeout(() => {
      window.location.reload()
    }, 1)
  }
}

const reloadFlag = ref(true)
const reload = async() => {
  reloadFlag.value = false
  await nextTick()
  reloadFlag.value = true
}

const isShadowBg = ref(false)
const totalCollapse = () => {
  isCollapse.value = !isCollapse.value
  isSider.value = !isCollapse.value
  isShadowBg.value = !isCollapse.value
  emitter.emit('collapse', isCollapse.value)
}

const toPerson = () => {
  router.push({ name: 'person' })
}
const changeShadow = () => {
  isShadowBg.value = !isShadowBg.value
  isSider.value = !!isCollapse.value
  totalCollapse()
229
}
Mr.奇淼('s avatar
Mr.奇淼( 已提交
230
</script>
何秀钢 已提交
231

232 233
<style lang="scss">
@import '@/style/mobile.scss';
1
1319612909 已提交
234

235
.dark{
D
Devil 已提交
236 237 238
  background-color: #191a23 !important;
  color: #fff !important;
}
239
.light{
D
Devil 已提交
240 241 242
  background-color: #fff !important;
  color: #000 !important;
}
K
klausY 已提交
243
</style>