Compare commits

...

5 Commits

Author SHA1 Message Date
刘正航
a0f7a758eb feat: 首页发布增加发布类型选择(公开/私有/私信)
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-14 21:20:57 +08:00
刘正航
b8acc8be43 feat: admin-web新增feedback工具和配置优化
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-14 21:15:27 +08:00
刘正航
829599bc17 1 2026-05-14 17:49:23 +08:00
刘正航
f3c0c44f27 feat: tabbar移除首页,发布tab指向合并后的首页
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-14 16:25:57 +08:00
刘正航
eaa5a27370 feat: 首页整合发布信息功能,移除检测引擎状态
将发布信息与检测反馈直接放在首页,加入快捷示例和批量识别入口

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-14 16:21:39 +08:00
15 changed files with 284 additions and 91 deletions

5
.gitignore vendored
View File

@@ -17,3 +17,8 @@ __pycache__/
# OS
.DS_Store
Thumbs.db
# Archives
*.zip
*.tar.gz
*.7z

View File

@@ -5,6 +5,23 @@ import './styles/theme.css'
Vue.config.productionTip = false
Vue.config.errorHandler = (err, vm, info) => {
console.error('[vue error]', info, err)
}
Vue.config.warnHandler = (msg, vm, trace) => {
console.warn('[vue warn]', msg, trace)
}
window.addEventListener('unhandledrejection', (event) => {
console.warn('[unhandled rejection]', event.reason)
event.preventDefault()
})
window.addEventListener('error', (event) => {
console.error('[window error]', event.error || event.message)
})
new Vue({
router,
render: (h) => h(App)

View File

@@ -57,3 +57,42 @@ export function previewImage(urls, current) {
if (!urls || !urls.length) return
ensurePreview().open({ urls, current })
}
export async function copyText(text) {
if (text === undefined || text === null) return false
const value = String(text)
if (navigator.clipboard && window.isSecureContext) {
try {
await navigator.clipboard.writeText(value)
return true
} catch (err) {
console.warn('[copyText] navigator.clipboard 不可用,回退到 execCommand', err)
}
}
try {
const textarea = document.createElement('textarea')
textarea.value = value
textarea.setAttribute('readonly', '')
textarea.style.position = 'fixed'
textarea.style.top = '0'
textarea.style.left = '0'
textarea.style.width = '1px'
textarea.style.height = '1px'
textarea.style.opacity = '0'
textarea.style.pointerEvents = 'none'
document.body.appendChild(textarea)
textarea.focus()
textarea.select()
textarea.setSelectionRange(0, value.length)
const ok = document.execCommand('copy')
document.body.removeChild(textarea)
return !!ok
} catch (err) {
console.error('[copyText] execCommand 也失败了', err)
return false
}
}

View File

@@ -1,6 +1,5 @@
import axios from 'axios'
import { getToken, clearAuth } from '@/utils/auth'
import { toast } from '@/utils/feedback'
const BASE_URL = '/api'
@@ -21,21 +20,21 @@ instance.interceptors.request.use(
(err) => Promise.reject(err)
)
function handleUnauthorized() {
function handleUnauthorized(url) {
console.warn('[auth] 登录已过期,自动退出登录', url || '')
clearAuth()
toast('登录已过期,请重新登录', 'error')
setTimeout(() => {
if (location.hash !== '#/login') {
location.hash = '#/login'
}
}, 400)
}, 200)
}
instance.interceptors.response.use(
(response) => response,
(err) => {
if (err && err.response && err.response.status === 401) {
handleUnauthorized()
handleUnauthorized(err.config && err.config.url)
}
return Promise.reject(err)
}
@@ -43,14 +42,7 @@ instance.interceptors.response.use(
export function request({ url, method = 'GET', data, params, headers, responseType } = {}) {
return new Promise((resolve, reject) => {
instance({
url,
method,
data,
params,
headers,
responseType
})
instance({ url, method, data, params, headers, responseType })
.then((res) => {
if (responseType === 'blob' || responseType === 'arraybuffer') {
resolve(res)
@@ -64,18 +56,16 @@ export function request({ url, method = 'GET', data, params, headers, responseTy
}
const message = body.message || '请求失败'
toast(message, 'error')
console.error('[request]', method, url, '业务失败:', message, body)
reject(new Error(message))
})
.catch((err) => {
if (err && err.response && err.response.status === 401) {
reject(err)
reject(new Error('Unauthorized'))
return
}
const msg = (err && err.message) || '网络异常'
if (!/Unauthorized/.test(msg)) {
toast(msg, 'error')
}
console.error('[request]', method, url, '请求异常:', msg, err)
reject(err)
})
})
@@ -98,12 +88,16 @@ export function uploadFile(file) {
return
}
const message = body.message || '上传失败'
toast(message, 'error')
console.error('[upload] 业务失败:', message, body)
reject(new Error(message))
})
.catch((err) => {
if (err && err.response && err.response.status === 401) {
reject(new Error('Unauthorized'))
return
}
const msg = (err && err.message) || '上传失败'
toast(msg, 'error')
console.error('[upload] 请求异常:', msg, err)
reject(err)
})
})

View File

@@ -136,7 +136,7 @@
<script>
import { request } from '@/utils/request'
import { toast, confirm } from '@/utils/feedback'
import { toast, confirm, copyText } from '@/utils/feedback'
export default {
name: 'BatchView',
@@ -176,7 +176,10 @@ export default {
this.lineCount = lines.length
toast(`已读取 ${lines.length} 条文本`, 'success')
}
reader.onerror = () => toast('文件读取失败', 'error')
reader.onerror = (e) => {
console.error('[batch] 文件读取失败', e)
toast('文件读取失败', 'error')
}
reader.readAsText(file, 'utf-8')
e.target.value = ''
},
@@ -267,6 +270,7 @@ export default {
}, 0)
toast('导出成功', 'success')
} catch (err) {
console.error('[batch] 导出失败', err)
toast('导出失败', 'error')
} finally {
this.exporting = false
@@ -278,10 +282,11 @@ export default {
return
}
const csv = this.generateCSV()
try {
await navigator.clipboard.writeText(csv)
const ok = await copyText(csv)
if (ok) {
toast('CSV 内容已复制到剪贴板', 'success')
} catch (err) {
} else {
console.error('[batch] 复制失败CSV 内容打印到控制台供手动复制\n' + csv)
toast('复制失败,请手动选择文本', 'error')
}
}

View File

@@ -168,6 +168,8 @@ export default {
detect_spam_probability_text: this.formatPercent((result.detect || {}).spam_probability, 2)
}
toast(result.publish_allowed ? '发布成功' : '已拦截,可申诉', result.publish_allowed ? 'success' : 'error')
} catch (err) {
console.error('[detect] 发布失败', err)
} finally {
this.loading = false
}

