文件
fenleixinxi/uniapp/components/fc-report-modal/fc-report-modal.vue
MiAn 134267fcd9 feat: 新增举报详情功能及相关接口、页面
新增举报详情页面路由与配置
新增举报详情接口及路由规则
新增举报列表状态筛选功能
新增错误信息标准化处理方法
优化举报列表页面UI交互
完善微信登录异常提示处理
2026-11-19 09:16:58 +08:00

707 行
16 KiB
Vue

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<template>
<view v-if="show" class="report-modal__mask" @click="handleClose" @touchmove.stop.prevent>
<view class="report-modal__panel" @click.stop>
<!-- 顶部下拉把手 -->
<view class="report-modal__handle-bar"></view>
<!-- 弹窗标题 -->
<view class="report-modal__header">
<view class="report-modal__title-group">
<text class="report-modal__title">{{ titleText }}</text>
<text v-if="targetName" class="report-modal__subtitle">对象:{{ targetName }}</text>
</view>
<view class="report-modal__close-btn" @click="handleClose">
<text class="report-modal__close-icon">✕</text>
</view>
</view>
<!-- 安全监督承诺条 -->
<view class="report-modal__notice">
<text class="report-modal__notice-text">平台将对您的举报信息严格保密,并在核实后通过系统消息向您反馈处置结果。</text>
</view>
<!-- 内容滚动区 -->
<scroll-view class="report-modal__scroll" scroll-y :show-scrollbar="false">
<!-- 1. 举报原因(必选) -->
<view class="report-modal__section">
<view class="report-modal__section-header">
<text class="report-modal__section-title">选择违规原因</text>
<text class="report-modal__section-required">* 必选</text>
</view>
<view class="report-modal__reasons-grid">
<view
v-for="item in availableReasons"
:key="item"
class="report-modal__reason-tag"
:class="{ 'report-modal__reason-tag--active': currentReason === item }"
@click="selectReason(item)"
>
<text class="report-modal__reason-text">{{ item }}</text>
<view v-if="currentReason === item" class="report-modal__reason-badge">
<text class="report-modal__reason-check">✓</text>
</view>
</view>
</view>
</view>
<!-- 2. 详细说明(选填) -->
<view class="report-modal__section">
<view class="report-modal__section-header">
<text class="report-modal__section-title">补充详细说明</text>
<text class="report-modal__section-counter">{{ detailText.length }}/200</text>
</view>
<view class="report-modal__textarea-wrap">
<textarea
v-model="detailText"
class="report-modal__textarea"
placeholder="请详细描述具体的违规事实、受骗经过或异常情况(选填)"
placeholder-class="report-modal__textarea-placeholder"
maxlength="200"
:cursor-spacing="60"
/>
</view>
</view>
<!-- 3. 上传截图凭证(选填,最多4张) -->
<view class="report-modal__section">
<view class="report-modal__section-header">
<text class="report-modal__section-title">上传证据截图</text>
<text class="report-modal__section-sub">聊天记录、转账或违规截图(选填,最多4张)</text>
</view>
<view class="report-modal__images-grid">
<!-- 已上传图片 -->
<view
v-for="(imgUrl, idx) in imageList"
:key="imgUrl + idx"
class="report-modal__img-item"
@click="previewImage(idx)"
>
<image class="report-modal__img-thumb" :src="formatImgUrl(imgUrl)" mode="aspectFill" />
<view class="report-modal__img-del" @click.stop="removeImage(idx)">
<text class="report-modal__img-del-icon">✕</text>
</view>
</view>
<!-- 上传中占位 -->
<view v-if="uploading" class="report-modal__img-item report-modal__img-item--uploading">
<text class="report-modal__img-loading-txt">上传中…</text>
</view>
<!-- 添加图片按钮 -->
<view
v-if="imageList.length < 4 && !uploading"
class="report-modal__img-uploader"
@click="chooseAndUploadImage"
>
<text class="report-modal__img-uploader-plus">+</text>
<text class="report-modal__img-uploader-txt">{{ imageList.length }}/4</text>
</view>
</view>
</view>
</scroll-view>
<!-- 底部提交操作栏 -->
<view class="report-modal__footer">
<button
class="report-modal__submit-btn"
:class="{ 'report-modal__submit-btn--disabled': !currentReason || submitting || uploading }"
:loading="submitting"
:disabled="!currentReason || submitting || uploading"
@click="handleSubmit"
>
{{ submitting ? '正在提交…' : '确认提交举报' }}
</button>
</view>
</view>
</view>
</template>
<script>
/**
* 组件 · 举报与维权申诉弹窗(BottomSheet)
*
* 遵循轻氧浅绿 Mint Green 视觉主题规范与本地生活合规存证要求:
* 1. 支持举报信息(post)与评价(comment);
* 2. 纯原生字符串数组解包,彻底消除微信小程序 Structured Clone 异常;
* 3. 支持选择原因、填写 200 字详细文字说明、上传最多 4 张截图凭证;
* 4. 提交后自动对接到后端 fc_report 与后台全功能核实处置工作台。
*/
import reportApi from '@/common/api/report.js'
import postApi from '@/common/api/post.js'
import { REPORT_REASONS } from '@/common/constants/report.js'
import { assetUrl } from '@/common/utils/format.js'
export default {
name: 'FcReportModal',
props: {
/** 是否展示弹窗 */
show: {
type: Boolean,
default: false,
},
/** 举报目标类型:post 信息 | comment 评价 */
targetType: {
type: String,
default: 'post',
},
/** 举报目标ID */
targetId: {
type: [Number, String],
required: true,
},
/** 目标摘要展示名称(如帖子标题、评价内容片段) */
targetTitle: {
type: String,
default: '',
},
/** 外部可注入的举报原因列表 */
reasons: {
type: Array,
default: () => [],
},
},
data() {
return {
currentReason: '',
detailText: '',
imageList: [],
uploading: false,
submitting: false,
}
},
computed: {
/**
* 弹窗主标题
* @returns {string}
*/
titleText() {
return this.targetType === 'comment' ? '举报违规评价' : '举报违规信息'
},
/**
* 截断显示的对象名称
* @returns {string}
*/
targetName() {
if (!this.targetTitle) return ''
const clean = this.targetTitle.replace(/\s+/g, ' ').trim()
return clean.length > 20 ? clean.slice(0, 20) + '…' : clean
},
/**
* 可选原因列表(脱除 Vue 响应式代理并保障是纯字符串数组)
* @returns {string[]}
*/
availableReasons() {
const source = (this.reasons && this.reasons.length) ? this.reasons : REPORT_REASONS
const list = []
for (let i = 0; i < source.length; i++) {
const item = source[i]
const str = typeof item === 'string' ? item.trim() : (item && String(item.label || item.value || '').trim())
if (str && !list.includes(str)) {
list.push(str)
}
}
return list.length ? list : ['虚假信息', '违法违禁', '垃圾广告', '重复发布', '引诱私下交易', '其他']
},
},
watch: {
show(val) {
if (val) {
// 每次弹开重置状态
this.currentReason = this.availableReasons[0] || '虚假信息'
this.detailText = ''
this.imageList = []
this.uploading = false
this.submitting = false
}
},
},
methods: {
/**
* 格式化图片地址为可渲染 URL
* @param {string} url
* @returns {string}
*/
formatImgUrl(url) {
return assetUrl(url)
},
/**
* 选择举报原因
* @param {string} reason
*/
selectReason(reason) {
this.currentReason = reason
},
/**
* 关闭弹窗
*/
handleClose() {
if (this.submitting) return
this.$emit('close')
},
/**
* 移除某张已上传图片
* @param {number} idx
*/
removeImage(idx) {
this.imageList.splice(idx, 1)
},
/**
* 预览已上传截图
* @param {number} currentIdx
*/
previewImage(currentIdx) {
const urls = this.imageList.map((u) => assetUrl(u))
uni.previewImage({
current: urls[currentIdx],
urls,
})
},
/**
* 选择并上传图片凭证(最多 4 张)
*/
chooseAndUploadImage() {
const maxRemain = 4 - this.imageList.length
if (maxRemain <= 0) return
uni.chooseImage({
count: maxRemain,
sizeType: ['compressed'],
sourceType: ['album', 'camera'],
success: async (res) => {
const tempFilePaths = res.tempFilePaths || []
if (!tempFilePaths.length) return
this.uploading = true
uni.showLoading({ title: '正在上传凭证…' })
try {
for (let i = 0; i < tempFilePaths.length; i++) {
const path = tempFilePaths[i]
const uploaded = await postApi.uploadMedia(path, 'image')
if (uploaded && uploaded.url) {
this.imageList.push(uploaded.url)
}
}
} catch (e) {
uni.showToast({ title: e.message || '部分凭证上传失败', icon: 'none' })
} finally {
this.uploading = false
uni.hideLoading()
}
},
})
},
/**
* 提交举报表单
*/
async handleSubmit() {
if (!this.currentReason) {
uni.showToast({ title: '请选择违规原因', icon: 'none' })
return
}
if (this.submitting || this.uploading) return
this.submitting = true
try {
const payload = {
targetType: this.targetType,
targetId: Number(this.targetId),
reason: this.currentReason,
detail: this.detailText.trim(),
images: this.imageList,
}
await reportApi.create(payload)
uni.showToast({
title: '举报已提交核实',
icon: 'success',
duration: 2000,
})
this.$emit('success', payload)
this.$emit('close')
} catch (e) {
uni.showToast({
title: e.message || '提交失败,请重试',
icon: 'none',
})
} finally {
this.submitting = false
}
},
},
}
</script>
<style lang="scss" scoped>
.report-modal__mask {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 999;
background: rgba(15, 23, 42, 0.55);
backdrop-filter: blur(4rpx);
display: flex;
align-items: flex-end;
animation: reportModalFadeIn 0.22s ease-out;
}
.report-modal__panel {
width: 100%;
max-height: 85vh;
overflow: hidden;
background: #ffffff;
border-radius: 36rpx 36rpx 0 0;
box-shadow: 0 -8rpx 36rpx rgba(15, 23, 42, 0.12);
display: flex;
flex-direction: column;
padding-bottom: constant(safe-area-inset-bottom);
padding-bottom: env(safe-area-inset-bottom);
animation: reportModalSlideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
box-sizing: border-box;
}
.report-modal__handle-bar {
flex-shrink: 0;
width: 72rpx;
height: 8rpx;
background: #e2e8f0;
border-radius: 4rpx;
margin: 18rpx auto 8rpx;
}
.report-modal__header {
flex-shrink: 0;
display: flex;
align-items: flex-start;
justify-content: space-between;
padding: 16rpx 32rpx 14rpx;
}
.report-modal__title-group {
flex: 1;
min-width: 0;
margin-right: 20rpx;
}
.report-modal__title {
font-size: 34rpx;
font-weight: 700;
color: #1e293b;
line-height: 1.3;
display: block;
}
.report-modal__subtitle {
font-size: 24rpx;
color: #64748b;
margin-top: 6rpx;
display: block;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.report-modal__close-btn {
width: 56rpx;
height: 56rpx;
border-radius: 28rpx;
background: #f1f5f9;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
&:active {
background: #e2e8f0;
}
}
.report-modal__close-icon {
font-size: 26rpx;
color: #64748b;
line-height: 1;
}
.report-modal__notice {
margin: 0 32rpx 16rpx;
padding: 14rpx 20rpx;
background: #f2fef7;
border: 1rpx solid #bbf7d0;
border-radius: 14rpx;
}
.report-modal__notice-text {
font-size: 22rpx;
color: #00a854;
line-height: 1.45;
display: block;
}
.report-modal__scroll {
flex: 1;
min-height: 0;
max-height: 50vh;
padding: 0 32rpx;
box-sizing: border-box;
overflow-y: auto;
}
.report-modal__section {
margin-bottom: 28rpx;
}
.report-modal__section-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 14rpx;
}
.report-modal__section-title {
font-size: 28rpx;
font-weight: 600;
color: #1e293b;
}
.report-modal__section-required {
font-size: 22rpx;
color: #ef4444;
font-weight: 500;
}
.report-modal__section-counter,
.report-modal__section-sub {
font-size: 22rpx;
color: #94a3b8;
}
.report-modal__reasons-grid {
display: flex;
flex-wrap: wrap;
gap: 16rpx;
}
.report-modal__reason-tag {
position: relative;
padding: 14rpx 24rpx;
border-radius: 16rpx;
background: #f8fafc;
border: 1rpx solid #e2e8f0;
transition: all 0.2s ease;
display: inline-flex;
align-items: center;
justify-content: center;
&:active {
opacity: 0.85;
}
&--active {
background: #ecfdf5;
border-color: #00d26a;
box-shadow: 0 2rpx 10rpx rgba(0, 210, 106, 0.15);
.report-modal__reason-text {
color: #00a854;
font-weight: 600;
}
}
}
.report-modal__reason-text {
font-size: 26rpx;
color: #334155;
line-height: 1.3;
}
.report-modal__reason-badge {
position: absolute;
right: -4rpx;
bottom: -4rpx;
width: 24rpx;
height: 24rpx;
border-radius: 12rpx;
background: #00d26a;
display: flex;
align-items: center;
justify-content: center;
}
.report-modal__reason-check {
color: #ffffff;
font-size: 16rpx;
line-height: 1;
font-weight: 700;
}
.report-modal__textarea-wrap {
background: #f8fafc;
border: 1rpx solid #e2e8f0;
border-radius: 20rpx;
padding: 16rpx 20rpx;
box-sizing: border-box;
&:focus-within {
border-color: #00d26a;
background: #ffffff;
}
}
.report-modal__textarea {
width: 100%;
height: 150rpx;
font-size: 26rpx;
color: #1e293b;
line-height: 1.5;
box-sizing: border-box;
}
.report-modal__textarea-placeholder {
color: #94a3b8;
font-size: 24rpx;
}
.report-modal__images-grid {
display: flex;
flex-wrap: wrap;
gap: 16rpx;
}
.report-modal__img-item {
position: relative;
width: 150rpx;
height: 150rpx;
border-radius: 18rpx;
overflow: hidden;
background: #f1f5f9;
&--uploading {
display: flex;
align-items: center;
justify-content: center;
border: 1rpx dashed #00d26a;
background: #ecfdf5;
}
}
.report-modal__img-thumb {
width: 100%;
height: 100%;
}
.report-modal__img-del {
position: absolute;
top: 8rpx;
right: 8rpx;
width: 36rpx;
height: 36rpx;
border-radius: 18rpx;
background: rgba(15, 23, 42, 0.65);
display: flex;
align-items: center;
justify-content: center;
z-index: 2;
&:active {
background: rgba(239, 68, 68, 0.9);
}
}
.report-modal__img-del-icon {
color: #ffffff;
font-size: 20rpx;
line-height: 1;
}
.report-modal__img-loading-txt {
font-size: 22rpx;
color: #00a854;
}
.report-modal__img-uploader {
width: 150rpx;
height: 150rpx;
border-radius: 18rpx;
border: 2rpx dashed #cbd5e1;
background: #f8fafc;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 4rpx;
&:active {
background: #f1f5f9;
border-color: #00d26a;
}
}
.report-modal__img-uploader-plus {
font-size: 44rpx;
color: #94a3b8;
line-height: 1;
}
.report-modal__img-uploader-txt {
font-size: 20rpx;
color: #94a3b8;
}
.report-modal__footer {
flex-shrink: 0;
padding: 18rpx 32rpx 20rpx;
background: #ffffff;
border-top: 1rpx solid #f1f5f9;
}
.report-modal__submit-btn {
width: 100%;
height: 88rpx;
border-radius: 44rpx;
background: linear-gradient(135deg, #00e070 0%, #00d26a 100%);
color: #ffffff;
font-size: 30rpx;
font-weight: 600;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 8rpx 20rpx rgba(0, 210, 106, 0.28);
border: none;
&::after {
border: none;
}
&:active {
opacity: 0.9;
transform: scale(0.99);
}
&--disabled {
background: #cbd5e1 !important;
color: #ffffff !important;
box-shadow: none !important;
opacity: 0.7;
}
}
@keyframes reportModalFadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@keyframes reportModalSlideUp {
from {
transform: translateY(100%);
}
to {
transform: translateY(0);
}
}
</style>