schangxiang@126.com
2025-05-21 912ebf022f5aff755971341c555726fa6ac5496d
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
<template>
  <el-config-provider :namespace="namespace" :z-index="100" :locale="local">
    <!-- 页面 -->
    <div v-if="!notPage" class="widget_slot_page_content" v-bind="widgetProps">
      <template v-if="hasNested">
        <!-- 自定义套壳 -->
        <slot name="nested"></slot>
      </template>
      <!-- 组件 -->
      <template v-else>
        <slot v-bind="customProps"></slot>
      </template>
    </div>
    <!-- 组件 -->
    <slot v-else v-bind="widgetProps"></slot>
  </el-config-provider>
</template>
<script lang="ts">
import {
  computed,
  defineComponent,
  onMounted,
  ref,
  provide,
  watch,
  useSlots,
  h,
} from 'vue'
import { isNil } from 'lodash'
import 'element-plus/theme-chalk/src/message.scss'
import 'element-plus/theme-chalk/src/message-box.scss'
import 'element-plus/theme-chalk/src/notification.scss'
import 'element-plus/theme-chalk/src/loading.scss'
import sdk from 'sdk'
declare global {
  interface Window {
    __BUILD_INFO__: Record<string, any>
    __BUILD_TIME__: string
    __COMMIT__: string
    __BRANCH__: string
    __USER_NAME__: string
  }
}
 
export default defineComponent({
  name: 'Provider',
  props: {
    isApp: {
      type: Boolean,
    },
    widgetName: {
      type: String,
    },
    widgetProps: {
      type: Object,
      default: () => ({}),
    },
    isFullyCover: {
      type: Boolean,
      default: false,
    },
    defaultConfig: {
      type: Object,
      default: () => ({}),
    },
    notPage: {
      type: Boolean,
    },
    NestedComponents: {
      type: [Function, Object] as any,
    },
  },
  setup(props, { attrs }: { attrs: any }) {
    const { models } = sdk
    const { Language } = models
    const { local } = Language.useElementPlusI18n()
    const slots = useSlots()
    const hasNested = computed(() => {
      return slots.nested
    })
    const namespace = import.meta.env.VITE_APP_NAMESPACE
    provide('isApp', props.isApp)
    const notPage = computed(() => {
      return props.notPage
    })
    const background = computed(() => {
      const { background } = props.defaultConfig
      return props.isApp ? '#fff' : background || '#fff'
    })
    const width = computed(() => {
      const { width } = props.defaultConfig
      return props.isApp ? '100%' : width || '1920px'
    })
    const height = computed(() => {
      const { height } = props.defaultConfig
      return props.isApp ? '100%' : height || '1080px'
    })
 
    const widgetProps = computed(() => {
      return props.widgetProps
    })
 
    const padding = computed(() => {
      const { padding } = props.defaultConfig
      const paddingValue = isNil(padding) ? '12px 18px 0 18px' : padding
      return props.isFullyCover ? '0px' : paddingValue
    })
 
    const customProps = ref({})
 
    window.__BUILD_INFO__ = {
      // 编译时间
      time: window.__BUILD_TIME__,
      // 组件版本
      // 组件名
      widgetName: props.widgetName || '-',
    }
 
    const onUpdateWidgetProps = () => {
      const o = { ...props.widgetProps }
      delete o.style
      customProps.value = {
        ...o,
      }
    }
 
    watch(() => props.widgetProps, onUpdateWidgetProps, {
      deep: true,
      immediate: true,
    })
 
    onMounted(() => {
      onUpdateWidgetProps()
    })
 
    return {
      attrs,
      namespace,
      width,
      local,
      widgetProps,
      customProps,
      padding,
      height,
      background,
      notPage,
      hasNested,
    }
  },
})
</script>
<style lang="scss">
.cs-message--error,
.cs-message--success,
.cs-message--warning,
.cs-message--info {
  padding: 12px;
  box-shadow: 0px 2px 6px 0px rgba(1, 1, 1, 0.43);
 
  .cs-message__icon {
    font-size: 20px;
 
    &::before {
      // content: '\e6a4';
      font-family: 'iconfont' !important;
      font-style: normal;
    }
  }
 
  .cs-message__content {
    color: #fff;
  }
}
 
.cs-message--error {
  background: #33242b;
  border: 1px solid #a45769;
 
  .cs-message__icon {
    color: var(--cms-color-warning-darker);
 
    &::before {
      content: '\e6c5';
    }
  }
}
 
.cs-message--success {
  background: #192f1d;
  border: 1px solid #57d05b;
  color: #fff;
  width: 380px;
  .cs-message__content {
    color: #fff;
    overflow-wrap: anywhere;
  }
  .cs-message__icon {
    color: #57d05b;
 
    &::before {
      content: '\e6c7';
    }
  }
}
 
.cs-message--warning {
  background: #382c21;
  border: 1px solid #febf72;
  width: 380px;
  .cs-message__content {
    color: #fff;
    overflow-wrap: anywhere;
  }
  .cs-message__icon {
    color: #febf72;
 
    &::before {
      content: '\e6c6';
    }
  }
}
 
.cs-message--info {
  background: #333;
  border: 1px solid #111;
  width: 380px;
  .cs-message__content {
    color: #fff;
    overflow-wrap: anywhere;
  }
  .cs-message__icon {
    color: #fff;
 
    &::before {
      content: '\e6c6';
    }
  }
}
:root {
  --cs-disabled-bg-color: #f5f7fa;
  --cs-fill-color-light: #e8e8e8;
  --cs-disabled-text-color: #5c5c5c;
}
</style>
<style lang="scss" scoped>
.widget_slot_page_content {
  width: v-bind(width);
  padding: v-bind(padding);
  background: v-bind(background);
  height: v-bind(height);
}
</style>