Skip to content

Commit 69ed682

Browse files
committed
refactor: options
1 parent 4457cc6 commit 69ed682

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+252
-144
lines changed

src/i18n/message/app/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import dashboardMessages, { type DashboardMessage } from "./dashboard"
1919
import dataManageMessages, { type DataManageMessage } from "./data-manage"
2020
import habitMessages, { type HabitMessage } from "./habit"
2121
import helpUsMessages, { type HelpUsMessage } from "./help-us"
22+
import integrationMessages, { type IntegrationMessage } from './integration'
2223
import limitMessages, { type LimitMessage } from "./limit"
2324
import menuMessages, { type MenuMessage } from "./menu"
2425
import mergeRuleMessages, { type MergeRuleMessage } from "./merge-rule"
@@ -38,6 +39,7 @@ export type AppMessage = {
3839
whitelist: WhitelistMessage
3940
mergeRule: MergeRuleMessage
4041
option: OptionMessage
42+
integration: IntegrationMessage
4143
analysis: AnalysisMessage
4244
menu: MenuMessage
4345
habit: HabitMessage
@@ -63,6 +65,7 @@ const MESSAGE_ROOT: MessageRoot<AppMessage> = {
6365
whitelist: whitelistMessages,
6466
mergeRule: mergeRuleMessages,
6567
option: optionMessages,
68+
integration: integrationMessages,
6669
analysis: analysisMessages,
6770
menu: menuMessages,
6871
habit: habitMessages,
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"en": {
3+
"notification": {
4+
"title": "Notification"
5+
}
6+
}
7+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import resource from './integration-resource.json'
2+
3+
export type IntegrationMessage = {
4+
notification: { title: string }
5+
}
6+
7+
const _default: Messages<IntegrationMessage> = resource
8+
9+
export default _default

src/i18n/message/app/menu-resource.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"siteManage": "Site Management",
4747
"whitelist": "Whitelist",
4848
"mergeRule": "Merge-site Rules",
49+
"integration": "Integrations",
4950
"other": "Other Features",
5051
"helpUs": "Help Translation",
5152
"about": "About"

src/i18n/message/app/menu.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export type MenuMessage = {
2020
siteManage: string
2121
whitelist: string
2222
mergeRule: string
23+
integration: string
2324
other: string
2425
helpUs: string
2526
about: string

src/pages/app/Layout/menu/item.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import { type I18nKey } from "@app/locale"
1010
import { ANALYSIS_ROUTE, MERGE_ROUTE } from "@app/router/constants"
11-
import { Aim, Connection, HelpFilled, Histogram, Memo, MoreFilled, Rank, SetUp, Stopwatch, Timer, View } from "@element-plus/icons-vue"
11+
import { Aim, Connection, Cpu, HelpFilled, Histogram, Memo, MoreFilled, Rank, SetUp, Stopwatch, Timer, View } from "@element-plus/icons-vue"
1212
import { getGuidePageUrl } from "@util/constant/url"
1313
import { type Component } from 'vue'
1414
import About from "../icons/About"
@@ -95,6 +95,10 @@ export const menuGroups = (): MenuGroup[] => [{
9595
title: msg => msg.menu.mergeRule,
9696
route: MERGE_ROUTE,
9797
icon: Rank
98+
}, {
99+
title: msg => msg.menu.integration,
100+
route: '/additional/integration',
101+
icon: Cpu,
98102
}, {
99103
title: msg => msg.base.option,
100104
route: '/additional/option',
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { ElCard, ElSelect } from "element-plus"
2+
import { defineComponent, h, useSlots } from "vue"
3+
import ContentContainer from "../common/ContentContainer"
4+
import { useCategory } from './useCategory'
5+
6+
const _default = defineComponent(() => {
7+
const { category, setCategory, getLabel } = useCategory()
8+
9+
const slots = useSlots()
10+
11+
return () => (
12+
<ContentContainer v-slots={{
13+
filter: () => (
14+
<ElSelect modelValue={category.value} onChange={setCategory}>
15+
{Object.keys(slots).map(c => <ElSelect.Option value={c} label={getLabel(c)} />)}
16+
</ElSelect>
17+
),
18+
default: () => {
19+
const slot = slots[category.value]
20+
return !!slot && <ElCard style={{ "--el-card-padding": '20px 10px' }}>{h(slot)}</ElCard>
21+
}
22+
}} />
23+
)
24+
})
25+
26+
export default _default

src/pages/app/components/Integration/Tabs.ts

Whitespace-only changes.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { defineComponent } from 'vue'
2+
3+
const Integration = defineComponent(() => {
4+
return () => (
5+
<div class="integration">
6+
<h1>Integration</h1>
7+
</div>
8+
)
9+
})
10+
11+
export default Integration
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { type I18nKey, t } from '@app/locale'
2+
import { createStringUnionGuard } from 'typescript-guard'
3+
import { computed, type ShallowRef } from 'vue'
4+
import { type LocationQuery, useRoute, useRouter } from 'vue-router'
5+
6+
export type IntegrationCategory = 'backup' | 'notification'
7+
const isCategory = createStringUnionGuard<IntegrationCategory>('backup', 'notification')
8+
9+
const CATE_LABELS: Record<IntegrationCategory, I18nKey> = {
10+
backup: msg => msg.option.backup.title,
11+
notification: msg => msg.integration.notification.title,
12+
}
13+
14+
const PARAM = "i"
15+
16+
function parseInit(query: LocationQuery): IntegrationCategory | undefined {
17+
const initialQuery = query[PARAM]
18+
const queryVal = Array.isArray(initialQuery) ? initialQuery[0] : initialQuery
19+
return isCategory(queryVal) ? queryVal : undefined
20+
}
21+
22+
export const useCategory = (): {
23+
category: ShallowRef<IntegrationCategory>
24+
setCategory: (value: unknown) => void
25+
getLabel: (value: unknown) => string | undefined
26+
} => {
27+
const route = useRoute()
28+
const router = useRouter()
29+
30+
const category = computed({
31+
set(value: IntegrationCategory) {
32+
const oldQuery = route.query
33+
const query: LocationQuery = {
34+
...oldQuery,
35+
[PARAM]: value,
36+
}
37+
router.replace({ query })
38+
},
39+
get: () => parseInit(route.query) ?? 'backup',
40+
})
41+
42+
const setCategory = (value: unknown) => isCategory(value) && (category.value = value)
43+
const getLabel = (value: unknown) => {
44+
const key = isCategory(value) ? CATE_LABELS[value] : undefined
45+
return key ? t(key) : undefined
46+
}
47+
48+
return { category, setCategory, getLabel }
49+
}

0 commit comments

Comments
 (0)