Commit 88c1216e by chenwq1

feat:部署

1 parent 5253a6b2
Pipeline #142 for 88c1216e failed in 0 seconds
......@@ -27,6 +27,8 @@ interface ImportMetaEnv {
readonly VITE_APP_TITLE: string;
readonly VITE_API_BASE_URL: string;
readonly VITE_APP_ENV: "development" | "staging" | "production";
/** 静态资源与路由公共路径,如 /venus-usedcar-h5/;不设时非 development 构建默认为该子路径 */
readonly VITE_PUBLIC_BASE?: string;
}
interface ImportMeta {
......
{
"name": "venus-usedcar-h5",
"name": "venus-usedcar-quality",
"version": "1.0.0",
"description": "二手车H5移动端应用",
"private": true,
......
......@@ -12,23 +12,6 @@ const defaultBaseURL = import.meta.env.VITE_API_BASE_URL ?? "";
let config: Record<string, unknown> = {};
let requestInstance: null | Request = null;
function getCached<T>(key: string): null | T {
try {
const item = localStorage.getItem(key);
return item ? (JSON.parse(item) as T) : null;
} catch {
return null;
}
}
function setCache(key: string, value: unknown): void {
try {
localStorage.setItem(key, JSON.stringify(value));
} catch {
/* ignore */
}
}
function getToken(): string {
const token = localStorage.getItem(TOKEN_KEY);
return token ? `Bearer ${token}` : "";
......@@ -109,21 +92,14 @@ function initRequestInstance(cfg: Record<string, unknown>): void {
}
/**
* 获取远程配置(优先缓存)
* 获取远程配置(不落 localStorage,每次调用都请求配置中心;登录页进入时由路由再次拉取)
*/
export async function fetchConfig(): Promise<Record<string, unknown>> {
const cached = getCached<Record<string, unknown>>(CONFIG_CACHE_KEY);
if (cached) {
config = cached;
initRequestInstance(config);
return config;
}
try {
const res = await fetch(CONFIG_CENTER_URL);
const res = await fetch(CONFIG_CENTER_URL, { cache: "no-store" });
const data = (await res.json()) as Record<string, unknown>;
if (data) {
config = (data?.data ?? data) as Record<string, unknown>;
setCache(CONFIG_CACHE_KEY, config);
initRequestInstance(config);
} else {
initRequestInstance({ apiBaseUrl: defaultBaseURL });
......
/*
* @Author: cen
* @Date: 2026-03-25 20:49:38
* @Description:
* @FilePath: /venus-usedcar-h5/apps/web/venus-usedcar-quality/src/config/constants.ts
* @LastEditTime: 2026-03-26 19:53:34
* @LastEditors: cenchengwei@foreverht.com
* 可以输入预定的版权声明、个性签名、空行等
*/
/**
* 应用级常量(配置中心、鉴权存储 key 等)
*/
/** 二手车 H5 配置请求 URL */
export const CONFIG_CENTER_URL =
"https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=venus-usedcar-config&env=develop";
"https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=venus-usedcar-config";
/** 配置缓存 key */
export const CONFIG_CACHE_KEY = "venus_usedcar_config";
......
import { createRouter, createWebHistory } from "vue-router";
import { fetchConfig } from "@/config/center";
import { LOGIN_REDIRECT_KEY } from "@/config/constants";
import { useUserStore } from "@stores/modules/user.ts";
import { closeToast, showLoadingToast } from "vant";
......@@ -23,8 +24,18 @@ const router = createRouter({
// 不需要登录的白名单路由
const WHITE_LIST = new Set(["/inspect-detail", "/inspect-report", "/login"]);
router.beforeEach((to, from, next) => {
router.beforeEach(async (to, from, next) => {
const userStore = useUserStore();
const hasToken = !!userStore.token;
// SPA 内进入登录页时再拉配置(首屏由 main 拉过;已登录去登录页会重定向,不必请求)
if (to.path === "/login" && from.matched.length > 0 && !hasToken) {
try {
await fetchConfig();
} catch {
/* 失败时沿用内存/默认配置 */
}
}
if (routeLoadingTimer !== undefined) {
clearTimeout(routeLoadingTimer);
......@@ -47,8 +58,6 @@ router.beforeEach((to, from, next) => {
document.title = `${to.meta.title} - ${import.meta.env.VITE_APP_TITLE}`;
}
const hasToken = !!userStore.token;
// 1. 有 token 的情况
if (hasToken) {
// 已经登录还去登录页,直接跳到首页或来源页
......
......@@ -5,6 +5,7 @@ const {
phone,
code,
sending,
loggingIn,
countdown,
hasSent,
handleSendCode,
......@@ -61,7 +62,9 @@ const {
<van-button block
class="mt-6 !h-[52px] border-0 !bg-[#185EFE] !text-[#ffffff] text-[16px] font-medium"
:disabled="!phone || !code"
:disabled="!phone || !code || loggingIn"
:loading="loggingIn"
loading-text="登录中..."
round
@click="handleLogin">
登录
......
......@@ -5,6 +5,7 @@ const {
phone,
code,
sending,
loggingIn,
countdown,
hasSent,
handleSendCode,
......@@ -57,6 +58,9 @@ const {
<van-button block
class="mt-6 !h-[52px] w-[83%] border-0 bg-gradient-to-r from-[#84a9ff] to-[#90b5ff] text-[16px] font-medium"
:disabled="!phone || !code || loggingIn"
:loading="loggingIn"
loading-text="登录中..."
round
type="primary"
@click="handleLogin">
......
......@@ -25,6 +25,7 @@ export function useLogin() {
});
const sending = ref(false);
const loggingIn = ref(false);
const countdown = ref(0);
const hasSent = ref(false);
let timer: null | number = null;
......@@ -77,6 +78,7 @@ export function useLogin() {
}
try {
loggingIn.value = true;
const res = await login({
phone: phone.value,
verifyCode: code.value,
......@@ -101,6 +103,8 @@ export function useLogin() {
} catch (error) {
console.error("login error", error);
showFailToast("登录失败,请稍后重试");
} finally {
loggingIn.value = false;
}
};
......@@ -108,6 +112,7 @@ export function useLogin() {
phone,
code,
sending,
loggingIn,
countdown,
hasSent,
handleSendCode,
......
/*
* @Author: cen
* @Date: 2026-03-26 10:52:58
* @Description:
* @FilePath: /venus-usedcar-h5/apps/web/venus-usedcar-quality/vite.config.ts
* @LastEditTime: 2026-03-26 18:56:16
* @LastEditors: cenchengwei@foreverht.com
* 可以输入预定的版权声明、个性签名、空行等
*/
import { dirname, resolve } from "node:path";
import process from "node:process";
import { fileURLToPath } from "node:url";
......@@ -13,10 +22,26 @@ const __dirname = dirname(__filename);
const PORT = 8082;
function normalizePublicBase(path: string): string {
if (!path || path === "/") return "/";
return path.endsWith("/") ? path : `${path}/`;
}
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), "VITE_");
// 部署在 https://host/venus-usedcar-h5/;开发为根路径。可用 .env.* 中 VITE_PUBLIC_BASE 覆盖
let base: string;
if (env.VITE_PUBLIC_BASE) {
base = normalizePublicBase(env.VITE_PUBLIC_BASE);
} else if (mode === "development") {
base = "/";
} else {
base = "/venus-usedcar-h5/";
}
return {
base,
plugins: [
vue(),
AutoImport({
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!