shish пре 11 месеци
родитељ
комит
5c855f1024
3 измењених фајлова са 76 додато и 40 уклоњено
  1. 13 9
      hdh5/admin/ghs/pay.vue
  2. 5 0
      hdh5/api/ghs/index.js
  3. 58 31
      hdh5/plugins/luch-request_0.0.7/request.js

+ 13 - 9
hdh5/admin/ghs/pay.vue

@@ -105,7 +105,7 @@
 </template>
 
 <script>
-import { } from '@/api/payment';
+import { getGhsData } from '@/api/ghs';
 
 // 优化:使用常量避免重复创建
 const KEY_TYPES = {
@@ -151,12 +151,13 @@ export default {
 			amountBuffer: '0',
 			updateScheduled: false,
 			updateTimer: null,
-			orderId: null,
 			// 优化:缓存计算结果
 			_cachedCanPay: false,
 			_lastAmount: '0',
 			// 弹框状态
-			showConfirm: false
+			showConfirm: false,
+			id:0,
+			salt:''
 		}
 	},
 	computed: {
@@ -172,13 +173,16 @@ export default {
 		}
 	},
 	onLoad(options) {
-		// 从扫码页面传递过来的金额
-		if (options.amount) {
-			this.setAmount(options.amount);
+		if (options.id) {
+			this.id = options.id;
 		}
-		// 从扫码页面传递过来的订单信息
-		if (options.orderId) {
-			this.orderId = options.orderId;
+		if (options.salt) {
+			this.salt = options.salt;
+		}
+		if (this.id && this.salt) {
+			getGhsData({id:this.id,salt:this.salt}).then(res => {
+				console.log(res)
+			})
 		}
 	},
 	methods: {

+ 5 - 0
hdh5/api/ghs/index.js

@@ -0,0 +1,5 @@
+import https from '@/plugins/luch-request_0.0.7/request'
+
+export const getGhsData = data => {
+	return https.get('/ghs/get-ghs-data', data)
+}

+ 58 - 31
hdh5/plugins/luch-request_0.0.7/request.js

@@ -123,41 +123,68 @@ class Request {
 		options.data = options.data || this.config.data
 		options.header = options.header || this.config.header
 		options.method = options.method || this.config.method
-
-		let _config = null
-		if (config) {
-			response.config = _config
-			response.config.config = config
-		}
-
-		if (config && config.hideError) {
-			// 隐藏错误提示
-		} else {
-			// 显示错误提示
-			if (response.statusCode !== 200) {
-				uni.showToast({
-					title: response.data.message || '请求失败',
-					icon: 'none'
-				})
+		
+		return new Promise((resolve, reject) => {
+			let next = true
+			let _config = null
+			
+			options.complete = (response) => {
+				const statusCode = response.statusCode
+				response.config = _config
+				response.config.config = config
+				response = this.requestComFun(response)
+				
+				// 全局忽略错误,在单个请求里面自行处理
+				if (config && config.hideError) {
+					resolve(response.data)
+					return
+				}
+				
+				if (statusCode === 200) {
+					if (response.data.code === 1) {
+						resolve(response.data)
+					} else {
+						if (response.data.code == 0) {
+							if (!config.hideError) {
+								uni.showToast({ title: response.data.msg, icon: 'none', mask: false, duration: 2000 })
+							}
+							reject(response.data)
+						} else if (response.data.code && response.data.code == -1) {
+							// 特殊处理
+						} else if (response.data.code == 2) {
+							uni.removeStorageSync('token')
+							uni.removeStorageSync('shopUser')
+							uni.removeStorageSync('account')
+						} else {
+							if (!config.hideError) {
+								uni.showToast({ title: response.data.msg, icon: 'none', mask: false })
+							}
+							reject(response.data)
+						}
+					}
+				} else {
+					if (!config.hideError) {
+						uni.showToast({
+							title: response.data.message || '请求失败',
+							icon: 'none'
+						})
+					}
+					reject(response)
+				}
 			}
-		}
-
-		if (config && config.hideError) {
-			// 隐藏错误提示
-		} else {
-			// 显示错误提示
-			if (response.statusCode !== 200) {
-				uni.showToast({
-					title: response.data.message || '请求失败',
-					icon: 'none'
-				})
+			
+			const cancel = (t = 'handle cancel') => {
+				const err = {
+					errMsg: t,
+					config: afC
+				}
+				reject(err)
+				next = false
 			}
-		}
-
-		return new Promise((resolve, reject) => {
+			
 			const afC = { ...this.config, ...options, config: config }
 			_config = { ...afC, ...this.requestBeforeFun(afC, cancel) }
-
+			if (!next) return
 			uni.request(_config)
 		})
 	}