From 3a29fba5993298399eb602d770f87dbbfbe2b419 Mon Sep 17 00:00:00 2001 From: toesbieya <1647775459@qq.com> Date: Wed, 25 Nov 2020 19:10:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=BA=9B=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vue/src/layout/component/Page/index.vue | 1 + vue/src/mixin/tablePageMixin.js | 13 ++++++++++-- vue/src/util/vue.js | 23 ++++++++++++++++++++++ vue/src/view/system/customer/indexPage.vue | 1 + vue/src/view/system/supplier/indexPage.vue | 1 + 5 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 vue/src/util/vue.js diff --git a/vue/src/layout/component/Page/index.vue b/vue/src/layout/component/Page/index.vue index b955120..c6d3f1e 100644 --- a/vue/src/layout/component/Page/index.vue +++ b/vue/src/layout/component/Page/index.vue @@ -67,6 +67,7 @@ export default { display: flex; flex-direction: column; flex: 1; + position: relative; overflow: hidden; background-color: #f0f2f5; diff --git a/vue/src/mixin/tablePageMixin.js b/vue/src/mixin/tablePageMixin.js index 3a09738..89e969e 100644 --- a/vue/src/mixin/tablePageMixin.js +++ b/vue/src/mixin/tablePageMixin.js @@ -4,6 +4,7 @@ * */ import AbstractPagination from '@/component/abstract/Pagination' import AbstractTable from '@/component/abstract/Table' +import {findComponentByTag} from "@/util/vue" const mixin = { components: {AbstractPagination, AbstractTable}, @@ -33,7 +34,7 @@ const mixin = { watch: { row(v) { - !v && this.$refs.table && this.$refs.table.setCurrentRow() + !v && this.$_getElTableInstance().setCurrentRow() }, tablePageNeedSearchMap: { @@ -47,9 +48,17 @@ const mixin = { }, methods: { + $_getElTableInstance() { + if (!this.$_elTableInstance) { + this.$_elTableInstance = findComponentByTag(this, 'el-table') + } + + return this.$_elTableInstance + }, + rowClick(row) { if (this.row === row) { - this.$refs.table.setCurrentRow() + this.$_getElTableInstance().setCurrentRow() this.row = null } else this.row = row diff --git a/vue/src/util/vue.js b/vue/src/util/vue.js new file mode 100644 index 0000000..bcb6d1b --- /dev/null +++ b/vue/src/util/vue.js @@ -0,0 +1,23 @@ +/** + * 根据组件标签名称获取组件实例 + * 使用广度优先搜索 + * + * @param instance 从哪个组件实例开始查找,一般是this + * @param tag 要查找的组件的标签名称 + */ +export function findComponentByTag(instance, tag) { + if (!instance || !tag) return + + const queue = [instance] + + while (queue.length > 0) { + const item = queue.shift() + const {$options, $children} = item + + if ($options._componentTag === tag) return item + + if (Array.isArray($children)) { + queue.push(...$children) + } + } +} diff --git a/vue/src/view/system/customer/indexPage.vue b/vue/src/view/system/customer/indexPage.vue index 38aa210..19e54f9 100644 --- a/vue/src/view/system/customer/indexPage.vue +++ b/vue/src/view/system/customer/indexPage.vue @@ -164,6 +164,7 @@ export default { }, add() { + this.row = null this.type = 'add' this.editDialog = true }, diff --git a/vue/src/view/system/supplier/indexPage.vue b/vue/src/view/system/supplier/indexPage.vue index 290bee2..4623230 100644 --- a/vue/src/view/system/supplier/indexPage.vue +++ b/vue/src/view/system/supplier/indexPage.vue @@ -164,6 +164,7 @@ export default { }, add() { + this.row = null this.type = 'add' this.editDialog = true },