| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- import common from '../utils/util';
- import constant from '../utils/constant';
- 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.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) {
- 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
- });
- },
- });
- }
- 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 returnTop() {
- if (wx.canIUse('pageScrollTo')) {
- wx.pageScrollTo({
- scrollTop: 0
- });
- }
- }
- function getCollect(callback) {
- var that = this;
- var list=wx.getStorageSync("CollectList");
- if (list){
- if (callback)
- callback(list);
- }
- else{
- var id=app.globalData.userInfo.UserID;
- getData("GetMPSSchoolCollect?UserID="+id, function (data) {
- if (data) {
- wx.setStorageSync('CollectList', data);
- if (callback)
- callback(data);
- }
- else
- if (callback)
- callback(null);
- });
- }
- }
- function gotoMiniprogram(AppID,Path){
- wx.navigateToMiniProgram({
- appId: AppID,
- path: Path,
- extraData: {
- },
- success(res) {
- // 打开成功
- }
- });
- }
- function getProgramList() {
- return [
- {
- ID: 166,
- Name: "秒过",
- ImageUrl:"../images/ad_01.png",
- AppID: 'wx84b3feac6069eec3',
- Path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
- },
- {
- ID: 164,
- Name: "口算",
- ImageUrl:"../images/ad_03.png",
- AppID: 'wxa5441bbf344692ba',
- Path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
- },
- {
- ID: 105,
- Name: "计算题",
- ImageUrl:"../images/ad_04.png",
- AppID: 'wx1fef080f74481cbd',
- Path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
- },
- {
- ID: 98,
- Name: "拼音",
- ImageUrl:"../images/ad_05.png",
- AppID: 'wx331e8dd070f01d0e',
- Path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
- },
- {
- ID: 106,
- Name: "识字",
- ImageUrl:"../images/ad_06.png",
- AppID: 'wx313a8f2c0741efe1',
- Path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
- },
- {
- ID: 99,
- Name: "自然拼读",
- ImageUrl:"../images/ad_07.png",
- AppID: 'wxb54a6d5aff836ee3',
- Path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
- },
- {
- id: 90,
- Name: "注意力游戏",
- ImageUrl:"../images/ad_08.png",
- AppID: 'wxa5e33c61fe37dd01',
- Path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
- },
- ];
- }
- function goto(e) {
- if (app.globalData.IsGoto){
- app.globalData.IsGoto=false;
- setTimeout(function(){
- app.globalData.IsGoto=true;
- },1000);
- var url = e.currentTarget.dataset.url;
-
- wx.navigateTo({
- url: './' + url,
- });
- }
- }
- module.exports = {
- getData: getData,
- postData: postData,
- getLocalHost: getLocalHost,
- getWindowHeight: getWindowHeight,
- onSelect: onSelect,
- returnTop:returnTop,
- getCollect: getCollect,
- gotoMiniprogram:gotoMiniprogram,
- getProgramList:getProgramList,
- goto:goto,
- }
|