index.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <template>
  2. <ul class="list">
  3. <li class="header">
  4. <h3>数据列表</h3>
  5. <div class="action" v-if="$slots.action">
  6. <slot name="action"></slot>
  7. </div>
  8. </li>
  9. <ul class="content">
  10. <li
  11. v-for="(item, i) in data"
  12. :key="key ? item[key] : i"
  13. :class="{select: item.select}"
  14. @click="$emit('changeSelect', item)"
  15. >
  16. <div class="atom-content">
  17. <slot name="atom" :item="item"></slot>
  18. </div>
  19. </li>
  20. </ul>
  21. </ul>
  22. </template>
  23. <script lang="ts" setup>
  24. type Item = Record<string, any> & {select?: boolean}
  25. type ListProps = { title: string, key?: string, data: Array<Item>}
  26. defineProps<ListProps>()
  27. defineEmits<{ (e: 'changeSelect', item: Item): void }>()
  28. </script>
  29. <style lang="scss" scoped>
  30. .header {
  31. border-bottom: 1px solid rgba(255,255,255,0.16);
  32. display: flex;
  33. justify-content: space-between;
  34. padding: 20px;
  35. h3 {
  36. font-size: 16px;
  37. font-weight: bold;
  38. color: #999999;
  39. }
  40. }
  41. .content {
  42. li {
  43. padding: 0 20px;
  44. cursor: pointer;
  45. &.select {
  46. background: rgba(0,200,175,0.1600);
  47. }
  48. .atom-content {
  49. padding: 20px 0;
  50. border-bottom: 1px solid rgba(255,255,255,0.16);
  51. }
  52. }
  53. }
  54. .list li {
  55. list-style: none;
  56. }
  57. </style>