@steedos/standard-ui 2.4.18-beta.2 → 2.4.18
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,199 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: 殷亮辉 yinlianghui@hotoa.com
|
|
3
|
+
* @Date: 2023-05-16 17:00:38
|
|
4
|
+
* @LastEditors: 殷亮辉 yinlianghui@hotoa.com
|
|
5
|
+
* @LastEditTime: 2023-05-28 10:13:45
|
|
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
|
+
let historyPathsStoreKey = "history_paths";
|
|
82
|
+
|
|
83
|
+
// 使用debounce防抖动函数,连续多次自动触发enter事件时,只需要捕获最后一次
|
|
84
|
+
FlowRouter.triggers.enter(debounce(function (context, redirect, stop) {
|
|
85
|
+
if(!!window.opener){
|
|
86
|
+
// 记录详细页面点击右上角查看审批单等打开新窗口情况下,新窗口的history path继承了opener页面的history path,所以需要区别出来,否则会报错
|
|
87
|
+
historyPathsStoreKey = "history_paths_opener_level" + getOpenerLevel(window,0);
|
|
88
|
+
}
|
|
89
|
+
const path = context.path;
|
|
90
|
+
const params = context.params || {};
|
|
91
|
+
// const pathDef = context.route.pathDef;
|
|
92
|
+
const recordId = params.record_id;
|
|
93
|
+
if (recordId) {
|
|
94
|
+
// 触发广播事件,把当前path和params累加存入amis变量historyPaths中
|
|
95
|
+
pushHistoryPath(path, params);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
// 触发广播事件重围amis变量historyPaths值为空数组,并把当前path和params存入amis变量historyPaths中
|
|
99
|
+
resetHistoryPath(path, params);
|
|
100
|
+
}
|
|
101
|
+
triggerBroadcastHistoryPathsChanged(buttonTriggerHistoryPathsChange);
|
|
102
|
+
}, 200));
|
|
103
|
+
|
|
104
|
+
function goBack(){
|
|
105
|
+
let prevPath = popHistoryPath();
|
|
106
|
+
if(prevPath && prevPath.path){
|
|
107
|
+
FlowRouter.go(prevPath.path);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* 移除最后一个path,并且返回要返回的上一个path
|
|
113
|
+
* 如果是从推送通知中点开进入记录详细页面,则返回当前记录所属对象的列表页面
|
|
114
|
+
*/
|
|
115
|
+
function popHistoryPath() {
|
|
116
|
+
var paths = getHistoryPaths() || [];
|
|
117
|
+
let lastPath = paths && paths[paths.length - 1];
|
|
118
|
+
paths.pop();
|
|
119
|
+
setHistoryPaths(paths);
|
|
120
|
+
let prevPath = paths && paths[paths.length - 1];
|
|
121
|
+
if(!prevPath && lastPath){
|
|
122
|
+
// 如果是从推送通知中点开进入记录详细页面,在paths.pop()前的paths肯定只有当前记录详细页面的path
|
|
123
|
+
// 此时lastPath肯定是记录详细页面,值如以下格式:
|
|
124
|
+
/**{
|
|
125
|
+
"path": "/app/projects/project_program/view/6465c790f85da77bbccefbe6",
|
|
126
|
+
"params": {
|
|
127
|
+
"app_id": "projects",
|
|
128
|
+
"object_name": "project_program",
|
|
129
|
+
"record_id": "6465c790f85da77bbccefbe6"
|
|
130
|
+
}
|
|
131
|
+
}**/
|
|
132
|
+
prevPath = {
|
|
133
|
+
path: `/app/${lastPath.params.app_id || "-"}/${lastPath.params.object_name}`,
|
|
134
|
+
params: {
|
|
135
|
+
app_id: lastPath.params.app_id,
|
|
136
|
+
object_name: lastPath.params.object_name
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return prevPath;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function pushHistoryPath(path, params) {
|
|
144
|
+
let paths = getHistoryPaths() || [];
|
|
145
|
+
let lastPath = paths && paths[paths.length - 1];
|
|
146
|
+
if(lastPath && lastPath.path === path){
|
|
147
|
+
// 点返回按钮执行goBack函数触发FlowRouter.triggers.enter从而进入该函数,此时lastPath肯定跟传入的path值一样,正好排除掉不重复加入paths
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
paths.push({ path, params });
|
|
151
|
+
setHistoryPaths(paths);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function resetHistoryPath(path, params) {
|
|
155
|
+
setHistoryPaths([{ path, params }]);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function getHistoryPaths() {
|
|
159
|
+
if (!window.historyPaths) {
|
|
160
|
+
var paths = sessionStorage.getItem(historyPathsStoreKey);
|
|
161
|
+
if (paths) {
|
|
162
|
+
window.historyPaths = JSON.parse(paths);
|
|
163
|
+
}else{
|
|
164
|
+
window.historyPaths = [];
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return window.historyPaths;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function setHistoryPaths(paths) {
|
|
171
|
+
window.historyPaths = paths;
|
|
172
|
+
sessionStorage.setItem(historyPathsStoreKey, JSON.stringify(paths));
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function triggerBroadcastHistoryPathsChanged(button) {
|
|
176
|
+
if (button) {
|
|
177
|
+
button.props.dispatchEvent('click', {});
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function debounce(fn, delay) {
|
|
182
|
+
let time = null;
|
|
183
|
+
return function (...args) {
|
|
184
|
+
if (time) {
|
|
185
|
+
clearTimeout(time);
|
|
186
|
+
}
|
|
187
|
+
time = setTimeout(() => {
|
|
188
|
+
fn.apply(this, args);
|
|
189
|
+
}, delay)
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function getOpenerLevel(opener,level){
|
|
194
|
+
if (!!opener['opener']) {
|
|
195
|
+
return getOpenerLevel(opener['opener'], level + 1);
|
|
196
|
+
}else{
|
|
197
|
+
return level;
|
|
198
|
+
}
|
|
199
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steedos/standard-ui",
|
|
3
|
-
"version": "2.4.18
|
|
3
|
+
"version": "2.4.18",
|
|
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": "98ae279a56e6ffaf6bebaebd83f8beaed4031492"
|
|
16
16
|
}
|