index.vue 8.2 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 21 22
              <el-col>
                <el-header class="header-cont">
                  <el-row class="pd-0">
Mr.奇淼('s avatar
Mr.奇淼( 已提交
23
                    <el-col :xs="2" :lg="1" :md="1" :sm="1" :xl="1" style="z-index:100">
24
                      <div class="menu-total" @click="totalCollapse">
Mr.奇淼('s avatar
Mr.奇淼( 已提交
25 26
                        <div v-if="isCollapse" class="gvaIcon gvaIcon-arrow-double-right"></div>
                        <div v-else class="gvaIcon gvaIcon-arrow-double-left"></div>
27 28
                      </div>
                    </el-col>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
29 30
                    <el-col :xs="10" :lg="14" :md="14" :sm="9" :xl="14" :pull="1">
                      <el-breadcrumb class="breadcrumb">
31
                        <el-breadcrumb-item
32
                          v-for="item in matched.slice(1,matched.length)"
33
                          :key="item.path"
34
                        >{{ route.params.title || item.meta.title }}</el-breadcrumb-item>
35 36 37
                      </el-breadcrumb>
                    </el-col>
                    <el-col :xs="12" :lg="9" :md="9" :sm="14" :xl="9">
Mr.奇淼('s avatar
Mr.奇淼( 已提交
38
                      <div class="right-box">
39 40
                        <Search />
                        <el-dropdown>
41
                          <div class="dp-flex justify-content-center align-items height-full width-full">
42 43
                            <span class="header-avatar" style="cursor: pointer">
                              <CustomPic />
Mr.奇淼('s avatar
Mr.奇淼( 已提交
44
                              <span style="margin-left: 5px">{{ userStore.userInfo.nickName }}</span>
P
piexlmax 已提交
45 46 47
                              <el-icon>
                                <arrow-down />
                              </el-icon>
48
                            </span>
49 50 51 52
                          </div>
                          <template #dropdown>
                            <el-dropdown-menu class="dropdown-group">
                              <el-dropdown-item>
53
                                <span style="font-weight: 600;">
Mr.奇淼('s avatar
Mr.奇淼( 已提交
54
                                  当前角色:{{ userStore.userInfo.authority.authorityName }}
55
                                </span>
56
                              </el-dropdown-item>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
57 58
                              <template v-if="userStore.userInfo.authorities">
                                <el-dropdown-item v-for="item in userStore.userInfo.authorities.filter(i=>i.authorityId!==userStore.userInfo.authorityId)" :key="item.authorityId" @click="changeUserAuth(item.authorityId)">
59 60 61
                                  <span>
                                    切换为:{{ item.authorityName }}
                                  </span>
62 63
                                </el-dropdown-item>
                              </template>
P
piexlmax 已提交
64
                              <el-dropdown-item icon="avatar" @click="toPerson">个人信息</el-dropdown-item>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
65
                              <el-dropdown-item icon="reading-lamp" @click="userStore.LoginOut">登 出</el-dropdown-item>
66 67 68 69 70 71 72 73
                            </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">
83
            <keep-alive :include="routerStore.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>
97 98 99 100 101 102
export default {
  name: 'Layout',
}
</script>

<script setup>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
103 104 105 106 107 108
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'
109
import { setUserAuthority } from '@/api/user'
110
import { emitter } from '@/utils/bus.js'
111 112
import { computed, ref, onMounted, nextTick } from 'vue'
import { useRouter, useRoute } from 'vue-router'
Mr.奇淼('s avatar
Mr.奇淼( 已提交
113 114
import { useUserStore } from '@/pinia/modules/user'
import { useRouterStore } from '@/pinia/modules/router'
115 116 117

const router = useRouter()
const route = useRoute()
118
const routerStore = useRouterStore()
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
// 三种窗口适配
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)
    })()
  }
})

Mr.奇淼('s avatar
Mr.奇淼( 已提交
163 164
const userStore = useUserStore()

165
const textColor = computed(() => {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
166
  if (userStore.sideMode === 'dark') {
167
    return '#fff'
Mr.奇淼('s avatar
Mr.奇淼( 已提交
168
  } else if (userStore.sideMode === 'light') {
169 170
    return '#191a23'
  } else {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
171
    return userStore.baseColor
Mr.奇淼('s avatar
Mr.奇淼( 已提交
172
  }
173 174 175
})

const backgroundColor = computed(() => {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
176
  if (userStore.sideMode === 'dark') {
177
    return '#191a23'
Mr.奇淼('s avatar
Mr.奇淼( 已提交
178
  } else if (userStore.sideMode === 'light') {
179 180
    return '#fff'
  } else {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
181
    return userStore.sideMode
182 183 184
  }
})

Mr.奇淼('s avatar
Mr.奇淼( 已提交
185
const matched = computed(() => route.meta.matched)
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200

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() => {
201 202 203 204 205 206 207 208
  if (route.meta.keepAlive) {
    reloadFlag.value = false
    await nextTick()
    reloadFlag.value = true
  } else {
    const title = route.meta.title
    router.push({ name: 'Reload', params: { title }})
  }
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
}

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()
226
}
Mr.奇淼('s avatar
Mr.奇淼( 已提交
227
</script>
何秀钢 已提交
228

229 230
<style lang="scss">
@import '@/style/mobile.scss';
1
1319612909 已提交
231

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