mirror of
https://github.com/fireinrain/JHS-enhance.git
synced 2026-10-12 04:36:37 +08:00
详情页也添加删除按钮
This commit is contained in:
@@ -147,80 +147,9 @@ class CoverButtonPlugin extends BasePlugin {
|
||||
const matchList = JSON.parse(matchData);
|
||||
const $box2 = $btn.closest(".item");
|
||||
const {carNum: carNum2} = this.getBoxCarInfo($box2);
|
||||
this.showDeleteDialog(carNum2, matchList, $box2);
|
||||
}));
|
||||
}
|
||||
|
||||
showDeleteDialog(carNum2, matchList, $box2) {
|
||||
const formatSize = bytes => {
|
||||
if (!bytes) return "-";
|
||||
const units = ["B", "KB", "MB", "GB", "TB"];
|
||||
let size = parseFloat(bytes), unit = 0;
|
||||
for (; size >= 1024 && unit < units.length - 1;) size /= 1024, unit++;
|
||||
return size.toFixed(2) + " " + units[unit];
|
||||
};
|
||||
let html = '<div style="padding: 15px; max-height: 400px; overflow-y: auto;">';
|
||||
html += `<div style="margin-bottom: 12px; font-size: 14px;">作品 <b>${carNum2}</b> 匹配到 <b>${matchList.length}</b> 个文件夹:</div>`;
|
||||
html += '<div style="margin-bottom: 10px;"><label style="cursor: pointer;"><input type="checkbox" class="jhs-delete-select-all" checked> <b>全选</b></label></div>';
|
||||
for (let i = 0; i < matchList.length; i++) {
|
||||
const m = matchList[i];
|
||||
html += `<div style="margin-bottom: 6px; padding: 8px 10px; border: 1px solid #e0e0e0; border-radius: 4px; background: #fafafa;">
|
||||
<label style="display: flex; align-items: flex-start; cursor: pointer; width: 100%;">
|
||||
<input type="checkbox" class="jhs-delete-folder-cb" data-index="${i}" checked style="margin-top: 3px; flex-shrink: 0;">
|
||||
<span style="margin-left: 8px; flex: 1;">
|
||||
<div style="word-break: break-all;">${m.name}</div>
|
||||
<div style="font-size: 12px; color: #888; margin-top: 2px;">${formatSize(m.size)} | ${m.createTime}</div>
|
||||
</span>
|
||||
</label>
|
||||
</div>`;
|
||||
}
|
||||
html += "</div>";
|
||||
const layerIndex = layer.open({
|
||||
type: 1,
|
||||
title: `删除115作品文件夹`,
|
||||
content: html,
|
||||
area: ["520px", "auto"],
|
||||
btn: ["确定删除", "取消"],
|
||||
shadeClose: !1,
|
||||
yes: async index => {
|
||||
const $layer = $(`#layui-layer${index}`);
|
||||
const checked = $layer.find(".jhs-delete-folder-cb:checked");
|
||||
if (0 === checked.length) {
|
||||
show.error("请至少选择一个文件夹");
|
||||
return;
|
||||
}
|
||||
const selected = checked.map((function () {
|
||||
return parseInt($(this).data("index"));
|
||||
})).get();
|
||||
layer.close(index);
|
||||
let loadObj = loading();
|
||||
let deletedCount = 0;
|
||||
try {
|
||||
for (const i of selected) {
|
||||
const m = matchList[i];
|
||||
const result = await gmHttp.postForm("https://webapi.115.com/rb/delete", {
|
||||
pid: m.dirId,
|
||||
"fid[0]": m.folderId
|
||||
});
|
||||
result && result.state ? deletedCount++ : console.error(`删除失败: ${m.name}`, result);
|
||||
}
|
||||
loadObj.close();
|
||||
show.ok(`作品 "${carNum2}" 已删除 ${deletedCount} 个文件夹`);
|
||||
const matchPlugin = this.getBean("WangPan115MatchPlugin");
|
||||
const newMatchList = await matchPlugin.searchFiles(carNum2);
|
||||
matchPlugin.updateMatchStatus($box2, carNum2, newMatchList);
|
||||
//暂时没有删除离线任务的功能
|
||||
//this.getBean("WangPan115TaskPlugin").deleteOfflineTasksByKeyword(carNum2);
|
||||
} catch (error) {
|
||||
loadObj.close();
|
||||
console.error("删除115文件失败:", error);
|
||||
show.error(`删除失败: ${error.message || "网络错误"}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
$(`#layui-layer${layerIndex}`).on("change", ".jhs-delete-select-all", (function () {
|
||||
const checked = $(this).prop("checked");
|
||||
$(`#layui-layer${layerIndex} .jhs-delete-folder-cb`).prop("checked", checked);
|
||||
this.getBean("WangPan115MatchPlugin").showDeleteDialog(carNum2, matchList, (async newMatchList => {
|
||||
this.getBean("WangPan115MatchPlugin").updateMatchStatus($box2, carNum2, newMatchList);
|
||||
}));
|
||||
}));
|
||||
}
|
||||
showImg($svgElement, $img, carNum2) {
|
||||
|
||||
Reference in New Issue
Block a user