Refactor user settings (#209)
Co-authored-by: AceDataCloud <office@acedata.cloud>
This commit is contained in:
1 parent
1964814509
commit
5cbddd5d95
32 files changed
+2534
-1160
No files matched your search
@@ -0,0 +1,33 @@
|
||||
<template>
|
||||
<img :src="user?.avatar || defaultAvatar" class="avatar" />
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import defaultAvatar from '@/assets/images/avatar.png';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'UserAvatar',
|
||||
data() {
|
||||
return {
|
||||
defaultAvatar
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
user() {
|
||||
return this.$store.getters?.user;
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.avatar {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
border-radius: 50%;
|
||||
object-fit: cover;
|
||||
cursor: pointer;
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,101 @@
|
||||
<template>
|
||||
<div class="relative inline-block text-left">
|
||||
<div @click="toggleMenu">
|
||||
<user-avatar class="cursor-pointer" />
|
||||
</div>
|
||||
<transition name="fade">
|
||||
<el-card v-if="showMenu" class="absolute right-0 mt-2 min-w-[220px] z-50 p-0">
|
||||
<div v-if="user.email" class="px-4 py-2 text-sm font-medium">
|
||||
{{ user?.email }}
|
||||
</div>
|
||||
<el-divider v-if="user.email" class="mb-1 mt-1" />
|
||||
<div class="py-1">
|
||||
<button class="block w-full px-4 py-2 text-left text-sm rounded-lg" @click="onSettings">
|
||||
<font-awesome-icon icon="fa-solid fa-cog" class="mr-1" />
|
||||
{{ $t('common.nav.setting') }}
|
||||
</button>
|
||||
<button class="block w-full px-4 py-2 text-left text-sm rounded-lg" @click="onDistribution">
|
||||
<font-awesome-icon icon="fa-solid fa-coins" class="mr-1" />
|
||||
{{ $t('common.nav.distribution') }}
|
||||
</button>
|
||||
<button class="block w-full px-4 py-2 text-left text-sm rounded-lg" @click="onConsole">
|
||||
<font-awesome-icon icon="fa-solid fa-compass" class="mr-1" />
|
||||
{{ $t('common.nav.console') }}
|
||||
</button>
|
||||
<button class="block w-full px-4 py-2 text-left text-sm rounded-lg" @click="onLogout">
|
||||
<font-awesome-icon icon="fa-solid fa-arrow-right-from-bracket" class="mr-1" />
|
||||
{{ $t('common.nav.logOut') }}
|
||||
</button>
|
||||
</div>
|
||||
</el-card>
|
||||
</transition>
|
||||
<user-setting v-model:visible="showSetting" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import UserAvatar from '@/components/user/Avatar.vue';
|
||||
import UserSetting from '@/components/user/Setting.vue';
|
||||
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
||||
import { ROUTE_CONSOLE_ROOT, ROUTE_DISTRIBUTION_INDEX } from '@/router';
|
||||
import { ElDivider, ElCard } from 'element-plus';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'UserCenter',
|
||||
components: { UserAvatar, UserSetting, FontAwesomeIcon, ElDivider, ElCard },
|
||||
data() {
|
||||
return {
|
||||
showMenu: false,
|
||||
showSetting: false
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
user() {
|
||||
return this.$store.getters?.user;
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
document.addEventListener('click', this.closeMenu);
|
||||
},
|
||||
unmounted() {
|
||||
document.removeEventListener('click', this.closeMenu);
|
||||
},
|
||||
methods: {
|
||||
toggleMenu() {
|
||||
this.showMenu = !this.showMenu;
|
||||
},
|
||||
closeMenu(event: MouseEvent) {
|
||||
const target = event.target as HTMLElement;
|
||||
if (!this.$el.contains(target)) {
|
||||
this.showMenu = false;
|
||||
}
|
||||
},
|
||||
async onLogout() {
|
||||
await this.$store.dispatch('logout');
|
||||
},
|
||||
onConsole() {
|
||||
this.$router.push({ name: ROUTE_CONSOLE_ROOT });
|
||||
},
|
||||
onDistribution() {
|
||||
this.$router.push({
|
||||
name: ROUTE_DISTRIBUTION_INDEX
|
||||
});
|
||||
},
|
||||
onSettings() {
|
||||
this.showSetting = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.fade-enter-active,
|
||||
.fade-leave-active {
|
||||
transition: opacity 0.2s;
|
||||
}
|
||||
.fade-enter-from,
|
||||
.fade-leave-to {
|
||||
opacity: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,72 @@
|
||||
<template>
|
||||
<el-dropdown trigger="click" @command="onSelectLocale">
|
||||
<span class="el-dropdown-link">
|
||||
{{ currentLabel }}
|
||||
<el-icon class="el-icon--right"><arrow-down /></el-icon>
|
||||
</span>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item v-for="(locale, idx) in locales" :key="idx" :command="locale.value">
|
||||
{{ locale.label }}
|
||||
</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { ElDropdown, ElDropdownMenu, ElDropdownItem, ElIcon } from 'element-plus';
|
||||
import { ArrowDown } from '@element-plus/icons-vue';
|
||||
import { SUPPORTED_LOCALES, setI18nLanguage } from '@/i18n';
|
||||
import { setCookie } from 'typescript-cookie';
|
||||
import { getDomain } from '@/utils/initializer';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'LocaleSelector',
|
||||
components: {
|
||||
ElDropdown,
|
||||
ElDropdownMenu,
|
||||
ElDropdownItem,
|
||||
ElIcon,
|
||||
ArrowDown
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
locales: SUPPORTED_LOCALES
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
value(): string {
|
||||
return this.$i18n.locale;
|
||||
},
|
||||
currentLabel(): string {
|
||||
const found = this.locales.find((l) => l.value === this.value);
|
||||
return found ? found.label : this.value;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async onSelectLocale(locale: string) {
|
||||
this.$router.push({ query: { ...this.$route.query, locale: undefined } });
|
||||
await setI18nLanguage(locale);
|
||||
setCookie('LOCALE', locale, {
|
||||
path: '/',
|
||||
domain: getDomain()
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.el-dropdown-link {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
cursor: pointer;
|
||||
color: var(--el-text-color-primary);
|
||||
font-weight: 500;
|
||||
}
|
||||
.el-icon--right {
|
||||
margin-left: 4px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,104 @@
|
||||
<template>
|
||||
<el-dialog :model-value="visible" @close="onClose">
|
||||
<div class="flex settings">
|
||||
<aside class="w-56 border-r">
|
||||
<nav class="flex flex-col p-2 space-y-1">
|
||||
<button
|
||||
v-for="(item, index) in navItems"
|
||||
:key="index"
|
||||
:class="[
|
||||
'flex items-center px-4 py-2 text-sm rounded-lg cursor-pointer',
|
||||
activeTab === item.key ? 'active' : ''
|
||||
]"
|
||||
@click="activeTab = item.key"
|
||||
>
|
||||
<font-awesome-icon :icon="item.icon" class="mr-2" />
|
||||
{{ item.label }}
|
||||
</button>
|
||||
</nav>
|
||||
</aside>
|
||||
<main class="flex-1 p-6 overflow-y-auto">
|
||||
<div v-if="activeTab === 'general'">
|
||||
<general-setting />
|
||||
</div>
|
||||
<div v-else-if="activeTab === 'site' && isSiteAdmin">
|
||||
<site-setting />
|
||||
</div>
|
||||
<div v-else-if="activeTab === 'seo' && isSiteAdmin">
|
||||
<seo-setting />
|
||||
</div>
|
||||
<div v-else-if="activeTab === 'distribution' && isSiteAdmin">
|
||||
<distribution-setting />
|
||||
</div>
|
||||
<div v-else-if="activeTab === 'function' && isSiteAdmin">
|
||||
<function-setting />
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { ElDialog } from 'element-plus';
|
||||
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
||||
import { faCog, faBell, faUserShield, faMagic, faMoneyBill } from '@fortawesome/free-solid-svg-icons';
|
||||
import GeneralSetting from '@/components/setting/General.vue';
|
||||
import SiteSetting from '@/components/setting/Site.vue';
|
||||
import SeoSetting from '@/components/setting/Seo.vue';
|
||||
import DistributionSetting from '@/components/setting/Distribution.vue';
|
||||
import FunctionSetting from '@/components/setting/Function.vue';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'UserSetting',
|
||||
components: {
|
||||
ElDialog,
|
||||
FontAwesomeIcon,
|
||||
GeneralSetting,
|
||||
SiteSetting,
|
||||
SeoSetting,
|
||||
DistributionSetting,
|
||||
FunctionSetting
|
||||
},
|
||||
props: {
|
||||
visible: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
},
|
||||
emits: ['update:visible'],
|
||||
data() {
|
||||
return {
|
||||
activeTab: 'general',
|
||||
showSuggestions: true,
|
||||
navItems: [
|
||||
{ key: 'general', label: this.$t('common.settings.general'), icon: faCog },
|
||||
{ key: 'site', label: this.$t('common.settings.site'), icon: faBell },
|
||||
{ key: 'seo', label: this.$t('common.settings.seo'), icon: faUserShield },
|
||||
{ key: 'distribution', label: this.$t('common.settings.distribution'), icon: faMoneyBill },
|
||||
{ key: 'function', label: this.$t('common.settings.function'), icon: faMagic }
|
||||
]
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
currentTabTitle() {
|
||||
const current = this.navItems.find((item) => item.key === this.activeTab);
|
||||
return current ? current.label : '';
|
||||
},
|
||||
isSiteAdmin(): boolean {
|
||||
return !!this.$store?.state?.site?.admins?.includes(this.$store.getters.user?.id);
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onClose() {
|
||||
this.$emit('update:visible', false);
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.settings {
|
||||
height: 460px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,85 @@
|
||||
<template>
|
||||
<el-dropdown trigger="click" @command="onSelect">
|
||||
<span class="el-dropdown-link">
|
||||
{{ currentLabel }}
|
||||
<el-icon class="el-icon--right"><arrow-down /></el-icon>
|
||||
</span>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item command="light">{{ $t('common.theme.light') }}</el-dropdown-item>
|
||||
<el-dropdown-item command="dark">{{ $t('common.theme.dark') }}</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { ElDropdown, ElDropdownMenu, ElDropdownItem, ElIcon } from 'element-plus';
|
||||
import { getDomain } from '@/utils';
|
||||
import { getCookie, setCookie } from 'typescript-cookie';
|
||||
import { ArrowDown } from '@element-plus/icons-vue';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ThemeSelector',
|
||||
components: {
|
||||
ArrowDown,
|
||||
ElDropdown,
|
||||
ElDropdownMenu,
|
||||
ElDropdownItem,
|
||||
ElIcon
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
theme: 'light' as 'light' | 'dark'
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
currentLabel(): string {
|
||||
return this.theme === 'dark'
|
||||
? (this.$t('common.theme.dark') as string)
|
||||
: (this.$t('common.theme.light') as string);
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.theme = this.loadFromCookie();
|
||||
this.applyTheme();
|
||||
},
|
||||
methods: {
|
||||
onSelect(command: 'light' | 'dark') {
|
||||
this.theme = command;
|
||||
this.applyTheme();
|
||||
},
|
||||
applyTheme() {
|
||||
setCookie('THEME', this.theme, {
|
||||
path: '/',
|
||||
domain: getDomain()
|
||||
});
|
||||
if (this.theme === 'dark') {
|
||||
document.documentElement.classList.add('dark');
|
||||
} else {
|
||||
document.documentElement.classList.remove('dark');
|
||||
}
|
||||
},
|
||||
loadFromCookie(): 'light' | 'dark' {
|
||||
const saved = getCookie('THEME');
|
||||
return saved === 'dark' ? 'dark' : 'light';
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.demonstration {
|
||||
margin-right: 8px;
|
||||
cursor: pointer;
|
||||
color: var(--el-text-color-regular);
|
||||
}
|
||||
.el-dropdown-link {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
cursor: pointer;
|
||||
color: var(--el-text-color-primary);
|
||||
font-weight: 500;
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user