From f968a4130358d38fd7fc4f09bdae8909d8f56d80 Mon Sep 17 00:00:00 2001 From: fanxb Date: Wed, 3 Mar 2021 14:13:59 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=90=9C=E7=B4=A2=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bookmark_front/src/components/main/Search.vue | 43 ++++++++++++++++++- .../components/main/things/AddBookmark.vue | 4 +- bookmark_front/src/global.less | 12 ++++++ bookmark_front/src/store/modules/treeData.js | 8 +++- .../main/pages/things/BookmarkManage.vue | 8 ++++ 5 files changed, 70 insertions(+), 5 deletions(-) diff --git a/bookmark_front/src/components/main/Search.vue b/bookmark_front/src/components/main/Search.vue index 54d3b4e..bfa9b28 100644 --- a/bookmark_front/src/components/main/Search.vue +++ b/bookmark_front/src/components/main/Search.vue @@ -11,11 +11,13 @@ allowClear @blur.prevent="inputBlur" @focus="inputFocus" + @keydown="keyPress" />
- + {{ item.name }} @@ -31,6 +39,7 @@
+ @@ -50,7 +59,10 @@ export default { list: [], //计时器结束列表的显示 timer: null, + //鼠标悬浮选中 hoverIndex: null, + //上下选中 + selectIndex: null, }; }, computed: { @@ -102,6 +114,26 @@ export default { location(item) { this.$emit("location", item); }, + //上下事件 + keyPress(e) { + switch (e.key) { + case "ArrowUp": + this.selectIndex = this.selectIndex == null ? this.list.length - 1 : this.selectIndex == 0 ? null : this.selectIndex - 1; + break; + case "ArrowDown": + this.selectIndex = this.selectIndex == null ? 0 : this.selectIndex == this.list.length - 1 ? null : this.selectIndex + 1; + break; + case "Enter": + if (this.selectIndex == null) { + this.targetUrl = "https://www.baidu.com/s?ie=UTF-8&wd=" + encodeURIComponent(this.value); + } else { + this.targetUrl = this.list[this.selectIndex].url; + } + let a = this.$refs["targetA"]; + a.href = this.targetUrl; + a.click(); + } + }, dealSearch(content) { let res = []; let arrs = Object.values(this.totalTreeData); @@ -137,7 +169,16 @@ export default { font-size: 0.16rem; display: flex; height: 0.3rem; + line-height: 0.3rem; align-items: center; + .listItemUrl { + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + } + } + .itemActive { + background-color: #f8f8f8; } } } diff --git a/bookmark_front/src/components/main/things/AddBookmark.vue b/bookmark_front/src/components/main/things/AddBookmark.vue index c1cb6c9..ab086f5 100644 --- a/bookmark_front/src/components/main/things/AddBookmark.vue +++ b/bookmark_front/src/components/main/things/AddBookmark.vue @@ -69,9 +69,9 @@ export default { created() { console.log(this.isAdd, this.targetNode); if (!this.isAdd) { - this.form.type = this.targetNode.type; + this.form.type = this.targetNode.type.toString(); this.form.name = this.targetNode.name; - this.form.url = this.form.type === "bookmark" ? this.targetNode.url : ""; + this.form.url = this.form.type === "0" ? this.targetNode.url : ""; } this.token = window.token; this.form.path = this.targetNode == null ? "" : this.targetNode.path + (this.isAdd ? "." + this.targetNode.bookmarkId : ""); diff --git a/bookmark_front/src/global.less b/bookmark_front/src/global.less index 96351a8..6f5138d 100644 --- a/bookmark_front/src/global.less +++ b/bookmark_front/src/global.less @@ -20,3 +20,15 @@ * content配置 */ @contentbgcolor: rgb(255, 255, 255); //公共背景色 + +.treeNodeItem { + span { + span { + display: inline-block; + width: 100%; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + } + } +} diff --git a/bookmark_front/src/store/modules/treeData.js b/bookmark_front/src/store/modules/treeData.js index 00e030f..0a50cbc 100644 --- a/bookmark_front/src/store/modules/treeData.js +++ b/bookmark_front/src/store/modules/treeData.js @@ -77,7 +77,12 @@ const actions = { if (!treeData[""]) { treeData[""] = []; } - treeData[""].forEach(item => (item.isLeaf = item.type === 0)); + Object.values(treeData).forEach(item => + item.forEach(item1 => { + item1.isLeaf = item.type === 0; + item1.class = "treeNodeItem"; + }) + ); context.commit(TOTAL_TREE_DATA, treeData); await localforage.setItem(TOTAL_TREE_DATA, treeData); let userInfo = await httpUtil.get("/user/currentUserInfo"); @@ -94,7 +99,6 @@ const actions = { await localforage.removeItem(VERSION); }, async moveNode(context, info) { - debugger; let data = context.state[TOTAL_TREE_DATA]; const target = info.node.dataRef; const current = info.dragNode.dataRef; diff --git a/bookmark_front/src/views/main/pages/things/BookmarkManage.vue b/bookmark_front/src/views/main/pages/things/BookmarkManage.vue index 1072975..0dcb8df 100644 --- a/bookmark_front/src/views/main/pages/things/BookmarkManage.vue +++ b/bookmark_front/src/views/main/pages/things/BookmarkManage.vue @@ -56,6 +56,7 @@ checkStrictly :draggable="!isPhone" @drop="onDrop" + @rightClick="rightClick" /> @@ -151,6 +152,13 @@ export default { this.expandedKeys.pop(); } }, + rightClick({ node }) { + if (this.currentSelect === node.dataRef) { + this.currentSelect = null; + } else { + this.currentSelect = node.dataRef; + } + }, check(key, { checked, node }) { let item = node.dataRef; if (checked) {