efront 3.10.3 → 3.10.4
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/coms/basic/_cross.js +28 -18
- package/coms/basic/cookie.js +1 -0
- package/coms/compile/common.js +3 -0
- package/coms/compile/scanner2.js +3 -0
- package/coms/reptile/cross.js +52 -11
- package/coms/zimoli/cross.js +1 -1
- package/coms/zimoli/selectList.js +3 -3
- package/coms/zimoli/selectList.less +13 -1
- package/coms/zimoli/view.less +1 -1
- package/package.json +1 -1
- package/public/efront.js +1 -1
package/coms/basic/_cross.js
CHANGED
|
@@ -42,10 +42,13 @@ var getCrossUrl = function (domain, headers) {
|
|
|
42
42
|
.replace(domainReg, base + `*${/^(https\:|s\/\/)/i.test(domain) ? "*" : ""}$2${_headers}/$3$4`);
|
|
43
43
|
};
|
|
44
44
|
function noop() { }
|
|
45
|
-
|
|
45
|
+
function toResponse() {
|
|
46
|
+
if (this.responseType === 'json') return JSON.stringify(this.response);
|
|
47
|
+
return this.response;
|
|
48
|
+
}
|
|
46
49
|
function _cross(jsonp, digest = noop, method, url, headers) {
|
|
47
50
|
var originDomain = getDomainPath(url);
|
|
48
|
-
if (!originDomain) throw new Error("
|
|
51
|
+
if (!originDomain) throw new Error("路径格式错误!");
|
|
49
52
|
var _cookies = getCookies(originDomain);
|
|
50
53
|
var _headers = {};
|
|
51
54
|
if (_cookies) {
|
|
@@ -59,24 +62,24 @@ function _cross(jsonp, digest = noop, method, url, headers) {
|
|
|
59
62
|
method = method.slice(1);
|
|
60
63
|
}
|
|
61
64
|
var loaded, errored;
|
|
62
|
-
var onload = function (
|
|
65
|
+
var onload = function (data) {
|
|
63
66
|
removeFromList(requests, xhr);
|
|
64
67
|
if (xhr.decoder) {
|
|
65
|
-
|
|
68
|
+
data = xhr.decoder(data);
|
|
66
69
|
}
|
|
67
|
-
loaded =
|
|
70
|
+
loaded = data;
|
|
68
71
|
flush();
|
|
69
72
|
digest();
|
|
70
73
|
};
|
|
71
74
|
var onerror1 = function (e) {
|
|
72
|
-
removeFromList(requests,
|
|
75
|
+
removeFromList(requests, xhr);
|
|
73
76
|
errored = e || "未知错误!";
|
|
74
77
|
flush();
|
|
75
78
|
digest();
|
|
76
79
|
};
|
|
77
80
|
var onerror = async function (e) {
|
|
78
81
|
if (e.type === 'error') {
|
|
79
|
-
e = {
|
|
82
|
+
e = { response: "无法访问服务器", toString: toResponse };
|
|
80
83
|
}
|
|
81
84
|
for (var r of reforms) {
|
|
82
85
|
var r = await reform(r, { method, url, status: xhr.status, headers: _headers }, fire, onerror1, e);
|
|
@@ -103,23 +106,28 @@ function _cross(jsonp, digest = noop, method, url, headers) {
|
|
|
103
106
|
});
|
|
104
107
|
var xhr = jsonp(url, {
|
|
105
108
|
[cb](a) {
|
|
106
|
-
|
|
107
|
-
onload(xhr);
|
|
109
|
+
onload({ status: 200, response: JSON.stringify(a), toString: toResponse });
|
|
108
110
|
}
|
|
109
111
|
});
|
|
110
112
|
xhr.onerror = onerror;
|
|
111
113
|
}
|
|
112
114
|
else {
|
|
113
115
|
var nocross = notCross(url);
|
|
114
|
-
var callback = function (
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
var callback = function () {
|
|
117
|
+
var exposeHeaders = xhr.getResponseHeader("access-control-expose-headers");
|
|
118
|
+
var exposeMap = {};
|
|
119
|
+
if (exposeHeaders) exposeHeaders.split(",").forEach(h => exposeMap[h.toLowerCase()] = true);
|
|
120
|
+
if (xhr.getResponseHeader) {
|
|
121
|
+
var exposekey = nocross ? "set-cookie" : "efront-cookie";
|
|
122
|
+
if (exposeMap[exposekey]) {
|
|
123
|
+
var cookie = xhr.getResponseHeader(exposekey);
|
|
124
|
+
addCookie(cookie, originDomain);
|
|
125
|
+
}
|
|
118
126
|
}
|
|
119
|
-
switch (status) {
|
|
127
|
+
switch (xhr.status) {
|
|
120
128
|
case 0:
|
|
121
|
-
if (!response) {
|
|
122
|
-
onerror({ status: "无法访问服务器" });
|
|
129
|
+
if (!xhr.response) {
|
|
130
|
+
onerror({ status: 0, response: "无法访问服务器", toString: toResponse });
|
|
123
131
|
break;
|
|
124
132
|
}
|
|
125
133
|
case 200:
|
|
@@ -130,8 +138,9 @@ function _cross(jsonp, digest = noop, method, url, headers) {
|
|
|
130
138
|
case 307:
|
|
131
139
|
case 302:
|
|
132
140
|
case 301:
|
|
133
|
-
if (xhr.isRedirected > 2
|
|
134
|
-
var
|
|
141
|
+
if (xhr.isRedirected > 2) break;
|
|
142
|
+
var exposekey = nocross ? "location" : "efront-location";
|
|
143
|
+
var location = exposeMap[exposekey] && xhr.getResponseHeader(exposekey);
|
|
135
144
|
if (!domainReg.test(location)) {
|
|
136
145
|
if (/^\//.test(location)) {
|
|
137
146
|
location = originDomain.replace(/\/.*$/, location);
|
|
@@ -152,6 +161,7 @@ function _cross(jsonp, digest = noop, method, url, headers) {
|
|
|
152
161
|
var cross = this;
|
|
153
162
|
var xhr = cross(callback, onerror);
|
|
154
163
|
var send = xhr.send;
|
|
164
|
+
xhr.toString = toResponse;
|
|
155
165
|
xhr.json = xhr.data = xhr.send = function (data, value) {
|
|
156
166
|
if (!jsondata && !(isEmpty(data) && isEmpty(value))) jsondata = data instanceof Array ? [] : {};
|
|
157
167
|
if (FormData && data instanceof FormData) {
|
package/coms/basic/cookie.js
CHANGED
|
@@ -24,6 +24,7 @@ var parseCookieFromText = function (cookie) {
|
|
|
24
24
|
|
|
25
25
|
function addCookie(cookie_text, originDomain = "") {
|
|
26
26
|
if (!cookie_text) return;
|
|
27
|
+
if (cookie_text instanceof Array) cookie_text = cookie_text.join(",");
|
|
27
28
|
var cookies = cookie_text.replace(/(^|;|,)\s*(expires)=(\w*),([^=]*)(;|$)/ig, "$1$2=$3.$4$5")
|
|
28
29
|
.split(/,\s*/).map(parseCookieFromText);
|
|
29
30
|
for (var cookie of cookies) {
|
package/coms/compile/common.js
CHANGED
package/coms/compile/scanner2.js
CHANGED
package/coms/reptile/cross.js
CHANGED
|
@@ -1,17 +1,45 @@
|
|
|
1
1
|
return _cross.bind(function (callback, onerror) {
|
|
2
|
-
var response;
|
|
2
|
+
var response, responseObject, responseType = "", error;
|
|
3
3
|
var xhr = {
|
|
4
4
|
status: 0,
|
|
5
|
+
readyState: 0,
|
|
5
6
|
method: null,
|
|
6
7
|
url: null,
|
|
7
8
|
http: null,
|
|
8
9
|
headers: {},
|
|
9
|
-
|
|
10
|
+
responseHeaders: {},
|
|
11
|
+
get response() {
|
|
12
|
+
if (responseType === "" || responseType === "text") {
|
|
13
|
+
if (this.readyState !== 4) return '';
|
|
14
|
+
return String(response);
|
|
15
|
+
}
|
|
16
|
+
else if (error) return null;
|
|
17
|
+
if (responseObject !== null) return responseObject;
|
|
18
|
+
switch (responseType) {
|
|
19
|
+
case "arraybuffer":
|
|
20
|
+
return response.buffer;
|
|
21
|
+
case "json":
|
|
22
|
+
if (!response) return null;
|
|
23
|
+
responseObject = JSON.parse(String(response));
|
|
24
|
+
return responseObject;
|
|
25
|
+
}
|
|
26
|
+
return responseObject;
|
|
27
|
+
|
|
28
|
+
},
|
|
29
|
+
set response(v) {
|
|
30
|
+
response = v;
|
|
31
|
+
},
|
|
10
32
|
getResponseHeader(key) {
|
|
11
|
-
|
|
33
|
+
key = String(key).toLowerCase();
|
|
34
|
+
if (this.responseHeaders[key]) return this.responseHeaders[key];
|
|
35
|
+
if (key === "access-control-expose-headers") {
|
|
36
|
+
return 'set-cookie,location';
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
12
39
|
},
|
|
13
40
|
send(data) {
|
|
14
41
|
var { hostname, port, path, auth } = parseURL(this.url);
|
|
42
|
+
if (data instanceof FormData) data = String(data);
|
|
15
43
|
if (data) {
|
|
16
44
|
data = Buffer.from(data);
|
|
17
45
|
this.headers["Content-Length"] = data.length;
|
|
@@ -25,24 +53,25 @@ return _cross.bind(function (callback, onerror) {
|
|
|
25
53
|
headers: this.headers,
|
|
26
54
|
}, function (res) {
|
|
27
55
|
var data = [];
|
|
28
|
-
var session_text = res.headers["set-cookie"];
|
|
29
|
-
if (session_text instanceof Array) session_text.forEach(t => cookie.addCookie(t));
|
|
30
|
-
else if (typeof session_text === "string") cookie.addCookie(session_text);
|
|
31
56
|
xhr.status = res.statusCode;
|
|
32
|
-
xhr.
|
|
57
|
+
xhr.responseHeaders = res.headers;
|
|
33
58
|
res.on("data", function (chunk) {
|
|
59
|
+
xhr.readyState = 4;
|
|
34
60
|
data.push(chunk);
|
|
35
61
|
});
|
|
36
62
|
res.on("end", function () {
|
|
37
|
-
|
|
38
|
-
xhr.
|
|
39
|
-
callback(
|
|
40
|
-
console.log(String(data), res.statusCode);
|
|
63
|
+
response = Buffer.concat(data);
|
|
64
|
+
xhr.readyState = 4;
|
|
65
|
+
callback();
|
|
41
66
|
});
|
|
42
67
|
res.on("error", function (e) {
|
|
68
|
+
xhr.readyState = 4;
|
|
69
|
+
error = e;
|
|
43
70
|
onerror(e);
|
|
44
71
|
});
|
|
72
|
+
this.readyState = 2;
|
|
45
73
|
});
|
|
74
|
+
this.readyState = 1;
|
|
46
75
|
if (data) req.end(data);
|
|
47
76
|
else req.end();
|
|
48
77
|
},
|
|
@@ -50,6 +79,10 @@ return _cross.bind(function (callback, onerror) {
|
|
|
50
79
|
this.method = method;
|
|
51
80
|
this.url = url;
|
|
52
81
|
this.status = 0;
|
|
82
|
+
this.readyState = 0;
|
|
83
|
+
response = null;
|
|
84
|
+
responseObject = null;
|
|
85
|
+
error = null;
|
|
53
86
|
var http;
|
|
54
87
|
if (/^https?\:/i.test(url)) {
|
|
55
88
|
http = require("http");
|
|
@@ -59,6 +92,14 @@ return _cross.bind(function (callback, onerror) {
|
|
|
59
92
|
}
|
|
60
93
|
this.http = http;
|
|
61
94
|
},
|
|
95
|
+
get responseType() {
|
|
96
|
+
return responseType;
|
|
97
|
+
},
|
|
98
|
+
set responseType(v) {
|
|
99
|
+
if (v === "document") return;
|
|
100
|
+
if (this.status !== 0) throw new Error("状态错误");
|
|
101
|
+
responseType = v;
|
|
102
|
+
},
|
|
62
103
|
setRequestHeader(key, value) {
|
|
63
104
|
this.headers[key] = value;
|
|
64
105
|
},
|
package/coms/zimoli/cross.js
CHANGED
|
@@ -38,6 +38,9 @@ function main(children, multiple, addable) {
|
|
|
38
38
|
item.name = option.name || option.innerHTML;
|
|
39
39
|
var icon = option.getAttribute ? option.getAttribute("icon") : option.icon;
|
|
40
40
|
if (icon) {
|
|
41
|
+
if (!hasIcon) {
|
|
42
|
+
page.setAttribute('iconed', '');
|
|
43
|
+
}
|
|
41
44
|
hasIcon = true;
|
|
42
45
|
css(item, { backgroundImage: `url('${icon}')` });
|
|
43
46
|
}
|
|
@@ -125,9 +128,6 @@ function main(children, multiple, addable) {
|
|
|
125
128
|
});
|
|
126
129
|
adder.setAttribute("adder", '');
|
|
127
130
|
}
|
|
128
|
-
if (hasIcon) {
|
|
129
|
-
page.setAttribute('iconed', '');
|
|
130
|
-
}
|
|
131
131
|
page.icon = iconed;
|
|
132
132
|
on('mousedown')(page, e => e.preventDefault());
|
|
133
133
|
return page;
|
|
@@ -36,10 +36,22 @@
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
&[iconed] {
|
|
39
|
-
|
|
39
|
+
padding-left: 30px;
|
|
40
|
+
|
|
41
|
+
&:before {
|
|
42
|
+
content: "";
|
|
43
|
+
display: block;
|
|
44
|
+
position: absolute;
|
|
45
|
+
height: 100%;
|
|
46
|
+
top: 0;
|
|
47
|
+
left: 0;
|
|
48
|
+
width: 30px;
|
|
49
|
+
background: #f2f4f6;
|
|
50
|
+
}
|
|
40
51
|
|
|
41
52
|
>div {
|
|
42
53
|
filter: grayscale(1);
|
|
54
|
+
position: relative;
|
|
43
55
|
|
|
44
56
|
&:hover,
|
|
45
57
|
&:active,
|
package/coms/zimoli/view.less
CHANGED