From 2af5f043b60c1f7ac38ecccc8f5bf44743134325 Mon Sep 17 00:00:00 2001
From: cuiqian2004 <cuiqian2004@163.com>
Date: 星期五, 12 十二月 2025 18:08:00 +0800
Subject: [PATCH] test

---
 comm/utils.js |  128 ++++++++++++++++++++++++++++++++++++++----
 1 files changed, 116 insertions(+), 12 deletions(-)

diff --git a/comm/utils.js b/comm/utils.js
index 9e3ec1a..421a8dd 100644
--- a/comm/utils.js
+++ b/comm/utils.js
@@ -1,11 +1,26 @@
+import {
+	sendEmail as sendEmailAndroid
+} from './utils-android.js';
+import {
+	sendEmail as sendEmailiOS
+} from './utils-ios.js';
 
-var SESSION_SUFFIX = "diniu_app_"
-export function showModal(message, title = '鎻愮ず', iscancel = true) {
+const SESSION_SUFFIX = "diniu_app_"
+
+export function showModal({
+	content,
+	title = '',
+	showCancel = true,
+	confirmText,
+	cancelText
+}) {
 	return new Promise((resolve) => {
 		uni.showModal({
-			title: title,
-			content: message,
-			showCancel: iscancel,
+			title,
+			content,
+			showCancel,
+			confirmText,
+			cancelText,
 			success: function(res) {
 				if (res.confirm) {
 					resolve(true)
@@ -17,26 +32,115 @@
 	})
 }
 
-export function showToast(title, icon) {
-	uni.showToast({
-		title: title,
-		icon: icon ? icon : 'none'
-	})
+export function showToast(ex) {
+	if (!ex)
+		return
+	let tip = ex
+	// console.log(ex);
+	if (typeof ex !== "string") {
+		let exStr = JSON.stringify(ex)
+		if (exStr == "{}")
+			exStr = ex
+		tip = typeof ex.errMsg == "string" ? ex.errMsg : typeof ex.msg == "string" ? ex.msg : typeof ex.message ==
+			"string" ? ex.message : exStr
+	}
+	plus.nativeUI.toast(tip, {
+		duration: "short",
+		verticalAlign: "center"
+	});
+	// uni.showToast({
+	// 	title: title,
+	// 	icon: icon ? icon : 'none'
+	// })
+}
+export function showInfo(ex) {
+	if (!ex)
+		return
+	let tip = ex
+	// console.log(ex);
+	if (typeof ex !== "string") {
+		let exStr = JSON.stringify(ex)
+		if (exStr == "{}")
+			exStr = ex
+		tip = typeof ex.errMsg == "string" ? ex.errMsg : typeof ex.msg == "string" ? ex.msg : typeof ex.message ==
+			"string" ? ex.message : exStr
+	}
+	// plus.nativeUI.toast(tip, {
+	// 	duration: "short",
+	// 	verticalAlign:"center"
+	// });
+	return uni.showModal({
+		// title: "鎻愮ず",
+		content: tip,
+		showCancel: false
+	});
+}
+
+export function showError(ex, title = "") {
+	if (!ex)
+		return
+	let tip = ex
+	if (typeof ex !== "string") {
+		let exStr = JSON.stringify(ex)
+		if (exStr == "{}")
+			exStr = ex
+		tip = typeof ex.errMsg == "string" ? ex.errMsg : typeof ex.msg == "string" ? ex.msg : typeof ex.message ==
+			"string" ? ex.message : exStr
+	}
+	console.log(ex, tip)
+	//plus.nativeUI.alert(tip,title);
+	return uni.showModal({
+		title: title || "",
+		content: tip,
+		showCancel: false
+	});
 }
 export function showLoading(title) {
-
-
 	uni.showLoading({
 		title: title,
 		mask: true
 	})
+}
 
+
+export function hexToRGBA(hex, alpha) {
+	const r = parseInt(hex.slice(1, 3), 16);
+	const g = parseInt(hex.slice(3, 5), 16);
+	const b = parseInt(hex.slice(5, 7), 16);
+
+	return `rgba(${r}, ${g}, ${b}, ${alpha})`;
 }
 
 export function hideLoading() {
 
 	uni.hideLoading()
 }
+// 1. 鎶婁换鎰忔暟鎹啓鎴�txt 鏂囦欢
+export function saveAndSendEmail(data, fileName = 'report.txt') {
+	const fullPath = `_esgo/${fileName}`; // 娌欑洅鍐呰矾寰�+	plus.io.requestFileSystem(plus.io.PRIVATE_DOC, fs => {
+		fs.root.getFile(fullPath, {
+			create: true
+		}, fileEntry => {
+			fileEntry.createWriter(writer => {
+				writer.onwrite = () => {
+					// 鍐欏畬绔嬪嵆鍙戦偖浠�+					sendEmailWithAttach(fileEntry.fullPath);
+				};
+				writer.write(data); // data 鍙互鏄瓧绗︿覆/JSON
+			});
+		});
+	});
+}
+//甯﹂檮浠惰皟璧风郴缁熼偖浠跺鎴风
+export function sendEmailWithAttach(absPath) {
+	const platform = uni.getSystemInfoSync().platform;
+	if (platform === 'android') {
+		sendEmailAndroid(absPath);
+	} else if (platform === 'ios') {
+		sendEmailiOS(absPath);
+	}
+}
 
 let session = {
 	setValue(key, value) {

--
Gitblit v1.9.1