From fc8377adde573a3befc2771f9fb914bcfeb3dac8 Mon Sep 17 00:00:00 2001 From: taoran Date: Thu, 30 Nov 2023 18:53:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=99=BE=E5=BA=A6=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=EF=BC=8C=E5=A4=84=E7=90=86vite=E4=BB=A3=E7=90=86=E5=90=8Eip?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E4=B8=8D=E5=8F=AF=E7=94=A8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 10 ++++++++-- README.md | 4 +--- index.html | 11 +++++++++++ mock/tools.ts | 24 ++++++++++-------------- src/api/ip/index.ts | 2 +- src/router/index.ts | 1 + src/utils/request.ts | 3 +-- vite.config.ts | 24 +++++++++++++++++++----- 8 files changed, 52 insertions(+), 27 deletions(-) diff --git a/.env.example b/.env.example index d0d84de..b59056b 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,12 @@ # 变量必须以 VITE_ 为前缀才能暴露给外部读取 NODE_ENV = 'dev' +# 网站名称 VITE_APP_TITLE = '工具坊' +# 网站域名 VITE_APP_WEBSITE = 'xxx.xxx.com' -VITE_APP_BASE_API = '/api' -VITE_SERVE = '' \ No newline at end of file +# base api +VITE_APP_BASE_API = '/v1' +# 服务端地址: https://xxx.xxx.com +VITE_SERVE = '' +# 是否使用mock: bool +VITE_IS_MOCK = 'true' \ No newline at end of file diff --git a/README.md b/README.md index e0a101b..f78297c 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ - - # 工具站 -当前包含工具: +包含工具: - 时间戳转换 - MD5在线加密 - Json在线转换 diff --git a/index.html b/index.html index 725f85d..3a42269 100644 --- a/index.html +++ b/index.html @@ -5,9 +5,20 @@ <%= title %> + +
+ diff --git a/mock/tools.ts b/mock/tools.ts index 511e4b0..8487ec1 100644 --- a/mock/tools.ts +++ b/mock/tools.ts @@ -3,8 +3,8 @@ function getTools() { return [ { id: 1, - value: '时间戳转换', - img: 'https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg', + title: '时间戳转换', + logo: 'https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg', desc: '在线时间戳转换工具以及获取当前时间戳', url: '/timetran', cateId: 2, @@ -12,7 +12,7 @@ function getTools() { }, { id: 1, - value: 'MD5在线加密', + title: 'MD5在线加密', logo: 'https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg', desc: 'MD5在线加密,长度包含32位、16位', url: '/MD5', @@ -21,7 +21,7 @@ function getTools() { }, { id: 1, - value: 'Json在线转换', + title: 'Json在线转换', logo: 'https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg', desc: '在线编辑json, 语法检查', url: '/json', @@ -30,7 +30,7 @@ function getTools() { }, { id: 1, - value: '正则测试工具', + title: '正则测试工具', logo: 'https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg', desc: '正则表达式测试工具, 常用正则表达式', url: '/reg', @@ -39,7 +39,7 @@ function getTools() { }, { id: 1, - value: 'Unicode转中文', + title: 'Unicode转中文', logo: 'https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg', desc: 'Unicode和中文的相互转换', url: '/unicode', @@ -48,7 +48,7 @@ function getTools() { }, { id: 1, - value: '字数统计', + title: '字数统计', logo: 'https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg', desc: '在线统计字符串的字数、段落、标点符号数量', url: '/wordCount', @@ -57,7 +57,7 @@ function getTools() { }, { id: 1, - value: 'IP查询', + title: 'IP查询', logo: 'https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg', desc: '在线查询ip地址、ip归属地', url: '/ip', @@ -66,7 +66,7 @@ function getTools() { }, { id: 1, - value: '常用进制转换', + title: '常用进制转换', logo: 'https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg', desc: '在线进制转换工具,可在2到64进制之间相互转换', url: '/scaletran', @@ -75,7 +75,7 @@ function getTools() { }, { id: 1, - value: '在线图片处理', + title: '在线图片处理', logo: 'https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg', desc: '在线图片裁剪,标注,滤镜,画等操作', url: '/signimage', @@ -88,10 +88,6 @@ function getTools() { //获取tools分类 function getToolsCate() { return [ - { - id: 0, - title: '全部工具', - }, { id: 2, title: '开发运维' diff --git a/src/api/ip/index.ts b/src/api/ip/index.ts index cf6f042..dce7ad7 100644 --- a/src/api/ip/index.ts +++ b/src/api/ip/index.ts @@ -9,7 +9,7 @@ import type { enum API { //获取ip - GET_IP = '/v1/ip/get?ip=' + GET_IP = '/ip/get?ip=' } //获取ip export const getIp = (ip:string) => request.get(API.GET_IP + ip) \ No newline at end of file diff --git a/src/router/index.ts b/src/router/index.ts index 3b9f41d..81fd532 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -16,6 +16,7 @@ const router = createRouter({ }) router.beforeEach((to, from, next) => { if (to.meta.title && to.meta.title != '') { + console.log(from) let oldTitle = document.title document.title = to.meta.title + ' - ' + oldTitle } diff --git a/src/utils/request.ts b/src/utils/request.ts index aad8214..8b8dabb 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -2,8 +2,7 @@ import axios from "axios"; import { ElMessage } from "element-plus"; //创建axios实例 let request = axios.create({ - //判断mock是否启用 - baseURL: import.meta.env.VITE_IS_MOCK == 'true' ? import.meta.env.VITE_APP_BASE_API : import.meta.env.VITE_SERVE + import.meta.env.VITE_APP_BASE_API, + baseURL: import.meta.env.VITE_APP_BASE_API, timeout: 5000 }) //请求拦截器 diff --git a/vite.config.ts b/vite.config.ts index 2309a99..3afcc47 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -37,13 +37,27 @@ export default defineConfig(({command, mode}) => { }, server: { proxy: { - '/api': { + '/v1/ip': { target: 'https://searchplugin.csdn.net', //ip查询 changeOrigin: true, - pathRewrite: { - '^/api': '' - } - } + rewrite: (path) => path.replace(/^\/v1\/ip/, '/api/v1/ip'), + // bypass(req, res, options) { + // console.log(1111) + // const proxyUrl = new URL(options.rewrite(req.url) || '', (options.target) as string)?.href || '' + // req.headers['x-req-proxyUrl'] = proxyUrl; + // res.setHeader("x-res-proxyUrl", proxyUrl) + // } + }, + [env.VITE_APP_BASE_API] : { + target: env.VITE_SERVE, + changeOrigin: true, + // bypass(req, res, options) { + // const proxyUrl = new URL(options.rewrite(req.url) || '', (options.target) as string)?.href || '' + // req.headers['x-req-proxyUrl'] = proxyUrl; + // res.setHeader("x-res-proxyUrl", proxyUrl) + // } + }, + } } }