This commit is contained in:
g7hoo 2022-08-10 13:42:46 +08:00
parent df3b11b6dd
commit 9653474e2f
3 changed files with 49 additions and 41 deletions

View File

@ -11,20 +11,10 @@
:label="getLabel(n, c)"
>
<!-- 暂时先不实现部分输入方式 -->
<el-input
v-if="getType(n, c) === 'input'"
:placeholder="configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].placeholder || '...'"
v-model="dataForm[configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].name]"
clearable
/>
<el-input v-if="getType(n, c) === 'input'" :placeholder="getPlaceholder(n, c)" v-model="dataForm[configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].name]" clearable />
<el-radio v-if="getType(n, c) === 'radio'" v-model="dataForm[configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].name]"></el-radio>
<el-checkbox v-if="getType(n, c) === 'check'" v-model="dataForm[configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].name]"></el-checkbox>
<el-select
v-if="getType(n, c) === 'select'"
:placeholder="configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].placeholder || ''"
v-model="dataForm[configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].name]"
clearable
>
<el-select v-if="getType(n, c) === 'select'" :placeholder="getPlaceholder(n, c)" v-model="dataForm[configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].name]" clearable>
<el-option v-for="opt in configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].options" :key="opt.label" :label="opt.label" :value="opt.value" />
</el-select>
<el-switch v-if="getType(n, c) === 'switch'" v-model="dataForm[configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].name]"></el-switch>
@ -129,7 +119,8 @@ export default {
remark: '备注',
specifications: '规格'
// add more...
}
},
defaultPlaceholders: {} // defaultNames
}
},
computed: {
@ -139,8 +130,14 @@ export default {
}
},
mounted() {
/** 计算 defaultPlaceholders */
const prefix = '请输入'
Object.entries(this.defaultNames).map(([key, value]) => {
this.defaultPlaceholders[key] = prefix + value
})
/** 转换 configs.fields 的结构,把纯字符串转为对象 */
this.$nextTick(() => {
/** 转换 configs.fields 的结构,把纯字符串转为对象 */
this.configs.fields = this.configs.fields.map(item => {
if (typeof item === 'string') {
return { name: item }
@ -234,6 +231,13 @@ export default {
return opt.label ? opt.label : this.defaultNames[opt.name]
}
},
getPlaceholder(n, c) {
const opt = this.configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)]
if (opt) {
// if opt is valid
return opt.placeholder ? opt.placeholder : this.defaultPlaceholders[opt.name]
}
},
getType(n, c) {
const opt = this.configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)]
if (opt) {
@ -251,17 +255,18 @@ export default {
this.visible = true
},
handleClick(btn) {
this.$refs['dataForm'].validate(valid => {
if (valid) {
/** 提取url */
const urls = {}
this.configs.operations.map(item => {
urls[item.name] = item.url
})
/** 操作 */
switch (btn.name) {
case 'save':
case 'update':
/** 提取url */
const urls = {}
this.configs.operations.map(item => {
urls[item.name] = item.url
})
/** 操作 */
switch (btn.name) {
case 'save':
case 'update':
/** 需要验证表单的操作 */
this.$refs['dataForm'].validate(valid => {
if (valid) {
this.$http({
url: this.$http.adornUrl(urls[btn.name]),
method: btn.name === 'save' ? 'POST' : 'PUT',
@ -279,23 +284,23 @@ export default {
})
}
})
return
case 'reset':
for (const key of Object.keys(this.dataForm)) {
if (typeof this.dataForm[key] === 'string') {
this.dataForm[key] = ''
} else if (this.dataForm[key] instanceof Array) {
this.dataForm[key].splice(0)
} else {
this.dataForm[key] = null
}
}
console.log('after reset: ', JSON.stringify(this.dataForm))
break
// add more..
}
})
return
case 'reset':
for (const key of Object.keys(this.dataForm)) {
if (typeof this.dataForm[key] === 'string') {
this.dataForm[key] = ''
} else if (this.dataForm[key] instanceof Array) {
this.dataForm[key].splice(0)
} else {
this.dataForm[key] = null
}
}
}
})
console.log('after reset: ', JSON.stringify(this.dataForm))
break
// add more..
}
},
handleClose() {
if (this.isAdd || this.isUpdated) this.$emit('refreshDataList')

View File

@ -97,6 +97,7 @@ http.adornData = (data = {}, openDefaultdata = true, contentType = 'json') => {
}
data = openDefaultdata ? merge(defaults, data) : data
return contentType === 'json' ? JSON.stringify(data) : qs.stringify(data)
// return contentType === 'json' ? JSON.stringify(data, (_, v) => typeof v === 'bigint' ? v.toString() : v) : qs.stringify(data)
}

View File

@ -141,6 +141,7 @@ const addOrUpdateConfigs = {
name: 'unitDictValue',
label: '单位',
type: 'select',
// placeholder: '',
options: [
//
]
@ -265,6 +266,7 @@ export default {
deleteHandle(id) {
var ids = id
? [id]
// ? [1556817256347828335]
: this.dataListSelections.map(item => {
return item.id
})