封装测试

dev2
wangchen 2023-08-01 17:28:15 +08:00
parent 15dd186cb9
commit 29498a07a3
4 changed files with 3358 additions and 564 deletions

View File

@ -1,26 +1,63 @@
const formatTime = date => {
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
const hour = date.getHours()
const minute = date.getMinutes()
const second = date.getSeconds()
return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}
const formatDate = date => {
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
return [year, month, day].map(formatNumber).join('-')
}
const formatNumber = n => {
n = n.toString()
return n[1] ? n : '0' + n
}
module.exports = { module.exports = {
formatTime: formatTime, formatTime(date) {
formatDate: formatDate const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
const hour = date.getHours()
const minute = date.getMinutes()
const second = date.getSeconds()
return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(
':')
},
formatDate(date) {
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
return [year, month, day].map(formatNumber).join('-')
},
formatNumber(n) {
n = n.toString()
return n[1] ? n : '0' + n
},
compress(base64String, w, quality) {
console.log(base64String.length);
var getMimeType = (urlData) => {
var arr = urlData.split(",");
var mime = arr[0].match(/:(.*?);/)[1];
// return mime.replace("image/", "");
return mime;
};
var newImage = new Image();
var imgWidth, imgHeight;
var promise = new Promise((resolve) => (newImage.onload = resolve));
newImage.src = base64String;
return promise.then(() => {
imgWidth = newImage.width;
imgHeight = newImage.height;
var canvas = document.createElement("canvas");
var ctx = canvas.getContext("2d");
if (Math.max(imgWidth, imgHeight) > w) {
if (imgWidth > imgHeight) {
canvas.width = w;
canvas.height = (w * imgHeight) / imgWidth;
} else {
canvas.height = w;
canvas.width = (w * imgWidth) / imgHeight;
}
} else {
canvas.width = imgWidth;
canvas.height = imgHeight;
}
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.drawImage(newImage, 0, 0, canvas.width, canvas.height);
var base64 = canvas.toDataURL(getMimeType(base64String), quality);
console.log(base64);
return base64;
});
}
} }

3349
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,23 +1,27 @@
{ {
"id": "fjj-condition", "id": "fjj-condition",
"name": "tongtong-条件筛选", "name": "tongtong-条件筛选",
"version": "1.0.6", "version": "1.0.6",
"description": "支持单选多选筛选、日期范围筛选、数量或金额范围筛选, 兼容h5、微信小程序、其它端未测试", "description": "支持单选多选筛选、日期范围筛选、数量或金额范围筛选, 兼容h5、微信小程序、其它端未测试",
"keywords": [ "keywords": [
"筛选", "筛选",
"条件筛选", "条件筛选",
"多选", "多选",
"单选", "单选",
"日期筛选" "日期筛选"
], ],
"dcloudext": { "dcloudext": {
"category": [ "category": [
"前端组件", "前端组件",
"通用组件" "通用组件"
] ]
}, },
"dependencies": { "dependencies": {
"uuid": "^9.0.0", "imagemin": "^8.0.1",
"vant": "^2.12.54" "imagemin-mozjpeg": "^10.0.0",
} "imagemin-pngquant": "^9.0.2",
"imagemin-svgo": "^10.0.1",
"uuid": "^9.0.0",
"vant": "^2.12.54"
}
} }

View File

@ -17,6 +17,7 @@
</template> </template>
<script> <script>
import utils from '@/common/util.js';
var x = 20; var x = 20;
var y = 20; var y = 20;
var tempPoint = []; // var tempPoint = []; //
@ -139,8 +140,10 @@
canvasId: 'mycanvas', canvasId: 'mycanvas',
success: function(res) { success: function(res) {
let tempPath = res.tempFilePath; let tempPath = res.tempFilePath;
console.log(tempPath) console.log(tempPath,'压缩前')
//
let compressBase64Img = utils.compress(tempPath, 500, 0.3); //conpress
console.log(compressBase64Img,'压缩后');
const ctx = uni.createCanvasContext('camCacnvs', that); const ctx = uni.createCanvasContext('camCacnvs', that);
ctx.translate(0, that.width); ctx.translate(0, that.width);
ctx.rotate((-90 * Math.PI) / 180); ctx.rotate((-90 * Math.PI) / 180);
@ -165,8 +168,7 @@
}, 200); }, 200);
} }
}); });
} },
} }
}; };
</script> </script>