widget-renderer.vue
1.56 KB
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
<template>
<div class="widget-wrap" :class="{ 'is-edit': editMode }">
<button
v-if="editMode"
type="button"
class="widget-wrap__remove"
title="移除组件"
@click.stop="$emit('remove')"
>
<i class="el-icon-close" />
</button>
<component :is="comp" v-if="comp" />
<workbench-card v-else title="组件缺失" icon="el-icon-warning" tone="neutral">
<div class="wb-empty">
<div class="wb-empty__circle"><i class="el-icon-warning" /></div>
<div class="wb-empty__title">组件未注册</div>
<div class="wb-empty__desc">{{ code }}</div>
</div>
</workbench-card>
</div>
</template>
<script>
import { getWidgetComponent } from './widget-map'
import WorkbenchCard from './workbench-card.vue'
export default {
name: 'WidgetRenderer',
components: { WorkbenchCard },
props: {
code: { type: String, required: true },
editMode: { type: Boolean, default: false }
},
computed: {
comp() {
return getWidgetComponent(this.code)
}
}
}
</script>
<style lang="scss" scoped>
@import './widget-common.scss';
.widget-wrap {
height: 100%;
position: relative;
}
.widget-wrap__remove {
position: absolute;
top: 8px;
right: 8px;
z-index: 10;
width: 24px;
height: 24px;
border: none;
border-radius: 50%;
background: #fef2f2;
color: #ef4444;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 2px 8px rgba(239, 68, 68, 0.15);
transition: background 200ms ease;
&:hover { background: #fee2e2; }
}
</style>