This commit is contained in:
fanxb 2022-03-28 17:01:45 +08:00
parent 62d3c43436
commit ee22c4b77a
6 changed files with 62 additions and 54 deletions

View File

@ -19,22 +19,20 @@
<div v-if="focused && list.length > 0" class="searchContent"> <div v-if="focused && list.length > 0" class="searchContent">
<div <div
class="listItem" class="listItem"
:class="{ itemActive: index == hoverIndex || index == selectIndex }" :class="{ itemActive: index == selectIndex }"
v-for="(item, index) in list" v-for="(item, index) in list"
:key="item.bookmarkId" :key="item.bookmarkId"
@mousedown="itemClick(index)" @mousedown="itemClick(index)"
@mouseenter="mouseEnterOut(index, 'enter')"
@mouseleave="mouseEnterOut(index, 'leave')"
:id="'bookmark:' + item.bookmarkId" :id="'bookmark:' + item.bookmarkId"
> >
<div class="name" style="" target="_blank"> <div class="name" target="_blank" :title="item.url.substr(0, 50)">
{{ item.name }} {{ item.name }}
</div> </div>
<div class="icons" v-if="hoverIndex === index"> <div class="icons">
<a-tooltip title="定位到书签树中" v-if="showLocation"> <a-tooltip title="定位到书签树中" v-if="showLocation">
<my-icon style="color: white; font-size: 1.3em" type="icon-et-location" @mousedown="location($event, item)" /> <my-icon style="color: white; font-size: 1.3em" type="icon-et-location" @mousedown="location($event, item)" />
</a-tooltip> </a-tooltip>
<a-tooltip :title="'复制链接:' + item.url"> <a-tooltip title="复制链接">
<a-icon <a-icon
type="copy" type="copy"
style="color: white; font-size: 1.3em; padding-left: 0.5em" style="color: white; font-size: 1.3em; padding-left: 0.5em"
@ -65,8 +63,6 @@ export default {
value: "", value: "",
focused: false, focused: false,
list: [], list: [],
//
hoverIndex: null,
// //
selectIndex: null, selectIndex: null,
copyBoard: null, // copyBoard: null, //
@ -129,7 +125,7 @@ export default {
submit(forceSearch) { submit(forceSearch) {
let url; let url;
if (forceSearch || this.selectIndex == null) { if (forceSearch || this.selectIndex == null) {
//使 //使
url = this.searchUrl + encodeURIComponent(this.value); url = this.searchUrl + encodeURIComponent(this.value);
} else { } else {
// //
@ -142,21 +138,11 @@ export default {
a.click(); a.click();
}, },
inputBlur() { inputBlur() {
console.log("blur");
this.focused = false; this.focused = false;
}, },
inputFocus() { inputFocus() {
console.log("focus");
this.focused = true; this.focused = true;
}, },
mouseEnterOut(item, type) {
console.log(item, type);
if (type === "enter") {
this.hoverIndex = item;
} else {
this.hoverIndex = null;
}
},
// //
location(event, item) { location(event, item) {
this.$emit("location", item); this.$emit("location", item);
@ -299,13 +285,19 @@ export default {
white-space: nowrap; white-space: nowrap;
} }
.icons { .icons {
display: flex; display: none;
align-items: center; align-items: center;
} }
} }
.listItem:hover {
background-color: @listActiveBgColor;
}
.itemActive { .itemActive {
background-color: @listActiveBgColor; background-color: @listActiveBgColor;
} }
.listItem:hover .icons {
display: flex;
}
} }
} }
</style> </style>

View File

