feat: 批量检测支持上传TXT文件
- 新增文件选择功能,支持TXT格式 - 自动读取文件内容并逐行拆解 - 显示已选文件名和文本条数 - 保留手动输入方式作为备选 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,8 @@ const { request } = require('../../utils/request')
|
|||||||
Page({
|
Page({
|
||||||
data: {
|
data: {
|
||||||
inputText: '',
|
inputText: '',
|
||||||
|
fileName: '',
|
||||||
|
lineCount: 0,
|
||||||
loading: false,
|
loading: false,
|
||||||
summary: null,
|
summary: null,
|
||||||
items: []
|
items: []
|
||||||
@@ -24,6 +26,43 @@ Page({
|
|||||||
.filter((line) => line.length >= 2)
|
.filter((line) => line.length >= 2)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
chooseFile() {
|
||||||
|
wx.chooseMessageFile({
|
||||||
|
count: 1,
|
||||||
|
type: 'file',
|
||||||
|
extension: ['txt'],
|
||||||
|
success: (res) => {
|
||||||
|
const file = res.tempFiles[0]
|
||||||
|
const fs = wx.getFileSystemManager()
|
||||||
|
|
||||||
|
try {
|
||||||
|
const content = fs.readFileSync(file.path, 'utf8')
|
||||||
|
const lines = content
|
||||||
|
.split('\n')
|
||||||
|
.map((line) => line.trim())
|
||||||
|
.filter((line) => line.length >= 2)
|
||||||
|
|
||||||
|
this.setData({
|
||||||
|
inputText: lines.join('\n'),
|
||||||
|
fileName: file.name,
|
||||||
|
lineCount: lines.length
|
||||||
|
})
|
||||||
|
|
||||||
|
wx.showToast({ title: `已读取 ${lines.length} 条文本`, icon: 'success' })
|
||||||
|
} catch (err) {
|
||||||
|
console.error('读取文件失败', err)
|
||||||
|
wx.showToast({ title: '文件读取失败', icon: 'none' })
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fail: (err) => {
|
||||||
|
console.error('选择文件失败', err)
|
||||||
|
if (err.errMsg !== 'chooseMessageFile:fail cancel') {
|
||||||
|
wx.showToast({ title: '请选择TXT文件', icon: 'none' })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
async submit() {
|
async submit() {
|
||||||
if (this.data.loading) return
|
if (this.data.loading) return
|
||||||
const items = this.parseLines()
|
const items = this.parseLines()
|
||||||
|
|||||||
@@ -2,17 +2,37 @@
|
|||||||
<view class="hero fade-up">
|
<view class="hero fade-up">
|
||||||
<view class="hero-badge">BATCH SCAN</view>
|
<view class="hero-badge">BATCH SCAN</view>
|
||||||
<view class="hero-title">批量文本筛查</view>
|
<view class="hero-title">批量文本筛查</view>
|
||||||
<view class="hero-sub">每行一条文本,适用于活动文案、客服话术、私信模板的集中检测。</view>
|
<view class="hero-sub">上传TXT文件或手动输入,每行一条文本,系统自动逐行检测。</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="card fade-up fade-up-delay-1">
|
<view class="card fade-up fade-up-delay-1">
|
||||||
<view class="card-title">批量输入</view>
|
<view class="card-title">上传文件</view>
|
||||||
<view class="card-desc">请按“每行一条”粘贴文本内容,系统会自动跳过空行。</view>
|
<view class="card-desc">支持TXT文本文件,每行一条待检测内容。</view>
|
||||||
|
|
||||||
|
<view class="btn-row">
|
||||||
|
<button class="btn btn-primary" bindtap="chooseFile">选择TXT文件</button>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="field" wx:if="{{fileName}}">
|
||||||
|
<view class="row">
|
||||||
|
<text class="label">已选文件</text>
|
||||||
|
<text class="value">{{fileName}}</text>
|
||||||
|
</view>
|
||||||
|
<view class="row">
|
||||||
|
<text class="label">文本条数</text>
|
||||||
|
<text class="value">{{lineCount}} 条</text>
|
||||||
|
</view>
|
||||||
|
</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" />
|
<textarea class="textarea" placeholder="示例: 点击链接领取红包 今天下午三点开会" value="{{inputText}}" bindinput="onInput" />
|
||||||
|
|
||||||
<view class="btn-row">
|
<view class="btn-row">
|
||||||
<button class="btn btn-ghost" bindtap="fillDemo">填充示例</button>
|
<button class="btn btn-ghost" bindtap="fillDemo">填充示例</button>
|
||||||
<button class="btn btn-primary" loading="{{loading}}" bindtap="submit">开始识别</button>
|
<button class="btn btn-accent" loading="{{loading}}" bindtap="submit">开始识别</button>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
@@ -85,4 +105,4 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
Reference in New Issue
Block a user