|
@@ -25,9 +25,11 @@ Page({
|
|
|
_chunks: [],
|
|
|
progress: 0,
|
|
|
_timer: null,
|
|
|
+ // 裁剪后的图片地址
|
|
|
_imgUrl: null,
|
|
|
_imgMD5: null,
|
|
|
_imgIndex: null,
|
|
|
+ // 从上级界面过来的图片地址,也是要返回去的地址
|
|
|
_imgTopPic: null,
|
|
|
_imgNext: 0,
|
|
|
max_scale: 2,
|
|
@@ -37,7 +39,7 @@ Page({
|
|
|
cropper: null,
|
|
|
callback() {
|
|
|
let that = this
|
|
|
- if (this.data.progress > 0) {
|
|
|
+ if (this.data._chunks.length > 0) {
|
|
|
wx.showModal({
|
|
|
title: '保存壁纸中,确定要中断退出吗?',
|
|
|
content: '',
|
|
@@ -158,75 +160,109 @@ Page({
|
|
|
delta: -1
|
|
|
})
|
|
|
},
|
|
|
+ _uploadImage(url) {
|
|
|
+ wx.showLoading({
|
|
|
+ title: '壁纸裁剪中',
|
|
|
+ })
|
|
|
+ const fs = wx.getFileSystemManager();
|
|
|
+
|
|
|
+ let _this = this;
|
|
|
+ // app.globalData.imgSrc = obj.url;
|
|
|
+ console.log("裁剪壁纸:", url);
|
|
|
+ _this.data._imgUrl = url
|
|
|
+ fs.readFile({
|
|
|
+ filePath: _this.data._imgUrl,
|
|
|
+ encoding: '', // 不指定编码以获取原始二进制数据
|
|
|
+ success: (obj) => {
|
|
|
+ console.log("加载文件成功:", obj.data.byteLength, obj.data.length)
|
|
|
+
|
|
|
+ fs.getFileInfo({
|
|
|
+ "filePath": _this.data._imgUrl, "digestAlgorithm": "md5", success: (res2) => {
|
|
|
+ console.log("md5:", res2)
|
|
|
+ _this.data._imgMD5 = res2.digest
|
|
|
+ _this.data._imgIndex = 0
|
|
|
+
|
|
|
+ console.log("加载文件成功:", obj.data.byteLength, obj.data.length, obj.getFileInfo)
|
|
|
+
|
|
|
+ let binData = obj.data;
|
|
|
+ // let myMd5 = _this.getImgMd5(binData)
|
|
|
+ // let my2Md5 = _this.getImg2Md5(binData)
|
|
|
+ // let my3Md5 = _this.getImg3Md5(binData)
|
|
|
+ // todo 测试用
|
|
|
+ // wx.setClipboardData({
|
|
|
+ // data: res2.digest,
|
|
|
+ // })
|
|
|
+
|
|
|
+ _this.sliceDataIntoChunks(binData, 64);
|
|
|
+
|
|
|
+ console.log("加载文件成功2:", binData.byteLength, binData.length)
|
|
|
+ _this.data._imageBufferLength = binData.byteLength ?? binData.length
|
|
|
+ wx.hideLoading();
|
|
|
+ wx.showLoading({
|
|
|
+ title: '开始传输壁纸',
|
|
|
+ })
|
|
|
+
|
|
|
+ console.log("md5 2:", _this.data._imgMD5)
|
|
|
+ _this.startImage()
|
|
|
+ }, fail: (err) => {
|
|
|
+ console.error('getFileInfo失败:', err);
|
|
|
+ },
|
|
|
+ })
|
|
|
+
|
|
|
+ },
|
|
|
+ fail: (err) => {
|
|
|
+ s
|
|
|
+ wx.hideLoading()
|
|
|
+ wx.showToast({
|
|
|
+ title: '读取该图片失败',
|
|
|
+ })
|
|
|
+ console.error('读取 .bin 文件失败:', err);
|
|
|
+ },
|
|
|
+ });
|
|
|
+ },
|
|
|
submit() {
|
|
|
let _this = this
|
|
|
// if (_this.data._chunks.length > 0) {
|
|
|
// return;
|
|
|
// }
|
|
|
-
|
|
|
+ let _imgTopPic = _this.data._imgTopPic ?? ""
|
|
|
+ if (_imgTopPic.startsWith("http")) {
|
|
|
+ // 服务器的走下载图片
|
|
|
+ console.log("服务器的走下载图片", _this.data._imgTopPic)
|
|
|
+ _this._downloadAndSaveFile(_this.data._imgTopPic)
|
|
|
+ return;
|
|
|
+ }
|
|
|
// 读取裁剪的jpg图片
|
|
|
- const fs = wx.getFileSystemManager();
|
|
|
this.cropper.getImg((res) => {
|
|
|
- wx.showLoading({
|
|
|
- title: '壁纸裁剪中',
|
|
|
- })
|
|
|
- // app.globalData.imgSrc = obj.url;
|
|
|
- console.log("裁剪壁纸:", res);
|
|
|
- _this.data._imgUrl = res.url
|
|
|
_this.data._imgTopPic = res.url
|
|
|
- fs.readFile({
|
|
|
- filePath: _this.data._imgUrl,
|
|
|
- encoding: '', // 不指定编码以获取原始二进制数据
|
|
|
- success: (obj) => {
|
|
|
- console.log("加载文件成功:", obj.data.byteLength, obj.data.length)
|
|
|
-
|
|
|
- fs.getFileInfo({
|
|
|
- "filePath": _this.data._imgUrl, "digestAlgorithm": "md5", success: (res2) => {
|
|
|
- console.log("md5:", res2)
|
|
|
- _this.data._imgMD5 = res2.digest
|
|
|
- _this.data._imgIndex = 0
|
|
|
-
|
|
|
- console.log("加载文件成功:", obj.data.byteLength, obj.data.length, obj.getFileInfo)
|
|
|
-
|
|
|
- let binData = obj.data;
|
|
|
- // let myMd5 = _this.getImgMd5(binData)
|
|
|
- // let my2Md5 = _this.getImg2Md5(binData)
|
|
|
- // let my3Md5 = _this.getImg3Md5(binData)
|
|
|
- // todo 测试用
|
|
|
- // wx.setClipboardData({
|
|
|
- // data: res2.digest,
|
|
|
- // })
|
|
|
-
|
|
|
- _this.sliceDataIntoChunks(binData, 64);
|
|
|
-
|
|
|
- console.log("加载文件成功2:", binData.byteLength, binData.length)
|
|
|
- _this.data._imageBufferLength = binData.byteLength ?? binData.length
|
|
|
- wx.hideLoading();
|
|
|
- wx.showLoading({
|
|
|
- title: '开始传输壁纸',
|
|
|
- })
|
|
|
-
|
|
|
- console.log("md5 2:", _this.data._imgMD5)
|
|
|
- _this.startImage()
|
|
|
- }, fail: (err) => {
|
|
|
- console.error('getFileInfo失败:', err);
|
|
|
- },
|
|
|
- })
|
|
|
-
|
|
|
- },
|
|
|
- fail: (err) => {
|
|
|
- s
|
|
|
- wx.hideLoading()
|
|
|
+ _this._uploadImage(res.url)
|
|
|
+ });
|
|
|
+ },
|
|
|
+ _downloadAndSaveFile(url) {
|
|
|
+ let _this = this
|
|
|
+ // 下载文件
|
|
|
+ wx.downloadFile({
|
|
|
+ url: url,
|
|
|
+ success: function (res) {
|
|
|
+ if (res.statusCode === 200) {
|
|
|
+ const tempFilePath = res.tempFilePath;
|
|
|
+ _this.data._imgTopPic = url
|
|
|
+ _this._uploadImage(tempFilePath)
|
|
|
+ } else {
|
|
|
wx.showToast({
|
|
|
- title: '读取该图片失败',
|
|
|
- })
|
|
|
- console.error('读取 .bin 文件失败:', err);
|
|
|
- },
|
|
|
- });
|
|
|
+ title: '下载图片失败',
|
|
|
+ icon: 'error'
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: function (err) {
|
|
|
+ console.error('下载文件失败', err);
|
|
|
+ wx.showToast({
|
|
|
+ title: '下载失败',
|
|
|
+ icon: 'error'
|
|
|
+ });
|
|
|
+ }
|
|
|
});
|
|
|
- // 651kb的
|
|
|
- // _this.downloadAndSaveFile("https://music-play.oss-cn-shenzhen.aliyuncs.com/backOss/file/8770a6097d9940b59032d099b2fdde3b.bin");
|
|
|
-
|
|
|
},
|
|
|
|
|
|
checkAndRequestImagePermission: function () {
|
|
@@ -285,10 +321,13 @@ Page({
|
|
|
BtHelper.sendCallBack(BtCmd.wallPaper(1), function (res) {
|
|
|
if (!res) {
|
|
|
wx.hideLoading()
|
|
|
- wx.showToast({
|
|
|
- title: '发送图片失败',
|
|
|
- icon: 'error'
|
|
|
- })
|
|
|
+ wx.setTimeout(function () {
|
|
|
+ wx.showToast({
|
|
|
+ title: '发送失败',
|
|
|
+ icon: 'error',
|
|
|
+ duration: 2000
|
|
|
+ })
|
|
|
+ }, 100)
|
|
|
}
|
|
|
});
|
|
|
},
|
|
@@ -444,7 +483,7 @@ Page({
|
|
|
},
|
|
|
failSend(showToast) {
|
|
|
let _this = this
|
|
|
- _this.data._chunks = null
|
|
|
+ _this.data._chunks = []
|
|
|
_this.data._imgMD5 = null
|
|
|
_this.data._imgIndex = 0
|
|
|
_this.data._imgNext = 0
|
|
@@ -457,11 +496,12 @@ Page({
|
|
|
// })
|
|
|
wx.showToast({
|
|
|
title: '发送图片败',
|
|
|
- icon: 'failure'
|
|
|
+ icon: 'error'
|
|
|
})
|
|
|
}
|
|
|
_this.setData({
|
|
|
progress: 0,
|
|
|
+ showProgress: false,
|
|
|
showCropImg: false
|
|
|
});
|
|
|
},
|
|
@@ -524,6 +564,7 @@ Page({
|
|
|
|
|
|
switch (name) {
|
|
|
case EnumCmdEvent.onoffline:
|
|
|
+ wx.hideLoading();
|
|
|
_this.disconnect(event)
|
|
|
break;
|
|
|
case EnumCmdEvent.wallpaper:
|
|
@@ -563,6 +604,17 @@ Page({
|
|
|
// 收到回复md5,开始发送图片
|
|
|
if (kind == 1 && value === 1) {
|
|
|
_this.sendImage(0)
|
|
|
+ } else if (kind == 0 && value === 3) {
|
|
|
+ _this.failSend(false)
|
|
|
+ wx.showModal({
|
|
|
+ title: '发送图片失败,请重启设备再试试吧',
|
|
|
+ showCancel: false,
|
|
|
+ success: function (res) {
|
|
|
+ if (res.confirm) {
|
|
|
+ console.log('用户点击确定')
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
} else {
|
|
|
_this.failSend(true)
|
|
|
}
|