diff --git a/apps/web/src/components/editor/editor-header/PostInfo.vue b/apps/web/src/components/editor/editor-header/PostInfo.vue index 2a16b9281..22c77bd07 100644 --- a/apps/web/src/components/editor/editor-header/PostInfo.vue +++ b/apps/web/src/components/editor/editor-header/PostInfo.vue @@ -75,16 +75,21 @@ async function prePost() { declare global { interface Window { syncPost: (data: { thumb: string, title: string, desc: string, content: string }) => void - $syncer: any + $cose: any } } async function getAccounts(): Promise { return new Promise((resolve) => { - window.$syncer?.getAccounts((resp: PostAccount[]) => { - allAccounts.value = resp.map(a => ({ ...a, checked: true })) + if (window.$cose !== undefined) { + window.$cose.getAccounts((resp: PostAccount[]) => { + allAccounts.value = resp.map(a => ({ ...a, checked: false })) + resolve() + }) + } + else { resolve() - }) + } }) } @@ -100,8 +105,17 @@ function onUpdate(val: boolean) { } } +function getPlatformUrl(type: string): string { + const urls: Record = { + csdn: 'https://blog.csdn.net', + juejin: 'https://juejin.cn', + wechat: 'https://mp.weixin.qq.com', + } + return urls[type] || '#' +} + function checkExtension() { - if (window.$syncer !== undefined) { + if (window.$cose !== undefined) { extensionInstalled.value = true return } @@ -109,7 +123,7 @@ function checkExtension() { // 如果插件还没加载,5秒内每 500ms 检查一次 let count = 0 const timer = setInterval(async () => { - if (window.$syncer !== undefined) { + if (window.$cose !== undefined) { extensionInstalled.value = true await getAccounts() clearInterval(timer) @@ -117,7 +131,7 @@ function checkExtension() { } count++ - if (count > 10) { // 5秒后还是没有检测到,就停止检查 + if (count > 10) { clearInterval(timer) } }, 500) @@ -156,14 +170,7 @@ onBeforeMount(() => { 未检测到插件 - 请安装 - - 文章同步助手 - - 插件 + 请安装 cose 文章同步助手 浏览器扩展 @@ -188,28 +195,51 @@ onBeforeMount(() => {
-
-
-
diff --git a/apps/web/src/components/editor/editor-header/PostTaskDialog.vue b/apps/web/src/components/editor/editor-header/PostTaskDialog.vue index 5d4875b70..c1aa7ec10 100644 --- a/apps/web/src/components/editor/editor-header/PostTaskDialog.vue +++ b/apps/web/src/components/editor/editor-header/PostTaskDialog.vue @@ -2,6 +2,12 @@ import type { Post } from '@md/shared/types' import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog' +declare global { + interface Window { + $cose: any + } +} + const props = defineProps<{ post: Post open: boolean @@ -21,25 +27,27 @@ async function startPost() { if (!props.post) return + const taskData = { + post: { + title: props.post.title, + content: props.post.content, + markdown: props.post.markdown, + thumb: props.post.thumb, + desc: props.post.desc, + }, + accounts: props.post.accounts.filter(a => a.checked), + } + + const onProgress = (newStatus: any) => { + taskStatus.value = newStatus + } + + const onComplete = () => { + submitting.value = false + } + try { - window.$syncer?.addTask( - { - post: { - title: props.post.title, - content: props.post.content, - markdown: props.post.markdown, - thumb: props.post.thumb, - desc: props.post.desc, - }, - accounts: props.post.accounts.filter(a => a.checked), - }, - (newStatus: any) => { - taskStatus.value = newStatus - }, - () => { - submitting.value = false - }, - ) + window.$cose?.addTask(taskData, onProgress, onComplete) } catch (error) { console.error(`发布失败:`, error) diff --git a/packages/shared/src/types/common.ts b/packages/shared/src/types/common.ts index af5f2f129..ed028396a 100644 --- a/packages/shared/src/types/common.ts +++ b/packages/shared/src/types/common.ts @@ -56,15 +56,16 @@ export interface Alert { } export interface PostAccount { - avatar: string + avatar?: string displayName: string home: string icon: string - supportTypes: string[] + supportTypes?: string[] title: string type: string uid: string checked: boolean + loggedIn?: boolean status?: string error?: string }