Commit 3cad6300 authored by 杨柠瑞's avatar 杨柠瑞

coding

parents 7cfb5054 2d456dee
...@@ -212,9 +212,10 @@ ...@@ -212,9 +212,10 @@
```vue ```vue
<template> <template>
<hm-complex-form :schema="schema['HmUser']" <hm-complex-form :schema="schema['HmUser']"
:columns="showUserColumns" :columns="showUserColumns"
:tableId="tableId" :tableId="tableId"
:buttons="showUserButtons"> :layout="layout"
:buttons="showUserButtons">
</hm-complex-form> </hm-complex-form>
</template> </template>
...@@ -424,7 +425,8 @@ ...@@ -424,7 +425,8 @@
}, },
showUserColumns: [{ name: 'username', widgetType: 1 }, { name: 'securityLevel', widgetType: 5 }, { name: 'type', widgetType: 2, options: ['企业', '代理商'] }, { name: 'avatar', widgetType: 3 }, { name: 'departmentId', widgetType: 4 }, { name: 'createTime', widgetType: 6 }], showUserColumns: [{ name: 'username', widgetType: 1 }, { name: 'securityLevel', widgetType: 5 }, { name: 'type', widgetType: 2, options: ['企业', '代理商'] }, { name: 'avatar', widgetType: 3 }, { name: 'departmentId', widgetType: 4 }, { name: 'createTime', widgetType: 6 }],
// 要显示按钮 暂只支持确定、保存、取消、提交、重置 // 要显示按钮 暂只支持确定、保存、取消、提交、重置
showUserButtons: ['确定', '取消'] showUserButtons: ['确定', '取消'],
layout: { left: 0, middle: 12, right: 12 }
} }
}, },
created() { created() {
......
<template> <template>
<div class="app-container documentation-container"> <div class="app-container documentation-container">
<el-row type="flex" class="hm-form" style="margin-top: 50px"> <!--v-loading="Loading"-->
<el-col :span="6"> <el-row type="flex" class="hm-form" style="margin-top: 20px" >
<el-col :span="layout.left">
<div></div> <div></div>
</el-col> </el-col>
<el-col :span="12"> <el-col :span="layout.middle">
<div> <div>
<!--表单部分--> <!--表单部分-->
<el-form ref="form" <el-form ref="form"
element-loading-text="加载中"
:model="formModel" :model="formModel"
:rules="rules" :rules="rules"
label-width="110px" label-width="110px"
...@@ -46,9 +48,13 @@ ...@@ -46,9 +48,13 @@
:rows="2"> :rows="2">
</el-input> </el-input>
<!-- 5 复选框 --> <!-- 5 复选框 -->
<el-checkbox v-else-if="column.widgetType === 3 && !column.options" v-model="formModel[column.codeCamel]" true-label="1" false-label="0"></el-checkbox> <el-checkbox v-else-if="column.widgetType === 3 && !column.options"
<el-checkbox-group v-else-if="column.widgetType === 3 && column.options" v-model="formModel[column.codeCamel]"> v-model="formModel[column.codeCamel]"
<el-checkbox v-for="option in column.options" :label="option" :key="option">{{option}}</el-checkbox> true-label="1" false-label="0"></el-checkbox>
<el-checkbox-group v-else-if="column.widgetType === 3 && column.options"
v-model="formModel[column.codeCamel]">
<el-checkbox v-for="option in column.options"
:label="option" :key="option">{{option}}</el-checkbox>
</el-checkbox-group> </el-checkbox-group>
<!-- 6 富文本 --> <!-- 6 富文本 -->
<quill-editor v-else-if="column.widgetType === 5" <quill-editor v-else-if="column.widgetType === 5"
...@@ -60,22 +66,30 @@ ...@@ -60,22 +66,30 @@
@ready="onEditorReady($event)"> @ready="onEditorReady($event)">
</quill-editor> </quill-editor>
<!-- 7 单选框 --> <!-- 7 单选框 -->
<el-radio-group v-else-if="column.widgetType === 7" v-model="formModel[column.codeCamel]"> <el-radio-group v-else-if="column.widgetType === 7"
<el-radio v-for="(option,key) in column.options" :key="key" :label="key">{{option}}</el-radio> v-model="formModel[column.codeCamel]">
<el-radio v-for="(option,key) in column.options"
:key="key" :label="key">{{option}}</el-radio>
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>
<!--按钮--> <!--按钮-->
<el-form-item v-if="buttons && buttons.length > 0"> <el-form-item v-if="buttons && buttons.length > 0">
<el-col :span="12" v-for="(btn,key) in buttons" :key="key"> <el-col :span="24/buttons.length" v-for="(btn,key) in buttons" :key="key">
<el-button v-if="btn === '确定' || btn === '提交' || btn === '保存' || btn === '发布'" type="primary" @click="onSubmit()">{{btn}}</el-button> <el-button v-if="btn.type === 1"
<el-button v-if="btn === '重置'" type="primary" @click="resetForm()">{{btn}}</el-button> type="primary"
<el-button v-if="btn === '取消'" type="primary" @click="cancelFunction?cancelFunction():''">{{btn}}</el-button> @click="onSubmit(btn.method)">{{btn.text}}</el-button>
<el-button v-if="btn.type === 2"
type="primary"
@click="resetForm(btn.method)">{{btn.text}}</el-button>
<el-button v-if="btn.type === 3"
type="primary"
@click="btn.method">{{btn.text}}</el-button>
</el-col> </el-col>
</el-form-item> </el-form-item>
</el-form> </el-form>
</div> </div>
</el-col> </el-col>
<el-col :span="6"> <el-col :span="layout.right">
<div></div> <div></div>
</el-col> </el-col>
</el-row> </el-row>
...@@ -141,9 +155,16 @@ ...@@ -141,9 +155,16 @@
} }
}, },
/** /**
* 非必传,指定要显示的按钮(确定、保存、取消、提交、重置),默认不显示。 * 非必传,指定要显示的按钮及类型,默认不显示。
* 类型(type)关系到按钮要执行的方法,type=1,执行组件的提交方法,如果用户传入了method,会作为提交方法的回调函数执行
* type=2,执行组件的重置方法,如果用户传入了method,会作为重置方法的回调函数执行
* type=3,直接执行用户传入的方法
* 如果要传入了确定/取消的回调函数,请先传入对应的按钮 * 如果要传入了确定/取消的回调函数,请先传入对应的按钮
* 示例:['确定', '取消'] * 示例:[
* {text: '确定', type: '1', method: method1},
* {text: '重置', type: '2', method: method2},
* {text: '取消', type: '3', method: method3}
* ]
*/ */
buttons: { buttons: {
type: Array, type: Array,
...@@ -157,19 +178,12 @@ ...@@ -157,19 +178,12 @@
required: false required: false
}, },
/** /**
* 非必传,传入点击'确定'后的回调函数,该回调函数会在form组件onSubmit函数的成功回调中调用 * 非必传,布局方式,form组件布局分三栏,左右为留白,中间是form,
* 如果要传入该函数,请先传入对应的按钮 * 通过传参可以控制各部分所占份数,遵循elementUi24分栏,默认居中布局(left:6,middle:12,right:6)
*/ * 示例:{ left: 0, middle: 12, right: 12 }
confirmFunction: {
type: Function,
required: false
},
/**
* 非必传,传入点击'取消'后的回调函数,该回调函数会在点击'取消'后直接调用
* 如果要传入该函数,请先传入对应的按钮
*/ */
cancelFunction: { layout: {
type: Function, type: Object,
required: false required: false
} }
}, },
...@@ -208,6 +222,7 @@ ...@@ -208,6 +222,7 @@
// } // }
// } // }
return { return {
Loading: true,
form: null, form: null,
formModel: {}, // 双向绑定的数据变量 formModel: {}, // 双向绑定的数据变量
showUserColumns: [], // 要显示的字段 showUserColumns: [], // 要显示的字段
...@@ -274,6 +289,7 @@ ...@@ -274,6 +289,7 @@
created() { created() {
// this.validate() // this.validate()
this.init() this.init()
this.getList()
console.log(this.buttons) console.log(this.buttons)
}, },
methods: { methods: {
...@@ -316,6 +332,24 @@ ...@@ -316,6 +332,24 @@
onEditorReady(editor) { onEditorReady(editor) {
// console.log('editor ready!') // console.log('editor ready!')
}, },
// 存在tableId,修改数据前先获取数据
getList() {
const self = this
// 获取数据
request(self.schema.modelUnderscorePlural + '/' + self.tableId).then(resp => {
// 数据库字段转化显示
/* if (self.options.changeValue) {
resp.data = self.changeValue(resp.data)
} */
self.Loading = false
// console.log(self.formModel)
var formArray = _.keys(self.formModel)
// console.log(formArray)
self.formModel = _.pick(resp.data, formArray)
// console.log(self.formModel)
})
},
init() { init() {
const self = this const self = this
// 如果没有传columns,则全部显示 // 如果没有传columns,则全部显示
...@@ -340,9 +374,9 @@ ...@@ -340,9 +374,9 @@
self.$set(tmp, 'widgetType', column.widgetType || 1) self.$set(tmp, 'widgetType', column.widgetType || 1)
column.options && self.$set(tmp, 'options', column.options) column.options && self.$set(tmp, 'options', column.options)
self.$set(self.showUserColumns, index, tmp) // 顺序 self.$set(self.showUserColumns, index, tmp) // 顺序
// console.log(self.showUserColumns)
} }
}) })
console.log(self.showUserColumns)
// 提取v-model绑定的变量 // 提取v-model绑定的变量
_.each(self.showUserColumns, function(item) { _.each(self.showUserColumns, function(item) {
if (item.widgetType === 3 && item.options && item.options.length > 0) { if (item.widgetType === 3 && item.options && item.options.length > 0) {
...@@ -351,10 +385,15 @@ ...@@ -351,10 +385,15 @@
self.$set(self.formModel, item.codeCamel, '') self.$set(self.formModel, item.codeCamel, '')
} }
}) })
console.log(self.formModel)
if (!request.defaults.baseURL) { if (!request.defaults.baseURL) {
request.defaults.baseURL = '/org/api' request.defaults.baseURL = '/org/api'
} }
// 加载等待
if (self.tableId) {
self.Loading = true
} else {
self.Loading = false
}
} else { } else {
console.log('columns为必传字段!!') console.log('columns为必传字段!!')
} }
...@@ -366,7 +405,7 @@ ...@@ -366,7 +405,7 @@
* 所有选项输入并验证通过,正确提交 * 所有选项输入并验证通过,正确提交
* 验证失败,禁止提交并给出提示 * 验证失败,禁止提交并给出提示
*/ */
onSubmit() { onSubmit(callback) {
const self = this const self = this
console.log('点击了提交函数') console.log('点击了提交函数')
console.log(self.formModel) console.log(self.formModel)
...@@ -395,7 +434,9 @@ ...@@ -395,7 +434,9 @@
}).then(resp => { }).then(resp => {
console.log('修改成功') console.log('修改成功')
self.resetForm() self.resetForm()
self.confirmFunction && self.confirmFunction() if (typeof (callback) === 'function') {
callback()
}
}) })
} else { // 不存在tableId 则创建一条数据 } else { // 不存在tableId 则创建一条数据
request(self.schema.modelUnderscorePlural + '/new', { request(self.schema.modelUnderscorePlural + '/new', {
...@@ -413,7 +454,9 @@ ...@@ -413,7 +454,9 @@
}).then(resp => { }).then(resp => {
console.log('创建成功') console.log('创建成功')
self.resetForm() self.resetForm()
self.confirmFunction && self.confirmFunction() if (typeof (callback) === 'function') {
callback()
}
}) })
} }
} else { } else {
...@@ -432,9 +475,12 @@ ...@@ -432,9 +475,12 @@
* *
* 清空所有输入及提示信息。 * 清空所有输入及提示信息。
*/ */
resetForm() { resetForm(callback) {
console.log('重置') console.log('重置')
this.$refs.form.resetFields() this.$refs.form.resetFields()
if (typeof (callback) === 'function') {
callback()
}
} }
} }
......
...@@ -3,8 +3,7 @@ ...@@ -3,8 +3,7 @@
<hm-complex-form :schema="schema['HmUser']" <hm-complex-form :schema="schema['HmUser']"
:columns="showUserColumns" :columns="showUserColumns"
:buttons="showUserButtons" :buttons="showUserButtons"
:confirmFunction="confirm" :layout="layout"
:cancelFunction="cancel"
:tableId="tableId"> :tableId="tableId">
</hm-complex-form> </hm-complex-form>
</div> </div>
...@@ -27,16 +26,22 @@ ...@@ -27,16 +26,22 @@
// widgetType值 1:普通input 2:下拉框 (如果是下拉框 再传一个options表示下拉框选项)3:复选框 4:文本域 5:富文本 6:日期 7:单选框 // widgetType值 1:普通input 2:下拉框 (如果是下拉框 再传一个options表示下拉框选项)3:复选框 4:文本域 5:富文本 6:日期 7:单选框
showUserColumns: [ showUserColumns: [
{ name: '姓名', codeCamel: 'username', widgetType: 1 }, { name: '姓名', codeCamel: 'username', widgetType: 1 },
{ name: '安全级别', codeCamel: 'securityLevel', widgetType: 5 }, { name: '邮箱', codeCamel: 'email', widgetType: 5 },
{ name: '选择类型', codeCamel: 'type', widgetType: 2, options: ['选项1', '选项2'] }, { name: '选择类型', codeCamel: 'type', widgetType: 2, options: ['选项1', '选项2'] },
{ name: '选择头像', codeCamel: 'avatar', widgetType: 3, options: ['美女', '帅哥'] }, { name: '选择头像', codeCamel: 'avatar', widgetType: 3, options: ['美女', '帅哥'] },
{ name: '部门', codeCamel: 'departmentId', widgetType: 4 }, { codeCamel: 'password', widgetType: 4 },
{ name: '新建时间', codeCamel: 'createTime', widgetType: 6 }, { name: '新建时间', codeCamel: 'createTime', widgetType: 6 },
{ name: '登陆地址', codeCamel: 'loginid', widgetType: 7, options: ['会员', '访客'] } { name: '登陆id', codeCamel: 'loginid', widgetType: 7, options: ['会员', '访客'] }
],
// 要显示按钮
showUserButtons: [
{ text: '确定', type: 1, method: this.method1 },
{ text: '重置', type: 2, method: this.method2 },
{ text: '取消', type: 3, method: this.method3 }
], ],
// 要显示按钮 暂只支持确定、保存、取消、提交、重置
showUserButtons: ['确定', '取消']
// showUserButtons: [] // showUserButtons: []
// 布局方式
layout: { left: 0, middle: 12, right: 12 }
} }
}, },
computed: { computed: {
...@@ -49,11 +54,14 @@ ...@@ -49,11 +54,14 @@
this.tableId = '0e26566e953449a7a7500c34be39fd26' this.tableId = '0e26566e953449a7a7500c34be39fd26'
}, },
methods: { methods: {
confirm() { method1() {
console.log('确定') console.log('method1')
},
method2() {
console.log('method2')
}, },
cancel() { method3() {
console.log('取消') console.log('method3')
} }
} }
} }
......
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