123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522 |
- const Parse = getApp().Parse;
- const company = getApp().globalData.company;
- Page({
-
- data: {
-
- statusBarHeight: 0,
- screenHeight: 0,
- customHeight: 0,
- bottomNavHeight: 0,
- contentHeight: 0,
- contentHeight2: 0,
- contentpadding: 0,
- sharList: [],
- images: [
- 'https://file-cloud.fmode.cn/qpFbRRSZrO/20250102/gtontq125800552.jpg?imageView2/1/w/200/h/200',
- 'https://file-cloud.fmode.cn/qpFbRRSZrO/20250102/8e1ps0125800358.jpg?imageView2/1/w/200/h/200',
- 'https://file-cloud.fmode.cn/qpFbRRSZrO/20250102/l5321n125800284.jpg?imageView2/1/w/200/h/200',
- 'https://file-cloud.fmode.cn/qpFbRRSZrO/20250102/j1p6l7125757884.jpg?imageView2/1/w/200/h/200'
- ],
- randomImage: '',
- saveimage: ''
- },
-
- onLoad: function (options) {
-
- const systemInfo = wx.getSystemInfoSync();
- const statusBarHeight = systemInfo.statusBarHeight || 0;
- const screenHeight = systemInfo.screenHeight || 0;
- const custom = wx.getMenuButtonBoundingClientRect();
- const customHeight = custom.height + 10 + 2 || 0;
- const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
- const contentpadding = (statusBarHeight + customHeight) * 750 / systemInfo.windowWidth;
- const contentHeight = (screenHeight - bottomNavHeight - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
- this.setData({
- statusBarHeight,
- screenHeight,
- customHeight,
- bottomNavHeight,
- contentpadding,
- contentHeight
- });
- this.order()
- this.showRandomImage()
- },
-
- onReady: function () {
- },
-
- onShow: function () {
- },
-
- onHide: function () {
- },
-
- onUnload: function () {
- },
-
- onPullDownRefresh: function () {
- },
-
- onReachBottom: function () {
- },
-
- onShareAppMessage: function () {
- },
-
- async order() {
- const currentUser = Parse.User.current();
- let ActivityDataquery = new Parse.Query('ActivityData');
-
- ActivityDataquery.equalTo('company', company);
- ActivityDataquery.equalTo('type', 'today');
- ActivityDataquery.notEqualTo('isDeleted', true);
-
- const today = new Date();
- const todayStart = new Date(today.getFullYear(), today.getMonth(), today.getDate());
- const todayEnd = new Date(todayStart);
- todayEnd.setHours(23, 59, 59, 999);
-
- ActivityDataquery.greaterThanOrEqualTo('createdAt', todayStart);
- ActivityDataquery.lessThanOrEqualTo('createdAt', todayEnd);
- ActivityDataquery.include('user');
-
- ActivityDataquery.descending('steps');
- let r = await ActivityDataquery.find();
- let todayList = r.map(item => {
- let itemData = item.toJSON();
-
- const now = new Date();
- 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')}`;
- itemData.currentTime = formattedTime;
- return itemData;
- });
- let sharList = []
- todayList.forEach((item, index) => {
- if (item.user.objectId == currentUser.id) {
- sharList.push({
- ...item,
- rank: index + 1
- });
- }
- })
- this.setData({
- sharList
- });
- this.saveImage()
- console.log(this.data.sharList);
- },
-
- showRandomImage: function () {
- const randomIndex = Math.floor(Math.random() * this.data.images.length);
- this.setData({
- randomImage: this.data.images[randomIndex]
- });
- },
-
- rpxToPx(rpx) {
- const systemInfo = wx.getSystemInfoSync();
- return rpx * (systemInfo.windowWidth / 750);
- },
-
- saveImage() {
-
- const canvas = wx.createCanvasContext('myCanvas');
- const width = this.rpxToPx(670);
- const height = this.rpxToPx(1100);
-
- canvas.width = this.rpxToPx(670);
- canvas.height = this.rpxToPx(1100);
-
- canvas.setFillStyle('#CAE1FD');
- canvas.fillRect(0, 0, width, height);
- canvas.setFillStyle('#0178EE');
-
- wx.getImageInfo({
- src: this.data.randomImage,
- success: (res) => {
- canvas.drawImage(res.path, 0, 0, width, this.rpxToPx(500));
-
-
- wx.getImageInfo({
- src: this.data.sharList[0].user.avatar,
- success: (avatarRes) => {
-
- const avatarX = this.rpxToPx(40);
- const avatarY = this.rpxToPx(540);
- const avatarSize = this.rpxToPx(83);
- const radius = avatarSize / 2;
-
- canvas.save();
- canvas.beginPath();
- canvas.moveTo(avatarX + radius, avatarY);
- canvas.lineTo(avatarX + avatarSize - radius, avatarY);
- canvas.arc(avatarX + avatarSize - radius, avatarY + radius, radius, 1.5 * Math.PI, 0, false);
- canvas.lineTo(avatarX + avatarSize, avatarY + avatarSize - radius);
- canvas.arc(avatarX + avatarSize - radius, avatarY + avatarSize - radius, radius, 0, 0.5 * Math.PI, false);
- canvas.lineTo(avatarX + radius, avatarY + avatarSize);
- canvas.arc(avatarX + radius, avatarY + avatarSize - radius, radius, 0.5 * Math.PI, Math.PI, false);
- canvas.lineTo(avatarX, avatarY + radius);
- canvas.arc(avatarX + radius, avatarY + radius, radius, Math.PI, 1.5 * Math.PI, false);
- canvas.closePath();
- canvas.clip();
-
- canvas.drawImage(avatarRes.path, avatarX, avatarY, avatarSize, avatarSize);
- canvas.restore();
-
-
- const nickname = this.data.sharList[0].user.nickname;
- const currentTime = this.data.sharList[0].currentTime;
- const rank = this.data.sharList[0].rank;
- const steps = this.data.sharList[0].steps || 0;
- const distance = this.data.sharList[0].distance || 0;
- canvas.setFontSize(this.rpxToPx(30));
- canvas.fillText(nickname, this.rpxToPx(140), this.rpxToPx(580));
-
- canvas.setFontSize(this.rpxToPx(28));
- canvas.fillText(currentTime, this.rpxToPx(140), this.rpxToPx(610));
-
-
- canvas.setFontSize(this.rpxToPx(55));
- canvas.fillText('梦想家', this.rpxToPx(40), this.rpxToPx(720));
-
- canvas.setFontSize(this.rpxToPx(30));
- canvas.fillText('用汗水实现想象,用脚步丈量梦想', this.rpxToPx(40), this.rpxToPx(780));
-
-
- canvas.setFontSize(this.rpxToPx(28));
-
- canvas.fillText('今日排名', this.rpxToPx(40), this.rpxToPx(840));
-
-
- canvas.fillText('今日步数', this.rpxToPx(240), this.rpxToPx(840));
-
-
- canvas.fillText('公里数', this.rpxToPx(440), this.rpxToPx(840));
-
- canvas.setFontSize(this.rpxToPx(40));
- canvas.fillText(rank, this.rpxToPx(80), this.rpxToPx(900));
- canvas.fillText(steps, this.rpxToPx(240), this.rpxToPx(900));
- canvas.fillText(distance + 'km', this.rpxToPx(444), this.rpxToPx(900));
-
- canvas.setFillStyle('red');
- canvas.fillRect(width - this.rpxToPx(140), height - this.rpxToPx(160), this.rpxToPx(120), this.rpxToPx(120));
-
- canvas.setFillStyle('#0178EE');
- canvas.setFontSize(this.rpxToPx(28));
- canvas.fillText('长按二维码加入跑团', width - this.rpxToPx(420), height - this.rpxToPx(120));
- canvas.fillText('和我一起运动', width - this.rpxToPx(380), height - this.rpxToPx(80));
-
- canvas.draw(false, () => {
- console.log('123');
- wx.canvasToTempFilePath({
- canvasId: 'myCanvas',
- success: (res) => {
- console.log('绘制完成', res);
- this.setData({
- saveimage: res.tempFilePath
- });
- console.log(this.data.saveimage);
- },
- fail: (err) => {
- console.error('canvasToTempFilePath 失败', err);
- }
- });
- });
- },
- fail: (err) => {
- console.error('用户头像加载失败', this.data.sharList[0].user.avatar, err);
- }
- });
- },
- fail: () => {
- console.error('主图片加载失败');
- }
- });
- },
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- async savepic() {
- await this.saveImage()
- const imagePath = this.data.saveimage;
- if (imagePath) {
-
- wx.saveImageToPhotosAlbum({
- filePath: imagePath,
- success: () => {
- wx.showToast({
- title: '保存成功',
- icon: 'success'
- });
- },
- fail: (err) => {
- console.error('保存失败', err);
- wx.showToast({
- title: '保存失败',
- icon: 'none'
- });
- }
- });
- } else {
- wx.showToast({
- title: '没有可保存的图片',
- icon: 'none'
- });
- }
- },
- savepic2() {
- const that = this
- let fileName = new Date().valueOf();
- let filePath = wx.env.USER_DATA_PATH + '/' + fileName + '.jpg'
- wx.downloadFile({
- url: that.data.saveimage,
- filePath: filePath,
- success: function (res) {
-
- wx.saveImageToPhotosAlbum({
- filePath: filePath,
- success(data) {
- let fileMgr = wx.getFileSystemManager()
- fileMgr.unlink({
- filePath: filePath,
- success() {
- wx.showToast({
- title: '已保存至您的相册',
- icon: 'none',
- duration: 1500
- });
- }
- })
- },
- fail(err) {
- if (err.errMsg === "saveImageToPhotosAlbum:fail:auth denied" || err.errMsg === "saveImageToPhotosAlbum:fail auth deny" || err.errMsg === "saveImageToPhotosAlbum:fail authorize no response") {
- wx.showModal({
- title: '提示',
- content: '需要您授权保存相册',
- showCancel: false,
- success: modalSuccess => {
- wx.openSetting({
- success(settingdata) {
- if (settingdata.authSetting['scope.writePhotosAlbum']) {
- console.log('获取权限成功,给出再次点击图片保存到相册的提示。')
- } else {
- console.log('获取权限失败,给出不给权限就无法正常使用的提示')
- }
- }
- })
- }
- })
- }
- }
- })
- },
- fail: function (res) {}
- })
- },
- shar() {
- wx.downloadFile({
- url: this.data.saveimage,
- success: (res) => {
- wx.showShareImageMenu({
- path: res.tempFilePath,
- success: (res) => {
- uni.hideLoading();
- this.modalShare = null;
- },
- fail: (err) => {
- uni.hideLoading();
- this.modalShare = null;
- },
- });
- },
- });
- },
- sharecircle(){
- wx.navigateTo({
- url: '../../circle/send-circle/index?image='+this.data.saveimage
- });
- }
- })
|