Skip to content

Commit

Permalink
feat: 常规发布显示预览链接
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Aug 5, 2023
1 parent 4d34248 commit c2eceaa
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/components/publish/BatchPublishIndex.vue
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const handleDelete = async () => {
ElMessageBox.confirm(
`确认要删除平台 ${formData.dynList.join(
""
)} 下面的文章吗,此平台文章数据也将永久删除 [注意:系统内置平台会忽略,不做删除] ?`,
)} 下的这篇文章吗,此平台文章数据也将永久删除 [注意:系统内置平台会忽略,不做删除] ?`,
"温馨提示",
{
type: "error",
Expand Down
88 changes: 75 additions & 13 deletions src/components/publish/SinglePublishDoPublish.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@
-->

<script setup lang="ts">
import { onMounted, reactive } from "vue"
import { markRaw, onMounted, reactive } from "vue"
import { useRoute } from "vue-router"
import BackPage from "~/src/components/common/BackPage.vue"
import { usePublish } from "~/src/composables/usePublish.ts"
import { MethodEnum } from "~/src/models/methodEnum.ts"
import { Post } from "zhi-blog-api"
import { createAppLogger } from "~/src/utils/appLogger.ts"
import { useVueI18n } from "~/src/composables/useVueI18n.ts"
import { pre } from "~/src/utils/import/pre.ts"
import { DynamicConfig } from "~/src/components/set/publish/platform/dynamicConfig.ts"
import { useSiyuanApi } from "~/src/composables/useSiyuanApi.ts"
import { ElMessage } from "element-plus"
import { ElMessage, ElMessageBox } from "element-plus"
import { Delete } from "@element-plus/icons-vue"
const logger = createAppLogger("single-publish-do-publish")
Expand All @@ -44,19 +44,15 @@ const { t } = useVueI18n()
const route = useRoute()
const { doInitPage } = usePublish()
const { query } = useRoute()
const { kernelApi, blogApi } = useSiyuanApi()
const { doSinglePublish } = usePublish()
const { kernelApi } = useSiyuanApi()
const { doSinglePublish, doSingleDelete } = usePublish()
// datas
const sysKeys = pre.systemCfg.map((item) => {
return item.platformKey
})
const params = reactive(route.params)
const key = params.key as string
const id = params.id as string
const method = query.method as MethodEnum
const dynList = sysKeys.concat(key)
const formData = reactive({
isInit: false,
isPublishLoading: false,
Expand Down Expand Up @@ -97,13 +93,61 @@ const handlePublish = async () => {
}
}
const handleDelete = async () => {}
const handleDelete = async () => {
const platformName = getPlatformName()
const blogName = getBlogName()
ElMessageBox.confirm(
`确认要删除 [${platformName} - ${blogName}] 下的这篇文章吗,此平台的文章数据将永久删除 ?`,
"温馨提示",
{
type: "error",
icon: markRaw(Delete),
confirmButtonText: t("main.opt.ok"),
cancelButtonText: t("main.opt.cancel"),
}
)
.then(async () => {
await doDelete()
})
.catch(() => {})
}
const getTitle = () => {
const doDelete = async () => {
try {
formData.isDeleteLoading = true
await doSingleDelete(key, id)
// 刷新页面
formData.isInit = false
formData.actionEnable = false
await initPage()
// 需要刷新才能继续操作,防止重复提交
formData.isInit = true
formData.actionEnable = true
const platformName = getPlatformName()
const blogName = getBlogName()
ElMessage.success(`[${platformName} - ${blogName}] 文章删除成功`)
} catch (error) {
ElMessage.error(error.message)
} finally {
formData.isDeleteLoading = false
}
}
const getPlatformName = () => {
const dynCfg = formData.singleFormData?.dynCfg as DynamicConfig
return dynCfg?.platformName || ""
}
const getBlogName = () => {
const cfg = formData.singleFormData?.cfg as any
const platformName = dynCfg?.platformName || ""
const blogName = cfg?.blogName || ""
return cfg?.blogName || ""
}
const getTitle = () => {
const platformName = getPlatformName()
const blogName = getBlogName()
let title = "当前操作的平台为 - "
title += platformName ? platformName : key
Expand Down Expand Up @@ -205,6 +249,24 @@ onMounted(async () => {
{{ t("main.cancel") }}
</el-button>
</el-form-item>

<!-- 文章状态 -->
<el-form-item>
<el-button :type="method === MethodEnum.METHOD_EDIT ? 'success' : 'danger'" text disabled>
{{
method === MethodEnum.METHOD_EDIT
? t("main.publish.status.published")
: t("main.publish.status.unpublish")
}}
</el-button>
<a
v-if="method === MethodEnum.METHOD_EDIT"
:href="formData.singleFormData.previewUrl"
:title="formData.singleFormData.previewUrl"
target="_blank"
>{{ t("main.publish.see.preview") }}</a
>
</el-form-item>
</el-form>
</div>
</el-main>
Expand Down
17 changes: 13 additions & 4 deletions src/composables/usePublish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { JsonUtil, StrUtil } from "zhi-common"
import { AppInstance } from "~/src/appInstance.ts"
import Adaptors from "~/src/adaptors"
import { Utils } from "~/src/utils/utils.ts"
import { Post } from "zhi-blog-api"
import { BlogAdaptor, Post } from "zhi-blog-api"
import { useVueI18n } from "~/src/composables/useVueI18n.ts"
import { useSettingStore } from "~/src/stores/useSettingStore.ts"
import { useSiyuanApi } from "~/src/composables/useSiyuanApi.ts"
Expand Down Expand Up @@ -119,9 +119,9 @@ const usePublish = () => {
const result = await api.editPost(singleFormData.postid, doc)
logger.info("edit post=>", result)
}
const previewUrl = await api.getPreviewUrl(singleFormData.postid)
const isAbsoluteUrl = /^http/.test(previewUrl)
singleFormData.previewUrl = isAbsoluteUrl ? previewUrl : `${singleFormData.cfg?.home ?? ""}${previewUrl}`

// 更新预览链接
await setPreviewUrl(api, singleFormData.postid)

singleFormData.publishProcessStatus = true
} catch (e) {
Expand Down Expand Up @@ -236,6 +236,12 @@ const usePublish = () => {
}
}

const setPreviewUrl = async (api: BlogAdaptor, postid: string) => {
const previewUrl = await api.getPreviewUrl(postid)
const isAbsoluteUrl = /^http/.test(previewUrl)
singleFormData.previewUrl = isAbsoluteUrl ? previewUrl : `${singleFormData.cfg?.home ?? ""}${previewUrl}`
}

const assignValue = (title1: string, title2: string) => (title1.length > title2.length ? title1 : title2)

const doInitPage = async (key: string, id: string, method: MethodEnum = MethodEnum.METHOD_ADD) => {
Expand Down Expand Up @@ -287,6 +293,9 @@ const usePublish = () => {
singleFormData.mergedPost.title = assignValue(singleFormData.siyuanPost.title, singleFormData.platformPost.title)
// 正文以思源笔记为准
singleFormData.mergedPost.description = singleFormData.siyuanPost.description

// 更新预览链接
await setPreviewUrl(api, postid)
}
return singleFormData
}
Expand Down

0 comments on commit c2eceaa

Please sign in to comment.