schangxiang@126.com
2025-05-07 cace264ad9d86a7831099810b079da1141957add
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
import { Component, DefineComponent, h } from 'vue'
import Provider from './index.vue'
/**
 *
 * @param Widget 组件
 * @param data  notPage 是否为组件 | NestedComponents 嵌套组件
 * @param isFullyCover 是否铺满
 * @param defaultConfig 默认样式配置,支持width,height,padding,background
 * @returns
 */
export function provider(
  Widget: Component,
  data: boolean | Component = false,
  isFullyCover: boolean = false,
  defaultConfig: Record<string, any> = {}
) {
  // const v = typeof notPage === 'boolean' ? notPage :
  let notPage
  let NestedComponents
  if (typeof data === 'boolean') {
    notPage === !!data
  }
  if (typeof data === 'object' || typeof data === 'function') {
    NestedComponents = data
  }
  return (arg: any) => {
    return h(
      Provider,
      {
        widgetProps: arg,
        widgetName: Widget.name,
        isFullyCover,
        notPage,
        defaultConfig,
        NestedComponents,
      },
      {
        default: !NestedComponents
          ? (props) => {
              return h(Widget, props)
            }
          : null,
        nested: NestedComponents
          ? (props: any) => {
              return h(NestedComponents, props, {
                default: (childProps) => {
                  return h(Widget, { ...props, ...childProps })
                },
              })
            }
          : null,
      }
    )
  }
}