From 3814adf47a5d2e68017578335aa857ceb39f29b9 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Thu, 4 May 2023 19:09:21 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/8043 --- app/appearance/langs/zh_CN.json | 1 + app/src/config/bazaar.ts | 85 ++++++++++++++++++++++----------- app/src/types/index.d.ts | 2 +- 3 files changed, 59 insertions(+), 29 deletions(-) diff --git a/app/appearance/langs/zh_CN.json b/app/appearance/langs/zh_CN.json index bcdfe2b4b..82396b949 100644 --- a/app/appearance/langs/zh_CN.json +++ b/app/appearance/langs/zh_CN.json @@ -1,4 +1,5 @@ { + "plugin": "插件", "attrBookmarkTip": "将该块和一个书签进行关联,以便后续通过书签面板查看", "attrNameTip": "为该块设置命名,主要用于引用和搜索,一个块只能拥有一个唯一的命名", "attrAliasTip": "为该块设置别名,一个块可以通过英文逗号分隔设置多个别名", diff --git a/app/src/config/bazaar.ts b/app/src/config/bazaar.ts index 0dd6ecde2..d24e1bb60 100644 --- a/app/src/config/bazaar.ts +++ b/app/src/config/bazaar.ts @@ -19,14 +19,34 @@ export const bazaar = { const loadingHTML = `
`; return `
-
${window.siyuan.languages.theme}
+
${window.siyuan.languages.downloaded}
+
${window.siyuan.languages.theme}
${window.siyuan.languages.template}
+
${window.siyuan.languages.plugin}
${window.siyuan.languages.icon}
${window.siyuan.languages.widget}
-
${window.siyuan.languages.downloaded}
-
+
+
+
+
+
+ +
+ +
+ +
+ +
+ +
+
+ ${loadingHTML} +
+
+
@@ -70,6 +90,24 @@ export const bazaar = { ${loadingHTML}
+
+
+
+
+
+ +
+ +
+
+ ${loadingHTML} +
+
@@ -106,23 +144,6 @@ export const bazaar = { ${loadingHTML}
-
-
-
-
-
- -
- -
- -
- -
-
- ${loadingHTML} -
-
`; @@ -185,6 +206,8 @@ export const bazaar = { url = "/api/bazaar/getInstalledWidget"; } else if (bazaarType === "templates") { url = "/api/bazaar/getInstalledTemplate"; + } else if (bazaarType === "plugins") { + url = "/api/bazaar/getInstalledPlugin"; } fetchPost(url, {}, response => { let html = ""; @@ -236,6 +259,7 @@ export const bazaar = { templates: [] as IBazaarItem[], icons: [] as IBazaarItem[], widgets: [] as IBazaarItem[], + plugins: [] as IBazaarItem[], downloaded: [] as IBazaarItem[], }, _renderReadme(cardElement: HTMLElement, bazaarType: TBazaarType) { @@ -342,10 +366,7 @@ export const bazaar = { readmeElement.classList.add("config-bazaar__readme--show"); }, bindEvent() { - fetchPost("/api/bazaar/getBazaarTheme", {}, response => { - bazaar._onBazaar(response, "themes", false); - bazaar._data.themes = response.data.packages; - }); + this._genMyHTML("themes"); bazaar.element.firstElementChild.addEventListener("click", (event) => { let target = event.target as HTMLElement; while (target && !target.isEqualNode(bazaar.element)) { @@ -363,7 +384,7 @@ export const bazaar = { event.preventDefault(); event.stopPropagation(); break; - } else if (type === "myTheme" || type === "myTemplate" || type === "myIcon" || type === "myWidget") { + } else if (["myTheme", "myTemplate", "myIcon", "myWidget", "myPlugin"].includes(type)) { if (target.classList.contains("b3-button--outline")) { target.parentElement.childNodes.forEach((item: HTMLElement) => { if (item.nodeType !== 3 && item.classList.contains("b3-button")) { @@ -551,8 +572,16 @@ export const bazaar = { bazaar._onBazaar(response, "widgets", false); bazaar._data.widgets = response.data.packages; }); - } else if (type === "downloaded") { - this._genMyHTML("themes"); + } else if (type === "theme") { + fetchPost("/api/bazaar/getBazaarTheme", {}, response => { + bazaar._onBazaar(response, "themes", false); + bazaar._data.themes = response.data.packages; + }); + } else if (type === "plugin") { + fetchPost("/api/bazaar/getBazaarPlugin", {}, response => { + bazaar._onBazaar(response, "plugins", false); + bazaar._data.themes = response.data.packages; + }); } item.setAttribute("data-init", "true"); } @@ -578,7 +607,7 @@ export const bazaar = { if (selectElement.id === "bazaarSelect") { // theme select bazaar.element.querySelectorAll("#configBazaarTheme .b3-card").forEach((item) => { - const dataObj = JSON.parse(item.getAttribute("data-obj")); + const dataObj = JSON.parse(item.getAttribute("data-obj")); if (selectElement.value === "0") { if (dataObj.themeMode.indexOf("light") > -1) { item.classList.remove("fn__none"); diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts index b7d499f48..93a535d2d 100644 --- a/app/src/types/index.d.ts +++ b/app/src/types/index.d.ts @@ -29,7 +29,7 @@ type TOperation = | "removeAttrViewBlock" | "addFlashcards" | "removeFlashcards" -type TBazaarType = "templates" | "icons" | "widgets" | "themes" +type TBazaarType = "templates" | "icons" | "widgets" | "themes" | "plugins" type TCardType = "doc" | "notebook" | "all" declare module "blueimp-md5"