Browse Source

no message

linwenxin 5 months ago
parent
commit
81d03f58ac

+ 3 - 0
.env.production

@@ -5,6 +5,7 @@ NODE_ENV = 'production'
 # VUE_APP_BASE_API = '/zfdminiapp'
 # VUE_APP_BASE_PATH = '/jsm-sxbh5/'
 # VUE_APP_HREF = 'https://jiasm.zfire.top/jsm-sxbh5'
+# VUE_APP_FILE_URL = 'https://jiasm.zfire.top/zfdminiapp/common/img/get?key='
 
 
 #正式环境配置
@@ -12,3 +13,5 @@ VUE_APP_BASE_URL = 'https://fw.greeapps.com'
 VUE_APP_BASE_API = '/zfdminiapp'
 VUE_APP_BASE_PATH = '/jsm-h5/'
 VUE_APP_HREF = 'https://fw.greeapps.com/jsm-h5'
+VUE_APP_FILE_URL = 'https://fw.greeapps.com/zfdminiapp/common/img/get?key='
+

+ 3 - 5
src/common/http/baseApi.js

@@ -1,9 +1,7 @@
-let BaseApi = '/aip' 
+let BaseApi = '/aip'
 
 if (process.env.NODE_ENV === 'production') {
-	BaseApi = 'xxxxx'
+  BaseApi = 'xxxxx'
 }
 
-export {
-	BaseApi
-}
+export { BaseApi }

+ 6 - 2
src/common/http/index.js

@@ -1,6 +1,6 @@
 import http from './interface'
 import { platform } from '../utils/index'
-import { webLogin, mini_env } from '@/common/utils/util'
+import { webLogin, mini_env, replaceStringInObject } from '@/common/utils/util'
 import store from '@/store/index.js'
 
 import { goLoginPage } from '@/mixins/index.js'
