Commit 8bea58ab7af4f94a315be30ab2aef923b3a478bb
Merge branch 'dev_20191114' of http://git.vipzhuang.cn/wxd/MShopWeApp into dev_20191114
Showing
2 changed files
with
286 additions
and
1 deletions
pages/user/Detailed/Detailed.js
| ... | ... | @@ -25,6 +25,11 @@ Page({ |
| 25 | 25 | * 生命周期函数--监听页面加载 |
| 26 | 26 | */ |
| 27 | 27 | onLoad: function(options) { |
| 28 | + var img_money = url + "/miniapp/images/plus/share/money.png"; | |
| 29 | + var img_Ancrown = url + "/miniapp/images/plus/share/Ancrown.png"; | |
| 30 | + var img_Identification = url + "/miniapp/images/plus/share/Identification.png"; | |
| 31 | + var img_square = url + "/miniapp/images/plus/share/square.png"; | |
| 32 | + var privilege_o = url + "/miniapp/images/plus/share/privilege_o.png"; | |
| 28 | 33 | |
| 29 | 34 | }, |
| 30 | 35 | selectDetailed: function() { |
| ... | ... | @@ -83,5 +88,245 @@ Page({ |
| 83 | 88 | return |
| 84 | 89 | }; |
| 85 | 90 | this.selectDetailed(); |
| 86 | - } | |
| 91 | + }, | |
| 92 | + | |
| 93 | + | |
| 94 | + saveImageToPhotosAlbum: function () { | |
| 95 | + if (this.data.imagePath != "") { | |
| 96 | + wx.previewImage({ | |
| 97 | + urls: [this.data.imagePath], | |
| 98 | + }) | |
| 99 | + return; | |
| 100 | + } | |
| 101 | + // if(this.data.is_loading) return false ; | |
| 102 | + this.data.is_loading=1; | |
| 103 | + | |
| 104 | + wx.showLoading({ | |
| 105 | + title: '生成中...', | |
| 106 | + }) | |
| 107 | + | |
| 108 | + this.setData({ | |
| 109 | + canvasHidden: false | |
| 110 | + }) | |
| 111 | + | |
| 112 | + var th = this; | |
| 113 | + //设置画板显示,才能开始绘图 | |
| 114 | + var card_ming=th.data.bas_ming;//卡的图片 | |
| 115 | + var user = th.data.user;//会员资料; | |
| 116 | + var big_card= th.data.big_card;//获取最大的卡 | |
| 117 | + var user_head = th.data.head_pic;//会员头像 | |
| 118 | + var img_money = th.data.img_money;//缓存vip的价格 | |
| 119 | + var img_Ancrown = th.data.img_Ancrown;//会员权益的图片 | |
| 120 | + var img_Identification = th.data.img_Identification;//会员标识 | |
| 121 | + var privilege_o = th.data.privilege_o;//勋章图片 | |
| 122 | + var img_square=th.data.img_square; | |
| 123 | + | |
| 124 | + var app = getApp(); | |
| 125 | + var unit = th.data.screenWidth / 750 * 1.35; | |
| 126 | + var scene = getApp().globalData.user_id; | |
| 127 | + console.log("用户头像", th.data.head_pic); | |
| 128 | + ///二微码 | |
| 129 | + | |
| 130 | + var path3 = os.url + "/api/wx/open/app/user/getWeAppEwm/" + | |
| 131 | + os.stoid + "?sceneValue=" + scene + "&pageValue=pages/user/index/index"; | |
| 132 | + wx.getImageInfo({ | |
| 133 | + src: path3, | |
| 134 | + success: function (res) { | |
| 135 | + //回调写法 | |
| 136 | + th.get_head_temp(th.get_goods_temp, function () { | |
| 137 | + var vpath=res.path; | |
| 138 | + | |
| 139 | + console.log("生成二维码", path3); | |
| 140 | + //开启画布 | |
| 141 | + const ctx = wx.createCanvasContext('myCanvas'); | |
| 142 | + | |
| 143 | + //先画背景 | |
| 144 | + ctx.drawImage("../../../images/plus/share/mackground.png", 0, 0, 554 * unit, 930 * unit); | |
| 145 | + ctx.setFontSize(26 * unit); | |
| 146 | + ctx.setFillStyle("rgb(0,0,0)"); | |
| 147 | + ctx.fillText(user.nickname, 155 * unit, 75 * unit, 200 * unit); | |
| 148 | + | |
| 149 | + var tj_path = "../../../images/userinfo/q_tj.png"; | |
| 150 | + ctx.drawImage(tj_path, 385 * unit, 45 * unit, 90 * unit, 30 * unit); | |
| 151 | + ctx.setFontSize(18 * unit); | |
| 152 | + ctx.setFillStyle("rgb(255,255,255)"); | |
| 153 | + ctx.fillText("强烈推荐", 394 * unit, 65 * unit); | |
| 154 | + | |
| 155 | + ctx.setStrokeStyle("rgb(255,255,255)"); | |
| 156 | + ctx.setLineDash([5 * unit, 5 * unit], 5 * unit); | |
| 157 | + ctx.beginPath(); | |
| 158 | + ctx.moveTo(0, 125 * unit); | |
| 159 | + ctx.lineTo(554 * unit, 125 * unit); | |
| 160 | + ctx.stroke(); | |
| 161 | + | |
| 162 | + var x = 55 * unit, y = 165 * unit,w = 444 * unit, h = 220 * unit,r = 14 * unit; | |
| 163 | + ut.draw_randon_rect(ctx,x,y,r,w,h); | |
| 164 | + ctx.clip(); //画了圆 再剪切 原始画布中剪切任意形状和尺寸。一旦剪切了某个区域,则所有之后的绘图都会被限制在被剪切的区域内 | |
| 165 | + ctx.drawImage(card_ming, x, y, 444 * unit, 220 * unit); // 推进去图片 | |
| 166 | + ctx.restore(); //恢复之前保存的绘图上下文 恢复之前保存的绘图上下午即状态 可以继续绘制 | |
| 167 | + | |
| 168 | + ctx.beginPath(); | |
| 169 | + // 卡图片 | |
| 170 | + // ctx.drawImage("../../../images/plus/share/one.jpg", 55 * unit, 165 * unit, 444 * unit, 220 * unit,); | |
| 171 | + ctx.setFontSize(26 * unit); | |
| 172 | + ctx.setFillStyle('rgb(218,194,169)'); | |
| 173 | + ctx.fillText(big_card.CardName, 80 * unit, 215 * unit); | |
| 174 | + ctx.setFontSize(18 * unit); | |
| 175 | + ctx.setFillStyle('rgb(218,194,169)'); | |
| 176 | + ctx.fillText("开通会员年卡仅" + big_card.CardFee+"元", 80 * unit, 240 * unit); | |
| 177 | + | |
| 178 | + ctx.drawImage(privilege_o, 80 * unit, 343 * unit, 20 * unit, 20 * unit); | |
| 179 | + | |
| 180 | + ctx.setFontSize(14 * unit); | |
| 181 | + ctx.setFillStyle('rgb(218,194,169)'); | |
| 182 | + ctx.fillText("根据大家购买数据,您成为超级会员预计可省¥3031元", 105 * unit, 360 * unit); | |
| 183 | + | |
| 184 | + ctx.rect(70 * unit, 425 * unit, 182 * unit, 1 * unit); | |
| 185 | + ctx.setFillStyle('rgb(218,194,169)'); | |
| 186 | + ctx.fill(); | |
| 187 | + | |
| 188 | + ctx.drawImage(img_square, 267 * unit, 420 * unit, 13 * unit, 13 * unit); | |
| 189 | + | |
| 190 | + ctx.beginPath(); | |
| 191 | + ctx.rect(295 * unit, 425 * unit, 182 * unit, 1 * unit); | |
| 192 | + ctx.setFillStyle('rgb(218,194,169)'); | |
| 193 | + ctx.fill(); | |
| 194 | + | |
| 195 | + ctx.drawImage(img_square, 80 * unit, 470 * unit, 10 * unit, 10 * unit); | |
| 196 | + ctx.setFontSize(24 * unit); | |
| 197 | + ctx.setFillStyle("rgb(198,165,126)"); | |
| 198 | + ctx.fillText("超级VIP权益", 100 * unit, 475 * unit); | |
| 199 | + | |
| 200 | + ctx.setFontSize(20 * unit); | |
| 201 | + ctx.setFillStyle("rgb(198,165,126)"); | |
| 202 | + ctx.fillText("超级会员专属权益", 100 * unit, 505 * unit); | |
| 203 | + ctx.drawImage(img_Ancrown, 355 * unit, 440 * unit, 65 * unit, 65 * unit); | |
| 204 | + | |
| 205 | + ctx.rect(85 * unit, 530 * unit, 375 * unit, 1 * unit) | |
| 206 | + ctx.setFillStyle('rgb(218,194,169)') | |
| 207 | + ctx.fill(); | |
| 208 | + | |
| 209 | + ctx.drawImage(img_square, 80 * unit, 575 * unit, 10 * unit, 10 * unit); | |
| 210 | + ctx.setFontSize(24 * unit); | |
| 211 | + ctx.setFillStyle("rgb(198,165,126)"); | |
| 212 | + ctx.fillText("超级VIP标识", 100 * unit, 580 * unit); | |
| 213 | + | |
| 214 | + ctx.setFontSize(20 * unit); | |
| 215 | + ctx.setFillStyle("rgb(198,165,126)"); | |
| 216 | + ctx.fillText("彰显尊贵身份的象征", 100 * unit, 610 * unit); | |
| 217 | + ctx.drawImage(img_Identification, 355 * unit, 548 * unit, 65 * unit, 65 * unit); | |
| 218 | + | |
| 219 | + ctx.rect(85 * unit, 635 * unit, 375 * unit, 1 * unit); | |
| 220 | + ctx.setFillStyle('rgb(218,194,169)'); | |
| 221 | + ctx.fill(); | |
| 222 | + | |
| 223 | + ctx.drawImage(img_square, 80 * unit, 695 * unit, 10 * unit, 10 * unit); | |
| 224 | + ctx.setFontSize(24 * unit); | |
| 225 | + ctx.setFillStyle("rgb(198,165,126)"); | |
| 226 | + ctx.fillText("超级VIP价格", 100 * unit, 695 * unit); | |
| 227 | + | |
| 228 | + ctx.setFontSize(20 * unit); | |
| 229 | + ctx.setFillStyle("rgb(198,165,126)"); | |
| 230 | + ctx.fillText("享受专属会员超低价", 100 * unit, 725 * unit); | |
| 231 | + ctx.drawImage(img_money, 355 * unit, 660 * unit, 65 * unit, 65 * unit); | |
| 232 | + | |
| 233 | + ctx.rect(85 * unit, 750 * unit, 375 * unit, 1 * unit) | |
| 234 | + ctx.setFillStyle('rgb(218,194,169)') | |
| 235 | + ctx.fill(); | |
| 236 | + | |
| 237 | + ctx.drawImage(vpath, 100 * unit, 780 * unit, 110 * unit, 110 * unit); | |
| 238 | + | |
| 239 | + ctx.setFontSize(20 * unit); | |
| 240 | + ctx.setFillStyle("#000"); | |
| 241 | + ctx.fillText("解锁新权益 精彩享不停", 230 * unit, 825 * unit); | |
| 242 | + | |
| 243 | + ctx.setFontSize(20 * unit); | |
| 244 | + ctx.setFillStyle("#000"); | |
| 245 | + ctx.fillText("长按识别二维码,立即开通!", 230 * unit, 865 * unit); | |
| 246 | + | |
| 247 | + //---绘制圆形要放在最后---- | |
| 248 | + ctx.save(); | |
| 249 | + ctx.beginPath(); | |
| 250 | + var h_x = 60 * unit; | |
| 251 | + var h_y = 24 * unit; | |
| 252 | + var h_r = 40 * unit; | |
| 253 | + var cx = h_x + h_r; | |
| 254 | + var cy = h_y + h_r; | |
| 255 | + ctx.arc(cx, cy, h_r, 0, Math.PI * 2, false); | |
| 256 | + ctx.closePath(); | |
| 257 | + ctx.fill(); | |
| 258 | + ctx.clip(); | |
| 259 | + ctx.drawImage(th.data.head_pic, h_x, h_y, h_r * 2, h_r * 2); | |
| 260 | + ctx.restore(); | |
| 261 | + | |
| 262 | + x = 345 * unit, | |
| 263 | + y = 190 * unit, | |
| 264 | + w = 105 * unit, | |
| 265 | + h = 30 * unit, | |
| 266 | + r = 14 * unit; | |
| 267 | + ut.draw_randon_rect(ctx,x,y,r,w,h); | |
| 268 | + ctx.setFontSize(18 * unit); | |
| 269 | + ctx.setFillStyle("#000"); | |
| 270 | + ctx.fillText("立即开通", 362 * unit, 212 * unit); | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + //绘制图片 | |
| 275 | + ctx.draw(false, | |
| 276 | + | |
| 277 | + function(){ | |
| 278 | + | |
| 279 | + setTimeout(function(){ | |
| 280 | + wx.canvasToTempFilePath({ | |
| 281 | + x: 0, | |
| 282 | + y: 0, | |
| 283 | + width: 750, | |
| 284 | + height: 930, | |
| 285 | + destWidth: 1.2 * 750 * 750 / th.data.screenWidth, | |
| 286 | + destHeight: 1.2 * 1217 * 750 / th.data.screenWidth, | |
| 287 | + canvasId: 'myCanvas', | |
| 288 | + success: function (res) { | |
| 289 | + wx.hideLoading();//关闭生成中的方法 | |
| 290 | + th.data.is_loading = 0; | |
| 291 | + console.log("生成的海报"); | |
| 292 | + console.log(res.tempFilePath); | |
| 293 | + var tempFilePath = res.tempFilePath; | |
| 294 | + th.setData({ | |
| 295 | + imagePath: tempFilePath, | |
| 296 | + maskHidden: false, | |
| 297 | + canvasHidden: true | |
| 298 | + }); | |
| 299 | + wx.previewImage({ | |
| 300 | + urls: [res.tempFilePath], | |
| 301 | + }) | |
| 302 | + if (!res.tempFilePath) { | |
| 303 | + wx.showModal({ | |
| 304 | + title: '提示', | |
| 305 | + content: '图片绘制中,请稍后重试', | |
| 306 | + showCancel: false | |
| 307 | + }) | |
| 308 | + } | |
| 309 | + | |
| 310 | + } | |
| 311 | + | |
| 312 | + }) | |
| 313 | + },500) | |
| 314 | + | |
| 315 | + | |
| 316 | + } | |
| 317 | + ) | |
| 318 | + | |
| 319 | + | |
| 320 | + }) | |
| 321 | + } | |
| 322 | + }) | |
| 323 | + | |
| 324 | + }, | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 87 | 332 | }) |
| 88 | 333 | \ No newline at end of file | ... | ... |
utils/util.js
| ... | ... | @@ -258,6 +258,46 @@ function get_rand_item(arr){ |
| 258 | 258 | return arr[ind]; |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | + | |
| 262 | +//画布画椭圆矩形 | |
| 263 | +function draw_randon_rect(ctx,x,y,r,w,h){ | |
| 264 | + ctx.save(); | |
| 265 | + // 开始绘制 | |
| 266 | + ctx.beginPath(); | |
| 267 | + // 因为边缘描边存在锯齿,最好指定使用 transparent 填充 | |
| 268 | + // 这里是使用 fill 还是 stroke都可以,二选一即可 | |
| 269 | + ctx.setFillStyle('rgb(237,188,150)') | |
| 270 | + // ctx.setStrokeStyle('transparent') | |
| 271 | + // 左上角 | |
| 272 | + ctx.arc(x + r, y + r, r, Math.PI, Math.PI * 1.5) | |
| 273 | + | |
| 274 | + // border-top | |
| 275 | + ctx.moveTo(x + r, y) | |
| 276 | + ctx.lineTo(x + w - r, y) | |
| 277 | + ctx.lineTo(x + w, y + r) | |
| 278 | + // 右上角 | |
| 279 | + ctx.arc(x + w - r, y + r, r, Math.PI * 1.5, Math.PI * 2) | |
| 280 | + | |
| 281 | + // border-right | |
| 282 | + ctx.lineTo(x + w, y + h - r) | |
| 283 | + ctx.lineTo(x + w - r, y + h) | |
| 284 | + // 右下角 | |
| 285 | + ctx.arc(x + w - r, y + h - r, r, 0, Math.PI * 0.5) | |
| 286 | + | |
| 287 | + // border-bottom | |
| 288 | + ctx.lineTo(x + r, y + h) | |
| 289 | + ctx.lineTo(x, y + h - r) | |
| 290 | + // 左下角 | |
| 291 | + ctx.arc(x + r, y + h - r, r, Math.PI * 0.5, Math.PI) | |
| 292 | + | |
| 293 | + // border-left | |
| 294 | + ctx.lineTo(x, y + r) | |
| 295 | + ctx.lineTo(x + r, y) | |
| 296 | + // 这里是使用 fill 还是 stroke都可以,二选一即可,但是需要与上面对应 | |
| 297 | + ctx.fill(); | |
| 298 | + | |
| 299 | +} | |
| 300 | + | |
| 261 | 301 | module.exports = { |
| 262 | 302 | formatTime: function(e, r) { |
| 263 | 303 | var t = e ? new Date(1e3 * e) : new Date(), n = t.getFullYear(), o = t.getMonth() + 1, a = t.getDate(), u = t.getHours(), i = t.getMinutes(), f = t.getSeconds(), s = function(e) { | ... | ... |