feat: 首页整合发布信息功能,移除检测引擎状态
将发布信息与检测反馈直接放在首页,加入快捷示例和批量识别入口 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -1,17 +1,19 @@
|
||||
const { request } = require('../../utils/request')
|
||||
|
||||
const USER_MODULES = [
|
||||
{ name: '批量识别', desc: '多条文本批量检测并给出风险汇总', tag: '批量筛查', path: '/pages/batch/index' }
|
||||
const QUICK_TEXTS = [
|
||||
'大家好,今晚 8 点社区线上读书会,欢迎参加。',
|
||||
'恭喜中奖领取大额现金,点击链接立即到账。',
|
||||
'本周活动报名已开放,请在群里接龙。',
|
||||
'高薪兼职日结,扫码进群立刻赚钱。'
|
||||
]
|
||||
|
||||
Page({
|
||||
data: {
|
||||
loading: true,
|
||||
loading: false,
|
||||
user: null,
|
||||
modelInfo: null,
|
||||
threshold: null,
|
||||
thresholdText: '--',
|
||||
userModules: USER_MODULES
|
||||
text: '',
|
||||
result: null,
|
||||
quickTexts: QUICK_TEXTS
|
||||
},
|
||||
|
||||
onShow() {
|
||||
@@ -25,29 +27,89 @@ Page({
|
||||
return
|
||||
}
|
||||
|
||||
this.setData({ loading: true })
|
||||
try {
|
||||
const [user, modelInfo] = await Promise.all([
|
||||
request({ url: '/auth/me' }),
|
||||
request({ url: '/spam/model/info' })
|
||||
])
|
||||
|
||||
const user = await request({ url: '/auth/me' })
|
||||
app.globalData.user = user
|
||||
wx.setStorageSync('user', user)
|
||||
const threshold = modelInfo.threshold || null
|
||||
const thresholdText = threshold === null || threshold === undefined ? '--' : `${(Number(threshold) * 100).toFixed(1)}%`
|
||||
this.setData({ user, modelInfo, threshold, thresholdText })
|
||||
this.setData({ user })
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
},
|
||||
|
||||
formatPercent(value, digits = 2) {
|
||||
const num = Number(value || 0)
|
||||
return `${(num * 100).toFixed(digits)}%`
|
||||
},
|
||||
|
||||
onInput(e) {
|
||||
this.setData({ text: e.detail.value || '' })
|
||||
},
|
||||
|
||||
fillQuick(e) {
|
||||
this.setData({ text: e.currentTarget.dataset.text || '' })
|
||||
},
|
||||
|
||||
async publish() {
|
||||
if (this.data.loading) return
|
||||
const text = (this.data.text || '').trim()
|
||||
if (text.length < 2) {
|
||||
wx.showToast({ title: '请输入至少 2 个字符', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
this.setData({ loading: true })
|
||||
try {
|
||||
const result = await request({
|
||||
url: '/content/publish',
|
||||
method: 'POST',
|
||||
data: { text }
|
||||
})
|
||||
|
||||
this.setData({
|
||||
result: {
|
||||
...result,
|
||||
detect: {
|
||||
...(result.detect || {}),
|
||||
confidence_text: this.formatPercent((result.detect || {}).confidence, 2)
|
||||
},
|
||||
post_threshold_text: this.formatPercent((result.post || {}).threshold, 1),
|
||||
detect_spam_probability_text: this.formatPercent((result.detect || {}).spam_probability, 2)
|
||||
}
|
||||
})
|
||||
|
||||
wx.showToast({
|
||||
title: result.publish_allowed ? '发布成功' : '已拦截,可申诉',
|
||||
icon: result.publish_allowed ? 'success' : 'none'
|
||||
})
|
||||
} finally {
|
||||
this.setData({ loading: false })
|
||||
}
|
||||
},
|
||||
|
||||
goBatch() {
|
||||
wx.navigateTo({ url: '/pages/batch/index' })
|
||||
},
|
||||
|
||||
goto(e) {
|
||||
const path = e.currentTarget.dataset.path
|
||||
if (!path) return
|
||||
wx.navigateTo({ url: path })
|
||||
},
|
||||
|
||||
showTokenWeight(e) {
|
||||
const token = e.currentTarget.dataset.token
|
||||
const weight = e.currentTarget.dataset.weight
|
||||
const weightNum = Number(weight || 0)
|
||||
const direction = weightNum >= 0 ? '倾向垃圾判定' : '倾向正常判定'
|
||||
wx.showModal({
|
||||
title: '关键词权重',
|
||||
content: `关键词"${token}"\n权重贡献:${weightNum >= 0 ? '+' : ''}${weightNum.toFixed(4)}\n(${direction})`,
|
||||
showCancel: false,
|
||||
confirmText: '关闭'
|
||||
})
|
||||
},
|
||||
|
||||
logout() {
|
||||
getApp().clearAuth()
|
||||
wx.reLaunch({ url: '/pages/login/index' })
|
||||
|
||||
@@ -3,45 +3,65 @@
|
||||
<view class="hero-badge">CONTROL CENTER</view>
|
||||
<view class="hero-title">{{user ? ('欢迎,' + user.nickname) : '社区内容风控工作台'}}</view>
|
||||
<view class="hero-sub">发布内容将实时进入朴素贝叶斯识别流程,疑似垃圾信息自动拦截并支持申诉。</view>
|
||||
<view class="hero-meta" wx:if="{{modelInfo}}">
|
||||
<text class="hero-metric">版本 {{modelInfo.version || '未训练'}}</text>
|
||||
<text class="hero-metric">阈值 {{thresholdText}}</text>
|
||||
<text class="hero-metric">样本 {{modelInfo.sample_count || 0}}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="card fade-up fade-up-delay-1" wx:if="{{modelInfo}}">
|
||||
<view class="card-title">检测引擎状态</view>
|
||||
<view class="grid-2">
|
||||
<view class="kpi">
|
||||
<view class="kpi-label">模型版本</view>
|
||||
<view class="kpi-value">{{modelInfo.version || '未训练'}}</view>
|
||||
<view class="card fade-up fade-up-delay-1">
|
||||
<view class="card-title">发布信息</view>
|
||||
|
||||
<view class="field">
|
||||
<text class="field-label">内容文本</text>
|
||||
<textarea class="textarea" placeholder="请输入要发布的文本信息" value="{{text}}" bindinput="onInput" />
|
||||
<view class="field-help">当前字数:{{text.length}},建议不少于 2 个字符。</view>
|
||||
</view>
|
||||
|
||||
<view class="field" wx:if="{{result}}">
|
||||
<text class="field-label">识别反馈</text>
|
||||
<view class="row">
|
||||
<text class="label">发布结果</text>
|
||||
<text class="{{result.publish_allowed ? 'status-ham' : 'status-spam'}}">{{result.publish_allowed ? '发布成功' : '已拦截,需申诉'}}</text>
|
||||
</view>
|
||||
<view class="kpi">
|
||||
<view class="kpi-label">训练样本</view>
|
||||
<view class="kpi-value">{{modelInfo.sample_count || 0}}</view>
|
||||
<view class="row" wx:if="{{result.detect.category_label}}">
|
||||
<text class="label">分类标签</text>
|
||||
<text class="status-spam">{{result.detect.category_label}}</text>
|
||||
</view>
|
||||
<view class="kpi">
|
||||
<view class="kpi-label">垃圾阈值</view>
|
||||
<view class="kpi-value">{{thresholdText}}</view>
|
||||
<view class="row">
|
||||
<text class="label">模型判断</text>
|
||||
<text class="value">{{result.detect.prediction_text}}</text>
|
||||
</view>
|
||||
<view class="kpi">
|
||||
<view class="kpi-label">最近训练</view>
|
||||
<view class="kpi-value small">{{modelInfo.trained_at || '--'}}</view>
|
||||
<view class="row">
|
||||
<text class="label">垃圾概率</text>
|
||||
<text class="value">{{result.detect_spam_probability_text}}</text>
|
||||
</view>
|
||||
<view class="progress-track">
|
||||
<view class="progress-fill" style="width: {{result.detect_spam_probability_text}};"></view>
|
||||
</view>
|
||||
<view class="row">
|
||||
<text class="label">检测置信度</text>
|
||||
<text class="value">{{result.detect.confidence_text}}</text>
|
||||
</view>
|
||||
<view class="progress-track">
|
||||
<view class="progress-fill-safe" style="width: {{result.detect.confidence_text}};"></view>
|
||||
</view>
|
||||
<view class="row">
|
||||
<text class="label">本次阈值</text>
|
||||
<text class="value">{{result.post_threshold_text}}</text>
|
||||
</view>
|
||||
<view class="field" wx:if="{{result.detect.reason_tokens && result.detect.reason_tokens.length}}">
|
||||
<text class="field-label">风险关键词</text>
|
||||
<view class="chip-group">
|
||||
<text class="tag tag-danger" wx:for="{{result.detect.reason_tokens}}" wx:key="token" data-token="{{item.token}}" data-weight="{{item.weight}}" bindtap="showTokenWeight">{{item.token}}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="card fade-up fade-up-delay-2">
|
||||
<view class="card-title">更多功能</view>
|
||||
<view class="card-desc">批量检测与管理功能入口。</view>
|
||||
<view class="grid-2">
|
||||
<view class="module-card" wx:for="{{userModules}}" wx:key="name" data-path="{{item.path}}" bindtap="goto">
|
||||
<view class="module-name">{{item.name}}</view>
|
||||
<view class="module-desc">{{item.desc}}</view>
|
||||
<view class="module-tag">{{item.tag}}</view>
|
||||
<view class="field" wx:if="{{!result}}">
|
||||
<text class="field-label">快捷示例</text>
|
||||
<view class="chip-group">
|
||||
<view class="chip" wx:for="{{quickTexts}}" wx:key="*this" data-text="{{item}}" bindtap="fillQuick">{{item}}</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<button class="btn btn-primary" loading="{{loading}}" bindtap="publish">提交发布</button>
|
||||
<button class="btn btn-ghost" style="margin-top: 12rpx;" bindtap="goBatch">批量识别</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
Reference in New Issue
Block a user