zjs_project 1 yıl önce
ebeveyn
işleme
a7a0704ec2

+ 55 - 32
src/components/newBottomCom/viewMask/viewMask.vue

@@ -209,7 +209,6 @@
 					this.showToast("请选中图片后再试!");
 			        return false;
 			    }
-			    let that = this;
 			    var para = {
 			        type: 'CLK', //埋点类型
 			        clkId: 'clk_2cmina_56', //点击ID,固定
@@ -219,7 +218,32 @@
 			        },
 			    }
 			    util.trackRequest(para);
-			    that.saveImageHandle(_resultImg);
+				if(navigator.userAgent.includes('miniProgram')){
+					this.showToast("请长按图片保存!");
+				}else{
+					this.saveImageHandle(_resultImg);
+				}
+			},
+			downloadIamge(imgsrc) {  //下载图片地址和图片名
+				var fileName = "4DImage" + util.formatDate(new Date(), "yyyyMMddhhmmss") + '.jpg';
+				const image = new Image();
+				// 解决跨域 Canvas 污染问题
+				image.setAttribute("crossOrigin", "anonymous");
+				image.onload = ()=> {
+					// let canvas = document.createElement("canvas");
+					// canvas.width = image.width;
+					// canvas.height = image.height;
+					// const context = canvas.getContext("2d");
+					// context.drawImage(image, 0, 0, image.width, image.height);
+					// const url = canvas.toDataURL("image/jpg"); //得到图片的base64编码数据
+					const a = document.createElement("a"); // 生成一个a元素
+					const event = new MouseEvent("click"); // 创建一个单击事件
+					a.download = fileName || "photo"; // 设置图片名称
+					a.href = imgsrc; // 将生成的URL设置为a.href属性
+					a.dispatchEvent(event); // 触发a的单击事件
+					this.showToast("保存成功!");
+				};
+				image.src = imgsrc;
 			},
 			saveImageHandle(_resultImg){
 				let param = {
@@ -232,37 +256,36 @@
 					}
 				};
 				util.trackRequest(param);
+				this.downloadIamge(_resultImg)
 				//表示图是临时文件,则可以直接保存
-				if (_resultImg.startsWith("http://tmp/") || _resultImg.startsWith("wxfile://")) {
-				    uni.saveImageToPhotosAlbum({
-				        filePath: _resultImg,
-				        success(result) {
-				            this.showToast("保存成功!");
-				        },
-				        fail(err) {
-				            // uni.hideLoading();
-				        }
-				    })
-				} else { //表示该图是网络图片,需要先下载才能保存
-				    console.log("***getSetting.save***网络图片", _resultImg);
-				    uni.downloadFile({
-				        url: _resultImg,
-				        success: function(res) {
-				            uni.saveImageToPhotosAlbum({
-				                filePath: res.tempFilePath,
-				                success(result) {
-									this.showToast("保存成功!");
-				                },
-				                fail(err) {
-				                    // uni.hideLoading();
-				                }
-				            })
-				        },
-				        fail(err) {
-				            // uni.hideLoading();
-				        }
-				    });
-				}
+				// if (_resultImg.startsWith("http://tmp/") || _resultImg.startsWith("wxfile://")) {
+				//     uni.saveImageToPhotosAlbum({
+				//         filePath: _resultImg,
+				//         success(result) {
+				//             this.showToast("保存成功!");
+				//         },
+				//         fail(err) {
+				//             // uni.hideLoading();
+				//         }
+				//     })
+				// } else { //表示该图是网络图片,需要先下载才能保存
+				//     console.log("***getSetting.save***网络图片", _resultImg);
+				//     uni.downloadFile({
+				//         url: _resultImg,
+				//         success: function(res) {
+				//             uni.saveImageToPhotosAlbum({
+				//                 filePath: res.tempFilePath,
+				//                 success(result) {
+				// 					this.showToast("保存成功!");
+				//                 },
+				//                 fail(err) {
+				//                 }
+				//             })
+				//         },
+				//         fail(err) {
+				//         }
+				//     });
+				// }
 			},
 		
 			//选项变更

+ 1 - 1
src/pages/webgl_rxdz/webgl_rxdz.vue

@@ -674,7 +674,7 @@
 						postAIData:this.aiData,
 					}
 				};
