@cloudbase/framework-plugin-low-code 1.0.3-beta.9 → 1.0.5
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/lib/builder/mp/lowcode.d.ts.map +1 -1
- package/lib/builder/mp/lowcode.js +3 -7
- package/lib/builder/service/builder/generate.d.ts.map +1 -1
- package/lib/builder/service/builder/generate.js +3 -0
- package/lib/generator/core/generate.d.ts.map +1 -1
- package/lib/generator/core/generate.js +11 -17
- package/lib/utils/dataSource.d.ts +4 -0
- package/lib/utils/dataSource.d.ts.map +1 -1
- package/lib/utils/dataSource.js +27 -12
- package/lib/weapps-core/utils/file.d.ts +1 -1
- package/package.json +3 -3
- package/template/src/app/common.js +0 -13
- package/template/src/app/global-api.js +0 -132
- package/template/src/app/handlers.js +0 -13
- package/template/src/app/material-actions.js +0 -16
- package/template/src/app/mountAppApis.js +0 -25
- package/template/src/app/mountMpApis.js +0 -4
- package/template/src/datasources/config.js.tpl +0 -27
- package/template/src/datasources/dataset-profiles.js.tpl +0 -5
- package/template/src/datasources/datasource-profiles.js.tpl +0 -4
- package/template/src/datasources/index.js.tpl +0 -27
- package/template/src/handlers/FieldMiddleware/renderer.jsx +0 -536
- package/template/src/handlers/HotAreas.js +0 -36
- package/template/src/handlers/PositionHandler.jsx +0 -8
- package/template/src/handlers/actionHandler/utils.js +0 -154
- package/template/src/handlers/componentEventActionEmitter.js +0 -29
- package/template/src/handlers/componentNodeMap.js +0 -24
- package/template/src/handlers/controller.js +0 -5
- package/template/src/handlers/emitComponentEvent.js +0 -8
- package/template/src/handlers/eventListener/componentEventListener.js +0 -15
- package/template/src/handlers/eventListener/hotAreaEventListener.js +0 -32
- package/template/src/handlers/eventListener/index.js +0 -29
- package/template/src/handlers/eventListener/pageEventListener.js +0 -11
- package/template/src/handlers/eventListener/types.js +0 -32
- package/template/src/handlers/hooks/index.js +0 -15
- package/template/src/handlers/initWebEnv.js +0 -4
- package/template/src/handlers/injectStyle.js +0 -14
- package/template/src/handlers/instanceMap.js +0 -39
- package/template/src/handlers/lifecycle.js +0 -222
- package/template/src/handlers/render.jsx +0 -170
- package/template/src/handlers/utils/common.js +0 -298
- package/template/src/handlers/utils/eventProxy.js +0 -64
- package/template/src/handlers/utils/events.js +0 -8
- package/template/src/handlers/utils/index.js +0 -4
- package/template/src/handlers/utils/widgets.js +0 -307
- package/template/src/index.jsx +0 -185
- package/template/src/index.less +0 -119
- package/template/src/libraries/default-lib/wx_yypt_report_v2.js +0 -441
- package/template/src/pages/app.tpl +0 -200
- package/template/src/pages/composite.tpl +0 -171
- package/template/src/router/index.tpl +0 -29
- package/template/src/store/computed.js +0 -11
- package/template/src/store/index.js +0 -40
- package/template/src/utils/formatEnum.js +0 -42
- package/template/src/utils/history.js +0 -66
- package/template/src/utils/index.js +0 -82
- package/template/src/utils/kbone.js +0 -18
- package/template/src/utils/monitor-jssdk.min.js +0 -763
- package/template/src/utils/request.js +0 -5
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import { resolveDataBinds } from '../utils/common';
|
|
2
|
-
import { set as lodashSet } from 'lodash';
|
|
3
|
-
|
|
4
|
-
const DEFAULT_MAX_TIMEOUT = 10 * 1000;
|
|
5
|
-
|
|
6
|
-
export function getMetaInfoBySourceKey(sourceKey) {
|
|
7
|
-
const [materialName, name] = sourceKey.split(':');
|
|
8
|
-
return {
|
|
9
|
-
materialName,
|
|
10
|
-
name,
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function emitEvent(trigger, listeners = [], args, scopeContext = {}, context) {
|
|
15
|
-
const targetListeners = listeners.filter((l) => l.trigger === trigger);
|
|
16
|
-
targetListeners.forEach(async (listener) => {
|
|
17
|
-
// 当前非捕获Event,再判断冒泡行为
|
|
18
|
-
if (!args?.event?.isCapturePhase && listener.noPropagation) {
|
|
19
|
-
args?.customEventData?.stopPropagation();
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// 判断捕获的执行,只有执行的捕获与配置的捕获一致时。才会执行。
|
|
23
|
-
if ((listener?.isCapturePhase || false) === (args?.customEventData?.isCapturePhase || false)) {
|
|
24
|
-
try {
|
|
25
|
-
const res = await invokeListener(listener, args, scopeContext, context);
|
|
26
|
-
const eventName = `${listener.key}.success`;
|
|
27
|
-
const event = {
|
|
28
|
-
detail:
|
|
29
|
-
typeof res === 'object' && res !== null && !Array.isArray(res)
|
|
30
|
-
? {
|
|
31
|
-
/**
|
|
32
|
-
* @deprecated 历史bug
|
|
33
|
-
* value
|
|
34
|
-
*/
|
|
35
|
-
value: res,
|
|
36
|
-
...res,
|
|
37
|
-
}
|
|
38
|
-
: res,
|
|
39
|
-
origin: args.event,
|
|
40
|
-
isCapturePhase: !!args.event?.isCapturePhase,
|
|
41
|
-
name: eventName,
|
|
42
|
-
};
|
|
43
|
-
emitEvent(
|
|
44
|
-
eventName,
|
|
45
|
-
listeners,
|
|
46
|
-
{
|
|
47
|
-
...args,
|
|
48
|
-
event,
|
|
49
|
-
customEventData: event,
|
|
50
|
-
},
|
|
51
|
-
scopeContext,
|
|
52
|
-
context,
|
|
53
|
-
);
|
|
54
|
-
if (res) {
|
|
55
|
-
console.warn(
|
|
56
|
-
`@deprecated 事件编排中后续事件(${eventName}) event.detail.value.xxx 已废弃,建议使用 event.detail 直接访问前一动作返回值`,
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
} catch (e) {
|
|
60
|
-
const eventName = `${listener.key}.fail`;
|
|
61
|
-
try {
|
|
62
|
-
e.value = e;
|
|
63
|
-
e.origin = args.event;
|
|
64
|
-
e.isCapturePhase = !!args.event?.isCapturePhase;
|
|
65
|
-
} catch (e) {}
|
|
66
|
-
const event = {
|
|
67
|
-
detail: e,
|
|
68
|
-
origin: args.event,
|
|
69
|
-
isCapturePhase: !!args.event?.isCapturePhase,
|
|
70
|
-
name: eventName,
|
|
71
|
-
};
|
|
72
|
-
emitEvent(
|
|
73
|
-
eventName,
|
|
74
|
-
listeners,
|
|
75
|
-
{
|
|
76
|
-
...args,
|
|
77
|
-
event,
|
|
78
|
-
customEventData: event,
|
|
79
|
-
},
|
|
80
|
-
scopeContext,
|
|
81
|
-
context,
|
|
82
|
-
);
|
|
83
|
-
console.warn(
|
|
84
|
-
`@deprecated 事件编排中后续事件(${eventName}) event.detail.value.xxx 已废弃,建议使用 event.detail 直接访问前一动作返回值`,
|
|
85
|
-
);
|
|
86
|
-
// 之前 invoke 内部catch 了错误,不会抛错
|
|
87
|
-
// throw e
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
async function invokeListener({ instanceFunction, data = {}, dataBinds = {} }, args, scopeContext, context) {
|
|
94
|
-
// ToDo resolve databinds
|
|
95
|
-
const action = instanceFunction;
|
|
96
|
-
let maxTimeout = DEFAULT_MAX_TIMEOUT;
|
|
97
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
98
|
-
if (data._maxTimeout === 'Infinity') maxTimeout = data._maxTimeout;
|
|
99
|
-
const resolvedData = {
|
|
100
|
-
...data,
|
|
101
|
-
};
|
|
102
|
-
const resolvedDataBinds = resolveDataBinds(
|
|
103
|
-
dataBinds,
|
|
104
|
-
args.forItems,
|
|
105
|
-
{ event: args.event },
|
|
106
|
-
scopeContext,
|
|
107
|
-
true,
|
|
108
|
-
context,
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
112
|
-
for (const key in resolvedDataBinds) {
|
|
113
|
-
if (resolvedDataBinds[key] && resolvedDataBinds[key].__type === 'scopedValue') {
|
|
114
|
-
try {
|
|
115
|
-
lodashSet(resolvedData, key, resolvedDataBinds[key].getValue(scopeContext));
|
|
116
|
-
} catch (e) {
|
|
117
|
-
lodashSet(resolvedData, key, '');
|
|
118
|
-
}
|
|
119
|
-
} else {
|
|
120
|
-
lodashSet(resolvedData, key, resolvedDataBinds[key]);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const params = {
|
|
125
|
-
data: resolvedData,
|
|
126
|
-
...args,
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
try {
|
|
130
|
-
if (maxTimeout === 'Infinity') {
|
|
131
|
-
return await action(params);
|
|
132
|
-
}
|
|
133
|
-
const p = action(params);
|
|
134
|
-
if (p instanceof Promise) {
|
|
135
|
-
let timeout = null;
|
|
136
|
-
const r = await Promise.race([
|
|
137
|
-
new Promise((resolve, reject) => {
|
|
138
|
-
timeout = setTimeout(() => {
|
|
139
|
-
reject(new Error(`timeout in ${maxTimeout}ms`));
|
|
140
|
-
}, maxTimeout);
|
|
141
|
-
}),
|
|
142
|
-
p,
|
|
143
|
-
]);
|
|
144
|
-
if (timeout) {
|
|
145
|
-
clearTimeout(timeout);
|
|
146
|
-
}
|
|
147
|
-
return r;
|
|
148
|
-
}
|
|
149
|
-
return p;
|
|
150
|
-
} catch (e) {
|
|
151
|
-
console.error('Action error: ', e);
|
|
152
|
-
throw e;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
const actionCallbackMap = new Map();
|
|
2
|
-
|
|
3
|
-
export function onComponentEventAction({ key }, iEventName, callback) {
|
|
4
|
-
const eventName = `__weapps__component-event-${iEventName}`;
|
|
5
|
-
const map = getCallbackMap(key);
|
|
6
|
-
if (!map) {
|
|
7
|
-
return actionCallbackMap.set(key, new Map([[eventName, [callback]]]));
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const callbacks = map.get(eventName);
|
|
11
|
-
if (!callbacks) {
|
|
12
|
-
return map.set(eventName, [callback]);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
callbacks.push(callback);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function getCallbackMap(componentKey) {
|
|
19
|
-
return actionCallbackMap.get(componentKey);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function getComponentEventActionCallbacks(componentKey, eventName) {
|
|
23
|
-
const map = getCallbackMap(componentKey);
|
|
24
|
-
if (!map) {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return map.get(eventName);
|
|
29
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { getComponentId } from './utils/common';
|
|
2
|
-
|
|
3
|
-
export const componentNodeMap = new Map();
|
|
4
|
-
|
|
5
|
-
export function setComponentNode(key, node) {
|
|
6
|
-
return componentNodeMap.set(key, node);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function deleteComponentNode(key) {
|
|
10
|
-
return componentNodeMap.delete(key);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function getComponentNode(key) {
|
|
14
|
-
return componentNodeMap.get(key) || document.getElementById(getComponentId(key));
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
if (typeof window !== 'undefined') {
|
|
18
|
-
Object.defineProperty(window, '__componentInstanceNodeMap', {
|
|
19
|
-
get() {
|
|
20
|
-
return componentNodeMap;
|
|
21
|
-
},
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { getComponentEventActionCallbacks } from './componentEventActionEmitter';
|
|
2
|
-
|
|
3
|
-
export function emitComponentEvent({ data: { actionName }, target }) {
|
|
4
|
-
const callbacks = getComponentEventActionCallbacks(target.key, actionName);
|
|
5
|
-
if (callbacks) {
|
|
6
|
-
callbacks.forEach(callback => callback());
|
|
7
|
-
}
|
|
8
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { EventProxy } from '../utils/eventProxy';
|
|
2
|
-
|
|
3
|
-
const componentEvents = new EventProxy();
|
|
4
|
-
|
|
5
|
-
export function onComponent(eventType, callback) {
|
|
6
|
-
componentEvents.on(eventType, callback);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function emitComponent(eventType, schema) {
|
|
10
|
-
componentEvents.emit(eventType, {
|
|
11
|
-
key: schema.key,
|
|
12
|
-
sourceKey: schema['x-component']
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { EventProxy } from '../utils/eventProxy';
|
|
2
|
-
|
|
3
|
-
const hotAreaEventListeners = new EventProxy();
|
|
4
|
-
|
|
5
|
-
export function onHotArea(eventType, callback) {
|
|
6
|
-
hotAreaEventListeners.on(eventType, callback);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function emitHotArea(eventType, hotArea, instance, meta, global) {
|
|
10
|
-
// eslint-disable-next-line
|
|
11
|
-
const params = getHotAreaEventListenerCallbackParams(hotArea, instance, global, meta);
|
|
12
|
-
hotAreaEventListeners.emit(eventType, params);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function getHotAreaEventListenerCallbackParams(
|
|
16
|
-
{ key, position, size },
|
|
17
|
-
{ key: componentKey, sourceKey },
|
|
18
|
-
global,
|
|
19
|
-
meta
|
|
20
|
-
) {
|
|
21
|
-
return {
|
|
22
|
-
global,
|
|
23
|
-
meta,
|
|
24
|
-
hotArea: {
|
|
25
|
-
key,
|
|
26
|
-
position,
|
|
27
|
-
size,
|
|
28
|
-
},
|
|
29
|
-
sourceKey,
|
|
30
|
-
componentKey
|
|
31
|
-
};
|
|
32
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { EventListenerTarget } from './types';
|
|
2
|
-
import { onComponent } from './componentEventListener';
|
|
3
|
-
import { onPage } from './pageEventListener';
|
|
4
|
-
import { onHotArea } from './hotAreaEventListener';
|
|
5
|
-
|
|
6
|
-
export function on(target, eventType, callback) {
|
|
7
|
-
switch (target) {
|
|
8
|
-
case EventListenerTarget.PAGE: {
|
|
9
|
-
return onPage(eventType, callback);
|
|
10
|
-
}
|
|
11
|
-
case EventListenerTarget.COMPONENT: {
|
|
12
|
-
return onComponent(eventType, callback);
|
|
13
|
-
}
|
|
14
|
-
case EventListenerTarget.HOT_AREA: {
|
|
15
|
-
return onHotArea(eventType, callback);
|
|
16
|
-
}
|
|
17
|
-
default: {
|
|
18
|
-
// eslint-disable-next-line
|
|
19
|
-
throw `Invalid [target], must one of '${EventListenerTarget.PAGE}', '${
|
|
20
|
-
EventListenerTarget.COMPONENT
|
|
21
|
-
}', '${EventListenerTarget.HOT_AREA}'`;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export * from './pageEventListener';
|
|
27
|
-
export * from './componentEventListener';
|
|
28
|
-
export * from './hotAreaEventListener';
|
|
29
|
-
export * from './types';
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { EventProxy } from '../utils/eventProxy';
|
|
2
|
-
|
|
3
|
-
const pageEvents = new EventProxy();
|
|
4
|
-
|
|
5
|
-
export function onPage(eventType, callback) {
|
|
6
|
-
pageEvents.on(eventType, callback);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function emitPage(eventType, params) {
|
|
10
|
-
pageEvents.emit(eventType, params);
|
|
11
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
export const EventListenerTarget = {
|
|
2
|
-
PAGE: 'page',
|
|
3
|
-
COMPONENT: 'component',
|
|
4
|
-
HOT_AREA: 'hotarea',
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @desc Page Events
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
export const PageEventListenerTypes = {
|
|
12
|
-
INIT: 'afterRender',
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @desc Component Events
|
|
17
|
-
*/
|
|
18
|
-
export const ComponentEventListenerTypes = {
|
|
19
|
-
INIT: 'afterRender',
|
|
20
|
-
CLICK: 'click',
|
|
21
|
-
MOUSE_ENTER: 'mouseEnter',
|
|
22
|
-
MOUSE_LEAVE: 'mouseLeave',
|
|
23
|
-
DOUBLE_CLICK: 'doubleClick',
|
|
24
|
-
LONG_PRESS: 'longPress',
|
|
25
|
-
ENTER_VIEW: 'enterView',
|
|
26
|
-
LEAVE_VIEW: 'leaveView',
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* @desc HotArea Events
|
|
31
|
-
*/
|
|
32
|
-
export const HotAreaEventListenerTypes = ComponentEventListenerTypes;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { useLocation } from 'react-router-dom';
|
|
3
|
-
|
|
4
|
-
export function useScrollTop() {
|
|
5
|
-
const { pathname } = useLocation();
|
|
6
|
-
React.useEffect(() => {
|
|
7
|
-
// window.scrollTo({
|
|
8
|
-
// top: 0,
|
|
9
|
-
// left: 0,
|
|
10
|
-
// behavior: 'auto',
|
|
11
|
-
// });
|
|
12
|
-
window.scrollTo(0, 0);
|
|
13
|
-
}, [pathname]);
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export function injectStyle(content, className) {
|
|
2
|
-
if (typeof window === 'undefined') {
|
|
3
|
-
return;
|
|
4
|
-
}
|
|
5
|
-
if (!content.toString().trim()) {
|
|
6
|
-
return;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const style = document.createElement('style');
|
|
10
|
-
style.setAttribute('type', 'text/css');
|
|
11
|
-
style.setAttribute('class', className);
|
|
12
|
-
style.innerHTML = content;
|
|
13
|
-
document.head.appendChild(style);
|
|
14
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
let instances = null;
|
|
2
|
-
const componentInstanceIndexMap = new Map();
|
|
3
|
-
|
|
4
|
-
export function initComponentInstanceIndexMap(componentInstances) {
|
|
5
|
-
instances = componentInstances;
|
|
6
|
-
return generateComponentInstanceIndexMap(instances);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function generateComponentInstanceIndexMap() {
|
|
10
|
-
componentInstanceIndexMap.clear();
|
|
11
|
-
instances.forEach(({ key, children }, index) => {
|
|
12
|
-
if (children) {
|
|
13
|
-
children.forEach(({ key }, childIndex) => setComponentInstanceIndex(key, childIndex, index));
|
|
14
|
-
}
|
|
15
|
-
setComponentInstanceIndex(key, index);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
function setComponentInstanceIndex(key, index, parentIndex) {
|
|
19
|
-
return componentInstanceIndexMap.set(key, { index, parentIndex });
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function getComponentInstanceIndex(key) {
|
|
24
|
-
return componentInstanceIndexMap.get(key);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function getComponentInstance(key) {
|
|
28
|
-
const iIndex = getComponentInstanceIndex(key);
|
|
29
|
-
if (!iIndex) {
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const { index, parentIndex } = iIndex;
|
|
34
|
-
let componentInstances = instances;
|
|
35
|
-
if (typeof parentIndex === 'number') {
|
|
36
|
-
componentInstances = componentInstances[parentIndex].children;
|
|
37
|
-
}
|
|
38
|
-
return componentInstances[index];
|
|
39
|
-
}
|
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
2
|
-
/**
|
|
3
|
-
* 生命周期处理函数
|
|
4
|
-
*/
|
|
5
|
-
import { throttle } from 'lodash';
|
|
6
|
-
import { wx } from '@tcwd/weapps-sdk';
|
|
7
|
-
import * as querystring from 'querystring';
|
|
8
|
-
// 小程序 端使用lifeCycle
|
|
9
|
-
|
|
10
|
-
export function initLifeCycle(
|
|
11
|
-
{
|
|
12
|
-
onAppLaunch = () => {},
|
|
13
|
-
onAppShow = () => {},
|
|
14
|
-
onAppHide = () => {},
|
|
15
|
-
onAppError = () => {},
|
|
16
|
-
onAppPageNotFound = () => {},
|
|
17
|
-
onAppUnhandledRejection = () => {},
|
|
18
|
-
beforeCustomLaunch = (query) => {},
|
|
19
|
-
|
|
20
|
-
onPageLoad = () => {},
|
|
21
|
-
onPageShow = () => {},
|
|
22
|
-
onPageReady = () => {},
|
|
23
|
-
onPageHide = () => {},
|
|
24
|
-
onPageUnload = () => {},
|
|
25
|
-
beforePageCustomLaunch = (query) => {},
|
|
26
|
-
onPullDownRefresh,
|
|
27
|
-
onReachBottom,
|
|
28
|
-
onShareAppMessage,
|
|
29
|
-
onPageScroll,
|
|
30
|
-
onResize,
|
|
31
|
-
onAddToFavorites,
|
|
32
|
-
onShareTimeline,
|
|
33
|
-
onTabItemTap,
|
|
34
|
-
},
|
|
35
|
-
app,
|
|
36
|
-
mainApp,
|
|
37
|
-
) {
|
|
38
|
-
if (!process.env.isMiniprogram) {
|
|
39
|
-
window.$$global = window.$$global || {};
|
|
40
|
-
}
|
|
41
|
-
// 包装应用显示回掉, 增加取数据变量值逻辑
|
|
42
|
-
const onAppLaunchCb = (...args) => {
|
|
43
|
-
beforeCustomLaunch(...args);
|
|
44
|
-
onAppLaunch(...args);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
// 包装页面加载回掉, 增加取数据变量值逻辑
|
|
48
|
-
const onPageLoadCb = (...args) => {
|
|
49
|
-
beforePageCustomLaunch(...args);
|
|
50
|
-
onPageLoad(...args);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
// 应用级别事件监听
|
|
54
|
-
if (!window.$$global.alreadyInitAppLifeCycle) {
|
|
55
|
-
if (!window.$$global.isOnLaunchRunned) {
|
|
56
|
-
onAppLaunchCb(wx.getLaunchOptionsSync());
|
|
57
|
-
window.$$global.isOnLaunchRunned = true;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
mainApp.onAppShow && mainApp.onAppShow(onAppShow);
|
|
61
|
-
mainApp.onAppHide && mainApp.onAppHide(onAppHide);
|
|
62
|
-
mainApp.onError && mainApp.onError(onAppError);
|
|
63
|
-
mainApp.onPageNotFound && mainApp.onPageNotFound(onAppPageNotFound);
|
|
64
|
-
mainApp.onUnhandledRejection && mainApp.onUnhandledRejection(onAppUnhandledRejection);
|
|
65
|
-
|
|
66
|
-
// 预留等客户端来触发
|
|
67
|
-
window.addEventListener('appLaunch', (...args) => onAppLaunchCb(...args));
|
|
68
|
-
window.addEventListener('appShow', (...args) => onAppShow(...args));
|
|
69
|
-
window.addEventListener('appHide', (...args) => onAppHide(...args));
|
|
70
|
-
window.addEventListener('error', (...args) => onAppError(...args));
|
|
71
|
-
window.addEventListener('unhandledRejection', (...args) => onAppUnhandledRejection(...args));
|
|
72
|
-
window.$$global.alreadyInitAppLifeCycle = true;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// wx兼容的页面级别事件监听
|
|
76
|
-
if (process.env.isMiniprogram) {
|
|
77
|
-
window.addEventListener('wxload', (...args) => onPageLoadCb(...args));
|
|
78
|
-
window.addEventListener('wxshow', (...args) => onPageShow(...args));
|
|
79
|
-
window.addEventListener('wxready', (...args) => onPageReady(...args));
|
|
80
|
-
window.addEventListener('wxhide', (...args) => onPageHide(...args));
|
|
81
|
-
window.addEventListener('wxunload', (...args) => onPageUnload(...args));
|
|
82
|
-
// 页面级别特殊事件
|
|
83
|
-
if (typeof onPullDownRefresh === 'function') {
|
|
84
|
-
window.addEventListener('pulldownrefresh', (...args) => onPullDownRefresh(...args));
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (typeof onPageScroll === 'function') {
|
|
88
|
-
window.addEventListener('scroll', () => {
|
|
89
|
-
onPageScroll({
|
|
90
|
-
scrollTop: document.documentElement.scrollTop,
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (typeof onReachBottom === 'function') {
|
|
96
|
-
window.addEventListener('reachbottom', onReachBottom);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (typeof onShareAppMessage === 'function') {
|
|
100
|
-
window.onShareAppMessage = onShareAppMessage;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if (typeof onShareTimeline === 'function') {
|
|
104
|
-
window.onShareTimeline = onShareTimeline;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (typeof onAddToFavorites === 'function') {
|
|
108
|
-
window.onAddToFavorites = onAddToFavorites;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (typeof onResize === 'function') {
|
|
112
|
-
window.addEventListener('resize', onResize);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (typeof onTabItemTap === 'function') {
|
|
116
|
-
window.onTabItemTap = onTabItemTap;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
let isReachBottom = false;
|
|
122
|
-
// web 端使用lifeCycle
|
|
123
|
-
export function pageLifeCycleMount(
|
|
124
|
-
useEffect,
|
|
125
|
-
{
|
|
126
|
-
onPageLoad,
|
|
127
|
-
beforePageCustomLaunch,
|
|
128
|
-
onPageShow,
|
|
129
|
-
onPageReady,
|
|
130
|
-
onPageHide,
|
|
131
|
-
onPageUnload,
|
|
132
|
-
onPullDownRefresh,
|
|
133
|
-
onReachBottom,
|
|
134
|
-
onShareAppMessage,
|
|
135
|
-
onPageScroll,
|
|
136
|
-
onResize,
|
|
137
|
-
onAddToFavorites,
|
|
138
|
-
onShareTimeline,
|
|
139
|
-
onTabItemTap,
|
|
140
|
-
},
|
|
141
|
-
app = {},
|
|
142
|
-
extra = {},
|
|
143
|
-
) {
|
|
144
|
-
let queryText = location.href.split('?')[1];
|
|
145
|
-
let query = querystring.parse(queryText);
|
|
146
|
-
// 页面挂载时加载数据源变量值
|
|
147
|
-
typeof fetchPageDataVar === 'function' && fetchPageDataVar();
|
|
148
|
-
// 包装页面加载回掉, 增加取数据变量值逻辑
|
|
149
|
-
const onPageLoadCallback = (...args) => {
|
|
150
|
-
beforePageCustomLaunch(...args);
|
|
151
|
-
onPageLoad?.(...args);
|
|
152
|
-
};
|
|
153
|
-
useEffect(() => {
|
|
154
|
-
onPageLoadCallback(query);
|
|
155
|
-
typeof onPageReady === 'function' && onPageReady();
|
|
156
|
-
typeof onPageShow === 'function' && onPageShow();
|
|
157
|
-
|
|
158
|
-
if (typeof onPullDownRefresh === 'function') {
|
|
159
|
-
app.onPullDownRefresh(onPullDownRefresh);
|
|
160
|
-
}
|
|
161
|
-
if (typeof onPageScroll === 'function' || typeof onReachBottom === 'function') {
|
|
162
|
-
window.onscroll = throttle(() => {
|
|
163
|
-
// 变量scrollTop是滚动条滚动时,滚动条上端距离顶部的距离
|
|
164
|
-
let scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
|
|
165
|
-
|
|
166
|
-
// 变量windowHeight是可视区的高度
|
|
167
|
-
let windowHeight = document.documentElement.clientHeight || document.body.clientHeight;
|
|
168
|
-
|
|
169
|
-
// 变量scrollHeight是滚动条的总高度(当前可滚动的页面的总高度)
|
|
170
|
-
let scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight;
|
|
171
|
-
if (typeof onPageScroll === 'function') {
|
|
172
|
-
onPageScroll({
|
|
173
|
-
scrollTop: window.pageYOffset,
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// console.log(scrollTop, windowHeight, scrollTop + windowHeight, scrollHeight, isReachBottom)
|
|
178
|
-
//滚动条到底部
|
|
179
|
-
if (scrollTop + windowHeight >= scrollHeight - (extra.reachBottomDistance || 50)) {
|
|
180
|
-
//要进行的操作
|
|
181
|
-
if (!isReachBottom) {
|
|
182
|
-
isReachBottom = true;
|
|
183
|
-
if (typeof onReachBottom === 'function') {
|
|
184
|
-
onReachBottom();
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
} else {
|
|
188
|
-
isReachBottom = false;
|
|
189
|
-
}
|
|
190
|
-
}, 300);
|
|
191
|
-
}
|
|
192
|
-
// todo
|
|
193
|
-
if (typeof onShareAppMessage === 'function') {
|
|
194
|
-
window.onShareAppMessage = onShareAppMessage;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
if (typeof onResize === 'function') {
|
|
198
|
-
window.onresize = () => {
|
|
199
|
-
onResize({
|
|
200
|
-
size: {
|
|
201
|
-
windowWidth: window.innerWidth,
|
|
202
|
-
windowHeight: window.innerHeight,
|
|
203
|
-
},
|
|
204
|
-
});
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
return () => {
|
|
208
|
-
typeof onPageHide === 'function' && onPageHide({});
|
|
209
|
-
typeof onPageUnload === 'function' && onPageUnload({});
|
|
210
|
-
if (typeof onPullDownRefresh === 'function') {
|
|
211
|
-
app.offPullDownRefresh(onPullDownRefresh);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
window.onscroll = null;
|
|
215
|
-
window.onresize = null;
|
|
216
|
-
};
|
|
217
|
-
}, []);
|
|
218
|
-
}
|
|
219
|
-
export function initWebConfig(app, appConfig) {
|
|
220
|
-
// miniprogram.config 配置截取
|
|
221
|
-
app.setConfig(appConfig);
|
|
222
|
-
}
|