From f7374bee3ed1f95a447ca9017e003838c147b250 Mon Sep 17 00:00:00 2001 From: liyang <1711467488@qq.com> Date: Tue, 28 Aug 2018 17:34:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: 74e5de6c31b689f7d3da5a649a91113d583ecc58 [formerly 74e5de6c31b689f7d3da5a649a91113d583ecc58 [formerly 74e5de6c31b689f7d3da5a649a91113d583ecc58 [formerly 74e5de6c31b689f7d3da5a649a91113d583ecc58 [formerly 4d2a16382139b1c2e0e4e28740ddba6ba3c63a2e [formerly 17859adf57bf5b8cc6149612d3e9a57f1cf59401]]]]] Former-commit-id: f49ae444b2b3cff3ba3b531a4d07a8ecc150a655 Former-commit-id: a3f99935f53d76df1b031a82a4b325c16ca0c893 Former-commit-id: bced9b902cbbe8273d6b41ff3887094cf73892b0 [formerly 6fb4f87d3611434f990e7fce053d787ac75dbddd] Former-commit-id: 249b528c4bd3e852b6e7fcd9536b140fe24501d1 Former-commit-id: 40cadc71cb7c238d0e405587bb39d40ad0c45e88 Former-commit-id: 141981b6e688078dcc13d8f148a7ee62e9d3139d Former-commit-id: 018aca6a468a4a29d93ca5411be21dbcc8eaa094 Former-commit-id: deb3e7fac201bd70da7ba3f04701c111daac208a --- .../components/panel-search/index.vue | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/layout/header-aside/components/panel-search/index.vue b/src/layout/header-aside/components/panel-search/index.vue index 25016796..2e51a0a2 100644 --- a/src/layout/header-aside/components/panel-search/index.vue +++ b/src/layout/header-aside/components/panel-search/index.vue @@ -67,9 +67,22 @@ export default { ]) }, methods: { + /** + * @description 过滤选项 这个方法在每次输入框的值发生变化时会触发 + */ querySearch (queryString, callback) { var pool = this.pool - const results = (queryString ? pool : []).filter(item => { + const results = this.query(queryString ? pool : [], queryString) + this.results = results + callback(results) + }, + /** + * @description 指定的数据源中根据指定的查询字符串过滤数据 + * @param {Object} pool 需要过滤的数据 + * @param {String} queryString 查询字符串 + */ + query (pool, queryString) { + return pool.filter(item => { const path = item.path || '' const fullTitle = item.fullTitle || '' return (`${fullTitle}${path}`.toLowerCase().indexOf(queryString.toLowerCase()) >= 0) @@ -77,16 +90,19 @@ export default { value: e.fullTitle, ...e })) - this.results = results - callback(results) }, + /** + * @description 聚焦输入框 + */ focus () { this.input = '' setTimeout(() => { this.$refs.input.focus() }, 500) }, - // 接收用户在列表中选择项目的事件 + /** + * @description 接收用户在列表中选择项目的事件 + */ handleResultsGroupItemClick (path) { // 如果用户选择的就是当前页面 就直接关闭搜索面板 if (path === this.$route.path) { @@ -96,7 +112,9 @@ export default { // 用户选择的是其它页面 this.handleMenuSelect(path) }, - // 接收用户在下拉菜单中选中事件 + /** + * @description 接收用户在下拉菜单中选中事件 + */ handleSelect ({ path }) { // 如果用户选择的就是当前页面 就直接关闭搜索面板 if (path === this.$route.path) { @@ -108,12 +126,18 @@ export default { this.handleMenuSelect(path) }) }, + /** + * @augments 关闭输入框的下拉菜单 + */ closeSuggestion () { if (this.$refs.input.activated) { this.$refs.input.suggestions = [] this.$refs.input.activated = false } }, + /** + * @augments 接收用户触发的关闭 + */ handleEsc () { this.closeSuggestion() this.$nextTick(() => {