Commit 6c9e2e67 by chenwq1

feat: 更新二手车质检平台功能

- 修改 pnpm-lock.yaml,更新依赖版本和规范
- 新增 Tailwind CSS 和 PostCSS 配置
- 实现 OSS 文件上传功能
- 优化路由和状态管理,增强用户体验
- 添加新组件和页面,支持车检报告展示
- 更新样式和布局,提升界面友好性
1 parent 959b6809
Pipeline #67 for 6c9e2e67 failed in 0 seconds
Showing 30 changed files with 824 additions and 304 deletions
export default {
// 必填:填你自己的真实值(本文件建议不要提交到仓库)
ACCESS_KEY_ID: "LTAI5tCRcCUgd7bt1J7JY596",
ACCESS_KEY_SECRET: "kJos9mgylkR5ztosnDt8Asrc3ulgqy",
STS_ROLE_ARN: "OPTIONAL",
BUCKET: "glsk-oss",
REGION: "oss-cn-shenzhen",
DIR: "usedCarH5/",
PORT: 3000,
};
...@@ -11,11 +11,14 @@ ...@@ -11,11 +11,14 @@
"type-check": "vue-tsc --noEmit" "type-check": "vue-tsc --noEmit"
}, },
"dependencies": { "dependencies": {
"axios": "^1.12.2",
"@vueuse/core": "catalog:", "@vueuse/core": "catalog:",
"dayjs": "catalog:", "dayjs": "catalog:",
"glsk-toolkit": "catalog:", "glsk-toolkit": "catalog:",
"glsk-oss-jssdk": "catalog:",
"pinia": "catalog:", "pinia": "catalog:",
"pinia-plugin-persistedstate": "catalog:", "pinia-plugin-persistedstate": "catalog:",
"tailwindcss": "catalog:",
"vant": "^4.9.0", "vant": "^4.9.0",
"vue": "catalog:", "vue": "catalog:",
"vue-router": "catalog:" "vue-router": "catalog:"
...@@ -25,7 +28,7 @@ ...@@ -25,7 +28,7 @@
"@vitejs/plugin-vue": "catalog:", "@vitejs/plugin-vue": "catalog:",
"autoprefixer": "catalog:", "autoprefixer": "catalog:",
"postcss": "catalog:", "postcss": "catalog:",
"postcss-px-to-viewport-8-plugin": "^1.2.5", "postcss-pxtorem": "^6.1.0",
"sass": "catalog:", "sass": "catalog:",
"typescript": "catalog:", "typescript": "catalog:",
"unplugin-auto-import": "catalog:", "unplugin-auto-import": "catalog:",
......
import tailwindcss from "tailwindcss";
import autoprefixer from "autoprefixer";
import pxtorem from "postcss-pxtorem";
export default {
plugins: [
tailwindcss,
autoprefixer,
pxtorem({
// 与 flexible 中的 BASE_FONT_SIZE 保持一致:
// 设计稿 375 宽时,html 字体为 14px,则 1rem = 14px
rootValue: 14,
propList: ["*"],
unitPrecision: 5,
minPixelValue: 1,
selectorBlackList: [".ignore", "html"],
}),
],
};
@tailwind base;
@tailwind components;
@tailwind utilities;
...@@ -13,7 +13,9 @@ declare module 'vue' { ...@@ -13,7 +13,9 @@ declare module 'vue' {
VanButton: typeof import('vant/es')['Button'] VanButton: typeof import('vant/es')['Button']
VanCell: typeof import('vant/es')['Cell'] VanCell: typeof import('vant/es')['Cell']
VanCellGroup: typeof import('vant/es')['CellGroup'] VanCellGroup: typeof import('vant/es')['CellGroup']
VanCheckbox: typeof import('vant/es')['Checkbox']
VanEmpty: typeof import('vant/es')['Empty'] VanEmpty: typeof import('vant/es')['Empty']
VanField: typeof import('vant/es')['Field']
VanGrid: typeof import('vant/es')['Grid'] VanGrid: typeof import('vant/es')['Grid']
VanGridItem: typeof import('vant/es')['GridItem'] VanGridItem: typeof import('vant/es')['GridItem']
VanIcon: typeof import('vant/es')['Icon'] VanIcon: typeof import('vant/es')['Icon']
......
import { onMounted, ref } from "vue";
const isPad = ref(false);
let inited = false;
const updateDevice = () => {
const width = window.innerWidth;
const height = window.innerHeight;
isPad.value = width >= 768 && width > height;
};
export function useDeviceLayout() {
if (typeof window !== "undefined" && !inited) {
updateDevice();
window.addEventListener("resize", updateDevice);
inited = true;
}
onMounted(() => {
if (typeof window !== "undefined" && !inited) {
updateDevice();
window.addEventListener("resize", updateDevice);
inited = true;
}
});
return {
isPad,
};
}
export const OSS_CONFIG = {
BUCKET_NAME: "glsk-oss",
OSS_DOMAIN: "https://glsk-oss.oss-cn-shenzhen.aliyuncs.com",
FOLDER: "usedCarH5/",
/**
* glsk-oss-jssdk 需要的 systemSource(会传给 STS 凭证接口)
* H5 默认用 h5,按你们接口约定调整
*/
SYSTEM_SOURCE: "h5",
} as const;
...@@ -8,20 +8,20 @@ const router = useRouter(); ...@@ -8,20 +8,20 @@ const router = useRouter();
const showTabBar = computed(() => route.meta.showTabBar !== false); const showTabBar = computed(() => route.meta.showTabBar !== false);
const tabList = [ const tabList = [
{ name: "home", title: "首页", icon: "home-o", activeIcon: "home" }, { routeName: "Home", title: "检测工单", icon: "todo-list-o", activeIcon: "todo-list" },
{ name: "car-list", title: "找车", icon: "search", activeIcon: "search" }, { routeName: "CarList", title: "检测报告", icon: "description", activeIcon: "description" },
{ name: "mine", title: "我的", icon: "contact-o", activeIcon: "contact" }, { routeName: "Mine", title: "我的", icon: "user-o", activeIcon: "user" },
]; ];
const activeTab = computed(() => { const activeTab = computed(() => {
const name = route.name as string; const name = route.name as string | undefined;
return tabList.findIndex((tab) => tab.name === name.toLowerCase()); return tabList.findIndex((tab) => tab.routeName === name);
}); });
function onTabChange(index: number) { function onTabChange(index: number) {
const tab = tabList[index]; const tab = tabList[index];
if (tab) { if (tab) {
router.push({ name: tab.name.charAt(0).toUpperCase() + tab.name.slice(1) }); router.push({ name: tab.routeName });
} }
} }
</script> </script>
...@@ -44,7 +44,7 @@ function onTabChange(index: number) { ...@@ -44,7 +44,7 @@ function onTabChange(index: number) {
</RouterView> </RouterView>
<van-tabbar v-if="showTabBar" <van-tabbar v-if="showTabBar"
active-color="#ee0a24" active-color="var(--color-primary)"
fixed fixed
inactive-color="#7d7e80" inactive-color="#7d7e80"
:model-value="activeTab" :model-value="activeTab"
...@@ -52,7 +52,7 @@ function onTabChange(index: number) { ...@@ -52,7 +52,7 @@ function onTabChange(index: number) {
safe-area-inset-bottom safe-area-inset-bottom
@change="onTabChange"> @change="onTabChange">
<van-tabbar-item v-for="tab in tabList" <van-tabbar-item v-for="tab in tabList"
:key="tab.name" :key="tab.routeName"
:icon="activeTab === tabList.indexOf(tab) ? tab.activeIcon : tab.icon"> :icon="activeTab === tabList.indexOf(tab) ? tab.activeIcon : tab.icon">
{{ tab.title }} {{ tab.title }}
</van-tabbar-item> </van-tabbar-item>
......
...@@ -6,17 +6,24 @@ import piniaPluginPersistedstate from "pinia-plugin-persistedstate"; ...@@ -6,17 +6,24 @@ import piniaPluginPersistedstate from "pinia-plugin-persistedstate";
import App from "./App.vue"; import App from "./App.vue";
import { fetchConfig } from "./config/center.ts"; import { fetchConfig } from "./config/center.ts";
import router from "./router"; import router from "./router";
import { initFlexible } from "./utils/flexible.ts";
import "@assets/styles/reset.scss"; import "@assets/styles/reset.scss";
import "@assets/styles/index.scss"; import "@assets/styles/index.scss";
import "@assets/tailwind.css";
import "vant/es/toast/style";
import { useUserStore } from "@/stores/modules/user";
async function bootstrap() { async function bootstrap() {
initFlexible();
await fetchConfig(); await fetchConfig();
const app = createApp(App); const app = createApp(App);
const pinia = createPinia(); const pinia = createPinia();
pinia.use(piniaPluginPersistedstate); pinia.use(piniaPluginPersistedstate);
app.use(pinia); app.use(pinia);
app.use(router); app.use(router);
const userStore = useUserStore();
userStore.setToken("mock-token-123");
app.mount("#app"); app.mount("#app");
} }
......
...@@ -3,6 +3,7 @@ import { createRouter, createWebHistory } from "vue-router"; ...@@ -3,6 +3,7 @@ import { createRouter, createWebHistory } from "vue-router";
import { closeToast, showLoadingToast } from "vant"; import { closeToast, showLoadingToast } from "vant";
import routes from "./routes.ts"; import routes from "./routes.ts";
import { useUserStore } from "@stores/modules/user.ts";
const router = createRouter({ const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL), history: createWebHistory(import.meta.env.BASE_URL),
...@@ -15,7 +16,12 @@ const router = createRouter({ ...@@ -15,7 +16,12 @@ const router = createRouter({
}, },
}); });
router.beforeEach((to, _from, next) => { // 不需要登录的白名单路由
const WHITE_LIST: string[] = ["/login"];
router.beforeEach((to, from, next) => {
const userStore = useUserStore();
showLoadingToast({ showLoadingToast({
message: "加载中...", message: "加载中...",
forbidClick: true, forbidClick: true,
...@@ -27,7 +33,33 @@ router.beforeEach((to, _from, next) => { ...@@ -27,7 +33,33 @@ router.beforeEach((to, _from, next) => {
document.title = `${to.meta.title} - ${import.meta.env.VITE_APP_TITLE}`; document.title = `${to.meta.title} - ${import.meta.env.VITE_APP_TITLE}`;
} }
const hasToken = !!userStore.token;
// 1. 有 token 的情况
if (hasToken) {
// 已经登录还去登录页,直接跳到首页或来源页
if (to.path === "/login") {
next(from.path && from.path !== "/login" ? from.fullPath : "/home");
return;
}
next();
return;
}
// 2. 没有 token 的情况
if (WHITE_LIST.includes(to.path)) {
next(); next();
return;
}
// 记录想去的地址,占个位:登录后再跳回来
next({
path: "/login",
query: {
redirect: to.fullPath,
},
});
}); });
router.afterEach(() => { router.afterEach(() => {
......
...@@ -2,6 +2,15 @@ import type { RouteRecordRaw } from "vue-router"; ...@@ -2,6 +2,15 @@ import type { RouteRecordRaw } from "vue-router";
const routes: RouteRecordRaw[] = [ const routes: RouteRecordRaw[] = [
{ {
path: "/login",
name: "Login",
component: () => import("@views/login/index.vue"),
meta: {
title: "登录",
showTabBar: false,
},
},
{
path: "/", path: "/",
component: () => import("@/layouts/index.vue"), component: () => import("@/layouts/index.vue"),
children: [ children: [
...@@ -14,7 +23,7 @@ const routes: RouteRecordRaw[] = [ ...@@ -14,7 +23,7 @@ const routes: RouteRecordRaw[] = [
name: "Home", name: "Home",
component: () => import("@views/home/index.vue"), component: () => import("@views/home/index.vue"),
meta: { meta: {
title: "首页", title: "检测工单",
keepAlive: true, keepAlive: true,
showTabBar: true, showTabBar: true,
}, },
...@@ -24,7 +33,7 @@ const routes: RouteRecordRaw[] = [ ...@@ -24,7 +33,7 @@ const routes: RouteRecordRaw[] = [
name: "CarList", name: "CarList",
component: () => import("@views/car-list/index.vue"), component: () => import("@views/car-list/index.vue"),
meta: { meta: {
title: "找车", title: "检测报告",
keepAlive: true, keepAlive: true,
showTabBar: true, showTabBar: true,
}, },
......
/**
* glsk-oss-jssdk 类型声明
*/
declare module "glsk-oss-jssdk" {
export interface MultipartUploadResult {
aliyunAddress: string;
attachment: string;
size?: string;
[key: string]: any;
}
class GlOssApi {
multipartUpload(
file: File,
successCallback: (result: MultipartUploadResult) => void,
errCallBack: (error: Error) => void,
bucketName?: string,
dir?: string,
custAttrObj?: Record<string, any>,
compressObj?: Record<string, any>,
partSize?: number,
maxRetries?: number
): Promise<void> | void;
}
export default GlOssApi;
}
// 简易版 rem 适配:
// 以设计稿 375 宽为基准,希望设计稿下 html 字体为 14px。
// 不同屏幕下:html.fontSize = (当前宽度 / 375) * 14px。
const DESIGN_WIDTH = 375;
const BASE_FONT_SIZE = 14; // 设计稿宽度下的根字体大小
function setRootFontSize() {
const docEl = document.documentElement;
const width = docEl.clientWidth || window.innerWidth;
// 限制最大/最小宽度,防止在大屏或非常小的屏幕上过大/过小
const minWidth = 320;
const maxWidth = 540;
const clampedWidth = Math.min(Math.max(width, minWidth), maxWidth);
const fontSize = (clampedWidth / DESIGN_WIDTH) * BASE_FONT_SIZE;
docEl.style.fontSize = `${fontSize}px`;
}
export function initFlexible() {
if (typeof window === "undefined") return;
setRootFontSize();
window.addEventListener("resize", () => {
setRootFontSize();
});
window.addEventListener("pageshow", (event) => {
if (event.persisted) {
setRootFontSize();
}
});
}
import { getRequestApi } from "@/config/center.ts"; import axios, { AxiosInstance, AxiosResponse } from "axios";
/**
* 请求封装 - 基于 glsk-toolkit Request
* 参考 gscrequest.ts 模式,Authorization 通过 center 拦截器统一处理
*/
import { showToast } from "vant"; import { showToast } from "vant";
import { getConfig } from "@/config/center.ts";
export interface ApiResponse<T = unknown> { export interface ApiResponse<T = unknown> {
code: number; code: number;
message: string; message: string;
...@@ -25,28 +23,113 @@ export interface RequestConfig { ...@@ -25,28 +23,113 @@ export interface RequestConfig {
[key: string]: unknown; [key: string]: unknown;
} }
function getInstance() { const TOKEN_KEY = "venus_usedcar_token";
const api = getRequestApi(); const defaultBaseURL = import.meta.env.VITE_API_BASE_URL ?? "";
if (!api) {
throw new Error( let axiosInstance: AxiosInstance | null = null;
"[Request] API 实例未初始化,请确保 fetchConfig 已在 main.ts 中执行"
function getToken(): string {
const token = localStorage.getItem(TOKEN_KEY);
return token ? `Bearer ${token}` : "";
}
function resolveBaseURL(): string {
const cfg = getConfig() as Record<string, unknown>;
const apiBaseUrl = (cfg.apiBaseUrl ??
(cfg.gsc as { baseUrl?: string; baseURL?: string })?.baseUrl ??
(cfg.gsc as { baseUrl?: string; baseURL?: string })?.baseURL) as
| string
| undefined;
return apiBaseUrl || defaultBaseURL || "/";
}
function getInstance(): AxiosInstance {
if (axiosInstance) return axiosInstance;
const baseURL = resolveBaseURL();
const instance = axios.create({
baseURL,
timeout: 15_000,
headers: {
"Content-Type": "application/json",
},
});
// 请求拦截:自动附带 Token
instance.interceptors.request.use(
(config) => {
const token = getToken();
if (token) {
config.headers = {
...(config.headers || {}),
Authorization: token,
} as typeof config.headers;
}
return config;
},
(error) => Promise.reject(error)
); );
// 响应拦截:统一处理 HTTP 状态码
instance.interceptors.response.use(
(response) => response,
(error) => {
const status = error?.response?.status as number | undefined;
const msg =
error?.response?.data?.message ||
error?.message ||
"网络错误,请检查网络连接";
switch (status) {
case 401: {
showToast("登录已过期,请重新登录");
localStorage.removeItem(TOKEN_KEY);
window.location.href = "/login";
break;
}
case 403: {
showToast("暂无权限");
break;
}
case 500: {
showToast("服务器异常,请稍后重试");
break;
}
default: {
showToast(msg);
}
}
return Promise.reject(error);
} }
return api; );
axiosInstance = instance;
return instance;
} }
/** 统一处理响应,提取 data 或按业务码处理 */ /** 统一处理响应,提取 data 或按业务码处理 */
async function handleResponse<T>(promise: Promise<unknown>): Promise<T> { async function handleResponse<T>(
promise: Promise<AxiosResponse<ApiResponse<T> | T>>
): Promise<T> {
const res = await promise; const res = await promise;
const data = res as ApiResponse<T>; const data = res.data as ApiResponse<T> | T;
if (data?.code === 200 || data?.code === 0) {
return (data.data ?? res) as T; // 兼容有业务 code 的返回
if (typeof data === "object" && data && "code" in data) {
const biz = data as ApiResponse<T>;
if (biz.code === 200 || biz.code === 0) {
return (biz.data ?? (data as unknown)) as T;
} }
if (data?.code === undefined) {
return res as T; showToast(biz.message || "请求失败");
throw new Error(biz.message || "请求失败");
} }
showToast(data?.message || "请求失败");
throw new Error(data?.message || "请求失败"); // 非标准结构,直接返回 data
return data as T;
} }
function get<T = unknown>( function get<T = unknown>(
......
import GlOssApi from "glsk-oss-jssdk";
import { OSS_CONFIG } from "@/config/oss.ts";
let ossApi = null;
function getOssApi() {
if (!ossApi) ossApi = new GlOssApi();
return ossApi;
}
/**
* 使用 glsk-oss-jssdk 分片上传到 OSS。
*
* @param {File} file
* @param {{
* bucketName?: string,
* dir?: string,
* custAttrObj?: Record<string, any>,
* partSizeKB?: number,
* maxRetries?: number
* }} [options]
* @returns {Promise<any>} SDK 返回结果(含 aliyunAddress/attachment 等字段)
*/
export function uploadFile(file, options = {}) {
if (!file) return Promise.reject(new Error("file 不能为空"));
const api = getOssApi();
const bucketName = options.bucketName ?? OSS_CONFIG.BUCKET_NAME;
const dir = options.dir ?? OSS_CONFIG.FOLDER;
const custAttrObj =
options.custAttrObj ?? { systemSource: OSS_CONFIG.SYSTEM_SOURCE };
const partSizeKB = options.partSizeKB ?? 500;
const maxRetries = options.maxRetries ?? 3;
return new Promise((resolve, reject) => {
api.multipartUpload(
file,
(res) => resolve(res),
(err) => reject(err),
bucketName,
dir,
custAttrObj,
{},
partSizeKB,
maxRetries
);
});
}
/**
* 批量上传
* @param {File[]} files
* @param {Parameters<typeof uploadFile>[1]} [options]
*/
export function uploadFiles(files, options = {}) {
if (!Array.isArray(files) || files.length === 0) {
return Promise.reject(new Error("files 不能为空"));
}
return Promise.all(files.map((f) => uploadFile(f, options)));
}
<script setup lang="ts">
import { useLogin } from "./useLogin.ts";
const {
phone,
code,
agreed,
sending,
countdown,
hasSent,
handleSendCode,
handleLogin,
} = useLogin();
</script>
<template>
<div class="relative flex min-h-screen flex-col box-border bg-gradient-to-b from-[#f4f7ff] via-[#f7f9ff] to-white px-[32px] pb-6">
<div class="pointer-events-none absolute inset-0 bg-[radial-gradient(circle_at_0_0,#e4f0ff_0,transparent_50%),radial-gradient(circle_at_100%_0,#e1e8ff_0,transparent_50%)]" />
<div class="relative flex flex-1 flex-col mt-[160px]">
<div class="text-center text-[24px] font-semibold text-[#111]">
检测端登录
</div>
<div class="mt-[6px] text-center text-[12px] text-[#999]">
专业的车辆检测工具
</div>
<div class="mt-8 space-y-4">
<van-field v-model="phone"
class="rounded-full login-input"
clearable
label="手机号"
maxlength="11"
placeholder="请输入手机号"
type="tel" />
<van-field v-model="code"
class="rounded-full login-input"
clearable
label="验证码"
maxlength="6"
placeholder="请输入验证码"
type="tel">
<template #button>
<van-button class="p-0 text-[13px]"
:class="countdown > 0 ? '!text-[#CCCCCC]' : '!text-[#185EFE]'"
:disabled="sending || countdown > 0"
:loading="sending"
size="small"
@click="handleSendCode">
<span v-if="!hasSent">获取验证码</span>
<span v-else-if="countdown > 0">重新发送({{ countdown }}s)</span>
<span v-else>重新发送</span>
</van-button>
</template>
</van-field>
<van-button block
class="mt-6 !h-[52px] border-0 bg-gradient-to-r from-[#84a9ff] to-[#90b5ff] text-[16px] font-medium"
round
type="primary"
@click="handleLogin">
登录
</van-button>
<div class="absolute bottom-[70px] left-1/2 flex -translate-x-1/2 items-center justify-center text-[12px] text-[#999]">
<van-checkbox v-model="agreed"
checked-color="#4f8cff"
icon-size="14px">
<span class="whitespace-nowrap">
我已阅读并同意
<a class="mx-0.5 text-[#4f8cff] no-underline" href="javascript:;">《用户协议》</a>
<a class="mx-0.5 text-[#4f8cff] no-underline" href="javascript:;">《隐私协议》</a>
</span>
</van-checkbox>
</div>
</div>
</div>
</div>
</template>
<style scoped lang="scss">
.login-input {
padding: 16px !important;
background: #f2f4f7;
&:deep(.van-field__label) {
font-size: 14px;
font-weight: 500;
color: #333;
}
&:deep(.van-button--default) {
padding: 0;
font-size: 13px;
color: transparent;
background: transparent;
border: none;
}
}
</style>
<script setup lang="ts">
import { useLogin } from "./useLogin.ts";
const {
phone,
code,
agreed,
sending,
countdown,
hasSent,
handleSendCode,
handleLogin,
} = useLogin();
</script>
<template>
<div class="flex min-h-screen items-center justify-center pad">
<div class="relative flex ">
<div class="flex-1">
<div class="text-center text-[40px] font-semibold text-[#111]">
检测端登录
</div>
<div class="mt-2 text-center text-[16px] text-[#999]">
专业的车辆检测工具
</div>
<div class="mt-8 space-y-4">
<van-field v-model="phone"
class="rounded-full login-input"
clearable
label="手机号"
maxlength="11"
placeholder="请输入手机号"
type="tel" />
<van-field v-model="code"
class="rounded-full login-input"
clearable
label="验证码"
maxlength="6"
placeholder="请输入验证码"
type="tel">
<template #button>
<van-button class="p-0 text-[13px]"
:class="countdown > 0 ? '!text-[#CCCCCC]' : '!text-[#185EFE]'"
:disabled="sending || countdown > 0"
:loading="sending"
size="small"
@click="handleSendCode">
<span v-if="!hasSent">获取验证码</span>
<span v-else-if="countdown > 0">重新发送({{ countdown }}s)</span>
<span v-else>重新发送</span>
</van-button>
</template>
</van-field>
<van-button block
class="mt-6 !h-[52px] w-[83%] border-0 bg-gradient-to-r from-[#84a9ff] to-[#90b5ff] text-[16px] font-medium"
round
type="primary"
@click="handleLogin">
登录
</van-button>
<div class="mt-4 flex items-center justify-center text-[12px] text-[#999]">
<van-checkbox v-model="agreed"
checked-color="#4f8cff"
icon-size="14px">
<span class="whitespace-nowrap">
我已阅读并同意
<a class="mx-0.5 text-[#4f8cff] no-underline" href="javascript:;">《用户协议》</a>
<a class="mx-0.5 text-[#4f8cff] no-underline" href="javascript:;">《隐私协议》</a>
</span>
</van-checkbox>
</div>
</div>
</div>
</div>
</div>
</template>
<style scoped lang="scss">
.pad {
background: url('@assets/image/login_pad.png') no-repeat center center;
background-size: 100% 100%;
}
.login-input {
padding: 16px !important;
background: #f2f4f7;
&:deep(.van-field__label) {
font-size: 14px;
font-weight: 500;
color: #333;
}
&:deep(.van-button--default) {
height: auto !important;
padding: 0;
font-size: 13px;
color: transparent;
background: transparent;
border: none;
}
}
</style>
<script setup lang="ts">
import { useDeviceLayout } from "@/composables/useDeviceLayout";
import LoginMobile from "./LoginMobile.vue";
import LoginPad from "./LoginPad.vue";
const { isPad } = useDeviceLayout();
</script>
<template>
<LoginPad v-if="isPad" />
<LoginMobile v-else />
</template>
import { ref } from "vue";
import { useRoute, useRouter } from "vue-router";
import { showFailToast, showSuccessToast } from "vant";
import { login, sendSmsCode } from "@/api/modules/user.ts";
import { useUserStore } from "@/stores/modules/user.ts";
export function useLogin() {
const router = useRouter();
const route = useRoute();
const userStore = useUserStore();
const phone = ref("");
const code = ref("");
const agreed = ref(false);
const sending = ref(false);
const countdown = ref(0);
const hasSent = ref(false);
let timer: number | null = null;
const validPhone = (value: string) => /^1\d{10}$/.test(value);
const handleSendCode = async () => {
if (sending.value || countdown.value > 0) return;
if (!validPhone(phone.value)) {
showFailToast("请输入正确的手机号");
return;
}
try {
sending.value = true;
await sendSmsCode(phone.value);
showSuccessToast("验证码已发送");
hasSent.value = true;
countdown.value = 60;
timer && window.clearInterval(timer);
timer = window.setInterval(() => {
if (countdown.value <= 1) {
window.clearInterval(timer!);
timer = null;
countdown.value = 0;
sending.value = false;
} else {
countdown.value -= 1;
}
}, 1000);
} catch (error) {
console.error("sendSmsCode error", error);
sending.value = false;
showFailToast("验证码发送失败,请稍后重试");
}
};
const handleLogin = async () => {
if (!validPhone(phone.value)) {
showFailToast("请输入正确的手机号");
return;
}
if (!code.value) {
showFailToast("请输入验证码");
return;
}
if (!agreed.value) {
showFailToast("请先阅读并同意相关协议");
return;
}
try {
const res = await login({
phone: phone.value,
code: code.value,
});
userStore.setToken(res.token);
userStore.setUserInfo(res.userInfo);
showSuccessToast("登录成功");
const redirect = (route.query.redirect as string) || "/home";
router.replace(redirect);
} catch (error) {
console.error("login error", error);
showFailToast("登录失败,请稍后重试");
}
};
return {
phone,
code,
agreed,
sending,
countdown,
hasSent,
handleSendCode,
handleLogin,
};
}
...@@ -4,51 +4,6 @@ import { showToast } from "vant"; ...@@ -4,51 +4,6 @@ import { showToast } from "vant";
const userStore = useUserStore(); const userStore = useUserStore();
const menuList = [
{
title: "我的收藏",
icon: "star-o",
iconColor: "#ee0a24",
action: () => showToast("功能开发中"),
},
{
title: "浏览历史",
icon: "clock-o",
iconColor: "#1989fa",
action: () => showToast("功能开发中"),
},
{
title: "我的订单",
icon: "orders-o",
iconColor: "#07c160",
action: () => showToast("功能开发中"),
},
{
title: "消息通知",
icon: "bell",
iconColor: "#ff976a",
action: () => showToast("功能开发中"),
},
];
const settingList = [
{
title: "关于我们",
icon: "info-o",
action: () => showToast("功能开发中"),
},
{
title: "意见反馈",
icon: "comment-o",
action: () => showToast("功能开发中"),
},
{
title: "隐私政策",
icon: "shield-o",
action: () => showToast("功能开发中"),
},
];
function onLogin() { function onLogin() {
showToast("登录功能开发中"); showToast("登录功能开发中");
} }
...@@ -61,113 +16,49 @@ async function onLogout() { ...@@ -61,113 +16,49 @@ async function onLogout() {
<template> <template>
<div class="mine-page safe-bottom"> <div class="mine-page safe-bottom">
<!-- 用户信息 -->
<div class="mine-header"> <div class="mine-header">
<div class="header-bg" /> <div class="header-bg" />
<div class="user-info"> <div class="user-row">
<van-image class="avatar" <van-image class="avatar"
fit="cover" fit="cover"
height="64" height="44"
round round
:src="userStore.userInfo?.avatar || ''" :src="userStore.userInfo?.avatar || ''"
width="64"> width="44"
@click="!userStore.isLoggedIn && onLogin()">
<template #error> <template #error>
<van-icon color="#fff" <van-icon color="#fff" name="contact" size="26" />
name="contact"
size="36" />
</template> </template>
</van-image> </van-image>
<div v-if="userStore.isLoggedIn" class="user-detail">
<p class="username"> <div class="user-text">
<div v-if="userStore.isLoggedIn" class="name">
{{ userStore.username }} {{ userStore.username }}
</p>
<p class="phone">
{{ userStore.userInfo?.phone }}
</p>
</div> </div>
<div v-else <div v-else class="name" @click="onLogin">
class="user-login"
@click="onLogin">
<p class="login-text">
点击登录 点击登录
</p>
<p class="login-tip">
登录后享受更多服务
</p>
</div>
</div>
</div>
<!-- 数据统计 -->
<div class="mine-stats card">
<div class="stat-item" @click="showToast('功能开发中')">
<div class="stat-value">
0
</div>
<div class="stat-label">
收藏
</div> </div>
<div class="phone">
{{ userStore.isLoggedIn ? userStore.userInfo?.phone : "" }}
</div> </div>
<div class="stat-divider" />
<div class="stat-item" @click="showToast('功能开发中')">
<div class="stat-value">
0
</div> </div>
<div class="stat-label">
浏览
</div> </div>
</div> </div>
<div class="stat-divider" />
<div class="stat-item" @click="showToast('功能开发中')"> <div class="avg-card card">
<div class="stat-value"> <div class="avg-label">
0 平均检测耗时
</div>
<div class="stat-label">
询价
</div> </div>
<div class="avg-value">
2小时35分钟
</div> </div>
</div> </div>
<!-- 功能菜单 -->
<van-cell-group class="mine-menu" inset>
<van-cell v-for="item in menuList"
:key="item.title"
center
is-link
:title="item.title"
@click="item.action">
<template #icon>
<van-icon class="menu-icon"
:color="item.iconColor"
:name="item.icon"
size="20" />
</template>
</van-cell>
</van-cell-group>
<!-- 设置项 -->
<van-cell-group class="mine-settings" inset>
<van-cell v-for="item in settingList"
:key="item.title"
center
is-link
:title="item.title"
@click="item.action">
<template #icon>
<van-icon class="menu-icon"
color="#969799"
:name="item.icon"
size="20" />
</template>
</van-cell>
</van-cell-group>
<!-- 退出登录 --> <!-- 退出登录 -->
<div v-if="userStore.isLoggedIn" class="logout-btn"> <div class="logout-wrap">
<van-button block <van-button block
color="#ee0a24"
plain
round round
class="logout-btn"
@click="onLogout"> @click="onLogout">
退出登录 退出登录
</van-button> </van-button>
...@@ -189,30 +80,31 @@ const __APP_VERSION__ = "1.0.0"; ...@@ -189,30 +80,31 @@ const __APP_VERSION__ = "1.0.0";
.mine-page { .mine-page {
min-height: 100vh; min-height: 100vh;
background-color: var(--color-bg-page); background: #f2f6fb;
} }
.mine-header { .mine-header {
position: relative; position: relative;
padding-bottom: 16px; padding-bottom: 14px;
.header-bg { .header-bg {
position: absolute; position: absolute;
top: 0; top: 0;
right: 0; right: 0;
left: 0; left: 0;
height: 120px; height: 220px;
background: linear-gradient(135deg, #ee0a24 0%, #ff5a5a 100%); background:
border-radius: 0 0 24px 24px; radial-gradient(circle at 40px 40px, rgb(25 137 250 / 20%), transparent 60%),
linear-gradient(180deg, #eaf3ff 0%, rgb(234 243 255 / 0%) 100%);
} }
.user-info { .user-row {
position: relative; position: relative;
z-index: 1; z-index: 1;
display: flex; display: flex;
gap: 14px; gap: 12px;
align-items: center; align-items: center;
padding: 40px 20px 20px; padding: 28px 18px 10px;
} }
.avatar { .avatar {
...@@ -220,86 +112,58 @@ const __APP_VERSION__ = "1.0.0"; ...@@ -220,86 +112,58 @@ const __APP_VERSION__ = "1.0.0";
flex-shrink: 0; flex-shrink: 0;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
background-color: rgb(255 255 255 / 20%); background-color: rgb(25 137 250 / 15%);
border: 3px solid rgb(255 255 255 / 60%); border: 2px solid rgb(25 137 250 / 25%);
border-radius: 50%; border-radius: 50%;
} }
.user-detail { .user-text {
.username { .name {
margin-bottom: 4px; margin-bottom: 4px;
font-size: $font-size-lg; font-size: 18px;
font-weight: 700; font-weight: 700;
color: #fff; line-height: 1.2;
color: $color-text-primary;
} }
.phone { .phone {
font-size: $font-size-sm; min-height: 16px;
color: rgb(255 255 255 / 80%); font-size: 13px;
} color: $color-text-secondary;
}
.user-login {
cursor: pointer;
.login-text {
margin-bottom: 4px;
font-size: $font-size-lg;
font-weight: 700;
color: #fff;
}
.login-tip {
font-size: $font-size-sm;
color: rgb(255 255 255 / 80%);
} }
} }
} }
.mine-stats { .avg-card {
display: flex; padding: 16px;
align-items: center; margin: 6px 12px 0;
padding: 16px 0; border-radius: 10px;
margin: 0 12px 12px;
border-radius: $radius-base;
.stat-item {
flex: 1;
text-align: center;
cursor: pointer;
.stat-value {
margin-bottom: 4px;
font-size: $font-size-xl;
font-weight: 700;
color: $color-text-primary;
}
.stat-label { .avg-label {
font-size: $font-size-xs; margin-bottom: 8px;
font-size: 13px;
color: $color-text-secondary; color: $color-text-secondary;
} }
}
.stat-divider { .avg-value {
width: 1px; font-size: 24px;
height: 32px; font-weight: 800;
background-color: $color-border; color: var(--color-primary);
letter-spacing: 0.5px;
} }
} }
.mine-menu, .logout-wrap {
.mine-settings { padding: 0 12px;
margin-bottom: 12px; margin-top: auto;
.menu-icon {
margin-right: 10px;
}
} }
.logout-btn { .logout-btn {
padding: 0 12px; height: 44px;
margin-bottom: 16px; color: $color-text-primary;
background: #fff;
border: 0;
box-shadow: 0 1px 0 rgb(0 0 0 / 4%);
} }
.app-version { .app-version {
......
// 避免通过 workspace 包的 stub(dist) 再次触发 jiti(会和 tailwindcss 内部的 jiti 叠加导致递归/栈溢出)。
// 这里直接引用源配置,让 tailwindcss 自己的 jiti 只处理一次 TS。
export { default } from "../../../internal/tailwind-config/src/index";
...@@ -7,7 +7,12 @@ ...@@ -7,7 +7,12 @@
"skipLibCheck": true, "skipLibCheck": true,
"strict": true "strict": true
}, },
"files": [
"vite.config.ts",
"src/utils/upload.ts"
],
"include": [ "include": [
"vite.config.ts" "src/**/*.ts",
"src/**/*.d.ts"
] ]
} }
...@@ -2,7 +2,6 @@ import { dirname, resolve } from "node:path"; ...@@ -2,7 +2,6 @@ import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url"; import { fileURLToPath } from "node:url";
import vue from "@vitejs/plugin-vue"; import vue from "@vitejs/plugin-vue";
import autoprefixer from "autoprefixer";
import AutoImport from "unplugin-auto-import/vite"; import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite"; import Components from "unplugin-vue-components/vite";
import { VantResolver } from "unplugin-vue-components/resolvers"; import { VantResolver } from "unplugin-vue-components/resolvers";
...@@ -53,22 +52,6 @@ export default defineConfig(({ mode }) => { ...@@ -53,22 +52,6 @@ export default defineConfig(({ mode }) => {
api: "modern-compiler", api: "modern-compiler",
}, },
}, },
postcss: {
plugins: [
autoprefixer({
overrideBrowserslist: ["Android >= 4", "iOS >= 7", "Chrome >= 31"],
}),
pxToViewport({
viewportWidth: 375,
unitPrecision: 5,
viewportUnit: "vw",
fontViewportUnit: "vw",
selectorBlackList: [".ignore", ".hairlines", "html"],
minPixelValue: 1,
mediaQuery: false,
}),
],
},
}, },
server: { server: {
......
...@@ -12,7 +12,6 @@ packages: ...@@ -12,7 +12,6 @@ packages:
- packages/utils/* - packages/utils/*
- packages/common-ui/* - packages/common-ui/*
- packages/common-ui/vue-ui - packages/common-ui/vue-ui
- apps/* - apps/*
- apps/miniprogram/**/* - apps/miniprogram/**/*
- apps/web/**/* - apps/web/**/*
...@@ -23,44 +22,56 @@ packages: ...@@ -23,44 +22,56 @@ packages:
- example - example
catalog: catalog:
"eslint-plugin-wxml": ^0.8.0 '@ast-grep/napi': ^0.37.0
"jsencrypt": ^3.3.1 '@changesets/changelog-github': ^0.5.1
"@ast-grep/napi": ^0.37.0 '@changesets/cli': ^2.29.5
"@changesets/changelog-github": ^0.5.1 '@changesets/git': ^3.0.4
"@changesets/cli": ^2.29.5 '@clack/prompts': ^0.10.1
"@changesets/git": ^3.0.4 '@commitlint/cli': ^19.8.1
"@clack/prompts": ^0.10.1 '@commitlint/config-conventional': ^19.8.1
"@commitlint/cli": ^19.8.1 '@ctrl/tinycolor': ^4.1.0
"@commitlint/config-conventional": ^19.8.1 '@element-plus/icons-vue': ^2.3.2
"@ctrl/tinycolor": ^4.1.0 '@eslint/js': ^9.30.1
"@eslint/js": ^9.30.1 '@iconify/json': ^2.2.354
"@iconify/json": ^2.2.354 '@iconify/tailwind': ^1.2.0
"@iconify/tailwind": ^1.2.0 '@intlify/unplugin-vue-i18n': ^6.0.8
"@manypkg/get-packages": ^3.0.0 '@js-preview/docx': ^1.6.4
"@playwright/test": ^1.53.2 '@js-preview/excel': ^1.7.14
"@stylistic/stylelint-plugin": ^3.1.3 '@js-preview/pdf': ^2.0.10
"@tailwindcss/nesting": 0.0.0-insiders.565cd3e '@jspm/generator': ^2.6.2
"@tailwindcss/typography": ^0.5.16 '@manypkg/get-packages': ^3.0.0
"@types/eslint": ^9.6.1 '@playwright/test': ^1.53.2
"@types/node": ^24.9.2 '@pnpm/workspace.read-manifest': ^1000.2.6
"@types/postcss-import": ^14.0.3 '@rollup/plugin-commonjs': ^28.0.1
"@types/sortablejs": ^1.15.8 '@rollup/plugin-node-resolve': ^15.3.0
"@typescript-eslint/eslint-plugin": ^8.35.1 '@rollup/plugin-terser': ^0.4.4
"@typescript-eslint/parser": ^8.35.1 '@stylistic/stylelint-plugin': ^3.1.3
"@vitejs/plugin-vue": ^6.0.1 '@tailwindcss/nesting': 0.0.0-insiders.565cd3e
"@vitejs/plugin-vue-jsx": ^5.0.1 '@tailwindcss/typography': ^0.5.16
"@vue/test-utils": ^2.4.6 '@types/archiver': ^6.0.3
"@types/archiver": ^6.0.3 '@types/eslint': ^9.6.1
"@vueuse/core": ^13.4.0 '@types/html-minifier-terser': ^7.0.2
glsk-oss-jssdk: ^1.0.6 '@types/node': ^24.9.2
react: ^18.2.0 '@types/postcss-import': ^14.0.3
react-dom: ^18.2.0 '@types/sortablejs': ^1.15.8
'@typescript-eslint/eslint-plugin': ^8.35.1
'@typescript-eslint/parser': ^8.35.1
'@vitejs/plugin-vue': ^6.0.1
'@vitejs/plugin-vue-jsx': ^5.0.1
'@vue-office/docx': ^1.6.3
'@vue-office/excel': ^1.7.14
'@vue-office/pdf': ^2.0.10
'@vue-office/pptx': ^1.0.1
'@vue/test-utils': ^2.4.6
'@vueuse/core': ^13.4.0
'@wxml/parser': ^0.4.0
ant-design-vue: ^4.2.6 ant-design-vue: ^4.2.6
archiver: ^7.0.1 archiver: ^7.0.1
autoprefixer: ^10.4.21 autoprefixer: ^10.4.21
axios: ^1.7.9 axios: ^1.7.9
cac: ^6.7.14 cac: ^6.7.14
chalk: ^5.4.1 chalk: ^5.4.1
cheerio: ^1.1.0
circular-dependency-scanner: ^2.3.0 circular-dependency-scanner: ^2.3.0
clsx: ^2.1.1 clsx: ^2.1.1
commitlint-plugin-function-rules: ^4.0.2 commitlint-plugin-function-rules: ^4.0.2
...@@ -74,7 +85,6 @@ catalog: ...@@ -74,7 +85,6 @@ catalog:
defu: ^6.1.4 defu: ^6.1.4
depcheck: ^1.4.7 depcheck: ^1.4.7
dotenv: ^16.6.1 dotenv: ^16.6.1
"@element-plus/icons-vue": ^2.3.2
element-plus: ^2.11.9 element-plus: ^2.11.9
eslint: ^9.30.1 eslint: ^9.30.1
eslint-config-turbo: ^2.5.4 eslint-config-turbo: ^2.5.4
...@@ -90,17 +100,23 @@ catalog: ...@@ -90,17 +100,23 @@ catalog:
eslint-plugin-regexp: ^2.9.0 eslint-plugin-regexp: ^2.9.0
eslint-plugin-unicorn: ^59.0.1 eslint-plugin-unicorn: ^59.0.1
eslint-plugin-unused-imports: ^4.1.4 eslint-plugin-unused-imports: ^4.1.4
"@wxml/parser": ^0.4.0
eslint-plugin-vitest: ^0.5.4 eslint-plugin-vitest: ^0.5.4
eslint-plugin-vue: ^10.2.0 eslint-plugin-vue: ^10.2.0
eslint-plugin-wxml: ^0.8.0
execa: ^9.6.0 execa: ^9.6.0
find-up: ^7.0.0 find-up: ^7.0.0
get-port: ^7.1.0
globals: ^16.3.0 globals: ^16.3.0
glsk-oss-jssdk: 1.0.6
glsk-toolkit: ^1.0.5 glsk-toolkit: ^1.0.5
happy-dom: ^17.6.3 happy-dom: ^17.6.3
html-minifier-terser: ^7.2.0
jiti: ^1.21.6
jsencrypt: ^3.3.1
jsonc-eslint-parser: ^2.4.0 jsonc-eslint-parser: ^2.4.0
lefthook: ^1.11.14 lefthook: ^1.11.14
lucide-vue-next: ^0.507.0 lucide-vue-next: ^0.507.0
nitropack: ^2.11.13
nprogress: ^0.2.0 nprogress: ^0.2.0
ora: ^8.2.0 ora: ^8.2.0
pinia: ^3.0.3 pinia: ^3.0.3
...@@ -116,17 +132,18 @@ catalog: ...@@ -116,17 +132,18 @@ catalog:
prettier: ^3.6.2 prettier: ^3.6.2
prettier-plugin-tailwindcss: ^0.6.13 prettier-plugin-tailwindcss: ^0.6.13
publint: ^0.3.12 publint: ^0.3.12
qs: ^6.14.0
qiankun: ^2.10.16 qiankun: ^2.10.16
qs: ^6.14.0
radix-vue: ^1.9.17 radix-vue: ^1.9.17
react: ^18.2.0
react-dom: ^18.2.0
resolve.exports: ^2.0.3
rimraf: ^6.0.1 rimraf: ^6.0.1
rollup: ^4.44.1 rollup: ^4.44.1
"@rollup/plugin-node-resolve": ^15.3.0 rollup-plugin-postcss: ^4.0.2
"@rollup/plugin-commonjs": ^28.0.1
"@rollup/plugin-terser": ^0.4.4
rollup-plugin-typescript2: ^0.36.0 rollup-plugin-typescript2: ^0.36.0
rollup-plugin-visualizer: ^5.14.0
rollup-plugin-vue: ^6.0.0 rollup-plugin-vue: ^6.0.0
rollup-plugin-postcss: ^4.0.2
sass: ^1.89.2 sass: ^1.89.2
scss: ^0.2.4 scss: ^0.2.4
secure-ls: ^2.0.0 secure-ls: ^2.0.0
...@@ -153,31 +170,13 @@ catalog: ...@@ -153,31 +170,13 @@ catalog:
vite-plugin-dts: ^4.5.4 vite-plugin-dts: ^4.5.4
vite-plugin-html: ^3.2.2 vite-plugin-html: ^3.2.2
vite-plugin-lazy-import: ^1.0.7 vite-plugin-lazy-import: ^1.0.7
vite-plugin-pwa: ^1.0.1
vite-plugin-qiankun: ^1.0.15 vite-plugin-qiankun: ^1.0.15
vite-plugin-vue-devtools: ^8.0.3
vitepress: ^1.6.3 vitepress: ^1.6.3
vitest: ^3.2.4 vitest: ^3.2.4
vue: ^3.5.17 vue: ^3.5.17
vue-demi: ^0.14.6
vue-eslint-parser: ^10.2.0 vue-eslint-parser: ^10.2.0
vue-router: ^4.5.1 vue-router: ^4.5.1
vue-tsc: 2.2.10 vue-tsc: 2.2.10
vue-demi: ^0.14.6
"@vue-office/excel": ^1.7.14
"@vue-office/docx": ^1.6.3
"@vue-office/pdf": ^2.0.10
"@vue-office/pptx": ^1.0.1
"@js-preview/excel": ^1.7.14
"@js-preview/pdf": ^2.0.10
vite-plugin-pwa: ^1.0.1
vite-plugin-vue-devtools: ^8.0.3
"@pnpm/workspace.read-manifest": ^1000.2.6
"@jspm/generator": ^2.6.2
"@intlify/unplugin-vue-i18n": ^6.0.8
get-port: ^7.1.0
nitropack: ^2.11.13
resolve.exports: ^2.0.3
cheerio: ^1.1.0
html-minifier-terser: ^7.2.0
"@js-preview/docx": ^1.6.4
"jiti": ^1.21.6
rollup-plugin-visualizer: ^5.14.0
"@types/html-minifier-terser": ^7.0.2
File mode changed
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!