You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
2.3 KiB

2 years ago
<script>
2 years ago
import { deepCopy } from "@/utils"
2 years ago
import formBuilder from '@/utils/formBuilder'
export default {
props: {
2 years ago
readable: {
type: Array,
default: () => [],
required: true
},
writeable: {
type: Array,
default: () => [],
required: true
},
2 years ago
originalForm: {
type: Object,
default: () => ({}),
required: true
},
subForm: {
type: Map,
default: () => new Map()
},
2 years ago
device: {
type: String,
default: 'desktop',
required: true
2 years ago
},
2 years ago
fields: {
2 years ago
type: Array,
default: () => [],
required: true
2 years ago
},
fileList: {
type: Object,
default: () => ({}),
required: true
2 years ago
},
2 years ago
scriptContent: String,
rules: {
type: Object,
default: () => ({})
}
2 years ago
},
data() {
return {
2 years ago
form: {},
2 years ago
file: {},
2 years ago
}
},
methods: {
2 years ago
async validate() {
return await (this.$refs['elForm'].validate())
}
2 years ago
},
computed: {
2 years ago
},
watch: {
info(newVal) {
let keys = newVal.map(i => i.name)
keys.forEach(key => {
this.form[key] = ''
})
},
originalForm(newVal) {
this.form = deepCopy(newVal)
2 years ago
},
fileList: {
handler:function(newVal) {
this.file = deepCopy(newVal)
},
immediate: true,
deep: true
2 years ago
},
scriptContent(newVal) {
if(newVal) {
try {
new Function(newVal).bind(this)()
} catch (err) {
console.error(err)
}
}
2 years ago
}
2 years ago
},
render(h) {
2 years ago
const authFields = this.fields.map(field => ({
...field,
_readable: this.readable.indexOf(field.id) !== -1,
_writeable: this.writeable.indexOf(field.id) !== -1,
2 years ago
}))
2 years ago
return h('el-form', {
2 years ago
ref: 'elForm',
2 years ago
class: 'form',
props: {
model: this.form,
2 years ago
'label-position': 'right',
'label-width': '80px',
rules: this.rules,
'inline-message': true
2 years ago
}
2 years ago
},authFields.map(field => formBuilder.bind(this)(this.device, field, h)))
},
2 years ago
created() {}
2 years ago
}
</script>
<style scoped lang="scss">
.form {
display: grid;
grid-template-columns: repeat(12, 1fr);
2 years ago
//grid-gap: 20px;
2 years ago
}
::v-deep .el-form-item {
2 years ago
border: 1px solid #dee2e6;
padding: 8px 12px;
margin: -1px 0 0 -1px;
2 years ago
}
2 years ago
::v-deep .el-form-item__content {
2 years ago
}
</style>