From 9ca5d844e24a9d72307f17f6d81eac0f843ec9e2 Mon Sep 17 00:00:00 2001
From: xuefei <564615061@qq.cm>
Date: 星期一, 03 七月 2023 09:11:37 +0800
Subject: [PATCH] 请求过滤null
---
api/request.js | 148 +++++++++++++++++++++++++++++-------------------
1 files changed, 89 insertions(+), 59 deletions(-)
diff --git a/api/request.js b/api/request.js
index 55c6a91..26d4760 100644
--- a/api/request.js
+++ b/api/request.js
@@ -1,13 +1,35 @@
import {
globalApi
} from '@/api/globalApi.js';
+import {
+ apiLoginPassword
+} from './publicInterface';
// 鎴愬姛
const responseOK = (response) => {
const {
data
} = response;
+ test(data);
return data;
+}
+const test = (obj) => {
+ if (obj instanceof Array) {
+ obj.forEach(e => {
+ test(e);
+ })
+ } else if (obj instanceof Object) {
+ for (let key in obj) {
+ if (obj[key] == null) {
+ obj[key] = "";
+ } else {
+ if (obj[key] instanceof Array || obj[key] instanceof Object) {
+ test(obj[key])
+ }
+ }
+ }
+ }
+
}
// 鍝嶅簲澶辫触鐨勪緷璧栨��
@@ -81,8 +103,8 @@
// const BaseUrl = "http://192.168.31.18:9997"
// const webSocketUrl = "ws://192.168.31.18:9997/wrzs/ws/info"
-const BaseUrl = "http://192.168.31.14:9997";
-const webSocketUrl = "ws://192.168.31.14:9997/wrzs/ws/info"
+const BaseUrl = "http://localhost:9997";
+const webSocketUrl = "ws://localhost:9997/wrzs/ws/info"
export const onlineurl = "https://mx.jzeg.cn:9095";
// const BaseUrl = "http://192.168.0.100:9997";
// const webSocketUrl = "ws://192.168.0.100:9997/wrzs/ws/info"
@@ -96,68 +118,76 @@
// 璇锋眰鎷︽埅
const fetch = (url, opt) => {
- // 鏌ユ壘瀵瑰簲鍦板潃
- let urls = (globalApi[opt.url]?.url || globalApi[url]?.url);
- let params = opt.params ? ('?' + Object.keys(opt.params).map(key => key + '=' + opt.params[key]).join('&')) :
- '';
- opt.url = BaseUrl + urls + params
- opt.method = opt.method || "GET";
- var header = {}
- if (uni.getStorageSync('token')) {
- header = {
- "Authorization": "Bearer" + ' ' + uni.getStorageSync('token'),
- "CLIENT_TOC": "Y",
- }
- }
-
- opt.header = {
- ...opt.header,
- ...header
- }
-
- opt.data = opt.data || {};
-
- return new Promise((resolve, reject) => {
-
- let options = {}
-
- Object.keys(opt).map(key => {
- if (key !== "params") {
- return options[key] = opt[key]
+ // 鏌ユ壘瀵瑰簲鍦板潃
+ let urls = (globalApi[opt.url]?.url || globalApi[url]?.url);
+ let params = opt.params ? ('?' + Object.keys(opt.params).map(key => key + '=' + opt.params[key]).join('&')) :
+ '';
+ opt.url = BaseUrl + urls + params
+ opt.method = opt.method || "GET";
+ var header = {}
+ if (uni.getStorageSync('token')) {
+ header = {
+ "Authorization": "Bearer" + ' ' + uni.getStorageSync('token'),
+ "CLIENT_TOC": "Y",
}
- })
+ }
- uni.request(options)
- .then(res => interceptorsRes(res, resolve, reject))
- .catch(err => interceptorsErr(err, reject))
- })
-}
+ opt.header = {
+ ...opt.header,
+ ...header
+ }
+
+ opt.data = opt.data || {};
+
+ return new Promise((resolve, reject) => {
+
+ let options = {}
+ if (opt.data) {
+ Object.keys(opt.data).map(key => {
+ if (opt.data[key] == '' || opt.data[key] == "") {
+ opt.data[key] = null;
+ }
+ });
+ }
+
+ Object.keys(opt).map(key => {
+ if (key !== "params") {
+
+ return options[key] = opt[key]
+ }
+ })
+
+ uni.request(options)
+ .then(res => interceptorsRes(res, resolve, reject))
+ .catch(err => interceptorsErr(err, reject))
+ })
+ }
-// 鍝嶅簲鎷︽埅
-const interceptorsRes = ([err, resp], resolve, reject) => {
- const {
- statusCode,
- data
- } = resp;
- // 楠岃瘉http鐘舵�佺爜
- const handlerHTTPStatus = handlerCode[statusCode];
+ // 鍝嶅簲鎷︽埅
+ const interceptorsRes = ([err, resp], resolve, reject) => {
+ const {
+ statusCode,
+ data
+ } = resp;
+ // 楠岃瘉http鐘舵�佺爜
+ const handlerHTTPStatus = handlerCode[statusCode];
- // 娌℃湁鎵惧埌鐩稿簲鐘舵�佹搷浣滅洿鎺ヨ繑鍥�
- if (!handlerHTTPStatus) return resolve(resp);
- if (!handlerHTTPStatus(resp, true)) return reject(false);
- resolve(resp.data)
-}
+ // 娌℃湁鎵惧埌鐩稿簲鐘舵�佹搷浣滅洿鎺ヨ繑鍥�
+ if (!handlerHTTPStatus) return resolve(resp);
+ if (!handlerHTTPStatus(resp, true)) return reject(false);
+ resolve(resp.data)
+ }
-// 寮傚父澶勭悊
-const interceptorsErr = (err, reject) => {
- console.log("缃戠粶寮傚父", err)
- reject(err)
-}
+ // 寮傚父澶勭悊
+ const interceptorsErr = (err, reject) => {
+ console.log("缃戠粶寮傚父", err)
+ reject(err)
+ }
-export {
- fetch,
- BaseUrl,
- webSocketUrl
-}
\ No newline at end of file
+ export {
+ fetch,
+ BaseUrl,
+ webSocketUrl
+ }
--
Gitblit v1.9.1