From 5234e76716d74223b4e0c234b6ec7a57f3e8ed85 Mon Sep 17 00:00:00 2001 From: terwer Date: Sun, 25 Jun 2023 01:43:46 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E7=89=88=E6=8C=82=E4=BB=B6-?= =?UTF-8?q?=E5=8A=A8=E6=80=81=E8=AF=BB=E5=8F=96=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components.d.ts | 4 + .../github/adaptor}/GithubApiAdaptor.ts | 0 .../{ => base}/github/config/GithubConfig.ts | 0 .../metaweblog/config/MetaweblogConfig.ts | 94 ++++++++ .../config/MetaweblogPlaceholder.ts | 78 +++++++ src/components/set/PlatformSetting.vue | 123 ++++++---- src/components/set/SinglePlatformSetting.vue | 36 +++ src/components/set/platform/dynamicConfig.ts | 6 + .../set/singleplatform/MetaweblogSetting.vue | 219 ++++++++++++++++++ src/composables/useVueRouter.ts | 5 + src/locales/en_US.ts | 2 +- src/locales/zh_CN.ts | 2 +- src/stores/useSettingStore.ts | 34 ++- 13 files changed, 558 insertions(+), 45 deletions(-) rename src/adaptors/{github => base/github/adaptor}/GithubApiAdaptor.ts (100%) rename src/adaptors/{ => base}/github/config/GithubConfig.ts (100%) create mode 100644 src/adaptors/base/metaweblog/config/MetaweblogConfig.ts create mode 100644 src/adaptors/base/metaweblog/config/MetaweblogPlaceholder.ts create mode 100644 src/components/set/SinglePlatformSetting.vue create mode 100644 src/components/set/singleplatform/MetaweblogSetting.vue diff --git a/components.d.ts b/components.d.ts index 4e81e9c..9696532 100644 --- a/components.d.ts +++ b/components.d.ts @@ -24,6 +24,8 @@ declare module '@vue/runtime-core' { ElInput: typeof import('element-plus/es')['ElInput'] ElMain: typeof import('element-plus/es')['ElMain'] ElOption: typeof import('element-plus/es')['ElOption'] + ElRadio: typeof import('element-plus/es')['ElRadio'] + ElRadioGroup: typeof import('element-plus/es')['ElRadioGroup'] ElScrollbar: typeof import('element-plus/es')['ElScrollbar'] ElSelect: typeof import('element-plus/es')['ElSelect'] ElSpace: typeof import('element-plus/es')['ElSpace'] @@ -36,12 +38,14 @@ declare module '@vue/runtime-core' { HexoTest: typeof import('./src/components/test/HexoTest.vue')['default'] HugoTest: typeof import('./src/components/test/HugoTest.vue')['default'] KmsTest: typeof import('./src/components/test/kmsTest.vue')['default'] + MetaweblogSetting: typeof import('./src/components/set/singleplatform/MetaweblogSetting.vue')['default'] PlatformSetting: typeof import('./src/components/set/PlatformSetting.vue')['default'] PublishIndex: typeof import('./src/components/publish/PublishIndex.vue')['default'] PublishSetting: typeof import('./src/components/set/PublishSetting.vue')['default'] RouterLink: typeof import('vue-router')['RouterLink'] RouterView: typeof import('vue-router')['RouterView'] SetIndex: typeof import('./src/components/set/SetIndex.vue')['default'] + SinglePlatformSetting: typeof import('./src/components/set/SinglePlatformSetting.vue')['default'] SiyuanTest: typeof import('./src/components/test/SiyuanTest.vue')['default'] TypechoTest: typeof import('./src/components/test/TypechoTest.vue')['default'] VitepressTest: typeof import('./src/components/test/VitepressTest.vue')['default'] diff --git a/src/adaptors/github/GithubApiAdaptor.ts b/src/adaptors/base/github/adaptor/GithubApiAdaptor.ts similarity index 100% rename from src/adaptors/github/GithubApiAdaptor.ts rename to src/adaptors/base/github/adaptor/GithubApiAdaptor.ts diff --git a/src/adaptors/github/config/GithubConfig.ts b/src/adaptors/base/github/config/GithubConfig.ts similarity index 100% rename from src/adaptors/github/config/GithubConfig.ts rename to src/adaptors/base/github/config/GithubConfig.ts diff --git a/src/adaptors/base/metaweblog/config/MetaweblogConfig.ts b/src/adaptors/base/metaweblog/config/MetaweblogConfig.ts new file mode 100644 index 0000000..11e4d0f --- /dev/null +++ b/src/adaptors/base/metaweblog/config/MetaweblogConfig.ts @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2023, Terwer . All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Terwer designates this + * particular file as subject to the "Classpath" exception as provided + * by Terwer in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Terwer, Shenzhen, Guangdong, China, youweics@163.com + * or visit www.terwer.space if you need additional information or have any + * questions. + */ + +import { BlogConfig, PageType, PageTypeEnum } from "zhi-blog-api" +import { MetaweblogPlaceholder } from "~/src/adaptors/base/metaweblog/config/MetaweblogPlaceholder.ts" + +/** + * Metaweblog配置类 + */ +export class MetaweblogConfig extends BlogConfig { + /** + * 首页 + */ + public override home = "" + + /** + * API地址 + */ + public override apiUrl = "" + /** + * 用户名 + */ + public override username = "" + /** + * 密码 + */ + public override password = "" + + /** + * 是否发布 + */ + public override apiStatus = false + + /** + * 博客名(API获取) + */ + public override blogName = "" + + /** + * 文章别名key + */ + public override posidKey = "" + + /** + * 文章预览链接 + */ + public override previewUrl = "" + + /** + * 文章类型 + */ + public override pageType = PageTypeEnum.Markdown + + /** + * 操作提示 + */ + public override placeholder = {} as MetaweblogPlaceholder + + constructor(home: string, apiUrl: string, username: string, password: string) { + super() + this.home = home + this.apiUrl = apiUrl + this.username = username + this.password = password + this.apiStatus = false + this.blogName = "" + this.posidKey = "" + this.previewUrl = "" + this.pageType = PageTypeEnum.Markdown + this.placeholder = new MetaweblogPlaceholder() + } +} diff --git a/src/adaptors/base/metaweblog/config/MetaweblogPlaceholder.ts b/src/adaptors/base/metaweblog/config/MetaweblogPlaceholder.ts new file mode 100644 index 0000000..f82f08e --- /dev/null +++ b/src/adaptors/base/metaweblog/config/MetaweblogPlaceholder.ts @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2023, Terwer . All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Terwer designates this + * particular file as subject to the "Classpath" exception as provided + * by Terwer in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Terwer, Shenzhen, Guangdong, China, youweics@163.com + * or visit www.terwer.space if you need additional information or have any + * questions. + */ + +import { BlogPlaceholder } from "zhi-blog-api" + +/** + * Metaweblog 操作提示 + */ +export class MetaweblogPlaceholder extends BlogPlaceholder { + /** + * 首页操作提示 + */ + public override homePlaceholder = "" + + /** + * API 地址操作提示 + */ + public override apiUrlPlaceholder = "" + + /** + * 用户名操作提示 + */ + public override usernamePlaceholder = "" + + /** + * 密码操作提示 + */ + public override passwordPlaceholder = "" + + /** + * API状态是否正常操作提示 + */ + public override apiStatusPlaceholder = false + + /** + * 博客名(API获取)操作提示 + */ + public override blogNamePlaceholder = "" + + /** + * 文章别名key操作提示 + */ + public override posidKeyPlaceholder = "" + /** + * 文章预览链接操作提示 + */ + public override previewUrlPlaceholder = "" + /** + * 文章类型操作提示 + */ + public override pageTypePlaceholder = "" + + constructor() { + super() + } +} diff --git a/src/components/set/PlatformSetting.vue b/src/components/set/PlatformSetting.vue index 061ddaa..bae72a9 100644 --- a/src/components/set/PlatformSetting.vue +++ b/src/components/set/PlatformSetting.vue @@ -24,12 +24,13 @@ --> + + + + diff --git a/src/components/set/platform/dynamicConfig.ts b/src/components/set/platform/dynamicConfig.ts index 12827a3..412aa28 100644 --- a/src/components/set/platform/dynamicConfig.ts +++ b/src/components/set/platform/dynamicConfig.ts @@ -59,6 +59,11 @@ export class DynamicConfig { */ platformName: string + /** + * 是否授权 + */ + isAuth: boolean + /** * YAML转换器 */ @@ -68,6 +73,7 @@ export class DynamicConfig { this.platformType = platformType this.platformKey = platformKey this.platformName = platformName + this.isAuth = false } } diff --git a/src/components/set/singleplatform/MetaweblogSetting.vue b/src/components/set/singleplatform/MetaweblogSetting.vue new file mode 100644 index 0000000..1532050 --- /dev/null +++ b/src/components/set/singleplatform/MetaweblogSetting.vue @@ -0,0 +1,219 @@ + + + + + diff --git a/src/composables/useVueRouter.ts b/src/composables/useVueRouter.ts index e159b57..9477f4b 100644 --- a/src/composables/useVueRouter.ts +++ b/src/composables/useVueRouter.ts @@ -29,6 +29,7 @@ import SetIndex from "~/src/components/set/SetIndex.vue" import GeneralSetting from "~/src/components/set/GeneralSetting.vue" import PlatformSetting from "~/src/components/set/PlatformSetting.vue" import PublishSetting from "~/src/components/set/PublishSetting.vue" +import SinglePlatformSetting from "~/src/components/set/SinglePlatformSetting.vue" const ApiTest = () => import("~/src/pages/ApiTest.vue") const SiyuanTest = () => import("~/src/components/test/SiyuanTest.vue") @@ -59,6 +60,10 @@ const routes: RouteRecordRaw[] = [ path: "/setting/platform", component: PlatformSetting, }, + { + path: "/setting/platform/single", + component: SinglePlatformSetting, + }, { path: "/setting/publish", component: PublishSetting, diff --git a/src/locales/en_US.ts b/src/locales/en_US.ts index f6b4c4f..4e8045b 100644 --- a/src/locales/en_US.ts +++ b/src/locales/en_US.ts @@ -233,7 +233,7 @@ export default { "dynamic.platform.opt.add": "Submit", "dynamic.platform.opt.noselect": "Please select platform type", "dynamic.platform.opt.key.exist": "Platform key exists", - "dynamic.platform.opt.del.select": "Delete selected", + "dynamic.platform.opt.del.select": "Delete", "dynamic.platform.opt.del.confirm": "Deleting this platform will completely remove the relevant configuration information of this platform. Do you continue?", "dynamic.platform.opt.item.select": "Item no select", diff --git a/src/locales/zh_CN.ts b/src/locales/zh_CN.ts index 3259130..47dd9a5 100644 --- a/src/locales/zh_CN.ts +++ b/src/locales/zh_CN.ts @@ -235,7 +235,7 @@ export default { "dynamic.platform.opt.noselect": "请选择平台类型", "dynamic.platform.opt.key.exist": "平台key已经存在", "dynamic.platform.opt.del.confirm": "删除此平台将会彻底移除此平台相关配置信息,是否继续?", - "dynamic.platform.opt.del.select": "删除选中", + "dynamic.platform.opt.del.select": "删除", "dynamic.platform.opt.item.select": "未选择", "dynamic.platform.opt.item.select.tip": "当前选择的是:", "dynamic.platform.opt.item.no.select.tip": "请选择要删除的行", diff --git a/src/stores/useSettingStore.ts b/src/stores/useSettingStore.ts index aedbd4f..12fd754 100755 --- a/src/stores/useSettingStore.ts +++ b/src/stores/useSettingStore.ts @@ -48,5 +48,37 @@ export const useSettingStore = defineStore("setting", () => { settingRef.value = { ...settingRef.value, ...setting } } - return { getSetting, updateSetting } + const checkKeyExists = (targetKey: string): boolean => { + const obj = settingRef.value + if (!obj) { + return false + } + + // 遍历所有属性名,检查是否存在目标属性 + for (const key in obj) { + if (key === targetKey) { + return true + } + } + + // 如果以上情况都不符合,则说明不存在目标属性 + return false + } + + const deleteKey = (targetKey: string): void => { + const obj = settingRef.value + if (!obj) { + return + } + + // 遍历所有属性名,检查是否存在目标属性 + for (const key in obj) { + if (key === targetKey) { + delete obj[key] + return + } + } + } + + return { getSetting, updateSetting, checkKeyExists, deleteKey } })