ModalSelectIcon.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <template>
  2. <a-modal
  3. v-model:visible="showModal"
  4. :align-center="false"
  5. top="15vh"
  6. @cancel="handleCancel"
  7. @before-ok="handleBeforeOk"
  8. >
  9. <template #title>{{ $t('management.change_icon_title') }}</template>
  10. <div class="section">
  11. <div class="labels">{{ $t('management.all_icon') }}</div>
  12. <div class="icons">
  13. <div
  14. class="icon-border"
  15. v-for="icon in icons"
  16. :key="icon.icon"
  17. :class="{ 'icon-border-active': icon.id === target_icon_id }"
  18. @click="changeItem(icon.id)"
  19. >
  20. <img class="icon" :src="getImageKnowLedge(icon.name)" alt="" />
  21. </div>
  22. </div>
  23. </div>
  24. </a-modal>
  25. </template>
  26. <script setup>
  27. import { ref, computed, watch } from 'vue';
  28. import { getImageKnowLedge } from '../common/icon-map.js';
  29. const props = defineProps({
  30. show_select_icon: {
  31. type: Boolean,
  32. default: false
  33. },
  34. target_icon: {
  35. type: String,
  36. default: ''
  37. }
  38. });
  39. const emit = defineEmits(['update:show_model_item', 'sendIcon', 'clearTargetIcon']);
  40. const icons = ref([
  41. {
  42. id: 1,
  43. name: 'knowledgeFrame1'
  44. },
  45. {
  46. id: 2,
  47. name: 'knowledgeFrame2'
  48. },
  49. {
  50. id: 3,
  51. name: 'knowledgeFrame3'
  52. },
  53. {
  54. id: 4,
  55. name: 'knowledgeFrame4'
  56. }
  57. ]);
  58. const target_icon_id = ref(icons.value[0].id);
  59. const showModal = computed(() => props.show_select_icon);
  60. const changeItem = (id) => {
  61. target_icon_id.value = id;
  62. };
  63. const handleBeforeOk = (done) => {
  64. emit('sendIcon', icons.value.filter((icon) => icon.id === target_icon_id.value)[0].name);
  65. emit('update:show_select_icon', false);
  66. done();
  67. };
  68. const handleCancel = () => {
  69. emit('update:show_select_icon', false);
  70. emit('clearTargetIcon');
  71. };
  72. watch(
  73. () => props.target_icon,
  74. (new_value) => {
  75. if (new_value && new_value.length) {
  76. target_icon_id.value = icons.value.filter((icon) => icon.name === new_value)[0]?.id || icons.value[0].id;
  77. } else {
  78. target_icon_id.value = icons.value[0].id;
  79. }
  80. },
  81. {
  82. immediate: true
  83. }
  84. );
  85. </script>
  86. <style scoped lang="css">
  87. .section {
  88. height: 200px;
  89. padding: 0 20px;
  90. }
  91. .icons {
  92. display: flex;
  93. flex-wrap: wrap;
  94. gap: 10px;
  95. margin-top: 10px;
  96. }
  97. .icon-border {
  98. border: 1px solid var(--color-border-1);
  99. border-radius: 5px;
  100. padding: 5px 8px 0px 8px;
  101. cursor: pointer;
  102. transition: transform 0.3s ease, box-shadow 0.3s ease;
  103. }
  104. .icon-border:hover {
  105. border: 1px solid var(--color-border-3);
  106. border-radius: 5px;
  107. transform: scale(1.05);
  108. }
  109. .icon-border .icon {
  110. width: 44px;
  111. height: 44px;
  112. }
  113. .icon-border-active {
  114. border: 1px solid var(--color-border-3);
  115. transform: scale(1.1);
  116. }
  117. .arco-input-wrapper {
  118. height: 32px;
  119. background-color: var(--color-border-2);
  120. }
  121. </style>