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
| <template>
| <component :is="widget.component" v-bind="getWidgetAttr(widget)" />
| </template>
| <script lang="ts">
| import { useAttrs, defineComponent, provide } from "vue"
| import type { Widget } from "@mars/widgets/common/store/widget"
| export default defineComponent({
| name: "mars-widget",
| props: ["widget"],
| setup(props) {
| const attrs = useAttrs()
|
| provide("getCurrentWidget", () => {
| return props.widget.name
| })
|
| const getWidgetAttr = (widget: Widget) => {
| let attr = {}
| if (widget.meta && widget.meta.props) {
| attr = {
| ...attr,
| ...widget.meta.props
| }
| }
| if (widget.data && widget.data.props) {
| attr = {
| ...attr,
| ...widget.data.props
| }
| }
| return attr
| }
|
| return {
| attrs,
| getWidgetAttr
| }
| }
| })
| </script>
|
|