@ -1,14 +1,14 @@
<template> <template>
<div> <div>
<a-form-model ref="addForm" :model="form" :rules="rules" :label-col="labelCol" :wrapper-col="wrapperCol"> <a-form-model ref="addForm" :model="form" :rules="rules" :label-col="labelCol" :wrapper-col="wrapperCol">
<a-form-model-item v-if="isAdd" prop="type" label="类别"> <a-form-model-item v-if="isAdd && !addType" prop="type" label="类别">
<a-radio-group v-model="form.type" :options="options" /> <a-radio-group v-model="form.type" :options="options" />
</a-form-model-item> </a-form-model-item>
<template v-if="form.type !== 'file'"> <template v-if="form.type !== 'file'">
<a-form-model-item prop="name" label="名称" :required="false"> <a-form-model-item prop="name" label="名称" :required="false">
<a-input v-model="form.name" placeholder="名称" /> <a-input v-model="form.name" placeholder="名称" />
</a-form-model-item> </a-form-model-item>
<a-form-model-item v-if="form.type === '0'" prop="url" label="URL"> <a-form-model-item v-if="form.type === 'bookmark'" prop="url" label="URL">
<a-input v-model="form.url" placeholder="url" /> <a-input v-model="form.url" placeholder="url" />
</a-form-model-item> </a-form-model-item>
<div class="btns"> <div class="btns">
@ -16,7 +16,13 @@
</div> </div>
</template> </template>
<div v-else prop="file"> <div v-else prop="file">
<a-upload-dragger name="file" :data="{ path: form.path }" :headers="{ 'jwt-token': token }" action="/bookmark/api/bookmark/uploadBookmarkFile" @change="fileChange"> <a-upload-dragger
name="file"
:data="{ path: form.path }"
:headers="{ 'jwt-token': token }"
action="/bookmark/api/bookmark/uploadBookmarkFile"
@change="fileChange"
>
<p class="ant-upload-drag-icon"> <p class="ant-upload-drag-icon">
<a-icon type="inbox" /> <a-icon type="inbox" />
</p> </p>
@ -30,14 +36,15 @@
<script> <script>
import HttpUtil from "@/util/HttpUtil"; import HttpUtil from "@/util/HttpUtil";
const options = [ const options = [
{ label: "书签", value: "0" }, { label: "书签", value: "bookmark" },
{ label: "文件夹", value: "1" }, { label: "文件夹", value: "folder" },
{ label: "导入", value: "file" }, { label: "导入", value: "file" },
]; ];
export default { export default {
name: "addBookmark", name: "addBookmark",
props: { props: {
isAdd: Boolean, isAdd: Boolean, //
addType: String, //
targetNode: Object, targetNode: Object,
}, },
data() { data() {
@ -48,7 +55,7 @@ export default {
token: "", token: "",
loading: false, loading: false,
form: { form: {
type: "0", //0:,1:,file: type: "bookmark",
name: "", name: "",
url: "", url: "",
path: "", path: "",
@ -63,9 +70,9 @@ export default {
created() { created() {
console.log(this.isAdd, this.targetNode); console.log(this.isAdd, this.targetNode);
if (!this.isAdd) { if (!this.isAdd) {
this.form.type = this.targetNode.type.toString(); this.form.type = this.targetNode.type == 0 ? "bookmark" : "folder";
this.form.name = this.targetNode.name; this.form.name = this.targetNode.name;
this.form.url = this.form.type === "0" ? this.targetNode.url : ""; this.form.url = this.form.type === "bookmark" ? this.targetNode.url : "";
} }
this.token = this.$store.state.globalConfig.token; this.token = this.$store.state.globalConfig.token;
this.form.path = this.targetNode == null ? "" : this.targetNode.path + (this.isAdd ? "." + this.targetNode.bookmarkId : ""); this.form.path = this.targetNode == null ? "" : this.targetNode.path + (this.isAdd ? "." + this.targetNode.bookmarkId : "");
@ -74,25 +81,27 @@ export default {
/** /**
* 文件提交不走这儿 * 文件提交不走这儿
*/ */
submit() { async submit() {
// //
this.loading = true; this.loading = true;
this.$refs["addForm"].validateField(this.form.type === 0 ? ["name", "url"] : "name", async (message) => { this.$refs["addForm"].validate(async (pass) => {
if (message.length > 0) { if (!pass) {
this.loading = false; this.loading = false;
return; return;
} }
let res = null; let res = null;
let body = JSON.parse(JSON.stringify(this.form));
body.type = body.type === "bookmark" ? 0 : 1;
if (this.isAdd) { if (this.isAdd) {
res = await HttpUtil.put("/bookmark", null, this.form); res = await HttpUtil.put("/bookmark", null, body);
await this.$store.dispatch("treeData/addNode", { sourceNode: this.targetNode, targetNode: res }); await this.$store.dispatch("treeData/addNode", { sourceNode: this.targetNode, targetNode: res });
} else { } else {
this.form.bookmarkId = this.targetNode.bookmarkId; body.bookmarkId = this.targetNode.bookmarkId;
let newIcon = await HttpUtil.post("/bookmark/updateOne", null, this.form); let newIcon = await HttpUtil.post("/bookmark/updateOne", null, body);
await this.$store.dispatch("treeData/editNode", { node: this.targetNode, newName: this.form.name, newUrl: this.form.url, newIcon }); await this.$store.dispatch("treeData/editNode", { node: this.targetNode, newName: this.form.name, newUrl: this.form.url, newIcon });
} }
this.$message.success("操作成功"); this.$message.success("操作成功");
this.$emit("close", false); this.$emit("close", this.form.type);
this.loading = false; this.loading = false;
}); });
}, },
@ -106,7 +115,7 @@ export default {
}); });
} else { } else {
this.$message.success("解析成功"); this.$message.success("解析成功");
this.$emit("close", true); this.$emit("close", this.form.type);
} }
} }
}, },

View File

@ -18,7 +18,8 @@ import {
Upload, Upload,
Popconfirm, Popconfirm,
AutoComplete, AutoComplete,
Select Select,
Popover
} from "ant-design-vue"; } from "ant-design-vue";
import App from "./App.vue"; import App from "./App.vue";
import router from "./router"; import router from "./router";
@ -44,6 +45,7 @@ Vue.use(Upload);
Vue.use(Popconfirm); Vue.use(Popconfirm);
Vue.use(AutoComplete); Vue.use(AutoComplete);
Vue.use(Select); Vue.use(Select);
Vue.use(Popover);
Vue.component("my-icon", IconFont); Vue.component("my-icon", IconFont);
Vue.prototype.$message = message; Vue.prototype.$message = message;

View File

@ -20,6 +20,10 @@ export const noLoginInit = "noLoginInit";
export const loginInit = "loginInit"; export const loginInit = "loginInit";
export const refresh = "refresh"; export const refresh = "refresh";
export const clear = "clear"; export const clear = "clear";
/**
* 删除书签数据
*/
export const deleteData = "deleteData";
/** /**
* 版本检查定时调度 * 版本检查定时调度
@ -240,7 +244,7 @@ const actions = {
/** /**
* 删除节点数据 * 删除节点数据
*/ */
async deleteData (context, { pathList, bookmarkIdList }) { async [deleteData] (context, { pathList, bookmarkIdList }) {
//待删除的书签 //待删除的书签
let bookmarkIdSet = new Set(); let bookmarkIdSet = new Set();
bookmarkIdList.forEach(item => bookmarkIdSet.add(item)); bookmarkIdList.forEach(item => bookmarkIdSet.add(item));

View File

@ -2,13 +2,11 @@
<div> <div>
<a href="pinObj.url" v-if="pinObj" class="pinBookmarkItem"> <a href="pinObj.url" v-if="pinObj" class="pinBookmarkItem">
<img :src="pinObj.icon.length > 0 ? pinObj.icon : '/favicon.ico'" class="icon" /> <img :src="pinObj.icon.length > 0 ? pinObj.icon : '/favicon.ico'" class="icon" />
<span class="text">{{ pinObj.name }}</span> <span class="text" :title="pinObj.name">{{ pinObj.name }}</span>
<span class="action actionShow">...</span> <span class="action actionShow">...</span>
</a> </a>
<div v-else class="pinBookmarkItem" @click="add"> <div v-else class="pinBookmarkItem" @click="showAddBlock = !showAddBlock" title="新增书签并固定到首页">
<a-tooltip title="新增"> <a-icon style="font-size: 1.5em" type="plus" />
<a-icon style="font-size: 1.5em" type="plus" />
</a-tooltip>
</div> </div>
</div> </div>
</template> </template>
@ -20,7 +18,12 @@ export default {
pinObj: Object, pinObj: Object,
}, },
data() { data() {
return {}; return {
showAddBlock: false,
};
},
methods: {
add() {},
}, },
}; };
</script> </script>

