refactor(client): refactor settings/plugin to use Composition API (#8590)
This commit is contained in:
		| @@ -1,38 +1,38 @@ | |||||||
| <template> | <template> | ||||||
| <div class="_formRoot"> | <div class="_formRoot"> | ||||||
| 	<FormLink to="/settings/plugin/install"><template #icon><i class="fas fa-download"></i></template>{{ $ts._plugin.install }}</FormLink> | 	<FormLink to="/settings/plugin/install"><template #icon><i class="fas fa-download"></i></template>{{ i18n.ts._plugin.install }}</FormLink> | ||||||
|  |  | ||||||
| 	<FormSection> | 	<FormSection> | ||||||
| 		<template #label>{{ $ts.manage }}</template> | 		<template #label>{{ i18n.ts.manage }}</template> | ||||||
| 		<div v-for="plugin in plugins" :key="plugin.id" class="_formBlock _panel" style="padding: 20px;"> | 		<div v-for="plugin in plugins" :key="plugin.id" class="_formBlock _panel" style="padding: 20px;"> | ||||||
| 			<span style="display: flex;"><b>{{ plugin.name }}</b><span style="margin-left: auto;">v{{ plugin.version }}</span></span> | 			<span style="display: flex;"><b>{{ plugin.name }}</b><span style="margin-left: auto;">v{{ plugin.version }}</span></span> | ||||||
|  |  | ||||||
| 			<FormSwitch class="_formBlock" :modelValue="plugin.active" @update:modelValue="changeActive(plugin, $event)">{{ $ts.makeActive }}</FormSwitch> | 			<FormSwitch class="_formBlock" :modelValue="plugin.active" @update:modelValue="changeActive(plugin, $event)">{{ i18n.ts.makeActive }}</FormSwitch> | ||||||
|  |  | ||||||
| 			<MkKeyValue class="_formBlock"> | 			<MkKeyValue class="_formBlock"> | ||||||
| 				<template #key>{{ $ts.author }}</template> | 				<template #key>{{ i18n.ts.author }}</template> | ||||||
| 				<template #value>{{ plugin.author }}</template> | 				<template #value>{{ plugin.author }}</template> | ||||||
| 			</MkKeyValue> | 			</MkKeyValue> | ||||||
| 			<MkKeyValue class="_formBlock"> | 			<MkKeyValue class="_formBlock"> | ||||||
| 				<template #key>{{ $ts.description }}</template> | 				<template #key>{{ i18n.ts.description }}</template> | ||||||
| 				<template #value>{{ plugin.description }}</template> | 				<template #value>{{ plugin.description }}</template> | ||||||
| 			</MkKeyValue> | 			</MkKeyValue> | ||||||
| 			<MkKeyValue class="_formBlock"> | 			<MkKeyValue class="_formBlock"> | ||||||
| 				<template #key>{{ $ts.permission }}</template> | 				<template #key>{{ i18n.ts.permission }}</template> | ||||||
| 				<template #value>{{ plugin.permission }}</template> | 				<template #value>{{ plugin.permission }}</template> | ||||||
| 			</MkKeyValue> | 			</MkKeyValue> | ||||||
|  |  | ||||||
| 			<div style="display: flex; gap: var(--margin); flex-wrap: wrap;"> | 			<div style="display: flex; gap: var(--margin); flex-wrap: wrap;"> | ||||||
| 				<MkButton v-if="plugin.config" inline @click="config(plugin)"><i class="fas fa-cog"></i> {{ $ts.settings }}</MkButton> | 				<MkButton v-if="plugin.config" inline @click="config(plugin)"><i class="fas fa-cog"></i> {{ i18n.ts.settings }}</MkButton> | ||||||
| 				<MkButton inline danger @click="uninstall(plugin)"><i class="fas fa-trash-alt"></i> {{ $ts.uninstall }}</MkButton> | 				<MkButton inline danger @click="uninstall(plugin)"><i class="fas fa-trash-alt"></i> {{ i18n.ts.uninstall }}</MkButton> | ||||||
| 			</div> | 			</div> | ||||||
| 		</div> | 		</div> | ||||||
| 	</FormSection> | 	</FormSection> | ||||||
| </div> | </div> | ||||||
| </template> | </template> | ||||||
|  |  | ||||||
| <script lang="ts"> | <script lang="ts" setup> | ||||||
| import { defineComponent } from 'vue'; | import { defineExpose, nextTick, ref } from 'vue'; | ||||||
| import FormLink from '@/components/form/link.vue'; | import FormLink from '@/components/form/link.vue'; | ||||||
| import FormSwitch from '@/components/form/switch.vue'; | import FormSwitch from '@/components/form/switch.vue'; | ||||||
| import FormSection from '@/components/form/section.vue'; | import FormSection from '@/components/form/section.vue'; | ||||||
| @@ -41,40 +41,21 @@ import MkKeyValue from '@/components/key-value.vue'; | |||||||
| import * as os from '@/os'; | import * as os from '@/os'; | ||||||
| import { ColdDeviceStorage } from '@/store'; | import { ColdDeviceStorage } from '@/store'; | ||||||
| import * as symbols from '@/symbols'; | import * as symbols from '@/symbols'; | ||||||
|  | import { unisonReload } from '@/scripts/unison-reload'; | ||||||
|  | import { i18n } from '@/i18n'; | ||||||
|  |  | ||||||
| export default defineComponent({ | const plugins = ref(ColdDeviceStorage.get('plugins')); | ||||||
| 	components: { |  | ||||||
| 		FormLink, |  | ||||||
| 		FormSwitch, |  | ||||||
| 		FormSection, |  | ||||||
| 		MkButton, |  | ||||||
| 		MkKeyValue, |  | ||||||
| 	}, |  | ||||||
|  |  | ||||||
| 	emits: ['info'], | function uninstall(plugin) { | ||||||
| 	 | 	ColdDeviceStorage.set('plugins', plugins.value.filter(x => x.id !== plugin.id)); | ||||||
| 	data() { |  | ||||||
| 		return { |  | ||||||
| 			[symbols.PAGE_INFO]: { |  | ||||||
| 				title: this.$ts.plugins, |  | ||||||
| 				icon: 'fas fa-plug', |  | ||||||
| 				bg: 'var(--bg)', |  | ||||||
| 			}, |  | ||||||
| 			plugins: ColdDeviceStorage.get('plugins'), |  | ||||||
| 		} |  | ||||||
| 	}, |  | ||||||
|  |  | ||||||
| 	methods: { |  | ||||||
| 		uninstall(plugin) { |  | ||||||
| 			ColdDeviceStorage.set('plugins', this.plugins.filter(x => x.id !== plugin.id)); |  | ||||||
| 	os.success(); | 	os.success(); | ||||||
| 			this.$nextTick(() => { | 	nextTick(() => { | ||||||
| 		unisonReload(); | 		unisonReload(); | ||||||
| 	}); | 	}); | ||||||
| 		}, | } | ||||||
|  |  | ||||||
| 		// TODO: この処理をstore側にactionとして移動し、設定画面を開くAiScriptAPIを実装できるようにする | // TODO: この処理をstore側にactionとして移動し、設定画面を開くAiScriptAPIを実装できるようにする | ||||||
| 		async config(plugin) { | async function config(plugin) { | ||||||
| 	const config = plugin.config; | 	const config = plugin.config; | ||||||
| 	for (const key in plugin.configData) { | 	for (const key in plugin.configData) { | ||||||
| 		config[key].default = plugin.configData[key]; | 		config[key].default = plugin.configData[key]; | ||||||
| @@ -83,25 +64,31 @@ export default defineComponent({ | |||||||
| 	const { canceled, result } = await os.form(plugin.name, config); | 	const { canceled, result } = await os.form(plugin.name, config); | ||||||
| 	if (canceled) return; | 	if (canceled) return; | ||||||
|  |  | ||||||
| 			const plugins = ColdDeviceStorage.get('plugins'); | 	const coldPlugins = ColdDeviceStorage.get('plugins'); | ||||||
| 			plugins.find(p => p.id === plugin.id).configData = result; | 	coldPlugins.find(p => p.id === plugin.id)!.configData = result; | ||||||
| 			ColdDeviceStorage.set('plugins', plugins); | 	ColdDeviceStorage.set('plugins', coldPlugins); | ||||||
|  |  | ||||||
| 			this.$nextTick(() => { | 	nextTick(() => { | ||||||
| 		location.reload(); | 		location.reload(); | ||||||
| 	}); | 	}); | ||||||
| 		}, | } | ||||||
|  |  | ||||||
| 		changeActive(plugin, active) { | function changeActive(plugin, active) { | ||||||
| 			const plugins = ColdDeviceStorage.get('plugins'); | 	const coldPlugins = ColdDeviceStorage.get('plugins'); | ||||||
| 			plugins.find(p => p.id === plugin.id).active = active; | 	coldPlugins.find(p => p.id === plugin.id)!.active = active; | ||||||
| 			ColdDeviceStorage.set('plugins', plugins); | 	ColdDeviceStorage.set('plugins', coldPlugins); | ||||||
|  |  | ||||||
| 			this.$nextTick(() => { | 	nextTick(() => { | ||||||
| 		location.reload(); | 		location.reload(); | ||||||
| 	}); | 	}); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | defineExpose({ | ||||||
|  | 	[symbols.PAGE_INFO]: { | ||||||
|  | 		title: i18n.ts.plugins, | ||||||
|  | 		icon: 'fas fa-plug', | ||||||
|  | 		bg: 'var(--bg)', | ||||||
| 	} | 	} | ||||||
| 	}, |  | ||||||
| }); | }); | ||||||
| </script> | </script> | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Andreas Nedbal
					Andreas Nedbal