-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c2e45fe
commit ddf4766
Showing
8 changed files
with
202 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<script setup lang="ts"> | ||
import { computed, ref, watchEffect } from 'vue' | ||
import { NAlert, NForm, NFormItem } from 'naive-ui' | ||
import type { Config } from 'fcitx5-js' | ||
import IntegerOption from './option/IntegerOption.vue' | ||
import BooleanOption from './option/BooleanOption.vue' | ||
import UnknownOption from './option/UnknownOption.vue' | ||
import { isMobile } from './util' | ||
const props = defineProps<{ | ||
path: string | ||
config: Config | ||
}>() | ||
const labelPlacement = computed(() => isMobile.value ? 'top' : 'left') | ||
function toComponent(type: string) { | ||
switch (type) { | ||
case 'Integer': | ||
return IntegerOption | ||
case 'Boolean': | ||
return BooleanOption | ||
default: | ||
return UnknownOption | ||
} | ||
} | ||
function extractValue(reset: boolean) { | ||
const value: { [key: string]: any } = {} | ||
if ('Children' in props.config) { | ||
for (const child of props.config.Children) { | ||
value[child.Option] = reset ? child.DefaultValue : child.Value | ||
} | ||
} | ||
return value | ||
} | ||
const form = ref<{ [key: string]: any }>({}) | ||
watchEffect(() => { | ||
form.value = extractValue(false) | ||
}) | ||
function reset() { | ||
form.value = extractValue(true) | ||
} | ||
function get() { | ||
return form.value | ||
} | ||
defineExpose({ | ||
reset, | ||
get, | ||
}) | ||
</script> | ||
|
||
<template> | ||
<NAlert v-if="'ERROR' in config" title="Error" type="error"> | ||
{{ config.ERROR }} | ||
</NAlert> | ||
<NForm | ||
v-else | ||
:model="form" | ||
:label-placement="labelPlacement" | ||
label-width="200px" | ||
> | ||
<NFormItem | ||
v-for="child in config.Children" | ||
:key="`${path}/${child.Option}`" | ||
:label="child.Description" | ||
> | ||
<component | ||
:is="toComponent(child.Type)" | ||
:config="child" | ||
:value="form[child.Option]" | ||
:on-update="(v) => { form[child.Option] = v }" | ||
/> | ||
</NFormItem> | ||
</NForm> | ||
</template> |
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,15 @@ | ||
<script setup lang="ts"> | ||
import { NSwitch } from 'naive-ui' | ||
defineProps<{ | ||
value: string | ||
onUpdate: (value: string) => void | ||
}>() | ||
</script> | ||
|
||
<template> | ||
<NSwitch | ||
:value="value === 'True'" | ||
@update:value="(v) => onUpdate(v ? 'True' : 'False')" | ||
/> | ||
</template> |
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,23 @@ | ||
<script setup lang="ts"> | ||
import { NInputNumber } from 'naive-ui' | ||
defineProps<{ | ||
config: { | ||
IntMax?: string | ||
IntMin?: string | ||
} | ||
value: string | ||
onUpdate: (value: string) => void | ||
}>() | ||
</script> | ||
|
||
<template> | ||
<NInputNumber | ||
:value="Number(value)" | ||
:precision="0" | ||
:min="config.IntMin && Number(config.IntMin)" | ||
:max="config.IntMax && Number(config.IntMax)" | ||
clearable | ||
@update:value="(v) => onUpdate(String(v))" | ||
/> | ||
</template> |
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,9 @@ | ||
<script setup lang="ts"> | ||
defineProps<{ | ||
config: any | ||
}>() | ||
</script> | ||
|
||
<template> | ||
<div>{{ config }}</div> | ||
</template> |
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,5 @@ | ||
import { computed } from 'vue' | ||
import { useBreakpoint } from 'vooks' | ||
|
||
const breakpoint = useBreakpoint() | ||
export const isMobile = computed(() => breakpoint.value === 'xs' || breakpoint.value === 's') |
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 |
---|---|---|
|
@@ -13,6 +13,7 @@ export default defineConfig({ | |
external: [ | ||
'vue', | ||
'naive-ui', | ||
'vooks', | ||
], | ||
}, | ||
}, | ||
|