index.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <template>
  2. <div class="furnitureItem">
  3. <furniture-icon :icon="props.icon" :width="width" :height="height" />
  4. <div class="contant">
  5. <span class="text">{{ furnitureIconNameMap[props.icon] }}</span>
  6. <div class="action" @click="addHandler">
  7. <slot name="action">
  8. <PlusCircleOutlined />
  9. </slot>
  10. </div>
  11. </div>
  12. </div>
  13. </template>
  14. <script setup lang="ts">
  15. import type { FurnitureIconType } from '@/types/furniture'
  16. import { furnitureIconNameMap } from '@/const/furniture'
  17. import { PlusCircleOutlined } from '@ant-design/icons-vue'
  18. defineOptions({
  19. name: 'FurnitureItem',
  20. })
  21. type Props = {
  22. icon: FurnitureIconType
  23. width?: number
  24. height?: number
  25. }
  26. const emit = defineEmits<{
  27. (e: 'add', icon: FurnitureIconType): void
  28. }>()
  29. const props = withDefaults(defineProps<Props>(), {
  30. icon: 'bed',
  31. width: 30,
  32. height: 30,
  33. })
  34. const addHandler = () => {
  35. emit('add', props.icon)
  36. }
  37. </script>
  38. <style scoped lang="less">
  39. .furnitureItem {
  40. display: flex;
  41. align-items: center;
  42. padding: 5px;
  43. .text {
  44. font-size: 14px;
  45. user-select: none;
  46. }
  47. .contant {
  48. display: flex;
  49. align-items: center;
  50. justify-content: space-between;
  51. width: 100%;
  52. padding: 0 8px;
  53. .action {
  54. cursor: pointer;
  55. font-size: 16px;
  56. transition: color 0.2s;
  57. }
  58. }
  59. .contant:hover {
  60. color: #1890ff;
  61. .action:hover {
  62. color: green;
  63. }
  64. }
  65. &:hover {
  66. box-shadow: 0 4px 12px rgba(220, 220, 220, 0.7);
  67. box-sizing: border-box;
  68. border-radius: 5px;
  69. }
  70. }
  71. </style>