|
@@ -2,9 +2,16 @@
|
|
|
<div>
|
|
<div>
|
|
|
<el-button @click="() => this.$refs.termRef.open()"size="small" type="primary">新增</el-button>
|
|
<el-button @click="() => this.$refs.termRef.open()"size="small" type="primary">新增</el-button>
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+ <div class="content_box" v-if="list.length > 0">
|
|
|
|
|
|
|
|
|
|
+ <div class="content_box_list" v-for="(item,index) in list" :key="index">
|
|
|
|
|
+ {{ item.id }}
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
<termPop ref="termRef"></termPop>
|
|
<termPop ref="termRef"></termPop>
|
|
|
</div>
|
|
</div>
|
|
|
</template>
|
|
</template>
|
|
@@ -15,16 +22,45 @@
|
|
|
export default {
|
|
export default {
|
|
|
components: { termPop },
|
|
components: { termPop },
|
|
|
data() {
|
|
data() {
|
|
|
- return {};
|
|
|
|
|
|
|
+ return {
|
|
|
|
|
+ list: []
|
|
|
|
|
+ };
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
created() {
|
|
created() {
|
|
|
|
|
|
|
|
EventBus.$on('inspectionSelection', (data) => {
|
|
EventBus.$on('inspectionSelection', (data) => {
|
|
|
console.log(data.message);
|
|
console.log(data.message);
|
|
|
|
|
+
|
|
|
|
|
+ let _arr = this.updateOrCreateObjectInArray(this.list, data.message);
|
|
|
|
|
+ this.list = JSON.parse(JSON.stringify(_arr));
|
|
|
|
|
+ this.$forceUpdate();
|
|
|
});
|
|
});
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ methods: {
|
|
|
|
|
+
|
|
|
|
|
+ updateOrCreateObjectInArray(array, newObj, idKey = 'id') {
|
|
|
|
|
+ // 用来检查是否已存在具有特定 id 的对象
|
|
|
|
|
+ const exists = array.some(obj => obj[idKey] === newObj[idKey]);
|
|
|
|
|
+
|
|
|
|
|
+ if (exists) {
|
|
|
|
|
+ // 如果存在,使用 map 来替换找到的对象
|
|
|
|
|
+ return array.map(obj => obj[idKey] === newObj[idKey] ? newObj : obj);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 如果不存在,将新对象添加到数组中
|
|
|
|
|
+ return [...array, newObj];
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|
|
|
-<style lang="scss" scoped></style>
|
|
|
|
|
|
|
+<style lang="scss" scoped>
|
|
|
|
|
+.content_box{
|
|
|
|
|
+ width: 100%;
|
|
|
|
|
+ margin-top: 12px;
|
|
|
|
|
+}
|
|
|
|
|
+</style>
|