|
| 1 | +<script setup lang="ts"> |
| 2 | +import { computed, ref, watchEffect } from 'vue' |
| 3 | +import { NLayout, NLayoutFooter, NLayoutSider, NMenu } from 'naive-ui' |
| 4 | +import BasicConfig from './BasicConfig.vue' |
| 5 | +import FooterButtons from './FooterButtons.vue' |
| 6 | +import { extractValue } from './util' |
| 7 | +
|
| 8 | +defineProps<{ |
| 9 | + onClose: () => void |
| 10 | +}>() |
| 11 | +
|
| 12 | +const options = window.fcitx.getAddons().map(category => ({ |
| 13 | + type: 'group', |
| 14 | + key: category.id, |
| 15 | + label: category.name, |
| 16 | + children: category.addons.map(addon => ({ |
| 17 | + key: addon.id, |
| 18 | + label: addon.name, |
| 19 | + })), |
| 20 | +})) |
| 21 | +
|
| 22 | +const addon = ref(options[0].children[0].key) |
| 23 | +
|
| 24 | +const uri = computed(() => `fcitx://config/addon/${addon.value}`) |
| 25 | +
|
| 26 | +const config = computed(() => window.fcitx.getConfig(uri.value)) |
| 27 | +
|
| 28 | +const collapsed = ref(false) |
| 29 | +
|
| 30 | +const form = ref({}) |
| 31 | +
|
| 32 | +watchEffect(() => { |
| 33 | + form.value = extractValue(config.value, false) |
| 34 | +}) |
| 35 | +
|
| 36 | +function reset() { |
| 37 | + form.value = extractValue(config.value, true) |
| 38 | +} |
| 39 | +
|
| 40 | +function apply() { |
| 41 | + window.fcitx.setConfig(uri.value, form.value) |
| 42 | +} |
| 43 | +</script> |
| 44 | + |
| 45 | +<template> |
| 46 | + <NLayout has-sider> |
| 47 | + <NLayoutSider |
| 48 | + bordered |
| 49 | + collapse-mode="width" |
| 50 | + :collapsed="collapsed" |
| 51 | + :native-scrollbar="false" |
| 52 | + show-trigger |
| 53 | + style="max-height: calc(100vh - 100px)" |
| 54 | + @collapse="collapsed = true" |
| 55 | + @expand="collapsed = false" |
| 56 | + > |
| 57 | + <NMenu |
| 58 | + v-model:value="addon" |
| 59 | + :options="options" |
| 60 | + /> |
| 61 | + </NLayoutSider> |
| 62 | + <NLayout style="height: calc(100vh - 100px)"> |
| 63 | + <NLayout |
| 64 | + position="absolute" |
| 65 | + :native-scrollbar="false" |
| 66 | + style="bottom: 50px" |
| 67 | + > |
| 68 | + <BasicConfig |
| 69 | + :path="addon" |
| 70 | + :config="config" |
| 71 | + :value="form" |
| 72 | + style="margin: 16px" |
| 73 | + @update="v => form = v" |
| 74 | + /> |
| 75 | + </NLayout> |
| 76 | + <NLayoutFooter position="absolute"> |
| 77 | + <FooterButtons |
| 78 | + :reset="reset" |
| 79 | + :apply="apply" |
| 80 | + :close="onClose" |
| 81 | + /> |
| 82 | + </NLayoutFooter> |
| 83 | + </NLayout> |
| 84 | + </NLayout> |
| 85 | +</template> |
0 commit comments