shareitem.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const app = getApp();
  4. var innerAudioContext1;
  5. Page({
  6. data: {
  7. IPhoneX: "",
  8. IsPlay: false,
  9. Info:{
  10. ButtonString:"查看详细信息"
  11. },
  12. },
  13. onReady: function () {
  14. var that = this;
  15. innerAudioContext1 = wx.createInnerAudioContext();
  16. innerAudioContext1.onPlay(() => {
  17. console.log('开始播放');
  18. });
  19. innerAudioContext1.onEnded(() => {
  20. console.log('停止播放');
  21. that.playSound();
  22. });
  23. innerAudioContext1.onError((res) => {
  24. console.log("innerAudioContext1.errMsg:" + res.errMsg);
  25. console.log("innerAudioContext1.errCode:" + res.errCode);
  26. main.getBaiduToken();
  27. that.setData({
  28. IsPlay: false,
  29. });
  30. });
  31. },
  32. onLoad: function (options) {
  33. var that = this;
  34. var ishistory = 0;
  35. if (options.IsHistory)
  36. ishistory = 1;
  37. that.setData({
  38. Containnerheight: main.getWindowHeight(),
  39. IsHistory: ishistory,
  40. IsBuildReport: false,
  41. IsBuildReportHistory: false,
  42. });
  43. that.init(options.TaskID, ishistory);
  44. },
  45. onUnload: function () {
  46. if (innerAudioContext1) {
  47. innerAudioContext1.stop();
  48. }
  49. },
  50. init: function (taskid, isHistory) {
  51. var that = this;
  52. wx.showLoading({
  53. title: '读取中',
  54. });
  55. var url = 'GetShareItemInfo?IsShow='+app.globalData.userInfo.isShow+'&IsHistory=' + isHistory + '&UserID=' + app.globalData.userInfo.UserID + "&TaskID=" + taskid;
  56. main.getData(url, function (data) {
  57. wx.hideLoading();
  58. if (!data.MilestoneDayNumber && !that.data.IsHistory && data.Remark)
  59. data.Remark=data.Remark.split("\n");
  60. that.setData({
  61. Info: data,
  62. });
  63. if (that.data.IsHistory) {
  64. that.setData({
  65. Avatar: app.globalData.userInfo.AvatarUrl,
  66. NickName: app.globalData.userInfo.NickName,
  67. BgColor: main.getShareImageBackColor(),
  68. });
  69. }
  70. });
  71. if (app.globalData.IsIPhoneX) {
  72. that.setData({
  73. IPhoneX: "_IPhoneX",
  74. });
  75. }
  76. //如果没有生成过二维码,则生成
  77. if (!app.globalData.userInfo.HasACode) {
  78. var imageQRCode = "BuildMiaoguoQRCode?IsWeb=1&UserID=" + app.globalData.userInfo.UserID;
  79. main.getData(imageQRCode, function (data) {});
  80. app.globalData.userInfo.HasACode = 1;
  81. }
  82. },
  83. showImageSource: function (e) {
  84. var name = e.currentTarget.dataset.image;
  85. name = name.replace("_b_", "_a_");
  86. wx.previewImage({
  87. current: name,
  88. urls: [name],
  89. });
  90. },
  91. playSound: function () {
  92. var that = this;
  93. that.data.IsPlay = !that.data.IsPlay;
  94. that.setData({
  95. IsPlay: that.data.IsPlay,
  96. });
  97. if (that.data.IsPlay) {
  98. var str = "练习之后小歇片刻,名言美景沁人心脾。\n";
  99. str += "小朋友,你好。今天是你第"+that.data.Info.DayNumber+"天练习,第"+that.data.Info.HardworkingNumber+"次接力。\n";
  100. str += "练习辛苦了。\n";
  101. str += "今天来给你打气的是【" + that.data.Info.AuthorCn + "】\n";
  102. str += "他要对你说:\n";
  103. str += that.data.Info.Content + "\n";
  104. if (that.data.Info.Paraphrase){
  105. str += "这句古文的意思是【"+that.data.Info.Paraphrase + "】";
  106. }
  107. str += that.data.Info.AuthorCn + "是谁?";
  108. str += "他是" + that.data.Info.Country + "的" + that.data.Info.Title + "。\n";
  109. str += "有兴趣的小朋友,可以了解一下他的故事。我们下次接力再见。";
  110. var url = app.globalData.audioUrlBaidu;
  111. url = url.replace("[token]", app.globalData.BaiduToken);
  112. url = url.replace("[word]", str);
  113. url = url.replace("spd=3", "spd=5");
  114. url = encodeURI(url);
  115. wx.showLoading({
  116. title: '音频下载中',
  117. mask: true,
  118. });
  119. var timeout = setTimeout(function () {
  120. wx.hideLoading();
  121. }, 30000);
  122. //console.log(url);
  123. wx.downloadFile({
  124. url: url,
  125. success(res) {
  126. wx.hideLoading();
  127. clearTimeout(timeout);
  128. innerAudioContext1.src = res.tempFilePath;
  129. innerAudioContext1.play();
  130. },
  131. fail(err) {
  132. wx.hideLoading();
  133. }
  134. });
  135. } else {
  136. if (innerAudioContext1)
  137. innerAudioContext1.stop();
  138. }
  139. },
  140. //生成里程碑图片
  141. buildShareImageMilestone: function () {
  142. var that = this;
  143. that.setData({
  144. IsBuildReport: true,
  145. });
  146. var url1 = that.data.Info.MilestoneImage;
  147. var url3 = app.globalData.userInfo.AvatarUrl;
  148. if (url3=="../images/universalpic_face_default_blue_120x120.png")
  149. url3="https://miaguo-1253256735.file.myqcloud.com/web/universalpic_face_default_blue_120x120.png";
  150. var _uid = common.Encrypt(app.globalData.userInfo.UserID);
  151. if (_uid.indexOf("/") >= 0)
  152. _uid = common.ReplaceAllString(_uid, "/", "___");
  153. if (_uid.indexOf("+") >= 0)
  154. _uid = _uid.replace("+", "___");
  155. var url4 = app.globalData.uploadImageUrl + "MiaoguoUser" + _uid + ".png";
  156. wx.showLoading({
  157. title: '生成中',
  158. });
  159. setTimeout(function () {
  160. wx.hideLoading();
  161. }, 20000);
  162. // console.log(url1);
  163. // console.log(url3);
  164. // console.log(url4);
  165. main.DownloadFile(url1,0,function (tempFilePath1) {
  166. main.DownloadFile(url3,0,function (tempFilePath3) {
  167. main.DownloadFile(url4,0,function (tempFilePath4) {
  168. const query = wx.createSelectorQuery();
  169. query.select('#shareCanvas')
  170. .fields({
  171. node: true,
  172. size: true
  173. })
  174. .exec((res) => {
  175. const canvas = res[0].node;
  176. const ctx = canvas.getContext('2d');
  177. const dpr = wx.getSystemInfoSync().pixelRatio;
  178. canvas.width = res[0].width * dpr;
  179. canvas.height = res[0].height * dpr;
  180. ctx.scale(dpr, dpr);
  181. var img = canvas.createImage();
  182. img.src = tempFilePath1;
  183. img.onload = e => {
  184. ctx.drawImage(img, 0, 0, 700, 1050);
  185. };
  186. setTimeout(function(){
  187. ctx.fillStyle = "#ffffff";
  188. ctx.shadowBlur=4;
  189. ctx.shadowOffsetY=2;
  190. ctx.shadowColor="rgba(0,0,0,0.3)";
  191. ctx.fillRect(570, 70, 90, 90);
  192. var img3 = canvas.createImage();
  193. img3.src = tempFilePath3;
  194. img3.onload = e => {
  195. ctx.drawImage(img3, 575, 75, 80, 80);
  196. };
  197. var img4 = canvas.createImage();
  198. img4.src = tempFilePath4;
  199. img4.onload = e => {
  200. ctx.drawImage(img4, 530, 880, 140, 140);
  201. };
  202. ctx.fillStyle = "#f2f2f2";
  203. ctx.font = "normal 500 24px caption";
  204. ctx.fillText(that.data.Info.Content1, 56, 650);
  205. ctx.fillText(that.data.Info.Content2, 56, 683);
  206. ctx.fillText(that.data.Info.Content3, 56, 716);
  207. ctx.fillStyle = "#4d4d4d";
  208. ctx.font = "normal 500 16px caption";
  209. ctx.shadowBlur=0;
  210. ctx.shadowOffsetY=0;
  211. for(var i=0;i< that.data.Info.Content.length;i++)
  212. ctx.fillText(that.data.Info.Content[i], 50, 917+i*30);
  213. main.BuildImage(700, 1050, canvas, function () {
  214. wx.hideLoading();
  215. var createTime=that.data.Info.CreateTimeStr1;
  216. if (createTime.indexOf(".")>0)
  217. createTime=common.ReplaceAllString(createTime,".","-");
  218. main.getData("ShareMiaoguoTask?UserID=" + app.globalData.userInfo.UserID+"&CreateTime="+createTime, function (data) {
  219. that.setData({
  220. IsBuildReport: false,
  221. });
  222. });
  223. });
  224. },500);
  225. });
  226. });
  227. });
  228. });
  229. },
  230. //生成图片
  231. buildShareImage: function () {
  232. var that = this;
  233. that.setData({
  234. IsBuildReport: true,
  235. });
  236. var url1 = that.data.Info.Image.replace("_b_", "_d_");
  237. var url2 = that.data.Info.WordImage;
  238. var url3 = app.globalData.userInfo.AvatarUrl;
  239. if (url3=="../images/universalpic_face_default_blue_120x120.png")
  240. url3="https://miaguo-1253256735.file.myqcloud.com/web/universalpic_face_default_blue_120x120.png";
  241. debugger;
  242. var _uid = common.Encrypt(app.globalData.userInfo.UserID);
  243. if (_uid.indexOf("/") >= 0)
  244. _uid = common.ReplaceAllString(_uid, "/", "___");
  245. if (_uid.indexOf("+") >= 0)
  246. _uid = _uid.replace("+", "___");
  247. var url4 = app.globalData.uploadImageUrl + "MiaoguoUser" + _uid + ".png";
  248. wx.showLoading({
  249. title: '生成中',
  250. });
  251. setTimeout(function () {
  252. wx.hideLoading();
  253. }, 20000);
  254. // console.log(url1);
  255. // console.log(url2);
  256. // console.log(url3);
  257. // console.log(url4);
  258. main.DownloadFile(url1,0,function (tempFilePath1) {
  259. main.DownloadFile(url2,0,function (tempFilePath2) {
  260. main.DownloadFile(url3,0,function (tempFilePath3) {
  261. main.DownloadFile(url4,0,function (tempFilePath4) {
  262. const query = wx.createSelectorQuery();
  263. query.select('#shareCanvas')
  264. .fields({
  265. node: true,
  266. size: true
  267. })
  268. .exec((res) => {
  269. const canvas = res[0].node;
  270. const ctx = canvas.getContext('2d');
  271. const dpr = wx.getSystemInfoSync().pixelRatio;
  272. canvas.width = res[0].width * dpr;
  273. canvas.height = res[0].height * dpr;
  274. ctx.scale(dpr, dpr);
  275. var img = canvas.createImage();
  276. img.src = tempFilePath1;
  277. img.onload = e => {
  278. ctx.drawImage(img, 0, 0, 700, 520);
  279. };
  280. var img2 = canvas.createImage();
  281. img2.src = tempFilePath2;
  282. img2.onload = e => {
  283. ctx.drawImage(img2, 0, 520, 700, 270);
  284. };
  285. ctx.fillStyle = "#ffffff";
  286. ctx.fillRect(0, 790, 700, 260);
  287. var img3 = canvas.createImage();
  288. img3.src = tempFilePath3;
  289. img3.onload = e => {
  290. ctx.drawImage(img3, 610, 807, 60, 60);
  291. var img5 = canvas.createImage();
  292. img5.src = "../../pages/images/promotion_face_circle.png";
  293. img5.onload = e => {
  294. ctx.drawImage(img5, 610, 807, 60, 60);
  295. };
  296. };
  297. var img4 = canvas.createImage();
  298. img4.src = tempFilePath4;
  299. img4.onload = e => {
  300. ctx.drawImage(img4, 530, 880, 140, 140);
  301. };
  302. ctx.fillStyle = "#4d4d4d";
  303. ctx.fillRect(30, 836, 560, 2);
  304. ctx.font = "normal 600 18px caption";
  305. ctx.fillText("我的「秒过」勤勉接力", 30, 866);
  306. ctx.font = "normal 600 18px caption";
  307. ctx.fillText("坚持练习", 30, 911);
  308. ctx.font = "normal 600 18px caption";
  309. ctx.fillText("天", 30, 1016);
  310. ctx.font = "normal 600 16px caption";
  311. ctx.fillText("勇敢挑战", 266, 934);
  312. ctx.font = "normal 600 16px caption";
  313. ctx.fillText("个知识点", 266, 998);
  314. ctx.font = "normal 600 16px caption";
  315. ctx.fillText("专注复习", 370, 934);
  316. ctx.font = "normal 600 16px caption";
  317. ctx.fillText("分钟", 370, 998);
  318. ctx.font = "normal 500 18px Roboto-Black";
  319. ctx.fillText(that.data.Info.CreateTimeStr1, 30, 823);
  320. ctx.font = "normal 500 96px Roboto-Black";
  321. ctx.fillText(that.data.Info.DayNumber, 30, 994);
  322. ctx.font = "normal 500 36px Roboto-Black";
  323. ctx.fillText(that.data.Info.CardTaskTotal, 266, 974);
  324. ctx.font = "normal 500 36px Roboto-Black";
  325. ctx.fillText(that.data.Info.DurationTotal, 370, 974);
  326. main.BuildImage(700, 1050, canvas, function () {
  327. wx.hideLoading();
  328. var createTime=that.data.Info.CreateTimeStr1;
  329. if (createTime.indexOf(".")>0){
  330. createTime=createTime.replace(".","-");
  331. createTime=createTime.replace(".","-");
  332. }
  333. main.getData("ShareMiaoguoTask?UserID=" + app.globalData.userInfo.UserID+"&CreateTime="+createTime, function (data) {
  334. that.setData({
  335. IsBuildReport: false,
  336. });
  337. });
  338. });
  339. });
  340. });
  341. });
  342. });
  343. });
  344. },
  345. //生成图片(历史)
  346. buildShareImageHistory: function () {
  347. var that = this;
  348. that.setData({
  349. IsBuildReportHistory: true,
  350. });
  351. var date = that.data.Info.CreateTimeStr1
  352. var todayTime = that.data.Info.DurationMinute;
  353. var dayNumber = that.data.Info.HardworkingNumber;
  354. var avatarUrl = app.globalData.userInfo.AvatarUrl;
  355. avatarUrl = avatarUrl.substring(0, avatarUrl.lastIndexOf("/") + 1);
  356. avatarUrl = avatarUrl + "0";
  357. wx.showLoading({
  358. title: '生成中',
  359. });
  360. setTimeout(function () {
  361. wx.hideLoading();
  362. }, 20000);
  363. main.DownloadFile(avatarUrl,0,function (tempFilePath) {
  364. const query = wx.createSelectorQuery();
  365. query.select('#shareCanvasHistory')
  366. .fields({
  367. node: true,
  368. size: true
  369. })
  370. .exec((res) => {
  371. const canvas = res[0].node;
  372. const ctx = canvas.getContext('2d');
  373. const dpr = wx.getSystemInfoSync().pixelRatio;
  374. canvas.width = res[0].width * dpr;
  375. canvas.height = res[0].height * dpr;
  376. ctx.scale(dpr, dpr);
  377. var img = canvas.createImage();
  378. img.src = tempFilePath;
  379. img.onerror = err => {
  380. console.log(err);
  381. };
  382. img.onload = e => {
  383. ctx.drawImage(img, 0, 0, 360, 360);
  384. var img2 = canvas.createImage();
  385. img2.src = "../images/universalpic_screenshot_jl_bgimage_360x360.png";
  386. img2.onload = e => {
  387. ctx.drawImage(img2, 0, 0, 360, 360);
  388. ctx.fillStyle = that.data.BgColor;
  389. ctx.fillRect(360, 0, 240, 360);
  390. ctx.fillStyle = "#ffffff";
  391. ctx.font = "normal 500 24px caption";
  392. ctx.fillText(app.globalData.userInfo.NickName, 30, 306);
  393. ctx.font = "normal 500 18px caption";
  394. ctx.fillText(date, 30, 335);
  395. ctx.font = "normal 500 20px caption";
  396. ctx.fillText("秒过学习", 390, 40);
  397. ctx.font = "normal 500 44px caption";
  398. ctx.fillText("勤勉接力", 390, 88);
  399. ctx.font = "normal 500 20px caption";
  400. ctx.fillText("见证成长", 390, 140);
  401. ctx.font = "normal 500 68px caption";
  402. if (!todayTime)
  403. todayTime = 0;
  404. ctx.fillText(todayTime, 390, 209);
  405. ctx.font = "normal 500 68px caption";
  406. var metrics = ctx.measureText(todayTime.toString());
  407. //console.log(JSON.stringify(metrics));
  408. var h = 209;
  409. if (app.globalData.IsIOS)
  410. h = 206;
  411. ctx.font = "normal 500 32px caption";
  412. ctx.fillText("分钟", 393 + Math.round(metrics.width), h);
  413. ctx.font = "normal 500 20px caption";
  414. ctx.fillText("迄今已接力", 390, 295);
  415. ctx.font = "normal 500 32px caption";
  416. ctx.fillText(dayNumber + "次", 390, 333);
  417. main.BuildImage(600, 360, canvas, function () {
  418. wx.hideLoading();
  419. that.setData({
  420. IsBuildReportHistory: false,
  421. });
  422. });
  423. };
  424. };
  425. });
  426. });
  427. },
  428. showHelpImage: function (e) {
  429. main.ShowHelpImage();
  430. },
  431. onShareAppMessage: function () {
  432. return {
  433. title: app.globalData.ShareTitle,
  434. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  435. imageUrl: app.globalData.ShareImage,
  436. }
  437. },
  438. })