ny
22 小时以前 282fbc6488f4e8ceb5fda759f963ee88fbf7b999
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
<script lang="ts" setup>
import { computed, defineAsyncComponent, inject, markRaw, nextTick, ref } from 'vue';
 
import { DeleteOutlined } from '@ant-design/icons-vue';
import { upperFirst } from 'lodash-es';
 
import { $t } from '#/locales';
 
import CardHeader from '../../Portal/CardHeader/index.vue';
import { chartList } from '../helper/dataMap';
import AddBtn from './AddBtn.vue';
 
defineOptions({ name: 'Parser' });
 
const props = defineProps(['item', 'activeId', 'showType', 'detailed']);
const allModules: any = import.meta.glob('../../Portal/H*/index.vue');
const layouts = ref<any>(null);
const emitter: any = inject('emitter');
if (props.item.jnpfKey !== 'card') layouts.value = markRaw(defineAsyncComponent(() => getComponents(props.item.jnpfKey)));
const useNeedKeyList = new Set(['carousel', 'customEcharts', 'dataBoard', 'image', 'notice', 'tableList', 'text', 'todo', 'video']);
 
const activeData = computed(() => {
  const activeData = props.item;
  if (!props.detailed) return activeData;
  if (activeData.titleI18nCode) activeData.title = $t(activeData.titleI18nCode, activeData.title);
  if (activeData.card.cardRightBtnI18nCode) activeData.card.cardRightBtn = $t(activeData.card.cardRightBtnI18nCode, activeData.card.cardRightBtn);
  if (activeData.jnpfKey === 'tab') {
    for (let i = 0; i < activeData.children.length; i++) {
      if (activeData.children[i].titleI18nCode) activeData.children[i].title = $t(activeData.children[i].titleI18nCode, activeData.children[i].title);
    }
  }
  if (['dataBoard', 'todo'].includes(activeData.jnpfKey)) {
    for (let i = 0; i < activeData.option.defaultValue.length; i++) {
      const e = activeData.option.defaultValue[i];
      if (e.fullNameI18nCode) e.fullName = $t(e.fullNameI18nCode, e.fullName);
    }
  }
  if (activeData.jnpfKey === 'carousel') {
    for (let i = 0; i < activeData.option.defaultValue.length; i++) {
      const e = activeData.option.defaultValue[i];
      if (e.textDefaultValueI18nCode) e.textDefaultValue = $t(e.textDefaultValueI18nCode, e.textDefaultValue);
    }
  }
  if (activeData.jnpfKey === 'text' && activeData.dataType === 'static' && activeData.option.defaultValueI18nCode) {
    activeData.option.defaultValue = $t(activeData.option.defaultValueI18nCode, activeData.option.defaultValue);
  }
  if (activeData.jnpfKey === 'image' && activeData.option.textDefaultValueI18nCode) {
    activeData.option.textDefaultValue = $t(activeData.option.textDefaultValueI18nCode, activeData.option.textDefaultValue);
  }
  if (['notice', 'tableList'].includes(activeData.jnpfKey)) {
    for (let i = 0; i < activeData.option.columnData.length; i++) {
      const e = activeData.option.columnData[i];
      if (e.fullNameI18nCode) e.fullName = $t(e.fullNameI18nCode, e.fullName);
    }
  }
  if (activeData.jnpfKey === 'rankList') {
    for (let i = 0; i < activeData.option.columnOptions.length; i++) {
      const e = activeData.option.columnOptions[i];
      if (e.labelI18nCode) e.label = $t(e.labelI18nCode, e.label);
    }
  }
  if (['mapChart', ...chartList].includes(activeData.jnpfKey)) {
    if (activeData.option.titleTextI18nCode) activeData.option.titleText = $t(activeData.option.titleTextI18nCode, activeData.option.titleText);
    if (activeData.option.titleSubtextI18nCode) activeData.option.titleSubtext = $t(activeData.option.titleSubtextI18nCode, activeData.option.titleSubtext);
    if (activeData.option.xAxisNameI18nCode) activeData.option.xAxisName = $t(activeData.option.xAxisNameI18nCode, activeData.option.xAxisName);
    if (activeData.option.yAxisNameI18nCode) activeData.option.yAxisName = $t(activeData.option.yAxisNameI18nCode, activeData.option.yAxisName);
  }
  return activeData;
});
 
