litian
2024-09-12 bbba5d26e9e26c910ed337dcb65f462752ee6dce
pages/personalCenter/certificate/index.js
@@ -1,4 +1,9 @@
const app = getApp();
import Wxml2Canvas from 'wxml2canvas';
import moment from 'moment'
import {
  getPublicImage
} from "../../../assets/js/middleGround/tool.js";
Page({
  /**
@@ -34,6 +39,9 @@
    closeBtn: false,
    deleteBtn: false,
    images: [],
    pubCertificateHide: false,
    contentData: {},
    rzzsImg: ''
  },
  /**
@@ -88,9 +96,10 @@
      .then((res) => {
        if (res.datas.length > 0) {
          res.datas.forEach((item) => {
            item.updateDate = item.updateDate.split('T')[0]
            if (item.content) {
              item.productList = JSON.parse(item.content)
              item.productList.updateDate = moment(item.updateDate).format('YYYY年MM月')
              item.productList.userPicture = getPublicImage(item.productList.userPicture, '', '')
            }
          })
          let dataList = res.datas;
@@ -119,18 +128,63 @@
  goBookDetails(e) {
    let productList = e.currentTarget.dataset.book.productList
    this.setData({
      images: productList.certificate ? [productList.certificate] : this.data.active === 0 ? ['/static/images/certificate/kczs.jpg'] : ['/static/images/certificate/jczs.jpg'],
      contentData: productList,
      pubCertificateHide: true,
    })
    this.drawImage1()
  },
  drawImage1() {
    let that = this;
    let drawMyImage1 = new Wxml2Canvas({
      width: that.data.imageWidth,
      height: that.data.imageHeight,
      element: 'myCanvas1',
      progress(percent) {},
      finish(url) {
        wx.getFileSystemManager().readFile({
          filePath: url,
          encoding: 'base64',
          success: (res) => {
            let MyImageBase641 = 'data:image/jpg;base64,' + res.data
            if (MyImageBase641) {
              that.setData({
                rzzsImg: MyImageBase641,
              })
            }
            setTimeout(() => {
              that.setData({
                pubCertificateHide: false,
                images: [that.data.rzzsImg],
      showIndex: true,
      visible: true,
    })
            }, 1000)
  },
        })
      },
      error(res) {
        console.log("生成的图片失败", res)
      }
    }, this);
    let data = {
      list: [{
        type: 'wxml',
        class: '.my_canvas1 .my_draw_canvas1', //.my_draw_canvas每个要绘制元素的类名
        limit: '.my_canvas1', //my_canvas根元素类名
        x: 0,
        y: 0
      }]
    }
    drawMyImage1.draw(data, that);
  },
  onClose(e) {
    const {
      trigger
    } = e.detail;
    this.setData({
      visible: false,
      images: [],
    });
  },
  /**