关键字管理
This commit is contained in:
@@ -40,6 +40,10 @@
|
||||
mode="inline"
|
||||
:config="config"
|
||||
:wizardStartDate.sync="wizardStartDate"
|
||||
:selectedFieldIds.sync="selectedFieldIds"
|
||||
:availableFields="availableFields"
|
||||
:fieldsLoading="fieldsLoading"
|
||||
:fieldsSaving="fieldsSaving"
|
||||
:currentJournalName="currentJournalName"
|
||||
:selectedTemplateThumbHtml="selectedTemplateThumbHtml"
|
||||
:selectedTemplateName="selectedTemplateName"
|
||||
@@ -47,6 +51,7 @@
|
||||
:saving="saving"
|
||||
:title="$t('autoPromotion.title')"
|
||||
@open-template-selector="showTemplateDialog = true"
|
||||
@confirm-fields="savePromotionFieldsNow"
|
||||
@confirm="completeInitialization"
|
||||
/>
|
||||
</el-card>
|
||||
@@ -204,6 +209,10 @@
|
||||
:visible.sync="showWizardDialog"
|
||||
:config="config"
|
||||
:wizardStartDate.sync="wizardStartDate"
|
||||
:selectedFieldIds.sync="selectedFieldIds"
|
||||
:availableFields="availableFields"
|
||||
:fieldsLoading="fieldsLoading"
|
||||
:fieldsSaving="fieldsSaving"
|
||||
:currentJournalName="currentJournalName"
|
||||
:selectedTemplateThumbHtml="selectedTemplateThumbHtml"
|
||||
:selectedTemplateName="selectedTemplateName"
|
||||
@@ -211,6 +220,7 @@
|
||||
:saving="saving"
|
||||
:title="$t('autoPromotion.title')"
|
||||
@open-template-selector="showTemplateDialog = true"
|
||||
@confirm-fields="savePromotionFieldsNow"
|
||||
@cancel="showWizardDialog = false"
|
||||
@confirm="completeInitialization"
|
||||
/>
|
||||
@@ -328,6 +338,10 @@ export default {
|
||||
templateDialogInitialStyleId: '',
|
||||
templateDialogInitialTemplateId: '',
|
||||
togglingTaskId: '',
|
||||
selectedFieldIds: [],
|
||||
availableFields: [],
|
||||
fieldsLoading: false,
|
||||
fieldsSaving: false,
|
||||
previewForm: {
|
||||
id: '',
|
||||
email: '',
|
||||
@@ -453,6 +467,9 @@ export default {
|
||||
this.loading = true;
|
||||
try {
|
||||
await this.fetchJournalDetail();
|
||||
if (this.selectedJournalId) {
|
||||
this.loadPromotionFields(this.selectedJournalId);
|
||||
}
|
||||
if (this.config.initialized) {
|
||||
await this.fetchTemplates();
|
||||
await this.fetchList();
|
||||
@@ -524,13 +541,74 @@ export default {
|
||||
},
|
||||
|
||||
// 打开向导弹窗:用于“修改期刊自动推广配置”
|
||||
openWizardDialog() {
|
||||
this.showWizardDialog = true;
|
||||
findArray(obj) {
|
||||
if (Array.isArray(obj)) return obj;
|
||||
if (!obj || typeof obj !== 'object') return null;
|
||||
const keys = ['list', 'fields', 'rows', 'items', 'data', 'result'];
|
||||
for (const k of keys) {
|
||||
if (Array.isArray(obj[k])) return obj[k];
|
||||
}
|
||||
const values = Object.values(obj);
|
||||
if (values.length && Array.isArray(values[0])) return values[0];
|
||||
return null;
|
||||
},
|
||||
async loadPromotionFields(journalId) {
|
||||
this.fieldsLoading = true;
|
||||
this.availableFields = [];
|
||||
this.selectedFieldIds = [];
|
||||
try {
|
||||
const availableRes = await this.$api.post('api/email_client/getAvailableFields', { journal_id: String(journalId) });
|
||||
const availablePayload = (availableRes && availableRes.data) || availableRes || {};
|
||||
let availableArr = this.findArray(availablePayload);
|
||||
if (!availableArr) availableArr = Array.isArray(availablePayload) ? availablePayload : [];
|
||||
this.availableFields = availableArr.map((item, idx) => {
|
||||
const id = item.expert_fetch_id || item.fetch_id || item.id || item.field_id || (idx + 1);
|
||||
const label = item.field || item.title || item.name || item.label || String(id);
|
||||
return { id: String(id), label };
|
||||
});
|
||||
} catch (e) {
|
||||
this.availableFields = [];
|
||||
}
|
||||
try {
|
||||
const selectedRes = await this.$api.post('api/email_client/getJournalPromotionFields', { journal_id: String(journalId) });
|
||||
const selectedPayload = (selectedRes && selectedRes.data) || selectedRes || {};
|
||||
let selectedArr = this.findArray(selectedPayload);
|
||||
if (selectedArr) {
|
||||
this.selectedFieldIds = selectedArr.map((it) => String(it.expert_fetch_id || it.fetch_id || it.id || it.field_id || it));
|
||||
} else if (typeof selectedPayload === 'string') {
|
||||
this.selectedFieldIds = selectedPayload.split(',').map((s) => s.trim()).filter(Boolean);
|
||||
} else if (typeof selectedPayload.fetch_ids === 'string') {
|
||||
this.selectedFieldIds = selectedPayload.fetch_ids.split(',').map((s) => s.trim()).filter(Boolean);
|
||||
}
|
||||
} catch (e) {
|
||||
this.selectedFieldIds = [];
|
||||
}
|
||||
this.fieldsLoading = false;
|
||||
},
|
||||
async savePromotionFieldsNow() {
|
||||
if (!this.selectedJournalId) return;
|
||||
this.fieldsSaving = true;
|
||||
try {
|
||||
await this.$api.post('api/email_client/setJournalPromotionFields', {
|
||||
journal_id: String(this.selectedJournalId),
|
||||
fetch_ids: (this.selectedFieldIds || []).join(',')
|
||||
});
|
||||
this.$message.success(this.$t('autoPromotion.fieldsSaved'));
|
||||
} catch (e) {
|
||||
this.$message.error(this.$t('autoPromotion.saveFailed'));
|
||||
} finally {
|
||||
this.fieldsSaving = false;
|
||||
}
|
||||
},
|
||||
async openWizardDialog() {
|
||||
this.wizardStep = 0;
|
||||
// 尽量从已加载的 config 里取开始日期(没有就保持空)
|
||||
if (this.config && this.config.start_date) {
|
||||
this.wizardStartDate = this.config.start_date;
|
||||
}
|
||||
if (this.selectedJournalId) {
|
||||
await this.loadPromotionFields(this.selectedJournalId);
|
||||
}
|
||||
this.showWizardDialog = true;
|
||||
},
|
||||
|
||||
// 切换期刊逻辑
|
||||
@@ -622,10 +700,14 @@ export default {
|
||||
default_style_id: String(this.config.defaultStyleId || ''),
|
||||
start_promotion: this.config.enabled ? '1' : '0'
|
||||
};
|
||||
this.config.initialized = true; // 切换到管理模式
|
||||
this.config.initialized = true;
|
||||
this.showWizardDialog = false;
|
||||
this.fetchList();
|
||||
await this.$api.post(API.saveConfig, payload);
|
||||
await this.$api.post('api/email_client/setJournalPromotionFields', {
|
||||
journal_id: String(this.selectedJournalId || ''),
|
||||
fetch_ids: (this.selectedFieldIds || []).join(',')
|
||||
});
|
||||
this.$message.success(this.$t('autoPromotionLogs.configUpdated'));
|
||||
} finally {
|
||||
this.saving = false;
|
||||
|
||||
Reference in New Issue
Block a user