海报制作,海报小程序,海报

  • I9_547815
    了解作者
  • 246.6KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-03-30 19:28
    上传日期
一款海波制作小程序源码,所有功能源码都有,除了里面用的海报模版是服务器上的,这个需要你自己去写。
海报制作-小程序.zip
内容介绍
var t = require("../../utils/util"), e = getApp(), a = wx.createCanvasContext("shareImg"); Page({ data: { hidden: !0, showMblog: !1, showImageDialog: !1, showTextDialog: !1, focus: !1, InputText: "", currentTmpl: 0, currentBg: 0, posterId: -1, categoryId: -1, templates: [], templateView: {}, templateIndex: 0, templateFontIndex: -1, templateFontText: "", templateImages: [], templateImageIndex: -1, canIUse: !1 }, canvasTextAutoLine: function(t, e, a, n, s, o) { var i = t.split(""), l = "", c = !0, r = !1, g = void 0; try { for (var d, h = i[Symbol.iterator](); !(c = (d = h.next()).done); c = !0) l += d.value, e.measureText(l).width > o && (e.fillText(l, a, n), l = "", n += s); } catch (t) { r = !0, g = t; } finally { try { !c && h.return && h.return(); } finally { if (r) throw g; } } l && e.fillText(l, a, n); }, onLoad: function(t) { var e = this; e.setData({ posterId: t.id, categoryId: t.cid }), e.fetchTempletes(), e.fetchImageList(function() { e.fetchTemplateDetail(); }); }, loadFontFace: function() { wx.loadFontFace({ family: "ygywgt", source: 'url("https://cdns.mtscrm.com/mtscrm/hb/fonts/ygywgt.ttf")', success: function(t) { console.log(t.status); }, fail: function(t) { console.log(t.status); }, complete: function(t) { console.log(t.status); } }); }, handlerOpenSetting: function(t) { var e = this; t.detail.authSetting["scope.writePhotosAlbum"] ? e.setData({ canIUse: !1, hidden: !1 }) : e.setData({ canIUse: !0 }); }, fetchTempletes: function() { var a = this; a.showLoading(), t.ajax({ url: e.globalData.baseApiUrl + "/admin/poster/list?categoryId=" + a.data.categoryId, header: { "Content-Type": "application/json" }, method: "GET", complete: function() { wx.hideLoading(); }, success: function(t) { for (var e = t.data.data, n = e.length, s = -1, o = 0; o < n; o++) e[o].id == a.data.posterId && (s = o); a.setData({ templates: e, templateIndex: s }); } }, !0); }, fetchTemplateDetail: function() { var a = this; a.showLoading(), t.ajax({ url: e.globalData.baseApiUrl + "/admin/poster/detail?posterId=" + a.data.posterId, header: { "Content-Type": "application/json" }, method: "GET", complete: function() { wx.hideLoading(); }, success: function(t) { var e = t.data.data; a.setData({ templateView: e }), a.changeImageIndex(); } }, !0); }, fetchImageList: function(a) { var n = this; t.ajax({ url: e.globalData.baseApiUrl + "/admin/poster/bgImglist?categoryId=" + n.data.categoryId, header: { "Content-Type": "application/json" }, method: "GET", success: function(t) { var e = t.data.data; n.setData({ templateImages: e }), a && a(); } }); }, handTemplateChange: function(t) { var e = this, a = t.currentTarget.dataset.index; if (this.data.templateIndex == a) return !1; var n = this.data.templates[a]; this.setData({ posterId: n.id, templateIndex: a }), e.fetchTemplateDetail(); }, changeImageIndex: function() { for (var t = this.data.templateImages, e = t.length, a = this.data.templateView.bgImgId, n = -1, s = 0; s < e; s++) t[s].id == a && (n = s); this.setData({ templateImageIndex: n }); }, getImageInfo: function(t, e) { wx.getImageInfo({ src: t, success: function(t) { e && e(t.path); } }); }, canvasDrawImage: function() { var t = this, e = this.data.templateView.bgImgUrl, n = this.data.templateView.bgBoxImgUrl, s = "", o = ""; wx.showLoading({ title: "努力生成中..." }), t.getImageInfo(e, function(e) { s = e, t.getImageInfo(n, function(e) { o = e, a.drawImage("../../images/mb-bg.jpg", 0, 0, 750, 1140), a.drawImage(s, 0, 0, 750, 1e3), a.drawImage(o, 0, 0, 750, 1e3); for (var n = t.data.templateView.texts.length, i = 0; i < n; i++) { var l = t.data.templateView.texts[i], c = t.getValue(l.adfontstyle, "text-align"), r = Number(t.getValue(l.adfontstyle, "font-size")); a.setTextAlign(c), a.setTextBaseline("top"), a.setFillStyle(t.getValue(l.adfontstyle, "color")), a.setFontSize(r); var g = Number(t.getValue(l.adfontstyle, "left")), d = Number(t.getValue(l.adfontstyle, "top")), h = (Number(t.getValue(l.adfontstyle, "height")), Number(t.getValue(l.adfontstyle, "width"))); "center" == c ? g += h / 2 : "right" == c && (g += h), t.canvasTextAutoLine(l.fonttext, a, g, d, 1.3 * r, h - 20); } a.stroke(), a.draw(!1, function() { setTimeout(function() { wx.canvasToTempFilePath({ x: 0, y: 0, width: 750, height: 1140, destWidth: 750, destHeight: 1140, canvasId: "shareImg", success: function(e) { console.log(e.tempFilePath), t.setData({ prurl: e.tempFilePath, hidden: !1 }), wx.hideLoading(); }, fail: function(t) { console.error(t); } }); }, 1e3); }); }); }); }, getValue: function(t, e) { var a = t.substr(t.indexOf(e) + (e.length + 1)), n = a.indexOf(";"); return a.substr(0, n).replace("rpx", ""); }, handChangeItemText: function(t) { var e = t.currentTarget.dataset.findex, a = this.data.templateView.texts[e].fonttext; this.setData({ focus: !0, showTextDialog: !1, changeTextDialog: !0, templateFontText: a, templateFontIndex: e }); }, templateFontInputChange: function(t) { var e = this.data.templateView; e.texts[this.data.templateFontIndex].fonttext = t.detail.value, this.setData({ templateView: e }); }, handTemplateUpdate: function() { this.setData({ changeTextDialog: !1 }); }, handCloseTextDialog: function() { this.setData({ showTextDialog: !1 }); }, handImageChange: function(t) { var e = t.currentTarget.dataset.bg; if (this.data.templateImageIndex == e) return !1; var a = this.data.templateImages[e], n = this.data.templateV
评论
    相关推荐