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 },