| | |
| | | <template> |
| | | <div> |
| | | <div class="search"> |
| | | <el-input placeholder="搜索" v-model="keyWord"> |
| | | <i slot="suffix" class="el-input__icon el-icon-search" id="key"></i> |
| | | <el-input placeholder="搜索" v-model="keyWord" size="mini" v-show="search"> |
| | | <i slot="suffix" class="el-input__icon el-icon-search" :id="searchBtnId"></i> |
| | | </el-input> |
| | | </div> |
| | | <div class="ztree" :id="ztreeId"></div> |
| | |
| | | showCheckbox: { type: Boolean, default: false }, |
| | | readonly: { type: Boolean, default: true }, |
| | | gb28181: { type: Boolean, default: false }, |
| | | search: { type: Boolean, default: false }, |
| | | setting: { |
| | | type: Object, |
| | | require: false, |
| | |
| | | data() { |
| | | return { |
| | | ztreeId: "ztree_" + parseInt(Math.random() * 1e10), |
| | | searchBtnId: "search_" + parseInt(Math.random() * 1e10), |
| | | ztreeObj: null, |
| | | list: [], |
| | | loading: false, |
| | | ztreeSetting: { |
| | | view: { |
| | | showLine: true, |
| | |
| | | Object.assign({}, this.ztreeSetting, this.setting), |
| | | this.list |
| | | ) |
| | | this.fuzzySearch(this.ztreeObj, "#key", null, true) //初始化模糊搜索方法 |
| | | this.fuzzySearch(this.ztreeObj, this.searchBtnId, false, true) //初始化模糊搜索方法 |
| | | this.$emit("onCreated", this.ztreeObj) |
| | | }) |
| | | }, |
| | |
| | | |
| | | var nodesShow = zTreeObj.getNodesByFilter(filterFunc) //get all nodes that would be shown |
| | | processShowNodes(nodesShow, _keywords) //nodes should be reprocessed to show correctly |
| | | _this.$emit("onAfterSearch", null) |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | //listen to change in input element |
| | | $(searchField).bind("click", function() { |
| | | _this.options.target = document.querySelector("#" + _this.ztreeId).parentNode.parentNode |
| | | $("#" + searchField).bind("click", function() { |
| | | // _this.options.target = document.querySelector("#" + _this.ztreeId).parentNode.parentNode |
| | | // console.log(_this.options.target); |
| | | let loadingInstance = Loading.service(_this.options) |
| | | // let loadingInstance = Loading.service(_this.options) |
| | | // console.log(_this.keyWord); |
| | | // var _keywords = $(this).val(); |
| | | $("#" + searchField).removeClass("el-icon-search") |
| | | $("#" + searchField).addClass("el-icon-loading") |
| | | searchNodeLazy(_this.keyWord) //call lazy load |
| | | loadingInstance.close() |
| | | // loadingInstance.close() |
| | | setTimeout(() => { |
| | | $("#" + searchField).removeClass("el-icon-loading") |
| | | $("#" + searchField).addClass("el-icon-search") |
| | | }, 300) |
| | | }) |
| | | |
| | | var timeoutId = null |
| | | var lastKeyword = "" |
| | | // excute lazy load once after input change, the last pending task will be cancled |
| | | function searchNodeLazy(_keywords) { |
| | | if (timeoutId) { |
| | | //clear pending task |
| | | clearTimeout(timeoutId) |
| | | if (lastKeyword === _keywords) { |
| | | return |
| | | } |
| | | timeoutId = setTimeout(function() { |
| | | if (lastKeyword === _keywords) { |
| | | return |
| | | } |
| | | ztreeFilter(zTreeObj, _keywords) //lazy load ztreeFilter function |
| | | // $(searchField).focus();//focus input field again after filtering |
| | | lastKeyword = _keywords |
| | | }, 500) |
| | | ztreeFilter(zTreeObj, _keywords) //lazy load ztreeFilter function |
| | | // $(searchField).focus();//focus input field again after filtering |
| | | lastKeyword = _keywords |
| | | } |
| | | }, |
| | | handleSearch() { |
| | | this.loading = true |
| | | searchNodeLazy(this.keyWord) //call lazy load |
| | | this.loading = false |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | <style scoped lang="scss"> |
| | | .search { |
| | | width: 300px; |
| | | width: 280px; |
| | | margin: 5px 5px; |
| | | |
| | | ::v-deep .el-input__suffix { |
| | | right: 0; |