@steedos/standard-ui 2.5.0-beta.25 → 2.5.0-beta.26
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.
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: 殷亮辉 yinlianghui@hotoa.com
|
|
3
|
+
* @Date: 2023-05-16 17:00:38
|
|
4
|
+
* @LastEditors: 殷亮辉 yinlianghui@hotoa.com
|
|
5
|
+
* @LastEditTime: 2023-05-17 17:42:02
|
|
6
|
+
*/
|
|
7
|
+
var buttonTriggerHistoryPathsChange;
|
|
8
|
+
; (function () {
|
|
9
|
+
try {
|
|
10
|
+
var rootId = "steedosHistoryPathsRoot";
|
|
11
|
+
var modalRoot = document.getElementById(rootId);
|
|
12
|
+
if (!modalRoot) {
|
|
13
|
+
modalRoot = document.createElement('div');
|
|
14
|
+
modalRoot.setAttribute('id', rootId);
|
|
15
|
+
$("body")[0].appendChild(modalRoot);
|
|
16
|
+
}
|
|
17
|
+
const page = {
|
|
18
|
+
name: "pageSteedosHistoryPaths",
|
|
19
|
+
render_engine: "amis",
|
|
20
|
+
schema: {
|
|
21
|
+
name: "serviceSteedosHistoryPaths",
|
|
22
|
+
id: "serviceSteedosHistoryPaths",
|
|
23
|
+
type: "service",
|
|
24
|
+
className: "service-steedos-history-paths",
|
|
25
|
+
body: [{
|
|
26
|
+
"type": "button",
|
|
27
|
+
"label": "触发@history_paths.changed",
|
|
28
|
+
"name": "buttonTriggerHistoryPathsChange",
|
|
29
|
+
"className": "button-trigger-history-paths-change hidden",
|
|
30
|
+
"onEvent": {
|
|
31
|
+
"click": {
|
|
32
|
+
"actions": [
|
|
33
|
+
{
|
|
34
|
+
"actionType": "broadcast",
|
|
35
|
+
"args": {
|
|
36
|
+
"eventName": "@history_paths.changed"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}]
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
Meteor.startup(function () {
|
|
46
|
+
const root = $("#" + rootId)[0];
|
|
47
|
+
Tracker.autorun(function (c) {
|
|
48
|
+
if (Creator.steedosInit.get() && Creator.validated.get()) {
|
|
49
|
+
Steedos.Page.render(root, page, {});
|
|
50
|
+
const findVars = (obj, vars) => {
|
|
51
|
+
try {
|
|
52
|
+
return vars.length === vars.filter(function (item) {
|
|
53
|
+
return item.split(".").reduce(function (sum, n) {
|
|
54
|
+
return sum[n];
|
|
55
|
+
}, obj) !== undefined;
|
|
56
|
+
}).length;
|
|
57
|
+
}
|
|
58
|
+
catch (ex) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const waittingVars = ["SteedosUI.refs.serviceSteedosHistoryPaths.getComponentByName"];
|
|
63
|
+
Promise.all([
|
|
64
|
+
waitForThing(window, waittingVars, findVars)
|
|
65
|
+
]).then(() => {
|
|
66
|
+
var scope = SteedosUI.refs["serviceSteedosHistoryPaths"];
|
|
67
|
+
buttonTriggerHistoryPathsChange = scope.getComponentByName("serviceSteedosHistoryPaths.buttonTriggerHistoryPathsChange");
|
|
68
|
+
Object.assign(Steedos, {
|
|
69
|
+
goBack
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
} catch (error) {
|
|
77
|
+
console.error(error)
|
|
78
|
+
};
|
|
79
|
+
})();
|
|
80
|
+
|
|
81
|
+
const historyPathsStoreKey = "history_paths";
|
|
82
|
+
|
|
83
|
+
// 使用debounce防抖动函数,连续多次自动触发enter事件时,只需要捕获最后一次
|
|
84
|
+
FlowRouter.triggers.enter(debounce(function (context, redirect, stop) {
|
|
85
|
+
const path = context.path;
|
|
86
|
+
const params = context.params || {};
|
|
87
|
+
// const pathDef = context.route.pathDef;
|
|
88
|
+
const recordId = params.record_id;
|
|
89
|
+
if (recordId) {
|
|
90
|
+
// 触发广播事件,把当前path和params累加存入amis变量historyPaths中
|
|
91
|
+
pushHistoryPath(path, params);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
// 触发广播事件重围amis变量historyPaths值为空数组,并把当前path和params存入amis变量historyPaths中
|
|
95
|
+
resetHistoryPath(path, params);
|
|
96
|
+
}
|
|
97
|
+
triggerBroadcastHistoryPathsChanged(buttonTriggerHistoryPathsChange);
|
|
98
|
+
}, 200));
|
|
99
|
+
|
|
100
|
+
function goBack(){
|
|
101
|
+
let prevPath = popHistoryPath();
|
|
102
|
+
if(prevPath && prevPath.path){
|
|
103
|
+
FlowRouter.go(prevPath.path);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function popHistoryPath() {
|
|
108
|
+
var paths = getHistoryPaths() || [];
|
|
109
|
+
paths.pop();
|
|
110
|
+
setHistoryPaths(paths);
|
|
111
|
+
return paths[paths.length - 1];
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function pushHistoryPath(path, params) {
|
|
115
|
+
let paths = getHistoryPaths() || [];
|
|
116
|
+
let lastPath = paths && paths[paths.length - 1];
|
|
117
|
+
if(lastPath && lastPath.path === path){
|
|
118
|
+
// 点返回按钮执行goBack函数触发FlowRouter.triggers.enter从而进入该函数,此时lastPath肯定跟传入的path值一样,正好排除掉不重复加入paths
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
paths.push({ path, params });
|
|
122
|
+
setHistoryPaths(paths);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function resetHistoryPath(path, params) {
|
|
126
|
+
setHistoryPaths([{ path, params }]);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function getHistoryPaths() {
|
|
130
|
+
if (!window.historyPaths) {
|
|
131
|
+
var paths = sessionStorage.getItem(historyPathsStoreKey);
|
|
132
|
+
if (paths) {
|
|
133
|
+
window.historyPaths = JSON.parse(paths);
|
|
134
|
+
}else{
|
|
135
|
+
window.historyPaths = [];
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return window.historyPaths;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function setHistoryPaths(paths) {
|
|
142
|
+
window.historyPaths = paths;
|
|
143
|
+
sessionStorage.setItem(historyPathsStoreKey, JSON.stringify(paths));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function triggerBroadcastHistoryPathsChanged(button) {
|
|
147
|
+
if (button) {
|
|
148
|
+
button.props.dispatchEvent('click', {});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function debounce(fn, delay) {
|
|
153
|
+
let time = null;
|
|
154
|
+
return function (...args) {
|
|
155
|
+
if (time) {
|
|
156
|
+
clearTimeout(time);
|
|
157
|
+
}
|
|
158
|
+
time = setTimeout(() => {
|
|
159
|
+
fn.apply(this, args);
|
|
160
|
+
}, delay)
|
|
161
|
+
}
|
|
162
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steedos/standard-ui",
|
|
3
|
-
"version": "2.5.0-beta.
|
|
3
|
+
"version": "2.5.0-beta.26",
|
|
4
4
|
"main": "package.service.js",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
@@ -12,5 +12,5 @@
|
|
|
12
12
|
"description": "steedos package",
|
|
13
13
|
"repository": {},
|
|
14
14
|
"license": "MIT",
|
|
15
|
-
"gitHead": "
|
|
15
|
+
"gitHead": "8f62fb81db976cfd84586ee18ef6f1e7fbd6a599"
|
|
16
16
|
}
|