Commit 6d2ee4be authored by 毛线's avatar 毛线

代码优化

parent 81e463d9
...@@ -99,7 +99,7 @@ export default { ...@@ -99,7 +99,7 @@ export default {
// 主键 // 主键
id() { id() {
const { primaryKey } = this const { primaryKey } = this
return this.form[primaryKey] return this.form ? this.form[primaryKey] : ''
}, },
width() { width() {
return this.props.width || '900px' return this.props.width || '900px'
...@@ -201,7 +201,7 @@ export default { ...@@ -201,7 +201,7 @@ export default {
return { return {
// 初始化表单数据 // 初始化表单数据
form: (data) => { form: (data) => {
const { fieldList } = this const { fieldList, primaryKey } = this
let form = {} let form = {}
if (!fieldList) { if (!fieldList) {
return return
...@@ -235,7 +235,7 @@ export default { ...@@ -235,7 +235,7 @@ export default {
break break
} }
} }
value = value || '' value = value || ''
attr.placeholder = placeholder attr.placeholder = placeholder
item.attr = attr item.attr = attr
...@@ -243,7 +243,8 @@ export default { ...@@ -243,7 +243,8 @@ export default {
form[field] = value form[field] = value
}) })
form[primaryKey] = data[primaryKey]
// 如果配置参数设置了编辑时候清空某个表单字段,则将字段的值清空 // 如果配置参数设置了编辑时候清空某个表单字段,则将字段的值清空
Object.keys(data).forEach(key => { Object.keys(data).forEach(key => {
const field = fieldList.filter(i => i.field == key)[0] const field = fieldList.filter(i => i.field == key)[0]
...@@ -261,7 +262,6 @@ export default { ...@@ -261,7 +262,6 @@ export default {
} }
} }
this.form = form this.form = form
this.$nextTick(() => { this.$nextTick(() => {
// 清除表单验证 // 清除表单验证
this.$refs['form']?.clearValidate() this.$refs['form']?.clearValidate()
...@@ -282,8 +282,7 @@ export default { ...@@ -282,8 +282,7 @@ export default {
// 请求成功并返回数据 // 请求成功并返回数据
this.loading = false // 关闭表单加载状态 this.loading = false // 关闭表单加载状态
if (this.id) { // id存在 把数据存储到当前页面 if (this.id) { // id存在 把数据存储到当前页面
const { form } = data this.form = data
this.form = form
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment