admin模块接入数据库

This commit is contained in:
comlibmb
2026-02-13 17:29:50 +08:00
parent 56209b7a75
commit ec636dc703
58 changed files with 5586 additions and 1394 deletions

View File

@@ -5,37 +5,40 @@
<view class="search-row">
<view class="search-item">
<text class="label">评价时间:</text>
<view class="mock-date-range">
<text class="emoji">📅</text>
<text class="txt">开始日期 - 结束日期</text>
</view>
<AnalyticsDateRangePicker
:initialStartDate="startDate"
:initialEndDate="endDate"
@apply="onApplyRange"
@clear="onClearRange"
/>
</view>
<view class="search-item">
<text class="label">评价状态:</text>
<view class="mock-select"><text>请选择</text><text class="arrow">▼</text></view>
</view>
<view class="search-item">
<text class="label">审核状态:</text>
<view class="mock-select"><text>请选择</text><text class="arrow">▼</text></view>
<picker :value="statusIndex" :range="statusOptions" range-key="label" @change="onStatusChange">
<view class="mock-select">
<text>{{ statusOptions[statusIndex].label }}</text>
<text class="arrow">▼</text>
</view>
</picker>
</view>
</view>
<view class="search-row mt-16">
<view class="search-item">
<text class="label">商品信息</text>
<input class="mock-input" placeholder="请输入商品信息" />
<text class="label">商品名称</text>
<input class="mock-input" v-model="searchProduct" placeholder="请输入商品信息" @confirm="onSearch" />
</view>
<view class="search-item">
<text class="label">用户名称:</text>
<input class="mock-input" placeholder="请输入" />
<input class="mock-input" v-model="searchUser" placeholder="请输入" @confirm="onSearch" />
</view>
<button class="btn-primary">查询</button>
<button class="btn-primary" @click="onSearch">查询</button>
<button class="btn-white" @click="onReset">重置</button>
</view>
</view>
<!-- 2. 操作行 -->
<view class="action-bar">
<button class="btn-primary">添加自评</button>
<button class="btn-white">批量审核</button>
<button class="btn-primary" @click="onAddSelfReview">添加自评</button>
</view>
<!-- 3. 数据表格 -->
@@ -45,7 +48,6 @@
<view class="th col-check"><text>□</text></view>
<view class="th col-id"><text>评论ID</text></view>
<view class="th col-product"><text>商品信息</text></view>
<view class="th col-spec"><text>规格</text></view>
<view class="th col-user"><text>用户名称</text></view>
<view class="th col-score"><text>评分</text></view>
<view class="th col-content"><text>评价内容</text></view>
@@ -55,40 +57,45 @@
<view class="th col-op"><text>操作</text></view>
</view>
<view v-for="item in replyList" :key="item.id" class="tr-row">
<view v-if="isLoading" class="table-empty" style="padding: 40px; text-align: center;">
<text>数据加载中...</text>
</view>
<view v-else-if="replyList.length === 0" class="table-empty" style="padding: 40px; text-align: center;">
<text>暂无评价数据</text>
</view>
<view v-else v-for="item in replyList" :key="item.id" class="tr-row">
<view class="td col-check"><text>□</text></view>
<view class="td col-id"><text>{{ item.id }}</text></view>
<view class="td col-product">
<image class="p-img" :src="item.image" mode="aspectFill" />
<text class="p-name-txt">{{ item.productName }}</text>
<image class="p-img" :src="item.product_image || '/static/logo.png'" mode="aspectFill" />
<text class="p-name-txt">{{ item.product_name }}</text>
</view>
<view class="td col-spec"><text>{{ item.spec }}</text></view>
<view class="td col-user"><text>{{ item.username }}</text></view>
<view class="td col-score"><text>{{ item.score }}</text></view>
<view class="td col-user"><text>{{ item.username || '游客' }}</text></view>
<view class="td col-score"><text>{{ item.rating }}</text></view>
<view class="td col-content"><text class="blue-link">{{ item.content }}</text></view>
<view class="td col-reply"><text>{{ item.reply || '无' }}</text></view>
<view class="td col-reply"><text>{{ item.merchant_reply || '无' }}</text></view>
<view class="td col-status">
<text class="status-tag" :class="item.status === 1 ? 'pass' : 'wait'">
{{ item.status === 1 ? '通过' : '待审核' }}
<text class="status-tag" :class="item.status === 1 ? 'pass' : (item.status === 3 ? 'fail' : 'wait')">
{{ item.status === 1 ? '通过' : (item.status === 3 ? '已驳回' : '待审核') }}
</text>
</view>
<view class="td col-time"><text>{{ item.time }}</text></view>
<view class="td col-time"><text>{{ formatDateTime(item.created_at) }}</text></view>
<view class="td col-op">
<text class="op-link">通过</text>
<text class="op-link">驳回</text>
<text class="op-link">回复</text>
<text class="op-link red">删除</text>
<text v-if="item.status !== 1" class="op-link" @click="handleApprove(item.id)">通过</text>
<text v-if="item.status !== 3" class="op-link" @click="handleReject(item.id)">驳回</text>
<text class="op-link" @click="handleReply(item)">回复</text>
<text class="op-link red" @click="handleDelete(item.id)">删除</text>
</view>
</view>
</view>
<!-- 分页 -->
<view class="pagination-row">
<text class="total">共 {{ replyList.length }} 条</text>
<text class="total">共 {{ total }} 条</text>
<view class="page-ctrl">
<text class="page-btn disabled">{"<"}</text>
<text class="page-num active">1</text>
<text class="page-btn">{">"}</text>
<text class="page-btn" :class="{ disabled: page <= 1 }" @click="onPrevPage">{"<"}</text>
<text class="page-num active">{{ page }}</text>
<text class="page-btn" :class="{ disabled: replyList.length < pageSize }" @click="onNextPage">{">"}</text>
</view>
</view>
</view>
@@ -96,46 +103,169 @@
</template>
<script setup lang="uts">
import { ref } from 'vue'
import { ref, onMounted } from 'vue'
import AnalyticsDateRangePicker from '@/components/analytics/AnalyticsDateRangePicker.uvue'
import { fetchAdminProductReviews, approveProductReview, rejectProductReview, replyProductReview, deleteProductReview, type ProductReviewItem } from '@/services/admin/productReviewService.uts'
const replyList = ref([
{
id: 1069,
image: 'https://img1.baidu.com/it/u=254065646,3100346083&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500',
productName: 'UR2024夏季新款女装复古纯欲氛围感一字肩短款T恤衫UWG440060',
spec: 'XL,卡其',
username: 'demo998',
score: 3.5,
content: '22',
reply: '',
status: 0,
time: '2025-02-19 14:56:43'
},
{
id: 1059,
image: 'https://img1.baidu.com/it/u=254065646,3100346083&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500',
productName: 'UR2024夏季新款女装复古纯欲氛围感一字肩短款T恤衫UWG440060',
spec: 'XL,卡其',
username: '你好呀',
score: 3.5,
content: '的',
reply: '',
status: 0,
time: '2025-01-07 15:35:36'
},
{
id: 980,
image: 'https://img1.baidu.com/it/u=254065646,3100346083&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500',
productName: 'UR2024夏季新款女装复古纯欲氛围感一字肩短款T恤衫UWG440060',
spec: 'XL,卡其',
username: 'wx209638',
score: 5,
content: '好',
reply: '',
status: 1,
time: '2024-09-12 14:20:12'
}
const replyList = ref<Array<ProductReviewItem>>([])
const isLoading = ref(false)
const searchProduct = ref('')
const searchUser = ref('')
const statusOptions = ref<Array<{ label: string; value: number | null }>>([
{ label: '全部', value: null },
{ label: '通过', value: 1 },
{ label: '已驳回', value: 3 },
{ label: '已删除', value: 2 }
])
const statusIndex = ref(0)
const startDate = ref<string>('')
const endDate = ref<string>('')
const page = ref(1)
const pageSize = 20
const total = ref(0)
onMounted(() => {
// 默认最近 30 天(本地日期)
const end = new Date()
const start = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000)
startDate.value = start.toISOString().substring(0, 10)
endDate.value = end.toISOString().substring(0, 10)
loadData()
})
async function loadData() {
isLoading.value = true
try {
const startTime = startDate.value ? (startDate.value + ' 00:00:00') : null
const endTime = endDate.value ? (endDate.value + ' 23:59:59') : null
const res = await fetchAdminProductReviews({
searchProduct: searchProduct.value,
searchUser: searchUser.value,
status: statusOptions.value[statusIndex.value].value,
startTime,
endTime,
page: page.value,
pageSize
})
replyList.value = res.items
total.value = res.total
} catch (e) {
uni.showToast({ title: '加载评价失败', icon: 'none' })
} finally {
isLoading.value = false
}
}
function onApplyRange(payload: any) {
startDate.value = payload?.start ?? ''
endDate.value = payload?.end ?? ''
page.value = 1
loadData()
}
function onClearRange() {
startDate.value = ''
endDate.value = ''
page.value = 1
loadData()
}
function onStatusChange(e: any) {
statusIndex.value = parseInt(String(e.detail.value))
page.value = 1
loadData()
}
function onSearch() {
page.value = 1
loadData()
}
function onReset() {
searchProduct.value = ''
searchUser.value = ''
statusIndex.value = 0
page.value = 1
loadData()
}
function onPrevPage() {
if (page.value <= 1) return
page.value--
loadData()
}
function onNextPage() {
if (replyList.value.length < pageSize) return
page.value++
loadData()
}
function onAddSelfReview() {
uni.showToast({ title: '添加自评开发中', icon: 'none' })
}
function formatDateTime(iso: string): string {
try {
return iso.replace('T', ' ').split('.')[0]
} catch (e) {
return iso
}
}
async function handleApprove(id: string) {
const ok = await approveProductReview(id)
if (ok) {
uni.showToast({ title: '已通过', icon: 'success' })
loadData()
}
}
async function handleReject(id: string) {
const ok = await rejectProductReview(id)
if (ok) {
uni.showToast({ title: '已驳回', icon: 'success' })
loadData()
}
}
async function handleDelete(id: string) {
uni.showModal({
title: '提示',
content: '确定删除该评价吗?',
success: async (res) => {
if (!res.confirm) return
const ok = await deleteProductReview(id)
if (ok) {
uni.showToast({ title: '已删除', icon: 'success' })
loadData()
}
}
})
}
async function handleReply(item: ProductReviewItem) {
uni.showModal({
title: '回复评价',
editable: true,
content: item.merchant_reply ?? '',
placeholderText: '请输入回复内容',
success: async (res) => {
if (!res.confirm) return
const content = res.content ?? ''
const ok = await replyProductReview(item.id, content)
if (ok) {
uni.showToast({ title: '回复成功', icon: 'success' })
loadData()
}
}
})
}
</script>
<style scoped lang="scss">