问题:crmeb标准版如何调整分销海报的位置和大小

解决方案:

在前端找到utils文件,找到util.js,在util.js中找到这部分,可以直接在文件内搜索"用户信息分享海报"

    /**
     * 用户信息分享海报
     * @param array arr2 海报素材  1背景 0二维码
     * @param string nickname 昵称
     * @param string sitename 价格
     * @param function successFn 回调函数
     */

路径为:盘符:\项目文件夹名称\utils\utils.js,具体路径可以根据自己的看

然后调整这部分代码,就可以调整二维码的位置和大小了,具体的写法有不同,可以根据自己的

//x:240 y:426
let codex = 0.1906
let codey = 0.7746
let codeSize = 0.21666
let namex = 0.4283
let namey = 0.8215
let markx = 0.4283
let marky = 0.8685

我的写法:

	/**
	 * 用户信息分享海报
	 * @param array arr2 海报素材  1背景 0二维码
	 * @param string nickname 昵称
	 * @param string sitename 价格
	 * @param function successFn 回调函数
	 * 
	 * 
	 */
	userPosterCanvas: function(arr2, nickname, sitename, index, w, h, successFn) {
		let that = this;
		const ctx = uni.createCanvasContext('myCanvas' + index);
		ctx.clearRect(0, 0, 0, 0);
		/**
		 * 只能获取合法域名下的图片信息,本地调试无法获取
		 * 
		 */
		uni.getImageInfo({
			src: arr2[1],
			success: function(res) {
				const WIDTH = res.width;
				const HEIGHT = res.height;
				ctx.fillStyle = '#fff';
				ctx.fillRect(0, 0, w, h);
				ctx.drawImage(arr2[1], 0, 0, w, h);
				ctx.setTextAlign('center')
				ctx.setFontSize(12);
				ctx.setFillStyle('#333');

				fx_hb_size().then(res => {
					const codeSizeRatio_f = res.data.codeSizeRatio; 
					const codey2 = res.data.codey2;
					const codeSize = w * codeSizeRatio_f;
					const codex = (w - codeSize) / 2;
					const codey = h * codey2; 
					// 绘制二维码
					ctx.drawImage(arr2[0], codex, codey, codeSize, codeSize);
					ctx.setTextAlign('center');
					ctx.setFillStyle('#333');
					let nameFontSize = w < 270 ? 14 : 18; 
					ctx.setFontSize(nameFontSize);
					ctx.fillText(nickname, w * 0.5, codey - h * 0.06);
					let markFontSize = w < 270 ? 11 : 14;
					ctx.setFontSize(markFontSize);
					ctx.fillText(i18n.t(`邀请您加入`) + sitename, w * 0.5, codey + codeSize + h *
						0.05);
					ctx.save();
					ctx.draw(true, function() {
						uni.canvasToTempFilePath({
							canvasId: 'myCanvas' + index,
							fileType: 'png',
							quality: 1,
							success: function(res) {
								successFn && successFn(res.tempFilePath);
							}
						})
					});
				})
			},
			fail: function(err) {
				uni.hideLoading();
				that.Tips({
					title: i18n.t(`无法获取图片信息`)
				});
			}
		})
	},

由于会经常改二维码大小所以这里写了个API来返回两个基础的控制参数以此做到不用每次都更新小程序端,其它代码都是原有的可以不用改。

Logo

火山引擎开发者社区是火山引擎打造的AI技术生态平台,聚焦Agent与大模型开发,提供豆包系列模型(图像/视频/视觉)、智能分析与会话工具,并配套评测集、动手实验室及行业案例库。社区通过技术沙龙、挑战赛等活动促进开发者成长,新用户可领50万Tokens权益,助力构建智能应用。

更多推荐