image.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <div class="image">
  3. <el-input style="width: 310px" v-model="input" placeholder="请输入图片描述">
  4. <template #append>
  5. <el-button
  6. type="primary"
  7. :loading="is_status === 'load'"
  8. @click="search"
  9. >查找</el-button
  10. >
  11. </template>
  12. </el-input>
  13. <div style="width: 310px; margin: 0 auto" v-if="is_status === 'none'">
  14. <el-image style="width: 310px; height: 232.5px" :src="image" fit="fill" />
  15. <div class="none_title">输入描述,自动配图</div>
  16. <ul>
  17. <li>根据您对图片的描述,智能匹配相关图片</li>
  18. <li>图片均来自Pixabay等图库,可免费商用</li>
  19. </ul>
  20. </div>
  21. <div class="masonry" v-if="is_status === 'data' && oriD.length">
  22. <div class="item" v-for="(item, index) in oriD" :key="index">
  23. <img :src="item.url" style="width: 100%;" />
  24. <el-icon class="saveImg" @click="()=>saveImg(item)"><Warning /></el-icon>
  25. </div>
  26. </div>
  27. </div>
  28. </template>
  29. <script setup>
  30. // 图片
  31. import image from '@/assets/img/image.png';
  32. import { textImageMatch } from '@/api/aleditor.js';
  33. import { ref, defineEmits } from 'vue';
  34. const is_status = ref('none');
  35. const input = ref('');
  36. const oriD = ref({});
  37. const emits = defineEmits(['closeType', 'setHtml', 'getImage', 'setImage']);
  38. const search = () => {
  39. is_status.value = 'load';
  40. textImageMatch({
  41. data: {
  42. text: input.value,
  43. type: '',
  44. },
  45. })
  46. .then(r => {
  47. const li = r ? r.data || [] : [];
  48. oriD.value= li;
  49. is_status.value = oriD.value.length ? 'data' : 'none';
  50. })
  51. .catch(() => {
  52. is_status.value = 'none';
  53. });
  54. };
  55. const saveImg = item => {
  56. emits('setImage', [item.url]);
  57. }
  58. </script>
  59. <style scoped>
  60. .none_title {
  61. font-size: 24px;
  62. text-align: left;
  63. font-weight: 700;
  64. margin-bottom: 16px;
  65. margin-left: 11.3%;
  66. }
  67. ul {
  68. margin-left: 20px;
  69. }
  70. ul > li {
  71. font-size: 14px;
  72. color: #2c3e50;
  73. margin-bottom: 16px;
  74. }
  75. .masonry {
  76. /* width: 95%;
  77. margin: 0 auto;
  78. padding-top: 1em;
  79. column-count: 2;
  80. column-gap: 0;
  81. display: flex;
  82. flex-wrap: wrap; */
  83. column-count: 3;
  84. column-gap: 3px;
  85. }
  86. .item{
  87. padding: 2px;
  88. position: relative;
  89. counter-increment: item-counter;
  90. }
  91. .item img{
  92. display: block;
  93. width: 100%;
  94. height: auto;
  95. }
  96. /* .item::after{
  97. position: absolute;
  98. display: block;
  99. top: 2px;
  100. left: 2px;
  101. width: 24px;
  102. height: 24px;
  103. text-align: center;
  104. line-height: 24px;
  105. background-color: #000;
  106. color: #fff;
  107. content: counter(item-counter);
  108. } */
  109. .saveImg{
  110. position: absolute;
  111. background-color: #fff;
  112. border-radius: 50%;
  113. right: 2px;
  114. top: 2px;
  115. display: none;
  116. cursor: pointer;
  117. }
  118. .item:hover .saveImg{
  119. display: block;
  120. }
  121. </style>