hejianhao
2025-04-16 dab2d210ca06c1faa514c6388fbd5de1ab355360
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<template>
  <div class="common-table-box">
    <el-table
      :data="tableLsit"
      size="mini"
      border
      @selection-change="handleSelectionChange"
    >
      <template v-for="(item, index) in columnList">
        <!-- 多选 -->
        <el-table-column
          :key="index + 1"
          v-if="item.type === 'select'"
          align="center"
          type="selection"
          width="50"
        >
        </el-table-column>
        <!-- 展开行 -->
        <el-table-column
          :key="index + 1"
          v-if="item.type === 'expand'"
          align="center"
          type="expand"
          width="50"
          label="更多"
        >
          <template slot-scope="propsChild">
            <el-form label-position="left" inline class="demo-table-expand">
              <el-form-item
                v-for="(ic, xc) in item.child"
                :key="xc"
                :label="ic.label"
              >
                <span>{{ propsChild.row[ic.key] }}</span>
              </el-form-item>
            </el-form>
          </template>
        </el-table-column>
        <!-- 序号 -->
        <el-table-column
          :key="index + 1"
          v-if="item.type === 'index'"
          align="center"
          type="index"
          width="70"
          label="序号"
        ></el-table-column>
        <!-- 图片 -->
        <el-table-column
          :key="index + 1"
          v-if="item.type === 'img'"
          align="center"
          :label="item.label"
        >
          <template slot-scope="scope">
            <div class="fl-cen">
              <el-image
                class="img-show-style"
                fit="cover"
                :style="[
                  {
                    width: item.width ? item.width + 'px' : 30 + 'px',
                    height: item.height ? item.height + 'px' : 30 + 'px',
                  },
                ]"
                :src="scope.row[item.key]"
                :preview-src-list="[scope.row[item.key]]"
              >
              </el-image>
            </div>
          </template>
        </el-table-column>
        <!-- 常规表格 -->
        <el-table-column
          :key="index + 1"
          v-if="item.type === 'common' || !item.type"
          :prop="item.key"
          :sortable="item.sort ? item.sort : false"
          align="center"
          :show-overflow-tooltip="item.overflow === false ? false : true"
          :label="item.label"
          :width="item.width"
        >
          <template slot-scope="scope">
            <span key="index+1" v-if="item.timeShow === 'year'">{{
              reYear(scope.row[item.key])
            }}</span>
            <span v-else-if="item.timeShow === 'month'">{{
              reMonth(scope.row[item.key])
            }}</span>
            <span v-else-if="item.timeShow === 'day'">{{
              reSecond(scope.row[item.key])
            }}</span>
            <span v-else>{{ scope.row[item.key] || "-" }}</span>
          </template>
        </el-table-column>
        <!-- 自定义插槽 -->
        <el-table-column
          :key="index + 1"
          v-if="item.type === 'custom'"
          align="center"
          :label="item.label"
          :width="item.width"
          :prop="item.key"
          :sortable="item.sort ? item.sort : false"
          :show-overflow-tooltip="item.overflow === false ? false : true"
          :fixed="item.fixed ? item.fixed : false"
        >
          <template slot-scope="scope">
            <slot :row="scope.row" :name="item.slot"></slot>
          </template>
        </el-table-column>
      </template>
    </el-table>
    <slot></slot>
  </div>
</template>
 
<script>
import { dateTime, dateMonth, dateYear } from "@/utils/common";
export default {
  props: {
    tableLsit: {
      type: Array,
      default: [],
    }, // 列表
    columnList: {
      type: Array,
      default: [],
    }, // column属性列表
  },
  methods: {
    // 多选事件
    handleSelectionChange(arr) {
      this.$emit("selectionHandle", arr);
    },
    // 时间转换年
    reYear(t) {
      return dateYear(t);
    },
    // 时间转换年月日
    reSecond(t) {
      return dateTime(t);
    },
    // 时间转换年月
    reMonth(t) {
      return dateMonth(t);
    },
  },
};
</script>
 
<style scoped>
form {
  display: flex;
  flex-direction: column;
}
.img-show-style {
  cursor: pointer;
}
</style>
<style>
.demo-table-expand {
  font-size: 0;
}
.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}
.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
</style>