config page

This commit is contained in:
Rewrite0
2023-05-24 22:07:10 +08:00
parent 63920442b5
commit 026a20d60e
15 changed files with 335 additions and 8 deletions

24
src/api/auth.ts Normal file
View File

@@ -0,0 +1,24 @@
import axios from 'axios';
import type { Auth, Logout, Update } from '#/auth';
export const apiAuth = {
async login() {
const { data } = await axios.post<Auth>('api/v1/auth/login');
return data;
},
async refresh() {
const { data } = await axios.get<Auth>('api/v1/auth/refresh_token');
return data;
},
async logout() {
const { data } = await axios.get<Logout>('api/v1/auth/logout');
return data;
},
async update() {
const { data } = await axios.post<Update>('api/v1/auth/update');
return data;
},
};

View File

@@ -5,6 +5,7 @@ declare global {
const acceptHMRUpdate: typeof import('pinia')['acceptHMRUpdate']
const afterAll: typeof import('vitest')['afterAll']
const afterEach: typeof import('vitest')['afterEach']
const apiAuth: typeof import('./api/auth')['apiAuth']
const apiBangumi: typeof import('./api/bangumi')['apiBangumi']
const apiCheck: typeof import('./api/check')['apiCheck']
const apiConfig: typeof import('./api/config')['apiConfig']

View File

@@ -11,7 +11,7 @@ import { isObject, isString } from 'lodash';
const props = withDefaults(
defineProps<{
modelValue?: SelectItem;
modelValue?: SelectItem | string;
items: Array<SelectItem | string>;
}>(),
{}

6
src/components.d.ts vendored
View File

@@ -28,8 +28,14 @@ declare module '@vue/runtime-core' {
AbSwitch: typeof import('./basic/ab-switch.vue')['default']
AbTopbar: typeof import('./views/ab-topbar.vue')['default']
BangumiCard: typeof import('./components/bangumi-card.vue')['default']
ConfigDownload: typeof import('./views/config-download.vue')['default']
ConfigManage: typeof import('./views/config-manage.vue')['default']
ConfigManager: typeof import('./views/config-manager.vue')['default']
ConfigNormal: typeof import('./views/config-normal.vue')['default']
ConfigNotification: typeof import('./views/config-notification.vue')['default']
ConfigNotificcation: typeof import('./views/config-notificcation.vue')['default']
ConfigParser: typeof import('./views/config-parser.vue')['default']
ConfigProxy: typeof import('./views/config-proxy.vue')['default']
copy: typeof import('./basic/ab-switch copy.vue')['default']
RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView']

View File

@@ -14,7 +14,7 @@ const props = withDefaults(
<template>
<Disclosure v-slot="{ open }">
<div rounded-10px overflow-hidden>
<div rounded-10px overflow-hidden h-max>
<DisclosureButton
bg-theme-row
w-full

View File

@@ -8,7 +8,7 @@ withDefaults(defineProps<AbSettingProps>(), {
bottomLine: false,
});
const data = defineModel('data');
const data = defineModel<any>('data');
</script>
<template>

View File

@@ -1,5 +1,5 @@
<script lang="ts" setup>
const { getConfig } = useConfigStore();
const { getConfig, setConfig } = useConfigStore();
onBeforeMount(() => getConfig());
@@ -9,8 +9,22 @@ definePage({
</script>
<template>
<div flex="~ wrap" gap-20px>
<config-normal grow></config-normal>
<config-parser grow></config-parser>
<div gap-20px grid="~ cols-2">
<config-normal></config-normal>
<config-parser></config-parser>
<config-download></config-download>
<config-manage></config-manage>
<config-notification></config-notification>
<config-proxy></config-proxy>
<div fx-cer justify-end gap-8px col-span-2>
<ab-button type="warn" @click="getConfig">Cancel</ab-button>
<ab-button @click="setConfig">Apply</ab-button>
</div>
</div>
</template>

View File

@@ -55,6 +55,10 @@ export const useConfigStore = defineStore('config', () => {
config.value = res;
};
const setConfig = async () => {
const res = await apiConfig.updateConfig(config.value);
};
const getSettingGroup = <Tkey extends keyof Config>(key: Tkey) => {
return computed<Config[Tkey]>(() => config.value[key]);
};
@@ -62,6 +66,7 @@ export const useConfigStore = defineStore('config', () => {
return {
config,
getConfig,
setConfig,
getSettingGroup,
};
});

View File

@@ -0,0 +1,76 @@
<script lang="ts" setup>
import type { Downloader, DownloaderType } from '#/config';
import type { SettingItem } from '#/components';
const { getSettingGroup } = useConfigStore();
const downloader = getSettingGroup('downloader');
const downloaderType: DownloaderType = ['qbittorrent'];
const items: SettingItem<Downloader>[] = [
{
configKey: 'type',
label: 'Downloader Type',
type: 'select',
css: 'w-115px',
prop: {
items: downloaderType,
},
},
{
configKey: 'host',
label: 'Host',
type: 'input',
prop: {
type: 'text',
placeholder: '127.0.0.1:8989',
},
},
{
configKey: 'username',
label: 'Username',
type: 'input',
prop: {
type: 'text',
placeholder: 'admin',
},
},
{
configKey: 'password',
label: 'Password',
type: 'input',
prop: {
type: 'text',
placeholder: 'admindmin',
},
bottomLine: true,
},
{
configKey: 'path',
label: 'Download Path',
type: 'input',
prop: {
type: 'text',
placeholder: '/downloads/Bangumi',
},
},
{
configKey: 'ssl',
label: 'SSL',
type: 'switch',
},
];
</script>
<template>
<ab-fold-panel title="Downloader Setting">
<div space-y-12px>
<ab-setting
v-for="i in items"
:key="i.configKey"
v-bind="i"
v-model:data="downloader[i.configKey]"
></ab-setting>
</div>
</ab-fold-panel>
</template>

View File

@@ -0,0 +1,54 @@
<script lang="ts" setup>
import type { BangumiManage, RenameMethod } from '#/config';
import type { SettingItem } from '#/components';
const { getSettingGroup } = useConfigStore();
const manage = getSettingGroup('bangumi_manage');
const renameMethod: RenameMethod = ['normal', 'pn', 'advance', 'none'];
const items: SettingItem<BangumiManage>[] = [
{
configKey: 'enable',
label: 'Enable',
type: 'switch',
},
{
configKey: 'rename_method',
label: 'Rename Method',
type: 'select',
prop: {
items: renameMethod,
},
bottomLine: true,
},
{
configKey: 'eps_complete',
label: 'Eps complete',
type: 'switch',
},
{
configKey: 'group_tag',
label: 'Add Group Tag',
type: 'switch',
},
{
configKey: 'remove_bad_torrent',
label: 'Delete Bad Torrent',
type: 'switch',
},
];
</script>
<template>
<ab-fold-panel title="Manage Setting">
<div space-y-12px>
<ab-setting
v-for="i in items"
:key="i.configKey"
v-bind="i"
v-model:data="manage[i.configKey]"
></ab-setting>
</div>
</ab-fold-panel>
</template>

View File

@@ -0,0 +1,58 @@
<script lang="ts" setup>
import type { Notification, NotificationType } from '#/config';
import type { SettingItem } from '#/components';
const { getSettingGroup } = useConfigStore();
const notification = getSettingGroup('notification');
const notificationType: NotificationType = ['telegram', 'server-chan', 'bark'];
const items: SettingItem<Notification>[] = [
{
configKey: 'enable',
label: 'Enable',
type: 'switch',
bottomLine: true,
},
{
configKey: 'type',
label: 'Type',
type: 'select',
css: 'w-140px',
prop: {
items: notificationType,
},
},
{
configKey: 'token',
label: 'Token',
type: 'input',
prop: {
type: 'text',
placeholder: 'token',
},
},
{
configKey: 'chat_id',
label: 'Chat ID',
type: 'input',
prop: {
type: 'text',
placeholder: 'chat id',
},
},
];
</script>
<template>
<ab-fold-panel title="Notification Setting">
<div space-y-12px>
<ab-setting
v-for="i in items"
:key="i.configKey"
v-bind="i"
v-model:data="notification[i.configKey]"
></ab-setting>
</div>
</ab-fold-panel>
</template>

View File

@@ -13,6 +13,7 @@ const parser = getSettingGroup('rss_parser');
const sourceItems: RssParserType = ['mikan'];
const langs: RssParserLang = ['zh', 'en', 'jp'];
/** @ts-ignore */
const parserMethods: RssParserMethodType = ['tmdb', 'mikan', 'parser'];
const items: SettingItem<RssParser>[] = [

View File

@@ -0,0 +1,75 @@
<script lang="ts" setup>
import type { Proxy, ProxyType } from '#/config';
import type { SettingItem } from '#/components';
const { getSettingGroup } = useConfigStore();
const proxy = getSettingGroup('proxy');
const proxyType: ProxyType = ['http', 'https', 'socks5'];
const items: SettingItem<Proxy>[] = [
{
configKey: 'enable',
label: 'Enable',
type: 'switch',
},
{
configKey: 'type',
label: 'Proxy Type',
type: 'select',
prop: {
items: proxyType,
},
bottomLine: true,
},
{
configKey: 'host',
label: 'Host',
type: 'input',
prop: {
type: 'text',
placeholder: '127.0.0.1',
},
},
{
configKey: 'port',
label: 'Port',
type: 'input',
prop: {
type: 'text',
placeholder: '7890',
},
},
{
configKey: 'username',
label: 'Username',
type: 'input',
prop: {
type: 'text',
placeholder: 'username',
},
},
{
configKey: 'password',
label: 'Password',
type: 'input',
prop: {
type: 'text',
placeholder: 'password',
},
},
];
</script>
<template>
<ab-fold-panel title="Proxy Setting">
<div space-y-12px>
<ab-setting
v-for="i in items"
:key="i.configKey"
v-bind="i"
v-model:data="proxy[i.configKey]"
></ab-setting>
</div>
</ab-fold-panel>
</template>

View File

@@ -25,7 +25,7 @@
"src/**/*.d.ts",
"src/**/*.tsx",
"src/**/*.vue",
"types/config.ts"
"types/**/*.ts"
],
"references": [{ "path": "./tsconfig.node.json" }]
}

13
types/auth.ts Normal file
View File

@@ -0,0 +1,13 @@
export type Auth = {
access_token: string;
token_type: string;
expire: number;
};
export type Logout = {
message: 'logout success';
};
export type Update = {
message: 'update success';
};