v0.3
This commit is contained in:
1 parent
d1ee8edbbd
commit
7733a44362
429 files changed
+75840
-94
No files matched your search
@@ -0,0 +1,479 @@
|
||||
<template>
|
||||
<main class="add-user-page">
|
||||
<section class="add-user-card" aria-labelledby="add-user-title">
|
||||
<header class="page-header">
|
||||
<div class="header-icon" aria-hidden="true">
|
||||
<svg viewBox="0 0 24 24">
|
||||
<path d="M4 17h16M6 17V8l3-3h6l3 3v9M9 17v2m6-2v2M8 11h8" />
|
||||
</svg>
|
||||
</div>
|
||||
<div>
|
||||
<h1 id="add-user-title">添加用户</h1>
|
||||
<p>为客户创建天泽汽修服务账号</p>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<form class="user-form" @submit.prevent="handleSubmit">
|
||||
<div class="form-item">
|
||||
<label for="license-plate">用户名</label>
|
||||
<p class="field-tip">使用客户的车牌号作为登录用户名</p>
|
||||
<div class="input-wrap">
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||||
<path d="M4 16h16M6 16V9l2-3h8l2 3v7M8 16v2m8-2v2M8 11h8" />
|
||||
</svg>
|
||||
<input
|
||||
id="license-plate"
|
||||
v-model.trim="plateNumber"
|
||||
type="text"
|
||||
placeholder="请输入车牌号,如:粤B12345"
|
||||
maxlength="8"
|
||||
autocomplete="off"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-item">
|
||||
<label for="status">车辆状态</label>
|
||||
<p class="field-tip">设置车辆当前服务状态</p>
|
||||
<div class="input-wrap">
|
||||
<select id="status" v-model="status">
|
||||
<option value="正常">正常</option>
|
||||
<option value="维修中">维修中</option>
|
||||
<option value="停用">停用</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-item">
|
||||
<label for="car-model">车型</label>
|
||||
<p class="field-tip">填写车辆品牌和具体车型</p>
|
||||
<div class="input-wrap">
|
||||
<input
|
||||
id="car-model"
|
||||
v-model.trim="carModel"
|
||||
type="text"
|
||||
placeholder="如:宝马 3系 2022款 325Li"
|
||||
maxlength="50"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-item">
|
||||
<label for="car-color">车辆颜色</label>
|
||||
<p class="field-tip">填写车辆外观颜色</p>
|
||||
<div class="input-wrap">
|
||||
<input
|
||||
id="car-color"
|
||||
v-model.trim="carColor"
|
||||
type="text"
|
||||
placeholder="如:星光棕"
|
||||
maxlength="20"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-item">
|
||||
<label for="purchase-year">购车年份</label>
|
||||
<p class="field-tip">填写车辆购买年份</p>
|
||||
<div class="input-wrap">
|
||||
<input
|
||||
id="purchase-year"
|
||||
v-model.number="purchaseYear"
|
||||
type="number"
|
||||
min="1900"
|
||||
:max="new Date().getFullYear()"
|
||||
placeholder="如:2022"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-item">
|
||||
<label for="role">账号角色</label>
|
||||
<p class="field-tip">设置用户可使用的权限</p>
|
||||
<div class="input-wrap">
|
||||
<select id="role" v-model="role">
|
||||
<option value="user">普通用户</option>
|
||||
<option value="admin">管理员</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-item">
|
||||
<label>初始密码</label>
|
||||
<p class="field-tip">系统统一使用默认密码,用户登录后可自行修改</p>
|
||||
<div class="default-password">
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||||
<rect x="5" y="10" width="14" height="10" rx="2" />
|
||||
<path d="M8 10V7a4 4 0 0 1 8 0v3" />
|
||||
</svg>
|
||||
<strong>{{ DEFAULT_PASSWORD }}</strong>
|
||||
<span>默认密码</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="message" class="form-message" :class="{ success: submitted }" role="status">
|
||||
{{ message }}
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
<button type="button" class="cancel-button" @click="resetForm">重置</button>
|
||||
<button type="submit" class="submit-button">确认添加</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<footer class="card-footer">
|
||||
<span class="footer-dot"></span>
|
||||
添加成功后,客户可使用车牌号和默认密码登录
|
||||
</footer>
|
||||
</section>
|
||||
</main>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import apiClient from '../../apiClient/apiClient';
|
||||
|
||||
const DEFAULT_PASSWORD = '123456'
|
||||
const plateNumber = ref('')
|
||||
const status = ref('正常')
|
||||
const role = ref('')
|
||||
const carModel = ref('')
|
||||
const carColor = ref('')
|
||||
const purchaseYear = ref('')
|
||||
const message = ref('')
|
||||
const submitted = ref(false)
|
||||
|
||||
async function handleSubmit() {
|
||||
submitted.value = false
|
||||
message.value = ''
|
||||
|
||||
if (!plateNumber.value) {
|
||||
message.value = '请输入客户车牌号'
|
||||
return
|
||||
}
|
||||
|
||||
const userPayload = {
|
||||
plateNumber: plateNumber.value,
|
||||
password: DEFAULT_PASSWORD,
|
||||
role: role.value,
|
||||
status: status.value,
|
||||
carModel: carModel.value || null,
|
||||
carColor: carColor.value || null,
|
||||
purchaseYear: purchaseYear.value || null,
|
||||
}
|
||||
|
||||
// 后续接入接口时,将 userPayload 作为新增用户请求参数提交。
|
||||
console.log('新增用户参数', userPayload)
|
||||
const response = await apiClient.post('/addUser', userPayload)
|
||||
if (response.status == 201) {
|
||||
message.value = '添加用户失败,请稍后重试'
|
||||
return
|
||||
}else if (response.status == 200) {
|
||||
message.value = `用户 ${plateNumber.value} 添加成功,初始密码为 ${DEFAULT_PASSWORD}`
|
||||
submitted.value = true
|
||||
} else {
|
||||
message.value = '添加用户失败,请稍后重试'
|
||||
}
|
||||
}
|
||||
|
||||
function resetForm() {
|
||||
plateNumber.value = ''
|
||||
status.value = '正常'
|
||||
role.value = 'user'
|
||||
carModel.value = ''
|
||||
carColor.value = ''
|
||||
purchaseYear.value = ''
|
||||
message.value = ''
|
||||
submitted.value = false
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.add-user-page,
|
||||
.add-user-page * {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.add-user-page {
|
||||
display: flex;
|
||||
min-height: calc(100vh - 74px);
|
||||
padding: 48px 24px;
|
||||
align-items: flex-start;
|
||||
justify-content: center;
|
||||
background: #f5f7fb;
|
||||
color: #1d2b45;
|
||||
}
|
||||
|
||||
.add-user-card {
|
||||
width: 100%;
|
||||
max-width: 620px;
|
||||
padding: 32px 36px 24px;
|
||||
background: #fff;
|
||||
border: 1px solid #e8edf5;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 8px 26px #29466b0d;
|
||||
}
|
||||
|
||||
.page-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
padding-bottom: 25px;
|
||||
border-bottom: 1px solid #edf0f5;
|
||||
}
|
||||
|
||||
.header-icon {
|
||||
display: grid;
|
||||
width: 46px;
|
||||
height: 46px;
|
||||
place-items: center;
|
||||
color: #1769e1;
|
||||
background: #eaf2ff;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
.header-icon svg,
|
||||
.input-wrap svg,
|
||||
.default-password svg {
|
||||
width: 22px;
|
||||
fill: none;
|
||||
stroke: currentColor;
|
||||
stroke-linecap: round;
|
||||
stroke-linejoin: round;
|
||||
stroke-width: 1.7;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin: 0 0 5px;
|
||||
color: #1b2942;
|
||||
font-size: 22px;
|
||||
}
|
||||
|
||||
.page-header p,
|
||||
.field-tip {
|
||||
margin: 0;
|
||||
color: #8d98aa;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.user-form {
|
||||
padding-top: 27px;
|
||||
}
|
||||
|
||||
.user-form > .form-item + .form-item,
|
||||
.user-form > .form-item + .form-row,
|
||||
.user-form > .form-row + .form-item,
|
||||
.user-form > .form-row + .form-row {
|
||||
margin-top: 24px;
|
||||
}
|
||||
|
||||
.form-row {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.form-row .form-item {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.form-item label {
|
||||
display: block;
|
||||
margin-bottom: 6px;
|
||||
color: #3c4a62;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.field-tip {
|
||||
margin-bottom: 10px;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.input-wrap,
|
||||
.default-password {
|
||||
display: flex;
|
||||
min-height: 48px;
|
||||
align-items: center;
|
||||
padding: 0 14px;
|
||||
gap: 10px;
|
||||
border-radius: 7px;
|
||||
}
|
||||
|
||||
.input-wrap {
|
||||
background: #fff;
|
||||
border: 1px solid #dfe6ef;
|
||||
transition: border-color .2s, box-shadow .2s;
|
||||
}
|
||||
|
||||
.input-wrap:focus-within {
|
||||
border-color: #1769e1;
|
||||
box-shadow: 0 0 0 3px #1769e11a;
|
||||
}
|
||||
|
||||
.input-wrap svg,
|
||||
.default-password svg {
|
||||
flex: 0 0 19px;
|
||||
width: 19px;
|
||||
color: #9da9b8;
|
||||
}
|
||||
|
||||
.input-wrap input {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
padding: 0;
|
||||
color: #263650;
|
||||
outline: 0;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
font: inherit;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.input-wrap input::placeholder {
|
||||
color: #adb7c4;
|
||||
}
|
||||
|
||||
.input-wrap select {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
padding: 0;
|
||||
color: #263650;
|
||||
outline: 0;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
cursor: pointer;
|
||||
font: inherit;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.default-password {
|
||||
color: #1769e1;
|
||||
background: #f3f7ff;
|
||||
border: 1px solid #dce9ff;
|
||||
}
|
||||
|
||||
.default-password strong {
|
||||
font-size: 15px;
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
|
||||
.default-password span {
|
||||
margin-left: auto;
|
||||
color: #8395b2;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.form-message {
|
||||
margin-top: 18px;
|
||||
padding: 10px 12px;
|
||||
color: #d47725;
|
||||
background: #fff7eb;
|
||||
border-radius: 6px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.form-message.success {
|
||||
color: #16835d;
|
||||
background: #eaf8f1;
|
||||
}
|
||||
|
||||
.form-actions {
|
||||
display: flex;
|
||||
margin-top: 30px;
|
||||
justify-content: flex-end;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.cancel-button,
|
||||
.submit-button {
|
||||
min-width: 96px;
|
||||
height: 42px;
|
||||
padding: 0 18px;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
font: inherit;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.cancel-button {
|
||||
color: #65748b;
|
||||
background: #fff;
|
||||
border: 1px solid #dfe6ef;
|
||||
}
|
||||
|
||||
.submit-button {
|
||||
color: #fff;
|
||||
background: #1769e1;
|
||||
border: 1px solid #1769e1;
|
||||
box-shadow: 0 5px 12px #1769e133;
|
||||
}
|
||||
|
||||
.cancel-button:hover {
|
||||
background: #f7f9fc;
|
||||
}
|
||||
|
||||
.submit-button:hover {
|
||||
background: #0e5ac7;
|
||||
}
|
||||
|
||||
.card-footer {
|
||||
display: flex;
|
||||
margin-top: 27px;
|
||||
padding-top: 18px;
|
||||
align-items: center;
|
||||
gap: 7px;
|
||||
color: #9ba6b5;
|
||||
border-top: 1px solid #edf0f5;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.footer-dot {
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
background: #43b883;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
.add-user-page {
|
||||
min-height: calc(100vh - 116px);
|
||||
padding: 24px 14px;
|
||||
}
|
||||
|
||||
.add-user-card {
|
||||
padding: 24px 18px 20px;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
.page-header {
|
||||
padding-bottom: 21px;
|
||||
}
|
||||
|
||||
.form-row {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.form-row .form-item + .form-item {
|
||||
margin-top: 24px;
|
||||
}
|
||||
|
||||
.form-actions {
|
||||
gap: 9px;
|
||||
}
|
||||
|
||||
.cancel-button,
|
||||
.submit-button {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.card-footer {
|
||||
align-items: flex-start;
|
||||
line-height: 1.6;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,206 @@
|
||||
<template>
|
||||
<main class="bill-page">
|
||||
<header class="page-header">
|
||||
<h1>我的账单</h1>
|
||||
<span class="bill-count">共 {{ total }} 笔</span>
|
||||
</header>
|
||||
|
||||
<section class="bill-list" aria-label="账单列表">
|
||||
<article v-for="bill in bills" :key="bill.id" class="bill-item">
|
||||
<div class="bill-icon" :class="bill.type">
|
||||
{{ bill.type === 'income' ? '收' : '支' }}
|
||||
</div>
|
||||
<div class="bill-info">
|
||||
<div class="bill-title">{{ bill.title || '账单' }}</div>
|
||||
<div class="bill-time">{{ bill.time }}</div>
|
||||
</div>
|
||||
<div class="bill-amount" :class="bill.type">
|
||||
{{ bill.type === 'income' ? '+' : '-' }}{{ formatAmount(bill.amount) }}
|
||||
</div>
|
||||
</article>
|
||||
|
||||
<div v-if="loading" class="list-status">正在加载...</div>
|
||||
<div v-else-if="!bills.length" class="list-status">暂无账单</div>
|
||||
<div v-else-if="finished" class="list-status">没有更多账单了</div>
|
||||
<!-- 滚动到此处时自动请求下一页 -->
|
||||
<div ref="loadMoreTarget" class="load-more-target" aria-hidden="true"></div>
|
||||
</section>
|
||||
</main>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { nextTick, onBeforeUnmount, onMounted, ref } from 'vue'
|
||||
|
||||
const PAGE_SIZE = 20
|
||||
const bills = ref([])
|
||||
const total = ref(0)
|
||||
const page = ref(1)
|
||||
const loading = ref(false)
|
||||
const finished = ref(false)
|
||||
const loadMoreTarget = ref(null)
|
||||
let observer
|
||||
|
||||
/**
|
||||
* 账单数据接口:将此处替换为项目实际的请求方法即可。
|
||||
* 返回格式建议为:{ list: Array, total: Number }。
|
||||
*/
|
||||
async function getBillList(params) {
|
||||
// 示例:return request.get('/bill/list', { params })
|
||||
return { list: [], total: 0 }
|
||||
}
|
||||
|
||||
async function loadBills(reset = false) {
|
||||
if (loading.value || (!reset && finished.value)) return
|
||||
if (reset) {
|
||||
page.value = 1
|
||||
finished.value = false
|
||||
bills.value = []
|
||||
}
|
||||
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await getBillList({ page: page.value, pageSize: PAGE_SIZE })
|
||||
const list = result?.list || []
|
||||
bills.value = reset ? list : bills.value.concat(list)
|
||||
total.value = result?.total ?? bills.value.length
|
||||
finished.value = list.length < PAGE_SIZE || bills.value.length >= total.value
|
||||
if (!finished.value) page.value += 1
|
||||
} catch (error) {
|
||||
// 请求失败时保留已加载内容,下一次进入底部可重试。
|
||||
console.error('获取账单失败', error)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function formatAmount(amount) {
|
||||
return Number(amount || 0).toFixed(2)
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await loadBills()
|
||||
await nextTick()
|
||||
observer = new IntersectionObserver(
|
||||
([entry]) => entry.isIntersecting && loadBills(),
|
||||
{ rootMargin: '120px 0px' },
|
||||
)
|
||||
if (loadMoreTarget.value) observer.observe(loadMoreTarget.value)
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => observer?.disconnect())
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.bill-page {
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
min-height: 100vh;
|
||||
padding: 20px 16px calc(24px + env(safe-area-inset-bottom));
|
||||
background: #f6f7fb;
|
||||
color: #20232a;
|
||||
}
|
||||
|
||||
.page-header {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
justify-content: space-between;
|
||||
max-width: 720px;
|
||||
margin: 0 auto 16px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin: 0;
|
||||
font-size: 22px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.bill-count {
|
||||
color: #969ba6;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.bill-list {
|
||||
max-width: 720px;
|
||||
margin: 0 auto;
|
||||
overflow: hidden;
|
||||
border-radius: 12px;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.bill-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
min-height: 72px;
|
||||
padding: 0 16px;
|
||||
border-bottom: 1px solid #f0f1f4;
|
||||
}
|
||||
|
||||
.bill-icon {
|
||||
display: grid;
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
margin-right: 12px;
|
||||
place-items: center;
|
||||
border-radius: 50%;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.bill-icon.income {
|
||||
color: #14966b;
|
||||
background: #e7f8f1;
|
||||
}
|
||||
|
||||
.bill-icon.expense {
|
||||
color: #eb635b;
|
||||
background: #fff0ef;
|
||||
}
|
||||
|
||||
.bill-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.bill-title {
|
||||
overflow: hidden;
|
||||
font-size: 15px;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.bill-time {
|
||||
margin-top: 5px;
|
||||
color: #a0a5ae;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.bill-amount {
|
||||
margin-left: 12px;
|
||||
font-size: 15px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.bill-amount.income {
|
||||
color: #14966b;
|
||||
}
|
||||
|
||||
.bill-amount.expense {
|
||||
color: #20232a;
|
||||
}
|
||||
|
||||
.list-status {
|
||||
padding: 20px 0;
|
||||
color: #a0a5ae;
|
||||
font-size: 13px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.load-more-target {
|
||||
height: 1px;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.bill-page {
|
||||
padding-top: 32px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,803 @@
|
||||
<template>
|
||||
<main class="user-detail-page">
|
||||
<section class="detail-container">
|
||||
<header class="page-header">
|
||||
<div>
|
||||
<p class="eyebrow">CUSTOMER PROFILE</p>
|
||||
<h1>用户详情</h1>
|
||||
<p class="subtitle">查看客户车辆信息与维修保养记录</p>
|
||||
</div>
|
||||
<div class="header-actions">
|
||||
<button class="back-button" type="button" @click="goBack">
|
||||
<span>←</span> 返回用户列表
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<section class="profile-card">
|
||||
<div class="profile-avatar">{{ user.plate.slice(-1) }}</div>
|
||||
<div class="profile-main">
|
||||
<div class="profile-title">
|
||||
<h2>{{ user.plate }}</h2>
|
||||
<span class="status" :class="{ disabled: user.status !== '正常' }">
|
||||
<i></i>{{ user.status }}
|
||||
</span>
|
||||
</div>
|
||||
<p>用户账号:{{ user.username }}</p>
|
||||
<p>最近更新:{{ user.updatedAt }}</p>
|
||||
</div>
|
||||
<button class="delete-button" type="button" @click="handleDelete">删除用户</button>
|
||||
</section>
|
||||
|
||||
<div class="detail-grid">
|
||||
<section class="info-card">
|
||||
<div class="card-heading">
|
||||
<div class="heading-icon blue">
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||||
<path d="M4 16h16M6 16V9l2-3h8l2 3v7M8 16v2m8-2v2M8 11h8" />
|
||||
</svg>
|
||||
</div>
|
||||
<div>
|
||||
<h3>车辆信息</h3>
|
||||
<p>客户爱车的基础资料</p>
|
||||
</div>
|
||||
</div>
|
||||
<dl class="info-list">
|
||||
<div v-for="field in vehicleFields" :key="field.key" class="editable-row" @click.stop>
|
||||
<dt>{{ field.label }}</dt>
|
||||
<dd v-if="editingField !== field.key">{{ user[field.key] }}{{ field.suffix }}</dd>
|
||||
<input v-else v-model="editValue" class="inline-input" :type="field.type || 'text'" />
|
||||
<button v-if="editingField !== field.key" type="button"
|
||||
@click="startEdit(field.key)">修改</button>
|
||||
<button v-else type="button" class="save-field-button"
|
||||
@click="saveField(field.key)">保存</button>
|
||||
</div>
|
||||
</dl>
|
||||
</section>
|
||||
|
||||
<section class="info-card">
|
||||
<div class="card-heading">
|
||||
<div class="heading-icon orange">
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||||
<path d="M6 3h12v18H6zM9 7h6M9 11h6M9 15h3" />
|
||||
</svg>
|
||||
</div>
|
||||
<div>
|
||||
<h3>机油保养</h3>
|
||||
<p>记录最近一次机油服务</p>
|
||||
</div>
|
||||
</div>
|
||||
<dl class="info-list">
|
||||
<div>
|
||||
<dt>上次更换日期</dt>
|
||||
<dd>{{ user.oilChangedAt }}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>机油类型</dt>
|
||||
<dd>{{ user.oilType }}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>建议更换周期</dt>
|
||||
<dd>{{ user.oilCycle }}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>下次建议日期</dt>
|
||||
<dd class="highlight">{{ user.nextOilDate }}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
<button type="button" class="oil-button" @click="showOilFormFuntion">
|
||||
{{ showOilForm ? '取消更新' : '添加 / 更新机油' }}
|
||||
</button>
|
||||
<div v-if="showOilForm" class="oil-form" @click.stop>
|
||||
<label>机油类型<input v-model.trim="oilForm.type" type="text" placeholder="如:全合成 0W-30" /></label>
|
||||
<label>持续时间<input v-model.number="oilForm.duration" type="number" min="1"
|
||||
placeholder="请输入持续月数" /></label>
|
||||
<button type="button" class="save-field-button" @click="saveOil">保存机油信息</button>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<section class="info-card repair-card">
|
||||
<div class="card-heading repair-heading">
|
||||
<div class="heading-icon green">
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||||
<path
|
||||
d="M21 7.5a6.6 6.6 0 0 1-8.8 6.2L6.2 19.7a2.1 2.1 0 0 1-3-3l6-6A6.6 6.6 0 0 1 15.5 3l-2.7 2.7 1.5 1.5L17 4.5A6.6 6.6 0 0 1 21 7.5Z" />
|
||||
</svg>
|
||||
</div>
|
||||
<div>
|
||||
<h3>维修记录</h3>
|
||||
<p>车辆历史维修与服务明细</p>
|
||||
</div>
|
||||
<span class="record-count">共 {{ repairRecords.length }} 次</span>
|
||||
<button type="button" class="add-record-button" @click="showRepairForm = true">添加维修记录</button>
|
||||
</div>
|
||||
<div class="repair-list">
|
||||
<article v-for="record in repairRecords" :key="record.id" class="repair-item">
|
||||
<time>{{ record.date }}</time>
|
||||
<div class="timeline-dot"></div>
|
||||
<div class="repair-content">
|
||||
<strong>{{ record.title }}</strong>
|
||||
<p>{{ record.description }}</p>
|
||||
</div>
|
||||
<span class="repair-price">{{ record.price }}</span>
|
||||
</article>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
<div v-if="showRepairForm" class="modal-mask" @click.self="showRepairForm = false">
|
||||
<form class="repair-form" @submit.prevent="saveRepairRecord">
|
||||
<div class="modal-header">
|
||||
<h2>添加维修记录</h2><button type="button" @click="showRepairForm = false">×</button>
|
||||
</div>
|
||||
<label>维修项目<input v-model.trim="repairForm.title" required placeholder="如:常规保养" /></label>
|
||||
<label>维修日期<input v-model="repairForm.date" type="date" required /></label>
|
||||
<label>维修描述<textarea v-model.trim="repairForm.description" required
|
||||
placeholder="请输入维修内容"></textarea></label>
|
||||
<label>维修金额<input v-model.trim="repairForm.price" required placeholder="如:¥680" /></label>
|
||||
<button class="submit-record-button" type="submit">保存记录</button>
|
||||
</form>
|
||||
</div>
|
||||
</main>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { onBeforeUnmount, onMounted, reactive, ref } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
|
||||
// 后续接入详情接口时,可使用 route.query.plate 作为查询参数。
|
||||
const user = reactive({
|
||||
plate: String(route.query.plate || '粤B12345'),
|
||||
username: String(route.query.plate || '粤B12345'),
|
||||
status: '正常',
|
||||
carModel: '宝马 3系 2022款 325Li',
|
||||
carColor: '星光棕',
|
||||
purchaseYear: '2022',
|
||||
oilChangedAt: '2024-05-18',
|
||||
oilType: '全合成 0W-30',
|
||||
oilCycle: '10,000 公里 / 6 个月',
|
||||
oilDuration: 6,
|
||||
nextOilDate: '2024-11-18',
|
||||
updatedAt: '今天 10:28',
|
||||
})
|
||||
|
||||
const vehicleFields = [
|
||||
{ key: 'plate', label: '车牌号', type: 'text', suffix: '' },
|
||||
{ key: 'carModel', label: '车型', type: 'text', suffix: '' },
|
||||
{ key: 'carColor', label: '车辆颜色', type: 'text', suffix: '' },
|
||||
{ key: 'purchaseYear', label: '购车年份', type: 'number', suffix: ' 年' },
|
||||
]
|
||||
const editingField = ref('')
|
||||
const editValue = ref('')
|
||||
const showOilForm = ref(false)
|
||||
const oilForm = reactive({ type: '', duration: 6 })
|
||||
const showRepairForm = ref(false)
|
||||
const repairForm = reactive({ title: '', date: '', description: '', price: '' })
|
||||
|
||||
const repairRecords = [
|
||||
{ id: 1, date: '2024-05-18', title: '常规保养', description: '更换机油、机油滤清器,车辆 32 项安全检测', price: '¥680' },
|
||||
{ id: 2, date: '2024-03-06', title: '空调系统清洗', description: '空调滤芯更换,蒸发箱深度清洁', price: '¥280' },
|
||||
{ id: 3, date: '2023-12-22', title: '刹车系统检查', description: '前刹车片检查及刹车油液位检测', price: '¥120' },
|
||||
]
|
||||
|
||||
function showOilFormFuntion() {
|
||||
console.log('showOilForm.value:', showOilForm.value)
|
||||
showOilForm.value = !showOilForm.value
|
||||
}
|
||||
|
||||
function goBack() {
|
||||
if (window.history.length > 1) {
|
||||
router.back()
|
||||
} else {
|
||||
router.push('/search')
|
||||
}
|
||||
}
|
||||
|
||||
function handleDelete() { }
|
||||
|
||||
function startEdit(field) {
|
||||
editingField.value = field
|
||||
editValue.value = user[field]
|
||||
}
|
||||
|
||||
async function saveField(field) {
|
||||
if (!editValue.value) return
|
||||
user[field] = editValue.value
|
||||
await updateUserData()
|
||||
await refreshUserDetail()
|
||||
editingField.value = ''
|
||||
}
|
||||
|
||||
async function saveOil() {
|
||||
if (!oilForm.type || !oilForm.duration) return
|
||||
user.oilType = oilForm.type
|
||||
user.oilDuration = oilForm.duration
|
||||
user.oilChangedAt = new Date().toISOString().slice(0, 10)
|
||||
user.oilCycle = `10,000 公里 / ${oilForm.duration} 个月`
|
||||
await updateUserData()
|
||||
await refreshUserDetail()
|
||||
showOilForm.value = false
|
||||
}
|
||||
|
||||
async function saveRepairRecord() {
|
||||
const record = { id: Date.now(), ...repairForm }
|
||||
repairRecords.unshift(record)
|
||||
await updateUserData()
|
||||
await refreshUserDetail()
|
||||
Object.assign(repairForm, { title: '', date: '', description: '', price: '' })
|
||||
showRepairForm.value = false
|
||||
}
|
||||
|
||||
// 所有用户详情修改统一从这里提交给后端。
|
||||
async function updateUserData() { }
|
||||
|
||||
// 后端更新成功后,在这里重新请求详情并刷新页面数据。
|
||||
async function refreshUserDetail() { }
|
||||
|
||||
function closeEditing(event) {
|
||||
if (
|
||||
!event.target.closest('.editable-row') &&
|
||||
!event.target.closest('.oil-form') &&
|
||||
!event.target.closest('.oil-button')
|
||||
) {
|
||||
console.log('点击了编辑区域外部,关闭编辑状态')
|
||||
editingField.value = ''
|
||||
showOilForm.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => document.addEventListener('click', closeEditing))
|
||||
onBeforeUnmount(() => document.removeEventListener('click', closeEditing))
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.user-detail-page {
|
||||
min-height: calc(100vh - 74px);
|
||||
padding: 38px 24px 60px;
|
||||
background: #f5f7fb;
|
||||
color: #1d2b45;
|
||||
}
|
||||
|
||||
.detail-container {
|
||||
width: 100%;
|
||||
max-width: 860px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.page-header {
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.eyebrow {
|
||||
margin: 0 0 7px;
|
||||
color: #1769e1;
|
||||
font-size: 10px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 1.5px;
|
||||
}
|
||||
|
||||
h1,
|
||||
h2,
|
||||
h3,
|
||||
p {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin-bottom: 7px;
|
||||
color: #1b2942;
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.subtitle,
|
||||
.card-heading p,
|
||||
.profile-main p {
|
||||
margin-bottom: 0;
|
||||
color: #8d98aa;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.header-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.back-button,
|
||||
.delete-button {
|
||||
padding: 9px 13px;
|
||||
background: #fff;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
font: inherit;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.back-button {
|
||||
color: #1769e1;
|
||||
border: 1px solid #dfe8f5;
|
||||
}
|
||||
|
||||
.delete-button {
|
||||
color: #dc635b;
|
||||
border: 1px solid #f3d4d1;
|
||||
}
|
||||
|
||||
.back-button span {
|
||||
margin-right: 5px;
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
.profile-card,
|
||||
.info-card {
|
||||
background: #fff;
|
||||
border: 1px solid #e8edf5;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 7px 20px #29466b0a;
|
||||
}
|
||||
|
||||
.profile-card {
|
||||
display: flex;
|
||||
min-height: 116px;
|
||||
padding: 24px;
|
||||
align-items: center;
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.profile-avatar {
|
||||
display: grid;
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
flex: 0 0 60px;
|
||||
place-items: center;
|
||||
color: #1769e1;
|
||||
background: #eaf2ff;
|
||||
border-radius: 14px;
|
||||
font-size: 25px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.profile-main {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.profile-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.profile-title h2 {
|
||||
margin: 0 0 7px;
|
||||
color: #1d2b45;
|
||||
font-size: 19px;
|
||||
}
|
||||
|
||||
.profile-main p+p {
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
.status {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-top: -7px;
|
||||
gap: 5px;
|
||||
color: #239366;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.status i {
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
background: #38b982;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.status.disabled {
|
||||
color: #d78a37;
|
||||
}
|
||||
|
||||
.status.disabled i {
|
||||
background: #e8a24d;
|
||||
}
|
||||
|
||||
.back-button:hover {
|
||||
background: #f2f7ff;
|
||||
}
|
||||
|
||||
.delete-button:hover {
|
||||
background: #fff3f1;
|
||||
}
|
||||
|
||||
.detail-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
margin-top: 20px;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.info-card {
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
.card-heading {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 11px;
|
||||
padding-bottom: 18px;
|
||||
border-bottom: 1px solid #edf0f5;
|
||||
}
|
||||
|
||||
.heading-icon {
|
||||
display: grid;
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
place-items: center;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.heading-icon svg {
|
||||
width: 19px;
|
||||
fill: none;
|
||||
stroke: currentColor;
|
||||
stroke-linecap: round;
|
||||
stroke-linejoin: round;
|
||||
stroke-width: 1.7;
|
||||
}
|
||||
|
||||
.heading-icon.blue {
|
||||
color: #1769e1;
|
||||
background: #eaf2ff;
|
||||
}
|
||||
|
||||
.heading-icon.orange {
|
||||
color: #e58b2b;
|
||||
background: #fff2df;
|
||||
}
|
||||
|
||||
.heading-icon.green {
|
||||
color: #24966b;
|
||||
background: #e6f8ef;
|
||||
}
|
||||
|
||||
.card-heading h3 {
|
||||
margin: 0 0 4px;
|
||||
color: #27354d;
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
.card-heading p {
|
||||
font-size: 10px;
|
||||
}
|
||||
|
||||
.info-list {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.info-list div {
|
||||
display: flex;
|
||||
padding: 13px 0 0;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.editable-row {
|
||||
min-height: 31px;
|
||||
}
|
||||
|
||||
.inline-input {
|
||||
width: 0;
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
padding: 5px 7px;
|
||||
color: #263650;
|
||||
border: 1px solid #b9d1f6;
|
||||
border-radius: 4px;
|
||||
outline: 0;
|
||||
font: inherit;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.inline-input:focus {
|
||||
border-color: #1769e1;
|
||||
box-shadow: 0 0 0 2px #1769e11a;
|
||||
}
|
||||
|
||||
.info-list dt {
|
||||
color: #919cac;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.info-list dd {
|
||||
flex: 1;
|
||||
margin: 0;
|
||||
color: #3c4a62;
|
||||
font-size: 12px;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.info-list button,
|
||||
.save-field-button {
|
||||
flex: 0 0 auto;
|
||||
padding: 3px 7px;
|
||||
color: #1769e1;
|
||||
background: #f1f6ff;
|
||||
border: 0;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font: inherit;
|
||||
font-size: 10px;
|
||||
}
|
||||
|
||||
.info-list button:hover,
|
||||
.save-field-button:hover {
|
||||
background: #dceaff;
|
||||
}
|
||||
|
||||
.info-list dd.highlight {
|
||||
color: #e18427;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.repair-card {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.repair-heading {
|
||||
padding-bottom: 18px;
|
||||
}
|
||||
|
||||
.add-record-button,
|
||||
.oil-button {
|
||||
padding: 7px 10px;
|
||||
color: #1769e1;
|
||||
background: #f1f6ff;
|
||||
border: 0;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
font: inherit;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.add-record-button {
|
||||
margin-left: 10px;
|
||||
}
|
||||
|
||||
.add-record-button:hover,
|
||||
.oil-button:hover {
|
||||
background: #dceaff;
|
||||
}
|
||||
|
||||
.oil-button {
|
||||
margin-top: 18px;
|
||||
}
|
||||
|
||||
.oil-form {
|
||||
display: flex;
|
||||
margin-top: 12px;
|
||||
padding: 12px;
|
||||
align-items: flex-end;
|
||||
gap: 10px;
|
||||
background: #f7faff;
|
||||
border: 1px solid #e0ebfc;
|
||||
border-radius: 7px;
|
||||
}
|
||||
|
||||
.oil-form label,
|
||||
.repair-form label {
|
||||
display: flex;
|
||||
color: #738197;
|
||||
flex: 1;
|
||||
flex-direction: column;
|
||||
gap: 5px;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.oil-form input,
|
||||
.repair-form input,
|
||||
.repair-form textarea {
|
||||
width: 100%;
|
||||
padding: 8px;
|
||||
color: #354158;
|
||||
border: 1px solid #dfe6ef;
|
||||
border-radius: 5px;
|
||||
outline: 0;
|
||||
background: #fff;
|
||||
font: inherit;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.repair-form textarea {
|
||||
min-height: 70px;
|
||||
resize: vertical;
|
||||
}
|
||||
|
||||
.modal-mask {
|
||||
position: fixed;
|
||||
z-index: 10;
|
||||
inset: 0;
|
||||
display: flex;
|
||||
padding: 20px;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: #17233c66;
|
||||
}
|
||||
|
||||
.repair-form {
|
||||
width: 100%;
|
||||
max-width: 410px;
|
||||
padding: 24px;
|
||||
background: #fff;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 14px 40px #17233c33;
|
||||
}
|
||||
|
||||
.modal-header {
|
||||
display: flex;
|
||||
margin-bottom: 18px;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.modal-header h2 {
|
||||
margin: 0;
|
||||
color: #1b2942;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.modal-header button {
|
||||
padding: 0;
|
||||
color: #8d98aa;
|
||||
background: none;
|
||||
border: 0;
|
||||
cursor: pointer;
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.repair-form label+label {
|
||||
margin-top: 13px;
|
||||
}
|
||||
|
||||
.submit-record-button {
|
||||
width: 100%;
|
||||
height: 40px;
|
||||
margin-top: 20px;
|
||||
color: #fff;
|
||||
background: #1769e1;
|
||||
border: 0;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
font: inherit;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.record-count {
|
||||
margin-left: auto;
|
||||
padding: 5px 8px;
|
||||
color: #1769e1;
|
||||
background: #eaf2ff;
|
||||
border-radius: 4px;
|
||||
font-size: 10px;
|
||||
}
|
||||
|
||||
.repair-item {
|
||||
display: flex;
|
||||
min-height: 66px;
|
||||
padding: 16px 0 0;
|
||||
align-items: flex-start;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.repair-item time {
|
||||
width: 75px;
|
||||
padding-top: 2px;
|
||||
color: #8d98aa;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.timeline-dot {
|
||||
width: 9px;
|
||||
height: 9px;
|
||||
margin-top: 4px;
|
||||
flex: 0 0 9px;
|
||||
background: #42b883;
|
||||
border: 2px solid #d9f4e7;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.repair-content {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.repair-content strong {
|
||||
color: #3c4a62;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.repair-content p {
|
||||
margin: 5px 0 0;
|
||||
color: #9aa4b3;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.repair-price {
|
||||
color: #354158;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
.user-detail-page {
|
||||
min-height: calc(100vh - 116px);
|
||||
padding: 24px 14px 40px;
|
||||
}
|
||||
|
||||
.page-header {
|
||||
align-items: flex-start;
|
||||
flex-direction: column;
|
||||
gap: 14px;
|
||||
}
|
||||
|
||||
.profile-card {
|
||||
padding: 18px 15px;
|
||||
}
|
||||
|
||||
.profile-avatar {
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
flex-basis: 48px;
|
||||
border-radius: 11px;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.profile-title h2 {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.header-actions {
|
||||
width: 100%;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.detail-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.info-card {
|
||||
padding: 18px 15px;
|
||||
}
|
||||
|
||||
.repair-item {
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.repair-item time {
|
||||
width: 68px;
|
||||
font-size: 10px;
|
||||
}
|
||||
|
||||
.repair-price {
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.repair-heading {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.add-record-button {
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.oil-form {
|
||||
align-items: stretch;
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -39,13 +39,13 @@
|
||||
<p>登录后即可查看您的车辆服务记录</p>
|
||||
</div>
|
||||
<form class="login-form" @submit.prevent="handleSubmit">
|
||||
<label for="phone">手机号</label>
|
||||
<label for="phone">车牌号</label>
|
||||
<div class="input-wrap">
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||||
<circle cx="12" cy="7" r="3.5" />
|
||||
<path d="M5 20c.5-3.5 2.8-5.5 7-5.5s6.5 2 7 5.5" />
|
||||
<rect x="3" y="7" width="18" height="10" rx="2" />
|
||||
<path d="M6 10h12M6 13h2m2 0h2m2 0h2m2 0h2" />
|
||||
</svg>
|
||||
<input id="phone" type="tel" placeholder="请输入您的手机号" autocomplete="tel" />
|
||||
<input v-model="formData.plateNumber" id="phone" type="tel" placeholder="请输入您的车牌号" autocomplete="username" />
|
||||
</div>
|
||||
<div class="password-label"><label for="password">登录密码</label><a href="#">忘记密码?</a></div>
|
||||
<div class="input-wrap">
|
||||
@@ -53,14 +53,14 @@
|
||||
<rect x="5" y="10" width="14" height="10" rx="2" />
|
||||
<path d="M8 10V7a4 4 0 0 1 8 0v3" />
|
||||
</svg>
|
||||
<input id="password" type="password" placeholder="请输入登录密码" autocomplete="current-password" />
|
||||
<input v-model="formData.password" id="password" type="password" placeholder="请输入登录密码" autocomplete="current-password" />
|
||||
<button type="button" class="password-toggle" aria-label="显示密码"><svg viewBox="0 0 24 24"
|
||||
aria-hidden="true">
|
||||
<path d="M3 12s3.2-5 9-5 9 5 9 5-3.2 5-9 5-9-5-9-5Z" />
|
||||
<circle cx="12" cy="12" r="2" />
|
||||
</svg></button>
|
||||
</div>
|
||||
<label class="remember"><input type="checkbox" /><span>记住我</span></label>
|
||||
<label class="remember"><input v-model="formData.remember" type="checkbox" /><span>记住我</span></label>
|
||||
<button :disabled="loading" type="submit" class="login-button">{{ loading ? '登录中...' : '登录' }}</button>
|
||||
</form>
|
||||
<p class="register-tip">还没有账号?<a href="#">立即注册</a></p>
|
||||
@@ -76,9 +76,13 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import apiClient from '../../apiClient/apiClient';
|
||||
import { useUserInfoStore } from '../../stores/UserInfo';
|
||||
import { onMounted } from 'vue';
|
||||
const userStore = useUserInfoStore();
|
||||
const router = useRouter();
|
||||
const formData = ref({
|
||||
phone: '',
|
||||
plateNumber: '',
|
||||
password: '',
|
||||
remember: false
|
||||
});
|
||||
@@ -90,14 +94,55 @@
|
||||
try {
|
||||
// 模拟登录请求
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
alert(`登录成功!手机号:${formData.value.phone}`);
|
||||
router.push('/main'); // 登录成功后跳转到主页面
|
||||
const response =await apiClient.post('/login', formData.value); // 替换为实际的登录请求
|
||||
//await apiClient.post('/login', formData.value); // 替换为实际的登录请求
|
||||
if (response.status == 200) {
|
||||
userStore.setUserInfo({
|
||||
id: response.data.id,
|
||||
plateNumber: response.data.plateNumber,
|
||||
token: response.data.token,
|
||||
role: response.data.role
|
||||
});
|
||||
alert(`登录成功!车牌号:${formData.value.plateNumber}`);
|
||||
if(formData.value.remember){
|
||||
localStorage.setItem('token',response.data.token);
|
||||
}
|
||||
if(userStore.userInfo.role == 'admin'){
|
||||
router.push('/adduser'); // 登录成功后跳转到管理员页面
|
||||
}else{
|
||||
router.push('/main'); // 登录成功后跳转到主页面
|
||||
}
|
||||
} else {
|
||||
alert('登录失败,请检查您的车牌号和密码。');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('登录失败', error);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
onMounted(async () => {
|
||||
const token = localStorage.getItem('token');
|
||||
console.log('token', token);
|
||||
if (token) {
|
||||
const response =await apiClient.post('/loginByToken',null, { params: { token } }); // 替换为实际的验证请求
|
||||
if (response.status == 200) {
|
||||
userStore.setUserInfo({
|
||||
id: response.data.id,
|
||||
plateNumber: response.data.plateNumber,
|
||||
token: response.data.token,
|
||||
role: response.data.role
|
||||
});
|
||||
if(userStore.userInfo.role == 'admin'){
|
||||
router.push('/adduser'); // 登录成功后跳转到管理员页面
|
||||
}else{
|
||||
router.push('/main'); // 登录成功后跳转到主页面
|
||||
}
|
||||
} else {
|
||||
alert('登录过期或无效,请重新登录。');
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
||||
@@ -0,0 +1,513 @@
|
||||
<template>
|
||||
<main class="search-page">
|
||||
<section class="search-card">
|
||||
<header class="page-header">
|
||||
<div>
|
||||
<p class="eyebrow">CUSTOMER MANAGEMENT</p>
|
||||
<h1>查询用户</h1>
|
||||
<p class="subtitle">根据车牌号快速查找客户服务账号</p>
|
||||
</div>
|
||||
<div class="header-icon" aria-hidden="true">
|
||||
<svg viewBox="0 0 24 24">
|
||||
<circle cx="10.8" cy="10.8" r="6.8" />
|
||||
<path d="m16 16 5 5" />
|
||||
</svg>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<form class="search-form" @submit.prevent="handleSearch">
|
||||
<div class="search-input">
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||||
<circle cx="10.8" cy="10.8" r="6.8" />
|
||||
<path d="m16 16 5 5" />
|
||||
</svg>
|
||||
<input
|
||||
v-model.trim="keyword"
|
||||
type="search"
|
||||
placeholder="请输入车牌号,如:粤B12345"
|
||||
aria-label="输入车牌号"
|
||||
/>
|
||||
<button v-if="keyword" type="button" class="clear-button" aria-label="清空搜索" @click="clearSearch">×</button>
|
||||
</div>
|
||||
<button class="search-button" type="submit">查询</button>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<section class="result-section" aria-live="polite">
|
||||
<div class="result-heading">
|
||||
<div>
|
||||
<h2>{{ keyword ? '查询结果' : '最近更改的用户' }}</h2>
|
||||
<p>{{ keyword ? `包含“${keyword}”的用户` : '展示最近更新的客户账号' }}</p>
|
||||
</div>
|
||||
<span class="result-count">共 {{ total }} 位</span>
|
||||
</div>
|
||||
|
||||
<div class="user-list">
|
||||
<article @click="toUser" v-for="user in users" :key="user.id" class="user-item">
|
||||
<div class="car-avatar">{{ user.plateNumber.slice(-1) }}</div>
|
||||
<div class="user-info">
|
||||
<strong>{{ user.plateNumber }}</strong>
|
||||
<span>客户账号 · {{ user.updatedAt }}</span>
|
||||
</div>
|
||||
<span class="user-status" :class="user.status === '正常' ? 'normal' : 'disabled'">
|
||||
<i></i>{{ user.status }}
|
||||
</span>
|
||||
<button class="more-button" type="button" :aria-label="`查看 ${user.plate} 操作`">···</button>
|
||||
</article>
|
||||
|
||||
<div v-if="loading" class="list-state">
|
||||
<span class="loading-spinner"></span>正在加载用户...
|
||||
</div>
|
||||
<div v-else-if="errorMessage" class="list-state error-state">
|
||||
{{ errorMessage }}
|
||||
<button type="button" @click="loadUsers">重新加载</button>
|
||||
</div>
|
||||
<div v-else-if="!users.length" class="list-state">没有找到匹配的用户</div>
|
||||
<div v-else-if="finished" class="list-state">已加载全部用户</div>
|
||||
<div ref="loadMoreTarget" class="load-more-target" aria-hidden="true"></div>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { nextTick, onBeforeUnmount, onMounted, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import apiClient from '../../apiClient/apiClient'
|
||||
|
||||
// 后续修改每页请求数量时只需要调整这里。
|
||||
const PAGE_SIZE = 6
|
||||
const keyword = ref('')
|
||||
const users = ref([])
|
||||
const total = ref(0)
|
||||
const page = ref(1)
|
||||
const loading = ref(false)
|
||||
const finished = ref(false)
|
||||
const errorMessage = ref('')
|
||||
const loadMoreTarget = ref(null)
|
||||
const router = useRouter()
|
||||
let observer
|
||||
|
||||
const mockUsers = Array.from({ length: 24 }, (_, index) => {
|
||||
const plates = ['粤B12345', '粤B8236K', '粤A1902M', '粤B5618T', '粤B7801V', '粤C29481', '粤A67832', '粤B40916']
|
||||
return {
|
||||
id: index + 1,
|
||||
plate: plates[index % plates.length],
|
||||
updatedAt: `${index + 1}分钟前更新`,
|
||||
status: index === 7 || index === 16 ? '停用' : '正常',
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* 模拟用户接口。
|
||||
* 后续接入真实接口时,保持返回 { list, total } 即可替换此方法。
|
||||
*/
|
||||
function fetchUsers({ page: currentPage, pageSize, keyword: searchKeyword }) {
|
||||
|
||||
/* return response.then(res => {
|
||||
return {
|
||||
list: res.data.list,
|
||||
total: res.data.total,
|
||||
};
|
||||
}).catch(error => {
|
||||
console.error('获取用户失败', error);
|
||||
throw error;
|
||||
}); */
|
||||
return new Promise((resolve) => {
|
||||
window.setTimeout(() => {
|
||||
const normalizedKeyword = searchKeyword.toUpperCase()
|
||||
const filteredUsers = normalizedKeyword
|
||||
? mockUsers.filter((user) => user.plate.includes(normalizedKeyword))
|
||||
: mockUsers
|
||||
const start = (currentPage - 1) * pageSize
|
||||
resolve({
|
||||
list: filteredUsers.slice(start, start + pageSize),
|
||||
total: filteredUsers.length,
|
||||
})
|
||||
}, 500)
|
||||
})
|
||||
}
|
||||
|
||||
async function loadUsers(reset = false) {
|
||||
if (loading.value || (!reset && finished.value)) return
|
||||
if (reset) {
|
||||
page.value = 1
|
||||
finished.value = false
|
||||
users.value = []
|
||||
errorMessage.value = ''
|
||||
}
|
||||
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await apiClient.post('/users', {
|
||||
page: page.value-1,
|
||||
pageSize: PAGE_SIZE,
|
||||
keyword: keyword.value,
|
||||
});
|
||||
const list = result.data?.list || []
|
||||
console.log('获取用户列表', result.data.list);
|
||||
users.value = reset ? list : users.value.concat(list)
|
||||
total.value = result.data?.total ?? users.value.length
|
||||
finished.value = list.length < PAGE_SIZE || users.value.length >= total.value
|
||||
if (!finished.value) page.value += 1
|
||||
} catch (error) {
|
||||
console.error('获取用户失败', error)
|
||||
errorMessage.value = '用户加载失败,请稍后重试'
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function handleSearch() {
|
||||
loadUsers(true)
|
||||
}
|
||||
|
||||
function clearSearch() {
|
||||
keyword.value = ''
|
||||
loadUsers(true)
|
||||
}
|
||||
|
||||
function toUser() {
|
||||
router.push('/adminusers') // 点击用户跳转到用户详情页
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await loadUsers(true)
|
||||
await nextTick()
|
||||
observer = new IntersectionObserver(
|
||||
([entry]) => entry.isIntersecting && loadUsers(),
|
||||
{ rootMargin: '160px 0px' },
|
||||
)
|
||||
if (loadMoreTarget.value) observer.observe(loadMoreTarget.value)
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => observer?.disconnect())
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.search-page {
|
||||
min-height: calc(100vh - 74px);
|
||||
padding: 38px 24px 60px;
|
||||
background: #f5f7fb;
|
||||
color: #1d2b45;
|
||||
}
|
||||
|
||||
.search-card,
|
||||
.result-section {
|
||||
width: 100%;
|
||||
max-width: 860px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.search-card {
|
||||
padding: 28px 32px 30px;
|
||||
background: #fff;
|
||||
border: 1px solid #e8edf5;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 8px 26px #29466b0d;
|
||||
}
|
||||
|
||||
.page-header,
|
||||
.result-heading {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.eyebrow {
|
||||
margin: 0 0 7px;
|
||||
color: #1769e1;
|
||||
font-size: 10px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 1.5px;
|
||||
}
|
||||
|
||||
h1,
|
||||
h2 {
|
||||
margin: 0;
|
||||
color: #1b2942;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.subtitle,
|
||||
.result-heading p {
|
||||
margin: 7px 0 0;
|
||||
color: #8d98aa;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.header-icon {
|
||||
display: grid;
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
place-items: center;
|
||||
color: #1769e1;
|
||||
background: #eaf2ff;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
.header-icon svg,
|
||||
.search-input > svg {
|
||||
width: 21px;
|
||||
fill: none;
|
||||
stroke: currentColor;
|
||||
stroke-linecap: round;
|
||||
stroke-linejoin: round;
|
||||
stroke-width: 1.7;
|
||||
}
|
||||
|
||||
.search-form {
|
||||
display: flex;
|
||||
margin-top: 25px;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.search-input {
|
||||
display: flex;
|
||||
height: 46px;
|
||||
flex: 1;
|
||||
align-items: center;
|
||||
padding: 0 13px;
|
||||
gap: 9px;
|
||||
border: 1px solid #dfe6ef;
|
||||
border-radius: 7px;
|
||||
transition: border-color .2s, box-shadow .2s;
|
||||
}
|
||||
|
||||
.search-input:focus-within {
|
||||
border-color: #1769e1;
|
||||
box-shadow: 0 0 0 3px #1769e11a;
|
||||
}
|
||||
|
||||
.search-input input {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
padding: 0;
|
||||
outline: 0;
|
||||
border: 0;
|
||||
color: #263650;
|
||||
background: transparent;
|
||||
font: inherit;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.search-input input::-webkit-search-cancel-button {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.clear-button,
|
||||
.more-button {
|
||||
padding: 0;
|
||||
color: #99a5b4;
|
||||
background: none;
|
||||
border: 0;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.clear-button {
|
||||
font-size: 21px;
|
||||
}
|
||||
|
||||
.search-button {
|
||||
width: 90px;
|
||||
color: #fff;
|
||||
background: #1769e1;
|
||||
border: 0;
|
||||
border-radius: 7px;
|
||||
box-shadow: 0 5px 12px #1769e133;
|
||||
cursor: pointer;
|
||||
font: inherit;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.search-button:hover {
|
||||
background: #0e5ac7;
|
||||
}
|
||||
|
||||
.result-section {
|
||||
margin-top: 28px;
|
||||
}
|
||||
|
||||
.result-heading {
|
||||
align-items: center;
|
||||
margin-bottom: 13px;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 17px;
|
||||
}
|
||||
|
||||
.result-count {
|
||||
color: #8d98aa;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.user-list {
|
||||
overflow: hidden;
|
||||
background: #fff;
|
||||
border: 1px solid #e8edf5;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
.user-item {
|
||||
display: flex;
|
||||
min-height: 76px;
|
||||
align-items: center;
|
||||
padding: 0 20px;
|
||||
border-bottom: 1px solid #edf0f5;
|
||||
}
|
||||
|
||||
.car-avatar {
|
||||
display: grid;
|
||||
width: 38px;
|
||||
height: 38px;
|
||||
margin-right: 13px;
|
||||
place-items: center;
|
||||
color: #1769e1;
|
||||
background: #eaf2ff;
|
||||
border-radius: 9px;
|
||||
font-size: 16px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.user-info {
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
flex-direction: column;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.user-info strong {
|
||||
color: #354158;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.user-info span {
|
||||
color: #9aa4b3;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.user-status {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-right: 18px;
|
||||
gap: 5px;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.user-status i {
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.user-status.normal {
|
||||
color: #239366;
|
||||
}
|
||||
|
||||
.user-status.normal i {
|
||||
background: #38b982;
|
||||
}
|
||||
|
||||
.user-status.disabled {
|
||||
color: #d78a37;
|
||||
}
|
||||
|
||||
.user-status.disabled i {
|
||||
background: #e8a24d;
|
||||
}
|
||||
|
||||
.more-button {
|
||||
width: 28px;
|
||||
font-size: 17px;
|
||||
letter-spacing: 2px;
|
||||
}
|
||||
|
||||
.list-state {
|
||||
padding: 24px 0;
|
||||
color: #99a5b4;
|
||||
font-size: 12px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.list-state button {
|
||||
margin-left: 8px;
|
||||
padding: 0;
|
||||
color: #1769e1;
|
||||
background: none;
|
||||
border: 0;
|
||||
cursor: pointer;
|
||||
font: inherit;
|
||||
}
|
||||
|
||||
.error-state {
|
||||
color: #d47725;
|
||||
}
|
||||
|
||||
.loading-spinner {
|
||||
display: inline-block;
|
||||
width: 13px;
|
||||
height: 13px;
|
||||
margin-right: 7px;
|
||||
vertical-align: -2px;
|
||||
border: 2px solid #dce9ff;
|
||||
border-top-color: #1769e1;
|
||||
border-radius: 50%;
|
||||
animation: spin .7s linear infinite;
|
||||
}
|
||||
|
||||
.load-more-target {
|
||||
height: 1px;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
.search-page {
|
||||
min-height: calc(100vh - 116px);
|
||||
padding: 22px 14px 40px;
|
||||
}
|
||||
|
||||
.search-card {
|
||||
padding: 22px 18px 24px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 21px;
|
||||
}
|
||||
|
||||
.header-icon {
|
||||
width: 38px;
|
||||
height: 38px;
|
||||
}
|
||||
|
||||
.search-form {
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.search-button {
|
||||
width: 68px;
|
||||
}
|
||||
|
||||
.user-item {
|
||||
min-height: 70px;
|
||||
padding: 0 13px;
|
||||
}
|
||||
|
||||
.user-status {
|
||||
margin-right: 7px;
|
||||
}
|
||||
|
||||
.user-info span {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user