feat: ✨ 整合Vite 环境变量和反向代理
This commit is contained in:
6
src/env.d.ts
vendored
6
src/env.d.ts
vendored
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -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
4
src/shime-uni.d.ts
vendored
@@ -1,6 +1,6 @@
|
||||
export {}
|
||||
export {};
|
||||
|
||||
declare module "vue" {
|
||||
type Hooks = App.AppInstance & Page.PageInstance;
|
||||
interface ComponentCustomOptions extends Hooks {}
|
||||
}
|
||||
}
|
||||
|
||||
|
Before Width: | Height: | Size: 4.0 KiB After Width: | Height: | Size: 4.0 KiB |
|
Before Width: | Height: | Size: 3.9 KiB After Width: | Height: | Size: 3.9 KiB |
19
src/types/env.d.ts
vendored
Normal file
19
src/types/env.d.ts
vendored
Normal 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;
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user