自动化推广【约稿】
This commit is contained in:
@@ -9,7 +9,17 @@
|
||||
</div>
|
||||
<div class="right">
|
||||
<el-button size="mini" @click="goBack">{{ $t('mailboxMouldDetail.cancel') }}</el-button>
|
||||
<el-button type="primary" size="mini" icon="el-icon-document-checked" @click="handleSave">{{ $t('mailboxMouldDetail.save') }}</el-button>
|
||||
<el-button
|
||||
type="primary"
|
||||
size="mini"
|
||||
icon="el-icon-document-checked"
|
||||
@click="handleSave"
|
||||
:loading="saveLoading"
|
||||
:disabled="saveLoading || journalLoading"
|
||||
:loading-text="$t('mailboxMouldDetail.loading')"
|
||||
>
|
||||
{{ $t('mailboxMouldDetail.save') }}
|
||||
</el-button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
@@ -98,7 +108,7 @@
|
||||
import CkeditorMail from '@/components/page/components/email/CkeditorMail.vue';
|
||||
|
||||
const API = {
|
||||
getAllJournal: 'api/Journal/getAllJournal',
|
||||
getAllJournal: 'api/Article/getJournal',
|
||||
getTemplate: 'api/mail_template/getTemplate',
|
||||
saveTemplate: 'api/mail_template/saveTemplate'
|
||||
};
|
||||
@@ -110,6 +120,9 @@ export default {
|
||||
return {
|
||||
journalLoading: true,
|
||||
journalList: [],
|
||||
saveLoading: false,
|
||||
// 防抖:避免重复点击“保存”导致多次请求
|
||||
saveDebounceTimer: null,
|
||||
rules: {
|
||||
journalId: [{ required: true, message: this.$t('mailboxMouldDetail.rulesJournal'), trigger: 'change' }],
|
||||
scene: [{ required: true, message: this.$t('mailboxMouldDetail.rulesScene'), trigger: 'change' }],
|
||||
@@ -139,21 +152,31 @@ export default {
|
||||
created() {
|
||||
this.loadJournals();
|
||||
},
|
||||
beforeDestroy() {
|
||||
if (this.saveDebounceTimer) {
|
||||
clearTimeout(this.saveDebounceTimer);
|
||||
this.saveDebounceTimer = null;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
loadJournals() {
|
||||
this.journalLoading = true;
|
||||
const q = this.$route && this.$route.query ? this.$route.query : {};
|
||||
const fromRouteJournalId = q.journal_id || q.journalId || '';
|
||||
this.$api
|
||||
.post(API.getAllJournal, {})
|
||||
.post(API.getAllJournal, { username: localStorage.getItem('U_name') })
|
||||
.then(res => {
|
||||
const list = (res && res.data && res.data.journals) || res.data || [];
|
||||
const list = res || [];
|
||||
const mapped = (Array.isArray(list) ? list : []).map(j => ({
|
||||
journal_id: j.journal_id || j.id,
|
||||
title: j.title || j.name || ''
|
||||
}));
|
||||
this.journalList = mapped;
|
||||
if (!this.form.journalId && mapped.length > 0) {
|
||||
this.form.journalId = String(mapped[0].journal_id);
|
||||
if (fromRouteJournalId) {
|
||||
const has = mapped.some(j => String(j.journal_id) === String(fromRouteJournalId));
|
||||
if (has) this.form.journalId = String(fromRouteJournalId);
|
||||
}
|
||||
if (!this.form.journalId && mapped.length > 0) this.form.journalId = String(mapped[0].journal_id);
|
||||
})
|
||||
.catch(() => {
|
||||
this.journalList = [];
|
||||
@@ -188,51 +211,81 @@ export default {
|
||||
});
|
||||
},
|
||||
goBack() {
|
||||
const q = (this.$route && this.$route.query) || {};
|
||||
if (q.from_auto_promotion === '1') {
|
||||
this.$router.push({ path: '/autoPromotion' });
|
||||
return;
|
||||
}
|
||||
this.$router.push({ path: '/mailboxMould' });
|
||||
},
|
||||
handleSave() {
|
||||
const formRef = this.$refs.detailForm;
|
||||
const validatePromise = formRef && formRef.validate ? new Promise(resolve => formRef.validate(ok => resolve(ok))) : Promise.resolve(true);
|
||||
validatePromise.then(ok => {
|
||||
if (!ok) return;
|
||||
if (!this.form.subject) {
|
||||
this.$message.warning(this.$t('mailboxMouldDetail.rulesSubject'));
|
||||
return;
|
||||
}
|
||||
if (!this.form.body) {
|
||||
this.$message.warning(this.$t('mailboxMouldDetail.rulesBody'));
|
||||
return;
|
||||
}
|
||||
// 若已在保存中,直接忽略重复点击
|
||||
if (this.saveLoading) return;
|
||||
|
||||
const q = this.$route.query;
|
||||
const templateId = q.template_id || q.id || '';
|
||||
const bodyHtml = this.form.body || '';
|
||||
const bodyText = bodyHtml.replace(/<[^>]+>/g, ' ').replace(/\s+/g, ' ').trim();
|
||||
const params = {
|
||||
journal_id: String(this.form.journalId || ''),
|
||||
scene: String(this.form.scene || 'invite_submission'),
|
||||
language: String(this.form.lang || 'en'),
|
||||
title: String(this.form.title || ''),
|
||||
subject: String(this.form.subject || ''),
|
||||
body_html: bodyHtml,
|
||||
body_text: bodyText || '',
|
||||
variables_json: String(this.form.variables || ''),
|
||||
version: String(this.form.version || '1.0.0'),
|
||||
is_active: this.form.is_active === 1 ? '1' : '0'
|
||||
};
|
||||
if (templateId) params.template_id = String(templateId);
|
||||
this.$api.post(API.saveTemplate, params).then(res => {
|
||||
// 防抖:连续点击只触发最后一次
|
||||
if (this.saveDebounceTimer) {
|
||||
clearTimeout(this.saveDebounceTimer);
|
||||
}
|
||||
|
||||
this.saveDebounceTimer = setTimeout(() => {
|
||||
this.saveDebounceTimer = null;
|
||||
this._doSave();
|
||||
}, 600);
|
||||
}
|
||||
,
|
||||
async _doSave() {
|
||||
const formRef = this.$refs.detailForm;
|
||||
const validatePromise =
|
||||
formRef && formRef.validate
|
||||
? new Promise(resolve => formRef.validate(ok => resolve(ok)))
|
||||
: Promise.resolve(true);
|
||||
|
||||
const ok = await validatePromise;
|
||||
if (!ok) return;
|
||||
|
||||
if (!this.form.subject) {
|
||||
this.$message.warning(this.$t('mailboxMouldDetail.rulesSubject'));
|
||||
return;
|
||||
}
|
||||
if (!this.form.body) {
|
||||
this.$message.warning(this.$t('mailboxMouldDetail.rulesBody'));
|
||||
return;
|
||||
}
|
||||
|
||||
this.saveLoading = true;
|
||||
try {
|
||||
const q = this.$route.query;
|
||||
const templateId = q.template_id || q.id || '';
|
||||
const bodyHtml = this.form.body || '';
|
||||
const bodyText = bodyHtml.replace(/<[^>]+>/g, ' ').replace(/\s+/g, ' ').trim();
|
||||
|
||||
const params = {
|
||||
journal_id: String(this.form.journalId || ''),
|
||||
scene: String(this.form.scene || 'invite_submission'),
|
||||
language: String(this.form.lang || 'en'),
|
||||
title: String(this.form.title || ''),
|
||||
subject: String(this.form.subject || ''),
|
||||
body_html: bodyHtml,
|
||||
body_text: bodyText || '',
|
||||
variables_json: String(this.form.variables || ''),
|
||||
version: String(this.form.version || '1.0.0'),
|
||||
is_active: this.form.is_active === 1 ? '1' : '0'
|
||||
};
|
||||
|
||||
if (templateId) params.template_id = String(templateId);
|
||||
|
||||
const res = await this.$api.post(API.saveTemplate, params);
|
||||
if (res && res.code === 0) {
|
||||
this.$message.success(this.$t('mailboxMouldDetail.saveSuccess'));
|
||||
this.goBack();
|
||||
} else {
|
||||
this.$message.error((res && res.msg) || this.$t('mailboxMouldDetail.saveFail'));
|
||||
}
|
||||
}).catch(() => {
|
||||
} catch (e) {
|
||||
this.$message.error(this.$t('mailboxMouldDetail.saveFail'));
|
||||
});
|
||||
|
||||
});
|
||||
} finally {
|
||||
this.saveLoading = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user