Skip to content

Commit

Permalink
Merge pull request #571 from sugarforever/feat/default-page
Browse files Browse the repository at this point in the history
feat: support custom the default page
  • Loading branch information
satrong authored Sep 5, 2024
2 parents 39692cb + e5c4a35 commit a72ab0d
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 3 deletions.
14 changes: 14 additions & 0 deletions components/settings/LanguageSelectMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import { LanguageList, findLanguageItemByLanguageName } from '@/config/i18n'
const { locale, setLocale, t } = useI18n()
const links = useMenus()
const defaultPage = useCookie('default-page', { path: '/', default: () => DEFAULT_PAGE_LINK })
const selectLanguage = computed({
get() {
Expand All @@ -11,6 +13,11 @@ const selectLanguage = computed({
setLocale(val.code)
}
})
const defaultPageName = computed(() => {
return links.value.find(el => el.to === defaultPage.value)?.label || ''
})
function returnData() {
return findLanguageItemByLanguageName(locale.value)
}
Expand All @@ -29,6 +36,13 @@ function returnData() {
</template>
</USelectMenu>
</UFormGroup>
<UFormGroup :label="t('settings.defaultPage')">
<USelectMenu :options="links" valueAttribute="to" v-model="defaultPage">
<template #label>
<span>{{ defaultPageName }}</span>
</template>
</USelectMenu>
</UFormGroup>
</SettingsCard>
</ClientOnly>
</template>
5 changes: 4 additions & 1 deletion composables/useMenus.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@

export const DEFAULT_PAGE_LINK = '/welcome'

export function useMenus() {
const { t } = useI18n()

return computed(() => [
{ label: t('menu.home'), icon: 'i-heroicons-home', to: '/' },
{ label: t('menu.home'), icon: 'i-heroicons-home', to: '/welcome' },
{ label: t('menu.models'), icon: 'i-heroicons-rectangle-stack', to: '/models' },
{ label: t('menu.instructions'), icon: 'i-iconoir-terminal', to: '/instructions' },
{ label: t('menu.knowledgeBases'), icon: 'i-heroicons-book-open', to: '/knowledgebases' },
Expand Down
3 changes: 2 additions & 1 deletion locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@
"modelNameExist": "Model name already exists",
"modelNameSetting": "Custom model name",
"modelNameTip": "Please enter model name",
"removeCustomService": "Delete current custom service"
"removeCustomService": "Delete current custom service",
"defaultPage": "Default Page"
},
"auth": {
"signIn": "Sign In",
Expand Down
3 changes: 2 additions & 1 deletion locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@
"modelNameSetting": "自定义模型名称",
"modelNameExist": "模型名称已存在",
"removeCustomService": "删除自定义 API 服务",
"ensureRemoveCustomService": "确定要删除该自定义 API 服务吗?"
"ensureRemoveCustomService": "确定要删除该自定义 API 服务吗?",
"defaultPage": "默认页面"
},
"auth": {
"signIn": "登录",
Expand Down
8 changes: 8 additions & 0 deletions middleware/defaultPage.global.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

export default defineNuxtRouteMiddleware((to, from) => {
const defaultPage = useCookie('default-page', { path: '/', default: () => DEFAULT_PAGE_LINK })

if (to.path === '/') {
return navigateTo(defaultPage.value)
}
})
23 changes: 23 additions & 0 deletions pages/welcome.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<script setup>
const { t } = useI18n()
</script>
<template>
<div class="text-lg mx-auto max-w-6xl">
<h1 class="font-bold text-2xl my-8">{{ t("home.welcome") }}</h1>
<p v-html="t('home.description')"></p>

<h2 class="font-bold text-xl my-4">{{ t('home.quickStart') }}</h2>

<ul class="list-decimal list-inside">
<li v-html="t('home.step1')"></li>
<li v-html="t('home.step2')"></li>
<li>
{{ t('home.step3') }}
<ul class="list-disc list-inside ml-4">
<li v-html="t('home.step3_1')"></li>
<li v-html="t('home.step3_2')"></li>
</ul>
</li>
</ul>
</div>
</template>

0 comments on commit a72ab0d

Please sign in to comment.