整理初始化迁移并优化订单和用户菜单

This commit is contained in:
yml2213
2026-06-10 16:21:01 +08:00
parent 70a35204b3
commit 3e0a1a2d4b
6 changed files with 149 additions and 100 deletions
+10 -4
View File
@@ -143,7 +143,9 @@ CREATE TABLE IF NOT EXISTS rental_orders (
KEY idx_rental_orders_refund_status (refund_status), KEY idx_rental_orders_refund_status (refund_status),
KEY idx_rental_orders_rented_at (status, rented_at), KEY idx_rental_orders_rented_at (status, rented_at),
KEY idx_rental_orders_status_created_at (status, created_at DESC), KEY idx_rental_orders_status_created_at (status, created_at DESC),
KEY idx_rental_orders_settlement (settlement_status, owner_id, created_at) KEY idx_rental_orders_settlement (settlement_status, owner_id, created_at),
KEY idx_rental_orders_settled_at_id (settled_at, id),
KEY idx_rental_orders_created_at_id (created_at, id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='租号订单表'; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='租号订单表';
-- 订单结算记录表:记录租用完成后的结算信息 -- 订单结算记录表:记录租用完成后的结算信息
@@ -171,7 +173,8 @@ CREATE TABLE IF NOT EXISTS order_checkouts (
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
KEY idx_order_checkouts_order_id (order_id), KEY idx_order_checkouts_order_id (order_id),
KEY idx_order_checkouts_status (status) KEY idx_order_checkouts_status (status),
KEY idx_order_checkouts_status_order_id_id (status, order_id, id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='订单结算记录表'; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='订单结算记录表';
-- 账号交接记录表:记录号主和租客之间的账号交接 -- 账号交接记录表:记录号主和租客之间的账号交接
@@ -223,7 +226,8 @@ CREATE TABLE IF NOT EXISTS wallet_ledger (
KEY idx_wallet_ledger_user_created (user_id, created_at), KEY idx_wallet_ledger_user_created (user_id, created_at),
KEY idx_wallet_ledger_order_id (order_id), KEY idx_wallet_ledger_order_id (order_id),
KEY idx_wallet_ledger_biz (biz_type, biz_no), KEY idx_wallet_ledger_biz (biz_type, biz_no),
KEY idx_wallet_ledger_user_biz_created (user_id, biz_type, created_at DESC) KEY idx_wallet_ledger_user_biz_created (user_id, biz_type, created_at DESC),
KEY idx_wallet_ledger_order_direction_biz (order_id, direction, biz_type)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='钱包流水表'; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='钱包流水表';
-- ------------------------------------------- -- -------------------------------------------
@@ -262,7 +266,9 @@ CREATE TABLE IF NOT EXISTS payment_orders (
KEY idx_payment_orders_user_id (user_id), KEY idx_payment_orders_user_id (user_id),
KEY idx_payment_orders_provider_order_id (provider_order_id), KEY idx_payment_orders_provider_order_id (provider_order_id),
KEY idx_payment_orders_biz_type (biz_type), KEY idx_payment_orders_biz_type (biz_type),
KEY idx_payment_orders_status (status) KEY idx_payment_orders_status (status),
KEY idx_payment_orders_order_biz_status (order_id, biz_type, status),
KEY idx_payment_orders_created_biz_status (created_at, biz_type, status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='支付订单表'; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='支付订单表';
-- 支付商户配置表:支持多商户、多渠道支付配置 -- 支付商户配置表:支持多商户、多渠道支付配置
@@ -1,20 +0,0 @@
-- 为后台财务汇总、明细查询和退款统计补充复合索引。
-- 该迁移按版本只执行一次;若手工执行,请先确认索引不存在。
ALTER TABLE rental_orders
ADD INDEX idx_rental_orders_settled_at_id (settled_at, id);
ALTER TABLE rental_orders
ADD INDEX idx_rental_orders_created_at_id (created_at, id);
ALTER TABLE order_checkouts
ADD INDEX idx_order_checkouts_status_order_id_id (status, order_id, id);
ALTER TABLE payment_orders
ADD INDEX idx_payment_orders_order_biz_status (order_id, biz_type, status);
ALTER TABLE payment_orders
ADD INDEX idx_payment_orders_created_biz_status (created_at, biz_type, status);
ALTER TABLE wallet_ledger
ADD INDEX idx_wallet_ledger_order_direction_biz (order_id, direction, biz_type);
+2 -2
View File
@@ -165,8 +165,8 @@ export async function fetchPostRentalNotice() {
} }
export async function fetchOrders() { export async function fetchOrders() {
const { data } = await apiClient.get<ApiResponse<Order[]>>('/orders') const { data } = await apiClient.get<ApiResponse<{ items: Order[] }>>('/orders')
return data.data return Array.isArray(data.data?.items) ? data.data.items : []
} }
export async function fetchOrder(id: string | number) { export async function fetchOrder(id: string | number) {
@@ -34,7 +34,8 @@ onMounted(() => {
async function loadOrders() { async function loadOrders() {
loading.value = true loading.value = true
try { try {
orders.value = await fetchOrders() const items = await fetchOrders()
orders.value = Array.isArray(items) ? items : []
} catch { } catch {
showToast({ message: '订单加载失败,请稍后重试', icon: 'warning-o' }) showToast({ message: '订单加载失败,请稍后重试', icon: 'warning-o' })
} finally { } finally {
@@ -42,11 +42,11 @@ const displayOrders = computed(() => {
const keyword = searchKeyword.value.trim().toLowerCase() const keyword = searchKeyword.value.trim().toLowerCase()
filtered = filtered.filter( filtered = filtered.filter(
order => order =>
order.order_no.toLowerCase().includes(keyword) || textValue(order.order_no).toLowerCase().includes(keyword) ||
formatListingCode(order).toLowerCase().includes(keyword) || formatListingCode(order).toLowerCase().includes(keyword) ||
String(order.listing_id).includes(keyword) || String(order.listing_id).includes(keyword) ||
String(order.account_id).includes(keyword) || String(order.account_id).includes(keyword) ||
order.title.toLowerCase().includes(keyword) textValue(order.title).toLowerCase().includes(keyword)
) )
} }
@@ -85,7 +85,8 @@ function handleTabChange(tab: string | number) {
async function loadOrders() { async function loadOrders() {
loading.value = true loading.value = true
try { try {
orders.value = await fetchOrders() const items = await fetchOrders()
orders.value = Array.isArray(items) ? items : []
} finally { } finally {
loading.value = false loading.value = false
} }
@@ -143,14 +144,29 @@ function money(value: unknown) {
return formatMoney(Number(value || 0)) return formatMoney(Number(value || 0))
} }
function shortenOrderNo(orderNo: string) { function textValue(value: unknown) {
if (orderNo.length <= 20) return orderNo return typeof value === 'string' ? value : ''
return `${orderNo.slice(0, 12)}...${orderNo.slice(-6)}`
} }
async function copyOrderNo(orderNo: string) { function orderNoText(orderNo: unknown) {
return textValue(orderNo) || '订单号未生成'
}
function shortenOrderNo(orderNo: unknown) {
const value = orderNoText(orderNo)
if (value === '订单号未生成') return value
if (value.length <= 20) return value
return `${value.slice(0, 12)}...${value.slice(-6)}`
}
async function copyOrderNo(orderNo: unknown) {
const value = textValue(orderNo)
if (!value) {
ElMessage.warning('订单号未生成,暂无法复制')
return
}
try { try {
await navigator.clipboard.writeText(orderNo) await navigator.clipboard.writeText(value)
ElMessage.success('订单号已复制') ElMessage.success('订单号已复制')
} catch { } catch {
ElMessage.error('复制失败') ElMessage.error('复制失败')
+111 -65
View File
@@ -12,7 +12,6 @@ import {
EditPen, EditPen,
Finished, Finished,
House, House,
InfoFilled,
Search, Search,
Service, Service,
Shop, Shop,
@@ -201,45 +200,43 @@ async function handleSupportClick() {
<Transition name="dropdown"> <Transition name="dropdown">
<div v-if="showUserDropdown" class="pc-user-dropdown-container"> <div v-if="showUserDropdown" class="pc-user-dropdown-container">
<div class="pc-user-dropdown"> <div class="pc-user-dropdown">
<RouterLink class="dropdown-item" to="/profile" @click="showUserDropdown = false"> <div class="dropdown-basic-grid">
<el-icon><EditPen /></el-icon> <RouterLink
<span>个人资料</span> class="dropdown-basic-item"
</RouterLink> to="/profile"
<RouterLink class="dropdown-item" to="/orders" @click="showUserDropdown = false"> @click="showUserDropdown = false"
<el-icon><Tickets /></el-icon> >
<span>我的订单</span> <el-icon><EditPen /></el-icon>
</RouterLink> <span>个人资料</span>
<RouterLink class="dropdown-item" to="/wallet" @click="showUserDropdown = false"> </RouterLink>
<el-icon><Wallet /></el-icon> <RouterLink
<span>我的钱包</span> class="dropdown-basic-item"
</RouterLink> to="/orders"
<RouterLink @click="showUserDropdown = false"
class="dropdown-item" >
to="/seller/listings/create" <el-icon><Tickets /></el-icon>
@click="showUserDropdown = false" <span>我的订单</span>
> </RouterLink>
<el-icon><CirclePlus /></el-icon> <RouterLink
<span>发布账号</span> class="dropdown-basic-item"
</RouterLink> to="/wallet"
<RouterLink @click="showUserDropdown = false"
class="dropdown-item" >
to="/realname" <el-icon><Wallet /></el-icon>
@click="showUserDropdown = false" <span>我的钱包</span>
> </RouterLink>
<el-icon><DocumentChecked /></el-icon> <RouterLink
<span>实名认证</span> class="dropdown-basic-item"
<span class="dropdown-status" :class="`is-${realnameBadge.tone}`"> to="/realname"
{{ realnameBadge.text }} @click="showUserDropdown = false"
</span> >
</RouterLink> <el-icon><DocumentChecked /></el-icon>
<RouterLink <span>实名认证</span>
class="dropdown-item" <span class="dropdown-status" :class="`is-${realnameBadge.tone}`">
to="/post-rental-notice" {{ realnameBadge.text }}
@click="showUserDropdown = false" </span>
> </RouterLink>
<el-icon><InfoFilled /></el-icon> </div>
<span>租后须知</span>
</RouterLink>
<div class="dropdown-divider"></div> <div class="dropdown-divider"></div>
<section class="dropdown-service-group"> <section class="dropdown-service-group">
@@ -271,11 +268,11 @@ async function handleSupportClick() {
<div class="dropdown-service-head"> <div class="dropdown-service-head">
<span>卖家服务</span> <span>卖家服务</span>
</div> </div>
<div class="dropdown-seller-list"> <div class="dropdown-seller-grid">
<RouterLink <RouterLink
v-for="item in sellerServiceItems" v-for="item in sellerServiceItems"
:key="item.label" :key="item.label"
class="dropdown-seller-item" class="dropdown-seller-card"
:to="item.to" :to="item.to"
@click="showUserDropdown = false" @click="showUserDropdown = false"
> >
@@ -662,8 +659,8 @@ async function handleSupportClick() {
} }
.pc-user-dropdown { .pc-user-dropdown {
width: 324px; width: 388px;
padding: 10px; padding: 14px;
border-radius: 14px; border-radius: 14px;
background: #fff; background: #fff;
border: 1px solid #eef1f5; border: 1px solid #eef1f5;
@@ -691,12 +688,12 @@ async function handleSupportClick() {
display: inline-flex; display: inline-flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
min-width: 54px; min-width: 50px;
height: 22px; height: 20px;
margin-left: auto; margin-left: auto;
padding: 0 8px; padding: 0 7px;
border-radius: 999px; border-radius: 999px;
font-size: 12px; font-size: 11px;
font-weight: 800; font-weight: 800;
line-height: 1; line-height: 1;
white-space: nowrap; white-space: nowrap;
@@ -732,21 +729,66 @@ async function handleSupportClick() {
.dropdown-divider { .dropdown-divider {
height: 1px; height: 1px;
margin: 6px 10px; margin: 12px 6px;
background: #f1f5f9; background: #f1f5f9;
} }
.dropdown-basic-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 8px;
}
.dropdown-basic-item {
display: flex;
align-items: center;
gap: 9px;
min-width: 0;
min-height: 42px;
padding: 0 12px;
border-radius: 10px;
background: #f8fafc;
color: #475569;
font-size: 13px;
font-weight: 800;
text-decoration: none;
transition: all 0.2s;
}
.dropdown-basic-item .el-icon {
flex: 0 0 auto;
color: #94a3b8;
font-size: 16px;
}
.dropdown-basic-item span:not(.dropdown-status) {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.dropdown-basic-item:hover {
background: #fff3e8;
color: #ff6a00;
transform: translateY(-1px);
}
.dropdown-basic-item:hover .el-icon {
color: #ff6a00;
}
.dropdown-service-group { .dropdown-service-group {
padding: 6px 4px 4px; padding: 0 2px;
} }
.dropdown-service-head { .dropdown-service-head {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
padding: 0 8px 8px; padding: 0 2px 8px;
color: #17233d; color: #17233d;
font-size: 13px; font-size: 14px;
font-weight: 900; font-weight: 900;
} }
@@ -768,7 +810,7 @@ async function handleSupportClick() {
} }
.dropdown-service-card, .dropdown-service-card,
.dropdown-seller-item { .dropdown-seller-card {
text-decoration: none; text-decoration: none;
transition: all 0.2s; transition: all 0.2s;
} }
@@ -776,7 +818,7 @@ async function handleSupportClick() {
.dropdown-service-card { .dropdown-service-card {
display: grid; display: grid;
min-width: 0; min-width: 0;
min-height: 68px; min-height: 74px;
place-items: center; place-items: center;
gap: 6px; gap: 6px;
padding: 8px 4px; padding: 8px 4px;
@@ -799,35 +841,39 @@ async function handleSupportClick() {
transform: translateY(-1px); transform: translateY(-1px);
} }
.dropdown-seller-list { .dropdown-seller-grid {
display: grid; display: grid;
gap: 6px; grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 8px;
} }
.dropdown-seller-item { .dropdown-seller-card {
display: flex; display: grid;
place-items: center;
align-items: center; align-items: center;
gap: 10px; gap: 8px;
min-height: 36px; min-height: 72px;
padding: 0 10px; padding: 10px 6px;
border-radius: 10px; border-radius: 10px;
background: #f8fafc; background: #f8fafc;
color: #475569; color: #475569;
font-size: 13px; font-size: 13px;
font-weight: 800; font-weight: 800;
text-align: center;
} }
.dropdown-seller-item .el-icon { .dropdown-seller-card .el-icon {
color: #94a3b8; color: #94a3b8;
font-size: 16px; font-size: 18px;
} }
.dropdown-seller-item:hover { .dropdown-seller-card:hover {
background: #fff3e8; background: #fff3e8;
color: #ff6a00; color: #ff6a00;
transform: translateY(-1px);
} }
.dropdown-seller-item:hover .el-icon { .dropdown-seller-card:hover .el-icon {
color: #ff6a00; color: #ff6a00;
} }