|
@@ -3,10 +3,9 @@
|
|
|
const { BtCmd } = require('../../../devices/bluetooth/bt_cmd');
|
|
|
import EventManager from '../../../utils/event_bus'
|
|
|
import { EnumCmdEvent, CmdEvent } from '../../../devices/cmd_key_event';
|
|
|
-import js_md5 from '../../../utils/js_md5';
|
|
|
-import store from '../../../utils/store';
|
|
|
import route_util from '../../../utils/route_util';
|
|
|
const { BtHelper } = require('../../../devices/bt_helper');
|
|
|
+const { uploadImage } = require('../../../request/imageRequest');
|
|
|
|
|
|
Page({
|
|
|
|
|
@@ -36,6 +35,7 @@ Page({
|
|
|
max_scale: 2,
|
|
|
_hasPermission: false,
|
|
|
_hasShowModal: false,
|
|
|
+ _deviceId: null,
|
|
|
wallpaper: {},
|
|
|
},
|
|
|
cropper: null,
|
|
@@ -75,7 +75,6 @@ Page({
|
|
|
title: '加载中',
|
|
|
})
|
|
|
const tempFilePaths = res.tempFiles[0].tempFilePath;
|
|
|
- // //重置壁纸角度、缩放、位置
|
|
|
that.cropper.imgReset();
|
|
|
that.setData({
|
|
|
src: tempFilePaths
|
|
@@ -83,8 +82,8 @@ Page({
|
|
|
|
|
|
// todo 测试用
|
|
|
// that.testUpload(tempFilePaths)
|
|
|
- }, fail(res) {
|
|
|
- console.log(res)
|
|
|
+ }, fail(err2) {
|
|
|
+ console.log(err2)
|
|
|
}
|
|
|
})
|
|
|
},
|
|
@@ -146,8 +145,8 @@ Page({
|
|
|
},
|
|
|
loadimage(e) {
|
|
|
wx.hideLoading();
|
|
|
- console.log('壁纸', e);
|
|
|
- this.cropper.imgReset();
|
|
|
+ console.log('加载壁纸', e);
|
|
|
+ // this.cropper.imgReset();
|
|
|
},
|
|
|
clickcut(e) {
|
|
|
console.log("clickcut:", e.detail);
|
|
@@ -162,10 +161,16 @@ Page({
|
|
|
delta: -1
|
|
|
})
|
|
|
},
|
|
|
+ async _uploadImgIOS(url) {
|
|
|
+ let _this = this;
|
|
|
+ let res = await uploadImage(url);
|
|
|
+ // 服务器的走下载图片
|
|
|
+ _this.data._imgTopPic = res.data;
|
|
|
+ console.log("IOS的走下载图片", res)
|
|
|
+ _this._downloadAndSaveFile(_this.data._imgTopPic)
|
|
|
+ },
|
|
|
_uploadImage(url) {
|
|
|
- wx.showLoading({
|
|
|
- title: '壁纸裁剪中',
|
|
|
- })
|
|
|
+
|
|
|
const fs = wx.getFileSystemManager();
|
|
|
|
|
|
let _this = this;
|
|
@@ -213,7 +218,6 @@ Page({
|
|
|
|
|
|
},
|
|
|
fail: (err) => {
|
|
|
- s
|
|
|
wx.hideLoading()
|
|
|
wx.showToast({
|
|
|
title: '读取该图片失败',
|
|
@@ -234,10 +238,23 @@ Page({
|
|
|
_this._downloadAndSaveFile(_this.data._imgTopPic)
|
|
|
return;
|
|
|
}
|
|
|
+
|
|
|
+ const res = wx.getSystemInfoSync(); // 获取系统信息
|
|
|
+ /// android ios
|
|
|
+ const platform = res.platform; // 获取平台类型
|
|
|
+ wx.showLoading({
|
|
|
+ title: '壁纸裁剪中',
|
|
|
+ })
|
|
|
// 读取裁剪的jpg图片
|
|
|
this.cropper.getImg((res) => {
|
|
|
- _this.data._imgTopPic = res.url
|
|
|
- _this._uploadImage(res.url)
|
|
|
+ if (platform === 'ios') {
|
|
|
+ this.cropper.getImg((res) => {
|
|
|
+ _this._uploadImgIOS(res.url)
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ _this.data._imgTopPic = res.url
|
|
|
+ _this._uploadImage(res.url)
|
|
|
+ }
|
|
|
});
|
|
|
},
|
|
|
_downloadAndSaveFile(url) {
|
|
@@ -350,14 +367,14 @@ Page({
|
|
|
// }
|
|
|
this.data._chunks = chunks;
|
|
|
},
|
|
|
- getImgMd5(buffer) {
|
|
|
- let md5ctx = js_md5.md5_init();
|
|
|
- js_md5.md5_update(md5ctx, buffer, buffer.byteLength ?? buffer.length);
|
|
|
- let result = js_md5.md5_final(md5ctx);
|
|
|
- let md5 = js_md5.md5_encode_hex(result, 16);
|
|
|
- console.log("result:", md5, result);
|
|
|
- return md5
|
|
|
- },
|
|
|
+ // getImgMd5(buffer) {
|
|
|
+ // let md5ctx = js_md5.md5_init();
|
|
|
+ // js_md5.md5_update(md5ctx, buffer, buffer.byteLength ?? buffer.length);
|
|
|
+ // let result = js_md5.md5_final(md5ctx);
|
|
|
+ // let md5 = js_md5.md5_encode_hex(result, 16);
|
|
|
+ // console.log("result:", md5, result);
|
|
|
+ // return md5
|
|
|
+ // },
|
|
|
sendImageMD5() {
|
|
|
// let lengthCode = this.data._chunks.length
|
|
|
// console.log("发送壁纸MD5 1:", lengthCode, this.data._imgMD5)
|
|
@@ -519,8 +536,8 @@ Page({
|
|
|
},
|
|
|
disconnect(event) {
|
|
|
let _this = this;
|
|
|
- console.log("断开连接", event.commonValue, event.deviceId);
|
|
|
- if (event.commonValue === "offline" && !_this.data._hasShowModal) {
|
|
|
+ console.log("断开连接--", event.commonValue, event.deviceId);
|
|
|
+ if (event.deviceId === _this.data._deviceId && event.commonValue === "offline" && !_this.data._hasShowModal) {
|
|
|
_this.data._hasShowModal = true
|
|
|
wx.showModal({
|
|
|
title: '提示',
|
|
@@ -547,7 +564,10 @@ Page({
|
|
|
let image = options.param
|
|
|
let json = JSON.parse(image)
|
|
|
console.log("裁剪页:", image)
|
|
|
- if (json.pic) {
|
|
|
+ let topImg = json.topImg ?? {}
|
|
|
+ let deviceId = json.deviceId;
|
|
|
+ _this.data._deviceId = deviceId
|
|
|
+ if (topImg.pic) {
|
|
|
this.hasImage(json)
|
|
|
} else {
|
|
|
console.log("没有图片")
|