| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521 |
- import common from '../../utils/util';
- import main from '../../utils/main';
- const app = getApp();
- var innerAudioContext1;
- Page({
- data: {
- IPhoneX: "",
- IsPlay: false,
- Info:{
- ButtonString:"查看详细信息"
- },
- },
- onReady: function () {
- var that = this;
- innerAudioContext1 = wx.createInnerAudioContext();
- innerAudioContext1.onPlay(() => {
- console.log('开始播放');
- });
- innerAudioContext1.onEnded(() => {
- console.log('停止播放');
- that.playSound();
- });
- innerAudioContext1.onError((res) => {
- console.log("innerAudioContext1.errMsg:" + res.errMsg);
- console.log("innerAudioContext1.errCode:" + res.errCode);
- main.getBaiduToken();
- that.setData({
- IsPlay: false,
- });
- });
- },
- onLoad: function (options) {
- var that = this;
- var ishistory = 0;
- if (options.IsHistory)
- ishistory = 1;
- that.setData({
- Containnerheight: main.getWindowHeight(),
- IsHistory: ishistory,
- IsBuildReport: false,
- IsBuildReportHistory: false,
- });
- that.init(options.TaskID, ishistory);
- },
- onUnload: function () {
- if (innerAudioContext1) {
- innerAudioContext1.stop();
- }
- },
- init: function (taskid, isHistory) {
- var that = this;
- wx.showLoading({
- title: '读取中',
- });
- var url = 'GetShareItemInfo?IsShow='+app.globalData.userInfo.isShow+'&IsHistory=' + isHistory + '&UserID=' + app.globalData.userInfo.UserID + "&TaskID=" + taskid;
- main.getData(url, function (data) {
- wx.hideLoading();
- if (!data.MilestoneDayNumber && !that.data.IsHistory && data.Remark)
- data.Remark=data.Remark.split("\n");
- that.setData({
- Info: data,
- });
- if (that.data.IsHistory) {
- that.setData({
- Avatar: app.globalData.userInfo.AvatarUrl,
- NickName: app.globalData.userInfo.NickName,
- BgColor: main.getShareImageBackColor(),
- });
- }
- });
- if (app.globalData.IsIPhoneX) {
- that.setData({
- IPhoneX: "_IPhoneX",
- });
- }
- //如果没有生成过二维码,则生成
- if (!app.globalData.userInfo.HasACode) {
- var imageQRCode = "BuildMiaoguoQRCode?IsWeb=1&UserID=" + app.globalData.userInfo.UserID;
- main.getData(imageQRCode, function (data) {});
- app.globalData.userInfo.HasACode = 1;
- }
- },
- showImageSource: function (e) {
- var name = e.currentTarget.dataset.image;
- name = name.replace("_b_", "_a_");
- wx.previewImage({
- current: name,
- urls: [name],
- });
- },
- playSound: function () {
- var that = this;
- that.data.IsPlay = !that.data.IsPlay;
- that.setData({
- IsPlay: that.data.IsPlay,
- });
- if (that.data.IsPlay) {
- var str = "练习之后小歇片刻,名言美景沁人心脾。\n";
- str += "小朋友,你好。今天是你第"+that.data.Info.DayNumber+"天练习,第"+that.data.Info.HardworkingNumber+"次接力。\n";
- str += "练习辛苦了。\n";
- str += "今天来给你打气的是【" + that.data.Info.AuthorCn + "】\n";
- str += "他要对你说:\n";
- str += that.data.Info.Content + "\n";
- if (that.data.Info.Paraphrase){
- str += "这句古文的意思是【"+that.data.Info.Paraphrase + "】";
- }
- str += that.data.Info.AuthorCn + "是谁?";
- str += "他是" + that.data.Info.Country + "的" + that.data.Info.Title + "。\n";
- str += "有兴趣的小朋友,可以了解一下他的故事。我们下次接力再见。";
- var url = app.globalData.audioUrlBaidu;
- url = url.replace("[token]", app.globalData.BaiduToken);
- url = url.replace("[word]", str);
- url = url.replace("spd=3", "spd=5");
- url = encodeURI(url);
- wx.showLoading({
- title: '音频下载中',
- mask: true,
- });
- var timeout = setTimeout(function () {
- wx.hideLoading();
- }, 30000);
- //console.log(url);
- wx.downloadFile({
- url: url,
- success(res) {
- wx.hideLoading();
- clearTimeout(timeout);
- innerAudioContext1.src = res.tempFilePath;
- innerAudioContext1.play();
- },
- fail(err) {
- wx.hideLoading();
- }
- });
- } else {
- if (innerAudioContext1)
- innerAudioContext1.stop();
- }
- },
- //生成里程碑图片
- buildShareImageMilestone: function () {
- var that = this;
- that.setData({
- IsBuildReport: true,
- });
- var url1 = that.data.Info.MilestoneImage;
- var url3 = app.globalData.userInfo.AvatarUrl;
- if (url3=="../images/universalpic_face_default_blue_120x120.png")
- url3="https://miaguo-1253256735.file.myqcloud.com/web/universalpic_face_default_blue_120x120.png";
- var _uid = common.Encrypt(app.globalData.userInfo.UserID);
- if (_uid.indexOf("/") >= 0)
- _uid = common.ReplaceAllString(_uid, "/", "___");
- if (_uid.indexOf("+") >= 0)
- _uid = _uid.replace("+", "___");
- var url4 = app.globalData.uploadImageUrl + "MiaoguoUser" + _uid + ".png";
- wx.showLoading({
- title: '生成中',
- });
- setTimeout(function () {
- wx.hideLoading();
- }, 20000);
- // console.log(url1);
- // console.log(url3);
- // console.log(url4);
- main.DownloadFile(url1,0,function (tempFilePath1) {
- main.DownloadFile(url3,0,function (tempFilePath3) {
- main.DownloadFile(url4,0,function (tempFilePath4) {
- const query = wx.createSelectorQuery();
- query.select('#shareCanvas')
- .fields({
- node: true,
- size: true
- })
- .exec((res) => {
- const canvas = res[0].node;
- const ctx = canvas.getContext('2d');
- const dpr = wx.getSystemInfoSync().pixelRatio;
- canvas.width = res[0].width * dpr;
- canvas.height = res[0].height * dpr;
- ctx.scale(dpr, dpr);
- var img = canvas.createImage();
- img.src = tempFilePath1;
- img.onload = e => {
- ctx.drawImage(img, 0, 0, 700, 1050);
- };
- setTimeout(function(){
- ctx.fillStyle = "#ffffff";
- ctx.shadowBlur=4;
- ctx.shadowOffsetY=2;
- ctx.shadowColor="rgba(0,0,0,0.3)";
- ctx.fillRect(570, 70, 90, 90);
-
- var img3 = canvas.createImage();
- img3.src = tempFilePath3;
- img3.onload = e => {
- ctx.drawImage(img3, 575, 75, 80, 80);
- };
- var img4 = canvas.createImage();
- img4.src = tempFilePath4;
- img4.onload = e => {
- ctx.drawImage(img4, 530, 880, 140, 140);
- };
- ctx.fillStyle = "#f2f2f2";
- ctx.font = "normal 500 24px caption";
- ctx.fillText(that.data.Info.Content1, 56, 650);
- ctx.fillText(that.data.Info.Content2, 56, 683);
- ctx.fillText(that.data.Info.Content3, 56, 716);
-
- ctx.fillStyle = "#4d4d4d";
- ctx.font = "normal 500 16px caption";
- ctx.shadowBlur=0;
- ctx.shadowOffsetY=0;
- for(var i=0;i< that.data.Info.Content.length;i++)
- ctx.fillText(that.data.Info.Content[i], 50, 917+i*30);
-
- main.BuildImage(700, 1050, canvas, function () {
-
- wx.hideLoading();
- var createTime=that.data.Info.CreateTimeStr1;
- if (createTime.indexOf(".")>0)
- createTime=common.ReplaceAllString(createTime,".","-");
- main.getData("ShareMiaoguoTask?UserID=" + app.globalData.userInfo.UserID+"&CreateTime="+createTime, function (data) {
- that.setData({
- IsBuildReport: false,
- });
- });
- });
- },500);
- });
- });
- });
- });
- },
- //生成图片
- buildShareImage: function () {
- var that = this;
- that.setData({
- IsBuildReport: true,
- });
- var url1 = that.data.Info.Image.replace("_b_", "_d_");
- var url2 = that.data.Info.WordImage;
- var url3 = app.globalData.userInfo.AvatarUrl;
- if (url3=="../images/universalpic_face_default_blue_120x120.png")
- url3="https://miaguo-1253256735.file.myqcloud.com/web/universalpic_face_default_blue_120x120.png";
- debugger;
- var _uid = common.Encrypt(app.globalData.userInfo.UserID);
- if (_uid.indexOf("/") >= 0)
- _uid = common.ReplaceAllString(_uid, "/", "___");
- if (_uid.indexOf("+") >= 0)
- _uid = _uid.replace("+", "___");
- var url4 = app.globalData.uploadImageUrl + "MiaoguoUser" + _uid + ".png";
- wx.showLoading({
- title: '生成中',
- });
- setTimeout(function () {
- wx.hideLoading();
- }, 20000);
- // console.log(url1);
- // console.log(url2);
- // console.log(url3);
- // console.log(url4);
- main.DownloadFile(url1,0,function (tempFilePath1) {
- main.DownloadFile(url2,0,function (tempFilePath2) {
- main.DownloadFile(url3,0,function (tempFilePath3) {
- main.DownloadFile(url4,0,function (tempFilePath4) {
- const query = wx.createSelectorQuery();
- query.select('#shareCanvas')
- .fields({
- node: true,
- size: true
- })
- .exec((res) => {
- const canvas = res[0].node;
- const ctx = canvas.getContext('2d');
- const dpr = wx.getSystemInfoSync().pixelRatio;
- canvas.width = res[0].width * dpr;
- canvas.height = res[0].height * dpr;
- ctx.scale(dpr, dpr);
- var img = canvas.createImage();
- img.src = tempFilePath1;
- img.onload = e => {
- ctx.drawImage(img, 0, 0, 700, 520);
- };
- var img2 = canvas.createImage();
- img2.src = tempFilePath2;
- img2.onload = e => {
- ctx.drawImage(img2, 0, 520, 700, 270);
- };
- ctx.fillStyle = "#ffffff";
- ctx.fillRect(0, 790, 700, 260);
- var img3 = canvas.createImage();
- img3.src = tempFilePath3;
- img3.onload = e => {
- ctx.drawImage(img3, 610, 807, 60, 60);
- var img5 = canvas.createImage();
- img5.src = "../../pages/images/promotion_face_circle.png";
- img5.onload = e => {
- ctx.drawImage(img5, 610, 807, 60, 60);
- };
- };
- var img4 = canvas.createImage();
- img4.src = tempFilePath4;
- img4.onload = e => {
- ctx.drawImage(img4, 530, 880, 140, 140);
- };
- ctx.fillStyle = "#4d4d4d";
- ctx.fillRect(30, 836, 560, 2);
- ctx.font = "normal 600 18px caption";
- ctx.fillText("我的「秒过」勤勉接力", 30, 866);
- ctx.font = "normal 600 18px caption";
- ctx.fillText("坚持练习", 30, 911);
- ctx.font = "normal 600 18px caption";
- ctx.fillText("天", 30, 1016);
- ctx.font = "normal 600 16px caption";
- ctx.fillText("勇敢挑战", 266, 934);
- ctx.font = "normal 600 16px caption";
- ctx.fillText("个知识点", 266, 998);
- ctx.font = "normal 600 16px caption";
- ctx.fillText("专注复习", 370, 934);
- ctx.font = "normal 600 16px caption";
- ctx.fillText("分钟", 370, 998);
- ctx.font = "normal 500 18px Roboto-Black";
- ctx.fillText(that.data.Info.CreateTimeStr1, 30, 823);
- ctx.font = "normal 500 96px Roboto-Black";
- ctx.fillText(that.data.Info.DayNumber, 30, 994);
- ctx.font = "normal 500 36px Roboto-Black";
- ctx.fillText(that.data.Info.CardTaskTotal, 266, 974);
- ctx.font = "normal 500 36px Roboto-Black";
- ctx.fillText(that.data.Info.DurationTotal, 370, 974);
- main.BuildImage(700, 1050, canvas, function () {
-
- wx.hideLoading();
- var createTime=that.data.Info.CreateTimeStr1;
- if (createTime.indexOf(".")>0){
- createTime=createTime.replace(".","-");
- createTime=createTime.replace(".","-");
- }
- main.getData("ShareMiaoguoTask?UserID=" + app.globalData.userInfo.UserID+"&CreateTime="+createTime, function (data) {
- that.setData({
- IsBuildReport: false,
- });
- });
- });
- });
- });
- });
- });
- });
- },
- //生成图片(历史)
- buildShareImageHistory: function () {
- var that = this;
- that.setData({
- IsBuildReportHistory: true,
- });
- var date = that.data.Info.CreateTimeStr1
- var todayTime = that.data.Info.DurationMinute;
- var dayNumber = that.data.Info.HardworkingNumber;
- var avatarUrl = app.globalData.userInfo.AvatarUrl;
- avatarUrl = avatarUrl.substring(0, avatarUrl.lastIndexOf("/") + 1);
- avatarUrl = avatarUrl + "0";
- wx.showLoading({
- title: '生成中',
- });
- setTimeout(function () {
- wx.hideLoading();
- }, 20000);
- main.DownloadFile(avatarUrl,0,function (tempFilePath) {
- const query = wx.createSelectorQuery();
- query.select('#shareCanvasHistory')
- .fields({
- node: true,
- size: true
- })
- .exec((res) => {
- const canvas = res[0].node;
- const ctx = canvas.getContext('2d');
- const dpr = wx.getSystemInfoSync().pixelRatio;
- canvas.width = res[0].width * dpr;
- canvas.height = res[0].height * dpr;
- ctx.scale(dpr, dpr);
- var img = canvas.createImage();
- img.src = tempFilePath;
- img.onerror = err => {
- console.log(err);
- };
- img.onload = e => {
- ctx.drawImage(img, 0, 0, 360, 360);
- var img2 = canvas.createImage();
- img2.src = "../images/universalpic_screenshot_jl_bgimage_360x360.png";
- img2.onload = e => {
- ctx.drawImage(img2, 0, 0, 360, 360);
- ctx.fillStyle = that.data.BgColor;
- ctx.fillRect(360, 0, 240, 360);
- ctx.fillStyle = "#ffffff";
- ctx.font = "normal 500 24px caption";
- ctx.fillText(app.globalData.userInfo.NickName, 30, 306);
- ctx.font = "normal 500 18px caption";
- ctx.fillText(date, 30, 335);
- ctx.font = "normal 500 20px caption";
- ctx.fillText("秒过学习", 390, 40);
- ctx.font = "normal 500 44px caption";
- ctx.fillText("勤勉接力", 390, 88);
- ctx.font = "normal 500 20px caption";
- ctx.fillText("见证成长", 390, 140);
- ctx.font = "normal 500 68px caption";
- if (!todayTime)
- todayTime = 0;
- ctx.fillText(todayTime, 390, 209);
- ctx.font = "normal 500 68px caption";
- var metrics = ctx.measureText(todayTime.toString());
- //console.log(JSON.stringify(metrics));
- var h = 209;
- if (app.globalData.IsIOS)
- h = 206;
- ctx.font = "normal 500 32px caption";
- ctx.fillText("分钟", 393 + Math.round(metrics.width), h);
- ctx.font = "normal 500 20px caption";
- ctx.fillText("迄今已接力", 390, 295);
- ctx.font = "normal 500 32px caption";
- ctx.fillText(dayNumber + "次", 390, 333);
- main.BuildImage(600, 360, canvas, function () {
- wx.hideLoading();
- that.setData({
- IsBuildReportHistory: false,
- });
- });
- };
- };
- });
- });
- },
- showHelpImage: function (e) {
- main.ShowHelpImage();
- },
- onShareAppMessage: function () {
- return {
- title: app.globalData.ShareTitle,
- path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
- imageUrl: app.globalData.ShareImage,
- }
- },
- })
|