栏目名称判重修复

master
yujialong 2 months ago
parent 6f4d5c8432
commit 738fe9c15a
  1. 71
      src/pages/column/add/index.vue
  2. 2
      src/pages/column/list/index.vue

@ -478,32 +478,38 @@ export default {
}).catch(err => { }) }).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 () { nameChange () {
clearTimeout(this.nameTimer) clearTimeout(this.nameTimer)
this.nameTimer = setTimeout(() => { this.nameTimer = setTimeout(() => {
const { columnName, fatherId, id } = this.form this.queryNameRepeat()
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
}
}, 500) }, 500)
}, },
// //
fatherIdChange (val) { fatherIdChange () {
const check = this.$refs.fatherId.getCheckedNodes() const check = this.$refs.fatherId.getCheckedNodes()
this.form.level = check.length ? check[0].level + 1 : 1 // level this.form.level = check.length ? check[0].level + 1 : 1 // level
this.nameChange() this.queryNameRepeat()
}, },
// //
customUpload (data) { customUpload (data) {
@ -614,11 +620,14 @@ export default {
}).catch(err => { }) }).catch(err => { })
}, },
// //
submit (next) { async submit (next) {
if (this.submiting) return false if (this.submiting) return false
const { form } = this const { form } = this
if (!form.columnName) return Util.errorMsg('请填写栏目名称') 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('请填写分页条数') if (!form.pageSize) return Util.errorMsg('请填写分页条数')
const { fatherId } = form const { fatherId } = form
if (typeof fatherId === 'object') form.fatherId = fatherId.length ? fatherId[fatherId.length - 1] : 0 // id 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('请选择列表样式') if (form.typeId !== 2 && !form.listStyleId) return Util.errorMsg('请选择列表样式')
this.submiting = true this.submiting = true
if (this.isEdit) { try {
delete form.children if (this.isEdit) {
form.editorId = this.userId delete form.children
this.$post(this.api.updateColumn, form).then(res => { form.editorId = this.userId
await this.$post(this.api.updateColumn, form)
this.updateFile(form, form.id) this.updateFile(form, form.id)
// //
if (form.typeId === 3 && this.originListStyle !== form.listStyleId) this.savePage(form.id) if (form.typeId === 3 && this.originListStyle !== form.listStyleId) this.savePage(form.id)
Util.successMsg("修改成功") Util.successMsg("修改成功")
next ? next() : this.$router.back() next ? next() : this.$router.back()
}).catch(err => { } else {
this.submiting = false const { data } = await this.$post(this.api.saveColumn, form)
})
} else {
this.$post(this.api.saveColumn, form).then(({ data }) => {
this.updateFile(form, data) this.updateFile(form, data)
// //
form.typeId === 3 && this.savePage(data) form.typeId === 3 && this.savePage(data)
Util.successMsg("创建成功") Util.successMsg("创建成功")
next ? next() : this.$router.back() next ? next() : this.$router.back()
}).catch(err => { }
this.submiting = false } catch (e) {
}) this.submiting = false
} }
}, },
// //

@ -345,7 +345,7 @@ export default {
this.select(this.list, this.checkedKeys) this.select(this.list, this.checkedKeys)
}, },
select (data, flag) { select (data, flag) {
data.map(row => { data && data.map(row => {
this.$refs.table.toggleRowSelection(row, flag) this.$refs.table.toggleRowSelection(row, flag)
if (row.children != undefined) this.select(row.children, this.checkedKeys) if (row.children != undefined) this.select(row.children, this.checkedKeys)
}) })

Loading…
Cancel
Save