整个项目六百KB 首次加载为什么白屏四秒左右
发布于 5 年前 作者 minsong 10133 次浏览 来自 问答

app.js代码如下

const util = require(’./XX’);

var TAG = ‘app’;

var version_num = ‘XXX’;

App({

onLaunch: function (options) {

var vnum = wx.getStorageSync(util.key.versionNum) || ‘0’;

if (version_num != vnum) {

wx.clearStorageSync();

wx.setStorageSync(util.key.versionNum, version_num);

}

},

onLoad: function (options) {},

onShow: function (options) {

let that = this;

wx.getSystemInfo({

success: (res) => {

that.globalData.baseInfo.getPhoneSystem = String(res.system).substring(0, 3);

var clientHeight = res.windowHeight

var clientWidth = res.windowWidth,

rpxR = 750 / clientWidth;

var helfH = res.statusBarHeight

// 设置导航栏高度

if (res.statusBarHeight >= 40) {

wx.setStorageSync(util.key.navHeight, 188);

wx.setStorageSync(util.key.navPadding, 70);

wx.setStorageSync(util.key.lineNav, 246);

} else {

wx.setStorageSync(util.key.navHeight, 128);

wx.setStorageSync(util.key.navPadding, 40);

wx.setStorageSync(util.key.lineNav, 206);

wx.setStorageSync(util.key.helfH, helfH);

};

wx.setStorageSync(util.key.helfH, helfH);

wx.setStorageSync(util.key.clientHeight, clientHeight);

wx.setStorageSync(util.key.clientWidth, clientWidth);

}

});

let opencityCode = wx.getStorageSync(util.key.opencityCode);

let opencityName = wx.getStorageSync(util.key.opencityName);

if (options.scene == 1089) {

wx.setStorageSync(util.key.scene, 1089);

}

if (options.scene == 1038) {

wx.showLoading({

title: ‘加载中’,

})

var errorCode = options.referrerInfo && options.referrerInfo.extraData && options.referrerInfo.extraData.return_code ? options.referrerInfo.extraData.return_code : ‘’;

if (errorCode == ‘SUCCESS’) {

var appid = options.referrerInfo.appId;

var contractId = options.referrerInfo.extraData.contract_id;

that.globalData.baseInfo.showPage = true;

util.getBaseUserInfo(opencityCode, opencityName);

var timerName = setTimeout(function () {

wx.redirectTo({

url: “…/scan/scan?showPage=” + true

});

}, 2000)

} else {

var msg = options.referrerInfo.extraData.return_msg;

wx.showModal({

title: errorCode,

content: msg,

});

console.log(TAG + ‘:签约失败’);

}

}

},

onHide: function () {

clearTimeOut(timerName)

},

globalData: {

hasLogin: false,

baseInfo: {}

}

});

首页js代码如下:

import regeneratorRuntime from ‘.XXX’;

const api = require(‘XXX’);

const qrUtil = require(‘XXX’);

const util = require(‘XXX’);

const xyUtil = require(’.XXX’);

const app = getApp();

var TAG = ‘SCAN’;

Page({

/**

  * 页面的初始数据

  */

data: {

resDataObj: {}

},

getXyInfo: function () {

return new Promise(function (resolve, reject) {

let publicKey = xyUtil.generateKey()

let cardId = wx.getStorageSync(util.key.xyCardId)

let data = {

cardId: cardId,

cityCode: wx.getStorageSync(util.key.opencityCode),

openId: wx.getStorageSync(util.key.openId),

publicKey: publicKey

}

console.log(data)

util.request(XXX, data, ‘POST’, ‘application/x-www-form-urlencoded’).then(res => {

if (res.code === 0) {

wx.setStorageSync(util.key.cerMsg, ‘’)

let ciCert = res.data.ciCert

let keyVer = Number(res.data.keyVersion)

let userCert = res.data.userCert

let qrCodeVer = res.data.qrCodeVersion

xyUtil.writeUserCert(ciCert, userCert, keyVer, qrCodeVer)

wx.setStorageSync(util.key.xyCer, true)

resolve()

} else {

wx.setStorageSync(util.key.cerMsg, res.msg)

resolve()

}

})

})

},

start: async function (options) {

var that = this;

var locdata = ‘’;

if (options.opencityName) {

locdata = {

opencityName: options.opencityName,

opencityCode: options.opencityCode

}

} else {

let getCity = wx.getStorageSync(util.key.opencityCode)

if (!getCity) {

locdata = await util.getLocation();

}

}

var opencityName = ‘’;

var opencityCode = ‘’;

if (locdata) {

opencityName = locdata.opencityName;

opencityCode = locdata.opencityCode;

wx.setStorageSync(util.key.cityName, opencityName);

wx.setStorageSync(util.key.cityCode, opencityCode);

} else {

opencityName = wx.getStorageSync(util.key.opencityName);

opencityCode = wx.getStorageSync(util.key.opencityCode);

}

var openId = wx.getStorageSync(util.key.openId);

var outTokenTime = wx.getStorageSync(util.key.tokenTime);

if (openId == ‘’ || outTokenTime < (Date.parse(new Date()) + 10 * 60 * 1000)) {

await util.getOpenId()

}

var resData = await util.getBaseUserInfo(opencityCode, opencityName);

this.resDataObj = {

bindStatus: resData.bindStatus,

opencityCode: opencityCode,

opencityName: opencityName

}

let bind = wx.getStorageSync(util.key.bindStatus)

console.log(bind)

if (bind === 1) {

let reCity = this.resDataObj.opencityName + ‘’

if (reCity === ‘XXX’) {

await this.getXyInfo()

} else {

let ctf = wx.getStorageSync(util.key.ctf);

if (ctf === ‘’ || ctf === ‘undefined’) {

if (app.globalData.baseInfo.mchId) {

await util.loadcertificate(resData.userid);

}

}

}

}

return this.resDataObj;

},

onLoad: function (options) {

wx.showLoading({

title: ‘加载中’,

})

this.start(options).then(res => {

console.log('res = ’ + res)

let that = this

if (res.bindStatus === 1) {

let differentOptions = ‘?opencityCode=’ + res.opencityCode + ‘&opencityName=’ + res.opencityName

let reCity = this.resDataObj.opencityName

if (reCity === ‘XXX’) {

wx.redirectTo({

url: “…/…/pages/XX/XX” + differentOptions

});

} else {

wx.redirectTo({

url: “…/…/pages/XX/XX” + differentOptions

});

}

} else {

wx.redirectTo({

url: ‘…/…/pages/XX/XX’

})

}

}, function (error) {

console.log(error)

})

}

2 回复

白屏是整个页面白屏什么都不显示?这里能补充下截图?直接扫码打开小程序就白屏么?

是不是用了精确定位呢,这个非常慢

回到顶部