当前位置: 首页 > news >正文

【uniapp小程序-分享】

//分享到聊天onShareAppMessage() {let shareMessage = {title: this.liveInfo.wx_title,path: '/subPages/livePages/liveCourse/live_course_info?courseid=' +this.courseid,imageUrl: this.liveInfo.wx_thumb};let shearMsg = uni.getStorageSync('shearImg' + this.courseid);if (shearMsg && shearMsg.id == this.courseid) {return {title: shareMessage.title,path: shareMessage.path,imageUrl: `${this.liveInfo.wx_thumb}?imageView2/1/w/640/h/360`|| shearMsg.imgPath};} else {uni.showLoading({title: '分享图片生成中...',icon: 'none'});return new Promise((resolve, reject) => {this.shareCode().then(res => {uni.hideLoading();let img = res uni.hideLoading();resolve({title: shareMessage.title,path: shareMessage.path,imageUrl: img});// 将分享图片加入缓存let msg = {imgPath: img,id: this.courseid};uni.setStorageSync('shearImg' + this.courseid, msg);}).catch(err => {uni.hideLoading();resolve({title: shareMessage.title,path: shareMessage.path,imageUrl: imgPath});});});}},// 分享到朋友圈onShareTimeline() {return {title: this.liveInfo.name,path: '/subPages/livePages/liveCourse/live_course_info?courseid=' +this.courseid,imageUrl: this.liveInfo.wx_thumb};},methods:{// 分享卡片shareCode() {let _this = this;return new Promise(async (resolve, reject) => {const ctx = uni.createCanvasContext('shareCanvas', this);let bg = this.liveInfo.wx_thumblet bt = '背景图';ctx.draw();ctx.save();await uni.getImageInfo({src: bg}).then(res => {if (res[1].errMsg == 'getImageInfo:ok') {ctx.save();ctx.drawImage(res[1].path, 0, 0, 195, 160);ctx.restore();} else {uni.$u.toast('海报生成失败');}});ctx.restore();// 生成图片ctx.draw(true, ret => {setTimeout(() => {uni.canvasToTempFilePath({canvasId: 'shareCanvas',success: res => {resolve(res.tempFilePath);},fail: err => {uni.$u.toast('分享图片生成失败');}},_this);}, 10);});});},textPrewrap(ctx, content, drawX, drawY, lineHeight, lineMaxWidth, lineNum) {var drawTxt = ''; // 当前绘制的内容var drawLine = 1; // 第几行开始绘制var drawIndex = 0; // 当前绘制内容的索引// 判断内容是否可以一行绘制完毕if (ctx.measureText(content).width <= lineMaxWidth) {ctx.fillText(content.substring(drawIndex, i), drawX, drawY);} else {for (var i = 0; i < content.length; i++) {drawTxt += content[i];if (ctx.measureText(drawTxt).width >= lineMaxWidth) {if (drawLine >= lineNum) {ctx.fillText(content.substring(drawIndex, i) + '..', drawX, drawY);break;} else {ctx.fillText(content.substring(drawIndex, i + 1), drawX, drawY);drawIndex = i + 1;drawLine += 1;drawY += lineHeight;drawTxt = '';}} else {// 内容绘制完毕,但是剩下的内容宽度不到lineMaxWidthif (i === content.length - 1) {ctx.fillText(content.substring(drawIndex), drawX, drawY);}}}}},
}
http://www.lryc.cn/news/262798.html

相关文章:

  • 思幻二次元风格的工作室个人引导页源码
  • Rsync+notify文件实时同步工具
  • 小信砍柴的题解
  • 华为OD机试 - 跳格子3(Java JS Python C)
  • 每天五分钟计算机视觉:谷歌的Inception模块的计算成本的问题
  • 最新AI创作系统ChatGPT系统源码+DALL-E3文生图+支持AI绘画+GPT语音对话功能
  • 78-C语言-完数的判断,以及输出其因子
  • C# 使用FluentHttpClient请求WebApi
  • AXure交互及案列
  • 美颜SDK技术对比,深入了解视频美颜SDK的工作机制
  • OkHttp ,使用 HttpUrl.Builder 来添加查询参数并添加到请求对象
  • 图片速览 PoseGPT:基于量化的 3D 人体运动生成和预测(VQVAE)
  • Java对象结构
  • 基于redis的分布式锁实现方案
  • 基于JAVA+SpringBoot的线上智能问诊就医平台
  • adb: error: cannot create file/directory ‘d:/1.png‘: No such file or directory
  • Pelee: A Real-Time Object Detection System on Mobile Devices(CVPR 2019)
  • 分布式理论 | RPC | Spring Boot 整合 Dubbo + ZooKeeper
  • 局域网其他pc如何访问宿主机虚拟机IP?
  • U8 语法制导翻译技术
  • 剑指offer A + B
  • gitlab(gitlab-ce)下载,离线安装
  • Jmeter接口测试断言
  • Temu、Shein、OZON测评自养号,IP和指纹浏览器的优缺点分析
  • 亚信科技AntDB数据库——深入了解AntDB-M元数据锁的相关概念
  • yolov5 deepsort-船舶目标检测+目标跟踪+单目测距+速度测量
  • Wireshark与其他工具的整合
  • DDD架构实践
  • Bert-vits2-v2.2新版本本地训练推理整合包(原神八重神子英文模型miko)
  • 认识缓存,一文读懂Cookie,Session缓存机制。