zhuoyuan.wang
2024-06-19 15ebe96f28cadec6a726c5324593a40bbf56205f
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<template>
  <el-form class="app-form-details" ref="formRef" :model="$props.model" v-bind="$attrs">
    <el-row>
      <template v-for="field in $props.fields" :key="field.prop">
        <el-col v-bind="field?.col">
 
          <slot
            :name="field.prop"
            :model="$props.model"
            :field="field"
            v-if="field.type === 'slot'"
          />
 
          <el-form-item
            v-if="field.type === 'el-input'"
            v-bind="field.item"
          >
            <template #label="scope">
              <app-text-ellipsis :value="scope.label" class="label"/>
            </template>
            <app-text-ellipsis :value="formatData(field.format, $props.model[field.prop])" class="value"/>
          </el-form-item>
 
        </el-col>
      </template>
    </el-row>
  </el-form>
</template>
 
<script setup>
 
import {context} from '@/hooks';
 
const {useForceUpdate} = context;
 
/**
 * field 类型 type
 * @type {UnwrapNestedRefs<*[]>}
 */
 
const props = defineProps({
  fields: {
    type: Array,
    default: []
  },
  model: {
    type: Object,
    default: {}
  }
});
 
const [$props, forceUpdate] = useForceUpdate(props);
 
const $forceUpdate = forceUpdate
 
const formatData = (format, data) => {
  return format ? format(data) : (data || '')
}
 
const setModel = (model) => {
  $props.model = model;
}
/**
 * 暴露给父组件的参数和方法 (外部需要什么,都可以从这里暴露出去)
 */
defineExpose({
 
  $forceUpdate,
  setModel
});
 
</script>
 
<style lang='scss' scoped>
.row-bg {
  height: 100px;
}
 
.app-form-details {
  background: #fff;
 
  .label {
    color: rgba(0, 0, 0, 0.45);
  }
 
  .value {
    color: rgba(0, 0, 0, 0.88);
  }
}
</style>
 
 
<style lang='scss'>
 
.app-form-details {
 
  .label {
    color: rgba(0, 0, 0, 0.45);
  }
 
  .value {
    color: rgba(0, 0, 0, 0.88);
  }
}
</style>