share.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <template>
  2. <div id="dialog_index" v-show="show">
  3. <div class="created_dialog">
  4. <div class="blurBox"></div>
  5. <div class="content">
  6. <div class="dialog_title">{{ title }}</div>
  7. <div class="dialog_link">
  8. <p>
  9. {{ shareLink }}
  10. </p>
  11. </div>
  12. <div class="created_btn">
  13. <div class="created_cancel" @click="closeCreated">{{ t('base.cancel') }}</div>
  14. <div
  15. class="created_confirm"
  16. ref="copylink$"
  17. :data-clipboard-text="shareLink"
  18. @click="createdConfirm"
  19. >
  20. <!-- 复制分享 -->
  21. {{ t('base.copyShare') }}
  22. </div>
  23. </div>
  24. </div>
  25. </div>
  26. </div>
  27. </template>
  28. <script setup lang="ts">
  29. import {
  30. onMounted,
  31. defineProps,
  32. defineEmits,
  33. ref,
  34. unref,
  35. watchEffect,
  36. nextTick,
  37. onUnmounted,
  38. } from 'vue';
  39. import ClipboardJS from 'clipboard';
  40. import Dialog from '/@/components/basic/dialog';
  41. import { useI18n } from '/@/hooks/useI18n';
  42. const { t } = useI18n();
  43. const emit = defineEmits(['close']);
  44. const props = defineProps({
  45. title: {
  46. type: String,
  47. default: () => {
  48. const { t } = useI18n();
  49. return t('base.inviteFriends');
  50. },
  51. },
  52. shareLink: {
  53. type: String,
  54. default: '',
  55. },
  56. });
  57. const copylink$ = ref<Nullable<HTMLElement>>(null);
  58. const show = ref(false);
  59. let copyInstance: ClipboardJS;
  60. const closeCreated = () => {
  61. show.value = false;
  62. emit('close');
  63. };
  64. onMounted(() => {
  65. const ele = unref(copylink$) as any as HTMLElement;
  66. copyInstance = new ClipboardJS(ele);
  67. copyInstance.on('success', (e) => {
  68. e.clearSelection();
  69. });
  70. });
  71. onUnmounted(() => {
  72. copyInstance.destroy();
  73. });
  74. const createdConfirm = async () => {
  75. if (unref(copylink$)) {
  76. await nextTick(() => {
  77. console.log('copySuccess');
  78. Dialog.toast({ content: t('base.copyShareSuccess'), type: 'success' });
  79. setTimeout(() => {
  80. show.value = false;
  81. emit('close');
  82. }, 300);
  83. });
  84. }
  85. };
  86. onMounted(() => {
  87. watchEffect(() => {
  88. if (props.shareLink?.length) {
  89. show.value = true;
  90. }
  91. });
  92. });
  93. </script>
  94. <style scoped lang="scss">
  95. #dialog_index {
  96. width: 100vw;
  97. height: 100%;
  98. // background: rgba(0, 0, 0, 0.5);
  99. position: fixed;
  100. left: 0;
  101. top: 0;
  102. z-index: 100000;
  103. pointer-events: none;
  104. .created_dialog {
  105. width: 8.64rem;
  106. // min-height: 5rem;
  107. // background: #ffffff;
  108. border-radius: 8px;
  109. position: absolute;
  110. left: 50%;
  111. top: 50%;
  112. transform: translate(-50%, -50%);
  113. pointer-events: auto;
  114. border: 1px solid rgba(255, 255, 255, 0.1);
  115. border-radius: 4px;
  116. .blurBox {
  117. position: absolute;
  118. z-index: 1;
  119. top: 0;
  120. left: 0;
  121. width: 100%;
  122. height: 100%;
  123. background: rgba(0, 0, 0, 0.7);
  124. filter: blur(1px);
  125. }
  126. .content {
  127. position: relative;
  128. z-index: 2;
  129. top: 0;
  130. left: 0;
  131. width: 100%;
  132. height: 100%;
  133. }
  134. .dialog_title {
  135. width: 100%;
  136. height: 1.39rem;
  137. padding: 0 0.56rem;
  138. box-sizing: border-box;
  139. font-size: 0.39rem;
  140. color: #fff;
  141. line-height: 1.39rem;
  142. overflow: hidden;
  143. text-overflow: ellipsis;
  144. white-space: nowrap;
  145. border-bottom-style: solid;
  146. border-bottom-width: 1px;
  147. border-bottom-color: rgba(255, 255, 255, 0.1);
  148. }
  149. .dialog_link {
  150. width: 100%;
  151. font-size: 0.39rem;
  152. color: rgba(255, 255, 255, 0.5);
  153. padding: 0.53rem 0.56rem;
  154. box-sizing: border-box;
  155. text-align: justify;
  156. text-align: left;
  157. > p {
  158. background: rgba(0, 0, 0, 0.5);
  159. padding: 0.15rem 0.28rem;
  160. word-break: break-all;
  161. word-wrap: break-word;
  162. text-overflow: -o-ellipsis-lastline;
  163. overflow: hidden;
  164. text-overflow: ellipsis;
  165. display: -webkit-box;
  166. -webkit-line-clamp: 2;
  167. line-clamp: 2;
  168. -webkit-box-orient: vertical;
  169. line-height: 0.72rem;
  170. }
  171. }
  172. .created_btn {
  173. width: 100%;
  174. height: 1.36rem;
  175. border-top-style: solid;
  176. border-top-width: 1px;
  177. border-top-color: rgba(255, 255, 255, 0.1);
  178. box-sizing: border-box;
  179. display: flex;
  180. align-items: center;
  181. justify-content: center;
  182. > div {
  183. width: 50%;
  184. height: 1.36rem;
  185. text-align: center;
  186. line-height: 1.36rem;
  187. font-size: 0.39rem;
  188. box-sizing: border-box;
  189. &.created_cancel {
  190. color: #fff;
  191. border-right-style: solid;
  192. border-right-width: 1px;
  193. border-right-color: rgba(0, 0, 0, 0.05);
  194. }
  195. &.created_confirm {
  196. color: #ed5d18;
  197. }
  198. }
  199. }
  200. }
  201. }
  202. </style>