1
This commit is contained in:
130
miniprogram/pages/history/index.js
Normal file
130
miniprogram/pages/history/index.js
Normal file
@@ -0,0 +1,130 @@
|
||||
const { request } = require('../../utils/request')
|
||||
|
||||
const STATUS_OPTIONS = [
|
||||
{ value: '', label: '全部状态' },
|
||||
{ value: 'published', label: '发布成功' },
|
||||
{ value: 'blocked', label: '已拦截' }
|
||||
]
|
||||
|
||||
const VISIBILITY_OPTIONS = [
|
||||
{ value: '', label: '全部类型' },
|
||||
{ value: 'public', label: '公开' },
|
||||
{ value: 'private', label: '私有' },
|
||||
{ value: 'direct', label: '私信' }
|
||||
]
|
||||
|
||||
const VIS_LABEL = {
|
||||
public: '公开信息',
|
||||
private: '私有信息',
|
||||
direct: '用户私信'
|
||||
}
|
||||
|
||||
const APPEAL_STATUS_TEXT = {
|
||||
none: '未发起',
|
||||
pending: '处理中',
|
||||
approved: '已通过',
|
||||
rejected: '已驳回'
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
loading: false,
|
||||
list: [],
|
||||
statusOptions: STATUS_OPTIONS,
|
||||
statusIndex: 0,
|
||||
visibilityOptions: VISIBILITY_OPTIONS,
|
||||
visibilityIndex: 0,
|
||||
appealPostId: null,
|
||||
appealReason: ''
|
||||
},
|
||||
|
||||
formatPercent(value, digits = 2) {
|
||||
const num = Number(value || 0)
|
||||
return `${(num * 100).toFixed(digits)}%`
|
||||
},
|
||||
|
||||
onShow() {
|
||||
this.fetchList()
|
||||
},
|
||||
|
||||
onPullDownRefresh() {
|
||||
this.fetchList(true)
|
||||
},
|
||||
|
||||
onStatusChange(e) {
|
||||
this.setData({ statusIndex: Number(e.detail.value || 0) })
|
||||
this.fetchList()
|
||||
},
|
||||
|
||||
onVisibilityChange(e) {
|
||||
this.setData({ visibilityIndex: Number(e.detail.value || 0) })
|
||||
this.fetchList()
|
||||
},
|
||||
|
||||
async fetchList(fromPullDown = false) {
|
||||
this.setData({ loading: true })
|
||||
try {
|
||||
const status = this.data.statusOptions[this.data.statusIndex].value
|
||||
const visibility = this.data.visibilityOptions[this.data.visibilityIndex].value
|
||||
const query = `status=${encodeURIComponent(status)}&visibility=${encodeURIComponent(visibility)}&page=1&page_size=80`
|
||||
const data = await request({ url: `/content/posts/history?${query}` })
|
||||
const list = (data.items || []).map((item) => ({
|
||||
...item,
|
||||
created_text: (item.created_at || '').replace('T', ' ').slice(0, 19),
|
||||
spam_probability_text: this.formatPercent(item.spam_probability, 2),
|
||||
visibility_text: VIS_LABEL[item.visibility] || item.visibility,
|
||||
appeal_status_text: APPEAL_STATUS_TEXT[item.appeal_status] || item.appeal_status
|
||||
}))
|
||||
this.setData({ list })
|
||||
} finally {
|
||||
this.setData({ loading: false })
|
||||
if (fromPullDown) wx.stopPullDownRefresh()
|
||||
}
|
||||
},
|
||||
|
||||
startAppeal(e) {
|
||||
const postId = Number(e.currentTarget.dataset.id)
|
||||
this.setData({ appealPostId: postId, appealReason: '' })
|
||||
},
|
||||
|
||||
onAppealInput(e) {
|
||||
this.setData({ appealReason: e.detail.value || '' })
|
||||
},
|
||||
|
||||
cancelAppeal() {
|
||||
this.setData({ appealPostId: null, appealReason: '' })
|
||||
},
|
||||
|
||||
async submitAppeal() {
|
||||
const postId = this.data.appealPostId
|
||||
if (!postId) return
|
||||
const reason = (this.data.appealReason || '').trim()
|
||||
if (reason.length < 2) {
|
||||
wx.showToast({ title: '申诉理由至少 2 个字符', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
await request({
|
||||
url: `/content/posts/${postId}/appeal`,
|
||||
method: 'POST',
|
||||
data: { reason }
|
||||
})
|
||||
wx.showToast({ title: '申诉提交成功', icon: 'success' })
|
||||
this.setData({ appealPostId: null, appealReason: '' })
|
||||
this.fetchList()
|
||||
},
|
||||
|
||||
removeItem(e) {
|
||||
const id = Number(e.currentTarget.dataset.id)
|
||||
wx.showModal({
|
||||
title: '删除确认',
|
||||
content: '确定删除这条发布记录吗?',
|
||||
success: async (res) => {
|
||||
if (!res.confirm) return
|
||||
await request({ url: `/content/posts/${id}`, method: 'DELETE' })
|
||||
wx.showToast({ title: '删除成功', icon: 'success' })
|
||||
this.fetchList()
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
4
miniprogram/pages/history/index.json
Normal file
4
miniprogram/pages/history/index.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"navigationBarTitleText": "发布历史",
|
||||
"enablePullDownRefresh": true
|
||||
}
|
||||
78
miniprogram/pages/history/index.wxml
Normal file
78
miniprogram/pages/history/index.wxml
Normal file
@@ -0,0 +1,78 @@
|
||||
<view class="container">
|
||||
<view class="hero fade-up">
|
||||
<view class="hero-badge">PUBLISH HISTORY</view>
|
||||
<view class="hero-title">个人发布历史</view>
|
||||
<view class="hero-sub">查看公开/私有/私信发布结果,被拦截内容可在线提交申诉。</view>
|
||||
</view>
|
||||
|
||||
<view class="card fade-up fade-up-delay-1">
|
||||
<view class="card-title">筛选条件</view>
|
||||
|
||||
<view class="row">
|
||||
<text class="label">发布状态</text>
|
||||
<picker mode="selector" range="{{statusOptions}}" range-key="label" value="{{statusIndex}}" bindchange="onStatusChange">
|
||||
<view class="picker-value">{{statusOptions[statusIndex].label}}</view>
|
||||
</picker>
|
||||
</view>
|
||||
|
||||
<view class="row">
|
||||
<text class="label">发布类型</text>
|
||||
<picker mode="selector" range="{{visibilityOptions}}" range-key="label" value="{{visibilityIndex}}" bindchange="onVisibilityChange">
|
||||
<view class="picker-value">{{visibilityOptions[visibilityIndex].label}}</view>
|
||||
</picker>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="card fade-up fade-up-delay-2" wx:if="{{list.length}}">
|
||||
<view class="card-title">历史记录</view>
|
||||
|
||||
<view class="list-item" wx:for="{{list}}" wx:key="id">
|
||||
<view class="item-title">{{item.text}}</view>
|
||||
<view class="item-sub">类型:{{item.visibility_text}} · 时间:{{item.created_text}}</view>
|
||||
|
||||
<view class="row">
|
||||
<text class="label">发布状态</text>
|
||||
<text class="{{item.status === 'blocked' ? 'status-spam' : 'status-ham'}}">{{item.status === 'blocked' ? '已拦截' : '已发布'}}</text>
|
||||
</view>
|
||||
|
||||
<view class="row">
|
||||
<text class="label">垃圾概率</text>
|
||||
<text class="value">{{item.spam_probability_text}}</text>
|
||||
</view>
|
||||
|
||||
<view class="progress-track">
|
||||
<view class="progress-fill" style="width: {{item.spam_probability_text}};"></view>
|
||||
</view>
|
||||
|
||||
<view class="row">
|
||||
<text class="label">申诉状态</text>
|
||||
<text class="value">{{item.appeal_status_text}}</text>
|
||||
</view>
|
||||
|
||||
<view class="field" wx:if="{{item.reason_tokens && item.reason_tokens.length}}">
|
||||
<text class="field-label">风险关键词</text>
|
||||
<view class="chip-group">
|
||||
<text class="tag" wx:for="{{item.reason_tokens}}" wx:key="*this">{{item}}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{item.status === 'blocked' && item.appeal_status !== 'pending' && appealPostId !== item.id}}">
|
||||
<button class="btn btn-accent" data-id="{{item.id}}" bindtap="startAppeal">发起申诉</button>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{appealPostId === item.id}}">
|
||||
<textarea class="textarea" placeholder="请输入申诉理由(至少 2 个字符)" value="{{appealReason}}" bindinput="onAppealInput" />
|
||||
<view class="btn-row">
|
||||
<button class="btn btn-primary" bindtap="submitAppeal">提交申诉</button>
|
||||
<button class="btn btn-ghost" bindtap="cancelAppeal">取消</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<button class="btn btn-ghost" data-id="{{item.id}}" bindtap="removeItem">删除记录</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="card fade-up fade-up-delay-2" wx:if="{{!list.length}}">
|
||||
<view class="empty">暂无发布记录,先去“信息发布”页面提交文本。</view>
|
||||
</view>
|
||||
</view>
|
||||
1
miniprogram/pages/history/index.wxss
Normal file
1
miniprogram/pages/history/index.wxss
Normal file
@@ -0,0 +1 @@
|
||||
/* history styles use global theme */
|
||||
Reference in New Issue
Block a user