mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-04-06 03:57:56 +08:00
feat(data-source): 迭代器容器内容支持显示条件配置
This commit is contained in:
parent
022c10f2df
commit
882d222800
@ -222,7 +222,7 @@ class DataSourceManager extends EventEmitter {
|
|||||||
const [dsId, ...keys] = dataSourceField;
|
const [dsId, ...keys] = dataSourceField;
|
||||||
const ds = this.get(dsId);
|
const ds = this.get(dsId);
|
||||||
if (!ds) return items;
|
if (!ds) return items;
|
||||||
return compliedIteratorItems(itemData, items, dsId, keys);
|
return compliedIteratorItems(itemData, items, dsId, keys, this.app.platform !== 'editor');
|
||||||
}
|
}
|
||||||
|
|
||||||
public destroy() {
|
public destroy() {
|
||||||
|
@ -177,11 +177,18 @@ export const compiledNodeField = (value: any, data: DataSourceManagerData) => {
|
|||||||
return value;
|
return value;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const compliedIteratorItems = (itemData: any, items: MNode[], dsId: string, keys: string[] = []) => {
|
export const compliedIteratorItems = (
|
||||||
|
itemData: any,
|
||||||
|
items: MNode[],
|
||||||
|
dsId: string,
|
||||||
|
keys: string[] = [],
|
||||||
|
inEditor = false,
|
||||||
|
) => {
|
||||||
const watcher = new Watcher();
|
const watcher = new Watcher();
|
||||||
watcher.addTarget(
|
watcher.addTarget(
|
||||||
new Target({
|
new Target({
|
||||||
id: dsId,
|
id: dsId,
|
||||||
|
type: 'data-source',
|
||||||
isTarget: (key: string | number, value: any) => {
|
isTarget: (key: string | number, value: any) => {
|
||||||
if (`${key}`.startsWith(DSL_NODE_KEY_COPY_PREFIX)) {
|
if (`${key}`.startsWith(DSL_NODE_KEY_COPY_PREFIX)) {
|
||||||
return false;
|
return false;
|
||||||
@ -192,23 +199,44 @@ export const compliedIteratorItems = (itemData: any, items: MNode[], dsId: strin
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
watcher.addTarget(
|
||||||
|
new Target({
|
||||||
|
id: dsId,
|
||||||
|
type: 'cond',
|
||||||
|
isTarget: (key, value) => {
|
||||||
|
// 使用data-source-field-select value: 'key' 可以配置出来
|
||||||
|
if (!Array.isArray(value) || value[0] !== dsId || !`${key}`.startsWith('displayConds')) return false;
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
watcher.collect(items, {}, true);
|
watcher.collect(items, {}, true);
|
||||||
|
|
||||||
const { deps } = watcher.getTarget(dsId);
|
const { deps } = watcher.getTarget(dsId, 'data-source');
|
||||||
if (!Object.keys(deps).length) {
|
const { deps: condDeps } = watcher.getTarget(dsId, 'cond');
|
||||||
|
|
||||||
|
if (!Object.keys(deps).length && !Object.keys(condDeps).length) {
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
return items.map((item) => {
|
return items.map((item) => {
|
||||||
|
const ctxData = createIteratorContentData(itemData, dsId, keys);
|
||||||
|
|
||||||
|
if (condDeps[item.id]?.keys.length) {
|
||||||
|
item.condResult = compliedConditions(item, ctxData);
|
||||||
|
}
|
||||||
|
|
||||||
if (!deps[item.id]?.keys.length) {
|
if (!deps[item.id]?.keys.length) {
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!inEditor) {
|
||||||
|
item.condResult = compliedConditions(item, itemData);
|
||||||
|
}
|
||||||
|
|
||||||
return compiledNode(
|
return compiledNode(
|
||||||
(value: any) => {
|
(value: any) => compiledNodeField(value, ctxData),
|
||||||
const ctxData = createIteratorContentData(itemData, dsId, keys);
|
|
||||||
return compiledNodeField(value, ctxData);
|
|
||||||
},
|
|
||||||
cloneDeep(item),
|
cloneDeep(item),
|
||||||
{
|
{
|
||||||
[dsId]: deps,
|
[dsId]: deps,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user