feat:导出功能完成
This commit is contained in:
parent
91d69aab6a
commit
bfc7385fae
@ -71,15 +71,15 @@ public class BookmarkServiceImpl implements BookmarkService {
|
|||||||
int count = 0;
|
int count = 0;
|
||||||
List<Bookmark> bookmarks = new ArrayList<>();
|
List<Bookmark> bookmarks = new ArrayList<>();
|
||||||
for (int i = 0, length = elements.size(); i < length; i++) {
|
for (int i = 0, length = elements.size(); i < length; i++) {
|
||||||
if (i == 0) {
|
// if (i == 0) {
|
||||||
Elements firstChildren = elements.get(0).child(1).children();
|
// Elements firstChildren = elements.get(0).child(0).children();
|
||||||
count = firstChildren.size();
|
// count = firstChildren.size();
|
||||||
for (int j = 0; j < count; j++) {
|
// for (int j = 0; j < count; j++) {
|
||||||
dealBookmark(userId, firstChildren.get(j), path, sortBase + j, bookmarks);
|
// dealBookmark(userId, firstChildren.get(j), path, sortBase + j, bookmarks);
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
dealBookmark(userId, elements.get(i), path, sortBase + count + i - 1, bookmarks);
|
dealBookmark(userId, elements.get(i), path, sortBase+i , bookmarks);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
//每一千条处理插入一次
|
//每一千条处理插入一次
|
||||||
List<Bookmark> tempList = new ArrayList<>(1000);
|
List<Bookmark> tempList = new ArrayList<>(1000);
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
"clipboard": "^2.0.6",
|
"clipboard": "^2.0.6",
|
||||||
"core-js": "^3.6.5",
|
"core-js": "^3.6.5",
|
||||||
"localforage": "^1.7.4",
|
"localforage": "^1.7.4",
|
||||||
|
"moment": "^2.29.1",
|
||||||
"vue": "^2.6.11",
|
"vue": "^2.6.11",
|
||||||
"vue-router": "^3.2.0",
|
"vue-router": "^3.2.0",
|
||||||
"vuex": "^3.4.0"
|
"vuex": "^3.4.0"
|
||||||
|
17
bookmark_front/src/util/FileUtil.js
Normal file
17
bookmark_front/src/util/FileUtil.js
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
export function downloadFile(fileName, content) {
|
||||||
|
debugger;
|
||||||
|
// 定义触发事件的DOM
|
||||||
|
var aLink = document.createElement("a");
|
||||||
|
// 定义BLOB对象,生成文件内容
|
||||||
|
var blob = new Blob([content], { type: "text/html" });
|
||||||
|
// 定义事件对象
|
||||||
|
var evt = document.createEvent("MouseEvents");
|
||||||
|
// 初始化事件
|
||||||
|
evt.initMouseEvent("click", true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
|
||||||
|
// 定义下载文件名称
|
||||||
|
aLink.download = fileName;
|
||||||
|
// 根据上面定义的 BLOB 对象创建文件 dataURL
|
||||||
|
aLink.href = URL.createObjectURL(blob);
|
||||||
|
// 应用事件,触发下载
|
||||||
|
aLink.dispatchEvent(evt);
|
||||||
|
}
|
@ -4,30 +4,37 @@
|
|||||||
<search :showActions="true" @location="location" />
|
<search :showActions="true" @location="location" />
|
||||||
</div>
|
</div>
|
||||||
<div class="actions">
|
<div class="actions">
|
||||||
<span class="myBookmark">我的书签</span>
|
<div class="left">
|
||||||
<a-tooltip title="刷新书签缓存">
|
<span class="myBookmark">我的书签</span>
|
||||||
<a-button @click="refresh(true)" type="primary" shape="circle" icon="sync" />
|
<a-tooltip title="刷新书签缓存">
|
||||||
</a-tooltip>
|
<a-button @click="refresh(true)" type="primary" shape="circle" icon="sync" />
|
||||||
<a-tooltip title="多选">
|
</a-tooltip>
|
||||||
<a-button type="primary" shape="circle" icon="check" @click="switchMul" />
|
<a-tooltip title="多选">
|
||||||
</a-tooltip>
|
<a-button type="primary" shape="circle" icon="check" @click="switchMul" />
|
||||||
<a-tooltip v-if="
|
</a-tooltip>
|
||||||
|
<a-tooltip v-if="
|
||||||
(checkedKeys.length === 0 && (currentSelect == null || currentSelect.type === 1)) ||
|
(checkedKeys.length === 0 && (currentSelect == null || currentSelect.type === 1)) ||
|
||||||
(checkedKeys.length === 1 && checkedNodes[0].type === 1)
|
(checkedKeys.length === 1 && checkedNodes[0].type === 1)
|
||||||
" title="添加书签">
|
" title="添加书签">
|
||||||
<a-button type="primary" shape="circle" icon="plus" @click="addData" />
|
<a-button type="primary" shape="circle" icon="plus" @click="addData" />
|
||||||
</a-tooltip>
|
|
||||||
<a-tooltip v-if="currentSelect || checkedKeys.length === 1" title="编辑书签">
|
|
||||||
<a-button type="primary" shape="circle" icon="edit" @click="editData" />
|
|
||||||
</a-tooltip>
|
|
||||||
<a-tooltip v-if="moveShow" title="移动书签">
|
|
||||||
<a-button type="primary" shape="circle" icon="scissor" />
|
|
||||||
</a-tooltip>
|
|
||||||
<a-popconfirm v-if="checkedKeys.length > 0 || currentSelect" title="此操作同时也会删除子节点数据,确认?" ok-text="是" cancel-text="否" @confirm="deleteBookmarks">
|
|
||||||
<a-tooltip title="删除书签">
|
|
||||||
<a-button type="danger" shape="circle" icon="delete" />
|
|
||||||
</a-tooltip>
|
</a-tooltip>
|
||||||
</a-popconfirm>
|
<a-tooltip v-if="currentSelect || checkedKeys.length === 1" title="编辑书签">
|
||||||
|
<a-button type="primary" shape="circle" icon="edit" @click="editData" />
|
||||||
|
</a-tooltip>
|
||||||
|
<a-tooltip v-if="moveShow" title="移动书签">
|
||||||
|
<a-button type="primary" shape="circle" icon="scissor" />
|
||||||
|
</a-tooltip>
|
||||||
|
<a-popconfirm v-if="checkedKeys.length > 0 || currentSelect" title="此操作同时也会删除子节点数据,确认?" ok-text="是" cancel-text="否" @confirm="deleteBookmarks">
|
||||||
|
<a-tooltip title="删除书签">
|
||||||
|
<a-button type="danger" shape="circle" icon="delete" />
|
||||||
|
</a-tooltip>
|
||||||
|
</a-popconfirm>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<a-tooltip title="导出书签">
|
||||||
|
<a-button @click="exportBookmark" type="primary" shape="circle" icon="export" />
|
||||||
|
</a-tooltip>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<a-empty v-if="treeData.length == 0" description="无数据,点击上方 + 新增"></a-empty>
|
<a-empty v-if="treeData.length == 0" description="无数据,点击上方 + 新增"></a-empty>
|
||||||
<a-tree v-else :tree-data="treeData" :loaded-keys="loadedKeys" :selected-keys="currentSelect ? [currentSelect.bookmarkId] : []" :load-data="loadData" :checked-keys="checkedKeys" :replace-fields="replaceFields" :expandedKeys="expandedKeys" @select="select" @expand="expand" @check="check" blockNode :checkable="mulSelect" checkStrictly :draggable="!isPhone" @drop="onDrop">
|
<a-tree v-else :tree-data="treeData" :loaded-keys="loadedKeys" :selected-keys="currentSelect ? [currentSelect.bookmarkId] : []" :load-data="loadData" :checked-keys="checkedKeys" :replace-fields="replaceFields" :expandedKeys="expandedKeys" @select="select" @expand="expand" @check="check" blockNode :checkable="mulSelect" checkStrictly :draggable="!isPhone" @drop="onDrop">
|
||||||
@ -61,7 +68,9 @@ import AddBookmark from "../../../../components/main/things/AddBookmark.vue";
|
|||||||
import Search from "../../../../components/main/Search.vue";
|
import Search from "../../../../components/main/Search.vue";
|
||||||
import HttpUtil from "../../../../util/HttpUtil.js";
|
import HttpUtil from "../../../../util/HttpUtil.js";
|
||||||
import { mapState, mapActions } from "vuex";
|
import { mapState, mapActions } from "vuex";
|
||||||
|
import { downloadFile } from "../../../../util/FileUtil";
|
||||||
import ClipboardJS from "clipboard";
|
import ClipboardJS from "clipboard";
|
||||||
|
import moment from "moment";
|
||||||
export default {
|
export default {
|
||||||
name: "BookmarkManage",
|
name: "BookmarkManage",
|
||||||
components: { AddBookmark, Search },
|
components: { AddBookmark, Search },
|
||||||
@ -336,6 +345,52 @@ export default {
|
|||||||
this.editData();
|
this.editData();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* 书签文件导出
|
||||||
|
*/
|
||||||
|
exportBookmark() {
|
||||||
|
let map = this.totalTreeData;
|
||||||
|
let root = document.createElement("DL");
|
||||||
|
this.dealList(root, map[""], map);
|
||||||
|
let content =
|
||||||
|
`<!DOCTYPE NETSCAPE-Bookmark-file-1>
|
||||||
|
<!-- This is an automatically generated file.
|
||||||
|
It will be read and overwritten.
|
||||||
|
DO NOT EDIT! -->
|
||||||
|
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
|
||||||
|
<TITLE>Bookmarks</TITLE>
|
||||||
|
<H1>签签世界导出</H1>` + root.outerHTML;
|
||||||
|
downloadFile(moment().format("YYYY-MM-DD") + "导出书签.html", content);
|
||||||
|
},
|
||||||
|
dealList(root, list, totalMap) {
|
||||||
|
if (!list || list.length == undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
list.forEach((item) => {
|
||||||
|
let node = document.createElement("DT");
|
||||||
|
root.appendChild(node);
|
||||||
|
if (item.type === 0) {
|
||||||
|
//说明为书签
|
||||||
|
let url = document.createElement("A");
|
||||||
|
url.setAttribute("HREF", item.url);
|
||||||
|
url.setAttribute("ADD_DATE", parseInt(Date.now() / 1000));
|
||||||
|
url.innerText = item.name;
|
||||||
|
if (item.icon.length > 0) {
|
||||||
|
url.setAttribute("ICON", item.icon);
|
||||||
|
}
|
||||||
|
node.appendChild(url);
|
||||||
|
} else {
|
||||||
|
//说明为文件夹
|
||||||
|
let header = document.createElement("H3");
|
||||||
|
header.setAttribute("ADD_DATE", parseInt(Date.now() / 1000));
|
||||||
|
header.innerText = item.name;
|
||||||
|
node.appendChild(header);
|
||||||
|
let children = document.createElement("DL");
|
||||||
|
node.appendChild(children);
|
||||||
|
this.dealList(children, totalMap[item.path + "." + item.bookmarkId], totalMap);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
@ -347,6 +402,12 @@ export default {
|
|||||||
height: 0.42rem;
|
height: 0.42rem;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
|
||||||
|
.left {
|
||||||
|
display: flex;
|
||||||
|
justify-items: center;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.myBookmark {
|
.myBookmark {
|
||||||
font-size: 0.25rem;
|
font-size: 0.25rem;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user