Skip to content

Commit

Permalink
fix:设置添加页面切换动画
Browse files Browse the repository at this point in the history
  • Loading branch information
bypanghu authored and piexlMax(奇淼 committed Feb 13, 2025
1 parent e494e22 commit f608bfa
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 26 deletions.
1 change: 1 addition & 0 deletions web/src/pathInfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"/src/view/layout/screenfull/index.vue": "Screenfull",
"/src/view/layout/search/search.vue": "BtnBox",
"/src/view/layout/setting/index.vue": "GvaSetting",
"/src/view/layout/setting/title.vue": "layoutSettingTitle",
"/src/view/layout/tabs/index.vue": "HistoryComponent",
"/src/view/login/index.vue": "Login",
"/src/view/person/person.vue": "Person",
Expand Down
19 changes: 13 additions & 6 deletions web/src/pinia/modules/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ export const useAppStore = defineStore('app', () => {
layout_side_collapsed_width: 80,
layout_side_item_height: 48,
show_watermark: true,
side_mode: 'normal'
side_mode: 'normal',
// 页面过渡动画配置
transition_type: 'slide'
})

const isDark = useDark({
selector: 'html',
attribute: 'class',
valueDark: 'dark',
valueLight: 'light',
valueLight: 'light'
})

const preferredDark = usePreferredDark()
Expand All @@ -50,10 +52,10 @@ export const useAppStore = defineStore('app', () => {
}

const toggleDevice = (e) => {
if(e === 'mobile'){
if (e === 'mobile') {
drawerSize.value = '100%'
operateMinWith.value = '80'
}else {
} else {
drawerSize.value = '800'
operateMinWith.value = '240'
}
Expand Down Expand Up @@ -93,7 +95,11 @@ export const useAppStore = defineStore('app', () => {
config.side_mode = e
}

// 监听色弱模式和灰色模式
const toggleTransition = (e) => {
config.transition_type = e
}

// 监听色弱模式和灰色模式
watchEffect(() => {
document.documentElement.classList.toggle('html-weakenss', config.weakness)
document.documentElement.classList.toggle('html-grey', config.grey)
Expand Down Expand Up @@ -121,6 +127,7 @@ export const useAppStore = defineStore('app', () => {
toggleConfigSideCollapsedWidth,
toggleConfigSideItemHeight,
toggleConfigWatermark,
toggleSideMode
toggleSideMode,
toggleTransition
}
})
7 changes: 5 additions & 2 deletions web/src/pinia/modules/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ export const useUserStore = defineStore('user', () => {
userInfo.value = val
if (val.originSetting) {
Object.keys(appStore.config).forEach((key) => {
appStore.config[key] = val.originSetting[key]
if (val.originSetting[key]) {
appStore.config[key] = val.originSetting[key]
}
})
}
console.log(appStore.config)
}

const setToken = (val) => {
Expand Down Expand Up @@ -66,7 +69,7 @@ export const useUserStore = defineStore('user', () => {
})

const res = await login(loginInfo)

if (res.code !== 0) {
ElMessage.error(res.message || '登录失败')
return false
Expand Down
1 change: 1 addition & 0 deletions web/src/style/main.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@use '@/style/iconfont.css';
@use "./transition.scss";

.html-grey {
filter: grayscale(100%);
Expand Down
68 changes: 68 additions & 0 deletions web/src/style/transition.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@

// 淡入淡出动画
.fade-enter-active,
.fade-leave-active {
transition: all 0.3s ease;
}

.fade-enter-from,
.fade-leave-to {
opacity: 0;
transform: translateY(10px);
}

.header {
border-radius: 0 0 10px 10px;
}

.body {
height: calc(100% - 6rem);
}

@keyframes slideDown {
from {
transform: translateY(-20px);
opacity: 0;
}

to {
transform: translateY(0);
opacity: 1;
}
}

@keyframes fadeIn {
from {
opacity: 0;
}

to {
opacity: 1;
}
}
// 缩放动画
.zoom-enter-active,
.zoom-leave-active {
transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.zoom-enter-from,
.zoom-leave-to {
opacity: 0;
transform: scale(0.95);
}


/* fade-slide */
.slide-leave-active,
.slide-enter-active {
transition: all 0.3s;
}
.slide-enter-from {
opacity: 0;
transform: translateX(-30px);
}
.slide-leave-to {
opacity: 0;
transform: translateX(30px);
}
5 changes: 3 additions & 2 deletions web/src/view/layout/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
v-if="config.side_mode === 'combination' && device !== 'mobile'"
mode="normal"
/>
<div class="flex-1 p-2 w-0 h-full">
<div class="flex-1 px-2 w-0 h-full">
<gva-tabs v-if="config.showTabs" />
<div
class="overflow-auto"
Expand All @@ -34,7 +34,7 @@
id="gva-base-load-dom"
class="gva-body-h bg-gray-50 dark:bg-slate-800"
>
<transition mode="out-in" name="el-fade-in-linear">
<transition mode="out-in" :name="config.transition_type">
<keep-alive :include="routerStore.keepAliveRouters">
<component :is="Component" :key="route.fullPath" />
</keep-alive>
Expand All @@ -61,6 +61,7 @@
import { useUserStore } from '@/pinia/modules/user'
import { useAppStore } from '@/pinia'
import { storeToRefs } from 'pinia'
import '@/style/transition.scss'
const appStore = useAppStore()
const { config, isDark, device } = storeToRefs(appStore)
Expand Down
38 changes: 22 additions & 16 deletions web/src/view/layout/setting/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
</template>
<div class="flex flex-col">
<div class="mb-8">
<div class="text-gray-800 dark:text-gray-100">默认主题</div>
<div class="mt-2 text-sm p-2 flex items-center gap-2">
<Title title="默认主题"></Title>
<div class="mt-2 text-sm p-2 flex items-center justify-center gap-2">
<el-segmented
v-model="config.darkMode"
:options="options"
Expand All @@ -25,8 +25,8 @@
</div>
</div>
<div class="mb-8">
<div class="text-gray-800 dark:text-gray-100">主题色</div>
<div class="mt-2 text-sm p-2 flex items-center gap-2">
<Title title="主题色"></Title>
<div class="mt-2 text-sm p-2 flex items-center gap-2 justify-center">
<div
v-for="item in colors"
:key="item"
Expand All @@ -45,8 +45,8 @@
</div>
</div>
<div class="mb-8">
<div class="text-gray-800 dark:text-gray-100">界面显示</div>
<div class="mt-2 text-sm p-2">
<Title title="主题配置"></Title>
<div class="mt-2 text-md p-2 flex flex-col gap-2">
<div class="flex items-center justify-between">
<div>展示水印</div>
<el-switch
Expand All @@ -73,14 +73,6 @@
size="default"
@change="appStore.toggleSideMode"
/>
<!-- <el-select
v-model="config.side_mode"
@change="handleSideModelChange"
>
<el-option value="normal" label="标准模式" />
<el-option value="head" label="顶部导航栏" />
<el-option value="multilayer" disabled label="多侧边导航模式" />
</el-select> -->
</div>

<div class="flex items-center justify-between">
Expand All @@ -90,12 +82,25 @@
@change="appStore.toggleTabs"
/>
</div>
<div class="flex items-center justify-between gap-2">
<div class="flex-shrink-0">页面切换动画</div>
<el-select
v-model="config.transition_type"
@change="appStore.toggleTransition"
class="w-40"
>
<el-option value="fade" label="淡入淡出" />
<el-option value="slide" label="滑动" />
<el-option value="zoom" label="缩放" />
<el-option value="none" label="无动画" />
</el-select>
</div>
</div>
</div>

<div class="mb-8">
<div class="text-gray-800 dark:text-gray-100">layout 大小配置</div>
<div class="mt-2 text-sm p-2">
<Title title="layout 大小配置"></Title>
<div class="mt-2 text-md p-2 flex flex-col gap-2">
<div class="flex items-center justify-between mb-2">
<div>侧边栏展开宽度</div>
<el-input-number
Expand Down Expand Up @@ -138,6 +143,7 @@
import { ref, computed } from 'vue'
import { ElMessage } from 'element-plus'
import { setSelfSetting } from '@/api/user'
import Title from './title.vue'
const appStore = useAppStore()
const { config, device } = storeToRefs(appStore)
defineOptions({
Expand Down
34 changes: 34 additions & 0 deletions web/src/view/layout/setting/title.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<template>
<div class="title relative my-2">
<div class="flex-shrink-0 text-center text-xl text-gray-600">
{{ title }}
</div>
</div>
</template>

<script setup>
defineOptions({
name: 'layoutSettingTitle'
})
defineProps({
title: String
})
</script>

<style scoped>
.title {
display: flex;
align-items: center;
justify-content: center;
gap: 4rem;
}
.title::before,
.title::after {
content: '';
height: 1px;
width: 100%;
background-color: #e3e3e3;
}
</style>

0 comments on commit f608bfa

Please sign in to comment.