222
schangxiang@126.com
2025-05-21 8e4170267e8e5dc0c6b340b7ed119460324e2799
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
<template>
  <div class="cs-main">
    <div class="cs-menu-left" v-if="showMenu">
      <el-config-provider :namespace="namespace" :z-index="500" :locale="local">
        <Menu @change="onChangeMenu" />
      </el-config-provider>
    </div>
    <div
      class="cs-tools-box"
      @click="onClickToolBox"
      :style="{ left: showMenu ? '' : '5px' }"
    >
      <Icon
        :icon="showMenu ? 'left-arrow' : 'right-arrow'"
        :width="18"
        :height="18"
      ></Icon>
    </div>
    <div class="cs-container" :style="!showMenu ? 'width: 100%' : ''">
      <provider :isApp="true">
        <router-view v-bind="currentWidgetProps" />
      </provider>
      <el-config-provider :namespace="namespace" :z-index="500" :locale="local">
        <div class="project-config">
          <IconButton @click="onOpenProjectConfig" icon="lightsetting"
            >项目配置</IconButton
          >
        </div>
        <div class="language">
          <BaseConfigSelect />
        </div>
        <ProjectConfigDialog v-model="projectConfig.show" />
      </el-config-provider>
    </div>
    <div
      class="cs-bar-box"
      @click="onClickBarBox"
      :style="{ right: showBar ? '' : '5px' }"
      v-if="showAction"
    >
      <Icon
        :icon="showBar ? 'right-arrow' : 'left-arrow'"
        :width="18"
        :height="18"
      ></Icon>
    </div>
    <div class="right-bar" v-if="showBar">
      <component
        :is="currentWidgetSettings"
        v-bind="state"
        @update="onUpdate"
      ></component>
    </div>
  </div>
</template>
 
<script setup lang="ts">
import {
  computed,
  onMounted,
  ref,
  watch,
  provide,
  markRaw,
  reactive,
} from 'vue'
import provider from './provider/index.vue'
import Menu from '@/components/Menu/index.vue'
import sdk from 'sdk'
import Icon from '@/components/Icon/Icon'
import BaseConfigSelect from '@/components/BaseConfigSelect/BaseConfigSelect'
import { useRoute } from 'vue-router'
import { state } from '@/libs/Store/State'
import IconButton from '@/components/IconButton/IconButton'
import ProjectConfigDialog from '@/components/ProjectConfig/ProjectConfig'
 
const { models } = sdk
const { Language } = models
const { local } = Language.useElementPlusI18n()
const route = useRoute()
const namespace = import.meta.env.VITE_APP_NAMESPACE
const v = localStorage.getItem('showMenu') || 'true'
const showMenu = ref(v === 'true')
const showBar = ref(false)
const showAction = ref(true)
const currentWidgetSettings = ref()
const projectConfig = reactive({
  show: false,
})
provide('isLocal', true)
 
const onOpenProjectConfig = () => {
  projectConfig.show = true
}
/**
 * 右侧Bar控制
 */
const onClickBarBox = async () => {
  if (!currentWidgetSettings.value) {
    await getWidgetSettings()
    showBar.value = !!currentWidgetSettings.value
  } else {
    showBar.value = !showBar.value
  }
  localStorage.setItem('showBar', String(showBar.value))
}
/**
 * 左侧Bar
 */
const onClickToolBox = () => {
  showMenu.value = !showMenu.value
  localStorage.setItem('showMenu', showMenu.value ? 'true' : 'false')
}
const getWidgetSettingsFile = async (widgetName: string) => {
  const widgetPath = `./widgets/${widgetName}/Settings/${widgetName}.settings`
  const fn = async (suffix: string) => {
    const WidgetSettings = await import(/* @vite-ignore */ widgetPath + suffix)
    currentWidgetSettings.value = markRaw(WidgetSettings.default)
    showAction.value = true
    return currentWidgetSettings.value
  }
  try {
    await fn('.tsx')
  } catch (error) {
    await fn('.vue')
  }
}
/**
 * 获取当前组件
 */
const getWidgetSettings = async () => {
  const widgetName = route.meta?.widgetName
  if (!widgetName) {
    showBar.value = false
    return
  }
 
  try {
    // @ts-ignore
    await getWidgetSettingsFile(widgetName)
  } catch (error) {
    console.info(
      `%c 请检查 ${widgetName}.setting是否存在,重试`,
      'color: #ec7259'
    )
    // showAction.value = false
    currentWidgetSettings.value = null
  }
}
/**
 * 更新数据状态
 * @param data
 */
const onUpdate = (data: Record<string, any>) => {
  Object.assign(state.value, data)
}
/**
 * 菜单切换
 */
const onChangeMenu = () => {
  state.value = {}
  showBar.value = false
  localStorage.setItem('showBar', 'false')
}
 
/**
 * 当前组件属性状态
 */
const currentWidgetProps = computed(() => {
  return {
    ...state.value,
    node: {
      props: {
        ...state.value,
      },
    },
  }
})
watch(
  () => route.meta,
  (meta) => {
    const vBar = localStorage.getItem('showBar') || 'true'
    showBar.value = vBar === 'true'
    currentWidgetSettings.value = null
    if (showBar.value) {
      getWidgetSettings()
    }
  }
)
</script>
 
<style>
body {
  margin: 0;
}
</style>
<style lang="scss" scoped>
@import url('./assets/iconfont/iconfont.css');
 
.cs-tools-box {
  width: 30px;
  height: 30px;
  position: absolute;
  left: 205px;
  bottom: 50px;
  background-color: #fff;
  border-radius: 5px;
  border: 1px solid #ccc;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 999;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1), 0 1px 3px rgba(0, 0, 0, 0.08);
  transition: all 0.3s ease;
  opacity: 0.7;
  &:hover {
    background-color: #dae4ff;
    opacity: 1;
  }
}
.cs-main {
  display: flex;
  justify-content: flex-start;
  align-items: flex-start;
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: relative;
  .cs-bar-box {
    width: 30px;
    height: 30px;
    position: absolute;
    right: 280px;
    bottom: 50px;
    background-color: #fff;
    border-radius: 5px;
    border: 1px solid #ccc;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 999;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1), 0 1px 3px rgba(0, 0, 0, 0.08);
    transition: all 0.3s ease;
    opacity: 0.7;
    &:hover {
      background-color: #dae4ff;
      opacity: 1;
    }
  }
  .right-bar {
    width: 280px;
    height: 100%;
    background-color: #252727;
    flex-shrink: 0;
    position: relative;
  }
  .cs-menu-left {
    width: 200px;
    height: 100%;
    background-color: #545c64;
  }
  .cs-container {
    width: calc(100% - 200px);
    height: 100%;
    overflow: auto;
    position: relative;
    .language {
      width: fit-content;
      height: fit-content;
      position: absolute;
      right: 30px;
      top: 23px;
    }
    .project-config {
      width: fit-content;
      height: fit-content;
      position: absolute;
      right: 155px;
      top: 23px;
    }
    > div {
      width: 100%;
      height: 1080px;
    }
  }
}
</style>