From 79091dc40201fc92834e331da6159e0251f510ed Mon Sep 17 00:00:00 2001 From: winixt Date: Wed, 15 Nov 2023 20:40:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20cache=20=E6=B2=A1=E6=9C=89=20config=20?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/template/cacheControl.js | 1 + packages/fes-template-h5/src/app.js | 81 +++++++++---------- packages/fes-template-h5/src/pages/index.vue | 4 +- 3 files changed, 43 insertions(+), 43 deletions(-) diff --git a/packages/fes-plugin-request/src/template/cacheControl.js b/packages/fes-plugin-request/src/template/cacheControl.js index fafb44398..59a82ee65 100644 --- a/packages/fes-plugin-request/src/template/cacheControl.js +++ b/packages/fes-plugin-request/src/template/cacheControl.js @@ -170,6 +170,7 @@ export default async (ctx, next) => { const cacheData = getCacheData({ key: ctx.key, cacheType: config.cache.cacheType }); if (cacheData) { ctx.response = { + config, data: cacheData, }; return; diff --git a/packages/fes-template-h5/src/app.js b/packages/fes-template-h5/src/app.js index c20a9277a..2f1985764 100644 --- a/packages/fes-template-h5/src/app.js +++ b/packages/fes-template-h5/src/app.js @@ -1,46 +1,43 @@ import { defineRuntimeConfig } from '@fesjs/fes'; export default defineRuntimeConfig({ - // request: {}, + request: { + baseURL: '/ras-mas', + dataHandler(data) { + console.log('data', data); + if (data?.code !== '0') { + if (data.code === '10000') { + console.log('code', data.code); + } + if (data?.code === '20000') { + console.log('code', data.code); + } + throw new Error(data); + } + return data.result ? data.result : data; + }, + errorHandler(error) { + if (error.response) { + // 请求成功发出且服务器也响应了状态码,但状态代码超出了 2xx 的范围 + console.log(error.response.data); + console.log(error.response.status); + console.log(error.response.headers); + } else if (error.request) { + // 请求已经成功发起,但没有收到响应 + // `error.request` 在浏览器中是 XMLHttpRequest 的实例, + // 而在node.js中是 http.ClientRequest 的实例 + console.log(error.request); + } else if (error.type) { + // 插件异常 + console.log(error.msg); + } else { + // 发送请求时出了点问题 + console.log('Error', error.message); + } + console.log('error', error.config); + }, + }, + patchRoutes: () => { + console.log('patchRoutes'); + }, }); - -// export default defineRuntimeConfig({ -// request: { -// baseURL: '/ras-mas', -// dataHandler(data) { -// if (data?.code !== '0') { -// if (data.code === '10000') { -// console.log('code', data.code); -// } -// if (data?.code === '20000') { -// console.log('code', data.code); -// } -// throw new Error(data); -// } -// return data.result ? data.result : data; -// }, -// errorHandler(error) { -// if (error.response) { -// // 请求成功发出且服务器也响应了状态码,但状态代码超出了 2xx 的范围 -// console.log(error.response.data); -// console.log(error.response.status); -// console.log(error.response.headers); -// } else if (error.request) { -// // 请求已经成功发起,但没有收到响应 -// // `error.request` 在浏览器中是 XMLHttpRequest 的实例, -// // 而在node.js中是 http.ClientRequest 的实例 -// console.log(error.request); -// } else if (error.type) { -// // 插件异常 -// console.log(error.msg); -// } else { -// // 发送请求时出了点问题 -// console.log('Error', error.message); -// } -// console.log(error.config); -// }, -// }, -// patchRoutes: () => { -// console.log('patchRoutes'); -// }, -// }); diff --git a/packages/fes-template-h5/src/pages/index.vue b/packages/fes-template-h5/src/pages/index.vue index d118c5058..9c9eb5356 100644 --- a/packages/fes-template-h5/src/pages/index.vue +++ b/packages/fes-template-h5/src/pages/index.vue @@ -3,11 +3,13 @@