View File

@ -99,7 +99,7 @@ import { mapState } from "vuex";
import { downloadFile } from "@/util/FileUtil"; import { downloadFile } from "@/util/FileUtil";
import ClipboardJS from "clipboard"; import ClipboardJS from "clipboard";
import moment from "moment"; import moment from "moment";
import { TREE_DATA, SHOW_REFRESH_TOAST, refreshHomePinList, HOME_PIN_LIST } from "@/store/modules/treeData"; import { TREE_DATA, SHOW_REFRESH_TOAST, refreshHomePinList, deleteData, HOME_PIN_LIST } from "@/store/modules/treeData";
import { dealList, exportFileHead } from "@/views/manage/bookmarkTree/helper"; import { dealList, exportFileHead } from "@/views/manage/bookmarkTree/helper";
import { GLOBAL_CONFIG } from "@/store/modules/globalConfig"; import { GLOBAL_CONFIG } from "@/store/modules/globalConfig";
export default { export default {
@ -167,6 +167,7 @@ export default {
* 加载数据兼容treeNode为id * 加载数据兼容treeNode为id
*/ */
loadData(treeNode) { loadData(treeNode) {
console.log("加载数据", treeNode);
return new Promise((resolve) => { return new Promise((resolve) => {
const data = typeof treeNode === "number" ? this.$store.getters["treeData/getById"](treeNode) : treeNode.dataRef; const data = typeof treeNode === "number" ? this.$store.getters["treeData/getById"](treeNode) : treeNode.dataRef;
let newPath = data.path + "." + data.bookmarkId; let newPath = data.path + "." + data.bookmarkId;
@ -193,6 +194,7 @@ export default {
* 重置当前data中书签相关数据 * 重置当前data中书签相关数据
*/ */
resetData() { resetData() {
console.log("重置数据");
this.treeData = this.totalTreeData[""]; this.treeData = this.totalTreeData[""];
this.expandedKeys = []; this.expandedKeys = [];
this.checkedKeys = []; this.checkedKeys = [];
@ -284,13 +286,9 @@ export default {
this.$message.warn("请选择后再进行操作"); this.$message.warn("请选择后再进行操作");
return; return;
} }
this.loading = true; this.loading = true;
await HttpUtil.post("/bookmark/batchDelete", null, { await HttpUtil.post("/bookmark/batchDelete", null, { pathList, bookmarkIdList });
pathList, this.$store.dispatch(TREE_DATA + "/" + deleteData, { pathList, bookmarkIdList });
bookmarkIdList,
});
this.$store.dispatch("treeData/deleteData", { pathList, bookmarkIdList });
// //
pathList.forEach((item) => { pathList.forEach((item) => {
const id = parseInt(item.split(".").reverse()[0]); const id = parseInt(item.split(".").reverse()[0]);
@ -337,8 +335,8 @@ export default {
* 关闭弹窗 * 关闭弹窗
* @param isUpload 说明为上传书签文件需要刷新缓存数据 * @param isUpload 说明为上传书签文件需要刷新缓存数据
*/ */
async close(isUpload) { async close(type) {
if (isUpload) { if (type === "file") {
this.refresh(true); this.refresh(true);
} else { } else {
this.treeData.__ob__.dep.notify(); this.treeData.__ob__.dep.notify();