Skip to content

Commit

Permalink
feat: 新版挂件-通用平台定义
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Jul 18, 2023
1 parent fde3095 commit c380c1a
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 32 deletions.
Binary file added public/images/github.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/metaweblog.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 5 additions & 24 deletions src/components/set/PublishSetting.vue
Expand Up @@ -39,33 +39,22 @@ import {
} from "~/src/components/set/publish/platform/dynamicConfig.ts"
import { DYNAMIC_CONFIG_KEY } from "~/src/utils/constants.ts"
import { useRouter } from "vue-router"
import { usePlatformDefine } from "~/src/composables/usePlatformDefine.ts"
const logger = createAppLogger("publish-setting")
// uses
const { t } = useVueI18n()
const router = useRouter()
const { getSetting, updateSetting } = useSettingStore()
const { platformTypeList } = usePlatformDefine()
// datas
const formData = reactive({
setting: {} as typeof SypConfig,
showPlatformList: false,
platformTypeList: [
{
type: PlatformType.Common,
title: t("setting.platform.universal"),
img: "./images/universal.webp",
description: t("setting.platform.universal.desc"),
},
{
type: PlatformType.Wordpress,
title: t("setting.platform.wordpress"),
img: "./images/wordpress-logo.svg",
description: t("setting.platform.wordpress.desc"),
},
],
platformTypeList: platformTypeList,
dynamicConfigArray: [] as DynamicConfig[],
})
Expand All @@ -78,8 +67,7 @@ const handleHidePlatform = () => {
formData.showPlatformList = false
}
const handleAddPlatformStep = () => {
const type = PlatformType.Common
const handleAddPlatformStep = (type: PlatformType) => {
router.push({
path: `/setting/platform/quickadd/${type}`,
query: {
Expand All @@ -104,13 +92,6 @@ const initPage = async () => {
const dynJsonCfg = JsonUtil.safeParse<DynamicJsonCfg>(formData.setting[DYNAMIC_CONFIG_KEY], {} as DynamicJsonCfg)
// 默认展示通用平台
formData.dynamicConfigArray = dynJsonCfg.totalCfg || []
// test start
for (let i = 0; i < 20; i++) {
var newCfg = dynJsonCfg.totalCfg[0]
newCfg.platformKey = newCfg.platformKey + i
formData.dynamicConfigArray.push(newCfg)
}
// test end
logger.debug("dynamic init page=>", formData.dynamicConfigArray)
}
Expand Down Expand Up @@ -152,7 +133,7 @@ onMounted(async () => {
:key="p.type"
:span="24"
class="col-item"
@click="handleAddPlatformStep"
@click="handleAddPlatformStep(p.type)"
>
<el-card class="platform-right-card">
<img :src="p.img" class="image" alt="" />
Expand Down
11 changes: 4 additions & 7 deletions src/components/set/publish/PlatformAddForm.vue
Expand Up @@ -47,16 +47,13 @@ const { query } = useRoute()
// datas
const params = reactive(route.params)
const ptype = params.type as PlatformType
const formRef = ref()
const formData = reactive({
ptype: PlatformType.Common,
subtype: SubPlatformType.Common_Zhihu,
dynCfg: new DynamicConfig(
PlatformType.Common,
getNewPlatformKey(PlatformType.Common, SubPlatformType.Common_Zhihu),
"Zhihu-1"
),
ptype: ptype,
subtype: SubPlatformType.NONE,
dynCfg: new DynamicConfig(ptype, getNewPlatformKey(ptype, SubPlatformType.NONE), "None-1"),
subtypeOptions: [],
authMode: AuthMode.API,
isEnabled: false,
Expand Down
2 changes: 1 addition & 1 deletion src/components/set/publish/PlatformQuickAdd.vue
Expand Up @@ -41,7 +41,7 @@ const params = reactive(route.params)
// methods
const handleAddPlatform = () => {
const type = PlatformType.Common
const type = params.type
router.push({
path: `/setting/platform/add/${type}`,
query: {
Expand Down
103 changes: 103 additions & 0 deletions src/composables/usePlatformDefine.ts
@@ -0,0 +1,103 @@
/*
* 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 { DynamicConfig, PlatformType } from "~/src/components/set/publish/platform/dynamicConfig.ts"
import { useVueI18n } from "~/src/composables/useVueI18n.ts"
import { pre } from "~/src/utils/import/pre.ts"

/**
* 通用平台定义
*
* @returns {Object} - 包含平台类型列表、getPlatformType函数和getPrePlatform函数的对象。
* @since 0.9.0
*/
export const usePlatformDefine = () => {
const { t } = useVueI18n()

const platformTypeList = [
{
type: PlatformType.Common,
title: t("setting.platform.universal"),
img: "./images/universal.webp",
description: t("setting.platform.universal.desc"),
},
{
type: PlatformType.Github,
title: t("setting.platform.github"),
img: "./images/github.png",
description: t("setting.platform.github.desc"),
},
{
type: PlatformType.Metaweblog,
title: t("setting.platform.metaweblog"),
img: "./images/metaweblog.jpg",
description: t("setting.platform.metaweblog.desc"),
},
{
type: PlatformType.Wordpress,
title: t("setting.platform.wordpress"),
img: "./images/wordpress-logo.svg",
description: t("setting.platform.wordpress.desc"),
},
// {
// type: PlatformType.Custom,
// title: t("setting.platform.other"),
// img: "./images/other-platform.png",
// description: t("setting.platform.other.desc"),
// },
]

const prePlatformList: DynamicConfig[] = [
...pre.commonCfg,
...pre.githubCfg,
...pre.metaweblogCfg,
...pre.wordpressCfg,
]

/**
* 根据键获取平台类型
*
* @param {string} key - 平台类型的键
* @returns {Object} - 平台类型对象
*/
const getPlatformType = (key) => {
return platformTypeList.find((platformType) => platformType.type === key)
}

/**
* 根据类型获取预定义平台
*
* @returns {Object} - 预定义平台对象
*/
const getPrePlatform = (key: string) => {
return prePlatformList.find((platform) => platform.platformKey === key)
}

return {
platformTypeList,
getPlatformType,
getPrePlatform,
}
}
6 changes: 6 additions & 0 deletions src/locales/zh_CN.ts
Expand Up @@ -477,6 +477,12 @@ export default {
"setting.platform.wordpress": "WordPress",
"setting.platform.wordpress.desc":
"WordPress是一个以PHP和MySQL为平台的自由开源的博客软件和内容管理系统。它具有插件架构和模板系统,同时也是最受欢迎的网站内容管理系统。点击右侧图标快速添加,或者点击下方按钮自定义添加",
"setting.platform.github": "Github",
"setting.platform.github.desc":
"GitHub 是一个使用 Git 进行软件开发和版本控制的平台和基于云的服务,允许开发人员存储和管理他们的代码。",
"setting.platform.metaweblog": "Metaweblog",
"setting.platform.metaweblog.desc":
"MetaWeblog API是由软件开发人员Dave Winer创建的应用程序编程接口,它允许使用 Web 服务写入、编辑和删除。该 API 作为XML-RPC Web 服务实现,具有三个方法,其名称描述了其功能:metaweblog.newPost()、metaweblog.getPost() 和 metaweblog.editPost()。这些方法采用指定博客作者的用户名和密码以及与单个博客条目相关的信息的参数。",
"setting.platform.right.tips0": "特别提示:",
"setting.platform.right.tips1": "1、在这里可以进行发布配置,直接点击 [设置图标] 即可进行配置。",
"setting.platform.right.tips2": "2、如需新增平台,直接点击左侧 + 按钮即可。",
Expand Down
44 changes: 44 additions & 0 deletions src/utils/import/pre.ts
@@ -0,0 +1,44 @@
export const pre = {
commonCfg: [],
githubCfg: [
{
platformType: "Github",
subPlatformType: "Github_Hugo",
platformKey: "githubHugo-zdlc6l",
platformName: "Docsy",
},
{
platformType: "Github",
subPlatformType: "Github_Vitepress",
platformKey: "githubVitepress-mhxj3",
platformName: "Vitepress",
},
{
platformType: "Github",
subPlatformType: "Github_Nuxt",
platformKey: "githubNuxt-z1xcb7x",
platformName: "Nuxt content",
},
{
platformType: "Github",
subPlatformType: "Github_Next",
platformKey: "githubNext-ziz9v8",
platformName: "Nextra",
},
],
metaweblogCfg: [
{
platformType: "Metaweblog",
subPlatformType: "none",
platformKey: "metaweblog-zahrlw",
platformName: "开源中国",
},
{
platformType: "Metaweblog",
subPlatformType: "none",
platformKey: "metaweblog-22pamt",
platformName: "Typecho",
},
],
wordpressCfg: [],
}

0 comments on commit c380c1a

Please sign in to comment.