Skip to content

Commit a37dd08

Browse files
Create MetaChildItem.vue
1 parent 2227234 commit a37dd08

1 file changed

Lines changed: 131 additions & 0 deletions

File tree

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<template>
2+
<div class="items-container">
3+
<div class="title">{{ title }}</div>
4+
<div
5+
v-for="(data, idx) in properties"
6+
:key="idx"
7+
class="meta-config-item"
8+
>
9+
<config-item
10+
:key="idx"
11+
:property="data"
12+
:data-prop-index="idx"
13+
:data-group-index="index"
14+
@update:modelValue="onValueChange(data.property, $event)"
15+
>
16+
<slot
17+
name="prefix"
18+
:data="data"
19+
/>
20+
<slot
21+
name="suffix"
22+
:data="data"
23+
/>
24+
</config-item>
25+
</div>
26+
</div>
27+
</template>
28+
29+
<script>
30+
import { computed } from 'vue';
31+
import { isObject } from '@opentiny/vue-renderless/grid/static';
32+
import { ConfigItem } from '@opentiny/tiny-engine-common';
33+
34+
export default {
35+
components: {
36+
ConfigItem,
37+
},
38+
inheritAttrs: false,
39+
props: {
40+
meta: {
41+
type: Object,
42+
default: () => {},
43+
},
44+
type: {
45+
type: String,
46+
default: 'object',
47+
},
48+
arrayIndex: {
49+
type: Number,
50+
default: -1,
51+
},
52+
},
53+
emits: ['update:modelValue'],
54+
setup(props, { emit }) {
55+
const untitled = {
56+
zh_CN: '未命名标题',
57+
en_US: 'Untitled',
58+
};
59+
60+
const title = computed(() => {
61+
const propsModelValue = props.meta.widget.props?.modelValue?.value || [];
62+
const { title: propTitle, label, type } = propsModelValue[props.arrayIndex] || {};
63+
const text = propTitle || label;
64+
const localizedText = isObject(text) ? text['zh_CN'] : text;
65+
66+
return localizedText || type || untitled['zh_CN'] || untitled.zh_CN;
67+
});
68+
69+
const properties = computed(() => {
70+
const propertiesList = props.meta?.properties;
71+
let result = [...(props.meta?.properties?.[0]?.content || [])];
72+
const propsModelValue = props.meta.widget.props?.modelValue?.value;
73+
let selectedComponentProperties = null;
74+
if (propsModelValue) {
75+
let modelValue = propsModelValue;
76+
if (props.type === 'array' && props.arrayIndex > -1) {
77+
modelValue = modelValue[props.arrayIndex];
78+
}
79+
selectedComponentProperties = propertiesList.find(
80+
(group) => group?.componentName && group.componentName === modelValue.componentName,
81+
);
82+
}
83+
result = selectedComponentProperties ? result.concat(selectedComponentProperties.content) : result;
84+
if (result.length && propsModelValue) {
85+
result.forEach((item) => {
86+
let modelValue = propsModelValue;
87+
if (props.type === 'array' && props.arrayIndex > -1) {
88+
modelValue = modelValue[props.arrayIndex];
89+
}
90+
let model_value_property = modelValue[item.property];
91+
item.widget.props.modelValue =
92+
typeof model_value_property === 'boolean' ? model_value_property : model_value_property || null;
93+
});
94+
}
95+
return result;
96+
});
97+
98+
const onValueChange = (property, data) => {
99+
emit('update:modelValue', { propertyKey: property, propertyValue: data });
100+
};
101+
102+
return {
103+
title,
104+
properties,
105+
onValueChange,
106+
};
107+
},
108+
};
109+
</script>
110+
111+
<style lang="less" scoped>
112+
.title {
113+
color: var(--te-component-common-text-color-primary);
114+
padding: 0 20px 0 10px;
115+
font-weight: bold;
116+
margin-bottom: 16px;
117+
}
118+
.items-container {
119+
width: 100%;
120+
display: flex;
121+
flex-direction: column;
122+
height: calc(100% - 34px); // 34为头部+底部的高度
123+
overflow-y: auto;
124+
125+
.meta-config-item {
126+
flex: 1;
127+
padding: 0 10px;
128+
margin-bottom: var(--te-common-vertical-item-spacing-normal);
129+
}
130+
}
131+
</style>

0 commit comments

Comments
 (0)