提交
This commit is contained in:
@@ -239,18 +239,47 @@ export default {
|
||||
openAddDialog() { this.addDialogVisible = true; },
|
||||
resetAddForm() { this.addForm = { field: '', runNow: false }; this.addLoading = false; },
|
||||
async submitAddKeyword() {
|
||||
if (!this.addForm.field.trim()) return this.$message.warning(this.$t('crawlTask.enterKeyword'));
|
||||
const raw = String(this.addForm.field || '').trim();
|
||||
if (!raw) return this.$message.warning(this.$t('crawlTask.enterKeyword'));
|
||||
// 支持一次录入多个:按换行/逗号/分号拆分,去重
|
||||
const fields = raw
|
||||
.split(/[\r\n,,;;]+/g)
|
||||
.map((s) => s.trim())
|
||||
.filter(Boolean);
|
||||
const uniqFields = Array.from(new Set(fields));
|
||||
if (uniqFields.length === 0) return this.$message.warning(this.$t('crawlTask.enterKeyword'));
|
||||
this.addLoading = true;
|
||||
try {
|
||||
const res = await this.$api.post('api/expert_manage/addFetchField', { field: this.addForm.field });
|
||||
if (res.code === 0) {
|
||||
this.$message.success(this.$t('crawlTask.addKeywordSuccess'));
|
||||
if (this.addForm.runNow) {
|
||||
await this.$api.post('api/expert_finder/fetchOneField', { field: this.addForm.field });
|
||||
const ok = [];
|
||||
const fail = [];
|
||||
for (const field of uniqFields) {
|
||||
try {
|
||||
const res = await this.$api.post('api/expert_manage/addFetchField', { field });
|
||||
if (res && res.code === 0) {
|
||||
ok.push(field);
|
||||
if (this.addForm.runNow) {
|
||||
// 不阻塞整体添加:run once 失败也记录,不影响已添加成功
|
||||
try {
|
||||
await this.$api.post('api/expert_finder/fetchOneField', { field });
|
||||
} catch (e) {
|
||||
/* ignore */
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fail.push({ field, msg: (res && res.msg) || this.$t('crawlTask.operationFail') });
|
||||
}
|
||||
} catch (e) {
|
||||
fail.push({ field, msg: this.$t('crawlTask.operationFail') });
|
||||
}
|
||||
this.addDialogVisible = false;
|
||||
this.fetchList();
|
||||
}
|
||||
if (ok.length > 0) {
|
||||
this.$message.success(`${this.$t('crawlTask.addKeywordSuccess')} (${ok.length}/${uniqFields.length})`);
|
||||
}
|
||||
if (fail.length > 0) {
|
||||
this.$message.warning(`Failed: ${fail.map((x) => x.field).join(', ')}`);
|
||||
}
|
||||
this.addDialogVisible = false;
|
||||
this.fetchList();
|
||||
} finally { this.addLoading = false; }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user