1. 变量
路径:utils/variable.js
将一些常用的变量提取出来,以便在各个地方均可统一的使用这些变量。
const accountInfo = wx.getAccountInfoSync().miniProgram;
// 切线上打开
// accountInfo.envVersion = 'release';
module.exports = {
// token 失效时间,通常是2小时7200s,提前一点失效,单位/s
TokenFailureTime: 6600,
// 请求超时的时间,默认10s,单位/毫秒
timeout: 10000,
// 小程序appid
appId: accountInfo.appId,
// 小程序当前环境
env: accountInfo.envVersion,
// 小程序版本
version: accountInfo.version,
// 小程序别名,通常用于请求时添加到Header中
mini_alias: 'minifyjc',
// 【废弃】订阅消息模板id
templateCode: [],
// 底部tab页面路径
tabbarPath: ['/pages/index/index', '/pages/member/index'],
// 字体加载配置(全局通用)
familyArr: [{
"name": "montserrat",
"path": 'MONTSERRAT-REGULAR.TTF'
}, {
"name": "SourceHanSans",
"path": 'SourceHanSansCN-Regular.ttf'
}],
// 【废弃】页面position固定参数
position: {
'/pages/index/index': 'index',
'/pages/activeList/index': 'active_list',
'/pages/member/index': 'btn_one,btn_two'
}
};- 当需要切换到线上环境时,设置
accountInfo.envVersion = 'release'; - 字体配置:详见 02. 小程序字体
2. 配置
路径:utils/config.js
将一些常用的参数提取出来,统一配置。
import variable from './variable';
if (!variable.env) {
console.error("获取运行环境失败!");
}
// 接口请求前缀
const mcApi = {
// 开发版
develop: "https://scrm3.widiazine.com/api-cloud/",
// 体验版
trial: "https://scrm3.widiazine.com/api-cloud/",
// 正式版
release: "https://scrm3.widiazine.com/api-cloud/"
};
// 统计平台地址
const tongjiApi = {
// 开发版
develop: "https://tongji.widiazine.com/matomo.php",
// 体验版
trial: "https://tongji.widiazine.com/matomo.php",
// 正式版
release: "https://tongji.widiazine.com/matomo.php"
};
// 统计平台ID
const tongjiSiteId = {
// 开发版
develop: "44",
// 体验版
trial: "44",
// 正式版
release: "44"
};
// request请求baseURL
const mcPath = mcApi[variable.env];
const tongjiPath = tongjiApi[variable.env];
const tongjiId = tongjiSiteId[variable.env];
const fontPath = "https://font.widiazine.com/";
const imgPath = "https://cdn.widiazine.com/mc_default/";
/*
* 调研问卷相关配置
* surveyPath:设置请求地址,注意将此地址添加到业务域名
* surveyAuth: 获取用户身份信息的方式,mini: 小程序传递openid,offi:公众号网页授权,none:不获取用户身份
* none暂时和offi功能一致,但offi需要后台配置微信相关功能
*/
const surveyPath = "https://scrm3.widiazine.com/survey/s/";
// 获取用户的方式
const surveyAuth = "mini"
module.exports = {
mcPath,
tongjiPath,
imgPath,
tongjiId,
fontPath,
surveyPath,
surveyAuth
};页面信息›
已优化是