mbti-rengeceshi/components/shareBox/index.js

392 lines
13 KiB
JavaScript

var t = require("../../@babel/runtime/helpers/defineProperty");
Component({
properties: {
isCanDraw: {
type: Boolean,
value: !1,
observer: function(t, e) {
t && this.drawPic();
}
},
info: {
type: String,
value: !1,
observer: function(t, e) {
this.setData({
inf: t
});
}
},
vsA: {
type: Number,
value: !1,
observer: function(t, e) {
this.setData({
vsA1: 200 * t + "rpx"
});
}
},
vsB: {
type: Number,
value: !1,
observer: function(t, e) {
this.setData({
vsB1: 200 * t + "rpx"
});
}
},
vsC: {
type: Number,
value: !1,
observer: function(t, e) {
this.setData({
vsC1: 200 * t + "rpx"
});
}
},
vsD: {
type: Number,
value: !1,
observer: function(t, e) {
this.setData({
vsD1: 200 * t + "rpx"
});
}
},
pi: {
type: String,
value: !1,
observer: function(t, e) {
this.setData({
pic: "/img/" + t + ".jpg"
});
}
}
},
data: {
isModal: !1,
imgDraw: {},
sharePath: "",
visible: !1,
pic: ""
},
lifetimes: {
ready: function() {
console.log("@@", this.data.pic);
var t = this;
wx.compressImage({
src: "/img/jt.png",
quality: 36,
complete: function(e) {
console.log(e.tempFilePath), t.setData({
url1: e.tempFilePath
});
}
}), wx.compressImage({
src: t.data.pic,
quality: 36,
complete: function(e) {
console.log(e.tempFilePath), t.setData({
url2: e.tempFilePath
});
}
}), wx.compressImage({
src: "/img/mb.png",
quality: 36,
complete: function(e) {
console.log(e.tempFilePath), t.setData({
url4: e.tempFilePath
});
}
});
}
},
methods: {
handlePhotoSaved: function() {
this.savePhoto(this.data.sharePath);
},
handleClose: function() {
this.setData({
visible: !1
});
},
drawPic: function() {
if (this.data.sharePath) return this.setData({
visible: !0
}), void this.triggerEvent("initData");
wx.showLoading({
title: "报告生成中"
}), this.setData({
imgDraw: {
width: "750rpx",
height: "1334rpx",
background: this.data.url4,
views: [ {
type: "text",
text: "▎ 你好,测试报告如下:",
css: {
top: "276rpx",
fontSize: "32rpx",
left: "46rpx",
fontWeight: "bold",
color: "#7b92b7"
}
}, {
type: "text",
text: "E",
css: {
top: "344rpx",
fontSize: "28rpx",
left: "46rpx",
height: "30rpx"
}
}, {
type: "text",
text: "I",
css: {
top: "344rpx",
fontSize: "28rpx",
left: "290rpx",
height: "30rpx"
}
}, {
type: "rect",
css: {
borderRadius: "16rpx",
top: "346rpx",
fontSize: "28rpx",
left: "76rpx",
width: "200rpx",
height: "30rpx",
color: "#008000"
}
}, {
type: "rect",
css: t({
borderRadius: "16rpx",
top: "346rpx",
fontSize: "28rpx",
left: "76rpx",
width: this.data.vsA1,
height: "30rpx",
color: "#008000"
}, "color", "#FF0000")
}, {
type: "text",
text: "S",
css: {
top: "384rpx",
fontSize: "28rpx",
left: "46rpx",
height: "30rpx"
}
}, {
type: "text",
text: "N",
css: {
top: "384rpx",
fontSize: "28rpx",
left: "284rpx",
height: "30rpx"
}
}, {
type: "rect",
css: {
borderRadius: "16rpx",
top: "386rpx",
fontSize: "28rpx",
left: "76rpx",
width: "200rpx",
height: "30rpx",
color: "#008000"
}
}, {
type: "rect",
css: t({
borderRadius: "16rpx",
top: "386rpx",
fontSize: "28rpx",
left: "76rpx",
width: this.data.vsB1,
height: "30rpx",
color: "#008000"
}, "color", "#FF0000")
}, {
type: "text",
text: "T",
css: {
top: "424rpx",
fontSize: "28rpx",
left: "46rpx",
height: "30rpx"
}
}, {
type: "text",
text: "F",
css: {
top: "424rpx",
fontSize: "28rpx",
left: "286rpx",
height: "30rpx"
}
}, {
type: "rect",
css: {
borderRadius: "16rpx",
top: "426rpx",
fontSize: "28rpx",
left: "76rpx",
width: "200rpx",
height: "30rpx",
color: "#008000"
}
}, {
type: "rect",
css: t({
borderRadius: "16rpx",
top: "426rpx",
fontSize: "28rpx",
left: "76rpx",
width: this.data.vsC1,
height: "30rpx",
color: "#008000"
}, "color", "#FF0000")
}, {
type: "text",
text: "J",
css: {
top: "464rpx",
fontSize: "28rpx",
left: "46rpx",
height: "30rpx"
}
}, {
type: "text",
text: "P",
css: {
top: "464rpx",
fontSize: "28rpx",
left: "286rpx",
height: "30rpx"
}
}, {
type: "rect",
css: {
borderRadius: "16rpx",
top: "466rpx",
fontSize: "28rpx",
left: "76rpx",
width: "200rpx",
height: "30rpx",
color: "#008000"
}
}, {
type: "rect",
css: {
borderRadius: "16rpx",
top: "466rpx",
fontSize: "28rpx",
left: "76rpx",
width: this.data.vsD1,
height: "30rpx",
color: "#FF0000"
}
}, {
type: "image",
url: this.data.url1,
css: {
top: "366rpx",
fontSize: "28rpx",
left: "336rpx",
width: "100rpx",
height: "100rpx",
color: "#FF0000",
borderRadius: "16rpx"
}
}, {
type: "image",
url: this.data.url2,
css: {
top: "304rpx",
fontSize: "28rpx",
left: "466rpx",
width: "206rpx",
height: "206rpx",
color: "#FF0000",
borderRadius: "16rpx"
}
}, {
type: "text",
text: "▎ 该类型人格特点:",
css: {
top: "516rpx",
fontSize: "37rpx",
left: "46rpx",
fontWeight: "bold",
color: "#7b92b7"
}
}, {
type: "text",
text: " " + this.data.inf,
css: t({
top: "581rpx",
fontSize: "32rpx",
left: "56rpx",
fontWeight: "bold",
lineHeight: "56rpx",
width: "646rpx",
height: "620rpx"
}, "fontWeight", "lighter")
} ]
}
});
},
onImgErr: function(t) {
wx.hideLoading(), wx.showToast({
title: "生成分享图失败,请刷新页面重试"
});
},
onImgOK: function(t) {
wx.hideLoading(), this.setData({
sharePath: t.detail.path,
visible: !0
}), this.triggerEvent("initData");
},
preventDefault: function() {},
savePhoto: function(t) {
var e = this;
wx.showLoading({
title: "正在保存...",
mask: !0
}), this.setData({
isDrawImage: !1
}), wx.saveImageToPhotosAlbum({
filePath: t,
success: function(t) {
wx.showToast({
title: "保存成功",
icon: "none"
}), setTimeout(function() {
e.setData({
visible: !1
});
}, 300);
},
fail: function(t) {
wx.getSetting({
success: function(t) {
t.authSetting["scope.writePhotosAlbum"] || e.setData({
isModal: !0
});
}
}), setTimeout(function() {
wx.hideLoading(), e.setData({
visible: !1
});
}, 300);
}
});
}
}
});