Skip to content

Commit 031808f

Browse files
Merge pull request #3 from Little-LittleProgrammer/feature/1.1.2
Feature/1.1.2 完善 显示条件控制
1 parent ded650e commit 031808f

File tree

29 files changed

+717
-302
lines changed

29 files changed

+717
-302
lines changed

README.md

Lines changed: 458 additions & 124 deletions
Large diffs are not rendered by default.

apps/playground/components.d.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,13 @@ declare module 'vue' {
1010
CompList: typeof import('./src/components/classic/sidebar/comp-list/index.vue')['default']
1111
Preview: typeof import('./src/components/pagePreview/preview.vue')['default']
1212
PropsList: typeof import('./src/components/classic/sidebar/props-list/index.vue')['default']
13-
QAntdDrawer: typeof import('@quantum-design/vue3-antd-pc-ui/es')['QAntdDrawer']
14-
QAntdDropdown: typeof import('@quantum-design/vue3-antd-pc-ui/es')['QAntdDropdown']
1513
QAntdForm: typeof import('@quantum-design/vue3-antd-pc-ui/es')['QAntdForm']
1614
QAntdIcon: typeof import('@quantum-design/vue3-antd-pc-ui/es')['QAntdIcon']
1715
QAntdKeepAliveTabs: typeof import('@quantum-design/vue3-antd-pc-ui/es')['QAntdKeepAliveTabs']
1816
QAntdSearch: typeof import('@quantum-design/vue3-antd-pc-ui/es')['QAntdSearch']
1917
QAntdSetting: typeof import('@quantum-design/vue3-antd-pc-ui/es')['QAntdSetting']
20-
QAntdTable: typeof import('@quantum-design/vue3-antd-pc-ui/es')['QAntdTable']
21-
QAntdTableAction: typeof import('@quantum-design/vue3-antd-pc-ui/es')['QAntdTableAction']
2218
QAntdThemeModeButton: typeof import('@quantum-design/vue3-antd-pc-ui/es')['QAntdThemeModeButton']
2319
QBreadcrumb: typeof import('@quantum-design/vue3-pc-ui/es')['QBreadcrumb']
24-
QCodeEditor: typeof import('@quantum-design/vue3-pc-ui/es')['QCodeEditor']
2520
QLoading: typeof import('@quantum-design/vue3-pc-ui/es')['QLoading']
2621
QmAside: typeof import('./src/components/layout/qm-aside.vue')['default']
2722
QmAuthority: typeof import('./src/components/qm-authority/index.vue')['default']

apps/playground/src/views/editor/init-schemas.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,18 @@ export const testSchemasV2: ISchemasRoot = {
476476
event: 'openOverlay'
477477
}
478478
]
479-
}
479+
},
480+
ifShow: [
481+
{
482+
field: [
483+
'ds_2rp3',
484+
'commonNumber'
485+
],
486+
op: '>',
487+
value: 1001,
488+
range: []
489+
}
490+
]
480491
}
481492
]
482493
},

