| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627 |
- 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 downloadImage(scoreID) {
- wx.showLoading({
- title: '下载中_然后长按保存',
- });
- var that = this;
- getData('MakeSchulteShare?ScoreID=' + scoreID, function (data) {
- setTimeout(function () {
- wx.downloadFile({
- url: "https://schulte-1253256735.file.myqcloud.com/share" + scoreID + ".jpg",
- success: function (res) {
- wx.hideLoading();
- wx.previewImage({
- current: res.tempFilePath, // 当前显示图片的http链接
- urls: [res.tempFilePath] // 需要预览的图片http链接列表
- })
- },
- fail: function () {
- wx.hideLoading();
- getData('MakeSchulteShare?ScoreID=' + scoreID, function (data) { });
- wx.showToast({
- title: '请稍候再试!',
- duration: 2000
- });
- }
- });
- }, 2000);
- });
- }
- 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;
- }
- }
- 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);
- 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 getDifficulty(num) {
- switch (Number(num)) {
- case 3:
- case 4:
- case 5:
- return "EASY";
- case 6:
- case 7:
- return "HARD";
- case 8:
- case 9:
- return "SUPER";
- }
- }
- 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/g, "\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#####");
- }
- 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");
- }
- return str;
- }
- function changeStringToView(field) {
- var result = {};
- result.Field = [[]];
- 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/g, "\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";
- obj.Content = arr[k].substring(arr[k].indexOf("[图]") + 3, arr[k].indexOf("[/图]"));
- arrResult.push(obj);
- }
- else if (arr[k].indexOf("[线]") >= 0 && arr[k].indexOf("[/线]") > 0) {
- var obj;
- var content = ["", "", ""];
- if (arr[k].indexOf("[线]") > 0) {
- content[0] = arr[k].substring(0, arr[k].indexOf("[线]"));
- }
- content[1] = arr[k].substring(arr[k].indexOf("[线]") + 3, arr[k].indexOf("[/线]"));
- if (arr[k].length > arr[k].indexOf("[/线]") + 4) {
- content[2] = arr[k].substring(arr[k].indexOf("[/线]") + 4);
- }
- 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);
- }
- var obj = {};
- obj.Type = "return";
- arrResult.push(obj);
- }
- result.Field.push(arrResult);
- }
- else {
- result.Field.push([]);
- }
- }
- }
- return result;
- }
- function getDetailColor() {
- var arr = [
- {//配色1
- BackColor: "#F44336",
- FrontColor: "#ffffff",
- SelectBackColor: "#ffffff",
- SelectFrontColor: "#1E1E1E",
- TagBackColor: "#9C2880",
- },
- {//配色2
- BackColor: "#D81B60",
- FrontColor: "#ffffff",
- SelectBackColor: "#ffffff",
- SelectFrontColor: "#1E1E1E",
- TagBackColor: "#E86D24",
- },
- {//配色3
- BackColor: "#8E24AA",
- FrontColor: "#ffffff",
- SelectBackColor: "#ffffff",
- SelectFrontColor: "#1E1E1E",
- TagBackColor: "#E86D24",
- },
- {//配色4
- BackColor: "#6639B5",
- FrontColor: "#ffffff",
- SelectBackColor: "#ffffff",
- SelectFrontColor: "#1E1E1E",
- TagBackColor: "#E86D24",
- },
- {//配色5
- BackColor: "#3F51B5",
- FrontColor: "#ffffff",
- SelectBackColor: "#ffffff",
- SelectFrontColor: "#1E1E1E",
- TagBackColor: "#E54627",
- },
- {//配色6
- BackColor: "#1E88E5",
- FrontColor: "#ffffff",
- SelectBackColor: "#ffffff",
- SelectFrontColor: "#1E1E1E",
- TagBackColor: "#E54627",
- },
- {//配色7
- BackColor: "#039BE5",
- FrontColor: "#ffffff",
- SelectBackColor: "#ffffff",
- SelectFrontColor: "#1E1E1E",
- TagBackColor: "#E54627",
- },
- {//配色8
- BackColor: "#00ACC1",
- FrontColor: "#ffffff",
- SelectBackColor: "#ffffff",
- SelectFrontColor: "#1E1E1E",
- TagBackColor: "#E54627",
- },
- {//配色9
- BackColor: "#009688",
- FrontColor: "#ffffff",
- SelectBackColor: "#ffffff",
- SelectFrontColor: "#1E1E1E",
- TagBackColor: "#2A6358",
- },
- {//配色10
- BackColor: "#43A047",
- FrontColor: "#ffffff",
- SelectBackColor: "#ffffff",
- SelectFrontColor: "#1E1E1E",
- TagBackColor: "#2A6358",
- },
- {//配色11
- BackColor: "#71B12D",
- FrontColor: "#ffffff",
- SelectBackColor: "#ffffff",
- SelectFrontColor: "#1E1E1E",
- TagBackColor: "#2A6358",
- },
- {//配色12
- BackColor: "#CFDA37",
- FrontColor: "#1e1e1e",
- SelectBackColor: "#868E25",
- SelectFrontColor: "#FFFFFF",
- TagBackColor: "#868E25",
- },
- {//配色13
- BackColor: "#F9D342",
- FrontColor: "#1e1e1e",
- SelectBackColor: "#C46C28",
- SelectFrontColor: "#FFFFFF",
- TagBackColor: "#C46C28",
- },
- {//配色14
- BackColor: "#FF9F33",
- FrontColor: "#1e1e1e",
- SelectBackColor: "#C46C28",
- SelectFrontColor: "#FFFFFF",
- TagBackColor: "#C46C28",
- },
- {//配色15
- BackColor: "#EE7F33",
- FrontColor: "#ffffff",
- SelectBackColor: "#ffffff",
- SelectFrontColor: "#1E1E1E",
- TagBackColor: "#C43928",
- },
- {//配色16
- BackColor: "#FF5722",
- FrontColor: "#ffffff",
- SelectBackColor: "#ffffff",
- SelectFrontColor: "#1E1E1E",
- TagBackColor: "#C42843",
- },
- {//配色17
- BackColor: "#795548",
- FrontColor: "#ffffff",
- SelectBackColor: "#ffffff",
- SelectFrontColor: "#1E1E1E",
- TagBackColor: "#CC2A38",
- },
- {//配色18
- BackColor: "#616161",
- FrontColor: "#ffffff",
- SelectBackColor: "#ffffff",
- SelectFrontColor: "#1E1E1E",
- TagBackColor: "#9C3724",
- },
- {//配色19
- BackColor: "#FFBC00",
- FrontColor: "#1e1e1e",
- SelectBackColor: "#9C6226",
- SelectFrontColor: "#ffffff",
- TagBackColor: "#9C6226",
- },
- {//配色20
- BackColor: "#ACC6AA",
- FrontColor: "#1e1e1e",
- SelectBackColor: "#6F7F6D",
- SelectFrontColor: "#ffffff",
- TagBackColor: "#6F7F6D",
- },
- {//配色21
- BackColor: "#74B49B",
- FrontColor: "#ffffff",
- SelectBackColor: "#ffffff",
- SelectFrontColor: "#1e1e1e",
- TagBackColor: "#9A4391",
- },
- {//配色22
- BackColor: "#0B8457",
- FrontColor: "#ffffff",
- SelectBackColor: "#ffffff",
- SelectFrontColor: "#1e1e1e",
- TagBackColor: "#9A4391",
- },
- {//配色23
- BackColor: "#34699A",
- FrontColor: "#ffffff",
- SelectBackColor: "#ffffff",
- SelectFrontColor: "#1e1e1e",
- TagBackColor: "#D44139",
- },
- {//配色24
- BackColor: "#234A9A",
- FrontColor: "#ffffff",
- SelectBackColor: "#ffffff",
- SelectFrontColor: "#1e1e1e",
- TagBackColor: "#D44139",
- },
- {//配色25
- BackColor: "#786489",
- FrontColor: "#ffffff",
- SelectBackColor: "#ffffff",
- SelectFrontColor: "#1e1e1e",
- TagBackColor: "#E69109",
- },
- ];
- return arr;
- }
- module.exports = {
- getData: getData,
- postData: postData,
- shareGroup: shareGroup,
- payMoney: payMoney,
- downloadImage: downloadImage,
- getLocalHost: getLocalHost,
- getTimeFormat: getTimeFormat,
- getWindowHeight: getWindowHeight,
- getStorageValue: getStorageValue,
- getDifficulty: getDifficulty,
- getProgramList: getProgramList,
- gotoFeedback: gotoFeedback,
- getDetailColor: getDetailColor,
- changeStringToView: changeStringToView,
- changeViewToString: changeViewToString,
- encryptUrl: EncryptUrl,
- decryptUrl: DecryptUrl,
- }
|