index.vue 8.5 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
          <div v-if="isSider" class="tit-text" :style="{color:textColor}">{{ $GIN_VUE_ADMIN.appName }}</div>
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 v-else class="gvaIcon gvaIcon-arrow-double-left" />
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
                        >{{ fmtTitle(item.meta.title,route) }}</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 83 84 85 86 87 88
          <div>
            <transition mode="out-in" name="el-fade-in-linear">
              <keep-alive :include="routerStore.keepAliveRouters">
                <component :is="Component" />
              </keep-alive>
            </transition>
          </div>
89
        </router-view>
何秀钢 已提交
90
        <BottomInfo />
D
Devil 已提交
91
        <setting />
92 93
      </el-main>
    </el-container>
94

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

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

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

const router = useRouter()
const route = useRoute()
121
const routerStore = useRouterStore()
122 123 124 125
// 三种窗口适配
const isCollapse = ref(false)
const isSider = ref(true)
const isMobile = ref(false)
126 127 128 129 130

const cc = (e) => {
  console.log(e)
}

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
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.奇淼( 已提交
169 170 171
  if (userStore.loadingInstance) {
    userStore.loadingInstance.close()
  }
172 173
})

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

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

const backgroundColor = computed(() => {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
187
  if (userStore.sideMode === 'dark') {
188
    return '#191a23'
Mr.奇淼('s avatar
Mr.奇淼( 已提交
189
  } else if (userStore.sideMode === 'light') {
190 191
    return '#fff'
  } else {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
192
    return userStore.sideMode
193 194 195
  }
})

Mr.奇淼('s avatar
Mr.奇淼( 已提交
196
const matched = computed(() => route.meta.matched)
197 198 199 200 201 202 203 204 205 206 207 208 209 210

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)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
211
let reloadTimer = null
212
const reload = async() => {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
213 214
  if (reloadTimer) {
    window.clearTimeout(reloadTimer)
215
  }
Mr.奇淼('s avatar
Mr.奇淼( 已提交
216 217 218 219 220 221 222 223 224 225
  reloadTimer = window.setTimeout(async() => {
    if (route.meta.keepAlive) {
      reloadFlag.value = false
      await nextTick()
      reloadFlag.value = true
    } else {
      const title = route.meta.title
      router.push({ name: 'Reload', params: { title }})
    }
  }, 400)
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
}

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

246 247
<style lang="scss">
@import '@/style/mobile.scss';
1
1319612909 已提交
248

249
.dark{
D
Devil 已提交
250 251 252
  background-color: #191a23 !important;
  color: #fff !important;
}
253
.light{
D
Devil 已提交
254 255 256
  background-color: #fff !important;
  color: #000 !important;
}
K
klausY 已提交
257
</style>