Skip to content

Commit

Permalink
feat: #1076 #1077 优化发布配置、平台导入、插件商店使用体验 - 优化文章绑定,历史元数据导入
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Mar 7, 2024
1 parent 03f6793 commit e2e134c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 21 deletions.
40 changes: 24 additions & 16 deletions src/components/set/preference/PostBind.vue
Expand Up @@ -34,7 +34,7 @@ import { useRoute } from "vue-router"
import { getWidgetId } from "~/src/utils/widgetUtils.ts"
import { usePublishSettingStore } from "~/src/stores/usePublishSettingStore.ts"
import { createAppLogger } from "~/src/utils/appLogger.ts"
import { getSiyuanWidgetId } from "~/src/utils/siyuanUtils.ts"
import { getSiyuanPageId } from "~/src/utils/siyuanUtils.ts"
import { Utils } from "~/src/utils/utils.ts"
const logger = createAppLogger("post-bind")
Expand All @@ -46,38 +46,37 @@ const { getPublishCfg } = usePublishConfig()
const { updateSetting } = usePublishSettingStore()
// datas
const id = Utils.emptyOrDefault(query.id ?? getWidgetId(), getSiyuanWidgetId()) as string
const ruleFormRef = ref()
const ruleForm = reactive({})
const rules = reactive<FormRules>({})
const formData = reactive({
pageId: id,
pageId: "",
dynamicConfigArray: [] as DynamicConfig[],
postIdMap: {} as any,
})
// methods
const submitForm = async (formEl: any) => {
if (StrUtil.isEmptyString(id)) {
if (StrUtil.isEmptyString(formData.pageId)) {
ElMessage.error("")
return
}
try {
const publishCfg = await getPublishCfg()
const setting = publishCfg.setting
const postMeta = ObjectUtil.getProperty(setting, id, {})
const postMeta = ObjectUtil.getProperty(setting, formData.pageId, {})
formData.dynamicConfigArray = formData.dynamicConfigArray.map((item: DynamicConfig) => {
const postid = formData.postIdMap[item.platformKey]
const cfg = ObjectUtil.getProperty(setting, item.platformKey, {})
const posidKey = cfg?.posidKey
if (!StrUtil.isEmptyString(posidKey) && !StrUtil.isEmptyString(id)) {
if (!StrUtil.isEmptyString(posidKey) && !StrUtil.isEmptyString(formData.pageId)) {
postMeta[posidKey] = postid
}
return item
})
setting[id] = postMeta
setting[formData.pageId] = postMeta
logger.debug("prepare to save setting =>", { setting: toRaw(setting) })
await updateSetting(setting)
ElMessage.success(t("main.opt.success"))
Expand All @@ -89,6 +88,10 @@ const submitForm = async (formEl: any) => {
// lifecycles
onMounted(async () => {
const id = Utils.emptyOrDefault(query.id as string, getWidgetId())
const siyuanPageId = await getSiyuanPageId(id)
formData.pageId = siyuanPageId
const publishCfg = await getPublishCfg()
const setting = publishCfg.setting
formData.dynamicConfigArray = publishCfg.dynamicConfigArray
Expand All @@ -110,7 +113,7 @@ onMounted(async () => {
<div>
<el-alert class="top-tip" :title="t('post.bind.auto.tips')" type="error" :closable="false" />
<el-form-item>
<el-input v-model="formData.pageId" placeholder="请输入需要修复的文档根 ID"/>
<el-input v-model="formData.pageId" placeholder="请输入需要修复的文档根 ID" />
</el-form-item>
<el-divider border-style="dashed" />

Expand All @@ -133,14 +136,19 @@ onMounted(async () => {
:closable="false"
/>
<!-- 动态配置 -->
<el-form-item
v-for="(cfg, index) in formData.dynamicConfigArray"
:key="index"
:label="cfg.platformName"
v-show="cfg.isEnabled && cfg.isEnabled"
>
<el-input v-model="formData.postIdMap[cfg.platformKey]" />
</el-form-item>
<div v-if="formData.dynamicConfigArray.length > 0">
<el-form-item
v-for="(cfg, index) in formData.dynamicConfigArray"
:key="index"
:label="cfg.platformName"
v-show="cfg.isEnabled && cfg.isEnabled"
>
<el-input v-model="formData.postIdMap[cfg.platformKey]" />
</el-form-item>
</div>
<div v-else>
<el-alert class="top-tip" :title="t('post.bind.auto.empty')" type="info" :closable="false" />
</div>

<el-form-item>
<el-button type="primary" @click="submitForm(ruleFormRef)">{{ t("post.bind.conf.save") }}</el-button>
Expand Down
9 changes: 5 additions & 4 deletions src/locales/en_US.ts
Expand Up @@ -24,7 +24,7 @@
*/

export default {
"lang.choose": "Choose lang",
"lang.choose": "Language",
"lang.choose.placeholder": "Please select language",
"theme.mode.choose": "Mode",
"theme.mode.dark": "Dark mode",
Expand Down Expand Up @@ -225,8 +225,9 @@ export default {
"post.bind.yuque.postid": "Yuque ID",
"post.bind.kms.postid": "KMS ID",
"post.bind.conf.save": "Save",
"post.bind.conf.v081": "检测 v0.8.1 元数据并导入",
"post.bind.auto.":"未检测到ID,请手动输入文档根 ID ,然后再进行修复",
"post.bind.conf.v081": "Examine the v0.8.1 metadata and import it",
"post.bind.auto.error": "No ID detected, kindly input the document root ID manually, before proceeding with the repair.",
"post.bind.auto.empty": "This document has never been published, hence no repair is necessary",
"post.bind.conf.cancel": "Cancel",
"form.validate.name.required": "Please input name",
"form.validate.name.length": "Length should be 0 to 1",
Expand Down Expand Up @@ -607,7 +608,7 @@ export default {
"post.bind.auto.tips":
"The ID here is automatically saved by the publishing tool, if you are not clear about the principle, please do not modify it",
"siyuan.config.setting": "Source settings",
"setting.blog.siyuan.apiurl": "Siyuan API address",
"setting.blog.siyuan.apiurl": "Siyuan API",
"setting.blog.siyuan.apiurl.tip":
"The API address of Siyuan Note, including ports, The default address of Siyuan API is: http://127.0.0.1;6806",
"setting.blog.siyuan.password": "Siyuan Token",
Expand Down
3 changes: 2 additions & 1 deletion src/locales/zh_CN.ts
Expand Up @@ -225,8 +225,9 @@ export default {
"post.bind.yuque.postid": "语雀的ID",
"post.bind.kms.postid": "KMS的ID",
"post.bind.conf.save": "保存",
"post.bind.conf.v081": "Examine the v0.8.1 metadata and import it",
"post.bind.conf.v081": "检测 v0.8.1 元数据并导入",
"post.bind.auto.error": "未检测到ID,请手动输入文档根 ID ,然后再进行修复",
"post.bind.auto.empty": "该文档未发布过,无需修复",
"post.bind.conf.cancel": "取消",
"form.validate.name.required": "请输入名称",
"form.validate.name.length": "长度必须在0到1之间",
Expand Down

0 comments on commit e2e134c

Please sign in to comment.