1、增加网络检测功能

master
chris 3 months ago
parent f8fe327ee5
commit 32ddbd1316

@ -16,6 +16,19 @@
const appInfo = uni.getAppBaseInfo()
systemStore.setAppInfo(appInfo)
// #endif
uni.getNetworkType({
success ({ networkType }) {
console.log('enter network', networkType)
if (networkType === 'none') {
uni.showModal({
title: '提示',
content: '当前无网络,请连接网络',
showCancel: false
})
}
}
})
})
onShow(() => {

@ -2,8 +2,8 @@
"name" : "studypen",
"appid" : "__UNI__C183B0D",
"description" : "",
"versionName" : "0.0.0.8",
"versionCode" : 100,
"versionName" : "0.0.0.9",
"versionCode" : 101,
"transformPx" : false,
/* 5+App */
"app-plus" : {
@ -45,7 +45,8 @@
"<uses-feature android:name=\"android.hardware.camera\"/>",
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>",
"<uses-permission android:name=\"android.permission.BLUETOOTH\"/>",
"<uses-permission android:name=\"android.permission.BLUETOOTH_ADMIN\"/>"
"<uses-permission android:name=\"android.permission.BLUETOOTH_ADMIN\"/>",
"<uses-permission android:name=\"android.permission.INTERNET\"/>"
],
"minSdkVersion" : 21,
"abiFilters" : [ "armeabi-v7a" ],
@ -98,6 +99,20 @@
"pid" : "",
"parameters" : {}
}
},
"XM-SysPrinter" : {
"__plugin_info__" : {
"name" : "双端系统打印插件 - [试用版,仅用于自定义调试基座]",
"description" : "XM-SysPrinter是一款在原生系统中调起系统打印页面的插件支持图片、pdf、office、网页等。",
"platforms" : "Android,iOS",
"url" : "https://ext.dcloud.net.cn/plugin?id=9567",
"android_package_name" : "",
"ios_bundle_id" : "",
"isCloud" : true,
"bought" : 0,
"pid" : "9567",
"parameters" : {}
}
}
}
},

@ -24,8 +24,21 @@ uni.addInterceptor('request', {
}
})
function request (options, config) {
return checkNetworkStatus()
.then(res => {
return requestFun(options, config)
})
.catch(error => {
uni.showToast({
icon: 'error',
title: error.msg
})
})
}
// 请求函数
function request ({ url, method, data = {} }, config = { loading: true }) {
function requestFun ({ url, method, data = {} }, config = { loading: true }) {
url = netConfig.baseUrl + url;
const header = {
// 'Authorization': 'Bearer ' + getToken()
@ -73,6 +86,10 @@ function request ({ url, method, data = {} }, config = { loading: true }) {
},
fail: (error) => {
console.log('Request Error', new Error(error));
uni.showToast({
icon: 'error',
title: '请求失败'
})
reject(error);
},
complete: () => {
@ -90,6 +107,8 @@ function request ({ url, method, data = {} }, config = { loading: true }) {
})
}
export default request
// 处理401状态码
function dispose401 (response) {
logout().then(() => {
@ -147,4 +166,18 @@ function joinGetQuery(url, query) {
return queryStr;
}
export default request
// 检查网络状态
function checkNetworkStatus () {
return new Promise((resolve, reject) => {
uni.getNetworkType({
success (res) {
const { networkType } = res;
networkType === 'none' ? reject({status: false, msg: '无网络连接'})
: resolve({ status: true, msg: '网络连接正常' })
},
fail (err) {
reject({ status: false, msg: err.msg || '网络错误' });
}
})
})
}

Loading…
Cancel
Save