import common from '../utils/util'; var app = getApp(); function getData(url, callback) { if (!app.globalData.IsProduction) console.log("加密前的结果为===", url); var url = common.Encrypt(url); //console.log("加密后的结果为===",url); wx.request({ url: app.globalData.serverUrl + url, success: function (res) { if (res.statusCode) common.checkError(res.statusCode); var data = res.data.result; callback(data); }, fail: function () { wx.redirectTo({ url: './error', }); }, }); } function postData(url, postData, callback) { var url = common.Encrypt(url); //console.log("加密后的结果为===",url); wx.request({ url: app.globalData.serverUrl + url, method: "POST", data: postData, success: function (res) { if (res.statusCode) common.checkError(res.statusCode); var data = res.data.result; callback(data); }, fail: function () { wx.showToast({ title: '服务器忙,请稍候再试!', duration: 3000 }); wx.redirectTo({ url: './error', }); }, }); } function getLocalHost(callback) { if (!app.globalData.IsProduction) { var url = common.Encrypt("Ping"); wx.request({ url: app.globalData.serverUrlLocalhost + url, success: function (res) { app.globalData.serverUrl = app.globalData.serverUrlLocalhost; callback(); }, fail: function () { app.globalData.serverUrl = app.globalData.serverUrlServer; callback(); }, }); } else { app.globalData.serverUrl = app.globalData.serverUrlServer; callback(); } } function shareGroup(shareTickets, isShared) { // 转发成功 console.log("shareTickets:" + shareTickets); if (shareTickets && shareTickets.length > 0) { var that = this; for (var i = 0; i < shareTickets.length; i++) { wx.getShareInfo({ shareTicket: shareTickets[i], success: function (groupInfo) { wx.login({ success: function (res0) { console.log("groupInfo:" + groupInfo); that.postData('AddSpatialIntelligenceGroup', { Code: res0.code, UserID: app.globalData.userInfo.UserID, GroupInfo: groupInfo, IsShared: isShared, }, function (data) { }); } }); }, fail: function (err) { console.log(err); }, }); } } } function payMoney(payType, money, callback) { console.log(money); //登录认证 wx.login({ success: function (res) { if (res.code) { console.log('获取用户登录态成功!' + res.code); //预支付 getData('PayLogin?code=' + res.code + '&payType=' + payType + '&money=' + money, function (data) { if (data && data.timeStamp) { //微信支付 wx.requestPayment({ 'timeStamp': data.timeStamp.toString(), 'nonceStr': data.nonceStr, 'package': data.package, 'signType': 'MD5', 'paySign': data.paySign, 'success': function (res3) { console.log("success:" + res3); callback(); }, 'fail': function (err) { if (err && err.errMsg && err.errMsg.indexOf("fail cancel")) { } else { wx.showToast({ title: '服务器忙,请稍候再试!', duration: 3000 }); wx.redirectTo({ url: './error', }); } } }); } }); } else { console.log('获取用户登录态失败!' + res.errMsg); } } }); } function getTimeFormat(duration) { //console.log("duration:" + duration); var arr = ['', '', ''] if (duration.indexOf("'") > 0) arr[0] = duration.substring(0, duration.indexOf("'")); if (duration.indexOf(".") > 0) { arr[1] = duration.substring(duration.indexOf("'") + 1, duration.indexOf(".") + 1); arr[2] = duration.substring(duration.indexOf(".") + 1, duration.indexOf('"')); } else { arr[1] = duration.substring(duration.indexOf("'") + 1, duration.indexOf('"')); } return arr; } function getWindowHeight() { var height = app.globalData.systemInfo.windowHeight; //console.log("app.globalData.systemInfo.windowHeight:" + app.globalData.systemInfo.windowHeight * 2); if (app.globalData.systemInfo.model) { if (height == 504 && ( app.globalData.systemInfo.model.indexOf("iPhone 6<") >= 0 || app.globalData.systemInfo.model.indexOf("iPhone 7<") >= 0 || app.globalData.systemInfo.model.indexOf("iPhone 6s<") >= 0 || app.globalData.systemInfo.model.indexOf("iPhone 5") >= 0 || app.globalData.systemInfo.model.indexOf("iPhone SE") >= 0 )) { height = 596; } else if (app.globalData.systemInfo.model.indexOf("iPad") >= 0) { height = 470; } } height = height * 2; if (app.globalData.systemInfo.system && app.globalData.systemInfo.system.indexOf("Android") >= 0) { height = height + 168; } else { height = height + 50; } //console.log("height:" + height); //var height = app.globalData.systemInfo.screenHeight * 2; return height; } //获取存储数据,若不存在,则获得缺省值。 function getStorageValue(obj, name, defaultStatus, callback) { wx.getStorage({ key: name, success: function (res) { obj.data[name] = res.data; obj.setData(obj.data); callback(); }, fail: function (res) { obj.data[name] = defaultStatus; obj.setData(obj.data); callback(); }, }); } function getProgramList() { return [ { id: 89, appId: 'wx46a7b4c420e6d38f', path: 'pages/index/start?SourceID=' + app.globalData.ProgramID, }, { id: 98, appId: 'wx331e8dd070f01d0e', path: 'pages/index/index?SourceID=' + app.globalData.ProgramID, }, { id: 99, appId: 'wxb54a6d5aff836ee3', path: 'pages/index/index?SourceID=' + app.globalData.ProgramID, }, { id: 106, appId: 'wx313a8f2c0741efe1', path: 'pages/index/index?SourceID=' + app.globalData.ProgramID, }, ]; } function gotoFeedback() { wx.navigateToMiniProgram({ appId: "wx80059777521b897c", path: "pages/index/feedback", extraData: { }, success(res) { // 打开成功 } }); } function changeViewToString(content) { var str = content; if (str.constructor == Array) { if (str.length > 0) str = str.join(","); else str = ""; } if (!str) str = "" else { str = str.replace(/\n\n\n/g, "\n\n"); if (str.indexOf("\n") == 0) { str = str.substr(1); } if (str.lastIndexOf("\n") == str.length - 1) { str = str.substr(0, str.length - 1); } } return str; } function EncryptUrl(str) { if (str.constructor == Array) { if (str.length > 0) str = str.join(","); else str = ""; } if (str) { str = str.replace(/baidu.com/g, "#####1#####"); str = str.replace(/iciba.com/g, "#####2#####"); str = str.replace(/https:\/\/pinyin.kylx365.com\/sounds/g, "#####3#####"); str = str.replace(/https:\/\/miaguo-1253256735.file.myqcloud.com/g, "#####4#####"); } if (str.substr(0, 1) == "\n") str = str.substr(1); return str; } function DecryptUrl(str) { if (str.constructor == Array) { if (str.length > 0) str = str.join(","); else str = ""; } if (str) { str = str.replace(/#####1#####/g, "baidu.com"); str = str.replace(/#####2#####/g, "iciba.com"); str = str.replace(/#####3#####/g, "https://pinyin.kylx365.com/sounds"); str = str.replace(/#####4#####/g, "https://miaguo-1253256735.file.myqcloud.com"); } return str; } function changeStringToView(field) { var result = {}; result.Field = [[]]; result.Images = []; for (var j = 0; j < field.length; j++) { if (j == 0) { if (field[j].ContentType == 0 && field[j].Content && field[j].Content.length > 0) { result.Tags = field[j].Content.toString().split(","); } else { result.Tags = []; } } else { if (field[j].ContentType == j && field[j].Content && field[j].Content.length > 0) { var arrResult = [], arrSoundMark = []; var str = field[j].Content.toString(); str = DecryptUrl(str); str = str.replace(/\[读/g, "\n[读"); str = str.replace(/\[图/g, "\n[图"); str = str.replace(/\[\/读\]/g, "[\/读]\n"); str = str.replace(/\[\/图\]/g, "[\/图]\n"); str = str.replace(/\n\n\n/g, "\n\n"); var arr = str.split("\n"); for (var k = 0; k < arr.length; k++) { if (arr[k].indexOf("[图") >= 0 && arr[k].indexOf("[/图]") > 0) { var obj = {}; obj.Type = "image"; if (arr[k].indexOf("[图]") >= 0) { obj.ContentServer = arr[k].substring(arr[k].indexOf("[图]") + 3, arr[k].indexOf("[/图]")); obj.Content = getTempImage(obj.ContentServer); result.Images.push(obj.Content); } arrResult.push(obj); } else if (arr[k].indexOf("[线]") >= 0 && arr[k].indexOf("[/线]") > 0) { var obj; var content = [], temp = arr[k]; do { var temp1 = temp.substring(0, temp.indexOf("[线]")); if (temp1) { content.push({ key: "normal", value: temp1, }); } else { if (arr[k].indexOf("[线]") > 0) { content.push({ key: "normal", value: temp, }); temp = ""; } else { if (temp && temp.indexOf("[线]") < 0) { content.push({ key: "normal", value: temp, }); temp = ""; } } } if (temp.length > 0) { temp = temp.substr(temp.indexOf("[线]") + 3); temp1 = temp.substring(0, temp.indexOf("[/线]")); if (temp1) { content.push({ key: "line", value: temp1, }); } temp = temp.substr(temp.indexOf("[/线]") + 4); } } while (temp.length > 0); obj = {}; obj.Type = "line"; obj.Content = content; arrResult.push(obj); } else if (arr[k].indexOf("[读") >= 0 && arr[k].indexOf("[/读]") > 0) { var obj = {}; obj.Type = "sound"; if (arr[k].indexOf("[读]") >= 0) { obj.Content = arr[k].substring(arr[k].indexOf("[读]") + 3, arr[k].indexOf("[/读]")); obj.SoundImageName = "png"; } else { var tempIndex = arr[k].indexOf("\']") + 2; obj.Content = arr[k].substring(tempIndex, arr[k].indexOf("[/读]")); obj.SoundMark = arr[k].substring(arr[k].indexOf("src='") + 5, arr[k].indexOf("']"));; obj.SoundImageName = "png"; } arrResult.push(obj); } else if (arr[k] != "") { var obj = {}; obj.Type = "normal"; obj.Content = arr[k]; arrResult.push(obj); } else if (k > 0 && arr[k] == "") { var obj = {}; obj.Type = "br"; obj.Content = ""; arrResult.push(obj); } var obj = {}; obj.Type = "return"; arrResult.push(obj); } //去掉前回车换行 while (arrResult[0].Type == "return" || arrResult[0].Type == "br") { arrResult.shift(); } //去掉后回车换行 for (var i = arrResult.length - 1; i >= 0; i--) { if (arrResult[i].Type == "return" || arrResult[i].Type == "br") arrResult.pop(); else { break; } } result.Field.push(arrResult); } else { result.Field.push([]); } } } return result; } //得到当天任务 function getTaskTodayList(callback) { wx.showLoading({ title: '请稍候', mask: true, }) var that = this; var CardMaxNumberNew = wx.getStorageSync("CardMaxNumberNew"); if (!CardMaxNumberNew) CardMaxNumberNew = 10; var CardMaxNumberHistory = wx.getStorageSync("CardMaxNumberHistory"); if (!CardMaxNumberHistory) CardMaxNumberHistory = 30; var SortTypeIndex = wx.getStorageSync("SortTypeIndex"); if (!SortTypeIndex) SortTypeIndex = 0; var url = 'GetMiaoguoCardToday?UserID=' + app.globalData.userInfo.UserID; url += "&New=" + CardMaxNumberNew; url += "&History=" + CardMaxNumberHistory; url += "&SortTypeIndex=" + SortTypeIndex; getData(url, function (data) { wx.hideLoading(); if (data) { app.globalData.TaskToday = data; callback(data); } }); } function getTempImage(serverUrl) { if (serverUrl.indexOf("miaguo-1253256735") >= 0) { var list = wx.getStorageSync("TempImageList"); if (!list) list = []; for (var i = 0; i < list.length; i++) { if (list[i].ServerUrl == serverUrl) { return list[i].TempUrl; break; } } } return serverUrl; } function saveTempImage(serverUrl, tempUrl) { var list = wx.getStorageSync("TempImageList"); if (!list) list = []; var b = false; for (var i = 0; i < list.length; i++) { if (list[i].ServerUrl == serverUrl) { list[i].TempUrl = tempUrl; b = true; break; } } if (!b) { list.push({ "ServerUrl": serverUrl, "TempUrl": tempUrl }); } if (list.length > 200) { list.pop(); } wx.setStorageSync("TempImageList", list); } function UpdateMiaoguoCardTodayAll(callback){ var that = this; wx.showLoading({ title: '请稍候', mask: true, }); var list = wx.getStorageSync("ListTaskFinished"); if (list && list.length > 0) { var arr=[]; for(var i=0;i