From be714117a5879fb07a9a28f770d74c180d891f11 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=B0=B1=E7=9C=A0=E4=BB=AA=E5=BC=8F?= <854085467@qq.com>
Date: Sat, 21 Nov 2020 22:07:28 +0800
Subject: [PATCH] add convert module and imageToBase64 api
---
component/pear/modules/convert.js | 27 ++++++++++++++++++++++++++
component/pear/pear.js | 3 ++-
index.html | 19 ++++--------------
view/system/operate/uploadProfile.html | 16 +++++++--------
4 files changed, 40 insertions(+), 25 deletions(-)
create mode 100644 component/pear/modules/convert.js
diff --git a/component/pear/modules/convert.js b/component/pear/modules/convert.js
new file mode 100644
index 0000000..c0e6af4
--- /dev/null
+++ b/component/pear/modules/convert.js
@@ -0,0 +1,27 @@
+layui.define(['jquery', 'element'], function(exports) {
+ "use strict";
+
+ /**
+ * 数 字 滚 动 组 件
+ * */
+ var MOD_NAME = 'convert',
+ $ = layui.jquery,
+ element = layui.element;
+
+ var convert = new function() {
+
+ // image 转 base64
+ this.imageToBase64 = function(img) {
+ var canvas = document.createElement("canvas");
+ canvas.width = img.width;
+ canvas.height = img.height;
+ var ctx = canvas.getContext("2d");
+ ctx.drawImage(img, 0, 0, img.width, img.height);
+ var ext = img.src.substring(img.src.lastIndexOf(".")+1).toLowerCase();
+ var dataURL = canvas.toDataURL("image/"+ext);
+ return dataURL;
+ }
+
+ }
+ exports(MOD_NAME, convert);
+});
diff --git a/component/pear/pear.js b/component/pear/pear.js
index acc4595..d369034 100644
--- a/component/pear/pear.js
+++ b/component/pear/pear.js
@@ -38,5 +38,6 @@ layui.config({
dropdown: "dropdown",
card: "card",
loading: "loading",
- cropper:"cropper"
+ cropper:"cropper",
+ convert:"convert"
});
diff --git a/index.html b/index.html
index a584b57..8513109 100644
--- a/index.html
+++ b/index.html
@@ -72,31 +72,20 @@