123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- <template>
- <div>
- <el-form
- ref="formData"
- :label-position="labelPosition"
- class="form-box"
- :rules="rules"
- :inline="inline"
- :label-width="labelWidth"
- :model="formValue"
- >
- <template v-for="item in formList">
- <el-form-item :label="item.label" :prop="item.prop">
- <el-input
- v-if="item.type === 'input'"
- v-model.trim="formValue[item.prop]"
- :style="{ width: `${item.width}` }"
- :placeholder="item.placeholder"
- :type="item.style"
- :show-password="item.style == 'password' ? true : false"
- clearable
- ></el-input>
- <el-select
- v-if="item.type === 'select'"
- v-model="formValue[item.prop]"
- :placeholder="item.placeholder"
- >
- <el-option
- v-for="(item1, index1) in item.child"
- :key="index1"
- :label="item1.label"
- :value="item1.value"
- ></el-option>
- </el-select>
- <!-- 单选 -->
- <el-radio-group
- v-if="item.type === 'Radio'"
- v-model="formValue[item.prop]"
- >
- <el-radio
- v-for="ra in item.radios"
- :label="ra.value"
- :key="ra.value"
- >{{ ra.label }}</el-radio
- >
- </el-radio-group>
- <!-- 单选按钮 -->
- <el-radio-group
- v-if="item.type === 'RadioButton'"
- v-model="formValue[item.prop]"
- @change="item.change && item.change(formValue[item.prop])"
- >
- <el-radio-button
- v-for="ra in item.radios"
- :label="ra.value"
- :key="ra.value"
- >{{ ra.label }}</el-radio-button
- >
- </el-radio-group>
- <!-- 复选框 -->
- <el-checkbox-group
- v-if="item.type === 'Checkbox'"
- v-model="formValue[item.prop]"
- >
- <el-checkbox
- v-for="ch in item.checkboxs"
- :label="ch.value"
- :key="ch.value"
- >{{ ch.label }}</el-checkbox
- >
- </el-checkbox-group>
- <span v-if="item.type === 'text'">{{ item.value }}</span>
- <quill-editor
- v-if="item.type === 'richText'"
- id="quill-editor"
- v-model="formValue[item.prop]"
- >
- </quill-editor>
- </el-form-item>
- </template>
- <slot name="handle" :formData="formValue">
- <!-- <el-button type="primary" @click="submitForm">提交</el-button> -->
- </slot>
- </el-form>
- </div>
- </template>
- <script>
- export default {
- name: "my-form",
- props: {
- formList: {
- type: Array,
- default: function () {
- return [];
- },
- },
- formValue: {
- type: Object,
- default: function () {
- return {};
- },
- },
- rules: {
- type: Object,
- default: function () {
- return {};
- },
- },
- inline: {
- type: Boolean,
- default: function () {
- return false;
- },
- },
- labelPosition: {
- type: String,
- default: "right",
- },
- labelWidth: {
- type: String,
- default: "",
- },
- },
- data() {
- return {
- form: {
- name: "",
- region: "",
- date1: "",
- date2: "",
- delivery: false,
- type: [],
- resource: "",
- desc: "",
- },
- };
- },
- methods: {
- submitForm() {
- this.$refs.formData.validate((valid) => {
- if (valid) {
- // this.$emit("submitForm", this.formValue);
- } else {
- return false;
- }
- });
- },
- },
- mounted() {
- //console.log(this.formList, "sss");
- },
- };
- </script>
- <style lang="scss" scoped>
- // .form-box {
- // margin-top: 30px;
- // }
- .form-box ::v-deep .ql-container {
- height: auto;
-
- }
- </style>
|