正常wifi分销助手的的前端代码是编译后的,无法修改,只能手动一个个编译小程序版本为开源版本。编译过程记录。
修改wifi分组助手前端主要用uniapp编译,
前端框架用到uview知道这些就比较好操作,去uniapp插件市场导入uview
第二步修改新建文件目录,整体目录结构
主要请求用到请求拦截和返回
/**
* 请求拦截
* @param {Object} http
*/
module.exports = (vm) => {
uni.$u.http.interceptors.request.use((config) => { // 可使用async await 做异步操作
// 初始化请求拦截器时,会执行此方法,此时data为undefined,赋予默认{}
config.data = config.data || {}
var token = uni.getStorageSync("token");
config.header.token = token;
config.url = config.url + "&wxapp_id=" +uni.$u.http.config.wxapp_id+ "&token=" + token;
// 可以在此通过vm引用vuex中的变量,具体值在vm.$store.state中
// console.log(vm.$store.state);
return config
}, (config) => // 可使用async await 做异步操作
Promise.reject(config))
}
请求返回
/**
* 响应拦截
* @param {Object} http
*/
module.exports = (vm) => {
uni.$u.http.interceptors.response.use((response) => {
/* 对响应成功做点什么 可使用async await 做异步操作*/
console.log(response);
const data = response.data
var pages = getCurrentPages();
// 自定义参数
const custom = response.config.custom
if (data.code !== 1) { // 服务端返回的状态码不等于200,则reject()
// 如果没有显式定义custom的toast参数为false的话,默认对报错进行toast弹出提示
if (custom.toast !== false) {
uni.$u.toast(data.msg);
if (data.code == -1) {
uni.$u.toast("登录跳转中...");
setTimeout(function() {
// 防止多次跳转
if (pages[0].route != "pages/passport/login") {
uni.navigateTo({
url: "/pages/passport/login"
});
}
}, 1500);
return false;
}
}
// 如果需要catch返回,则进行reject
if (custom === null || custom === void 0 ? void 0 : custom.catch) {
return Promise.reject(data);
} else {
// 否则返回一个pending中的promise,请求不会进入catch中
return new Promise(function() {});
}
}
return data.data === undefined ? {} : data;
}, (response) => {
/* 对响应错误做点什么 (statusCode !== 200)*/
return Promise.reject(response)
})
}
请求配置我没有按照原来的方式编译,用来新配置
// 引入配置
import config from '@/common/config'
// 初始化请求配置
uni.$u.http.setConfig((defaultConfig) => {
/* defaultConfig 为默认全局配置 */
defaultConfig.baseURL = config.baseUrl /* 根域名 */
defaultConfig.wxapp_id = config.wxapp_id /* 根域名 */
return defaultConfig
})
module.exports = (vm) => {
require('./requestInterceptors')(vm)
require('./responseInterceptors')(vm)
}
第三步每个页面反编译,考虑销量,我特意用py写一个反编译工具,速度稍微一点
因为工具写法不是特别完善,所以最后的结果跟实际效果有所偏差,只能手动调整 ,修改每个请求时候设置,如请求地址,系统函数如n.设置成uni. this指向就可以