| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- import common from '../utils/util';
- import constant from '../utils/constant';
- var app = getApp();
- var dataSendTimeout = 0;
- 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,
- timeout:120000,
- success: function (res) {
- if (res.statusCode)
- common.checkError(res.statusCode);
- var data = res.data.result;
- callback(data);
- },
- fail: function () {
- wx.showToast({
- title: '系统忙请稍候',
- // image: "../images/universalpic_warning_white_126x120.png",
- duration: 3000
- });
- var err={};
- err.errCode=100;
- err.errMsg="网络错误";
- callback(null,err);
- },
- });
- }
- function postData(url, postData, callback) {
- console.log("加密前的结果为===", url);
- var url = common.Encrypt(url);
- //console.log("加密后的结果为===",url);
- wx.request({
- url: app.globalData.serverUrl + url,
- method: "POST",
- timeout:120000,
- 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
- });
- },
- });
- }
- 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 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 onSelect(obj,event,callback){
- var result=false;
- var str=event.currentTarget.dataset.object;
- var index=event.currentTarget.dataset.index;
- var clickType=event.currentTarget.dataset.clicktype;
- if (clickType=="checkbox"){
- if (obj.data[str][index].CSS)
- obj.data[str][index].CSS="";
- else{
- obj.data[str][index].CSS="Selected";
- result=true;
- }
- }
- else{
- for(var i=0;i<obj.data[str].length;i++){
- if (i==index){
- obj.data[str][i].CSS="Selected";
- }
- else{
- obj.data[str][i].CSS="";
- }
- }
- }
- obj.setData(obj.data);
- callback(obj,event,result);
- }
- function checkGenerating(){
- if (app.globalData.Generating){
- let intervalGenerate=setInterval(function(){
- console.log(new Date().getTime());
- if (!app.globalData.Generating){
- clearInterval(intervalGenerate);
- wx.showModal({
- title: '通知',
- content: '文章生成好了。',
- cancelText:"不去",
- confirmText:"去看",
- complete: (res) => {
- if (res.confirm) {
- let next='article?ID=MAX';
- wx.reLaunch({
- url: 'index',
- complete:function(){
- wx.navigateTo({
- url: next,
- })
- }
- })
- }
- }
- })
- }
- },1000);
- }
- }
- module.exports = {
- getData: getData,
- postData: postData,
- getLocalHost: getLocalHost,
- getWindowHeight: getWindowHeight,
- onSelect:onSelect,
- checkGenerating:checkGenerating,
- }
|