|
|
|
@ -478,32 +478,38 @@ export default { |
|
|
|
|
}).catch(err => { }) |
|
|
|
|
}, |
|
|
|
|
// 栏目名称判重 |
|
|
|
|
async queryNameRepeat () { |
|
|
|
|
const { columnName, fatherId, id } = this.form |
|
|
|
|
if (columnName && columnName !== this.originalName) { |
|
|
|
|
const data = { |
|
|
|
|
fatherId: typeof fatherId === 'object' ? (fatherId.length ? fatherId[0] : 0) : fatherId, |
|
|
|
|
siteId: this.site.id, |
|
|
|
|
columnName, |
|
|
|
|
} |
|
|
|
|
if (id) data.id = +id |
|
|
|
|
try { |
|
|
|
|
await this.$post(this.api.sameLevelJudgment, data) |
|
|
|
|
this.nameRepeat = false |
|
|
|
|
} catch (e) { |
|
|
|
|
this.nameRepeat = true |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
this.nameRepeat = false |
|
|
|
|
} |
|
|
|
|
return this.nameRepeat |
|
|
|
|
}, |
|
|
|
|
// 栏目名称输入回调 |
|
|
|
|
nameChange () { |
|
|
|
|
clearTimeout(this.nameTimer) |
|
|
|
|
this.nameTimer = setTimeout(() => { |
|
|
|
|
const { columnName, fatherId, id } = this.form |
|
|
|
|
if (columnName && columnName !== this.originalName) { |
|
|
|
|
const data = { |
|
|
|
|
fatherId: fatherId.length ? fatherId[0] : 0, |
|
|
|
|
siteId: this.site.id, |
|
|
|
|
columnName, |
|
|
|
|
} |
|
|
|
|
if (id) data.id = +id |
|
|
|
|
this.$post(this.api.sameLevelJudgment, data).then(res => { |
|
|
|
|
this.nameRepeat = false |
|
|
|
|
}).catch(res => { |
|
|
|
|
this.nameRepeat = true |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
|
this.nameRepeat = false |
|
|
|
|
} |
|
|
|
|
this.queryNameRepeat() |
|
|
|
|
}, 500) |
|
|
|
|
}, |
|
|
|
|
// 上级选择回调 |
|
|
|
|
fatherIdChange (val) { |
|
|
|
|
fatherIdChange () { |
|
|
|
|
const check = this.$refs.fatherId.getCheckedNodes() |
|
|
|
|
this.form.level = check.length ? check[0].level + 1 : 1 // 更改了父级后要重新获取当前栏目level |
|
|
|
|
this.nameChange() |
|
|
|
|
this.queryNameRepeat() |
|
|
|
|
}, |
|
|
|
|
// 图片裁剪上传事件 |
|
|
|
|
customUpload (data) { |
|
|
|
@ -614,11 +620,14 @@ export default { |
|
|
|
|
}).catch(err => { }) |
|
|
|
|
}, |
|
|
|
|
// 提交 |
|
|
|
|
submit (next) { |
|
|
|
|
async submit (next) { |
|
|
|
|
if (this.submiting) return false |
|
|
|
|
const { form } = this |
|
|
|
|
if (!form.columnName) return Util.errorMsg('请填写栏目名称') |
|
|
|
|
if (this.nameRepeat) return Util.errorMsg('同级下已存在重复栏目!') |
|
|
|
|
clearTimeout(this.nameTimer) |
|
|
|
|
const repeat = await this.queryNameRepeat() |
|
|
|
|
console.log("🚀 ~ submit ~ reepat:", repeat) |
|
|
|
|
if (repeat) return Util.errorMsg('同级下已存在重复栏目!') |
|
|
|
|
if (!form.pageSize) return Util.errorMsg('请填写分页条数') |
|
|
|
|
const { fatherId } = form |
|
|
|
|
if (typeof fatherId === 'object') form.fatherId = fatherId.length ? fatherId[fatherId.length - 1] : 0 // 选择了上级后结果会是数组,直接取最后一个id |
|
|
|
@ -637,28 +646,26 @@ export default { |
|
|
|
|
} |
|
|
|
|
if (form.typeId !== 2 && !form.listStyleId) return Util.errorMsg('请选择列表样式') |
|
|
|
|
this.submiting = true |
|
|
|
|
if (this.isEdit) { |
|
|
|
|
delete form.children |
|
|
|
|
form.editorId = this.userId |
|
|
|
|
this.$post(this.api.updateColumn, form).then(res => { |
|
|
|
|
try { |
|
|
|
|
if (this.isEdit) { |
|
|
|
|
delete form.children |
|
|
|
|
form.editorId = this.userId |
|
|
|
|
await this.$post(this.api.updateColumn, form) |
|
|
|
|
this.updateFile(form, form.id) |
|
|
|
|
// 长页模板有重新修改,则需要重新保存长页模板 |
|
|
|
|
if (form.typeId === 3 && this.originListStyle !== form.listStyleId) this.savePage(form.id) |
|
|
|
|
Util.successMsg("修改成功") |
|
|
|
|
next ? next() : this.$router.back() |
|
|
|
|
}).catch(err => { |
|
|
|
|
this.submiting = false |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
|
this.$post(this.api.saveColumn, form).then(({ data }) => { |
|
|
|
|
} else { |
|
|
|
|
const { data } = await this.$post(this.api.saveColumn, form) |
|
|
|
|
this.updateFile(form, data) |
|
|
|
|
// 栏目类型选择了长页栏目,才需要保存长页 |
|
|
|
|
form.typeId === 3 && this.savePage(data) |
|
|
|
|
Util.successMsg("创建成功") |
|
|
|
|
next ? next() : this.$router.back() |
|
|
|
|
}).catch(err => { |
|
|
|
|
this.submiting = false |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} catch (e) { |
|
|
|
|
this.submiting = false |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
// 保存长页模板 |
|
|
|
|