diff --git a/miniprogram/pages/batch/index.js b/miniprogram/pages/batch/index.js index a1b9c1c..dda7ece 100644 --- a/miniprogram/pages/batch/index.js +++ b/miniprogram/pages/batch/index.js @@ -3,6 +3,8 @@ const { request } = require('../../utils/request') Page({ data: { inputText: '', + fileName: '', + lineCount: 0, loading: false, summary: null, items: [] @@ -24,6 +26,43 @@ Page({ .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() { if (this.data.loading) return const items = this.parseLines() diff --git a/miniprogram/pages/batch/index.wxml b/miniprogram/pages/batch/index.wxml index 1193072..ba3f31e 100644 --- a/miniprogram/pages/batch/index.wxml +++ b/miniprogram/pages/batch/index.wxml @@ -2,17 +2,37 @@ BATCH SCAN 批量文本筛查 - 每行一条文本,适用于活动文案、客服话术、私信模板的集中检测。 + 上传TXT文件或手动输入,每行一条文本,系统自动逐行检测。 - 批量输入 - 请按“每行一条”粘贴文本内容,系统会自动跳过空行。 + 上传文件 + 支持TXT文本文件,每行一条待检测内容。 + + + + + + + + 已选文件 + {{fileName}} + + + 文本条数 + {{lineCount}} 条 + + + + + + 手动输入 + 或直接粘贴文本内容,每行一条。