@@ -251,7 +251,11 @@ export const axios = function (obj = {}) {
         if (obj.isLoading) {
           uni.hideLoading()
         }
-        const res = ress.data
+        const res = replaceStringInObject(
+          ress.data,
+          'https://zfire-jsm-h.oss-cn-shenzhen.aliyuncs.com/',
+          'https://fw.greeapps.com/zfdminiapp/common/img/get?key='
+        )
         if (whiteCodes.indexOf(res.code) < 0) {
           if (res.code === 1001) {
             webLogin(true)

+ 94 - 95
src/common/http/interface.js

@@ -1,117 +1,116 @@
 // import { BaseApi } from './baseApi'
 export default {
-	config: {
-		baseUrl: process.env.VUE_APP_BASE_URL + process.env.VUE_APP_BASE_API,
-		header: {
-			'Content-Type':'application/json;charset=UTF-8',
-			'Content-Type':'application/x-www-form-urlencoded'
-		},
-		data: {},
-		method: "GET",
-		dataType: "json",  /* 如设为json,会对返回的数据做一次 JSON.parse */
-		responseType: "text",
-		success() {},
-		fail() {},
-		complete() {}
-	},
-	interceptor: {
-		request: null,
-		response: null
-	},
-	request(options) {
-		if (!options) {
-			options = {}
-		}
-		options.baseUrl = options.baseUrl || this.config.baseUrl
-		options.dataType = options.dataType || this.config.dataType
-		options.url = options.baseUrl + options.url
-		options.data = options.data || {}
-		options.method = options.method || this.config.method
+  config: {
+    baseUrl: process.env.VUE_APP_BASE_URL + process.env.VUE_APP_BASE_API,
+    header: {
+      'Content-Type': 'application/json;charset=UTF-8',
+      'Content-Type': 'application/x-www-form-urlencoded'
+    },
+    data: {},
+    method: 'GET',
+    dataType: 'json' /* 如设为json,会对返回的数据做一次 JSON.parse */,
+    responseType: 'text',
+    success() {},
+    fail() {},
+    complete() {}
+  },
+  interceptor: {
+    request: null,
+    response: null
+  },
+  request(options) {
+    if (!options) {
+      options = {}
+    }
+    options.baseUrl = options.baseUrl || this.config.baseUrl
+    options.dataType = options.dataType || this.config.dataType
+    options.url = options.baseUrl + options.url
+    options.data = options.data || {}
+    options.method = options.method || this.config.method
 
-		return new Promise(async (resolve, reject) => {
-			let _config = null
+    return new Promise(async (resolve, reject) => {
+      let _config = null
 
-			options.complete = (response) => {
-				let statusCode = response.statusCode
-				response.config = _config
-				if (process.env.NODE_ENV === 'development') {
-					if (statusCode === 200) {
-						////console.log("【" + _config.requestId + "】 结果:" + JSON.stringify(response.data))
-					}
-				}
-				if (this.interceptor.response) {
+      options.complete = response => {
+        let statusCode = response.statusCode
+        response.config = _config
+        if (process.env.NODE_ENV === 'development') {
+          if (statusCode === 200) {
+            ////console.log("【" + _config.requestId + "】 结果:" + JSON.stringify(response.data))
+          }
+        }
+        if (this.interceptor.response) {
+          let newResponse = this.interceptor.response(response)
+          if (newResponse) {
+            response = newResponse
+          }
+        }
+        // 统一的响应日志记录
+        //_reslog(response)
+        if (statusCode === 200) {
+          //成功
+          resolve(response)
+        } else {
+          reject(response)
+        }
+      }
 
-					let newResponse = this.interceptor.response(response)
-					if (newResponse) {
-						response = newResponse
-					}
-				}
-				// 统一的响应日志记录
-				//_reslog(response)
-				if (statusCode === 200) { //成功
-					resolve(response);
-				} else {
-					reject(response)
-				}
-			}
+      _config = Object.assign({}, this.config, options)
+      _config.requestId = new Date().getTime()
 
-			_config = Object.assign({}, this.config, options)
-			_config.requestId = new Date().getTime()
+      if (this.interceptor.request) {
+        await this.interceptor.request(_config)
+      }
 
-			if (this.interceptor.request) {
-				await this.interceptor.request(_config)
-			}
+      // 统一的请求日志记录
+      //_reqlog(_config)
 
-			// 统一的请求日志记录
-			//_reqlog(_config)
+      if (process.env.NODE_ENV === 'development') {
+        //console.log("【" + _config.requestId + "】 地址:" + _config.url)
+        if (_config.data) {
+          //console.log("【" + _config.requestId + "】 参数:" + JSON.stringify(_config.data))
+        }
+      }
 
-			if (process.env.NODE_ENV === 'development') {
-				//console.log("【" + _config.requestId + "】 地址:" + _config.url)
-				if (_config.data) {
-					//console.log("【" + _config.requestId + "】 参数:" + JSON.stringify(_config.data))
-				}
-			}
-
-			uni.request(_config);
-		});
-	}
+      uni.request(_config)
+    })
+  }
 }
 
-
 /**
  * 请求接口日志记录
  */
 function _reqlog(req) {
-	if (process.env.NODE_ENV === 'development') {
-		//console.log("【" + req.requestId + "】 地址:" + req.url)
-		if (req.data) {
-			//console.log("【" + req.requestId + "】 请求参数:" + JSON.stringify(req.data))
-		}
-	}
-	//TODO 调接口异步写入日志数据库
+  if (process.env.NODE_ENV === 'development') {
+    //console.log("【" + req.requestId + "】 地址:" + req.url)
+    if (req.data) {
+      //console.log("【" + req.requestId + "】 请求参数:" + JSON.stringify(req.data))
+    }
+  }
+  //TODO 调接口异步写入日志数据库
 }
 
 /**
  * 响应接口日志记录
  */
 function _reslog(res) {
-	let _statusCode = res.statusCode;
-	if (process.env.NODE_ENV === 'development') {
-		//console.log("【" + res.config.requestId + "】 地址:" + res.config.url)
-		if (res.config.data) {
-			//console.log("【" + res.config.requestId + "】 请求参数:" + JSON.stringify(res.config.data))
-		}
-		//console.log("【" + res.config.requestId + "】 响应结果:" + JSON.stringify(res))
-	}
-	//TODO 除了接口服务错误外,其他日志调接口异步写入日志数据库
-	switch(_statusCode){
-		case 200:
-			break;
-		case 401:
-			break;
-		case 404:
-			break;
-		default:
-			break;
-	}
+  let _statusCode = res.statusCode
+  if (process.env.NODE_ENV === 'development') {
+    //console.log("【" + res.config.requestId + "】 地址:" + res.config.url)
+    if (res.config.data) {
+      //console.log("【" + res.config.requestId + "】 请求参数:" + JSON.stringify(res.config.data))
+    }
+    //console.log("【" + res.config.requestId + "】 响应结果:" + JSON.stringify(res))
+  }
+  //TODO 除了接口服务错误外,其他日志调接口异步写入日志数据库
+  switch (_statusCode) {
+    case 200:
+      break
+    case 401:
+      break
+    case 404:
+      break
+    default:
+      break
+  }
 }

+ 2 - 2
src/common/http/upload-file.js

@@ -17,7 +17,7 @@ const upload = async function (
   obj,
   successCallback = new Function(),
   errCallBack = new Function(),
-  progressCallback = new Function(),
+  progressCallback = new Function()
 ) {
   let fileName = file.name
 
@@ -53,7 +53,7 @@ const upload = async function (
     cache: false,
     contentType: false,
     headers: {
-      'x-token':store.getters.token, // 请求头
+      'x-token': store.getters.token // 请求头
     },
     // 这里,我们可以做上传经度
     onUploadProgress: function (progressEvent) {

+ 23 - 2
src/common/utils/util.js

@@ -8,6 +8,15 @@ import axios2 from 'axios'
 
 import { setStorage, getStorage, removeStorage } from '@/common/utils/storage.js'
 
+export function replaceStringInObject(obj, target, replacement) {
+  // 将对象转换为字符串
+  let str = JSON.stringify(obj)
+  // 替换所有目标字符串为替换字符串
+  str = str.replace(new RegExp(target, 'g'), replacement)
+  // 将字符串转换回对象
+  return JSON.parse(str)
+}
+
 export const mini_env = function (cb) {
   if (isWeixin()) {
     wx.miniProgram.getEnv(res => {
@@ -398,7 +407,13 @@ export const uploadImgFull = async function (file) {
       })
       .then(res => {
         uni.hideLoading()
-        resolve(res.data.data)
+        resolve(
+          replaceStringInObject(
+            res.data.data,
+            'https://zfire-jsm-h.oss-cn-shenzhen.aliyuncs.com/',
+            'https://fw.greeapps.com/zfdminiapp/common/img/get?key='
+          )
+        )
       })
     // #endif
 
@@ -413,7 +428,13 @@ export const uploadImgFull = async function (file) {
       filePath: file,
       success(res) {
         uni.hideLoading()
-        resolve(JSON.parse(res.data).data)
+        resolve(
+          replaceStringInObject(
+            JSON.parse(res.data).data,
+            'https://zfire-jsm-h.oss-cn-shenzhen.aliyuncs.com/',
+            'https://fw.greeapps.com/zfdminiapp/common/img/get?key='
+          )
+        )
       },
       fail(err) {
         reject(err)