Skip to content

Commit

Permalink
fix: 组件化重构-修复转换未及时更新问题
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Dec 10, 2022
1 parent 940ec77 commit dfbf9de
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
30 changes: 21 additions & 9 deletions components/publish/tab/main/GithubMain.vue
Original file line number Diff line number Diff line change
Expand Up @@ -325,23 +325,27 @@ const {
// page methods
const onEditModeChange = (val: PageEditMode) => {
formOptionData.etype = val
if (val === PageEditMode.EditMode_source) {
convertAttrToYAML(true)
}
}
const onYamlShowTypeChange = (val) => {
formOptionData.stype = val
switch (val) {
case SourceContentShowType.YAML:
yamlData.yamlContent = yamlData.formatter
initYaml(yamlData.formatter)
break
case SourceContentShowType.CONTENT:
yamlData.yamlContent = yamlData.mdContent
initYaml(yamlData.mdContent)
break
case SourceContentShowType.YAML_CONTENT:
yamlData.yamlContent = yamlData.formatter + yamlData.mdContent
initYaml(yamlData.formatter + yamlData.mdContent)
break
case SourceContentShowType.HTML_CONTENT:
yamlData.yamlContent = yamlData.htmlContent
initYaml(yamlData.htmlContent)
break
default:
break
Expand Down Expand Up @@ -414,16 +418,26 @@ const siyuanDataToForm = (publishCfg: PublishPreference) => {
}
// 组件数据转formData,主要是修改页面之后同步
const composableDataToForm = () => {}
const composableDataToForm = () => {
formData.value.postForm.formData.customSlug = slugData.customSlug
}
// 组件在页面上尽量使用自带的Data,这个是与DOM绑定的,可以实时获取最新数据,有改变的时候同步formData
// 调用之前先同步form
// 调用之前先同步form
const convertAttrToYAML = () => {
const convertAttrToYAML = (hideTip?: boolean) => {
const publishCfg = getPublishCfg()
composableDataToForm()
doConvertAttrToYAML(props.yamlConverter, formData.value.postForm)
const githubCfg = getJSONConf<IGithubCfg>(props.apiType)
doConvertAttrToYAML(props.yamlConverter, formData.value.postForm, githubCfg)
onYamlShowTypeChange(publishCfg.contentShowType)
if (hideTip !== true) {
ElMessage.success(t("main.opt.success"))
}
}
const initPage = async () => {
Expand Down Expand Up @@ -486,8 +500,6 @@ const initPage = async () => {
// 表单属性转换为YAML
doConvertAttrToYAML(props.yamlConverter, formData.value.postForm, githubCfg)
// YAML
initYaml(yamlData.yamlContent)
// 显示默认
onYamlShowTypeChange(publishCfg.contentShowType)
Expand Down
6 changes: 1 addition & 5 deletions composables/makeYamlCom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ import { LogFactory } from "~/utils/logUtil"
import { useI18n } from "vue-i18n"
import { YamlConvertAdaptor } from "~/utils/platform/yamlConvertAdaptor"
import { PostForm } from "~/utils/common/postForm"
import * as yamlUtil from "~/utils/yamlUtil"
import * as dateUtil from "~/utils/dateUtil"
import { YamlObj } from "~/utils/common/yamlObj"
import { IGithubCfg } from "~/utils/platform/github/githubCfg"

/**
Expand All @@ -59,7 +56,7 @@ export const useYaml = () => {
yamlConverter: YamlConvertAdaptor,
postForm: PostForm,
githubCfg?: IGithubCfg
): YamlObj => {
): void => {
if (!yamlConverter) {
yamlConverter = new YamlConvertAdaptor()
logger.error("未指定YAML转换器")
Expand All @@ -70,7 +67,6 @@ export const useYaml = () => {
yamlData.mdContent = yamlObj.mdContent
yamlData.mdFullContent = yamlObj.formatter + "\n" + yamlObj.mdContent
yamlData.htmlContent = yamlObj.htmlContent
return yamlObj
}

const convertYAMLToAttr = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export class VuepressYamlConvertAdaptor
postForm.formData.customSlug
)
}
this.logger.debug("link=>", link)
yamlObj.yamlObj.permalink = link

yamlObj.yamlObj.date = covertStringToDate(postForm.formData.created)
Expand Down

0 comments on commit dfbf9de

Please sign in to comment.