<template>
  <view class="messagetext" @longpress="handleCopy"> {{ messagetext }} </view>
</template>

<script>
export default {
  data() {
    return {};
  },
  onLoad() {
    // 页面加载时执行
  },
  props: {
    messagetext: {
      type: String,
      default: "",
    },
  },
  methods: {
    handleCopy() {
      // 复制到剪贴板
      uni.setClipboardData({
        data: this.messagetext,
        success: () => {
          // 显示成功提示
          uni.showToast({
            title: "复制成功",
            icon: "success",
            duration: 1500,
          });
        },
        fail: (err) => {
          console.error("复制失败:", err);
        },
      });
    },
  },
};
</script>

<style scoped>
.messagetext {
  font-size: 34rpx;
  color: #333;
  letter-spacing: 1rpx;
  padding: 19rpx 30rpx 19rpx 30rpx;
}
</style>
