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