Commit 227ae6e5 by Lin

feat: 类型优化

1 parent 779fbfae
Pipeline #63 for 227ae6e5 failed in 0 seconds
<!-- 此文件为项目占位文件,项目入口为 index.html + src/main.ts -->
...@@ -7,21 +7,24 @@ export {} ...@@ -7,21 +7,24 @@ export {}
declare module 'vue' { declare module 'vue' {
export interface GlobalComponents { export interface GlobalComponents {
Layout: typeof import('./layouts/index.vue')['default']
Layouts: typeof import('./layouts/index.vue')['default'] Layouts: typeof import('./layouts/index.vue')['default']
RouterLink: typeof import('vue-router')['RouterLink'] RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView'] RouterView: typeof import('vue-router')['RouterView']
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']
VanEmpty: typeof import('vant/es')['Empty']
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']
VanImage: typeof import('vant/es')['Image'] VanImage: typeof import('vant/es')['Image']
VanImagePreview: typeof import('vant/es')['ImagePreview']
VanList: typeof import('vant/es')['List'] VanList: typeof import('vant/es')['List']
VanLoading: typeof import('vant/es')['Loading'] VanLoading: typeof import('vant/es')['Loading']
VanNavBar: typeof import('vant/es')['NavBar']
VanPullRefresh: typeof import('vant/es')['PullRefresh'] VanPullRefresh: typeof import('vant/es')['PullRefresh']
VanSearch: typeof import('vant/es')['Search'] VanSearch: typeof import('vant/es')['Search']
VanSkeleton: typeof import('vant/es')['Skeleton']
VanSticky: typeof import('vant/es')['Sticky'] VanSticky: typeof import('vant/es')['Sticky']
VanSwipe: typeof import('vant/es')['Swipe'] VanSwipe: typeof import('vant/es')['Swipe']
VanSwipeItem: typeof import('vant/es')['SwipeItem'] VanSwipeItem: typeof import('vant/es')['SwipeItem']
......
<script setup lang="ts"> <script setup lang="ts">
import { ref, onMounted } from "vue";
import { useRoute, useRouter } from "vue-router";
import { showToast, showConfirmDialog } from "vant";
import type { CarItem } from "@/api/modules/car"; import type { CarItem } from "@/api/modules/car";
import { getCarDetail, collectCar, uncollectCar } from "@/api/modules/car";
import { onMounted, ref } from "vue";
import { useRoute, useRouter } from "vue-router";
import { collectCar, getCarDetail, uncollectCar } from "@/api/modules/car";
import { formatDate, formatMileage } from "@/utils"; import { formatDate, formatMileage } from "@/utils";
import { showConfirmDialog, showToast } from "vant";
const route = useRoute(); const route = useRoute();
const router = useRouter(); const router = useRouter();
...@@ -33,8 +35,8 @@ async function loadDetail() { ...@@ -33,8 +35,8 @@ async function loadDetail() {
brand: "宝马", brand: "宝马",
model: "3系", model: "3系",
year: 2021, year: 2021,
mileage: 28000, mileage: 28_000,
price: 268000, price: 268_000,
city: "上海", city: "上海",
coverImage: "https://fastly.jsdelivr.net/npm/@vant/assets/apple-1.jpeg", coverImage: "https://fastly.jsdelivr.net/npm/@vant/assets/apple-1.jpeg",
images: [ images: [
...@@ -112,40 +114,46 @@ onMounted(() => { ...@@ -112,40 +114,46 @@ onMounted(() => {
<template> <template>
<div class="car-detail-page"> <div class="car-detail-page">
<!-- 导航栏 --> <!-- 导航栏 -->
<van-nav-bar <van-nav-bar fixed
:title="car?.brand ?? '车辆详情'"
left-arrow left-arrow
fixed
placeholder placeholder
safe-area-inset-top safe-area-inset-top
@click-left="onBack" :title="car?.brand ?? '车辆详情'"
> @click-left="onBack">
<template #right> <template #right>
<van-icon <van-icon :color="collected ? '#ee0a24' : '#323233'"
:name="collected ? 'star' : 'star-o'" :name="collected ? 'star' : 'star-o'"
:color="collected ? '#ee0a24' : '#323233'"
size="20" size="20"
@click="onToggleCollect" @click="onToggleCollect" />
/>
</template> </template>
</van-nav-bar> </van-nav-bar>
<van-skeleton :loading="loading" :row="8" animated> <van-skeleton animated
:loading="loading"
:row="8">
<template v-if="car"> <template v-if="car">
<!-- 图片轮播 --> <!-- 图片轮播 -->
<van-swipe class="detail-swipe" :autoplay="false" indicator-color="#ee0a24"> <van-swipe :autoplay="0"
<van-swipe-item class="detail-swipe"
v-for="(img, index) in car.images" indicator-color="#ee0a24">
<van-swipe-item v-for="(img, index) in car.images"
:key="index" :key="index"
@click="onImageClick(index)" @click="onImageClick(index)">
> <van-image fit="cover"
<van-image :src="img" width="100%" height="220" fit="cover" /> height="220"
:src="img"
width="100%" />
</van-swipe-item> </van-swipe-item>
<van-swipe-item v-if="!car.images.length" @click="onImageClick(0)"> <van-swipe-item v-if="car.images.length === 0" @click="onImageClick(0)">
<van-image :src="car.coverImage" width="100%" height="220" fit="cover" /> <van-image fit="cover"
height="220"
:src="car.coverImage"
width="100%" />
</van-swipe-item> </van-swipe-item>
<template #indicator="{ active, total }"> <template #indicator="{ active, total }">
<div class="swipe-indicator">{{ active + 1 }}/{{ total }}</div> <div class="swipe-indicator">
{{ active + 1 }}/{{ total }}
</div>
</template> </template>
</van-swipe> </van-swipe>
...@@ -158,17 +166,17 @@ onMounted(() => { ...@@ -158,17 +166,17 @@ onMounted(() => {
<span class="unit">万</span> <span class="unit">万</span>
</div> </div>
<div class="tags"> <div class="tags">
<van-tag <van-tag v-for="tag in car.tags"
v-for="tag in car.tags"
:key="tag" :key="tag"
type="primary"
plain plain
> type="primary">
{{ tag }} {{ tag }}
</van-tag> </van-tag>
</div> </div>
</div> </div>
<h2 class="car-title">{{ car.title }}</h2> <h2 class="car-title">
{{ car.title }}
</h2>
<p class="car-summary"> <p class="car-summary">
<van-icon name="location-o" size="13" /> <van-icon name="location-o" size="13" />
{{ car.city }} · {{ car.year }}年 · {{ formatMileage(car.mileage) }} {{ car.city }} · {{ car.year }}年 · {{ formatMileage(car.mileage) }}
...@@ -177,46 +185,40 @@ onMounted(() => { ...@@ -177,46 +185,40 @@ onMounted(() => {
<!-- 车辆配置 --> <!-- 车辆配置 -->
<div class="detail-section card"> <div class="detail-section card">
<div class="section-title">车辆信息</div> <div class="section-title">
车辆信息
</div>
<van-cell-group :border="false"> <van-cell-group :border="false">
<van-cell <van-cell v-for="spec in specs"
v-for="spec in specs"
:key="spec.label" :key="spec.label"
:title="spec.label" :title="spec.label"
:value="spec.value" :value="spec.value" />
/>
</van-cell-group> </van-cell-group>
</div> </div>
<!-- 图片预览 --> <!-- 图片预览 -->
<van-image-preview <van-image-preview v-model:show="showImagePreview"
v-model:show="showImagePreview" :images="car.images.length > 0 ? car.images : [car.coverImage]"
:images="car.images.length ? car.images : [car.coverImage]" :start-position="previewIndex" />
:start-position="previewIndex"
/>
</template> </template>
</van-skeleton> </van-skeleton>
<!-- 底部操作栏 --> <!-- 底部操作栏 -->
<div class="detail-footer"> <div class="detail-footer">
<van-button <van-button :color="collected ? '#ee0a24' : '#646566'"
plain
:icon="collected ? 'star' : 'star-o'" :icon="collected ? 'star' : 'star-o'"
:color="collected ? '#ee0a24' : '#646566'" plain
size="small" size="small"
@click="onToggleCollect" @click="onToggleCollect">
>
{{ collected ? "已收藏" : "收藏" }} {{ collected ? "已收藏" : "收藏" }}
</van-button> </van-button>
<van-button <van-button block
type="primary"
block
round
size="normal"
color="#ee0a24" color="#ee0a24"
icon="phone-o" icon="phone-o"
@click="onContact" round
> size="normal"
type="primary"
@click="onContact">
联系卖家 联系卖家
</van-button> </van-button>
</div> </div>
...@@ -227,9 +229,9 @@ onMounted(() => { ...@@ -227,9 +229,9 @@ onMounted(() => {
@use "@/assets/styles/variables" as *; @use "@/assets/styles/variables" as *;
.car-detail-page { .car-detail-page {
background-color: var(--color-bg-page);
min-height: 100vh; min-height: 100vh;
padding-bottom: calc(64px + env(safe-area-inset-bottom)); padding-bottom: calc(64px + env(safe-area-inset-bottom));
background-color: var(--color-bg-page);
} }
.detail-swipe { .detail-swipe {
...@@ -238,16 +240,16 @@ onMounted(() => { ...@@ -238,16 +240,16 @@ onMounted(() => {
right: 12px; right: 12px;
bottom: 8px; bottom: 8px;
padding: 2px 8px; padding: 2px 8px;
background-color: rgba(0, 0, 0, 0.5);
color: #fff;
font-size: $font-size-xs; font-size: $font-size-xs;
color: #fff;
background-color: rgb(0 0 0 / 50%);
border-radius: $radius-full; border-radius: $radius-full;
} }
} }
.detail-header { .detail-header {
margin: 10px 12px;
padding: 14px; padding: 14px;
margin: 10px 12px;
border-radius: $radius-base; border-radius: $radius-base;
.price-section { .price-section {
...@@ -258,8 +260,8 @@ onMounted(() => { ...@@ -258,8 +260,8 @@ onMounted(() => {
} }
.price-tag { .price-tag {
color: $color-primary;
font-weight: 700; font-weight: 700;
color: $color-primary;
.unit { .unit {
font-size: $font-size-sm; font-size: $font-size-sm;
...@@ -272,51 +274,51 @@ onMounted(() => { ...@@ -272,51 +274,51 @@ onMounted(() => {
.tags { .tags {
display: flex; display: flex;
gap: 4px;
flex-wrap: wrap; flex-wrap: wrap;
gap: 4px;
} }
.car-title { .car-title {
margin-bottom: 6px;
font-size: $font-size-md; font-size: $font-size-md;
font-weight: 700; font-weight: 700;
color: $color-text-primary;
margin-bottom: 6px;
line-height: 1.4; line-height: 1.4;
color: $color-text-primary;
} }
.car-summary { .car-summary {
font-size: $font-size-sm;
color: $color-text-secondary;
display: flex; display: flex;
align-items: center;
gap: 3px; gap: 3px;
align-items: center;
font-size: $font-size-sm;
color: $color-text-secondary;
} }
} }
.detail-section { .detail-section {
margin: 0 12px 10px; margin: 0 12px 10px;
border-radius: $radius-base;
overflow: hidden; overflow: hidden;
border-radius: $radius-base;
.section-title { .section-title {
padding: 12px 16px 6px;
font-size: $font-size-base; font-size: $font-size-base;
font-weight: 700; font-weight: 700;
color: $color-text-primary; color: $color-text-primary;
padding: 12px 16px 6px;
} }
} }
.detail-footer { .detail-footer {
position: fixed; position: fixed;
right: 0;
bottom: 0; bottom: 0;
left: 0; left: 0;
right: 0;
display: flex; display: flex;
align-items: center;
gap: 12px; gap: 12px;
align-items: center;
padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
background-color: $color-bg-card; background-color: $color-bg-card;
box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.08); box-shadow: 0 -2px 10px rgb(0 0 0 / 8%);
.van-button:first-child { .van-button:first-child {
flex-shrink: 0; flex-shrink: 0;
......
...@@ -164,7 +164,7 @@ onMounted(() => { ...@@ -164,7 +164,7 @@ onMounted(() => {
:key="tag" :key="tag"
type="primary" type="primary"
plain plain
size="small" size="medium"
> >
{{ tag }} {{ tag }}
</van-tag> </van-tag>
......
<script setup lang="ts"> <script setup lang="ts">
import { ref, onMounted } from "vue"; import { ref, onMounted } from "vue";
import { useRouter } from "vue-router"; import { useRouter } from "vue-router";
import { showToast } from "vant";
import type { CarItem } from "@/api/modules/car"; import type { CarItem } from "@/api/modules/car";
import { getRecommendedCars } from "@/api/modules/car"; import { getRecommendedCars } from "@/api/modules/car";
...@@ -139,7 +138,7 @@ onMounted(() => { ...@@ -139,7 +138,7 @@ onMounted(() => {
:key="tag" :key="tag"
type="primary" type="primary"
plain plain
size="small" size="medium"
> >
{{ tag }} {{ tag }}
</van-tag> </van-tag>
......
<script setup lang="ts"> <script setup lang="ts">
import { ref } from "vue";
import { useRouter } from "vue-router";
import { showToast } from "vant"; import { showToast } from "vant";
import { useUserStore } from "@/stores"; import { useUserStore } from "@/stores";
const router = useRouter();
const userStore = useUserStore(); const userStore = useUserStore();
const menuList = [ const menuList = [
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!