123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592 |
- const qiniuUploader = require("../../../../utils/qiniuUploader");
- 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/20250113/bt19fm050427168.png'
- ],
- randomImage: '',
- saveimage: '',
- uptokenURL: '',
- domain: '',
- uploadURL: ''
- },
-
- 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);
- },
- getImageInfo(url) {
- console.log(url);
- return new Promise((result) => {
- wx.getImageInfo({
- src: url,
- success: function (res) {
-
- let Path = res.path;
- result(Path)
- },
- fail(err) {
- console.log(err);
- result()
- }
- });
- })
- },
-
- async 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);
- const backgroundImage2 = await this.getImageInfo(this.data.randomImage);
-
- canvas.drawImage(backgroundImage2, 0, 0, width, height);
-
- const backgroundImage1 = await this.getImageInfo('https://file-cloud.fmode.cn/qpFbRRSZrO/20250113/1r3o3q045323287.png');
-
- canvas.drawImage(backgroundImage1, 0, 0, width, height);
-
-
-
- canvas.setFillStyle('#0178EE');
-
- let avatar = Parse.User.current()?.get('avatar')
- console.log('avatar', avatar);
- let userAvatar = await this.getImageInfo(avatar)
- console.log('userAvatar', userAvatar);
-
-
-
- if (userAvatar) {
-
- 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(userAvatar, 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(22));
-
- canvas.fillText('今日排名', this.rpxToPx(40), this.rpxToPx(840));
-
-
- canvas.fillText('今日步数', this.rpxToPx(180), this.rpxToPx(840));
-
-
- canvas.fillText('公里数', this.rpxToPx(320), this.rpxToPx(840));
-
- canvas.setFontSize(this.rpxToPx(34));
- canvas.fillText(rank, this.rpxToPx(70), this.rpxToPx(900));
- canvas.fillText(steps, this.rpxToPx(180), this.rpxToPx(900));
- canvas.fillText(distance + 'km', this.rpxToPx(320), this.rpxToPx(900));
-
- const qrCodeImage = await this.getImageInfo('https://file-cloud.fmode.cn/qpFbRRSZrO/20250113/t2vst6051431547.png');
-
- canvas.drawImage(qrCodeImage, 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(510), height - this.rpxToPx(120));
- canvas.fillText('和我一起运动', width - this.rpxToPx(405), height - this.rpxToPx(80));
-
- canvas.draw(false, () => {
- console.log('123');
- wx.canvasToTempFilePath({
- canvasId: 'myCanvas',
- success: (res) => {
- console.log('绘制完成', res);
- this.setData({
- saveimage: res.tempFilePath
- });
- this.getUptoken()
- console.log(this.data.saveimage);
- },
- fail: (err) => {
- console.error('canvasToTempFilePath 失败', err);
- }
- });
- });
- },
- uploadImageToServer() {
- const that = this;
- const tempFilePath = this.data.saveimage;
- qiniuUploader.upload(
- tempFilePath,
- (res) => {
- const imageURL = res.imageURL;
- console.log('上传成功,网络地址:', imageURL);
- that.setData({
- saveimage: imageURL
- });
- },
- (error) => {
- console.error('上传失败:', error);
- }, {
- region: "SCN",
- uploadURL: that.data.uploadURL,
- domain: that.data.domain,
- uptoken: that.data.uptokenURL,
- }
- );
- console.log('saveimage', this.data.saveimage);
- },
- async getUptoken() {
- let res = await Parse.Cloud.run('qiniu_uptoken', {
- company: company
- })
- this.setData({
- uptokenURL: res.uptoken,
- domain: res.domain,
- uploadURL: res.zoneUrl
- })
- this.uploadImageToServer()
- console.log(this.data.uptokenURL, this.data.domain, this.data.uploadURL);
- },
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 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: function () {
- let that = this;
- wx.canvasToTempFilePath({
- x: 0,
- y: 0,
- width: 670,
- height: 1100,
- destWidth: 670,
- destHeight: 1100,
- canvasId: 'myCanvas',
- success: function (result) {
- wx.getSetting({
- success(res) {
- if (!res.authSetting['scope.writePhotosAlbum']) {
- wx.authorize({
- scope: 'scope.writePhotosAlbum',
- success() {
-
-
- wx.saveImageToPhotosAlbum({
- filePath: result.tempFilePath,
- success(res) {
- wx.showToast({
- title: '图片已保存到相册',
- icon: 'success'
- });
- }
- })
- },
- fail() {
- wx.showToast({
- title: '打开相册授权,才能保存图片哦~',
- icon: 'none',
- duration: 2000
- })
- that.setData({
- openSettingBtnHidden: false
- })
- }
- })
- } else {
-
- console.log(result.tempFilePath);
- wx.saveImageToPhotosAlbum({
- filePath: result.tempFilePath,
- success(res) {
- wx.showToast({
- title: '图片已保存到相册',
- icon: 'success'
- });
- }
- })
- }
- }
- })
- },
- fail: function (res) {
- console.log(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() {
- console.log('this.data.saveimage', this.data.saveimage);
- wx.navigateTo({
- url: '../../circle/send-circle/index?image=' + this.data.saveimage
- });
- }
- })
|