Skip to content

Commit

Permalink
feat: 掘金平台分类与标签初始化
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Sep 8, 2023
1 parent a3fa652 commit e322697
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 20 deletions.
33 changes: 33 additions & 0 deletions src/adaptors/web/juejin/juejinWebAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,39 @@ class JuejinWebAdaptor extends BaseWebApi {
return true
}

public async getPost(postid: string, useSlug?: boolean): Promise<Post> {
const juejinPostKey = this.getJuejinPostidKey(postid)
const pageId = juejinPostKey.pageId

const url = "https://api.juejin.cn/content_api/v1/article/detail"
const params = {
article_id: pageId,
}
const res = await this.webProxyFetch(url, [], params, "POST")
this.logger.debug("juejin get post res =>", res)
if (res.err_no !== 0) {
throw new Error("掘金文章获取失败 =>" + res.err_msg)
}

const commonPost = new Post()

// 掘金标签
const tags = res.data.tags ?? []
const tagSlugs = []
tags.forEach((item: any) => {
tagSlugs.push(item.tag_id)
})
commonPost.tags_slugs = tagSlugs.join(",")

// 掘金分类
const cate = res.data.category.category_id
const catSlugs = []
catSlugs.push(cate)
commonPost.cate_slugs = catSlugs

return commonPost
}

public async getCategories(): Promise<CategoryInfo[]> {
const cats = [] as CategoryInfo[]

Expand Down
3 changes: 2 additions & 1 deletion src/components/publish/SinglePublishDoPublish.vue
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ const getBlogName = () => {
if (formData.mergedPost?.categories?.length > 0) {
cateName = formData.mergedPost?.categories[0]
} else {
cateName = formData.mergedPost?.cate_slugs[0]
// cateName = formData.mergedPost?.cate_slugs[0]
cateName = ""
}
blogName = cateName ?? ""
}
Expand Down
13 changes: 11 additions & 2 deletions src/components/publish/form/kwspace/SingleKnowledgeSpace.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ const formData = reactive({
categorySelected: "",
categoryList: [],
},
isInit: false
})
// emits
Expand Down Expand Up @@ -99,12 +101,19 @@ const initPage = async () => {
}
onMounted(async () => {
await initPage()
try {
await initPage()
} catch (e) {
logger.error("知识空间加载失败", e)
} finally {
formData.isInit = true
}
})
</script>

<template>
<div class="single-knowledge-space" v-if="formData.knowledgeSpaceConfig.cateEnabled">
<el-skeleton class="placeholder" v-if="!formData.isInit" :rows="1" animated />
<div class="single-knowledge-space" v-else>
<el-form-item :label="cateTitle">
<el-select
v-model="formData.cate.categorySelected"
Expand Down
35 changes: 19 additions & 16 deletions src/components/publish/form/tagslug/SingleTagSlug.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { TagInfo } from "zhi-blog-api"
import Adaptors from "~/src/adaptors"
import { createAppLogger } from "~/src/utils/appLogger.ts"
import { useVueI18n } from "~/src/composables/useVueI18n.ts"
import {computed} from "vue/dist/vue";
import { computed } from "vue/dist/vue"
const logger = createAppLogger("single-tag-slugs")
const { t } = useVueI18n()
Expand Down Expand Up @@ -58,8 +58,9 @@ const formData = reactive({
tagSelected: "",
tagList: [],
},
})
isInit: false,
})
// emits
const emit = defineEmits(["emitSyncTagSlugs"])
Expand Down Expand Up @@ -100,27 +101,29 @@ const initPage = async () => {
}
onMounted(async () => {
await initPage()
try {
await initPage()
} catch (e) {
logger.error("别名标签加载失败", e)
} finally {
formData.isInit = true
}
})
</script>

<template>
<div class="single-tag-slug">
<el-skeleton class="placeholder" v-if="!formData.isInit" :rows="1" animated />
<div v-else class="single-tag-slug">
<el-form-item label="标签">
<el-select
v-model="formData.tag.tagSelected"
placeholder="请选择"
no-data-text="暂无数据"
class="m-2"
size="default"
@change="handleCatNodeSingleCheck"
v-model="formData.tag.tagSelected"
placeholder="请选择"
no-data-text="暂无数据"
class="m-2"
size="default"
@change="handleCatNodeSingleCheck"
>
<el-option
v-for="item in formData.tag.tagList"
:key="item.value"
:label="item.label"
:value="item.value"
/>
<el-option v-for="item in formData.tag.tagList" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</el-form-item>
<div class="form-item-bottom"></div>
Expand Down
2 changes: 1 addition & 1 deletion testdata/juejin/juejin.http
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Content-Type: application/json
}

### 获取文章详情
POST https://api.juejin.cn/content_api/v1/article/detail?aid=2608
POST https://api.juejin.cn/content_api/v1/article/detail
Cookie: {{cookie}}
Content-Type: application/json

Expand Down

0 comments on commit e322697

Please sign in to comment.