sq-copy-btn.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <script setup>
  2. import { computed } from 'vue';
  3. import { staticAssetUrl } from '@/utils/staticAsset';
  4. const props = defineProps({
  5. text: { type: [String, Number, Object], default: '' },
  6. label: { type: String, default: '' },
  7. iconOnly: { type: Boolean, default: false }
  8. });
  9. const value = computed(() => String(props.text ?? '').trim());
  10. const ICON_COPY = staticAssetUrl('copy.svg');
  11. function onCopy() {
  12. const v = value.value;
  13. if (!v || v === '—') return;
  14. uni.setClipboardData({
  15. data: v,
  16. success: () => uni.showToast({ title: `${props.label || '内容'}已复制`, icon: 'none' })
  17. });
  18. }
  19. </script>
  20. <template>
  21. <view
  22. v-if="value"
  23. class="sq-copy-btn"
  24. :class="{ 'sq-copy-btn--icon-only': !!iconOnly }"
  25. @click.stop="onCopy"
  26. >
  27. <image class="sq-copy-btn__icon" :src="ICON_COPY" mode="aspectFit" />
  28. <text v-if="!iconOnly" class="sq-copy-btn__text">复制</text>
  29. </view>
  30. </template>
  31. <style lang="scss" scoped>
  32. /* 参考配送员端复制按钮样式:浅绿底 + 绿字 */
  33. .sq-copy-btn {
  34. flex-shrink: 0;
  35. min-height: 36rpx;
  36. padding: 0 10rpx;
  37. border-radius: 999rpx;
  38. background: #eef8f3;
  39. display: inline-flex;
  40. align-items: center;
  41. gap: 6rpx;
  42. }
  43. .sq-copy-btn--icon-only {
  44. width: 44rpx;
  45. height: 44rpx;
  46. padding: 0;
  47. justify-content: center;
  48. border-radius: 10rpx;
  49. }
  50. .sq-copy-btn__icon {
  51. width: 20rpx;
  52. height: 20rpx;
  53. }
  54. .sq-copy-btn--icon-only .sq-copy-btn__icon {
  55. width: 22rpx;
  56. height: 22rpx;
  57. }
  58. .sq-copy-btn__text {
  59. font-size: 18rpx;
  60. color: #189b65;
  61. }
  62. </style>