apps/quantum-docs/docs/theory/data-source.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -316,17 +316,12 @@ export function trigger(sourceManage: ISourceManage, dataSourceId: Id, fieldId?:
316316
```typescript
317317
// 在 App.vue 中监听 update-data 事件
318318
app?.dataSourceManager?.on('update-data', (nodes: ISchemasNode[], sourceId: string, data: any) => {
319-
// 创建页面配置的深拷贝
320-
const newPageConfig = js_utils_deep_copy(pageConfig.value);
321-
319+
// 直接在原有数据上进行更新,确保响应式系统能正确检测变化
322320
nodes.forEach((node) => {
323-
// 在拷贝的数据上进行更新
324-
replaceChildNode(node, [newPageConfig]);
321+
replaceChildNode(reactive(node) as ISchemasNode, [pageConfig.value as ISchemasNode]);
325322
});
326323

327-
// 重新赋值整个配置对象来触发响应式更新
328-
pageConfig.value = newPageConfig;
329-
updateKey.value++;
324+
console.log('最终的pageConfig', pageConfig.value);
330325

331326
if (!app) return;
332327

packages/core/src/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ interface IAppOptionsConfig {
3030
designWidth?: number; // 设计稿宽度
3131
ua?: string; // 用户代理字符串
3232
curPage?: Id; // 当前页面ID
33-
platform?: 'mobile' | 'pc'; // 平台类型
33+
platform?: 'mobile' | 'pc' | 'editor'; // 平台类型
3434
disabledFlexible?: boolean; // 是否禁用移动端适配
3535
transformStyle?: (style: Record<string, any>) => Record<string, any>; // 样式转换函数
3636
request?: IRequestFunction; // 自定义请求函数

packages/core/src/node.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { LowCodeRoot } from './app';
33
import { LowCodePage } from './page';
44
import { Subscribe, isFunction, isObject, compiledNode, isArray, stringToBoolean } from '@quantum-lowcode/utils';
55
import {template} from 'lodash-es';
6+
import { compliedConditions } from '@quantum-lowcode/data';
67

78
/**
89
* 节点构造选项接口
@@ -121,6 +122,9 @@ export class LowCodeNode extends Subscribe {
121122
});
122123
}
123124
}
125+
if (this.root.dataSourceManager?.data) {
126+
data.showResult = compliedConditions(data, this.root.dataSourceManager?.data);
127+
}
124128
}
125129
}
126130

packages/data-source/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ export {DataSourceManager} from './src/data-source-manager';
33
export {DataSource} from './src/data-source/base';
44
export {HttpDataSource} from './src/data-source/http';
55

6+
export { compliedConditions } from './src/utils/tools';
7+
68
export {createDataSourceManager} from './src';
79

810
export type * from './src/types';

packages/data-source/src/utils/deps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export function trigger(sourceManage: ISourceManage, dataSourceId: Id, fieldId?:
8080
js_utils_edit_attr(key, rawValue, curNode);
8181
break;
8282
case 'cond':
83-
// 触发条件依赖 TODO123
83+
// 触发条件依赖 TODO
8484
curNode.showResult = compliedConditions(curNode, data);
8585
break;
8686
default:

packages/data-source/src/utils/tools.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,37 @@ import type { ISchemasNode } from '@quantum-lowcode/schemas';
22
import { compliedCondition, isArray, js_utils_find_attr } from '@quantum-lowcode/utils';
33
import type { IDataSourceManagerData } from '../types';
44

5+
/**
6+
* 校验节点是否满足所有显示条件(ifShow),所有条件都满足才会显示
7+
* @param node 节点
8+
* @param data 所有数据源的数据
9+
* @returns 是否显示
10+
*/
511
export function compliedConditions(node: ISchemasNode, data: IDataSourceManagerData) {
6-
if (!node.ifShow || !isArray(node.ifShow) || !node.ifShow.length) return true;
7-
12+
if (!node.ifShow || !isArray(node.ifShow) || !node.ifShow.length || !data) return true;
813
for (const cond of node.ifShow) {
9-
let result = true;
10-
const { op, value, range, field, } = cond;
14+
const { op, value, range, field } = cond;
15+
16+
if (!field || !field.length) {
17+
return false;
18+
}
1119
const [sourceId, ...fid] = field;
20+
if (!sourceId) {
21+
return false;
22+
}
1223

1324
const dsData = data[sourceId];
1425

15-
if (!dsData || !field.length) {
16-
break;
26+
if (!dsData) {
27+
return false;
1728
}
1829

1930
const fieldValue = js_utils_find_attr(dsData, fid.join('.'));
2031

2132
if (!compliedCondition(op, fieldValue, value, range)) {
22-
result = false;
23-
break;
24-
}
25-
26-
if (result) {
27-
return true;
33+
return false;
2834
}
2935
}
3036

31-
return false;
37+
return true;
3238
}

packages/editor/src/components/layouts/nav-menu.vue

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
</template>
2828
</div>
2929
</slot>
30-
30+
3131
</div>
3232
<div class="q-editor-nav-menu-right">
3333
<slot name=right></slot>
@@ -42,15 +42,15 @@ import { NodeType } from '@quantum-lowcode/schemas';
4242
import { Divider, Button, Tooltip } from 'ant-design-vue';
4343
import { isFunction } from '@quantum-lowcode/utils';
4444
defineOptions({
45-
name: 'QEditorNavMenu',
45+
name: 'QEditorNavMenu'
4646
});
4747
4848
const props = withDefaults(
4949
defineProps<{
5050
btnList?: IMenuItem[];
5151
}>(),
5252
{
53-
btnList: () => [],
53+
btnList: () => []
5454
}
5555
);
5656
@@ -63,18 +63,18 @@ const workspaceCenter = computed((): number => uiService?.get('workspaceCenter')
6363
6464
const leftStyle = computed(() => {
6565
if (workspaceLeft.value === 1) {
66-
return {flex: 1}
66+
return {flex: 1};
6767
}
6868
return {
69-
width: workspaceLeft.value + 'px',
70-
}
71-
})
69+
width: workspaceLeft.value + 'px'
70+
};
71+
});
7272
const getCenterStyle = computed(() => {
73-
if (workspaceCenter.value === 1) {
74-
return { flex: 1 };
75-
}
76-
return { width: workspaceCenter.value + 'px' };
77-
});
73+
if (workspaceCenter.value === 1) {
74+
return { flex: 1 };
75+
}
76+
return { width: workspaceCenter.value + 'px' };
77+
});
7878
7979
const isMac = /mac os x/.test(navigator.userAgent.toLowerCase());
8080
const ctrl = isMac ? 'Command' : 'Ctrl';
@@ -86,7 +86,7 @@ function get_config(item: IMenuItem) {
8686
const config:IMenuButton[] = [];
8787
switch (item) {
8888
case '/':
89-
config.push({type: 'divider', });
89+
config.push({type: 'divider' });
9090
break;
9191
case 'zoom':
9292
config.push(
@@ -106,7 +106,7 @@ function get_config(item: IMenuItem) {
106106
onClick: () => {
107107
const node = services?.editorService.get('node');
108108
node && services?.editorService.delete(node);
109-
},
109+
}
110110
});
111111
break;
112112
case 'undo':
@@ -115,7 +115,7 @@ function get_config(item: IMenuItem) {
115115
icon: 'ArrowLeftOutlined',
116116
tooltip: `后退(${ctrl}+z)`,
117117
disabled: () => !services?.historyService.state.canUndo,
118-
onClick: () => services?.editorService.undo(),
118+
onClick: () => services?.editorService.undo()
119119
});
120120
break;
121121
case 'redo':
@@ -125,45 +125,45 @@ function get_config(item: IMenuItem) {
125125
icon: 'ArrowRightOutlined',
126126
tooltip: `前进(${ctrl}+Shift+z)`,
127127
disabled: () => !services?.historyService.state.canRedo,
128-
onClick: () => services?.editorService.redo(),
128+
onClick: () => services?.editorService.redo()
129129
});
130130
break;
131131
case 'zoom-in':
132132
config.push({
133133
type: 'button',
134134
icon: 'ZoomInOutlined',
135135
tooltip: `放大(${ctrl}+=)`,
136-
onClick: () => uiService?.zoom(0.1),
136+
onClick: () => uiService?.zoom(0.1)
137137
});
138138
break;
139139
case 'zoom-out':
140140
config.push({
141141
type: 'button',
142142
icon: 'ZoomOutOutlined',
143143
tooltip: `縮小(${ctrl}+-)`,
144-
onClick: () => uiService?.zoom(-0.1),
144+
onClick: () => uiService?.zoom(-0.1)
145145
});
146146
break;
147147
case 'scale-to-fit':
148148
config.push({
149149
type: 'button',
150150
icon: 'BorderInnerOutlined',
151151
tooltip: `缩放以适应(${ctrl}+0)`,
152-
onClick: async() => uiService?.set('zoom', await uiService.calcZoom()),
152+
onClick: async() => uiService?.set('zoom', await uiService.calcZoom())
153153
});
154154
break;
155155
case 'scale-to-original':
156156
config.push({
157157
type: 'button',
158158
icon: 'BorderOuterOutlined',
159159
tooltip: `缩放到实际大小(${ctrl}+1)`,
160-
onClick: () => uiService?.set('zoom', 1),
160+
onClick: () => uiService?.set('zoom', 1)
161161
});
162162
break;
163163
default:
164164
config.push({
165165
type: 'text',
166-
text: item,
166+
text: item
167167
});
168168
break;
169169
}

0 commit comments

Comments
 (0)