1
This commit is contained in:
102
miniprogram/pages/detect/index.js
Normal file
102
miniprogram/pages/detect/index.js
Normal file
@@ -0,0 +1,102 @@
|
||||
const { request } = require('../../utils/request')
|
||||
|
||||
const QUICK_TEXTS = [
|
||||
'大家好,今晚 8 点社区线上读书会,欢迎参加。',
|
||||
'恭喜中奖领取大额现金,点击链接立即到账。',
|
||||
'本周活动报名已开放,请在群里接龙。',
|
||||
'高薪兼职日结,扫码进群立刻赚钱。'
|
||||
]
|
||||
|
||||
const VISIBILITY_OPTIONS = [
|
||||
{ value: 'public', label: '公开信息发布' },
|
||||
{ value: 'private', label: '私有信息发布' },
|
||||
{ value: 'direct', label: '用户私信发布' }
|
||||
]
|
||||
|
||||
Page({
|
||||
data: {
|
||||
text: '',
|
||||
loading: false,
|
||||
result: null,
|
||||
quickTexts: QUICK_TEXTS,
|
||||
visibilityOptions: VISIBILITY_OPTIONS,
|
||||
visibilityIndex: 0,
|
||||
visibility: 'public',
|
||||
recipientUsername: ''
|
||||
},
|
||||
|
||||
formatPercent(value, digits = 2) {
|
||||
const num = Number(value || 0)
|
||||
return `${(num * 100).toFixed(digits)}%`
|
||||
},
|
||||
|
||||
onInput(e) {
|
||||
const field = e.currentTarget.dataset.field
|
||||
this.setData({ [field]: e.detail.value || '' })
|
||||
},
|
||||
|
||||
fillQuick(e) {
|
||||
this.setData({ text: e.currentTarget.dataset.text || '' })
|
||||
},
|
||||
|
||||
onVisibilityChange(e) {
|
||||
const idx = Number(e.detail.value)
|
||||
const row = this.data.visibilityOptions[idx] || this.data.visibilityOptions[0]
|
||||
this.setData({ visibilityIndex: idx, visibility: row.value })
|
||||
},
|
||||
|
||||
async publish() {
|
||||
if (this.data.loading) return
|
||||
const text = (this.data.text || '').trim()
|
||||
if (text.length < 2) {
|
||||
wx.showToast({ title: '请输入至少 2 个字符', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
const payload = {
|
||||
text,
|
||||
visibility: this.data.visibility
|
||||
}
|
||||
|
||||
if (this.data.visibility === 'direct') {
|
||||
const receiver = (this.data.recipientUsername || '').trim()
|
||||
if (!receiver) {
|
||||
wx.showToast({ title: '私信请填写接收人用户名', icon: 'none' })
|
||||
return
|
||||
}
|
||||
payload.recipient_username = receiver
|
||||
}
|
||||
|
||||
this.setData({ loading: true })
|
||||
try {
|
||||
const result = await request({
|
||||
url: '/content/publish',
|
||||
method: 'POST',
|
||||
data: payload
|
||||
})
|
||||
|
||||
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 })
|
||||
}
|
||||
},
|
||||
|
||||
gotoHistory() {
|
||||
wx.navigateTo({ url: '/pages/history/index' })
|
||||
}
|
||||
})
|
||||
3
miniprogram/pages/detect/index.json
Normal file
3
miniprogram/pages/detect/index.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"navigationBarTitleText": "文本发布"
|
||||
}
|
||||
84
miniprogram/pages/detect/index.wxml
Normal file
84
miniprogram/pages/detect/index.wxml
Normal file
@@ -0,0 +1,84 @@
|
||||
<view class="container">
|
||||
<view class="hero fade-up">
|
||||
<view class="hero-badge">REAL-TIME CHECK</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="field">
|
||||
<text class="field-label">内容文本</text>
|
||||
<textarea class="textarea" placeholder="请输入要发布的文本信息" value="{{text}}" data-field="text" bindinput="onInput" />
|
||||
<view class="field-help">当前字数:{{text.length}},建议不少于 2 个字符。</view>
|
||||
</view>
|
||||
|
||||
<view class="field">
|
||||
<view class="row">
|
||||
<text class="field-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="field" wx:if="{{visibility === 'direct'}}">
|
||||
<text class="field-label">接收人用户名</text>
|
||||
<input class="input" placeholder="私信发送时必填" value="{{recipientUsername}}" data-field="recipientUsername" bindinput="onInput" />
|
||||
</view>
|
||||
|
||||
<button class="btn btn-primary" loading="{{loading}}" bindtap="publish">提交发布</button>
|
||||
</view>
|
||||
|
||||
<view class="card fade-up fade-up-delay-2">
|
||||
<view class="card-title">快捷示例</view>
|
||||
<view class="chip-group">
|
||||
<view class="chip" wx:for="{{quickTexts}}" wx:key="*this" data-text="{{item}}" bindtap="fillQuick">{{item}}</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="card fade-up fade-up-delay-3" wx:if="{{result}}">
|
||||
<view class="card-title">识别反馈</view>
|
||||
|
||||
<view class="row">
|
||||
<text class="label">发布结果</text>
|
||||
<text class="{{result.publish_allowed ? 'status-ham' : 'status-spam'}}">{{result.publish_allowed ? '发布成功' : '已拦截,需申诉'}}</text>
|
||||
</view>
|
||||
|
||||
<view class="row">
|
||||
<text class="label">模型判断</text>
|
||||
<text class="value">{{result.detect.prediction_text}}</text>
|
||||
</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" wx:for="{{result.detect.reason_tokens}}" wx:key="*this">{{item}}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<button class="btn btn-ghost" bindtap="gotoHistory">查看发布历史</button>
|
||||
</view>
|
||||
</view>
|
||||
1
miniprogram/pages/detect/index.wxss
Normal file
1
miniprogram/pages/detect/index.wxss
Normal file
@@ -0,0 +1 @@
|
||||
/* detect styles use global theme */
|
||||
Reference in New Issue
Block a user