index.vue
2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<script lang="ts" setup name="List">
import { ref, computed } from "vue";
const props = defineProps({
listInfo: {
type: Object,
default: {},
},
});
const emits = defineEmits(["itemClick"]);
const selectIndex = ref(0)
const listTitle = computed(() => {
return props.listInfo.title ?? '';
});
const listData = computed(() => {
if (props.listInfo.selectedItem) {
nextTick(() => {
setSelectList(props.listInfo.selectedItem.value, props.listInfo.selectedItem.field, false)
})
}
return props.listInfo.data ?? '';
});
const field = computed(() => {
return props.listInfo.field ?? 'label'
})
const setSelectList = (v, fieldName: any = null, isClick: any = true) => {
let index = listData.value.findIndex(d => d[fieldName || field.value] === v);
if (index > -1) {
selectIndex.value = index;
isClick && emits('itemClick', listData.value[index]);
}
}
defineExpose({
selectIndex,
listData,
setSelectList
});
const listItemClick = (row, i) => {
selectIndex.value = i;
emits('itemClick', row)
}
</script>
<template>
<div class="list_panel_wrap">
<div class="list_title" v-if="listTitle">{{ listTitle }}</div>
<div class="list_panel" v-loading="listInfo.loading" :class="{ full: !listTitle }">
<div class="list_item" :class="{ active: index == selectIndex }" v-for="(item, index) in listData"
@click="listItemClick(item, index)">
<ellipsis-tooltip :content="listInfo.getName ? listInfo.getName(item) : item[field]" class-name="w100f" :refName="'tooltipOver' + item.guid"></ellipsis-tooltip>
</div>
</div>
</div>
</template>
<style lang="scss" scoped>
.list_panel_wrap {
min-height: 100px;
// height: 100%;
// overflow: hidden;
.list_title {
line-height: 32px;
font-size: 12px;
color: #666;
font-weight: 400;
padding: 0 8px;
}
.list_panel {
height: calc(100% - 40px);
margin-bottom: 8px;
overflow: hidden auto;
&.full {
height: calc(100% - 8px);
}
.list_item {
font-size: 14px;
color: #666;
font-weight: 400;
line-height: 32px;
padding: 0 8px;
cursor: default;
&:hover {
background: #f5f5f5;
}
&.active {
background: #EBF6F7;
color: var(--el-color-regular);
}
}
}
}
</style>