import requestConfig from '../lib/requestConfig.js'; import CryptoJS from '@/common/static/crypto-js.min.js'; const config = require('../config.js'); let setIntervalKey; const keys = "ELAB_ADLWROEMSAQ"; const iv = "ELAB_LIDERT_WEDH"; function formatNumber(n) { n = n.toString() return n[1] ? n : '0' + n } var util = { formatTime: function(date) { var year = date.getFullYear() var month = date.getMonth() + 1 var day = date.getDate() var hour = date.getHours() var minute = date.getMinutes() var second = date.getSeconds() return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join( ':') }, formatCNTime: function(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) + '分' + second + '秒'; }, formatCNTime1: function(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 > 9 ? day : '0' + day) + '日'; }, buttonClicked(self, time) { self.setData({ buttonClicked: false }) setTimeout(function() { self.setData({ buttonClicked: true }) }, time) }, formatTodayTime: function(val) { if (typeof val !== 'object') { console.log('时间格式不对,不予转换') return 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(); 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) + ':' + (second > 9 ? second : '0' + second); } else { return year + '-' + (month > 9 ? month : '0' + month) + '-' + (day > 9 ? day : '0' + day) + ' ' + hour + ':' + ( minute > 9 ? minute : '0' + minute) + ':' + (second > 9 ? second : '0' + second); } }, formatMinuteTime: function(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 > 9 ? day : '0' + day) + ' ' + hour + ':' + ( minute > 9 ? minute : '0' + minute) }, formatSucTime: function(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()) { return hour + ':' + (minute > 9 ? minute : '0' + minute); } else { return year + '-' + (month > 9 ? month : '0' + month) + '-' + day + ' ' + hour + ':' + (minute > 9 ? minute : '0' + minute); } }, async sendScoreShare() { const app = getApp(); const res = await requestConfig('intergralShare', { customerId: app.globalData.single.id, brandId: config.brandId, houseId: config.houseId || '', }); }, trackRequest(para, app = getApp()) { if ((para.type && para.type.includes('Error'))) { //所有报错埋点以及曝光埋点不再发送至服务器 return } if (JSON.stringify(para.clkParams) === '"{}"' || JSON.stringify(para.clkParams) === "{}") { para.clkParams = ''; } if (JSON.stringify(para.expand) === '"{}"' || JSON.stringify(para.expand) === "{}") { para.expand = ''; } let _scene = (app.globalData.launchInfo && app.globalData.launchInfo.scene) ? app.globalData.launchInfo.scene : ''; console.log("app.globalData.launchInfo:" + JSON.stringify(app.globalData.launchInfo)); let _fromParam = app.globalData.exchangedFromChannel ? JSON.parse(app.globalData.exchangedFromChannel) : {}; //上一个页面 let lastPage = getCurrentPages()[getCurrentPages().length-2] ? getCurrentPages()[getCurrentPages().length-2].$vm : null; let _pvLastPageName = lastPage ? lastPage.pvCurPageName : '';//上一页面名称 let _pvLastPageParams = (lastPage && lastPage.pvCurPageParams) ? lastPage.pvCurPageParams : '';//上一页面参数 let _pvLastPagePath = lastPage ? (lastPage.route || lastPage.__route__) : '';//上一页面路径 let currPage = getCurrentPages()[getCurrentPages().length-1] ? getCurrentPages()[getCurrentPages().length-1].$vm : null; let _route = currPage ? (currPage.route || currPage.__route__) : ""; let _pvCurPageName = currPage ? currPage.pvCurPageName : '';//当前页面名称 let pvCurPageParams = "";//字符串string对象 if(para.pvCurPageParams){//调用的时候传递进来的-先转为对象 pvCurPageParams = typeof para.pvCurPageParams === 'object' ? para.pvCurPageParams : JSON.parse(para.pvCurPageParams) }else{ let _tmp = (currPage && currPage.pvCurPageParams) ? currPage.pvCurPageParams : '{}';//获取当前页面的参数 pvCurPageParams = typeof _tmp === 'string' ? JSON.parse(_tmp) : JSON.parse(JSON.stringify(_tmp)) } //在页面参数里面手动添加path参数 pvCurPageParams.brandId = config.brandId || ""; pvCurPageParams.path = _route; pvCurPageParams.pageId = currPage.pageId || ""; pvCurPageParams.mobile = app.globalData.phone || ""; pvCurPageParams.entryPageId = (lastPage && lastPage.pageId) ? lastPage.pageId : ""; pvCurPageParams.entryPagePath = _pvLastPagePath; pvCurPageParams = JSON.stringify(pvCurPageParams); if(para.clkId==='clk_2cmina_18'){ this.sendScoreShare() } if (JSON.stringify(pvCurPageParams) === '"{}"' || JSON.stringify(pvCurPageParams) === "{}") { pvCurPageParams = ''; } _fromParam["scene"] = _scene; _fromParam["appName"] = app.globalData.systemInfo ? app.globalData.systemInfo.appName : (app.$vm.$options.globalData.systemInfo.appName || ""); _fromParam['eventtime'] = Date.now(); let houseID = ""; if (currPage && currPage.houseId) { houseID = currPage.houseId; } if (currPage && (currPage.route == 'pages/shareCard/shareCard' || currPage.__route__ == 'pages/shareCard/shareCard')) { let enterPage = getCurrentPages()[getCurrentPages().length - 2] ? getCurrentPages()[getCurrentPages().length - 2].$vm : null; if (enterPage && enterPage.houseId) { houseID = enterPage.houseId; } } console.log("houseID:" + houseID); let data = { userAgent: '', browserName: '', browserVersion: app.globalData.systemInfo ? app.globalData.systemInfo.SDKVersion : app.$vm.$options.globalData.systemInfo.SDKVersion, platform: 'miniapp', //是否来自小程序的标志 fromPlatform: '', //来源平台,需要汤勇提供接口解析fromChannel存放 reserve1: app.globalData.terminal, //来源平台,抖音百度微信 reserve2: app.globalData.selectCityName || app.globalData.defaultProductCityName, //当前所在城市 fromParam: JSON.stringify(_fromParam), //转发者秘钥 deviceType: app.globalData.systemInfo ? app.globalData.systemInfo.model : (app.$vm.$options.globalData.systemInfo.SDKVersion || ""), //设备系统信息 ip: app.globalData.ip || '', //ip地址 cookieId: '', openId: app.globalData.openid || '', //openid customerId: (app.globalData.single && app.globalData.single.id) ? app.globalData.single.id : '', //用户id brandUserId: (app.globalData.single && app.globalData.single.id) ? app.globalData.single.id : '', //用户id createTime: this.formatTime(new Date()), //发送埋点时间 uploadTime: this.formatTime(new Date()), //发送埋点时间 product: app.globalData.projectName, //当前所在项目中文名称 project: houseID, //当前项目id eventId: para.eventId || '', //埋点ID eventName: para.eventName || '', //埋点ID expand: typeof para.expand === 'object' ? JSON.stringify(para.expand) : para.expand, //扩展字段 imTalkId: para.imTalkId || '', //IM对话编号 imTalkType: para.imTalkType || '', //IM对话类型 eventModuleDes: para.eventModuleDes || '', //模块描述信息 eventInnerModuleId: para.eventInnerModuleId || '', //事件内部模块信息 adviserId: para.adviserId || '', //顾问id clkDesPage: para.clkDesPage || _pvCurPageName || '', //点击前往的页面名称 clkId: para.clkId || '', //点击ID clkName: para.clkName || '', pvId: para.pvId || '', //PV埋点ID clkParams: typeof para.clkParams === 'object' ? JSON.stringify(para.clkParams) : para.clkParams, //点击参数 pvPageStayTime: para.pvPageStayTime || '', pvCurPageName: para.pvCurPageName || _pvCurPageName || '', //当前页面名称 pvCurPageParams: pvCurPageParams, //当前页面参数 pvLastPageName: para.pvLastPageName || _pvLastPageName || '', //上一页页面名称 pvLastPageParams: para.pvLastPageParams || _pvLastPageParams || '', //上一页页面参数 pvPageLoadTime: para.pvPageLoadTime || '', //加载时间 type: para.type || '', //埋点类型 longitude: app.globalData.longitude || '', //经度 latitude: app.globalData.latitude || '', //纬度 brandId: config.brandId //集团id }; let timeNow = new Date().getTime(); let session = uni.getStorageSync('sessionNumber') || timeNow; let sessionTime = uni.getStorageSync('sessionTime') || timeNow; if (timeNow - sessionTime > 180000) { session = timeNow; // wx.setStorageSync('sessionNumber', session) uni.setStorage({ key: "sessionNumber", data: session }) } else { // wx.setStorageSync('sessionNumber', session) uni.setStorage({ key: "sessionNumber", data: session }) } // wx.setStorageSync('sessionTime', timeNow) uni.setStorage({ key: "sessionTime", data: timeNow }) data.session = data.brandUserId + '_' + session; app.globalData.session_id = data.session app.globalData.sessionTime = timeNow; // requestConfig('upload', data, true); let param = ["SEND" + "\nproject:" + "elab-marketing-system" + "\nmethod:" + 'POST' + "\npath:" + '/behavior/brandMiniWeb/upload' + "\ndestination:" + '/ws/remote/invoke' + "\n\n" + JSON.stringify(data) + "\u0000" ]; app.wsSendOrder(param);//socket 消息发送 }, async shareToken(app) { const res = await requestConfig('sign', { customerId: app.globalData.single.id, houseId: config.houseId, userRole: 0 }); if (res && res.success && res.single) { app.globalData.shareToken = res.single || ""; } }, //此时此刻日期转化 timesData: function(timestamp) { var date = new Date(timestamp); var Y = date.getFullYear() + '/'; var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '/'; var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' '; // var h = (date.getHours() < 10 ? '0'+(date.getHours()) : date.getHours()) + ':'; // var m = (date.getMinutes() < 10 ? '0'+(date.getMinutes()) : date.getMinutes()); return Y + M + D; }, //此时此刻日期转化格式 dateFormat: function (timestamp) { var date = new Date(timestamp); var Y = date.getFullYear() + '年'; var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '月'; var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + '日 '; var h = (date.getHours() < 10 ? '0'+(date.getHours()) : date.getHours()) + ':'; var m = (date.getMinutes() < 10 ? '0'+(date.getMinutes()) : date.getMinutes()) + ':'; var s = (date.getSeconds() < 10 ? '0'+(date.getSeconds()) : date.getSeconds()); return Y + M + D + h + m + s; }, //此时此刻日期转化格式 dateFormats: function (timestamp) { var date = new Date(timestamp); var Y = date.getFullYear() + '年'; var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '月'; var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + '日 '; return Y + M + D; }, //此时此刻时间转化 timestampToTime: function(timestamp) { var date = new Date(timestamp); var h = (date.getHours() < 10 ? '0' + (date.getHours()) : date.getHours()) + ':'; var m = (date.getMinutes() < 10 ? '0' + (date.getMinutes()) : date.getMinutes()); return h + m; }, 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) }, /** * 先从微信小程序获取当前位置的经纬度; * 再从腾讯地图依据经纬度获取当前的地理位置信息. * successBack:成功回调,包含地理位置信息 * failBack:失败回调,包含失败的信息 */ getLocalPositionInformationFromTencent(successBack, failBack, isFirstIn, force) { const app = getApp(); //获取应用实例 uni.getLocation({ type: 'wgs84', success(res) { const latitude = res.latitude; //纬度,范围为 -90~90,负数表示南纬 const longitude = res.longitude; //经度,范围为 -180~180,负数表示西经 app.globalData.longitude = longitude; app.globalData.latitude = latitude; let getAddressUrl = "https://apis.map.qq.com/ws/geocoder/v1/?location=" + latitude + "," + longitude + "&key=AKWBZ-SVPC5-Z4WIT-Q2UOM-55O7O-76FV5&get_poi=1"; wx.request({ url: getAddressUrl, headers: { 'Content-Type': 'application/json' }, success: async function(result) { let resultData = result.data.result; if (successBack) { successBack(resultData); } }, fail: function(result) { if (failBack) { failBack(result); } } }); }, fail(res) { if (isFirstIn) { let para = { clkDesPage: '', //点击前往的页面名称 type: 'CLK', //埋点类型 clkId: 'clk_2cmina_137', //点击ID,固定 clkName: "wechatauthorize-location", //点击名称 clkParams: { "wx.authorize.scope": "wx.getLocation", "type": 'fail', }, }; util.trackRequest(para); console.log(res, 'ssssssssssssss') wx.showToast({ title: '授权失败', duration: 3000, icon: 'none' }); } else if (force) { wx.showToast({ title: '授权失败', duration: 1500, icon: 'none' }); } if (failBack) { failBack(res); } } }); }, /** * 获取微信地理位置信息 * @param force 是否强授权 * force=true: 只要调用就弹起授权弹窗 * force=false: 若拒绝过授权,则不再弹起授权弹窗 */ getPosition(successBack, failBack, force = false) { wx.getSetting({ success: (results) => { if (results.authSetting['scope.userLocation'] == undefined) { //该用户还没有弹起地理位置授权,可视为第一次进入小程序 var para = { type: 'EXP', //埋点类型 eventId: 'exp_2cmina_22', //点击ID,固定 eventName: "diliweizhishouquan", //点击名称 event_param: { "wx.authorize.scope": "wx.getLocation", }, } // util.trackRequest(para); if (successBack) { successBack({ firstIn: true }); } } else { if (!results.authSetting['scope.userLocation']) { if (force) { wx.showModal({ title: '请求授权当前位置', content: '是否开启地理位置授权,定位当前所在城市', cancelText: "下次再说", confirmText: "去开启", success: function(res) { if (res.cancel) { wx.showToast({ title: '授权失败', icon: 'none', duration: 1000 }); if (failBack) { failBack(); } } else if (res.confirm) { wx.openSetting({ success: function(dataAu) { if (dataAu.authSetting[ "scope.userLocation"] == true) { //再次授权,调用wx.getLocation的API if (successBack) { successBack({ firstIn: false }); } } else { if (failBack) { failBack(); } } }, fail: function() { wx.showToast({ title: '授权失败', icon: 'none', duration: 1000 }); } }) } } }) } else { console.log('上次登录的时候拒绝了授权') if (failBack) { failBack(); } } } else { console.log('上次登录的时候允许了授权') if (successBack) { successBack({ firstIn: false }); } } } } }) }, /** * 检查目标城市是否有效; * 将目标城市和上次选择的城市进行比较; * currentCityName:当前定位的城市名称 * currentCityCode:当前定位的城市code */ async compareCurrentCityWithHistoryCity(currentCityName, currentCityCode, successBack, failBack, firstInAPP) { const that = this; const app = getApp(); let param = { cityName: currentCityName, brandId: config.brandId, customerId: app.globalData.single.id || '', simplify: true }; const res = await requestConfig('queryCityData', param); if (res.success && res.single) { if (res.single.inCityData) { if (!res.single.currentCity) { that.addCustomerCity(1, currentCityName, currentCityCode, successBack, failBack); } else if (res.single.currentCity.cityName == currentCityName) { //定位的城市和上次选择的城市一样 app.globalData.selectCityCode = res.single.currentCity.cityCode; app.globalData.selectCityName = res.single.currentCity.cityName; if (successBack) { successBack(); } } else { let currPage = getCurrentPages()[getCurrentPages().length - 1] ? getCurrentPages()[ getCurrentPages().length - 1] .$vm : null; let currentRoute = currPage['route']; if (!app.globalData.cityChangeTips && currentRoute != '/subPackage/pages/addressModule/addressModule') { app.globalData.cityChangeTips = true; /*wx.showModal({ title: '是否切换城市', content: '您当前定位城市与产品系列城市不一致,是否切换至定位城市', cancelText:"取消", confirmText:"切换", success: function (modelRes) { if (modelRes.cancel) {//点击取消 if(failBack){ failBack(); } } else if (modelRes.confirm) {//点击切换 that.addCustomerCity(1,currentCityName,currentCityCode,successBack,failBack); } }, })*/ if (successBack) { successBack(true); } } else { if (failBack) { failBack(); } } } } else { /* let re = await requestConfig('addCustomerCity',{ city:currentCityName, brandId:config.brandId, customerId:app.globalData.single.id, cityCode:currentCityCode, citySource:1 });*/ /* app.globalData.selectCityCode = currentCityCode; app.globalData.selectCityName = currentCityName;*/ if (firstInAPP) { wx.showToast({ title: '定位城市暂未开放,先看看其他城市吧', duration: 2500, icon: 'none' }); } if (failBack) { failBack(); } } } else { wx.showToast({ title: '网络连接出现问题', duration: 1500, icon: 'none' }); if (failBack) { failBack(); } } }, /** * 添加客户城市位置 * type: * 1:用户授权城市; * 2:选择定位城市. * currentCityName:当前城市名 * currentCityCode:当前城市code */ async addCustomerCity(type, currentCityName, currentCityCode, successBack, failBack) { const app = getApp(); //获取应用实例 let re = await requestConfig('addCustomerCity', { city: currentCityName, brandId: config.brandId, customerId: app.globalData.single.id, cityCode: currentCityCode, citySource: type }); if (re.success) { if (type == 1) { /*wx.showToast({ title:`已为您切换至${currentCityName}!`, icon:'none', duration:1500 });*/ } app.globalData.selectCityCode = currentCityCode; app.globalData.selectCityName = currentCityName; if (successBack) { successBack(); } } else { if (failBack) { failBack(); } } }, /** * 精确处理小数点 为了解决Elab房贷计算器跨平台浮点运算差值,写了此套算法 * @param value 要处理的布尔数值 * @param length 精确的小数点的位数 * @param accurate 是否四舍五入 * @returns {string} */ handlePoint(value, length, accurate = false) { if (value.toString().split('.')[1] && (value.toString().split('.')[1]).length > length) { let startValue = value.toString().split('.')[0]; let endValue = value.toString().split('.')[1]; if (accurate) { let markValue = parseInt(endValue.toString().slice(length, length + 1)); if (markValue >= 5) { endValue = endValue.toString().slice(0, length); endValue = parseInt(endValue) + 1; if (endValue.toString().length > length) { startValue = parseInt(startValue) + 1; endValue = endValue.toString().slice(1, length + 1); } else if (endValue.toString().length < length) { let markLength = length - endValue.toString().length; let str = ''; for (let i = 0, len = markLength; i < len; i++) { str += '0'; } endValue = str + endValue; } } else { endValue = endValue.toString().slice(0, length); } } else { endValue = endValue.toString().slice(0, length); } /*if (parseInt(endValue) == 0) { value = startValue; } else { value = startValue + '.' + endValue; }*/ value = startValue + '.' + endValue; } return value; }, getPageTheme(val){ if (val ==-1){ //浅色模式,白底黑字 return { textColor1:'rgba(18,18,18,1)', //主文字颜色 textColor2:'rgba(18,18,18,0.5)', //副文字颜色 textColor3:'rgba(18,18,18,0.2)', //副文字颜色 bgColor:'rgba(255,255,255,1)', //主背景颜色 bgColor2:'rgba(255,255,255,1)', //副背景颜色 bgColor3:'rgba(255,255,255,1)', //副背景颜色 } }else if (val ==1){ //深色模式,黑底白字 return { textColor1:'rgba(255,255,255,1)', textColor2:'rgba(255,255,255,0.5)', textColor3:'rgba(255,255,255,0.2)', bgColor:'rgba(18,18,18,1)', bgColor2:'rgba(255,255,255,0.1)', bgColor3:'rgba(255,255,255,0.3)', } }else{ //浅色模式,白底黑字,默认浅色模式 return { textColor1:'rgba(18,18,18,1)', //主文字颜色 textColor2:'rgba(18,18,18,0.5)', //副文字颜色 textColor3:'rgba(18,18,18,0.2)', //副文字颜色 bgColor:'rgba(255,255,255,1)', //主背景颜色 bgColor2:'rgba(255,255,255,1)', //副背景颜色 bgColor3:'rgba(255,255,255,1)', //副背景颜色 } } }, /** * 加密参数 * @param content * @returns {string} * @constructor */ AES_encrypt(content) { content = JSON.stringify(content); let param = CryptoJS.enc.Utf8.parse(content); let _key = CryptoJS.enc.Utf8.parse(keys); let _iv = CryptoJS.enc.Utf8.parse(iv); let encrypted = CryptoJS.AES.encrypt(param, _key, { mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7, iv: _iv, }); return encrypted.ciphertext.toString(); }, /** * 解密参数 * @param content * @returns {string} * @constructor */ AES_decrypt(content) { let receive = CryptoJS.enc.Hex.parse(content); receive = CryptoJS.enc.Base64.stringify(receive); let _key = CryptoJS.enc.Utf8.parse(keys); let _iv = CryptoJS.enc.Utf8.parse(iv); var decrypt = CryptoJS.AES.decrypt(receive, _key, { mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7, iv:_iv }); console.log("555555555555555",decrypt); return decrypt.toString(CryptoJS.enc.Utf8); }, hexToRgba(hex, opacity) { if (!hex||!opacity){ return hex } let RGBA; if (hex.includes('#')&&hex.length==7){ RGBA = "rgba(" + parseInt("0x" + hex.slice(1, 3)) + "," + parseInt("0x" + hex.slice(3, 5)) + "," + parseInt("0x" + hex.slice(5, 7)) + "," + opacity + ")"; }else if (hex.includes('rgb(')){ var values = hex .replace(/rgb?\(/, '') .replace(/\)/, '') .replace(/[\s+]/g, '') .split(',') return `rgba(${values[0]},${values[1]},${values[2]},${opacity})` }else if(hex.includes('rgba(')){ var values = hex .replace(/rgba?\(/, '') .replace(/\)/, '') .replace(/[\s+]/g, '') .split(',') return `rgba(${values[0]},${values[1]},${values[2]},${opacity})` }else{ return hex } return RGBA }, getHexColor(color) { var values = color .replace(/rgba?\(/, '') .replace(/\)/, '') .replace(/[\s+]/g, '') .split(',') var a = parseFloat(values[3] || 1), r = Math.floor(a * parseInt(values[0]) + (1 - a) * 255), g = Math.floor(a * parseInt(values[1]) + (1 - a) * 255), b = Math.floor(a * parseInt(values[2]) + (1 - a) * 255) return '#' + ('0' + r.toString(16)).slice(-2) + ('0' + g.toString(16)).slice(-2) + ('0' + b.toString(16)).slice(-2) }, /** * 查询当前的城市 * @returns {Promise} */ async querySelectCity() { var app = getApp(); //获取应用实例; if (app.globalData.selectCityName) { this.currentSelectCity = app.globalData.selectCityName; this.navbar.currentSelectCity = app.globalData.selectCityName; if(this.hasOwnProperty('cityName')){ this.cityName = app.globalData.selectCityName; } } else{ let cityRequestData = { brandId: config.brandId, customerId: (app.globalData.single && app.globalData.single.id) ? app.globalData.single.id : '', simplify: false, }; const res = await requestConfig('queryCityData', cityRequestData, true); if (res.success && res.single && res.single.currentCity) { let mrak = false; for (let item of res.single.belongCityList) { if (item.cityName == res.single.currentCity.cityName || res.single.currentCity.cityCode == item.cityCode) { mrak = true; break; } } console.log("mrakindex:" + mrak + app.globalData.defaultProductCityName); if (!mrak) { //当前所处城市不是集团所属城市时,取默认城市(初始化时获取默认城市的值) this.currentSelectCity = app.globalData.defaultProductCityName; this.navbar.currentSelectCity = app.globalData.defaultProductCityName; app.globalData.selectCityName = app.globalData.defaultProductCityName; } else{ this.currentSelectCity = res.single.currentCity.cityName; this.navbar.currentSelectCity = res.single.currentCity.cityName; app.globalData.selectCityCode = res.single.currentCity.cityCode; app.globalData.selectCityName = res.single.currentCity.cityName; } } else { //不存在当前所属城市时,则取默认城市 // #ifdef H5 //如果不存在默认城市数据,有可能是接口还没返回,所以需要再次请求下数据 if(!app.globalData.defaultProductCityName){ await app.queryCityInfo() } // #endif this.currentSelectCity = app.globalData.defaultProductCityName; this.navbar.currentSelectCity = app.globalData.defaultProductCityName; app.globalData.selectCityName = app.globalData.defaultProductCityName; } } if(this.hasOwnProperty('cityName')){ this.cityName = app.globalData.selectCityName; } if(this.hasOwnProperty('selectCityCode')){ this.selectCityCode = app.globalData.selectCityCode; } }, // 置地老业主认证 async newAuthentication4Zd(pageId,fn,city='重庆') { var app = getApp(); //获取应用实例; if(pageId && pageId == '4213'){//需要修改为商城页面的实际页面id才能上线 4213 app.checkAuthTotal(2, async(checkRes) => { this.showPhoneModel = checkRes.showPhoneModel; if (!checkRes.showPhoneModel) { var {single: { id = ''} = {}} = app.globalData; let data = { brandId: config.brandId, id: id,//用户id mobile: app.globalData.phone || "", city: city, }; const res = await requestConfig('newAuthentication4Zd', data, true); if (res && res.success && res.list && res.list.length>0) {//是对应城市下的老业主 console.log('***是对应城市下的老业主***', res.list); fn && typeof fn == 'function' && fn(); } else{ uni.showToast({ title: '不是'+city+'区域老业主,不能参加活动', icon: 'none', duration: 1500, }); return false; } } }, true); } else{ fn && typeof fn == 'function' && fn(); } }, // websocket 返回的数据转义成object类型 parseWSData(data) { if (data.startsWith("a[")) { let endLength = data.length - 6; let textData = data.substr(3, endLength); let request = textData.split("\\n\\n"); let headerBody = request[0]; let body = request[1]; let headerArray = headerBody.split("\\n"); let header = {}; for (let i = 1; i < headerArray.length; i++) { let body = headerArray[i]; let resultBody = body.split(":"); header[resultBody[0]] = resultBody[1]; } let result = {}; result["command"] = headerArray[0]; result["header"] = header; if (body) { try { result["body"] = JSON.parse(body.replaceAll("\\", "")); } catch (e) { result["body"] = body; } } return result; } return data; } }; module.exports = util;