From 91a6d368073912a2e54bbd8c8a39c44d783881d8 Mon Sep 17 00:00:00 2001
From: zhangwei <1504152376@qq.com>
Date: 星期三, 28 八月 2024 17:03:00 +0800
Subject: [PATCH] 打卡相关
---
src/common/utils/util.js | 74 +++++++++++++++++++++++++++++++++++++
1 files changed, 74 insertions(+), 0 deletions(-)
diff --git a/src/common/utils/util.js b/src/common/utils/util.js
index 0d4f51e..e323207 100644
--- a/src/common/utils/util.js
+++ b/src/common/utils/util.js
@@ -133,6 +133,22 @@
parseInt(t[2], 10) || null
)).getTime() / 1000;
},
+ formatDate(dat, type) {
+ if(!dat){
+ return '-'
+ }
+ let date = new Date(dat)
+ console.log(date, dat, type);
+ const year = date.getFullYear();
+ const month = (date.getMonth() + 1).toString().padStart(2, '0');
+ const day = date.getDate().toString().padStart(2, '0');
+ const hours = date.getHours().toString().padStart(2, '0');
+ const minutes = date.getMinutes().toString().padStart(2, '0');
+ if (type) {
+ return `${year}-${month}-${day} ${hours}:${minutes}`;
+ }
+ return `${year}-${month}-${day}`;
+ },
/**
* 鍊掕鏃�
* @param {Object} seconds 绉�
@@ -695,6 +711,64 @@
}
}
typeof callback == 'function' && callback(theRequest);
+ },
+
+ /**
+ * 璺緞杞琤ase64
+ * @param {Object} string
+ */
+ pathToBase64(path) {
+ if (/^data:/.test(path)) return path
+ return new Promise((resolve, reject) => {
+ // #ifdef H5
+ let image = new Image();
+ image.setAttribute("crossOrigin", 'Anonymous');
+ image.onload = function() {
+ let canvas = document.createElement('canvas');
+ canvas.width = this.naturalWidth;
+ canvas.height = this.naturalHeight;
+ canvas.getContext('2d').drawImage(image, 0, 0);
+ let result = canvas.toDataURL('image/png')
+ resolve(result);
+ canvas.height = canvas.width = 0
+ }
+ image.src = path + '?v=' + Math.random()
+ image.onerror = (error) => {
+ reject(error);
+ };
+ // #endif
+
+ // #ifdef MP
+ if (uni.canIUse('getFileSystemManager')) {
+ uni.getFileSystemManager().readFile({
+ filePath: path,
+ encoding: 'base64',
+ success: (res) => {
+ resolve('data:image/png;base64,' + res.data)
+ },
+ fail: (error) => {
+ reject(error)
+ }
+ })
+ }
+ // #endif
+
+ // #ifdef APP-PLUS
+ plus.io.resolveLocalFileSystemURL(getLocalFilePath(path), (entry) => {
+ entry.file((file) => {
+ const fileReader = new plus.io.FileReader()
+ fileReader.onload = (data) => {
+ resolve(data.target.result)
+ }
+ fileReader.onerror = (error) => {
+ reject(error)
+ }
+ fileReader.readAsDataURL(file)
+ }, reject)
+ }, reject)
+ // #endif
+ })
}
+
}
--
Gitblit v1.9.1