Vanessa 2024-03-21 22:55:14 +08:00
parent 4817bc0812
commit 893f645a82

View file

@ -293,8 +293,17 @@ export const bazaar = {
</div> </div>
</div>`; </div>`;
}, },
_genUpdateItemHTML (item: IBazaarItem) { _genUpdateItemHTML(item: IBazaarItem, bazaarType: TBazaarType) {
return `<div class="b3-card"> const dataObj = {
bazaarType,
themeMode: item.modes?.toString(),
updated: item.updated,
name: item.name,
repoURL: item.repoURL,
repoHash: item.repoHash,
downloaded: true
};
return `<div class="b3-card" data-obj='${JSON.stringify(dataObj)}'>
<div class="b3-card__img"><img src="${item.iconURL}" onerror="this.src='/stage/images/icon.png'"/></div> <div class="b3-card__img"><img src="${item.iconURL}" onerror="this.src='/stage/images/icon.png'"/></div>
<div class="fn__flex-1 fn__flex-column"> <div class="fn__flex-1 fn__flex-column">
<div class="b3-card__info b3-card__info--left fn__flex-1"> <div class="b3-card__info b3-card__info--left fn__flex-1">
@ -303,39 +312,45 @@ export const bazaar = {
</div> </div>
</div> </div>
<div class="b3-card__actions b3-card__actions--right"> <div class="b3-card__actions b3-card__actions--right">
${item.incompatible ? `<span class="fn__flex-center b3-tooltips b3-tooltips__nw b3-chip b3-chip--error b3-chip--small" aria-label="${window.siyuan.languages.incompatiblePluginTip}">${window.siyuan.languages.incompatible}</span>` : ""} ${item.incompatible ? `<span class="fn__space"></span><span class="fn__flex-center b3-tooltips b3-tooltips__nw b3-chip b3-chip--error b3-chip--small" aria-label="${window.siyuan.languages.incompatiblePluginTip}">${window.siyuan.languages.incompatible}</span>` : ""}
${item.preferredFunding ? `<span class="fn__space"></span><a target="_blank" href="${item.preferredFunding}" class="block__icon block__icon--show ariaLabel" aria-label="${window.siyuan.languages.sponsor} ${item.preferredFunding}"><svg class="ft__pink"><use xlink:href="#iconHeart"></use></svg></a>` : ""} ${item.preferredFunding ? `<a target="_blank" href="${item.preferredFunding}" class="block__icon block__icon--show ariaLabel" aria-label="${window.siyuan.languages.sponsor} ${item.preferredFunding}"><svg class="ft__pink"><use xlink:href="#iconHeart"></use></svg></a>` : ""}
<span class="b3-tooltips b3-tooltips__nw block__icon block__icon--show${isBrowser() ? " fn__none" : ""}" data-type="open" aria-label="${window.siyuan.languages.showInFolder}">
<svg><use xlink:href="#iconFolder"></use></svg>
</span>
<span data-type="install-t" aria-label="${window.siyuan.languages.update}" class="b3-tooltips b3-tooltips__nw block__icon block__icon--show">
<svg class="ft__primary"><use xlink:href="#iconRefresh"></use></svg>
</span>
</div> </div>
</div>` </div>`;
}, },
_getUpdate() { _getUpdate() {
fetchPost("/api/bazaar/getUpdatedPackage", {frontend: getFrontend()}, (response) => { fetchPost("/api/bazaar/getUpdatedPackage", {frontend: getFrontend()}, (response) => {
let html = ""; let html = "";
response.data.plugins.forEach((item: IBazaarItem) => { response.data.plugins.forEach((item: IBazaarItem) => {
html += this._genUpdateItemHTML(item); html += this._genUpdateItemHTML(item, "plugins");
}); });
response.data.themes.forEach((item: IBazaarItem) => { response.data.themes.forEach((item: IBazaarItem) => {
html += this._genUpdateItemHTML(item); html += this._genUpdateItemHTML(item, "themes");
}); });
response.data.icons.forEach((item: IBazaarItem) => { response.data.icons.forEach((item: IBazaarItem) => {
html += this._genUpdateItemHTML(item); html += this._genUpdateItemHTML(item, "icons");
}); });
response.data.templates.forEach((item: IBazaarItem) => { response.data.templates.forEach((item: IBazaarItem) => {
html += this._genUpdateItemHTML(item); html += this._genUpdateItemHTML(item, "templates");
}); });
response.data.widgets.forEach((item: IBazaarItem) => { response.data.widgets.forEach((item: IBazaarItem) => {
html += this._genUpdateItemHTML(item); html += this._genUpdateItemHTML(item, "widgets");
}); });
this.element.querySelector('[data-type="downloaded-update"]').innerHTML = `<div class="fn__flex config-bazaar__title"> this.element.querySelector('[data-type="downloaded-update"]').innerHTML = `<div class="fn__flex config-bazaar__title">
<div class="fn__flex-1"></div> <div class="fn__flex-1"></div>
<button class="b3-button">${window.siyuan.languages.update}</button> <button class="b3-button" data-type="install-all">${window.siyuan.languages.update}</button>
<span class="fn__space"></span> <span class="fn__space"></span>
<div class="counter counter--bg fn__flex-center">${response.data.themes.length + response.data.icons.length + response.data.widgets.length + response.data.plugins.length + response.data.templates.length}</div> <div class="counter counter--bg fn__flex-center">${response.data.themes.length + response.data.icons.length + response.data.widgets.length + response.data.plugins.length + response.data.templates.length}</div>
</div> </div>
<div class="config-bazaar__content">${html}</div>`; <div class="config-bazaar__content">${html}</div>`;
}) })
}, },
_genMyHTML(bazaarType: TBazaarType, app: App) { _genMyHTML(bazaarType: TBazaarType, app: App, updateUpdate = true) {
const contentElement = bazaar.element.querySelector("#configBazaarDownloaded"); const contentElement = bazaar.element.querySelector("#configBazaarDownloaded");
if (contentElement.getAttribute("data-loading") === "true" || if (contentElement.getAttribute("data-loading") === "true" ||
contentElement.previousElementSibling.querySelector(`[data-type="my${bazaarType.replace(bazaarType[0], bazaarType[0].toUpperCase()).substring(0, bazaarType.length - 1)}"]`).classList.contains("b3-button--outline")) { contentElement.previousElementSibling.querySelector(`[data-type="my${bazaarType.replace(bazaarType[0], bazaarType[0].toUpperCase()).substring(0, bazaarType.length - 1)}"]`).classList.contains("b3-button--outline")) {
@ -430,6 +445,9 @@ export const bazaar = {
} }
contentElement.innerHTML = html ? html : `<div class="fn__hr"></div><ul class="b3-list b3-list--background"><li class="b3-list--empty">${window.siyuan.languages.emptyContent}</li></ul>`; contentElement.innerHTML = html ? html : `<div class="fn__hr"></div><ul class="b3-list b3-list--background"><li class="b3-list--empty">${window.siyuan.languages.emptyContent}</li></ul>`;
}); });
if (updateUpdate) {
this._getUpdate();
}
}, },
_data: { _data: {
themes: [] as IBazaarItem[], themes: [] as IBazaarItem[],
@ -578,7 +596,6 @@ export const bazaar = {
return; return;
} }
this._genMyHTML("plugins", app); this._genMyHTML("plugins", app);
this._getUpdate();
bazaar.element.firstElementChild.addEventListener("click", (event) => { bazaar.element.firstElementChild.addEventListener("click", (event) => {
let target = event.target as HTMLElement; let target = event.target as HTMLElement;
const dataElement = hasClosestByAttribute(target, "data-obj", null); const dataElement = hasClosestByAttribute(target, "data-obj", null);
@ -611,7 +628,7 @@ export const bazaar = {
} }
}); });
target.classList.remove("b3-button--outline"); target.classList.remove("b3-button--outline");
this._genMyHTML(type.replace("my", "").toLowerCase() + "s" as TBazaarType, app); this._genMyHTML(type.replace("my", "").toLowerCase() + "s" as TBazaarType, app, false);
} }
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
@ -662,7 +679,7 @@ export const bazaar = {
} }
} }
bazaar._onBazaar(response, bazaarType, ["themes", "icons"].includes(bazaarType)); bazaar._onBazaar(response, bazaarType, ["themes", "icons"].includes(bazaarType));
bazaar._genMyHTML(bazaarType, app); bazaar._genMyHTML(bazaarType, app, false);
if (bazaarType === "plugins") { if (bazaarType === "plugins") {
if (window.siyuan.config.bazaar.petalDisabled) { if (window.siyuan.config.bazaar.petalDisabled) {
confirmDialog(window.siyuan.languages.confirm, window.siyuan.languages.enablePluginTip2); confirmDialog(window.siyuan.languages.confirm, window.siyuan.languages.enablePluginTip2);
@ -674,7 +691,7 @@ export const bazaar = {
frontend: getFrontend() frontend: getFrontend()
}, (response) => { }, (response) => {
loadPlugin(app, response.data); loadPlugin(app, response.data);
bazaar._genMyHTML(bazaarType, app); bazaar._genMyHTML(bazaarType, app, false);
}); });
}); });
} }
@ -684,6 +701,11 @@ export const bazaar = {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
break; break;
} else if (type === "install-all") {
fetchPost("/api/bazaar/batchUpdatePackage", {frontend: getFrontend()});
event.preventDefault();
event.stopPropagation();
break;
} else if (type === "install-t") { } else if (type === "install-t") {
if (!target.classList.contains("b3-button--progress")) { if (!target.classList.contains("b3-button--progress")) {
confirmDialog(window.siyuan.languages.update, window.siyuan.languages.exportTplTip, () => { confirmDialog(window.siyuan.languages.update, window.siyuan.languages.exportTplTip, () => {
@ -790,7 +812,7 @@ export const bazaar = {
fetchPost("/api/setting/setAppearance", Object.assign({}, window.siyuan.config.appearance, { fetchPost("/api/setting/setAppearance", Object.assign({}, window.siyuan.config.appearance, {
icon: packageName, icon: packageName,
}), (appearanceResponse) => { }), (appearanceResponse) => {
this._genMyHTML(bazaarType, app); this._genMyHTML(bazaarType, app, false);
fetchPost("/api/bazaar/getBazaarIcon", {}, response => { fetchPost("/api/bazaar/getBazaarIcon", {}, response => {
response.data.appearance = appearanceResponse.data; response.data.appearance = appearanceResponse.data;
bazaar._onBazaar(response, "icons", true); bazaar._onBazaar(response, "icons", true);
@ -827,7 +849,7 @@ export const bazaar = {
return; return;
} }
} }
this._genMyHTML("themes", app); this._genMyHTML("themes", app, false);
fetchPost("/api/bazaar/getBazaarTheme", {}, response => { fetchPost("/api/bazaar/getBazaarTheme", {}, response => {
response.data.appearance = appearanceResponse.data; response.data.appearance = appearanceResponse.data;
bazaar._onBazaar(response, "themes", true); bazaar._onBazaar(response, "themes", true);