From 32ddbd13162ff5792eef24fcb015466fc0869e23 Mon Sep 17 00:00:00 2001 From: chris <510148846@qq.com> Date: Thu, 15 Aug 2024 17:28:52 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E5=A2=9E=E5=8A=A0=E7=BD=91=E7=BB=9C?= =?UTF-8?q?=E6=A3=80=E6=B5=8B=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.vue | 13 +++++++++++++ manifest.json | 21 ++++++++++++++++++--- utils/network/request.js | 37 +++++++++++++++++++++++++++++++++++-- 3 files changed, 66 insertions(+), 5 deletions(-) diff --git a/App.vue b/App.vue index d4c7728..f86a9fe 100644 --- a/App.vue +++ b/App.vue @@ -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(() => { diff --git a/manifest.json b/manifest.json index f9d5db0..91a6b78 100644 --- a/manifest.json +++ b/manifest.json @@ -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 @@ "", "", "", - "" + "", + "" ], "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" : {} + } } } }, diff --git a/utils/network/request.js b/utils/network/request.js index 2b65f46..5cc3051 100644 --- a/utils/network/request.js +++ b/utils/network/request.js @@ -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 || '网络错误' }); + } + }) + }) +}