@oinone/kunlun-vue-widget 6.3.9 → 6.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/oinone-kunlun-vue-widget.esm.js +2 -2
- package/dist/types/src/basic/Widget.d.ts +25 -2
- package/dist/types/src/data/ActiveRecordsWidget.d.ts +18 -3
- package/dist/types/src/dsl/DslDefinitionWidget.d.ts +6 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/state/context.d.ts +41 -0
- package/dist/types/src/state/global.d.ts +4 -0
- package/dist/types/src/state/index.d.ts +3 -0
- package/dist/types/src/state/method/action.d.ts +18 -0
- package/dist/types/src/state/method/field.d.ts +3 -0
- package/dist/types/src/state/method/index.d.ts +2 -0
- package/dist/types/src/state/typing.d.ts +105 -0
- package/dist/types/src/state/use-state.d.ts +16 -0
- package/dist/types/src/state/view.d.ts +5 -0
- package/package.json +11 -11
- package/src/basic/VueWidget.ts +2 -2
- package/src/basic/Widget.ts +137 -23
- package/src/data/ActiveRecordsWidget.ts +72 -20
- package/src/dsl/DslDefinitionWidget.ts +27 -7
- package/src/index.ts +1 -0
- package/src/state/context.ts +57 -0
- package/src/state/global.ts +13 -0
- package/src/state/index.ts +3 -0
- package/src/state/method/action.ts +83 -0
- package/src/state/method/field.ts +56 -0
- package/src/state/method/index.ts +2 -0
- package/src/state/typing.ts +169 -0
- package/src/state/use-state.ts +44 -0
- package/src/state/view.ts +58 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { reactive } from 'vue';
|
|
2
|
+
|
|
3
|
+
export interface OioGlobalState {
|
|
4
|
+
fullscreen: boolean;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function createGlobalState(): OioGlobalState {
|
|
8
|
+
return reactive<OioGlobalState>({
|
|
9
|
+
fullscreen: false
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const globalState = createGlobalState();
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { DEFAULT_SLOT_NAME } from '@oinone/kunlun-dsl';
|
|
2
|
+
import { reactive } from 'vue';
|
|
3
|
+
import { Widget } from '../../basic';
|
|
4
|
+
import { executeInvisible, InvisibleSupported } from '../../feature';
|
|
5
|
+
import { hasActionBarViewState, hasRowActionBarViewState, OioActionBarState, OioAnyViewState } from '../typing';
|
|
6
|
+
|
|
7
|
+
export function createActionBarState(
|
|
8
|
+
this: OioAnyViewState,
|
|
9
|
+
options: {
|
|
10
|
+
handle: string;
|
|
11
|
+
} & Partial<Omit<OioActionBarState, 'handle'>>
|
|
12
|
+
) {
|
|
13
|
+
const state: OioActionBarState = {
|
|
14
|
+
actions: [],
|
|
15
|
+
visibleActions: [],
|
|
16
|
+
...options
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(state, 'visibleActions', {
|
|
19
|
+
get() {
|
|
20
|
+
return this.actions.filter((handle: string) => {
|
|
21
|
+
const widget = Widget.select<Widget & InvisibleSupported>(handle);
|
|
22
|
+
if (!widget) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
return !executeInvisible(widget);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
return reactive(state);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function getActionBarState(this: OioAnyViewState, rowIndex?: number): OioActionBarState | undefined {
|
|
33
|
+
if (rowIndex == null) {
|
|
34
|
+
const position = this.__position[this.__position.length - 1];
|
|
35
|
+
if (position == null) {
|
|
36
|
+
console.warn('Please call getActionBarState method in the vue lifecycle.');
|
|
37
|
+
return this.actionBar;
|
|
38
|
+
}
|
|
39
|
+
// fixme @zbh 20251205 rowIndex 无法准确设置,暂不可用
|
|
40
|
+
// const { slotName, rowIndex } = position;
|
|
41
|
+
const { slotName } = position;
|
|
42
|
+
if (!slotName || slotName === DEFAULT_SLOT_NAME) {
|
|
43
|
+
if (hasActionBarViewState(this)) {
|
|
44
|
+
return this.actionBar;
|
|
45
|
+
}
|
|
46
|
+
} else if (hasActionBarViewState(this)) {
|
|
47
|
+
return this.actionBars[slotName];
|
|
48
|
+
}
|
|
49
|
+
} else if (hasRowActionBarViewState(this)) {
|
|
50
|
+
return this.inlineActionBars?.[rowIndex];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function pushAction(this: OioAnyViewState, handle: string, rowIndex?: number) {
|
|
55
|
+
const actionBarState = this.getActionBarState(rowIndex);
|
|
56
|
+
if (!actionBarState) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const { actions } = actionBarState;
|
|
60
|
+
if (!actions) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (!actions.some((v) => v === handle)) {
|
|
64
|
+
actions.push(handle);
|
|
65
|
+
actionBarState.actions = [...actions];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function popAction(this: OioAnyViewState, handle: string, rowIndex?: number) {
|
|
70
|
+
const actionBarState = this.getActionBarState(rowIndex);
|
|
71
|
+
if (!actionBarState) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const { actions } = actionBarState;
|
|
75
|
+
if (!actions) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const index = actions.findIndex((v) => v === handle);
|
|
79
|
+
if (index !== -1) {
|
|
80
|
+
actions.splice(index, 1);
|
|
81
|
+
actionBarState.actions = [...actions];
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { hasFieldsViewState, isGalleryViewState, OioAnyViewState } from '../typing';
|
|
2
|
+
|
|
3
|
+
interface FieldState {
|
|
4
|
+
fields?: string[];
|
|
5
|
+
fieldWidgets?: Record<string, string>;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function getFieldsState(viewState: OioAnyViewState, rowIndex?: number): FieldState | undefined {
|
|
9
|
+
// fixme @zbh 20251205 rowIndex 无法准确设置,暂不可用
|
|
10
|
+
// const position = viewState.__position[viewState.__position.length - 1];
|
|
11
|
+
// if (position == null) {
|
|
12
|
+
// console.warn('Please call getFieldsState method in the vue lifecycle.');
|
|
13
|
+
// if (hasFieldsViewState(viewState)) {
|
|
14
|
+
// return viewState;
|
|
15
|
+
// }
|
|
16
|
+
// return undefined;
|
|
17
|
+
// }
|
|
18
|
+
// const { rowIndex } = position;
|
|
19
|
+
if (rowIndex == null) {
|
|
20
|
+
if (hasFieldsViewState(viewState)) {
|
|
21
|
+
return viewState;
|
|
22
|
+
}
|
|
23
|
+
} else if (isGalleryViewState(viewState)) {
|
|
24
|
+
return viewState.cards?.[rowIndex];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function pushField(this: OioAnyViewState, handle: string, rowIndex?: number): void {
|
|
29
|
+
const fieldsState = getFieldsState(this, rowIndex);
|
|
30
|
+
if (!fieldsState) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const { fields, fieldWidgets } = fieldsState;
|
|
34
|
+
if (fields) {
|
|
35
|
+
if (!fields.some((v) => v === handle)) {
|
|
36
|
+
fields.push(handle);
|
|
37
|
+
fieldsState.fields = [...fields];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function popField(this: OioAnyViewState, handle: string, rowIndex?: number): void {
|
|
43
|
+
const fieldsState = getFieldsState(this, rowIndex);
|
|
44
|
+
if (!fieldsState) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const { fields } = fieldsState;
|
|
48
|
+
if (!fields) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const index = fields.findIndex((v) => v === handle);
|
|
52
|
+
if (index !== -1) {
|
|
53
|
+
fields.splice(index, 1);
|
|
54
|
+
fieldsState.fields = [...fields];
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { ViewType } from '@oinone/kunlun-meta';
|
|
2
|
+
import { ButtonBizStyle, ButtonType } from '@oinone/kunlun-vue-ui-common';
|
|
3
|
+
|
|
4
|
+
type StateEntity = {
|
|
5
|
+
readonly handle: string;
|
|
6
|
+
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export interface RenderPosition {
|
|
11
|
+
handle: string;
|
|
12
|
+
slotName?: string;
|
|
13
|
+
rowIndex?: number; // fixme @zbh 20251205 rowIndex 无法准确设置,暂不可用
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface OioViewState extends StateEntity {
|
|
17
|
+
/**
|
|
18
|
+
* Vue生命周期时可能有值,用于获取渲染参数处理属性多态的问题
|
|
19
|
+
*/
|
|
20
|
+
__position: RenderPosition[];
|
|
21
|
+
|
|
22
|
+
fullscreen: boolean;
|
|
23
|
+
viewType?: ViewType;
|
|
24
|
+
popupScene?: string;
|
|
25
|
+
|
|
26
|
+
createActionBarState(options: { handle: string } & Partial<Omit<OioActionBarState, 'handle'>>): OioActionBarState;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 此获取方法仅能用在Vue生命周期,否则无法准确获取真实的ActionBar状态变量
|
|
30
|
+
*/
|
|
31
|
+
getActionBarState(rowIndex?: number): OioActionBarState | undefined;
|
|
32
|
+
|
|
33
|
+
pushField(handle: string, rowIndex?: number): void;
|
|
34
|
+
|
|
35
|
+
popField(handle: string, rowIndex?: number): void;
|
|
36
|
+
|
|
37
|
+
pushAction(handle: string, rowIndex?: number): void;
|
|
38
|
+
|
|
39
|
+
popAction(handle: string, rowIndex?: number): void;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface OioActionBarState extends StateEntity {
|
|
43
|
+
inline?: boolean;
|
|
44
|
+
actions: string[];
|
|
45
|
+
visibleActions: string[];
|
|
46
|
+
bizStyle?: string;
|
|
47
|
+
|
|
48
|
+
getActionBarBizStyle?(actionHandle: string): { type: ButtonType; bizStyle: ButtonBizStyle } | undefined;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface OioTableViewState extends OioViewState {
|
|
52
|
+
searchView?: string;
|
|
53
|
+
actionBar?: OioActionBarState;
|
|
54
|
+
actionBars?: Record<string, OioActionBarState>;
|
|
55
|
+
inlineActionBars?: OioActionBarState[];
|
|
56
|
+
table?: string;
|
|
57
|
+
fields?: string[];
|
|
58
|
+
fieldWidgets?: Record<string, string>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface OioSearchViewState extends OioViewState {
|
|
62
|
+
search?: string;
|
|
63
|
+
fields?: string[];
|
|
64
|
+
fieldWidgets?: Record<string, string>;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface OioFormViewState extends OioViewState {
|
|
68
|
+
draftCode?: string;
|
|
69
|
+
actionBar?: OioActionBarState;
|
|
70
|
+
actionBars?: Record<string, OioActionBarState>;
|
|
71
|
+
form?: string;
|
|
72
|
+
fields?: string[];
|
|
73
|
+
fieldWidgets?: Record<string, string>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface OioDetailViewState extends OioViewState {
|
|
77
|
+
actionBar?: OioActionBarState;
|
|
78
|
+
actionBars?: Record<string, OioActionBarState>;
|
|
79
|
+
detail?: string;
|
|
80
|
+
fields?: string[];
|
|
81
|
+
fieldWidgets?: Record<string, string>;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface OioCardState extends StateEntity {
|
|
85
|
+
titleProps?: Record<string, unknown>;
|
|
86
|
+
contentProps?: Record<string, unknown>;
|
|
87
|
+
|
|
88
|
+
fields?: string[];
|
|
89
|
+
fieldWidgets?: Record<string, string>;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface OioGalleryViewState extends OioViewState {
|
|
93
|
+
searchView?: string;
|
|
94
|
+
actionBar?: OioActionBarState;
|
|
95
|
+
inlineActionBars?: OioActionBarState[];
|
|
96
|
+
gallery?: string;
|
|
97
|
+
cards?: OioCardState[];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export interface OioTreeViewState extends OioViewState {
|
|
101
|
+
searchView?: string;
|
|
102
|
+
actionBar?: OioActionBarState;
|
|
103
|
+
tree?: string;
|
|
104
|
+
fields?: string[];
|
|
105
|
+
fieldWidgets?: Record<string, string>;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export type OioAnyViewState =
|
|
109
|
+
| OioTableViewState
|
|
110
|
+
| OioSearchViewState
|
|
111
|
+
| OioFormViewState
|
|
112
|
+
| OioDetailViewState
|
|
113
|
+
| OioGalleryViewState
|
|
114
|
+
| OioTreeViewState;
|
|
115
|
+
|
|
116
|
+
export type OioListViewState = OioTableViewState | OioGalleryViewState;
|
|
117
|
+
|
|
118
|
+
export type OioObjectViewState = OioFormViewState | OioDetailViewState | OioSearchViewState;
|
|
119
|
+
|
|
120
|
+
export function isTableViewState(state: OioAnyViewState): state is OioTableViewState {
|
|
121
|
+
return state.viewType === ViewType.Table;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function isSearchViewState(state: OioAnyViewState): state is OioSearchViewState {
|
|
125
|
+
return state.viewType === ViewType.Search;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function isFormViewState(state: OioAnyViewState): state is OioFormViewState {
|
|
129
|
+
return state.viewType === ViewType.Form;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function isDetailViewState(state: OioAnyViewState): state is OioDetailViewState {
|
|
133
|
+
return state.viewType === ViewType.Detail;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function isGalleryViewState(state: OioAnyViewState): state is OioGalleryViewState {
|
|
137
|
+
return state.viewType === ViewType.Gallery;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function isTreeViewState(state: OioAnyViewState): state is OioTreeViewState {
|
|
141
|
+
return state.viewType === ViewType.Tree;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function isListViewState(state: OioAnyViewState): state is OioListViewState {
|
|
145
|
+
return state.viewType === ViewType.Table || state.viewType === ViewType.Gallery;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export function isObjectViewState(state: OioAnyViewState): state is OioObjectViewState {
|
|
149
|
+
return state.viewType === ViewType.Form || state.viewType === ViewType.Detail || state.viewType === ViewType.Search;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function hasFieldsViewState(
|
|
153
|
+
state: OioAnyViewState
|
|
154
|
+
): state is OioTableViewState | OioFormViewState | OioDetailViewState {
|
|
155
|
+
const { viewType } = state;
|
|
156
|
+
return !!viewType && (viewType === ViewType.Table || viewType === ViewType.Form || viewType === ViewType.Detail);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function hasActionBarViewState(
|
|
160
|
+
state: OioAnyViewState
|
|
161
|
+
): state is OioTableViewState | OioFormViewState | OioDetailViewState | OioGalleryViewState | OioTreeViewState {
|
|
162
|
+
const { viewType } = state;
|
|
163
|
+
return !!viewType && viewType !== ViewType.Search;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export function hasRowActionBarViewState(state: OioAnyViewState): state is OioTableViewState | OioGalleryViewState {
|
|
167
|
+
const { viewType } = state;
|
|
168
|
+
return !!viewType && (viewType === ViewType.Table || viewType === ViewType.Gallery);
|
|
169
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { globalState, OioGlobalState } from './global';
|
|
2
|
+
import { OioAnyViewState } from './typing';
|
|
3
|
+
import { clearViewState, createViewState, getViewState, setViewState } from './view';
|
|
4
|
+
|
|
5
|
+
export function useOioState(): {
|
|
6
|
+
globalState: OioGlobalState;
|
|
7
|
+
viewState: OioAnyViewState | undefined;
|
|
8
|
+
|
|
9
|
+
createViewState: (handle: string) => OioAnyViewState;
|
|
10
|
+
getViewState: (handle: string) => OioAnyViewState | undefined;
|
|
11
|
+
clearViewState: (handle: string) => OioAnyViewState | undefined;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export function useOioState(handle: string): {
|
|
15
|
+
globalState: OioGlobalState;
|
|
16
|
+
viewState: OioAnyViewState | undefined;
|
|
17
|
+
|
|
18
|
+
createViewState: () => OioAnyViewState;
|
|
19
|
+
getViewState: () => OioAnyViewState | undefined;
|
|
20
|
+
clearViewState: () => OioAnyViewState | undefined;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export function useOioState(handle?: string) {
|
|
24
|
+
if (handle) {
|
|
25
|
+
return {
|
|
26
|
+
globalState,
|
|
27
|
+
viewState: getViewState(handle),
|
|
28
|
+
createViewState: () => {
|
|
29
|
+
const state = createViewState(handle);
|
|
30
|
+
setViewState(state);
|
|
31
|
+
return state;
|
|
32
|
+
},
|
|
33
|
+
getViewState: () => getViewState(handle),
|
|
34
|
+
clearViewState: () => clearViewState(handle)
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
globalState,
|
|
39
|
+
viewState: getViewState(),
|
|
40
|
+
createViewState,
|
|
41
|
+
getViewState,
|
|
42
|
+
clearViewState
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { reactive } from 'vue';
|
|
2
|
+
import { useInjectMetaContext } from './context';
|
|
3
|
+
import { createActionBarState, getActionBarState, popAction, popField, pushAction, pushField } from './method';
|
|
4
|
+
import { OioAnyViewState } from './typing';
|
|
5
|
+
|
|
6
|
+
const viewStateStorage: Record<string, OioAnyViewState> = {};
|
|
7
|
+
|
|
8
|
+
const viewStateMethods: Record<string, Function> = {
|
|
9
|
+
pushField,
|
|
10
|
+
popField,
|
|
11
|
+
createActionBarState,
|
|
12
|
+
getActionBarState,
|
|
13
|
+
pushAction,
|
|
14
|
+
popAction
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export function createViewState(handle: string): OioAnyViewState {
|
|
18
|
+
const state = {
|
|
19
|
+
get handle() {
|
|
20
|
+
return handle;
|
|
21
|
+
},
|
|
22
|
+
fullscreen: false
|
|
23
|
+
} as OioAnyViewState;
|
|
24
|
+
state.__position = [];
|
|
25
|
+
const proxy = reactive<OioAnyViewState>(state);
|
|
26
|
+
for (const [method, fn] of Object.entries(viewStateMethods)) {
|
|
27
|
+
state[method] = fn.bind(proxy);
|
|
28
|
+
}
|
|
29
|
+
return proxy;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function getViewState(handle?: string): OioAnyViewState | undefined {
|
|
33
|
+
if (!handle) {
|
|
34
|
+
handle = useInjectMetaContext()?.rootHandle.value;
|
|
35
|
+
if (!handle) {
|
|
36
|
+
console.warn('Invalid root handle.');
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return viewStateStorage[handle];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function setViewState(state: OioAnyViewState): void {
|
|
44
|
+
viewStateStorage[state.handle] = state;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function clearViewState(handle?: string): OioAnyViewState | undefined {
|
|
48
|
+
if (!handle) {
|
|
49
|
+
handle = useInjectMetaContext()?.rootHandle.value;
|
|
50
|
+
if (!handle) {
|
|
51
|
+
console.warn('Invalid root handle.');
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const state = viewStateStorage[handle];
|
|
56
|
+
delete viewStateStorage[handle];
|
|
57
|
+
return state;
|
|
58
|
+
}
|