-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(client): separate settings to subroutes
- Loading branch information
Showing
6 changed files
with
147 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<template> | ||
<k-content> | ||
<k-schema :schema="schema" :initial="config" v-model="config"></k-schema> | ||
</k-content> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { config, Schema } from '..' | ||
const schema = Schema.object({ | ||
locale: Schema.union(['zh-CN', 'en-US']).description('语言设置。'), | ||
}).description('通用设置') | ||
</script> | ||
|
||
<style lang="scss"> | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<template> | ||
<k-layout main="darker page-settings"> | ||
<template #left> | ||
<el-scrollbar> | ||
<el-tree | ||
ref="tree" | ||
:data="data" | ||
:default-expand-all="true" | ||
@node-click="handleClick" | ||
></el-tree> | ||
</el-scrollbar> | ||
</template> | ||
<keep-alive> | ||
<component :is="components[path].component" :key="path" /> | ||
</keep-alive> | ||
</k-layout> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { useRoute, useRouter } from 'vue-router' | ||
import { computed } from 'vue' | ||
import General from './general.vue' | ||
import Theme from './theme.vue' | ||
const route = useRoute() | ||
const router = useRouter() | ||
const components = { | ||
'': { | ||
label: '通用', | ||
component: General, | ||
}, | ||
appearance: { | ||
label: '外观', | ||
component: Theme, | ||
}, | ||
} | ||
interface Tree { | ||
id: string | ||
label: string | ||
children?: Tree[] | ||
} | ||
const data = computed(() => { | ||
return Object.entries(components).map<Tree>(([id, { label }]) => ({ | ||
id, | ||
label, | ||
})) | ||
}) | ||
function handleClick(tree: Tree) { | ||
if (tree.children) return | ||
path.value = tree.id | ||
} | ||
const path = computed({ | ||
get() { | ||
const name = route.params.name.toString() | ||
return name in components ? name : '' | ||
}, | ||
set(value) { | ||
if (!(value in components)) value = '' | ||
router.replace('/settings/' + value) | ||
}, | ||
}) | ||
</script> | ||
|
||
<style lang="scss"> | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { defineComponent, h, resolveComponent } from 'vue' | ||
import { Console } from '@koishijs/plugin-console' | ||
import { isNullable } from 'cosmokit' | ||
import { Store, store } from './data' | ||
|
||
export type Field = keyof Console.Services | ||
|
||
export namespace Card { | ||
export function create(render: Function, fields: readonly Field[] = []) { | ||
return defineComponent({ | ||
render: () => fields.every(key => store[key]) ? render() : null, | ||
}) | ||
} | ||
|
||
export interface NumericOptions { | ||
icon: string | ||
title: string | ||
type?: string | ||
fields?: Field[] | ||
content: (store: Store) => any | ||
} | ||
|
||
export function numeric({ type, icon, fields, title, content }: NumericOptions) { | ||
if (!type) { | ||
return defineComponent(() => () => { | ||
if (!fields.every(key => store[key])) return | ||
return h(resolveComponent('k-numeric'), { icon, title }, () => content(store)) | ||
}) | ||
} | ||
|
||
return defineComponent(() => () => { | ||
if (!fields.every(key => store[key])) return | ||
let value = content(store) | ||
if (isNullable(value)) return | ||
if (type === 'size') { | ||
if (value >= (1 << 20) * 1000) { | ||
value = (value / (1 << 30)).toFixed(1) + ' GB' | ||
} else if (value >= (1 << 10) * 1000) { | ||
value = (value / (1 << 20)).toFixed(1) + ' MB' | ||
} else { | ||
value = (value / (1 << 10)).toFixed(1) + ' KB' | ||
} | ||
} | ||
return h(resolveComponent('k-numeric'), { icon, title }, () => [value]) | ||
}) | ||
} | ||
} |