feat: theme
This commit is contained in:
parent
190d25857f
commit
65a65de03e
@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="app-layout">
|
<div class="app-layout">
|
||||||
<div class="app-header">
|
<div class="app-header" :class="!isDefaultTheme ? 'custom-header' : ''">
|
||||||
<SystemHeader v-if="isShared"></SystemHeader>
|
<SystemHeader v-if="isShared"></SystemHeader>
|
||||||
<UserHeader v-else />
|
<UserHeader v-else />
|
||||||
</div>
|
</div>
|
||||||
@ -27,7 +27,10 @@ const route = useRoute()
|
|||||||
const isShared = computed(() => {
|
const isShared = computed(() => {
|
||||||
return route.path.endsWith('hared') || route.name.includes('ResourceManagement')
|
return route.path.endsWith('hared') || route.name.includes('ResourceManagement')
|
||||||
})
|
})
|
||||||
const { user } = useStore()
|
const { theme } = useStore()
|
||||||
|
const isDefaultTheme = computed(() => {
|
||||||
|
return theme.isDefaultTheme()
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
@use './index.scss';
|
@use './index.scss';
|
||||||
|
|||||||
@ -1,11 +1,17 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { computed } from 'vue'
|
||||||
import UserHeader from '@/layout/layout-header/UserHeader.vue'
|
import UserHeader from '@/layout/layout-header/UserHeader.vue'
|
||||||
import AppMain from '@/layout/app-main/index.vue'
|
import AppMain from '@/layout/app-main/index.vue'
|
||||||
|
import useStore from '@/stores'
|
||||||
|
const { theme } = useStore()
|
||||||
|
const isDefaultTheme = computed(() => {
|
||||||
|
return theme.isDefaultTheme()
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="app-layout">
|
<div class="app-layout">
|
||||||
<div class="app-header">
|
<div class="app-header" :class="!isDefaultTheme ? 'custom-header' : ''">
|
||||||
<UserHeader />
|
<UserHeader />
|
||||||
</div>
|
</div>
|
||||||
<div class="app-main">
|
<div class="app-main">
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="app-layout">
|
<div class="app-layout">
|
||||||
<div class="app-header">
|
<div class="app-header" :class="!isDefaultTheme ? 'custom-header' : ''">
|
||||||
<SystemHeader />
|
<SystemHeader />
|
||||||
</div>
|
</div>
|
||||||
<div class="app-main">
|
<div class="app-main">
|
||||||
@ -14,11 +14,15 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { computed } from 'vue'
|
||||||
import SystemHeader from '@/layout/layout-header/SystemHeader.vue'
|
import SystemHeader from '@/layout/layout-header/SystemHeader.vue'
|
||||||
import Sidebar from '@/layout/components/sidebar/index.vue'
|
import Sidebar from '@/layout/components/sidebar/index.vue'
|
||||||
import AppMain from '@/layout/app-main/index.vue'
|
import AppMain from '@/layout/app-main/index.vue'
|
||||||
import useStore from '@/stores'
|
import useStore from '@/stores'
|
||||||
const { user } = useStore()
|
const { theme } = useStore()
|
||||||
|
const isDefaultTheme = computed(() => {
|
||||||
|
return theme.isDefaultTheme()
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
@use './index.scss';
|
@use './index.scss';
|
||||||
|
|||||||
@ -24,16 +24,16 @@ const useThemeStore = defineStore('theme', {
|
|||||||
this.themeInfo = cloneDeep(data)
|
this.themeInfo = cloneDeep(data)
|
||||||
},
|
},
|
||||||
|
|
||||||
// async theme(loading?: Ref<boolean>) {
|
async theme(loading?: Ref<boolean>) {
|
||||||
// return await ThemeApi.getThemeInfo(loading).then((ok) => {
|
return await ThemeApi.getThemeInfo(loading).then((ok) => {
|
||||||
// this.setTheme(ok.data)
|
this.setTheme(ok.data)
|
||||||
// // window.document.title = this.themeInfo['title'] || 'MaxKB'
|
// window.document.title = this.themeInfo['title'] || 'MaxKB'
|
||||||
// // const link = document.querySelector('link[rel="icon"]') as any
|
// const link = document.querySelector('link[rel="icon"]') as any
|
||||||
// // if (link) {
|
// if (link) {
|
||||||
// // link['href'] = this.themeInfo['icon'] || '/favicon.ico'
|
// link['href'] = this.themeInfo['icon'] || '/favicon.ico'
|
||||||
// // }
|
// }
|
||||||
// })
|
})
|
||||||
// },
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@ -20,7 +20,6 @@ export interface userStateTypes {
|
|||||||
version?: string
|
version?: string
|
||||||
license_is_valid: boolean
|
license_is_valid: boolean
|
||||||
edition: 'CE' | 'PE' | 'EE'
|
edition: 'CE' | 'PE' | 'EE'
|
||||||
themeInfo: any
|
|
||||||
workspace_id: string
|
workspace_id: string
|
||||||
workspace_list: Array<any>
|
workspace_list: Array<any>
|
||||||
}
|
}
|
||||||
@ -32,7 +31,6 @@ const useUserStore = defineStore('user', {
|
|||||||
version: '',
|
version: '',
|
||||||
license_is_valid: false,
|
license_is_valid: false,
|
||||||
edition: 'CE',
|
edition: 'CE',
|
||||||
themeInfo: null,
|
|
||||||
workspace_id: '',
|
workspace_id: '',
|
||||||
workspace_list: [],
|
workspace_list: [],
|
||||||
}),
|
}),
|
||||||
@ -42,14 +40,7 @@ const useUserStore = defineStore('user', {
|
|||||||
? localStorage.getItem('MaxKB-locale') || getBrowserLang()
|
? localStorage.getItem('MaxKB-locale') || getBrowserLang()
|
||||||
: sessionStorage.getItem('language') || getBrowserLang()
|
: sessionStorage.getItem('language') || getBrowserLang()
|
||||||
},
|
},
|
||||||
isDefaultTheme() {
|
|
||||||
return !this.themeInfo?.theme || this.themeInfo?.theme === '#3370FF'
|
|
||||||
},
|
|
||||||
setTheme(data: any) {
|
|
||||||
const { changeTheme } = useElementPlusTheme(this.themeInfo?.theme)
|
|
||||||
changeTheme(data?.['theme'])
|
|
||||||
this.themeInfo = cloneDeep(data)
|
|
||||||
},
|
|
||||||
setWorkspaceId(workspace_id: string) {
|
setWorkspaceId(workspace_id: string) {
|
||||||
this.workspace_id = workspace_id
|
this.workspace_id = workspace_id
|
||||||
localStorage.setItem('workspace_id', workspace_id)
|
localStorage.setItem('workspace_id', workspace_id)
|
||||||
@ -114,16 +105,7 @@ const useUserStore = defineStore('user', {
|
|||||||
const login = useLoginStore()
|
const login = useLoginStore()
|
||||||
login.userAccessToken = token || ''
|
login.userAccessToken = token || ''
|
||||||
},
|
},
|
||||||
async theme(loading?: Ref<boolean>) {
|
|
||||||
return await ThemeApi.getThemeInfo(loading).then((ok) => {
|
|
||||||
this.setTheme(ok.data)
|
|
||||||
// window.document.title = this.themeInfo['title'] || 'MaxKB'
|
|
||||||
// const link = document.querySelector('link[rel="icon"]') as any
|
|
||||||
// if (link) {
|
|
||||||
// link['href'] = this.themeInfo['icon'] || '/favicon.ico'
|
|
||||||
// }
|
|
||||||
})
|
|
||||||
},
|
|
||||||
async profile(loading?: Ref<boolean>) {
|
async profile(loading?: Ref<boolean>) {
|
||||||
return UserApi.getUserProfile(loading).then((ok) => {
|
return UserApi.getUserProfile(loading).then((ok) => {
|
||||||
this.userInfo = ok.data
|
this.userInfo = ok.data
|
||||||
@ -151,11 +133,11 @@ const useUserStore = defineStore('user', {
|
|||||||
// this.version = ok.data?.version || '-'
|
// this.version = ok.data?.version || '-'
|
||||||
this.license_is_valid = ok.data.license_is_valid
|
this.license_is_valid = ok.data.license_is_valid
|
||||||
this.edition = ok.data.edition
|
this.edition = ok.data.edition
|
||||||
|
const theme = useThemeStore()
|
||||||
if (this.isEE() || this.isPE()) {
|
if (this.isEE() || this.isPE()) {
|
||||||
await this.theme()
|
await theme.theme()
|
||||||
} else {
|
} else {
|
||||||
this.themeInfo = {
|
theme.themeInfo = {
|
||||||
...defaultPlatformSetting,
|
...defaultPlatformSetting,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -485,3 +485,8 @@ h5 {
|
|||||||
height: var(--app-main-height);
|
height: var(--app-main-height);
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 自定义主题
|
||||||
|
.custom-header {
|
||||||
|
background: var(--el-color-primary-light-9) !important;
|
||||||
|
}
|
||||||
|
|||||||
@ -143,12 +143,12 @@ import { WorkFlowInstance } from '@/workflow/common/validate'
|
|||||||
import { hasPermission } from '@/utils/permission'
|
import { hasPermission } from '@/utils/permission'
|
||||||
import { t } from '@/locales'
|
import { t } from '@/locales'
|
||||||
|
|
||||||
const { user, application } = useStore()
|
const { theme, application } = useStore()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
|
|
||||||
const isDefaultTheme = computed(() => {
|
const isDefaultTheme = computed(() => {
|
||||||
return user.isDefaultTheme()
|
return theme.isDefaultTheme()
|
||||||
})
|
})
|
||||||
const {
|
const {
|
||||||
params: { id },
|
params: { id },
|
||||||
|
|||||||
@ -43,10 +43,10 @@ import { ref, computed } from 'vue'
|
|||||||
import { isAppIcon } from '@/utils/common'
|
import { isAppIcon } from '@/utils/common'
|
||||||
import useStore from '@/stores'
|
import useStore from '@/stores'
|
||||||
|
|
||||||
const { user } = useStore()
|
const { theme } = useStore()
|
||||||
|
|
||||||
const isDefaultTheme = computed(() => {
|
const isDefaultTheme = computed(() => {
|
||||||
return user.isDefaultTheme()
|
return theme.isDefaultTheme()
|
||||||
})
|
})
|
||||||
|
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
|
|||||||
@ -105,7 +105,7 @@
|
|||||||
<span
|
<span
|
||||||
:style="{
|
:style="{
|
||||||
'font-size': item === 'OAUTH2' ? '8px' : '10px',
|
'font-size': item === 'OAUTH2' ? '8px' : '10px',
|
||||||
color: user.themeInfo?.theme,
|
color: theme.themeInfo?.theme,
|
||||||
}"
|
}"
|
||||||
>{{ item }}</span
|
>{{ item }}</span
|
||||||
>
|
>
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
<login-layout v-if="!loading" v-loading="loading || sendLoading">
|
<login-layout v-if="!loading" v-loading="loading || sendLoading">
|
||||||
<LoginContainer
|
<LoginContainer
|
||||||
:subTitle="
|
:subTitle="
|
||||||
user.themeInfo?.slogan ? user.themeInfo?.slogan : $t('views.system.theme.defaultSlogan')
|
theme.themeInfo?.slogan ? theme.themeInfo?.slogan : $t('views.system.theme.defaultSlogan')
|
||||||
"
|
"
|
||||||
>
|
>
|
||||||
<h2 class="mb-24">{{ $t('views.login.forgotPassword') }}</h2>
|
<h2 class="mb-24">{{ $t('views.login.forgotPassword') }}</h2>
|
||||||
@ -81,7 +81,7 @@ import { t } from '@/locales'
|
|||||||
import useStore from '@/stores'
|
import useStore from '@/stores'
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const { user } = useStore()
|
const { theme } = useStore()
|
||||||
|
|
||||||
const CheckEmailForm = ref<CheckCodeRequest>({
|
const CheckEmailForm = ref<CheckCodeRequest>({
|
||||||
email: '',
|
email: '',
|
||||||
|
|||||||
@ -96,7 +96,7 @@
|
|||||||
<span
|
<span
|
||||||
:style="{
|
:style="{
|
||||||
'font-size': item === 'OAUTH2' ? '8px' : '10px',
|
'font-size': item === 'OAUTH2' ? '8px' : '10px',
|
||||||
color: user.themeInfo?.theme,
|
color: theme.themeInfo?.theme,
|
||||||
}"
|
}"
|
||||||
>{{ item }}</span
|
>{{ item }}</span
|
||||||
>
|
>
|
||||||
|
|||||||
@ -263,16 +263,16 @@ import { MsgSuccess, MsgError } from '@/utils/message'
|
|||||||
import useStore from '@/stores'
|
import useStore from '@/stores'
|
||||||
import { t } from '@/locales'
|
import { t } from '@/locales'
|
||||||
|
|
||||||
const { user } = useStore()
|
const { theme } = useStore()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
onBeforeRouteLeave((to, from) => {
|
onBeforeRouteLeave((to, from) => {
|
||||||
user.setTheme(cloneTheme.value)
|
theme.setTheme(cloneTheme.value)
|
||||||
})
|
})
|
||||||
|
|
||||||
const themeInfo = computed(() => user.themeInfo)
|
const themeInfo = computed(() => theme.themeInfo)
|
||||||
const isDefaultTheme = computed(() => {
|
const isDefaultTheme = computed(() => {
|
||||||
return user.isDefaultTheme()
|
return theme.isDefaultTheme()
|
||||||
})
|
})
|
||||||
|
|
||||||
const themeFormRef = ref<FormInstance>()
|
const themeFormRef = ref<FormInstance>()
|
||||||
@ -308,23 +308,23 @@ const onChange = (file: any, fileList: UploadFiles, attr: string) => {
|
|||||||
} else {
|
} else {
|
||||||
themeForm.value[attr] = file.raw
|
themeForm.value[attr] = file.raw
|
||||||
}
|
}
|
||||||
user.setTheme(themeForm.value)
|
theme.setTheme(themeForm.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
function changeThemeHandle(val: string) {
|
function changeThemeHandle(val: string) {
|
||||||
if (val !== 'custom') {
|
if (val !== 'custom') {
|
||||||
themeForm.value.theme = val
|
themeForm.value.theme = val
|
||||||
user.setTheme(themeForm.value)
|
theme.setTheme(themeForm.value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function customColorHandle(val: string) {
|
function customColorHandle(val: string) {
|
||||||
themeForm.value.theme = val
|
themeForm.value.theme = val
|
||||||
user.setTheme(themeForm.value)
|
theme.setTheme(themeForm.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetTheme() {
|
function resetTheme() {
|
||||||
user.setTheme(cloneTheme.value)
|
theme.setTheme(cloneTheme.value)
|
||||||
themeForm.value = cloneDeep(themeInfo.value)
|
themeForm.value = cloneDeep(themeInfo.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -342,7 +342,7 @@ function resetForm(val: string) {
|
|||||||
...defaultPlatformSetting,
|
...defaultPlatformSetting,
|
||||||
}
|
}
|
||||||
|
|
||||||
user.setTheme(themeForm.value)
|
theme.setTheme(themeForm.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateTheme = async (formEl: FormInstance | undefined, test?: string) => {
|
const updateTheme = async (formEl: FormInstance | undefined, test?: string) => {
|
||||||
@ -354,7 +354,7 @@ const updateTheme = async (formEl: FormInstance | undefined, test?: string) => {
|
|||||||
fd.append(item, themeForm.value[item])
|
fd.append(item, themeForm.value[item])
|
||||||
})
|
})
|
||||||
ThemeApi.postThemeInfo(fd, loading).then((res) => {
|
ThemeApi.postThemeInfo(fd, loading).then((res) => {
|
||||||
user.theme()
|
theme.theme()
|
||||||
cloneTheme.value = cloneDeep(themeForm.value)
|
cloneTheme.value = cloneDeep(themeForm.value)
|
||||||
MsgSuccess(t('views.system.theme.saveSuccess'))
|
MsgSuccess(t('views.system.theme.saveSuccess'))
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user