From eaa5a2737044a329a871b09e309c6bf82e5e32d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=AD=A3=E8=88=AA?= <1915581435@qq.com> Date: Thu, 14 May 2026 16:21:39 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=A6=96=E9=A1=B5=E6=95=B4=E5=90=88?= =?UTF-8?q?=E5=8F=91=E5=B8=83=E4=BF=A1=E6=81=AF=E5=8A=9F=E8=83=BD=EF=BC=8C?= =?UTF-8?q?=E7=A7=BB=E9=99=A4=E6=A3=80=E6=B5=8B=E5=BC=95=E6=93=8E=E7=8A=B6?= =?UTF-8?q?=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将发布信息与检测反馈直接放在首页,加入快捷示例和批量识别入口 Co-Authored-By: Claude Opus 4.7 --- miniprogram/pages/home/index.js | 94 +++++++++++++++++++++++++------ miniprogram/pages/home/index.wxml | 80 ++++++++++++++++---------- 2 files changed, 128 insertions(+), 46 deletions(-) diff --git a/miniprogram/pages/home/index.js b/miniprogram/pages/home/index.js index 22585b2..38a19e6 100644 --- a/miniprogram/pages/home/index.js +++ b/miniprogram/pages/home/index.js @@ -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' }) diff --git a/miniprogram/pages/home/index.wxml b/miniprogram/pages/home/index.wxml index 95193db..08e0d87 100644 --- a/miniprogram/pages/home/index.wxml +++ b/miniprogram/pages/home/index.wxml @@ -3,45 +3,65 @@ CONTROL CENTER {{user ? ('欢迎,' + user.nickname) : '社区内容风控工作台'}} 发布内容将实时进入朴素贝叶斯识别流程,疑似垃圾信息自动拦截并支持申诉。 - - 版本 {{modelInfo.version || '未训练'}} - 阈值 {{thresholdText}} - 样本 {{modelInfo.sample_count || 0}} - - - 检测引擎状态 - - - 模型版本 - {{modelInfo.version || '未训练'}} + + 发布信息 + + + 内容文本 +