From 5f402488d42f7280dbdb6107571af29ca1a9962e Mon Sep 17 00:00:00 2001 From: chenchun Date: Fri, 23 Aug 2024 18:26:26 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E7=99=BB=E5=BD=95=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E6=94=B9=E9=80=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Yi.Pure.Vue3/.env.development | 13 ++++++++++ Yi.Pure.Vue3/.env.production | 8 +++++- Yi.Pure.Vue3/build/utils.ts | 6 ++++- Yi.Pure.Vue3/mock/asyncRoutes.ts | 2 +- Yi.Pure.Vue3/src/api/user.ts | 14 +++++++++- Yi.Pure.Vue3/src/utils/http/index.ts | 1 + Yi.Pure.Vue3/src/views/login/index.vue | 30 ++++++++++++++++++---- Yi.Pure.Vue3/src/views/login/utils/rule.ts | 2 +- Yi.Pure.Vue3/types/global.d.ts | 4 +++ Yi.Pure.Vue3/vite.config.ts | 19 ++++++++++++-- Yi.RuoYi.Vue3/.env.development | 5 ---- Yi.RuoYi.Vue3/src/utils/request.js | 16 +----------- 12 files changed, 88 insertions(+), 32 deletions(-) diff --git a/Yi.Pure.Vue3/.env.development b/Yi.Pure.Vue3/.env.development index 90d1146f..0405b42d 100644 --- a/Yi.Pure.Vue3/.env.development +++ b/Yi.Pure.Vue3/.env.development @@ -6,3 +6,16 @@ VITE_PUBLIC_PATH = / # 开发环境路由历史模式(Hash模式传"hash"、HTML5模式传"h5"、Hash模式带base参数传"hash,base参数"、HTML5模式带base参数传"h5,base参数") VITE_ROUTER_HISTORY = "hash" + + +# 开发环境 +VITE_APP_BASE_API = '/dev-api' + +# ws/开发环境 +VITE_APP_BASE_WS = '/dev-ws' + +#RBAC +# VITE_APP_BASE_URL='http://localhost:19001/api' + +#长连接 +VITE_APP_BASE_URL_WS='http://localhost:19001/hub' diff --git a/Yi.Pure.Vue3/.env.production b/Yi.Pure.Vue3/.env.production index 84e60861..066186a8 100644 --- a/Yi.Pure.Vue3/.env.production +++ b/Yi.Pure.Vue3/.env.production @@ -7,7 +7,13 @@ VITE_ROUTER_HISTORY = "hash" # 是否在打包时使用cdn替换本地库 替换 true 不替换 false VITE_CDN = false +# 生产环境 +VITE_APP_BASE_API = '/prod-api' + +# ws/开发环境 +VITE_APP_BASE_WS = '/prod-ws' + # 是否启用gzip压缩或brotli压缩(分两种情况,删除原始文件和不删除原始文件) # 压缩时不删除原始文件的配置:gzip、brotli、both(同时开启 gzip 与 brotli 压缩)、none(不开启压缩,默认) # 压缩时删除原始文件的配置:gzip-clear、brotli-clear、both-clear(同时开启 gzip 与 brotli 压缩)、none(不开启压缩,默认) -VITE_COMPRESSION = "none" \ No newline at end of file +VITE_COMPRESSION = "none" diff --git a/Yi.Pure.Vue3/build/utils.ts b/Yi.Pure.Vue3/build/utils.ts index 3d778fe6..27dceb79 100644 --- a/Yi.Pure.Vue3/build/utils.ts +++ b/Yi.Pure.Vue3/build/utils.ts @@ -56,7 +56,11 @@ const wrapperEnv = (envConf: Recordable): ViteEnv => { VITE_ROUTER_HISTORY: "", VITE_CDN: false, VITE_HIDE_HOME: "false", - VITE_COMPRESSION: "none" + VITE_COMPRESSION: "none", + VITE_APP_BASE_API: "", + VITE_APP_BASE_URL: "", + VITE_APP_BASE_URL_WS: "", + VITE_APP_BASE_WS: "" }; for (const envName of Object.keys(envConf)) { diff --git a/Yi.Pure.Vue3/mock/asyncRoutes.ts b/Yi.Pure.Vue3/mock/asyncRoutes.ts index 5ca55597..83468576 100644 --- a/Yi.Pure.Vue3/mock/asyncRoutes.ts +++ b/Yi.Pure.Vue3/mock/asyncRoutes.ts @@ -322,7 +322,7 @@ const tabsRouter = { export default defineFakeRoute([ { - url: "/get-async-routes", + url: `/dev-api/get-async-routes`, method: "get", response: () => { return { diff --git a/Yi.Pure.Vue3/src/api/user.ts b/Yi.Pure.Vue3/src/api/user.ts index 2404c008..3cc6ade4 100644 --- a/Yi.Pure.Vue3/src/api/user.ts +++ b/Yi.Pure.Vue3/src/api/user.ts @@ -1,5 +1,12 @@ import { http } from "@/utils/http"; +export type imageCaptcha = { + //uuid + uuid: string; // 使用字符串表示 Guid + //验证码图片字节数值 + img: Uint8Array | null; +}; + export type UserResult = { success: boolean; data: { @@ -70,7 +77,12 @@ type ResultTable = { /** 登录 */ export const getLogin = (data?: object) => { - return http.request("post", "/login", { data }); + return http.request("post", "/account/login", { data }); +}; + +/** 获取验证码 */ +export const getCodeImg = () => { + return http.request("get", "/account/captcha-image"); }; /** 刷新`token` */ diff --git a/Yi.Pure.Vue3/src/utils/http/index.ts b/Yi.Pure.Vue3/src/utils/http/index.ts index 19b5be24..62722696 100644 --- a/Yi.Pure.Vue3/src/utils/http/index.ts +++ b/Yi.Pure.Vue3/src/utils/http/index.ts @@ -16,6 +16,7 @@ import { useUserStoreHook } from "@/store/modules/user"; // 相关配置请参考:www.axios-js.com/zh-cn/docs/#axios-request-config-1 const defaultConfig: AxiosRequestConfig = { + baseURL: import.meta.env.VITE_APP_BASE_API, // 请求超时时间 timeout: 10000, headers: { diff --git a/Yi.Pure.Vue3/src/views/login/index.vue b/Yi.Pure.Vue3/src/views/login/index.vue index a0bcaf3e..0002b762 100644 --- a/Yi.Pure.Vue3/src/views/login/index.vue +++ b/Yi.Pure.Vue3/src/views/login/index.vue @@ -24,6 +24,7 @@ import { ref, toRaw, reactive, watch, computed } from "vue"; import { useRenderIcon } from "@/components/ReIcon/src/hooks"; import { useTranslationLang } from "@/layout/hooks/useTranslationLang"; import { useDataThemeChange } from "@/layout/hooks/useDataThemeChange"; +import { getCodeImg } from "@/api/user"; import dayIcon from "@/assets/svg/day.svg?component"; import darkIcon from "@/assets/svg/dark.svg?component"; @@ -37,6 +38,7 @@ defineOptions({ name: "Login" }); +const codeUrl = ref(""); const imgCode = ref(""); const loginDay = ref(7); const router = useRouter(); @@ -57,18 +59,30 @@ const { title, getDropdownItemStyle, getDropdownItemClass } = useNav(); const { locale, translationCh, translationEn } = useTranslationLang(); const ruleForm = reactive({ - username: "admin", - password: "admin123", - verifyCode: "" + username: "cc", + password: "123456", + verifyCode: "", + uuid: "" }); +//获取验证码 +const getCode = () => { + getCodeImg().then(res => { + codeUrl.value = "data:image/gif;base64," + res.img; + ruleForm.uuid = res.uuid; + }); +}; + const onLogin = async (formEl: FormInstance | undefined) => { if (!formEl) return; await formEl.validate(valid => { if (valid) { loading.value = true; useUserStoreHook() - .loginByUsername({ username: ruleForm.username, password: "admin123" }) + .loginByUsername({ + username: ruleForm.username, + password: ruleForm.password + }) .then(res => { if (res.success) { // 获取后端路由 @@ -114,6 +128,7 @@ watch(checked, bool => { watch(loginDay, value => { useUserStoreHook().SET_LOGINDAY(value); }); +getCode();