feat: 整合Vite 环境变量和反向代理

This commit is contained in:
ray
2024-09-23 18:23:10 +08:00
parent 737f6a3ee5
commit 272d643744
16 changed files with 5187 additions and 6476 deletions

6
src/env.d.ts vendored
View File

@@ -1,7 +1,7 @@
/// <reference types="vite/client" />
declare module "*.vue" {
import { DefineComponent } from "vue"
const component: DefineComponent<{}, {}, any>
export default component
import { DefineComponent } from "vue";
const component: DefineComponent<{}, {}, any>;
export default component;
}

View File

@@ -51,8 +51,8 @@
{
"pagePath": "pages/profile/index",
"text": "我的",
"iconPath": "static/tabbar/my.png",
"selectedIconPath": "static/tabbar/my-active.png"
"iconPath": "static/tabbar/profile.png",
"selectedIconPath": "static/tabbar/profile-active.png"
}
]
}

View File

@@ -20,7 +20,7 @@ const userStore = useUserStore();
const handleLogin = async () => {
await userStore.login(username.value, password.value);
if (!!userStore.token) {
if (userStore.token) {
await userStore.getUserInfo(); // 登录成功后获取用户信息
uni.showToast({ title: "登录成功", icon: "success" });
uni.navigateBack(); // 登录成功后返回上一页

4
src/shime-uni.d.ts vendored
View File

@@ -1,6 +1,6 @@
export {}
export {};
declare module "vue" {
type Hooks = App.AppInstance & Page.PageInstance;
interface ComponentCustomOptions extends Hooks {}
}
}

View File

Before

Width:  |  Height:  |  Size: 4.0 KiB

After

Width:  |  Height:  |  Size: 4.0 KiB

View File

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

19
src/types/env.d.ts vendored Normal file
View File

@@ -0,0 +1,19 @@
// src/types/env.d.ts
interface ImportMetaEnv {
/**
* 应用端口
*/
VITE_APP_PORT: number;
/**
* API 基础路径
*/
VITE_APP_BASE_API: string;
/**
* API 服务器的 URL
*/
VITE_APP_API_URL: string;
}
interface ImportMeta {
readonly env: ImportMetaEnv;
}

View File

@@ -1,12 +1,10 @@
const API_HOST = "https://api.youlai.tech";
export default function request<T>(options: UniApp.RequestOptions): Promise<T> {
const token = uni.getStorageSync("token"); // 从本地缓存获取 token
return new Promise((resolve, reject) => {
uni.request({
...options,
url: `${API_HOST}${options.url}`,
url: `${import.meta.env.VITE_APP_BASE_API}${options.url}`,
header: {
...options.header,
Authorization: token,