<!-- @format -->

<template>
  <view style="padding: 20rpx">
    <view
      style="
        padding: 30rpx;
        background-color: #fff;
        border-radius: 10rpx;
        font-size: 32rpx;
        line-height: 50rpx;
      "
    >
      <!-- <view @linktap="handlelink" :content="contents" /> -->
      <u-parse :content="contents" @navigate="navigate"></u-parse>
    </view>
  </view>
</template>

<script>
import { getMessageDetails } from "@/api/work";
import uParse from "@/components/u-parse/u-parse.vue";
export default {
  components: {
    uParse,
  },
  data() {
    return {
      contents: "",
    };
  },
  onLoad(options) {
    getMessageDetails({ msgId: options.id }).then(({ data }) => {
      this.contents = data.contents;
    });
  },
  computed: {
    // formattedContents() {
    // 	// 替换原有的 onclick 为 Vue 的 @click 事件处理
    // 	return this.contents.replace(/onclick='window\.previewPdf\("([^"]+)"\)'/g, (match, p1) => {
    // 		return `@click.prevent="previewPdf('${p1}')"`;
    // 	});
    // }
  },
  methods: {
    navigate(row) {
      console.log(
        "http://im.hebjlzy.com/api/system/sys-file/download?bucket=local&path=" +
          row
      );
      uni.downloadFile({
        url:
          "http://im.hebjlzy.com/api/system/sys-file/download?bucket=local&path=" +
          row,
        success: (res) => {
          var filePath = res.tempFilePath;
          uni.openDocument({
            filePath: filePath,
            showMenu: true,
            success: function (res) {
              console.log("打开文档成功");
            },
          });
        },
      });
    },
    handlelink(row) {},
    // handleClick(event) {
    // 	// 处理点击事件
    // 	const target = event.target;
    // 	if (target && target.classList.contains('pdf-link')) {
    // 		const val = target.getAttribute('data-pdf'); // 获取链接文本
    // 		this.previewPdf(val);
    // 	}
    // },
    // previewPdf(val) {
    // 	// 在这里添加预览 PDF 的逻辑
    // 	console.log('预览 PDF', val);
    // }
  },
};
</script>

<style lang="scss"></style>
