123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- import {
- getVipInfo,
- } from '~/api/user'
- import {
- formatDate
- } from '~/utils/util'
- Component({
- /**
- * 组件的属性列表
- */
- properties: {
- },
- /**
- * 组件的初始数据
- */
- data: {
- show: false,
- type: '',
- vipTime: ''
- },
- methods: {
- open({
- type
- }) {
- if (typeof this.getTabBar === 'function') {
- this.getTabBar().setData({
- mask: true
- })
- }
- this.getVipInfo()
- this.setData({
- type,
- show: true
- })
- },
- closeModal() {
- this.setData({
- show: false
- })
- if (typeof this.getTabBar === 'function') {
- this.getTabBar().setData({
- mask: false
- })
- }
- },
- async getVipInfo() {
- let vipTime = await getVipInfo()
- console.log(vipTime);
- this.setData({
- vipTime
- })
- },
- creatShare() {
- let type = this.data.type
- let context = wx.createSelectorQuery();
- context
- .select('#vip')
- .fields({
- node: true,
- size: true
- }).exec((res) => {
- const canvas = res[0].node;
- const ctx = canvas.getContext('2d');
- const dpr = wx.getSystemInfoSync().pixelRatio;
- canvas.width = res[0].width * dpr;
- canvas.height = res[0].height * dpr;
- ctx.scale(dpr, dpr);
- ctx.font = '18px PingFang';
- let pic = canvas.createImage();
- pic.src = type == 'svip' ? 'http://reader-wx.ai160.com/images/reader/v3/learn/vip1.png' : 'http://reader-wx.ai160.com/images/reader/v3/learn/vip2.png'
- pic.onload = () => {
- ctx.drawImage(pic, 0, 0, 375, 201);
- if (type == 'svip') {
- ctx.fillStyle = "#D7E6FF";
- ctx.fillText('终身使用', 16, 184)
- } else {
- ctx.fillStyle = "#FFE6D2";
- ctx.fillText('有效期至:' + formatDate(this.data.vipTime, 5), 16, 184)
- }
- setTimeout(() => {
- wx.canvasToTempFilePath({
- canvas: canvas,
- success(res) {
- wx.saveImageToPhotosAlbum({
- filePath: res.tempFilePath,
- success(res) {
- wx.showToast({
- title: '保存成功!',
- icon: "none",
- duration: 3000
- })
- }
- })
- },
- fail(res) {
- console.log('fail', res);
- }
- }, this)
- }, 500)
- }
- })
- },
- }
- })
|