关键字管理
This commit is contained in:
@@ -98,6 +98,10 @@
|
||||
:visible.sync="showWizardDialog"
|
||||
:config="wizardConfig"
|
||||
:wizardStartDate.sync="wizardStartDate"
|
||||
:selectedFieldIds.sync="selectedFieldIds"
|
||||
:availableFields="availableFields"
|
||||
:fieldsLoading="fieldsLoading"
|
||||
:fieldsSaving="fieldsSaving"
|
||||
:currentJournalName="wizardJournal ? wizardJournal.title : ''"
|
||||
:selectedTemplateThumbHtml="selectedTemplateThumbHtml"
|
||||
:selectedTemplateName="selectedTemplateName"
|
||||
@@ -105,6 +109,7 @@
|
||||
:saving="saving"
|
||||
:title="`${$t('autoPromotion.journalManage')}: ${wizardJournal ? wizardJournal.title : ''}`"
|
||||
@open-template-selector="openTemplateSelector"
|
||||
@confirm-fields="savePromotionFieldsNow"
|
||||
@cancel="showWizardDialog = false"
|
||||
@confirm="saveWizardConfig"
|
||||
/>
|
||||
@@ -150,6 +155,10 @@ export default {
|
||||
selectedTemplateThumbHtml: '',
|
||||
selectedTemplateName: '',
|
||||
selectedStyleName: '',
|
||||
selectedFieldIds: [],
|
||||
availableFields: [],
|
||||
fieldsLoading: false,
|
||||
fieldsSaving: false,
|
||||
templateDialogInitialStyleId: '',
|
||||
templateDialogInitialTemplateId: '',
|
||||
templateNameMap: {},
|
||||
@@ -306,6 +315,81 @@ export default {
|
||||
? this.$t('autoPromotion.goManagePlan')
|
||||
: this.$t('autoPromotion.startPlan');
|
||||
},
|
||||
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) });
|
||||
console.log('[getAvailableFields] raw response:', JSON.stringify(availableRes));
|
||||
|
||||
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 };
|
||||
});
|
||||
console.log('[getAvailableFields] parsed fields:', this.availableFields.length, this.availableFields.slice(0, 3));
|
||||
} catch (e) {
|
||||
console.error('[getAvailableFields] error:', e);
|
||||
this.availableFields = [];
|
||||
}
|
||||
|
||||
try {
|
||||
const selectedRes = await this.$api.post('api/email_client/getJournalPromotionFields', { journal_id: String(journalId) });
|
||||
console.log('[getJournalPromotionFields] raw response:', JSON.stringify(selectedRes));
|
||||
|
||||
const selectedPayload = (selectedRes && selectedRes.data) || selectedRes || {};
|
||||
let selectedArr = this.findArray(selectedPayload);
|
||||
|
||||
if (selectedArr) {
|
||||
this.selectedFieldIds = selectedArr.map((it) => {
|
||||
return 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);
|
||||
}
|
||||
console.log('[getJournalPromotionFields] parsed selected:', this.selectedFieldIds);
|
||||
} catch (e) {
|
||||
console.error('[getJournalPromotionFields] error:', e);
|
||||
this.selectedFieldIds = [];
|
||||
}
|
||||
|
||||
this.fieldsLoading = false;
|
||||
},
|
||||
async savePromotionFieldsNow() {
|
||||
if (!this.wizardJournal || !this.wizardJournal.journal_id) return;
|
||||
this.fieldsSaving = true;
|
||||
try {
|
||||
await this.$api.post('api/email_client/setJournalPromotionFields', {
|
||||
journal_id: String(this.wizardJournal.journal_id),
|
||||
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 handleSolicitAction(journal) {
|
||||
if (!this.isSolicitConfigured(journal)) {
|
||||
@@ -344,7 +428,7 @@ export default {
|
||||
this.openDetail(journal);
|
||||
},
|
||||
|
||||
openWizardForJournal(journal) {
|
||||
async openWizardForJournal(journal) {
|
||||
this.wizardJournal = journal;
|
||||
const s = journal.solicit || {};
|
||||
this.wizardConfig = {
|
||||
@@ -355,6 +439,11 @@ export default {
|
||||
this.selectedTemplateName = s.templateName || '';
|
||||
this.selectedStyleName = s.styleName || '';
|
||||
this.selectedTemplateThumbHtml = `<div style="zoom:0.18; pointer-events:none; user-select:none;">${s.html || ''}</div>`;
|
||||
this.selectedFieldIds = [];
|
||||
this.availableFields = [];
|
||||
if (journal && journal.journal_id) {
|
||||
await this.loadPromotionFields(journal.journal_id);
|
||||
}
|
||||
this.showWizardDialog = true;
|
||||
},
|
||||
|
||||
@@ -387,6 +476,10 @@ export default {
|
||||
start_promotion: this.wizardConfig.enabled ? '1' : '0',
|
||||
user_id: userId
|
||||
});
|
||||
await this.$api.post('api/email_client/setJournalPromotionFields', {
|
||||
journal_id: String(this.wizardJournal.journal_id),
|
||||
fetch_ids: (this.selectedFieldIds || []).join(',')
|
||||
});
|
||||
await this.refreshJournalByDetail(this.wizardJournal);
|
||||
this.$message.success(this.$t('autoPromotion.configSaved'));
|
||||
this.showWizardDialog = false;
|
||||
|
||||
Reference in New Issue
Block a user