-
Notifications
You must be signed in to change notification settings - Fork 419
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 文章或草稿支持批量导出markdown或批量删除操作 #296
- Loading branch information
Showing
5 changed files
with
108 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { checkDemo } from "./check" | ||
import { parseObjToMarkdown } from "./parseMarkdownFile" | ||
import { getArticleById, deleteArticle, deleteDraft, getDraftById } from "./api" | ||
import { Modal } from "antd"; | ||
|
||
// 批量操作 | ||
export const batchDelete = (ids: string[],isDraft =false) => { | ||
return new Promise((resolve, reject) => { | ||
const result = checkDemo(); | ||
if (!result) { | ||
reject(); | ||
return; | ||
} | ||
Modal.confirm({ | ||
title: '确定要删除选中内容吗?', | ||
content: '删除后无法恢复', | ||
onOk: async () => { | ||
let cnt = 0; | ||
for (const id of ids) { | ||
const fn = isDraft ? deleteDraft : deleteArticle; | ||
|
||
fn(id).finally(()=>{ | ||
cnt = cnt + 1; | ||
if (cnt >= ids.length) { | ||
resolve(true); | ||
return; | ||
} | ||
}) | ||
} | ||
}, | ||
}) | ||
}); | ||
|
||
|
||
} | ||
|
||
|
||
|
||
export const batchExport = async (ids: string[], isDraft= false) => { | ||
for (const id of ids) { | ||
await exportEachById(id, isDraft); | ||
} | ||
} | ||
|
||
|
||
export const exportEachById = async (id: string,isDraft=false) => { | ||
const fn = isDraft ? getDraftById : getArticleById; | ||
const { data: obj } = await getArticleById(id); | ||
const md = parseObjToMarkdown(obj); | ||
const data = new Blob([md]); | ||
const url = URL.createObjectURL(data); | ||
const link = document.createElement('a'); | ||
link.href = url; | ||
link.download = `${obj.title}.md`; | ||
link.click(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { message } from "antd"; | ||
|
||
export const checkDemo = () => { | ||
if (location.hostname == 'blog-demo.mereith.com') { | ||
message.warn('演示站禁止此操作!'); | ||
return false; | ||
} | ||
return true; | ||
} |