View File

@@ -118,11 +118,14 @@ export default {
async bootstrap() {
this.loading = true
try {
const [, modelInfo] = await Promise.all([
refreshUser(),
request({ url: '/spam/model/info' })
])
this.modelInfo = modelInfo
await refreshUser()
const modelInfo = await request({ url: '/spam/model/info' }).catch((err) => {
console.warn('[home] 模型信息加载失败', err)
return null
})
if (modelInfo) this.modelInfo = modelInfo
} catch (err) {
console.warn('[home] bootstrap 异常', err)
} finally {
this.loading = false
}

View File

@@ -147,7 +147,7 @@
<script>
import { request } from '@/utils/request'
import { toast } from '@/utils/feedback'
import { toast, copyText } from '@/utils/feedback'
export default {
name: 'AdminDashboard',
@@ -256,10 +256,12 @@ export default {
`【近 7 日趋势】`,
(report.spam_trend || []).slice(-7).map((t) => `${t.label}: 拦截${t.blocked}条,发布${t.published}`).join('\n')
]
try {
await navigator.clipboard.writeText(lines.join('\n'))
const content = lines.join('\n')
const ok = await copyText(content)
if (ok) {
toast('报告已复制到剪贴板', 'success')
} catch (err) {
} else {
console.error('[dashboard] 复制失败,报告内容打印到控制台供手动复制\n' + content)
toast('复制失败,请手动选择', 'error')
}
}

View File

@@ -161,6 +161,7 @@ export default {
try {
items = JSON.parse(this.importText)
} catch (err) {
console.error('[samples] JSON 格式错误', err)
toast('JSON 格式错误', 'error')
return
}

View File

@@ -179,6 +179,7 @@ export default {
try {
items = JSON.parse(this.importText)
} catch (err) {
console.error('[users] JSON 格式错误', err)
toast('JSON 格式错误', 'error')
return
}

View File

@@ -7,6 +7,10 @@ module.exports = defineConfig({
port: 8080,
host: '0.0.0.0',
historyApiFallback: true,
client: {
overlay: false,
logging: 'warn'
},
proxy: {
'/api': {
target: 'http://127.0.0.1:5000',

View File

@@ -2,7 +2,7 @@
"host": "127.0.0.1",
"port": 3306,
"user": "root",
"password": "123456",
"password": "rootroot",
"database": "spam_nb_miniapp",
"charset": "utf8mb4",
"admin_init": {

View File

@@ -1,7 +1,6 @@
{
"pages": [
"pages/home/index",
"pages/detect/index",
"pages/history/index",
"pages/inbox/index",
"pages/profile/index",
@@ -24,12 +23,6 @@
"list": [
{
"pagePath": "pages/home/index",
"text": "首页",
"iconPath": "assets/icons/home.png",
"selectedIconPath": "assets/icons/home-active.png"
},
{
"pagePath": "pages/detect/index",
"text": "发布",
"iconPath": "assets/icons/publish.png",
"selectedIconPath": "assets/icons/publish-active.png"

View File

@@ -1,17 +1,29 @@
const { request } = require('../../utils/request')
const USER_MODULES = [
{ name: '批量识别', desc: '多条文本批量检测并给出风险汇总', tag: '批量筛查', path: '/pages/batch/index' }
const QUICK_TEXTS = [
'大家好,今晚 8 点社区线上读书会,欢迎参加。',
'恭喜中奖领取大额现金,点击链接立即到账。',
'本周活动报名已开放,请在群里接龙。',
'高薪兼职日结,扫码进群立刻赚钱。'
]
const VISIBILITY_OPTIONS = [
{ value: 'public', label: '公开信息发布' },
{ value: 'private', label: '私有信息发布' },
{ value: 'direct', label: '用户私信发布' }
]
Page({
data: {
loading: true,
loading: false,
user: null,
modelInfo: null,
threshold: null,
thresholdText: '--',
userModules: USER_MODULES
text: '',
result: null,
quickTexts: QUICK_TEXTS,
visibilityOptions: VISIBILITY_OPTIONS,
visibilityIndex: 0,
visibility: 'public',
recipientUsername: ''
},
onShow() {
@@ -25,29 +37,110 @@ 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) {
const field = e.currentTarget.dataset.field || 'text'
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 })
}
},
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' })

View File

@@ -3,45 +3,79 @@
<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>
<view class="kpi">
<view class="kpi-label">训练样本</view>
<view class="kpi-value">{{modelInfo.sample_count || 0}}</view>
</view>
<view class="kpi">
<view class="kpi-label">垃圾阈值</view>
<view class="kpi-value">{{thresholdText}}</view>
</view>
<view class="kpi">
<view class="kpi-label">最近训练</view>
<view class="kpi-value small">{{modelInfo.trained_at || '--'}}</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>
<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="{{visibility === 'direct'}}">
<text class="field-label">接收人用户名</text>
<input class="input" placeholder="私信发送时必填" value="{{recipientUsername}}" data-field="recipientUsername" bindinput="onInput" />
</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="row" wx:if="{{result.detect.category_label}}">
<text class="label">分类标签</text>
<text class="status-spam">{{result.detect.category_label}}</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 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="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>
<button class="btn btn-primary" loading="{{loading}}" bindtap="publish">提交发布</button>
<button class="btn btn-ghost" style="margin-top: 12rpx;" bindtap="goBatch">批量识别</button>
</view>
</view>