shishuaikang
2023-11-14 6358220b222fa74bd5991b77efe33120624e38e8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<template>
  <div class="role">
    <!-- https://juejin.cn/post/7042597964618924069?searchId=202310071305486BA29870D97939288832#heading-8 -->
    <!-- https://juejin.cn/post/7139110255748710436?searchId=2023092815420483B1983D44854DBE6608#comment -->
    <el-form ref="ruleForm" class="rule-form" :model="formConfig.formModels" :rules="formConfig.formRules"
      :label-width="formConfig.labelWidth || 'auto'">
 
      <el-row>
        <el-col v-for="item in formItems" :key="item.label" :span="item.span || 24"> 
          <el-form-item :label="item.label" :style="formConfig.itemStyle || null">
 
            <template v-if="item.type === 'input' || item.type === 'password'">
              <el-input :placeholder="item.placeholder || `请输入${item.label}`"
                :show-password="item.type === 'password'"></el-input>
            </template>
 
            <template v-else-if="item.type === 'textarea'">
              <el-input type="textarea" :placeholder="item.placeholder || `请输入${item.label}`"></el-input>
            </template>
 
            <template v-else-if="item.type === 'select'">
              <el-select v-model="formConfig.formModels.realNames" :placeholder="item.placeholder || `请选择${item.label}`">
                <el-option v-for="option in item.options" :key="option.id" :label="option.label"
                  :value="option.id"></el-option>
              </el-select>
            </template>
 
            <template v-else>
              <el-date-picker v-bind="item.otherOptions"></el-date-picker>
            </template>
 
          </el-form-item>
        </el-col>
      </el-row>
 
    </el-form>
  </div>
</template>
<script>
export default {
  name: "cForm",
  data() {
    return {}
  },
  props: {
    formConfig: {
      type: Object,
      default: () => { }
    },
    formItems: {
      type: Array,
      default: () => []
    },
  }
}
</script>
<style scoped lang="scss">
.el-form {
  padding-right: 15px;
  max-height: 550px;
  overflow-y: auto;
}
 
::v-deep .el-form-item__label {
  color: #fff
}
 
.el-select {
  width: 100%;
}
</style>