1
This commit is contained in:
70
miniprogram/pages/batch/index.js
Normal file
70
miniprogram/pages/batch/index.js
Normal file
@@ -0,0 +1,70 @@
|
||||
const { request } = require('../../utils/request')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
inputText: '',
|
||||
loading: false,
|
||||
summary: null,
|
||||
items: []
|
||||
},
|
||||
|
||||
formatPercent(value, digits = 2) {
|
||||
const num = Number(value || 0)
|
||||
return `${(num * 100).toFixed(digits)}%`
|
||||
},
|
||||
|
||||
onInput(e) {
|
||||
this.setData({ inputText: e.detail.value || '' })
|
||||
},
|
||||
|
||||
parseLines() {
|
||||
return (this.data.inputText || '')
|
||||
.split('\n')
|
||||
.map((line) => line.trim())
|
||||
.filter((line) => line.length >= 2)
|
||||
},
|
||||
|
||||
async submit() {
|
||||
if (this.data.loading) return
|
||||
const items = this.parseLines()
|
||||
if (!items.length) {
|
||||
wx.showToast({ title: '请至少输入一条有效文本', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
this.setData({ loading: true })
|
||||
try {
|
||||
const data = await request({
|
||||
url: '/spam/predict/batch',
|
||||
method: 'POST',
|
||||
data: { items }
|
||||
})
|
||||
|
||||
const summary = {
|
||||
...(data.summary || {}),
|
||||
spam_ratio_text: this.formatPercent((data.summary || {}).spam_ratio, 2),
|
||||
blocked_ratio_text: this.formatPercent((data.summary || {}).blocked_ratio, 2)
|
||||
}
|
||||
|
||||
const normalizedItems = (data.items || []).map((item) => ({
|
||||
...item,
|
||||
confidence_text: this.formatPercent(item.confidence, 2)
|
||||
}))
|
||||
|
||||
this.setData({ summary, items: normalizedItems })
|
||||
} finally {
|
||||
this.setData({ loading: false })
|
||||
}
|
||||
},
|
||||
|
||||
fillDemo() {
|
||||
this.setData({
|
||||
inputText: [
|
||||
'点击链接领取购物补贴,名额有限。',
|
||||
'明天下午三点上线前演练。',
|
||||
'高薪兼职日结,扫码进群。',
|
||||
'测试报告我已经同步到项目群。'
|
||||
].join('\n')
|
||||
})
|
||||
}
|
||||
})
|
||||
3
miniprogram/pages/batch/index.json
Normal file
3
miniprogram/pages/batch/index.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"navigationBarTitleText": "批量识别"
|
||||
}
|
||||
74
miniprogram/pages/batch/index.wxml
Normal file
74
miniprogram/pages/batch/index.wxml
Normal file
@@ -0,0 +1,74 @@
|
||||
<view class="container">
|
||||
<view class="hero fade-up">
|
||||
<view class="hero-badge">BATCH SCAN</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="card-desc">请按“每行一条”粘贴文本内容,系统会自动跳过空行。</view>
|
||||
<textarea class="textarea" placeholder="示例: 点击链接领取红包 今天下午三点开会" value="{{inputText}}" bindinput="onInput" />
|
||||
|
||||
<view class="btn-row">
|
||||
<button class="btn btn-ghost" bindtap="fillDemo">填充示例</button>
|
||||
<button class="btn btn-primary" loading="{{loading}}" bindtap="submit">开始识别</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="card fade-up fade-up-delay-2" wx:if="{{summary}}">
|
||||
<view class="card-title">识别汇总</view>
|
||||
<view class="grid-3">
|
||||
<view class="kpi">
|
||||
<view class="kpi-value">{{summary.total}}</view>
|
||||
<view class="kpi-label">总条数</view>
|
||||
</view>
|
||||
<view class="kpi">
|
||||
<view class="kpi-value">{{summary.spam_count}}</view>
|
||||
<view class="kpi-label">垃圾信息</view>
|
||||
</view>
|
||||
<view class="kpi">
|
||||
<view class="kpi-value">{{summary.ham_count}}</view>
|
||||
<view class="kpi-label">正常信息</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="field">
|
||||
<view class="row">
|
||||
<text class="label">垃圾占比</text>
|
||||
<text class="value">{{summary.spam_ratio_text}}</text>
|
||||
</view>
|
||||
<view class="progress-track">
|
||||
<view class="progress-fill" style="width: {{summary.spam_ratio_text}};"></view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="field">
|
||||
<view class="row">
|
||||
<text class="label">拦截占比</text>
|
||||
<text class="value">{{summary.blocked_ratio_text}}</text>
|
||||
</view>
|
||||
<view class="progress-track">
|
||||
<view class="progress-fill-safe" style="width: {{summary.blocked_ratio_text}};"></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="card fade-up fade-up-delay-3" wx:if="{{items.length}}">
|
||||
<view class="card-title">明细结果</view>
|
||||
<view class="list-item" wx:for="{{items}}" wx:key="index">
|
||||
<view class="item-title">{{item.text}}</view>
|
||||
<view class="row">
|
||||
<text class="label">判定结果</text>
|
||||
<text class="{{item.prediction === 'spam' ? 'status-spam' : 'status-ham'}}">{{item.prediction_text}}</text>
|
||||
</view>
|
||||
<view class="row">
|
||||
<text class="label">置信度</text>
|
||||
<text class="value">{{item.confidence_text}}</text>
|
||||
</view>
|
||||
<view class="progress-track">
|
||||
<view class="{{item.prediction === 'spam' ? 'progress-fill' : 'progress-fill-safe'}}" style="width: {{item.confidence_text}};"></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
1
miniprogram/pages/batch/index.wxss
Normal file
1
miniprogram/pages/batch/index.wxss
Normal file
@@ -0,0 +1 @@
|
||||
/* batch styles use global theme */
|
||||
Reference in New Issue
Block a user