metacubexd/src/pages/Config.tsx

73 lines
1.6 KiB
TypeScript
Raw Normal View History

import { createForm } from '@felte/solid'
import { validator } from '@felte/validator-zod'
2023-08-28 22:13:48 +08:00
import { For, onMount } from 'solid-js'
import { z } from 'zod'
import { useRequest } from '~/signals'
import type { Config as IConfig } from '~/types'
2023-08-28 22:13:48 +08:00
const schema = z.object({
port: z.number(),
'socks-port': z.number(),
'redir-port': z.number(),
'tproxy-port': z.number(),
'mixed-port': z.number(),
})
export default () => {
2023-08-28 22:13:48 +08:00
const request = useRequest()
const portsList = [
2023-08-28 22:13:48 +08:00
{
label: 'Http Port',
2023-08-28 22:13:48 +08:00
key: 'port',
},
{
label: 'Socks Port',
2023-08-28 22:13:48 +08:00
key: 'socks-port',
},
{
label: 'Redir Port',
2023-08-28 22:13:48 +08:00
key: 'redir-port',
},
{
label: 'Tproxy Port',
2023-08-28 22:13:48 +08:00
key: 'tproxy-port',
},
{
label: 'Mixed Port',
2023-08-28 22:13:48 +08:00
key: 'mixed-port',
},
]
const { form, setInitialValues, reset } = createForm<z.infer<typeof schema>>({
extend: validator({ schema }),
})
onMount(async () => {
const configs = await request.get('configs').json<IConfig>()
setInitialValues(configs)
reset()
})
return (
<div>
<form class="form" use:form={form}>
<For each={portsList}>
2023-08-28 22:13:48 +08:00
{(item) => (
<div class="form-control w-64 max-w-xs">
<label class="label">
<span class="label-text">{item.label}</span>
</label>
2023-08-28 22:13:48 +08:00
<input
name={item.key}
type="number"
2023-08-28 22:13:48 +08:00
class="input input-bordered"
placeholder={item.label}
/>
</div>
)}
</For>
</form>
</div>
)
2023-08-24 04:20:53 +08:00
}