-				// util.trackRequest(trackparam);
+				util.trackRequest(trackparam);
 				let res = await requestConfig("saveCustomizedRecord", param);
 				if(res && res.success && res.single){//提交成功
 					let data = {

+ 136 - 105
src/utils/util.js

@@ -1,99 +1,125 @@
-import { getStorage } from '@/utils/localStorage';
+import {
+	getStorage
+} from '@/utils/localStorage';
 window.sessionTime = new Date();
 var util = {
-    reformParam(methodName,para) {
-        var parameter = {}
-        parameter['merchantid'] = '1'
-        parameter['version'] = '1'
-        parameter['sign_type'] = 'RSA'
-        parameter['sign'] = '123'
-        parameter['charset'] = 'UTF-8'
-        parameter['method'] = methodName
-        var context = ''
-        for(var key in para){
-            context += '&'+key+'='+para[key]
-        }
-        parameter['context'] = context
-        return parameter
-    },
+	reformParam(methodName, para) {
+		var parameter = {}
+		parameter['merchantid'] = '1'
+		parameter['version'] = '1'
+		parameter['sign_type'] = 'RSA'
+		parameter['sign'] = '123'
+		parameter['charset'] = 'UTF-8'
+		parameter['method'] = methodName
+		var context = ''
+		for (var key in para) {
+			context += '&' + key + '=' + para[key]
+		}
+		parameter['context'] = context
+		return parameter
+	},
+
+	dateFormat(date, fmt) {
+		let ret
+		const opt = {
+			'y+': date.getFullYear().toString(), // 年
+			'M+': (date.getMonth() + 1).toString(), // 月
+			'd+': date.getDate().toString(), // 日
+			'H+': date.getHours().toString(), // 时
+			'm+': date.getMinutes().toString(), // 分
+			's+': date.getSeconds().toString(), // 秒
+			// 有其他格式化字符需求可以继续添加,必须转化成字符串
+		}
+		for (let k in opt) {
+			ret = new RegExp('(' + k + ')').exec(fmt)
+			if (ret) {
+				fmt = fmt.replace(
+					ret[1],
+					ret[1].length == 1 ? opt[k] : opt[k].padStart(ret[1].length, '0')
+				)
+			}
+		}
+		return fmt
+	},
+	formatDate: function(date, fmt) {
+		if (/(y+)/.test(fmt)) {
+			fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
+		}
+		let o = {
+			'M+': date.getMonth() + 1,
+			'd+': date.getDate(),
+			'h+': date.getHours(),
+			'm+': date.getMinutes(),
+			's+': date.getSeconds()
+		}
+		for (let k in o) {
+			if (new RegExp(`(${k})`).test(fmt)) {
+				let str = o[k] + ''
+				fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? str : this.padLeftZero(str))
+			}
+		}
+		return fmt
+	},
+	padLeftZero: function(str) {
+		return ('00' + str).substr(str.length)
+	},
+	formatDatetime(val, format) {
+		const year = val.getFullYear();
+		const month = val.getMonth() + 1;
+		const day = val.getDate();
+		const hour = val.getHours();
+		const minute = val.getMinutes();
+		const second = val.getSeconds();
+		return year + '-' + (month > 9 ? month : '0' + month) + '-' + day + ' ' + hour + ':' + (minute > 9 ?
+			minute : '0' + minute) + ':' + (second > 9 ? second : '0' + second);
 
-    dateFormat(date , fmt) {
-        let ret
-        const opt = {
-            'y+': date.getFullYear().toString(), // 年
-            'M+': (date.getMonth() + 1).toString(), // 月
-            'd+': date.getDate().toString(), // 日
-            'H+': date.getHours().toString(), // 时
-            'm+': date.getMinutes().toString(), // 分
-            's+': date.getSeconds().toString(), // 秒
-            // 有其他格式化字符需求可以继续添加,必须转化成字符串
-        }
-        for (let k in opt) {
-            ret = new RegExp('(' + k + ')').exec(fmt)
-            if (ret) {
-                fmt = fmt.replace(
-                  ret[1],
-                  ret[1].length == 1 ? opt[k] : opt[k].padStart(ret[1].length, '0')
-                )
-            }
-        }
-        return fmt
-    },
-    formatDatetime(val,format){
-        const year = val.getFullYear();
-        const month = val.getMonth()+1;
-        const day = val.getDate();
-        const hour = val.getHours();
-        const minute = val.getMinutes();
-        const second = val.getSeconds();
-        return year+'-'+(month>9?month:'0'+month)+'-'+day+' '+hour+':'+(minute>9?minute:'0'+minute)+':'+(second>9?second:'0'+second);
+	},
+	formatDayTime(val) {
+		const year = val.getFullYear();
+		const month = val.getMonth() + 1;
+		const day = val.getDate();
+		const hour = val.getHours();
+		const minute = val.getMinutes();
+		const second = val.getSeconds();
+		return year + '-' + (month > 9 ? month : '0' + month) + '-' + day + ' ' + hour + ':' + (minute > 9 ?
+			minute : '0' + minute);
+	},
+	formatTodayTime(val) {
+		const year = val.getFullYear();
+		const month = val.getMonth() + 1;
+		const day = val.getDate();
+		const hour = val.getHours();
+		const minute = val.getMinutes();
 
-    },
-    formatDayTime(val){
-        const year = val.getFullYear();
-        const month = val.getMonth()+1;
-        const day = val.getDate();
-        const hour = val.getHours();
-        const minute = val.getMinutes();
-        const second = val.getSeconds();
-        return year+'-'+(month>9?month:'0'+month)+'-'+day+' '+hour+':'+(minute>9?minute:'0'+minute);
-    },
-    formatTodayTime(val){
-        const year = val.getFullYear();
-        const month = val.getMonth()+1;
-        const day = val.getDate();
-        const hour = val.getHours();
-        const minute = val.getMinutes();
+		if (month == new Date().getMonth() + 1 && day + 1 == new Date().getDate()) {
+			return '昨天' + hour + ':' + (minute > 9 ? minute : '0' + minute);
+		} else if (month == new Date().getMonth() + 1 && day == new Date().getDate()) {
 
-        if(month==new Date().getMonth()+1&&day+1==new Date().getDate()){
-            return '昨天'+hour+':'+(minute>9?minute:'0'+minute);
-        }
-        else if(month==new Date().getMonth()+1&&day==new Date().getDate()){
+			return hour + ':' + (minute > 9 ? minute : '0' + minute);
+		} else {
+			return year + '-' + (month > 9 ? month : '0' + month) + '-' + day + ' ' + hour + ':' + (minute > 9 ?
+				minute : '0' + minute);
+		}
+	},
 
-            return hour+':'+(minute>9?minute:'0'+minute);
-        }else{
-            return year+'-'+(month>9?month:'0'+month)+'-'+day+' '+hour+':'+(minute>9?minute:'0'+minute);
-        }
-    },
+	/**
+	 * 计算天数
+	 * @param date1
+	 * @param date2
+	 * @returns {number}
+	 * @constructor
+	 */
+	getNumberOfDays(date1, date2) { //获得天数
+		if (!date1 || !date2) {
+			return 0;
+		}
+		//date1:开始日期,date2结束日期
+		var a1 = Date.parse(new Date(date1));
+		var a2 = Date.parse(new Date(date2));
+		var day = parseInt((a2 - a1) / (1000 * 60 * 60 * 24)) + 1; //核心:时间戳相减,然后除以天数
+		return day
+	},
 
-    /**
-     * 计算天数
-     * @param date1
-     * @param date2
-     * @returns {number}
-     * @constructor
-     */
-    getNumberOfDays(date1,date2){//获得天数
-        if(!date1 || !date2){
-            return 0;
-        }
-        //date1:开始日期,date2结束日期
-        var a1 = Date.parse(new Date(date1));
-        var a2 = Date.parse(new Date(date2));
-        var day = parseInt((a2-a1)/ (1000 * 60 * 60 * 24)) + 1;//核心:时间戳相减,然后除以天数
-        return day
-    },
-	
 	getUrlParams(url) {
 		url = url == null ? window.location.href : url;
 		var search = url.substring(url.lastIndexOf("?") + 1);
@@ -117,18 +143,19 @@ var util = {
 		var hour = date.getHours()
 		var minute = date.getMinutes()
 		var second = date.getSeconds()
-		return [year, month, day].map(this.formatNumber).join('-') + ' ' + [hour, minute, second].map(this.formatNumber).join(
+		return [year, month, day].map(this.formatNumber).join('-') + ' ' + [hour, minute, second].map(this
+			.formatNumber).join(
 			':')
 	},
 	formatNumber(n) {
 		n = n.toString()
 		return n[1] ? n : '0' + n
 	},
-	trackRequest(para, app = null ) {
-	    if ((para.type && para.type.includes('Error'))) {
-	        //所有报错埋点以及曝光埋点不再发送至服务器
-	        return
-	    }
+	trackRequest(para, app = null) {
+		if ((para.type && para.type.includes('Error'))) {
+			//所有报错埋点以及曝光埋点不再发送至服务器
+			return
+		}
 		try {
 			var session = Number(getStorage('sessionNumber')) + 1;
 			let data = {
@@ -137,7 +164,8 @@ var util = {
 				browserName: navigator.appName || '',
 				browserVersion: navigator.appVersion.substring(0, 255) || '',
 				platform: location.href.indexOf("shareSign") > -1 ? 'h5' : 'tfb', //iframeUrl代表是顾问分享的外链
-				fromPlatform: util.getUrlParams(location.href).fromPlatform || util.getUrlParams(location.href).fromProduce ||'tfb',
+				fromPlatform: util.getUrlParams(location.href).fromPlatform || util.getUrlParams(location.href)
+					.fromProduce || 'tfb',
 				deviceType: '' || "",
 				ip: window.ip || '',
 				cookieId: from_cookie || getStorage("cookie_id") || '',
@@ -148,7 +176,8 @@ var util = {
 				uploadTime: this.formatTime(new Date()),
 				product: location.href.indexOf("shareSign") > -1 ? 'h5' : 'tfb', //iframeUrl代表是顾问分享的外链
 				project: para.project,
-				brandId: util.getUrlParams(location.href).special_ID || util.getUrlParams(location.href).brandId || null,
+				brandId: util.getUrlParams(location.href).special_ID || util.getUrlParams(location.href)
+					.brandId || null,
 				// expand:typeof para.expand==='object'?JSON.stringify(para.expand):para.expand,//扩展字段
 				expand: JSON.stringify(util.getUrlParams(location.href)), //扩展字段
 				imTalkId: para.imTalkId || '', //IM对话编号
@@ -162,10 +191,12 @@ var util = {
 				clkId: para.clkId || '', //点击ID
 				clkName: para.clkName || '',
 				pvId: para.pvId || '', //PV埋点ID
-				clkParams: typeof para.clkParams === 'object' ? JSON.stringify(para.clkParams) : para.clkParams, //点击参数
+				clkParams: typeof para.clkParams === 'object' ? JSON.stringify(para.clkParams) : para
+				.clkParams, //点击参数
 				pvPageStayTime: para.pvPageStayTime || '',
 				pvCurPageName: para.pvCurPageName || '', //当前页面名称
-				pvCurPageParams: typeof para.pvCurPageParams === 'object' ? JSON.stringify(para.pvCurPageParams) : para.pvCurPageParams ||
+				pvCurPageParams: typeof para.pvCurPageParams === 'object' ? JSON.stringify(para
+					.pvCurPageParams) : para.pvCurPageParams ||
 					'', //当前页面参数
 				pvLastPageName: para.pvLastPageName || '', //上一页页面名称
 				pvLastPageParams: para.pvLastPageParams || '', //上一页页面参数
@@ -194,17 +225,17 @@ var util = {
 			// 	"\u0000"
 			// ];
 			// app.wsSendOrder(param,data);//socket 消息发送
-			console.warn("***mook***",(data.pvId || data.clkId || data.eventId),data.reserve3)
+			console.warn("***mook***", (data.pvId || data.clkId || data.eventId), data.reserve3)
 		} catch (e) {
 			console.warn("***util.js-onError***", e);
 		}
 	},
-	getSession(){//获取session
+	getSession() { //获取session
 		let timeNow = new Date().getTime();
-		let session = uni.getStorageSync('sessionNumber') || timeNow;//session具体的值
+		let session = uni.getStorageSync('sessionNumber') || timeNow; //session具体的值
 		uni.setStorage({
-		    key: "sessionNumber",
-		    data: session
+			key: "sessionNumber",
+			data: session
 		})
 		return session;
 	},
@@ -212,4 +243,4 @@ var util = {
 window.from_session = util.getUrlParams(location.href).session || '';
 window.from_cookie = util.getUrlParams(location.href).cookie || '';
 export default util;
-// module.exports = util;
+// module.exports = util;