const getBindValue = computed(() => ({
  activeData: props.item,
  key: useNeedKeyList.has(props.item.jnpfKey) ? props.item.renderKey : '',
}));
 
function getComponents(e: string): Promise<any> {
  if (chartList.includes(e)) e = 'chart';
  const name = `H${upperFirst(e)}`;
  const page = `../../Portal/${name}/index.vue`;
  return new Promise((resolve, reject) => {
    let flag = true;
    for (const path in allModules) {
      if (path == page) {
        flag = false;
        allModules[path]().then((mod) => {
          resolve(mod);
        });
      }
    }
    if (flag) reject(new Error(`该文件不存在:${page}`));
  });
}
function handleClick(data) {
  emitter.emit('handlerActive', data);
}
function handleRemoveItem(i, parent) {
  parent.splice(i, 1);
}
function handleAddComponent(val) {
  emitter.emit('addComponent', { val, item: props.item });
}
function handleTabClick() {
  nextTick(() => {
    const active = props.item.active;
    const list = props.item.children;
    for (const element of list) {
      if (element.name === active && element.children && element.children.length) {
        element.children.map((ele) => {
          emitter.emit(`eChart${ele.i}`);
          return ele;
        });
      }
    }
  });
}
</script>
<template>
  <div class="h-full" @click.stop="handleClick(activeData)">
    <component :is="layouts" v-bind="getBindValue" v-if="activeData.jnpfKey !== 'card' && activeData.jnpfKey !== 'tab'" />
    <template v-if="activeData.jnpfKey === 'card'">
      <a-card class="portal-card-box">
        <template #title v-if="activeData.title">
          <CardHeader :title="activeData.title" :card="activeData.card" />
        </template>
        <div class="portal-card-body flex items-center justify-center p-[15px]">
          <div
            v-show="activeData.children && activeData.children.length"
            class="portal-box-item"
            v-for="(it, index) in activeData.children"
            :key="index"
            @click.stop="handleClick(it)">
            <Parser :item="it" :class="{ 'active-item': it.i === activeId }" :active-id="activeId" :detailed="detailed" />
            <div class="drawing-item-action">
              <a-popconfirm
                :title="$t('formGenerator.delComponentTip')"
                class="drawing-item-action-item drawing-item-delete"
                @confirm="handleRemoveItem(index, activeData.children)"
                v-if="!detailed">
                <span :title="$t('common.delText')">
                  <DeleteOutlined />
                </span>
              </a-popconfirm>
            </div>
          </div>
          <AddBtn :active-data="activeData" @add-component="handleAddComponent" v-show="!activeData.children?.length && !detailed" />
        </div>
      </a-card>
    </template>
    <template v-if="activeData.jnpfKey === 'tab'">
      <a-tabs
        v-model:active-key="activeData.active"
        :tab-position="activeData.tabPosition"
        @tab-click="handleTabClick"
        :type="activeData.type"
        class="portal-box-tab h-full bg-white"
        :class="{ 'portal-eChart-tab-position': activeData.tabPosition == 'left' || activeData.tabPosition == 'right' }">
        <a-tab-pane v-for="child in activeData.children" :key="child.name">
          <template #tab>
            <span class="ml-[4px]"><i :class="child.icon" class="pr-[4px]"></i>{{ child.title }}</span>
          </template>
          <div class="portal-tab-body flex h-full items-center justify-center p-[15px]">
            <div v-show="child.children?.length" class="portal-box-item" v-for="(it, index) in child.children" :key="index" @click.stop="handleClick(it)">
              <parser :item="it" :class="{ 'active-item': it.i === activeId }" :active-id="activeId" :detailed="detailed" />
              <div class="drawing-item-action">
                <a-popconfirm
                  :title="$t('formGenerator.delComponentTip')"
                  class="drawing-item-action-item drawing-item-delete"
                  @confirm="handleRemoveItem(index, child.children)"
                  v-if="!detailed">
                  <span :title="$t('common.delText')">
                    <DeleteOutlined />
                  </span>
                </a-popconfirm>
              </div>
            </div>
            <AddBtn :active-data="activeData" @add-component="handleAddComponent" v-show="!child.children?.length && !detailed" />
          </div>
        </a-tab-pane>
      </a-tabs>
    </template>
  </div>
</template>
<style lang="scss" scoped>
.portal-box-tab {
  :deep(.ant-tabs-nav) {
    margin-bottom: unset;
  }
 
  :deep(.ant-tabs-content) {
    height: 100%;
  }
}
</style>