2023-06-29 17:43:15 +08:00
|
|
|
<template>
|
|
|
|
<a-menu class="spectra-list-in-menu">
|
2023-08-01 09:46:02 +08:00
|
|
|
<a-menu-item class="spectra-list-in-menu-item" v-for="item in list" :key="item.sampleId" @click="handleClick(item)">
|
2023-06-29 17:43:15 +08:00
|
|
|
<span class="checkbox">
|
|
|
|
<a-icon v-if="item.checked" type="check" style="color: #0de30d" />
|
|
|
|
</span>
|
2023-07-11 19:35:18 +08:00
|
|
|
<span class="name">{{ getFileName(item.inputFileName) }}</span>
|
2023-06-29 17:43:15 +08:00
|
|
|
<a-icon type="delete" @click.stop="handleRemove(item)" />
|
|
|
|
</a-menu-item>
|
|
|
|
</a-menu>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
list: {
|
|
|
|
type: Array,
|
|
|
|
default: () => []
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
handleClick(spectraItem) {
|
|
|
|
this.list.forEach(item => (item.checked = false))
|
|
|
|
spectraItem && (spectraItem.checked = true)
|
|
|
|
this.$emit('change', spectraItem)
|
|
|
|
this.$forceUpdate()
|
|
|
|
},
|
|
|
|
|
|
|
|
handleRemove(spectraItem) {
|
|
|
|
const index = this.list.findIndex(item => item == spectraItem)
|
|
|
|
this.list.splice(index, 1)
|
|
|
|
// 如果删除了一个选中的
|
|
|
|
if (spectraItem.checked) {
|
|
|
|
if (index == 0) {
|
|
|
|
// 如果是第一个,则选中下一个
|
|
|
|
this.handleClick(this.list[0])
|
|
|
|
} else {
|
|
|
|
// 如果不是第一个,则选中上一个
|
|
|
|
this.handleClick(this.list[index - 1])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.$forceUpdate()
|
2023-07-11 19:35:18 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取文件名
|
|
|
|
* @param {String} inputFileName
|
|
|
|
*/
|
|
|
|
getFileName(inputFileName) {
|
|
|
|
if (inputFileName) {
|
|
|
|
const arr = inputFileName.split('/')
|
|
|
|
return arr[arr.length - 1]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
list(newVal) {
|
|
|
|
if (newVal.length) {
|
|
|
|
this.handleClick(newVal[0])
|
|
|
|
}
|
2023-06-29 17:43:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="less" scoped>
|
|
|
|
.spectra-list-in-menu {
|
2023-08-01 09:46:02 +08:00
|
|
|
&-item {
|
|
|
|
display: flex !important;
|
|
|
|
align-items: center;
|
|
|
|
}
|
|
|
|
|
2023-06-29 17:43:15 +08:00
|
|
|
.checkbox {
|
|
|
|
width: 14px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.name {
|
2023-08-01 09:46:02 +08:00
|
|
|
flex: 1;
|
2023-06-29 17:43:15 +08:00
|
|
|
margin: 0 5px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|