finish 基本完成dialog“

This commit is contained in:
g7hoo 2022-08-09 16:45:16 +08:00
parent 5d8f537d05
commit cfec6ff3f5
2 changed files with 64 additions and 20 deletions

View File

@ -15,14 +15,22 @@
v-if="getType(n, c) === 'input'" v-if="getType(n, c) === 'input'"
:placeholder="configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].placeholder || '...'" :placeholder="configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].placeholder || '...'"
v-model="dataForm[configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].name]" v-model="dataForm[configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].name]"
clearable
/> />
<el-radio v-if="getType(n, c) === 'radio'"></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'"></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 v-if="getType(n, c) === 'select'" :placeholder="configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].placeholder || ''"></el-select> <el-select
<el-switch v-if="getType(n, c) === 'switch'"></el-switch> v-if="getType(n, c) === 'select'"
<el-cascader v-if="getType(n, c) === 'tree'"></el-cascader> :placeholder="configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].placeholder || ''"
<el-time-select v-if="getType(n, c) === 'time'"></el-time-select> v-model="dataForm[configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].name]"
<el-date-picker v-if="getType(n, c) === 'date'"></el-date-picker> clearable
>
<el-option v-for="opt in configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].options" :key="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>
<el-cascader v-if="getType(n, c) === 'tree'" v-model="dataForm[configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].name]"></el-cascader>
<el-time-select v-if="getType(n, c) === 'time'" v-model="dataForm[configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].name]"></el-time-select>
<el-date-picker v-if="getType(n, c) === 'date'" v-model="dataForm[configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].name]"></el-date-picker>
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row> </el-row>
@ -145,10 +153,10 @@ export default {
/** 自动请求并填充 */ /** 自动请求并填充 */
this.$http({ this.$http({
url: this.$http.adornUrl(item.api), url: this.$http.adornUrl(item.api),
methods: 'get' method: 'POST' //
}).then(({ data: res }) => { }).then(({ data: res }) => {
if (data & (data.code === 0)) { if (res && res.code === 0) {
this.dataFrom[item.name] = res.data // <=== this.dataForm[item.name] = res.data // <===
} }
}) })
} // end if (item.api) } // end if (item.api)
@ -241,15 +249,51 @@ export default {
this.visible = true this.visible = true
}, },
handleClick(btn) { 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) { switch (btn.name) {
case 'save': case 'save':
break
case 'update': case 'update':
break this.$http({
url: this.$http.adornUrl(urls[btn.name]),
method: btn.name === 'save' ? 'POST' : 'PUT',
data: this.dataForm
}).then(({ data: res }) => {
if (data && data.code === 0) {
this.$message({
message: btn.name === 'save' ? '添加成功!' : '更新成功!',
type: 'success',
duration: 1500,
onClose() {
this.$emit('refreshDataList')
this.visible = false
}
})
}
})
return
case 'reset': 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 break
// add more.. // add more..
} }
}
})
}, },
handleClose() { handleClose() {
if (this.isAdd || this.isUpdated) this.$emit('refreshDataList') if (this.isAdd || this.isUpdated) this.$emit('refreshDataList')

View File

@ -100,7 +100,7 @@ const addOrUpdateConfigs = {
'name', 'name',
{ {
name: 'code', name: 'code',
api: 'xx/code' api: '/monitoring/product/getCode'
}, },
{ {
name: 'processTime', name: 'processTime',