pyt
2025-05-08 cd47054e513f2e632ad67d3495eb8d9e35f99d82
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<template>
  <el-dialog
    title="新增组件"
    :visible.sync="visible"
    width="70%"
    :close-on-click-modal="false"
    custom-class="add-component-dialog"
    @close="handleClose"
  >
    <div class="component-cards">
      <div
        v-for="(item, index) in componentTypes"
        :key="index"
        class="component-card"
        :class="{ active: selectedType === item.type }"
        :data-type="item.type"
        @click="handleSelect(item)"
      >
        <div class="card-icon">
          <img :src="item.icon" :alt="item.title" />
        </div>
        <div class="card-content">
          <div class="card-title">{{ item.title }}</div>
          <div class="card-desc">{{ item.description }}</div>
        </div>
      </div>
    </div>
 
    <div slot="footer" class="dialog-footer select-member-footer">
      <el-button @click="handleClose">取消</el-button>
      <el-button type="primary" @click="handleConfirm">保存</el-button>
    </div>
  </el-dialog>
</template>
 
<script>
export default {
  name: 'AddComponentDialog',
  props: {
    visible: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      selectedType: '',
      componentTypes: [
        {
          type: 'richText',
          title: '富文本',
          icon: require('@/assets/public/modalImg1.png'),
          description: '富文本组件可以支持文本格式化(如字体、颜色、大小等)、图片插入、链接添加等多种功能。'
        },
        {
          type: 'customTable',
          title: '自定义表格',
          icon: require('@/assets/public/modalImg2.png'),
          description: '自定义表格组件可以支持自定义表头(包括配置表头类型、默认值、权限等)'
        },
        {
          type: 'fileUpload',
          title: '文件上传',
          icon: require('@/assets/public/modalImg3.png'),
          description: '支持上传.docx/.pdf/.xlsx/.txt文件'
        },
        {
          type: 'imageUpload',
          title: '图片上传',
          icon: require('@/assets/public/modalImg4.png'),
          description: '富文本组件可以支持文本格式化(如字体、颜色、大小等)、图片插入、链接添加等多种功能。'
        }
      ]
    }
  },
  methods: {
    handleSelect(item) {
      this.selectedType = item.type
    },
    handleClose() {
      this.$emit('close', false)
      this.selectedType = ''
    },
    handleConfirm() {
      if (!this.selectedType) {
        this.$message.warning('请选择要添加的组件类型')
        return
      }
      this.$emit('confirm', this.selectedType)
      this.handleClose()
    }
  }
}
</script>
 
<style lang="less" scoped>
.add-component-dialog {
  ::v-deep .el-dialog__header {
    border-bottom: 1px solid #e4e7ed;
    padding: 20px;
    margin: 0;
  }
 
  ::v-deep .el-dialog__body {
    padding: 30px;
  }
 
  .component-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    padding: 10px;
 
    .component-card {
      display: flex;
      flex-direction: column;
      align-items: center;
      padding: 30px 20px;
      background: #fff;
      border-radius: 10px;
      border: 1px solid #e4e7ed;
      cursor: pointer;
      transition: all 0.3s;
 
      &[data-type="richText"] {
        background: linear-gradient(180deg, #FFF1DE 0%, rgba(255,249,241,0) 100%);
        border: 1px solid rgba(249,171,20,0.5);
      }
 
      &[data-type="customTable"] {
        background: linear-gradient(180deg, rgba(5,112,255,0.14) 1%, rgba(234,243,255,0) 100%);
        border: 1px solid rgba(71,145,255,0.5);
      }
 
      &[data-type="fileUpload"] {
        background: linear-gradient(180deg, #E0FAEA 0%, rgba(224,250,234,0) 100%);
        border: 1px solid rgba(87,180,131,0.5);
      }
 
      &[data-type="imageUpload"] {
        background: linear-gradient(180deg, #F5EDFF 0%, rgba(234,243,255,0) 100%);
        border: 1px solid rgba(115,83,247,0.5);
      }
 
      &.active {
        transform: translateY(-4px);
        box-shadow: 0 4px 16px 0 rgba(0, 0, 0, 0.15);
 
        &[data-type="richText"] {
          border-color: rgba(249,171,20,0.8);
          background: linear-gradient(180deg, #FFF1DE 0%, rgba(255,249,241,0.5) 100%);
        }
 
        &[data-type="customTable"] {
          border-color: rgba(71,145,255,0.8);
          background: linear-gradient(180deg, rgba(5,112,255,0.2) 1%, rgba(234,243,255,0.5) 100%);
        }
 
        &[data-type="fileUpload"] {
          border-color: rgba(87,180,131,0.8);
          background: linear-gradient(180deg, #E0FAEA 0%, rgba(224,250,234,0.5) 100%);
        }
 
        &[data-type="imageUpload"] {
          border-color: rgba(115,83,247,0.8);
          background: linear-gradient(180deg, #F5EDFF 0%, rgba(234,243,255,0.5) 100%);
        }
      }
 
      .card-icon {
        width: 92px;
        height: 92px;
        margin-bottom: 16px;
 
        img {
          width: 100%;
          height: 100%;
          object-fit: contain;
        }
      }
 
      .card-content {
        text-align: center;
 
        .card-title {
          font-size: 16px;
          font-weight: 500;
          color: #303133;
          margin-bottom: 8px;
        }
 
        .card-desc {
          font-size: 14px;
          color: #909399;
          line-height: 1.4;
        }
      }
    }
  }
 
  .dialog-footer {
    text-align: center;
    padding-top: 20px;
 
    .el-button {
      min-width: 120px;
    }
  }
}
</style>