UnisKB/ui/src/components/common-list/index.vue

64 lines
1.4 KiB
Vue
Raw Normal View History

2023-11-15 09:42:31 +00:00
<template>
<div class="common-list">
<el-scrollbar>
<ul v-if="data.length > 0">
2023-11-27 10:08:58 +00:00
<li
v-if="slots.prefix"
@click="clickHandle()"
:class="modelValue === undefined || modelValue === null ? 'active' : ''"
class="cursor"
>
<slot name="prefix"> </slot>
</li>
2023-11-15 09:42:31 +00:00
<template v-for="(item, index) in data" :key="index">
<li
2023-11-27 10:08:58 +00:00
@click.prevent="clickHandle(item)"
:class="modelValue === item ? 'active' : ''"
2023-11-15 09:42:31 +00:00
class="cursor"
>
<slot :row="item" :index="index"> </slot>
</li>
</template>
</ul>
<el-empty description="暂无数据" v-else />
</el-scrollbar>
</div>
</template>
<script setup lang="ts">
2023-11-27 10:08:58 +00:00
import { ref, watch, useSlots } from 'vue'
const slots = useSlots()
2023-11-15 09:42:31 +00:00
defineOptions({ name: 'CommonList' })
2023-11-27 10:08:58 +00:00
withDefaults(
defineProps<{
modelValue?: any
data: Array<any>
}>(),
{
data: () => []
}
)
2023-11-15 09:42:31 +00:00
2023-11-27 10:08:58 +00:00
const emit = defineEmits(['click', 'update:modelValue'])
2023-11-15 09:42:31 +00:00
2023-11-27 10:08:58 +00:00
function clickHandle(row?: any) {
2023-11-15 09:42:31 +00:00
emit('click', row)
2023-11-27 10:08:58 +00:00
emit('update:modelValue', row)
2023-11-15 09:42:31 +00:00
}
</script>
<style lang="scss" scoped>
2023-11-22 03:05:06 +00:00
/* 通用 ui li样式 */
2023-11-15 09:42:31 +00:00
.common-list {
li {
padding: 11px 16px;
&.active {
background: var(--el-color-primary-light-9);
border-radius: 4px;
color: var(--el-color-primary);
}
}
}
</style>