Skip to content

Commit

Permalink
feat(projects): add LangSwitch to component, fix login page i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed Nov 7, 2023
1 parent 50b722c commit e435b18
Show file tree
Hide file tree
Showing 19 changed files with 169 additions and 99 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"email": "soybeanjs@outlook.com",
"url": "https://github.com/soybeanjs"
},
"packageManager": "pnpm@8.10.2",
"scripts": {
"dev": "vite",
"build": "run-s typecheck build-only",
Expand Down
61 changes: 46 additions & 15 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions src/components/common/lang-switch.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<script setup lang="ts">
defineOptions({
name: 'LangSwitch'
});
interface Props {
lang: App.I18n.LangType;
langOptions: App.I18n.LangOption[];
}
defineProps<Props>();
type Emits = {
(e: 'changeLang', lang: App.I18n.LangType): void;
};
const emits = defineEmits<Emits>();
function changeLang(lang: App.I18n.LangType) {
emits('changeLang', lang);
}
</script>

<template>
<ADropdown placement="bottom">
<AButton type="text" class="h-full">
<div class="flex-y-center">
<SvgIcon icon="heroicons:language" class="text-icon" />
</div>
</AButton>
<template #overlay>
<AMenu :selected-keys="[lang]">
<AMenuItem v-for="option in langOptions" :key="option.key" @click="changeLang(option.key)">
{{ option.label }}
</AMenuItem>
</AMenu>
</template>
</ADropdown>
</template>

<style scoped></style>
13 changes: 6 additions & 7 deletions src/constants/app.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { $t } from '@/locales';
import { transformObjectToOption } from '@/utils/common';

export const loginModuleLabels: Record<UnionKey.LoginModule, string> = {
'pwd-login': $t('page.login.pwdLogin.title'),
'code-login': $t('page.login.codeLogin.title'),
register: $t('page.login.register.title'),
'reset-pwd': $t('page.login.resetPwd.title'),
'bind-wechat': $t('page.login.bindWeChat.title')
export const loginModuleLabels: Record<UnionKey.LoginModule, App.I18n.I18nKey> = {
'pwd-login': 'page.login.pwdLogin.title',
'code-login': 'page.login.codeLogin.title',
register: 'page.login.register.title',
'reset-pwd': 'page.login.resetPwd.title',
'bind-wechat': 'page.login.bindWeChat.title'
};

export const themeLayoutModeLabels: Record<UnionKey.ThemeLayoutMode, string> = {
Expand Down
44 changes: 0 additions & 44 deletions src/layouts/modules/global-header/components/switch-lang.vue

This file was deleted.

15 changes: 10 additions & 5 deletions src/layouts/modules/global-header/components/user-avatar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ defineOptions({
name: 'UserAvatar'
});
const { resetStore } = useAuthStore();
const { routerPushByKey } = useRouterPush();
const auth = useAuthStore();
const { routerPushByKey, toLogin } = useRouterPush();
function loginOrRegister() {
toLogin();
}
function logout() {
Modal.confirm({
Expand All @@ -18,18 +22,19 @@ function logout() {
okText: $t('common.confirm'),
cancelText: $t('common.cancel'),
onOk: () => {
resetStore();
auth.resetStore();
}
});
}
</script>

<template>
<ADropdown placement="bottomRight">
<AButton v-if="!auth.isLogin" @click="loginOrRegister">{{ $t('page.login.common.loginOrRegister') }}</AButton>
<ADropdown v-else placement="bottomRight">
<AButton type="text" class="h-full">
<div class="flex-y-center">
<SvgIcon icon="ph:user-circle" class="text-icon-large" />
<span class="pl-8px text-16px font-medium">Soybean</span>
<span class="pl-8px text-16px font-medium">{{ auth.userInfo.userName }}</span>
</div>
</AButton>
<template #overlay>
Expand Down
3 changes: 1 addition & 2 deletions src/layouts/modules/global-header/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import { useAppStore } from '@/store/modules/app';
import { useThemeStore } from '@/store/modules/theme';
// import GlobalLogo from '../../components/global-logo.vue';
import SwitchLang from './components/switch-lang.vue';
import UserAvatar from './components/user-avatar.vue';
const app = useAppStore();
Expand All @@ -19,7 +18,7 @@ defineOptions({
<MenuToggler :collapsed="app.siderCollapse" @click="app.toggleSiderCollapse" />
</div>
<div class="flex justify-end h-full">
<SwitchLang />
<LangSwitch :lang="app.locale" :lang-options="app.localeOptions" @change-lang="app.changeLocale" />
<ColorSchemaSwitch
:color-schema="themeStore.colorScheme"
:is-dark="themeStore.darkMode"
Expand Down
11 changes: 11 additions & 0 deletions src/layouts/modules/global-tab/context-menu.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script setup lang="ts">
defineOptions({
name: 'ContextMenu'
});
</script>

<template>
<div></div>
</template>

<style scoped></style>
3 changes: 1 addition & 2 deletions src/layouts/modules/global-tab/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const { width: bsWrapperWidth, left: bsWrapperLeft } = useElementBounding(bsWrap
const bsScroll = ref<InstanceType<typeof BetterScroll>>();
const tabRef = ref<HTMLElement>();
const isChromeMode = false;
const isChromeMode = true;
const TAB_DATA_ID = 'data-tab-id';
Expand Down Expand Up @@ -96,7 +96,6 @@ init();
<PageTab
v-for="item in tab.tabs"
:key="item.id"
mode="button"
:[TAB_DATA_ID]="item.id"
:dark-mode="theme.darkMode"
:active="item.id === tab.activeTabId"
Expand Down
1 change: 1 addition & 0 deletions src/locales/lang/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const local: App.I18n.Schema = {
page: {
login: {
common: {
loginOrRegister: 'Login / Register',
userNamePlaceholder: 'Please enter user name',
phonePlaceholder: 'Please enter phone number',
codePlaceholder: 'Please enter verification code',
Expand Down
1 change: 1 addition & 0 deletions src/locales/lang/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const local: App.I18n.Schema = {
page: {
login: {
common: {
loginOrRegister: '登录 / 注册',
userNamePlaceholder: '请输入用户名',
phonePlaceholder: '请输入手机号',
codePlaceholder: '请输入验证码',
Expand Down
Loading

0 comments on commit e435b18

Please sign in to comment.