index.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. // nova-werun/pages/home/share/index.js
  2. const qiniuUploader = require("../../../../utils/qiniuUploader");
  3. const Parse = getApp().Parse;
  4. const company = getApp().globalData.company;
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. //屏幕高度
  11. statusBarHeight: 0, // 状态栏高度
  12. screenHeight: 0, // 屏幕高度
  13. customHeight: 0, // 自定义导航栏高度(如小程序右上角胶囊按钮)
  14. bottomNavHeight: 0, // 底部导航栏高度
  15. contentHeight: 0, // 可用内容高度
  16. contentHeight2: 0,
  17. contentpadding: 0, //顶部padding高度
  18. sharList: [],
  19. images: [
  20. // 'https://file-cloud.fmode.cn/qpFbRRSZrO/20250113/1p97lf053250915.png',
  21. 'https://file-cloud.fmode.cn/qpFbRRSZrO/20250113/bt19fm050427168.png'
  22. ],
  23. randomImage: '',
  24. saveimage: '',
  25. uptokenURL: '',
  26. domain: '',
  27. uploadURL: '',
  28. userList:[],
  29. },
  30. /**
  31. * 生命周期函数--监听页面加载
  32. */
  33. onLoad: function (options) {
  34. // 计算
  35. const systemInfo = wx.getSystemInfoSync();
  36. const statusBarHeight = systemInfo.statusBarHeight || 0;
  37. const screenHeight = systemInfo.screenHeight || 0;
  38. const custom = wx.getMenuButtonBoundingClientRect();
  39. const customHeight = custom.height + 10 + 2 || 0;
  40. const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
  41. const contentpadding = (statusBarHeight + customHeight) * 750 / systemInfo.windowWidth;
  42. const contentHeight = (screenHeight - bottomNavHeight - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
  43. this.setData({
  44. statusBarHeight,
  45. screenHeight,
  46. customHeight,
  47. bottomNavHeight,
  48. contentpadding,
  49. contentHeight
  50. });
  51. this.getuser()
  52. this.order()
  53. this.showRandomImage()
  54. },
  55. /**
  56. * 生命周期函数--监听页面初次渲染完成
  57. */
  58. onReady: function () {
  59. },
  60. /**
  61. * 生命周期函数--监听页面显示
  62. */
  63. onShow: function () {
  64. },
  65. /**
  66. * 生命周期函数--监听页面隐藏
  67. */
  68. onHide: function () {
  69. },
  70. /**
  71. * 生命周期函数--监听页面卸载
  72. */
  73. onUnload: function () {
  74. },
  75. /**
  76. * 页面相关事件处理函数--监听用户下拉动作
  77. */
  78. onPullDownRefresh: function () {
  79. },
  80. /**
  81. * 页面上拉触底事件的处理函数
  82. */
  83. onReachBottom: function () {
  84. },
  85. /**
  86. * 用户点击右上角分享
  87. */
  88. onShareAppMessage: function () {
  89. },
  90. //获取当天运动数据
  91. async order() {
  92. const currentUser = Parse.User.current();
  93. let ActivityDataquery = new Parse.Query('ActivityData');
  94. ActivityDataquery.equalTo('company', company);
  95. ActivityDataquery.notEqualTo('isDeleted', true);
  96. // 获取今天的日期
  97. const today = new Date();
  98. const todayStart = new Date(today.getFullYear(), today.getMonth(), today.getDate()); // 今天的开始时间
  99. const todayEnd = new Date(todayStart);
  100. todayEnd.setHours(23, 59, 59, 999); // 今天的结束时间
  101. console.log(todayStart, todayEnd);
  102. // 在查询条件中添加对 createdAt 的限制
  103. ActivityDataquery.greaterThanOrEqualTo('createdAt', todayStart);
  104. ActivityDataquery.lessThanOrEqualTo('createdAt', todayEnd);
  105. // 根据 steps 字段进行降序排序
  106. ActivityDataquery.include('user');
  107. try {
  108. let P = await ActivityDataquery.find();
  109. let todayList = P.map(item => {
  110. let itemData = item.toJSON();
  111. // 获取当前时间并格式化
  112. const now = new Date();
  113. const formattedTime = `${now.getFullYear()}/${String(now.getMonth() + 1).padStart(2, '0')}/${String(now.getDate()).padStart(2, '0')} ${String(now.getHours()).padStart(2, '0')}:${String(now.getMinutes()).padStart(2, '0')}`;
  114. itemData.currentTime = formattedTime; // 将当前时间添加到 item 中
  115. return itemData;
  116. });
  117. // 创建一个对象来存储用户的总步数
  118. const userStepsMap = {};
  119. // 遍历数据,累加相同用户的步数
  120. todayList.forEach(item => {
  121. const userId = item.user.objectId;
  122. const steps = item.steps;
  123. const distance = item.distance||0;
  124. if (steps) {
  125. if (!userStepsMap[userId]) {
  126. userStepsMap[userId] = {
  127. ...item.user, // 包含用户信息
  128. currentTime: item.currentTime,
  129. totalSteps: 0, // 初始化总步数
  130. totaldistance:0,
  131. };
  132. }
  133. userStepsMap[userId].totalSteps += steps;
  134. userStepsMap[userId].totaldistance += distance; // 累加步数
  135. }
  136. });
  137. // 将对象转换为数组
  138. const aggregatedList = Object.values(userStepsMap);
  139. // 按总步数降序排序
  140. aggregatedList.sort((a, b) => b.totalSteps - a.totalSteps);
  141. // 添加排名
  142. let currentRank = 1; // 当前排名
  143. for (let i = 0; i < aggregatedList.length; i++) {
  144. if (i > 0 && aggregatedList[i].totalSteps === aggregatedList[i - 1].totalSteps) {
  145. // 如果步数相同,排名相同
  146. aggregatedList[i].rank = aggregatedList[i - 1].rank;
  147. } else {
  148. // 否则,更新当前排名
  149. aggregatedList[i].rank = currentRank;
  150. }
  151. currentRank++;
  152. }
  153. console.log('aggregatedList',aggregatedList);
  154. aggregatedList.forEach(item=>{
  155. if(item.objectId == currentUser.id){
  156. this.setData({
  157. sharList:item,
  158. });
  159. console.log('sharList',this.data.sharList);
  160. this.saveImage()
  161. }
  162. })
  163. } catch (error) {
  164. console.error('Error fetching today\'s data:', error);
  165. }
  166. },
  167. //随机展示图片
  168. showRandomImage: function () {
  169. const randomIndex = Math.floor(Math.random() * this.data.images.length);
  170. this.setData({
  171. randomImage: this.data.images[randomIndex]
  172. });
  173. },
  174. //绘制canvas
  175. rpxToPx(rpx) {
  176. const systemInfo = wx.getSystemInfoSync();
  177. return rpx * (systemInfo.windowWidth / 750);
  178. },
  179. getImageInfo(url) {
  180. console.log(url);
  181. return new Promise((result) => {
  182. wx.getImageInfo({
  183. src: url, //服务器返回的图片地址
  184. success: function (res) {
  185. // res.path是网络图片的本地地址
  186. let Path = res.path;
  187. result(Path)
  188. },
  189. fail(err) {
  190. console.log(err);
  191. result()
  192. }
  193. });
  194. })
  195. },
  196. //获取用户信息
  197. async getuser(){
  198. const currentUser = Parse.User.current();
  199. let user = new Parse.Query('_User');
  200. user.equalTo('company', company);
  201. user.notEqualTo('isDeleted', true);
  202. user.equalTo('objectId', currentUser.id);
  203. let P = await user.find();
  204. let userList = P.map(item => item.toJSON());
  205. this.setData({
  206. userList,
  207. })
  208. console.log('userList',this.data.userList);
  209. },
  210. //rpx
  211. async saveImage() {
  212. // console.log('运行了');
  213. const canvas = wx.createCanvasContext('myCanvas');
  214. const width = this.rpxToPx(670);
  215. const height = this.rpxToPx(1100);
  216. // console.log(width, height);
  217. canvas.width = this.rpxToPx(670);
  218. canvas.height = this.rpxToPx(1100);
  219. const backgroundImage2 = await this.getImageInfo(this.data.randomImage);
  220. // 绘制背景图片
  221. canvas.drawImage(backgroundImage2, 0, 0, width, height);
  222. // 加载背景图片
  223. const backgroundImage1 = await this.getImageInfo('https://file-cloud.fmode.cn/qpFbRRSZrO/20250113/1r3o3q045323287.png');
  224. // 绘制背景图片
  225. canvas.drawImage(backgroundImage1, 0, 0, width, height);
  226. // 绘制背景
  227. // canvas.setFillStyle('#CAE1FD'); // 背景色
  228. // canvas.fillRect(0, 0, width, height);
  229. canvas.setFillStyle('#0178EE');
  230. // let mainimage = await this.getImageInfo(this.data.randomImage)
  231. let avatar = Parse.User.current()?.get('avatar')
  232. console.log('avatar', avatar);
  233. let userAvatar = await this.getImageInfo(avatar)
  234. console.log('userAvatar', userAvatar);
  235. //主图片
  236. // canvas.drawImage(mainimage, 0, 0, width, this.rpxToPx(500)); // 调整图片高度
  237. //头像
  238. if (userAvatar) {
  239. // 绘制带圆角的头像
  240. const avatarX = this.rpxToPx(40);
  241. const avatarY = this.rpxToPx(540);
  242. const avatarSize = this.rpxToPx(83);
  243. const radius = avatarSize / 2; // 半径为头像大小的一半
  244. // 绘制圆角矩形
  245. canvas.save(); // 保存当前状态
  246. canvas.beginPath(); // 开始路径
  247. canvas.moveTo(avatarX + radius, avatarY); // 左上角
  248. canvas.lineTo(avatarX + avatarSize - radius, avatarY); // 上边
  249. canvas.arc(avatarX + avatarSize - radius, avatarY + radius, radius, 1.5 * Math.PI, 0, false); // 右上角
  250. canvas.lineTo(avatarX + avatarSize, avatarY + avatarSize - radius); // 右边
  251. canvas.arc(avatarX + avatarSize - radius, avatarY + avatarSize - radius, radius, 0, 0.5 * Math.PI, false); // 右下角
  252. canvas.lineTo(avatarX + radius, avatarY + avatarSize); // 下边
  253. canvas.arc(avatarX + radius, avatarY + avatarSize - radius, radius, 0.5 * Math.PI, Math.PI, false); // 左下角
  254. canvas.lineTo(avatarX, avatarY + radius); // 左边
  255. canvas.arc(avatarX + radius, avatarY + radius, radius, Math.PI, 1.5 * Math.PI, false); // 左上角
  256. canvas.closePath(); // 关闭路径
  257. canvas.clip(); // 剪切
  258. // 绘制头像
  259. canvas.drawImage(userAvatar, avatarX, avatarY, avatarSize, avatarSize); // 头像位置和大小
  260. canvas.restore(); // 恢复状态
  261. }
  262. // 绘制昵称和时间
  263. const nickname = this.data.userList[0].nickname;
  264. const currentTime = this.data.sharList.currentTime;
  265. const rank = this.data.sharList.rank;
  266. const steps = this.data.sharList.totalSteps || 0;
  267. const distance = this.data.sharList.totaldistance || 0;
  268. canvas.setFontSize(this.rpxToPx(30));
  269. canvas.fillText(nickname, this.rpxToPx(140), this.rpxToPx(580)); // 昵称位置
  270. // console.log('昵称加载成功');
  271. canvas.setFontSize(this.rpxToPx(28));
  272. canvas.fillText(currentTime, this.rpxToPx(140), this.rpxToPx(610)); // 时间位置
  273. // console.log('时间加载成功');
  274. // 绘制其他文本
  275. canvas.setFontSize(this.rpxToPx(55));
  276. canvas.fillText('梦想家', this.rpxToPx(40), this.rpxToPx(720));
  277. // console.log('梦想家加载成功');
  278. canvas.setFontSize(this.rpxToPx(30));
  279. canvas.fillText('用汗水实现想象,用脚步丈量梦想', this.rpxToPx(40), this.rpxToPx(780));
  280. // console.log('汗水加载成功');
  281. // 绘制排名、步数和公里数
  282. canvas.setFontSize(this.rpxToPx(22));
  283. // canvas.fillText('今日排名: ' + rank, 20, 400);
  284. canvas.fillText('今日排名', this.rpxToPx(40), this.rpxToPx(840));
  285. // console.log('排名加载成功');
  286. // canvas.fillText('今日步数: ' + steps, 20, 420);
  287. canvas.fillText('今日步数', this.rpxToPx(180), this.rpxToPx(840));
  288. // console.log('步数加载成功');
  289. // canvas.fillText('公里数: ' + distance + 'km', 20, 430);
  290. canvas.fillText('公里数', this.rpxToPx(320), this.rpxToPx(840));
  291. // console.log('公里数加载成功');
  292. canvas.setFontSize(this.rpxToPx(34));
  293. canvas.fillText(rank, this.rpxToPx(70), this.rpxToPx(900));
  294. canvas.fillText(steps, this.rpxToPx(180), this.rpxToPx(900));
  295. canvas.fillText(distance + 'km', this.rpxToPx(320), this.rpxToPx(900));
  296. // 加载二维码图片
  297. const qrCodeImage = await this.getImageInfo('https://file-cloud.fmode.cn/qpFbRRSZrO/20250113/t2vst6051431547.png');
  298. // 绘制二维码
  299. canvas.drawImage(qrCodeImage, width - this.rpxToPx(140), height - this.rpxToPx(160), this.rpxToPx(120), this.rpxToPx(120));
  300. canvas.setFillStyle('#0178EE');
  301. canvas.setFontSize(this.rpxToPx(28));
  302. canvas.fillText('长按二维码加入儒乐湖健身跑', width - this.rpxToPx(510), height - this.rpxToPx(120));
  303. canvas.fillText('和我一起运动', width - this.rpxToPx(405), height - this.rpxToPx(80));
  304. // 完成绘制
  305. canvas.draw(false, () => {
  306. console.log('123');
  307. wx.canvasToTempFilePath({
  308. canvasId: 'myCanvas',
  309. success: (res) => {
  310. console.log('绘制完成', res);
  311. this.setData({
  312. saveimage: res.tempFilePath
  313. });
  314. this.getUptoken()
  315. console.log(this.data.saveimage);
  316. },
  317. fail: (err) => {
  318. console.error('canvasToTempFilePath 失败', err);
  319. }
  320. });
  321. });
  322. },
  323. uploadImageToServer() {
  324. const that = this;
  325. const tempFilePath = this.data.saveimage; // 获取本地临时文件路径
  326. qiniuUploader.upload(
  327. tempFilePath, // 本地文件路径
  328. (res) => {
  329. const imageURL = res.imageURL; // 上传成功后的网络地址
  330. console.log('上传成功,网络地址:', imageURL);
  331. that.setData({
  332. saveimage: imageURL // 更新 saveimage 为网络地址
  333. });
  334. },
  335. (error) => {
  336. console.error('上传失败:', error);
  337. }, {
  338. region: "SCN", // 七牛云区域
  339. uploadURL: that.data.uploadURL, // 上传地址
  340. domain: that.data.domain, // 域名
  341. uptoken: that.data.uptokenURL, // 上传凭证
  342. }
  343. );
  344. console.log('saveimage', this.data.saveimage);
  345. },
  346. async getUptoken() {
  347. let res = await Parse.Cloud.run('qiniu_uptoken', {
  348. company: company
  349. })
  350. this.setData({
  351. uptokenURL: res.uptoken,
  352. domain: res.domain,
  353. uploadURL: res.zoneUrl
  354. })
  355. this.uploadImageToServer()
  356. console.log(this.data.uptokenURL, this.data.domain, this.data.uploadURL);
  357. },
  358. //px
  359. // saveImage() {
  360. // // console.log('运行了');
  361. // const canvas = wx.createCanvasContext('myCanvas');
  362. // const width = 335;
  363. // const height = 550;
  364. // // console.log(width, height);
  365. // canvas.width = 335;
  366. // canvas.height = 550;
  367. // // 绘制背景
  368. // canvas.setFillStyle('#CAE1FD'); // 背景色
  369. // canvas.fillRect(0, 0, width, height);
  370. // canvas.setFillStyle('#0178EE');
  371. // // 加载主图片
  372. // wx.getImageInfo({
  373. // src: this.data.randomImage,
  374. // success: (res) => {
  375. // canvas.drawImage(res.path, 0, 0, width, 250); // 调整图片高度
  376. // // console.log('主图片加载成功');
  377. // // 加载用户头像
  378. // wx.getImageInfo({
  379. // src: this.data.sharList[0].user.avatar,
  380. // success: (avatarRes) => {
  381. // // 绘制带圆角的头像
  382. // const avatarX = 20;
  383. // const avatarY = 270;
  384. // const avatarSize = 42.5;
  385. // const radius = avatarSize / 2; // 半径为头像大小的一半
  386. // // 绘制圆角矩形
  387. // canvas.save(); // 保存当前状态
  388. // canvas.beginPath(); // 开始路径
  389. // canvas.moveTo(avatarX + radius, avatarY); // 左上角
  390. // canvas.lineTo(avatarX + avatarSize - radius, avatarY); // 上边
  391. // canvas.arc(avatarX + avatarSize - radius, avatarY + radius, radius, 1.5 * Math.PI, 0, false); // 右上角
  392. // canvas.lineTo(avatarX + avatarSize, avatarY + avatarSize - radius); // 右边
  393. // canvas.arc(avatarX + avatarSize - radius, avatarY + avatarSize - radius, radius, 0, 0.5 * Math.PI, false); // 右下角
  394. // canvas.lineTo(avatarX + radius, avatarY + avatarSize); // 下边
  395. // canvas.arc(avatarX + radius, avatarY + avatarSize - radius, radius, 0.5 * Math.PI, Math.PI, false); // 左下角
  396. // canvas.lineTo(avatarX, avatarY + radius); // 左边
  397. // canvas.arc(avatarX + radius, avatarY + radius, radius, Math.PI, 1.5 * Math.PI, false); // 左上角
  398. // canvas.closePath(); // 关闭路径
  399. // canvas.clip(); // 剪切
  400. // // 绘制头像
  401. // canvas.drawImage(avatarRes.path, avatarX, avatarY, avatarSize, avatarSize); // 头像位置和大小
  402. // canvas.restore(); // 恢复状态
  403. // // console.log('头像加载成功');
  404. // // 绘制昵称和时间
  405. // const nickname = this.data.sharList[0].user.nickname;
  406. // const currentTime = this.data.sharList[0].currentTime;
  407. // const rank = this.data.sharList[0].rank;
  408. // const steps = this.data.sharList[0].steps || 0;
  409. // const distance = this.data.sharList[0].distance || 0;
  410. // canvas.setFontSize(15);
  411. // canvas.fillText(nickname, 70, 290); // 昵称位置
  412. // // console.log('昵称加载成功');
  413. // canvas.setFontSize(14);
  414. // canvas.fillText(currentTime, 70, 305); // 时间位置
  415. // // console.log('时间加载成功');
  416. // // 绘制其他文本
  417. // canvas.setFontSize(27.5);
  418. // canvas.fillText('梦想家', 20, 360);
  419. // // console.log('梦想家加载成功');
  420. // canvas.setFontSize(15);
  421. // canvas.fillText('用汗水实现想象,用脚步丈量梦想', 20, 390);
  422. // // console.log('汗水加载成功');
  423. // // 绘制排名、步数和公里数
  424. // canvas.setFontSize(14);
  425. // // canvas.fillText('今日排名: ' + rank, 20, 400);
  426. // canvas.fillText('今日排名', 20, 420);
  427. // // console.log('排名加载成功');
  428. // // canvas.fillText('今日步数: ' + steps, 20, 420);
  429. // canvas.fillText('今日步数', 120, 420);
  430. // // console.log('步数加载成功');
  431. // // canvas.fillText('公里数: ' + distance + 'km', 20, 430);
  432. // canvas.fillText('公里数', 220, 420);
  433. // // console.log('公里数加载成功');
  434. // canvas.setFontSize(20);
  435. // canvas.fillText(rank, 40, 450);
  436. // canvas.fillText(steps, 122, 450);
  437. // canvas.fillText(distance + 'km', 222, 450);
  438. // // 绘制二维码(如果有)
  439. // canvas.setFillStyle('red'); // 示例二维码
  440. // canvas.fillRect(width - 70, height - 80, 60, 60); // QR 位置
  441. // // console.log('二维码绘制');
  442. // canvas.setFillStyle('#0178EE');
  443. // canvas.setFontSize(14);
  444. // canvas.fillText('长按二维码加入跑团', width - 210, height - 60);
  445. // canvas.fillText('和我一起运动', width - 190, height - 40);
  446. // // 完成绘制
  447. // canvas.draw(false, () => {
  448. // console.log('123');
  449. // wx.canvasToTempFilePath({
  450. // canvasId: 'myCanvas',
  451. // success: (res) => {
  452. // console.log('绘制完成', res);
  453. // this.setData({
  454. // saveimage: res.tempFilePath
  455. // });
  456. // console.log(this.data.saveimage);
  457. // },
  458. // fail: (err) => {
  459. // console.error('canvasToTempFilePath 失败', err);
  460. // }
  461. // });
  462. // });
  463. // },
  464. // fail: () => {
  465. // console.error('用户头像加载失败');
  466. // }
  467. // });
  468. // },
  469. // fail: () => {
  470. // console.error('主图片加载失败');
  471. // }
  472. // });
  473. // },
  474. //点击保存图片
  475. async savepic() {
  476. await this.saveImage()
  477. const imagePath = this.data.saveimage; // 获取保存的图片路径
  478. if (imagePath) {
  479. // 调用保存图片到相册的方法
  480. wx.saveImageToPhotosAlbum({
  481. filePath: imagePath,
  482. success: () => {
  483. wx.showToast({
  484. title: '图片已保存到相册',
  485. icon: 'success'
  486. });
  487. },
  488. fail: (err) => {
  489. console.error('保存失败', err);
  490. wx.showToast({
  491. title: '保存失败',
  492. icon: 'none'
  493. });
  494. }
  495. });
  496. } else {
  497. wx.showToast({
  498. title: '没有可保存的图片',
  499. icon: 'none'
  500. });
  501. }
  502. },
  503. //保存图片到相册
  504. savepic2: function () {
  505. let that = this;
  506. wx.canvasToTempFilePath({
  507. x: 0,
  508. y: 0,
  509. width: 670,
  510. height: 1100,
  511. destWidth: 670,
  512. destHeight: 1100,
  513. canvasId: 'myCanvas',
  514. success: function (result) {
  515. wx.getSetting({
  516. success(res) {
  517. if (!res.authSetting['scope.writePhotosAlbum']) {
  518. wx.authorize({
  519. scope: 'scope.writePhotosAlbum',
  520. success() {
  521. //这里是用户同意授权后的回调
  522. // that.saveImgToLocal();
  523. wx.saveImageToPhotosAlbum({
  524. filePath: result.tempFilePath,
  525. success(res) {
  526. wx.showToast({
  527. title: '图片已保存到相册',
  528. icon: 'success'
  529. });
  530. }
  531. })
  532. },
  533. fail() { //这里是用户拒绝授权后的回调
  534. wx.showToast({
  535. title: '打开相册授权,才能保存图片哦~',
  536. icon: 'none',
  537. duration: 2000
  538. })
  539. that.setData({
  540. openSettingBtnHidden: false
  541. })
  542. }
  543. })
  544. } else {
  545. //调取小程序当中获取图片
  546. console.log(result.tempFilePath);
  547. wx.saveImageToPhotosAlbum({
  548. filePath: result.tempFilePath,
  549. success(res) {
  550. wx.showToast({
  551. title: '图片已保存到相册',
  552. icon: 'success'
  553. });
  554. }
  555. })
  556. }
  557. }
  558. })
  559. },
  560. fail: function (res) {
  561. console.log(res)
  562. }
  563. })
  564. },
  565. shar() {
  566. wx.downloadFile({
  567. url: this.data.saveimage, //图片服务器地址
  568. success: (res) => {
  569. wx.showShareImageMenu({
  570. path: res.tempFilePath, //转为本地地址showShareImageMenu进行分享
  571. success: (res) => {
  572. uni.hideLoading();
  573. this.modalShare = null;
  574. },
  575. fail: (err) => {
  576. uni.hideLoading();
  577. this.modalShare = null;
  578. },
  579. });
  580. },
  581. });
  582. },
  583. sharecircle() {
  584. console.log('this.data.saveimage', this.data.saveimage);
  585. wx.navigateTo({
  586. url: '../../circle/send-circle/index?image=' + this.data.saveimage // 目标页面的路径
  587. });
  588. }
  589. })