Link.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <template>
  2. <div class="media" v-show="url">
  3. <iframe v-if="url" :src="url" frameborder="0"></iframe>
  4. <div v-if="isEdit" class="delete" @click.stop="onDelete"><i class="iconfont icon-delete"></i></div>
  5. <div class="link" v-if="isEdit">{{ url }}</div>
  6. </div>
  7. <div class="placeholder" v-show="url == null">
  8. <div class="icon">
  9. <span>{{ $t('components.linkView') }}</span>
  10. </div>
  11. <div class="link">
  12. <input type="text" placeholder="https://" v-model.trim="href" />
  13. <div class="save" :class="{ disabled: !href }" @click="onConfirm"><i class="iconfont icon-checkbox1"></i></div>
  14. </div>
  15. </div>
  16. </template>
  17. <script setup>
  18. import { ref, onMounted, inject, computed } from 'vue'
  19. const emits = defineEmits(['tips'])
  20. const notify = inject('notify')
  21. const isEdit = inject('isEdit')
  22. const url = ref(null)
  23. const href = ref('')
  24. const onDelete = () => {
  25. url.value = null
  26. notify.value.media['link'] = []
  27. }
  28. const onConfirm = () => {
  29. if (href.value) {
  30. url.value = 'https://' + href.value.replace(/http(s?):\/\//, '')
  31. href.value = ''
  32. }
  33. notify.value.media['link'] = [{ src: url.value }]
  34. }
  35. onMounted(() => {
  36. url.value = notify.value.media?.link && notify.value.media.link[0] ? notify.value.media.link[0].src : null
  37. })
  38. </script>
  39. <style lang="scss" scoped>
  40. .placeholder {
  41. width: 100%;
  42. height: 100%;
  43. display: flex;
  44. align-items: center;
  45. justify-content: center;
  46. .icon {
  47. display: flex;
  48. align-items: center;
  49. justify-content: center;
  50. flex-direction: column;
  51. color: rgba(255, 255, 255, 0.6);
  52. font-size: 14px;
  53. span {
  54. margin-top: 10px;
  55. }
  56. }
  57. .tips {
  58. font-size: 12px;
  59. padding: 10px;
  60. position: absolute;
  61. bottom: 0;
  62. width: 100%;
  63. color: rgba(255, 255, 255, 0.3);
  64. }
  65. .link {
  66. position: absolute;
  67. bottom: 0;
  68. left: 0;
  69. width: 100%;
  70. height: 32px;
  71. background: linear-gradient(180deg, rgba(0, 0, 0, 0.1), #000 200%);
  72. border-radius: 0 0 4px 4px;
  73. z-index: 10;
  74. display: flex;
  75. align-items: center;
  76. justify-content: center;
  77. .save {
  78. cursor: pointer;
  79. width: 16px;
  80. height: 16px;
  81. display: flex;
  82. align-items: center;
  83. justify-content: center;
  84. border-radius: 50%;
  85. background: hsla(0, 0%, 100%, 0.7);
  86. color: rgba(0, 0, 0, 0.6);
  87. margin: 0 8px;
  88. i {
  89. font-size: 16px;
  90. }
  91. }
  92. input {
  93. width: 100%;
  94. height: 100%;
  95. color: #fff;
  96. font-size: 14px;
  97. padding-left: 10px;
  98. }
  99. }
  100. }
  101. .media {
  102. width: 100%;
  103. height: 100%;
  104. iframe {
  105. width: 100%;
  106. height: 100%;
  107. }
  108. .link {
  109. padding: 0 12px;
  110. font-size: 14px;
  111. position: absolute;
  112. bottom: 0;
  113. left: 0;
  114. width: 100%;
  115. height: 32px;
  116. line-height: 32px;
  117. background: linear-gradient(180deg, rgba(0, 0, 0, 0.3), #000 200%) !important;
  118. border-radius: 0 0 4px 4px;
  119. z-index: 10;
  120. white-space: nowrap;
  121. overflow: hidden;
  122. text-overflow: ellipsis;
  123. }
  124. .delete {
  125. cursor: pointer;
  126. position: absolute;
  127. width: 24px;
  128. height: 24px;
  129. background: rgba(0, 0, 0, 0.3);
  130. border-radius: 50%;
  131. top: 10px;
  132. right: 10px;
  133. display: flex;
  134. align-items: center;
  135. justify-content: center;
  136. }
  137. }
  138. </style>