1
0
mirror of https://gitee.com/bookshelfplus/bookshelfplus synced 2025-09-12 19:51:39 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee

Merge branch 'big-change' into develop

This commit is contained in:
2022-04-20 20:23:31 +08:00
28 changed files with 690 additions and 943 deletions

View File

@@ -215,43 +215,7 @@
<hr>
<div class="download-container">
<h3 id="scrollTarget">下载这本书</h3>
<div id="file-container"><% /*
<!-- <div class="file-item">
<div class="file-title">
<span class="file-name size20">bookshelf</span><span class="file-ext size16">.json</span>
<span class="file-size size14" style="padding-left: 30px;">10.02MB</span>
</div>
<div class="file-detail">
<span class="size14 overflow-hide">SHA1<span class="file-sha1 size12">07b12eb2a5915282bf086a7913b0fd9720fc012c</span></span>
<span class="file-copyright size14 overflow-hide">来源信息:中国地质大学(武汉)</span>
<span class="file-copyright size14" style="margin-top: 12px; display: block;">下载方式:</span>
</div>
<div class="file-object">
<div class="file-object-item">
<div class="file-object-item-title">
<img src="/assets/image/svg/baidu_netdisk.svg"/>
<span>百度网盘</span>
</div>
<div class="file-object-item-content">
提取码abcd
</div>
<div class="file-object-item-link">
<a href="" target="_blank">百度网盘</a>
</div>
<div class="outdated-feedback">
<img src="/assets/image/svg/feedback.svg"/>
<span class="outdated-feedback-tip">链接失效?点击反馈!</span>
</div>
</div>
<div class="file-object-item">
<a href="" target="_blank">阿里云盘</a>
</div>
<div class="file-object-item">
<a href="" download="文件名.pdf">直链下载</a>
</div>
</div>
</div> --> */ %>
</div>
<div id="file-container"></div>
</div>
<p style="font-size: 12px;">
* 由于直链下载成本很高,为降低运营成本,目前仅提供给登录用户使用。
@@ -466,14 +430,14 @@
}
function getLinkDOM(fileObjectInfo) {
// 获取文件下载链接DOM
var iconSrc = "/assets/image/svg/direct_link.svg", title = fileObjectInfo.storageMediumType, content = "", downloadLink = "";
var iconSrc = "/assets/image/svg/direct_link.svg", title = fileObjectInfo.storageMedium, content = "", downloadLink = "";
if(fileObjectInfo.fileShareCode != "" && fileObjectInfo.fileShareCode != null) {
content = `<span>提取码: <span class="click2copy" style="user-select: all; cursor: pointer;">${fileObjectInfo.fileShareCode}</span>&nbsp;</span>`; // 最后一个 &nbsp; 是为了保证选中时不会选中后面的回车
downloadLink = `<a class="baiduNetdiskLink" share-code="${fileObjectInfo.fileShareCode}" share-link="${fileObjectInfo.filePath}" style="cursor: pointer;" title="复制提取码并前往">前往</a>`;
} else {
downloadLink = `<a href="${fileObjectInfo.filePath}" target="_blank">前往</a>`;
}
switch (fileObjectInfo.storageMediumType) {
switch (fileObjectInfo.storageMedium) {
case "腾讯云对象存储":
title = "直链下载";
if (!localStorageUtils.getLoginStatus()) {
@@ -490,7 +454,7 @@
iconSrc = "/assets/image/svg/aliyun_drive.svg";
break;
default:
title = fileObjectInfo.storageMediumType;
title = fileObjectInfo.storageMedium;
downloadLink = `<a href="${fileObjectInfo.filePath}" target="_blank">前往</a>`;
break;
}
@@ -530,29 +494,29 @@
// 再处理文件
var fileContainer = document.getElementById("file-container");
var innerHTML = [];
var innerHtmlList = [];
for (let i = 0; i < data.file.length; i++) {
const fileInfo = data.file[i];
innerHTML.push(`
innerHtmlList.push(`
<div class="file-item">
<div class="file-title">
<span class="file-name size20">${fileInfo.fileName}</span><span class="file-ext size16">${fileInfo.fileFormat == "" ? "" : ("." + fileInfo.fileFormat)}</span>
<span class="file-name size20">${fileInfo.fileName}</span><span class="file-ext size16">${fileInfo.fileExt == "" ? "" : ("." + fileInfo.fileExt)}</span>
<span class="file-size size14" style="padding-left: 30px;">${stringifyFileSize(fileInfo.fileSize)}</span>
</div>
<div class="file-detail">
<span class="overflow-hide file-sha1 size12">SHA1<span class="">${fileInfo.fileSha1}</span></span>
<span class="file-copyright size14 overflow-hide">${fileInfo.bookOrigin == "" ? "" : ("来源信息:" + fileInfo.bookOrigin) }</span>
<span class="file-copyright size14 overflow-hide">${fileInfo.source == "" ? "" : ("来源信息:" + fileInfo.source) }</span>
<span class="file-copyright size14" style="margin-top: 12px; display: block;">下载地址:</span>
</div>
<div class="file-object">
${fileObjectList[fileInfo.id] ? fileObjectList[fileInfo.id].join('') : ""}
${fileObjectList[fileInfo.id] ? fileObjectList[fileInfo.id].join('') : "暂无可用下载链接"}
</div>
</div>`
);
}
fileContainer.innerHTML = innerHTML.join("");
if (innerHTML.length == 0) {
fileContainer.innerHTML = innerHtmlList.join("");
if (innerHtmlList.length == 0) {
var fileItem = document.createElement("div");
fileItem.className = "file-item";
fileItem.style.textAlign = "center";

View File

@@ -1,6 +1,5 @@
<div class="searchBox">
<input id="searchInput" type="text" placeholder="只需两步:搜索、下载 就这么简单" /><!--
--><input id="searchButton" type="button" value="搜一下" />
</div>
<script>
@@ -45,13 +44,37 @@
});
// 搜索按钮点击事件
$('#searchButton').click(function () {
var searchBoxValue = $('#searchInput').val();
if (!searchBoxValue || searchBoxValue.trim() == "") {
// alert("请输入搜索内容");
// return;
window.location.href = "./search";
}
window.location.href = "./search?keyword=" + encodeURIComponent(searchBoxValue.trim());
});
if (location.pathname == "/" || !(window.history && history.pushState)) {
// 首页 或者不支持 history.pushState
$('#searchButton').click(function () {
var searchBoxValue = $('#searchInput').val();
if (!searchBoxValue || searchBoxValue.trim() == "") {
searchBoxValue = "";
}
window.location.href = "./search?keyword=" + encodeURIComponent(searchBoxValue.trim());
});
} else {
// 搜索页
$('#searchButton').click(function () {
var searchBoxValue = $('#searchInput').val();
// 如果搜索内容未变化,则不搜索
if (keyword == searchBoxValue.trim()) return;
if (!searchBoxValue || searchBoxValue.trim() == "") {
history.pushState({}, "", "./search"); // 第二个参数为保留参数
} else {
keyword = searchBoxValue.trim();
history.pushState({}, "", "./search?keyword=" + encodeURIComponent(keyword));
doSearch(keyword);
}
});
window.addEventListener('popstate', function (event) {
var requestParams = getParams();
var keyword = (requestParams["keyword"] || "").trim();
var searchbox = document.getElementById("searchInput");
searchbox.value = keyword;
doSearch(keyword);
});
}
</script>

View File

@@ -41,19 +41,26 @@
var renderData = [];
data.forEach(element => {
console.log(element);
var watermarkAndAdvertising = [];
if (element.watermark)
watermarkAndAdvertising.push("有水印");
if (element.advertising)
watermarkAndAdvertising.push("有广告");
watermarkAndAdvertising = watermarkAndAdvertising.join("") || "无";
renderData.push({
编号: `${element.id}`,
关联书籍: element.bookId === 0 ? "未关联书籍" : `<span class="overflow-omit" style="margin: 0 auto;">
关联书籍: element.bookId === 0 ? "<span style=\"font-size: 10px;\">未关联书籍</span>" : `<span class="overflow-omit" style="margin: 0 auto;">
ID: ${element.bookId}
<a href="/book?id=${element.bookId}">查看</a>
<a href="/dashboard/admin/book-manage/detail?id=${element.bookId}">修改</a>
</span>`,
文件名: `${element.fileDisplayName}`,
格式: `${element.fileFormat}`,
页数: `${element.numberOfPages}`,
水印: `${element.watermark}`,
广告: `${element.advertising}`,
来源: `<span class="overflow-omit" style="font-size: 10px;">${element.bookOrigin}</span>`,
文件名: `${element.fileName}`,
格式: `${element.fileExt}`,
页数: `${element.numberOfPages ?element.numberOfPages : ""}`,
"水印&广告": `<span style="font-size: 10px;">${watermarkAndAdvertising}</span>`,
来源: `<span class="overflow-omit" style="font-size: 10px;">${element.source}</span>`,
大小: `${element.fileSize}`,
"哈希(双击全选)": `<span class="overflow-omit" style="font-size: 10px;">${element.fileSha1}</span>`,
时间: `<span class="overflow-omit" style="font-size: 12px; line-height: 1.2em; display: block;"><nobr>

View File

@@ -1,10 +1,3 @@
<style>
/* 限制 哈希 列的宽度 */
tr>*:nth-child(8),
td>*:nth-child(8) {
max-width: 100px;
}
</style>
<p>
<a href="<%= pageUrl %>../">返回上一级</a>
&nbsp;
@@ -33,7 +26,6 @@
ID: ${element.fileId}
<a href="<%= pageUrl %>../detail?id=${element.fileId}">查看</a>
</span>`,
文件名: `${element.fileName}`,
修改日期: element.lastModified === 0 ? "未知" : `<span class="overflow-omit" style="font-size: 12px; line-height: 1.2em; display: block;"><nobr>
${new Date(element.lastModified).toISOString().replace(/T/, ' ').replace(/\..+/, '')}
</nobr></span>`,
@@ -45,9 +37,8 @@
提取码: ${element.fileShareCode}
</nobr></span>`,
存储介质: `<span class="overflow-omit" style="font-size: 12px; line-height: 1.2em; display: block;"><nobr>
${element.storageMediumType}
${element.storageMedium}
</nobr></span>`,
"哈希(双击全选)": `<span class="overflow-omit" style="font-size: 10px;">${element.fileSha1 ? element.fileSha1 : "未知"}</span>`,
状态: `${(element.uploadStatus ? element.uploadStatus : "<span style='color: grey; font-weight: bold;'>未知</span>")
.replace("SUCCESS", "<span style='color: green; font-weight: bold;'>成功</span>")
.replace("UPLOADING", "<span style='color: orange; font-weight: bold;'>正在上传</span>")

View File

@@ -374,9 +374,35 @@
if (status === "success") {
console.log("data", data);
// 取得预授权URL使用该URL进行文件上传
uploadFile(file, data.url, data.fileId);
uploadFile(file, data.url, data.fileId, data.fileObjectId);
} else {
alert(`出错啦!${data.errMsg} (错误码: ${data.errCode}) `);
if (data.errCode == "60001") {
// 文件已存在
console.log(`出错啦!${data.errMsg} (错误码: ${data.errCode}) `);
// 再次发送请求,查询这个已存在文件的 fileId
postRequest("/file/getFileByHash", { token: localStorageUtils.getToken(), fileSha1: fileInfo.fileSha1 })
.then(function (responseData) {
var axiosData = responseData.data;
var status = axiosData.status;
var data = axiosData.data;
if (status === "success") {
console.log(data);
// 查询到之后,询问用户是否跳转到文件详情页
var isRedirect = confirm(`文件已存在,是否前往查看详情?\n文件ID: ${data.id}`);
if (isRedirect)
location.href = `<%= pageUrl %>../detail?fileId=${data.id}`;
} else {
alert(`出错啦!${data.errMsg} (错误码: ${data.errCode}) `);
}
}).catch(function (error) {
console.log(error);
alert("无法连接到服务器,请检查网络连接!");
});
} else {
alert(`出错啦!${data.errMsg} (错误码: ${data.errCode}) `);
}
}
}).catch(function (error) {
console.log(error);
@@ -387,7 +413,7 @@
//##############################################
//传入预授权 URL ,将文件上传到这个地址
//##############################################
function uploadFile(file, preSignedUrl, fileId) {
function uploadFile(file, preSignedUrl, fileId, fileObjectId) {
// refer: https://cloud.tencent.com/document/product/436/35651
// 获取到 Url 后,前端可以这样 ajax 上传
@@ -408,13 +434,16 @@
console.log('上传成功', xhr.status, xhr.statusText);
// 等待进度条走到 100% 否则小文件进度条还没有走完就提示上传完成会让人感觉有点奇怪
setTimeout(function () {
alert("上传成功!");
if ($("#checkbox-auto-upload").is(":checked")) {
window.location.reload();
} else {
// location.href = "<%= pageUrl %>../";
location.href = "<%= pageUrl %>../detail?id=" + fileId;
}
// 上传成功触发一次 “刷新文件对象上传状态”,避免因为云函数回调不成功导致文件对象上传状态没有及时更新
refreshFileObjectStatus(fileObjectId, function () {
alert("上传成功!");
if ($("#checkbox-auto-upload").is(":checked")) {
window.location.reload();
} else {
// location.href = "<%= pageUrl %>../";
location.href = "<%= pageUrl %>../detail?id=" + fileId;
}
});
}, 300);
};
xhr.onerror = function (e) {
@@ -428,7 +457,7 @@
function getFileAssociatorList(fileSha1) {
var fileAssociator = document.getElementById("fileAssociator");
// 下拉框列表
postRequest("/file/list/MatchfileHash", { token: localStorageUtils.getToken(), fileSha1: fileSha1 })
postRequest("/file/list/MatchfileHashWithNullValue", { token: localStorageUtils.getToken(), fileSha1: fileSha1 })
.then(function (responseData) {
var axiosData = responseData.data;
var status = axiosData.status;
@@ -452,4 +481,25 @@
alert("无法连接到服务器,请检查网络连接!");
});
}
</script>
<script>
// 刷新文件对象上传状态
async function refreshFileObjectStatus(fileObjectId, callback) {
postRequest("/file/object/refreshFileObjectStatus", { token: localStorageUtils.getToken(), fileObjectId: fileObjectId })
.then(function (responseData) {
var axiosData = responseData.data;
var status = axiosData.status;
var data = axiosData.data;
if (status === "success") {
// console.log(data);
if (callback)
callback();
} else {
alert(`出错啦!${data.errMsg} (错误码: ${data.errCode}) `);
}
}).catch(function (error) {
console.log(error);
alert("无法连接到服务器,请检查网络连接!");
});
}
</script>

View File

@@ -52,11 +52,15 @@
searchbox.value = keyword;
if (keyword === "")
searchbox.focus();
search({
tableElementId: "result-table",
searchText: keyword,
categoryId: null
});
function doSearch(keyword) {
search({
tableElementId: "result-table",
searchText: keyword,
categoryId: null
});
}
doSearch(keyword);
</script>
</body>
</html>