efront 3.21.4 → 3.22.2
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/apps/pay/alipay-callback.jsp +8 -5
- package/apps/pay/alipay-query.jsp +15 -0
- package/apps/pay/alipay.jsp +11 -14
- package/apps/pay/alipay_test.js +2 -1
- package/coms/basic/BigNumber.js +24 -2
- package/coms/basic/BigNumber_test.js +6 -0
- package/coms/compile/scanner2.js +12 -1
- package/coms/frame/payment.js +18 -6
- package/coms/reptile/cross.js +5 -3
- package/coms/zimoli/render.js +49 -55
- package/package.json +1 -1
- package/public/efront.js +1 -1
|
@@ -5,12 +5,15 @@
|
|
|
5
5
|
var id = params.out_trade_no;
|
|
6
6
|
|
|
7
7
|
var data = await _runtask("couchdb", "get", `alipay-log/${id}`);
|
|
8
|
-
|
|
8
|
+
extend(data, {
|
|
9
9
|
alipay_trade_no: params.trade_no,
|
|
10
10
|
seller_id: params.seller_id,
|
|
11
11
|
return_amount: params.total_amount,
|
|
12
|
-
|
|
13
|
-
})
|
|
12
|
+
trade_status: params.trade_status
|
|
13
|
+
});
|
|
14
|
+
if (req.headers["user-agent"]) data.return_time = new Date().toISOString();
|
|
15
|
+
else data.notify_time = new Date().toISOString();
|
|
16
|
+
await _runtask("couchdb", "put", `alipay-log/${id}?_rev=${data._rev}`, data);
|
|
14
17
|
context.id = params.out_trade_no;
|
|
15
18
|
</script>
|
|
16
19
|
<script>
|
|
@@ -18,6 +21,6 @@
|
|
|
18
21
|
if (id) parent.postMessage(id);
|
|
19
22
|
</script>
|
|
20
23
|
<script serverside>
|
|
21
|
-
if(context.id)return `<body style="color:green">支付完成</body>`;
|
|
24
|
+
if (context.id) return `<body style="color:green">支付完成</body>`;
|
|
22
25
|
else return `<body style="color:red">支付失败</body>`
|
|
23
|
-
</script>
|
|
26
|
+
</script>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<script serverside>
|
|
2
|
+
var time = Date.now();
|
|
3
|
+
var out_trade_no = encode62.timedecode(request.id);
|
|
4
|
+
var payed = /^(TRADE_FINISHED|TRADE_SUCCESS)$/i;
|
|
5
|
+
for (var cx = 0, dx = 10; cx < dx; cx++) {
|
|
6
|
+
if (Date.now() - time > 30000) return;
|
|
7
|
+
var data = await _runtask("couchdb", 'get', `alipay-log/${out_trade_no}`);
|
|
8
|
+
if (data.return_time || data.notify_time || payed.test(data.trade_status)) return JSON.stringify(data);
|
|
9
|
+
var data1 = await _runtask("alipay-query", out_trade_no);
|
|
10
|
+
if (payed.test(data1.trade_status)) {
|
|
11
|
+
return JSON.stringify(Object.assign(data, { trade_status: data1.trade_status }));
|
|
12
|
+
}
|
|
13
|
+
await new Promise(ok => setTimeout(ok, 300));
|
|
14
|
+
}
|
|
15
|
+
</script>
|
package/apps/pay/alipay.jsp
CHANGED
|
@@ -50,18 +50,13 @@ ACQ.MERCHANT_PERM_RECEIPT_DAY_LIMIT 超过单日累计收款额度 联系支付
|
|
|
50
50
|
if (a < 10) return "0" + a;
|
|
51
51
|
return a;
|
|
52
52
|
}
|
|
53
|
-
var now = new Date();
|
|
54
|
-
function createStamp(now) {
|
|
55
|
-
var d = now;
|
|
56
|
-
return [d.getFullYear(), d.getMonth() + 1, d.getDate()].map(pad).join("-") +
|
|
57
|
-
" " + [d.getHours(), d.getMinutes(), d.getSeconds()].map(pad).join(":");
|
|
58
|
-
}
|
|
59
53
|
var amount = request.id;
|
|
60
54
|
if (!/^(\d+)(\.\d+)?$/.test(amount)) amount = encode62.timedecode(request.id);
|
|
61
55
|
var [amount, subject = '网页扫码支付'] = amount.split(',');
|
|
56
|
+
var trade_no = createId();
|
|
62
57
|
if (!+amount) return forbidden("参数异常");
|
|
63
58
|
var biz_content = {
|
|
64
|
-
out_trade_no: "alipay-" +
|
|
59
|
+
out_trade_no: "alipay-" + trade_no,
|
|
65
60
|
product_code: 'FAST_INSTANT_TRADE_PAY',
|
|
66
61
|
total_amount: amount,
|
|
67
62
|
qr_pay_mode: 4,
|
|
@@ -70,15 +65,15 @@ ACQ.MERCHANT_PERM_RECEIPT_DAY_LIMIT 超过单日累计收款额度 联系支付
|
|
|
70
65
|
body: subject,
|
|
71
66
|
};
|
|
72
67
|
var params = {
|
|
73
|
-
timestamp: createStamp(now),
|
|
74
68
|
method: "alipay.trade.page.pay",
|
|
75
69
|
app_id: "2021002143612677",
|
|
76
70
|
sign_type: "RSA2",
|
|
77
71
|
version: "1.0",
|
|
78
72
|
charset: "utf-8",
|
|
79
|
-
return_url: `${req.protocol}//${req.headers.host}${req.url.replace(/[\.\:][\s\S]*$/, '')}-callback`,
|
|
73
|
+
return_url: `${req.protocol}//${req.headers[":authority"] || req.headers.host}${req.url.replace(/[\.\:][\s\S]*$/, '')}-callback`,
|
|
80
74
|
biz_content: JSON.stringify(biz_content)
|
|
81
75
|
};
|
|
76
|
+
params.notify_url = params.return_url;
|
|
82
77
|
await _runtask("alipay-sign", params);
|
|
83
78
|
|
|
84
79
|
var log = await _runtask("couchdb", "put", "alipay-log/" + biz_content.out_trade_no, {
|
|
@@ -89,11 +84,13 @@ ACQ.MERCHANT_PERM_RECEIPT_DAY_LIMIT 超过单日累计收款额度 联系支付
|
|
|
89
84
|
subject: biz_content.subject,
|
|
90
85
|
body: biz_content.body,
|
|
91
86
|
timestamp: params.timestamp,
|
|
92
|
-
create_time:
|
|
87
|
+
create_time: new Date().toISOString(),
|
|
93
88
|
return_url: biz_content.return_url
|
|
94
89
|
});
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
90
|
+
context.id = biz_content.out_trade_no;
|
|
91
|
+
context.location = "https://openapi.alipay.com/gateway.do?" + serialize(params);
|
|
92
|
+
</script>
|
|
93
|
+
<script>
|
|
94
|
+
parent.postMessage(<%JSON.stringify(context.id)%>);
|
|
95
|
+
location.href = <%JSON.stringify(context.location)%>;
|
|
99
96
|
</script>
|
package/apps/pay/alipay_test.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
var pay = frame$payment([
|
|
2
2
|
{
|
|
3
3
|
url: './alipay:',
|
|
4
|
+
query: './alipay-query:',
|
|
4
5
|
name: '支付宝',
|
|
5
6
|
icon: 'alipay.ico',
|
|
6
7
|
cost(price) {
|
|
7
8
|
return BigNumber.prd((0.6036218 + 0.204081632) / 100, price);
|
|
8
9
|
},
|
|
9
10
|
}
|
|
10
|
-
],
|
|
11
|
+
], 0.01, '支付宝支付测试');
|
|
11
12
|
popup(pay, true);
|
|
12
13
|
console.log(pay)
|
|
13
14
|
care(pay, 'payment', function (a) {
|
package/coms/basic/BigNumber.js
CHANGED
|
@@ -46,7 +46,9 @@ var fixde = function (numstr, fractionDigits, compare) {
|
|
|
46
46
|
}
|
|
47
47
|
var res = s1 + s2;
|
|
48
48
|
if (frag) {
|
|
49
|
+
var res_length = res.length;
|
|
49
50
|
res = BigNumber.add(res, 1);
|
|
51
|
+
if (res.length < res_length) res = repeat0(res_length - res.length) + res;
|
|
50
52
|
}
|
|
51
53
|
if (fractionDigits > 0) res = res.slice(0, res.length - fractionDigits) + '.' + res.slice(res.length - fractionDigits);
|
|
52
54
|
if (/^\./.test(res)) res = "0" + res;
|
|
@@ -70,10 +72,10 @@ class BigNumber {
|
|
|
70
72
|
return fixde(numstr, 0, 4);
|
|
71
73
|
}
|
|
72
74
|
static ceil(numstr) {
|
|
73
|
-
return fixde(numstr, 0, 0);
|
|
75
|
+
return fixde(numstr, 0, /^\-/.test(numstr) ? 9 : 0);
|
|
74
76
|
}
|
|
75
77
|
static floor(numstr) {
|
|
76
|
-
return fixde(numstr, 0, 9);
|
|
78
|
+
return fixde(numstr, 0, /^\-/.test(numstr) ? 0 : 9);
|
|
77
79
|
}
|
|
78
80
|
static fix(numstr, fractionDigits) {
|
|
79
81
|
fractionDigits = +fractionDigits || 0;
|
|
@@ -181,4 +183,24 @@ class BigNumber {
|
|
|
181
183
|
res = res.reverse().join('');
|
|
182
184
|
return fixme(neg1 ^ neg2, res, d);
|
|
183
185
|
}
|
|
186
|
+
static sub(numstr1, numstr2) {
|
|
187
|
+
numstr2 = trim(numstr2);
|
|
188
|
+
if (/^\-/.test(numstr2)) numstr2 = numstr2.slice(1);
|
|
189
|
+
else numstr2 = '-' + numstr2;
|
|
190
|
+
return BigNumber.add(numstr1, numstr2);
|
|
191
|
+
}
|
|
192
|
+
// 按整数除法,超出输入的数字的位数之和
|
|
193
|
+
static div(numstr1, numstr2, decimal) {
|
|
194
|
+
if (isEmpty(decimal)) throw new Error("请输入保留小数的位数!");
|
|
195
|
+
var [neg1, s11, s12] = prepare(numstr1);
|
|
196
|
+
var [neg2, s21, s22] = prepare(numstr2);
|
|
197
|
+
var d = s12.length - s22.length;
|
|
198
|
+
numstr1 = s11 + s12;
|
|
199
|
+
numstr2 = s21 + s22;
|
|
200
|
+
|
|
201
|
+
if (d < 0) {
|
|
202
|
+
numstr2 += repeat0(0, -d);
|
|
203
|
+
}
|
|
204
|
+
numstr1 += repeat0(0);
|
|
205
|
+
}
|
|
184
206
|
}
|
|
@@ -38,14 +38,20 @@ assert(BigNumber.fix(2.235, 2), '2.24');
|
|
|
38
38
|
assert(BigNumber.fix(2.234, 2), '2.23');
|
|
39
39
|
assert(BigNumber.fix(2.2351, 2), '2.24');
|
|
40
40
|
assert(BigNumber.fix(2.2349, 2), '2.23');
|
|
41
|
+
assert(BigNumber.fix(0.00807703432, 2), '0.01');
|
|
41
42
|
assert(BigNumber.round(2.2349), '2');
|
|
42
43
|
assert(BigNumber.round(2.4999), '2');
|
|
43
44
|
assert(BigNumber.round(2.5000), '3');
|
|
45
|
+
assert(BigNumber.round(-2.5000), '-3');
|
|
44
46
|
assert(BigNumber.round(2.5100), '3');
|
|
45
47
|
assert(BigNumber.ceil(2.5100), '3');
|
|
48
|
+
assert(BigNumber.ceil(-2.5100), '-2');
|
|
46
49
|
assert(BigNumber.ceil(2.000), '2');
|
|
50
|
+
assert(BigNumber.ceil(-2.000), '-2');
|
|
47
51
|
assert(BigNumber.floor(2.000), '2');
|
|
52
|
+
assert(BigNumber.floor(-2.000), '-2');
|
|
48
53
|
assert(BigNumber.floor(2.999), '2');
|
|
54
|
+
assert(BigNumber.floor(-2.999), '-3');
|
|
49
55
|
assert(BigNumber.ceil(2.001), '3');
|
|
50
56
|
assert(BigNumber.ceil(2.999), '3');
|
|
51
57
|
assert(BigNumber.fix("9007199254740992.234", 6), '9007199254740992.234000');
|
package/coms/compile/scanner2.js
CHANGED
|
@@ -287,6 +287,17 @@ class Program extends Array {
|
|
|
287
287
|
}
|
|
288
288
|
}
|
|
289
289
|
|
|
290
|
+
var isShortMethodEnd = function (o) {
|
|
291
|
+
if (!o) return false;
|
|
292
|
+
if (o.type !== SCOPED || o.entry !== "{") return false;
|
|
293
|
+
o = o.prev;
|
|
294
|
+
if (!o) return false;
|
|
295
|
+
if (o.type !== SCOPED || o.entry !== "(") return false;
|
|
296
|
+
o = o.prev;
|
|
297
|
+
if (!o) return false;
|
|
298
|
+
return o.type === PROPERTY;
|
|
299
|
+
};
|
|
300
|
+
|
|
290
301
|
class Javascript {
|
|
291
302
|
quotes = [
|
|
292
303
|
[/'/, /'/, /\\[\s\S]/],
|
|
@@ -354,7 +365,7 @@ class Javascript {
|
|
|
354
365
|
if (queue.isClass) scope.isprop = !last || last.isprop || last.type === STAMP && last.text === ';';
|
|
355
366
|
}
|
|
356
367
|
else if (scope.type === STAMP) {
|
|
357
|
-
scope.isprop = scope.text === "*" &&
|
|
368
|
+
scope.isprop = scope.text === "*" && (!queue.lastUncomment || /^[,;]$/.test(queue.lastUncomment.text) || queue.isClass && isShortMethodEnd(queue.lastUncomment));
|
|
358
369
|
}
|
|
359
370
|
else if (scope.type === PROPERTY) {
|
|
360
371
|
scope.isprop = true;
|
package/coms/frame/payment.js
CHANGED
|
@@ -4,7 +4,7 @@ function main(paytypes, price, subject = '网站扫码支付') {
|
|
|
4
4
|
page.innerHTML = payment;
|
|
5
5
|
renderWithDefaults(page, {
|
|
6
6
|
get paytype() {
|
|
7
|
-
return paytype.value;
|
|
7
|
+
return paytype.value || '0';
|
|
8
8
|
},
|
|
9
9
|
set paytype(value) {
|
|
10
10
|
data.patchInstance("paytype", { value }, true);
|
|
@@ -36,13 +36,25 @@ function main(paytypes, price, subject = '网站扫码支付') {
|
|
|
36
36
|
});
|
|
37
37
|
drag.on(page.firstChild, page);
|
|
38
38
|
resize.on(page);
|
|
39
|
-
data.bindInstance("paytype", function (type) {
|
|
40
|
-
console.log(type)
|
|
41
|
-
});
|
|
42
39
|
var frame = page.querySelector("iframe");
|
|
40
|
+
var tradeid;
|
|
43
41
|
bind("message")(frame, function (e) {
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
if (tradeid === e.data && !queryres) cast(page, 'payment', tradeid), queryres = tradeid;
|
|
43
|
+
else tradeid = e.data, queryres = null;
|
|
44
|
+
});
|
|
45
|
+
var queryurl, queryres;
|
|
46
|
+
data.bindInstance("paytype", function ({ value }) {
|
|
47
|
+
var type = paytypes[value - 1];
|
|
48
|
+
queryurl = type && type.query;
|
|
46
49
|
});
|
|
50
|
+
var query = lazy(async function () {
|
|
51
|
+
if (!tradeid || queryres) return;
|
|
52
|
+
if (isFunction(queryurl)) var res = await queryurl(tradeid);
|
|
53
|
+
else if (isString(queryurl)) var res = await cross('get', queryurl + encode62.timeencode(tradeid)), res = JSAM.parse(res.response || res.responseText);
|
|
54
|
+
if (queryres) return;
|
|
55
|
+
if (res) queryres = res, cast(page, 'payment', res._id);
|
|
56
|
+
}, -200);
|
|
57
|
+
on('load')(frame, query);
|
|
58
|
+
on('remove')(frame, query);
|
|
47
59
|
return page;
|
|
48
60
|
}
|
package/coms/reptile/cross.js
CHANGED
|
@@ -44,14 +44,15 @@ return cross_.bind(function (callback, onerror) {
|
|
|
44
44
|
data = Buffer.from(data);
|
|
45
45
|
this.headers["Content-Length"] = data.length;
|
|
46
46
|
}
|
|
47
|
-
var
|
|
47
|
+
var options = {
|
|
48
48
|
method: this.method,
|
|
49
49
|
hostname,
|
|
50
50
|
port,
|
|
51
51
|
path,
|
|
52
52
|
auth,
|
|
53
53
|
headers: this.headers,
|
|
54
|
-
}
|
|
54
|
+
};
|
|
55
|
+
var req = this.http.request(options, function (res) {
|
|
55
56
|
var data = [];
|
|
56
57
|
xhr.status = res.statusCode;
|
|
57
58
|
xhr.responseHeaders = res.headers;
|
|
@@ -72,6 +73,7 @@ return cross_.bind(function (callback, onerror) {
|
|
|
72
73
|
this.readyState = 2;
|
|
73
74
|
});
|
|
74
75
|
this.readyState = 1;
|
|
76
|
+
req.setTimeout(3000);
|
|
75
77
|
if (data) req.end(data);
|
|
76
78
|
else req.end();
|
|
77
79
|
},
|
|
@@ -84,7 +86,7 @@ return cross_.bind(function (callback, onerror) {
|
|
|
84
86
|
responseObject = null;
|
|
85
87
|
error = null;
|
|
86
88
|
var http;
|
|
87
|
-
if (/^
|
|
89
|
+
if (/^http\:/i.test(url)) {
|
|
88
90
|
http = require("http");
|
|
89
91
|
}
|
|
90
92
|
else {
|
package/coms/zimoli/render.js
CHANGED
|
@@ -7,7 +7,7 @@ var createTemplateNodes = function (text) {
|
|
|
7
7
|
remove(this.with);
|
|
8
8
|
this.with = [].slice.call(node.childNodes, 0);
|
|
9
9
|
appendChild.after(this, this.with);
|
|
10
|
-
renderElement(this.with, this.$scope, this.$parentScopes, this.renderid === 9);
|
|
10
|
+
this.with = renderElement(this.with, this.$scope, this.$parentScopes, this.renderid === 9);
|
|
11
11
|
};
|
|
12
12
|
presets.template = function (t) {
|
|
13
13
|
var comment = document.createComment('template');
|
|
@@ -23,7 +23,7 @@ presets.template = function (t) {
|
|
|
23
23
|
}
|
|
24
24
|
return comment;
|
|
25
25
|
};
|
|
26
|
-
window.renderElements = renderElements;
|
|
26
|
+
if (!isProduction) window.renderElements = renderElements;
|
|
27
27
|
var renderidOffset = 10;
|
|
28
28
|
var renderidClosed = 0;
|
|
29
29
|
var addRenderElement = function () {
|
|
@@ -87,14 +87,22 @@ var createGetter = function (search, isprop = true) {
|
|
|
87
87
|
}
|
|
88
88
|
return new Function("event", `${withContext}with(this.$scope){${/([\=\(\+\-])/.test(searchContext) ? ret + searchContext : `${ret}${searchContext}.call(this.$scope,event)`}}`);
|
|
89
89
|
};
|
|
90
|
-
var
|
|
90
|
+
var createComment = function (renders, type, expression) {
|
|
91
91
|
var comment = document.createComment(`${type} ${expression}`);
|
|
92
92
|
comment.renders = renders;
|
|
93
93
|
comment.$scope = this.$scope;
|
|
94
|
+
comment.$struct = this.$struct;
|
|
94
95
|
comment.$parentScopes = this.$parentScopes;
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
if (this.parentNode) {
|
|
97
|
+
appendChild.after(this, comment);
|
|
98
|
+
if (!/^if|^else/i.test(type)) remove(this);
|
|
99
|
+
}
|
|
100
|
+
comment.template = this;
|
|
101
|
+
return comment;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
var initialComment = function (comment) {
|
|
105
|
+
if (!comment.$struct.once) {
|
|
98
106
|
comment.renderid = ++renderidOffset;
|
|
99
107
|
onmounted(comment, addRenderElement);
|
|
100
108
|
onremove(comment, removeRenderElement);
|
|
@@ -105,8 +113,8 @@ var initialComment = function (renders, type, expression) {
|
|
|
105
113
|
rebuild(comment);
|
|
106
114
|
remove(comment);
|
|
107
115
|
}
|
|
108
|
-
return comment;
|
|
109
116
|
};
|
|
117
|
+
|
|
110
118
|
var parseRepeat = function (expression) {
|
|
111
119
|
var reg =
|
|
112
120
|
// /////////////////////////////////////////// i // r ///////////////////////// o ///// a ///////////////////// t /////
|
|
@@ -141,7 +149,6 @@ var parseRepeat = function (expression) {
|
|
|
141
149
|
var createRepeat = function (search, id = 0) {
|
|
142
150
|
// 懒渲染
|
|
143
151
|
// throw new Error("repeat is not supported! use list component instead");
|
|
144
|
-
|
|
145
152
|
var [context, expression] = search;
|
|
146
153
|
var res = parseRepeat(expression);
|
|
147
154
|
if (!res) throw new Error(`不能识别循环表达式: ${expression} `);
|
|
@@ -206,33 +213,15 @@ var createRepeat = function (search, id = 0) {
|
|
|
206
213
|
if (clonedElements1[k] !== clonedElements[k]) remove(clonedElements[k]);
|
|
207
214
|
}
|
|
208
215
|
clonedElements = clonedElements1;
|
|
216
|
+
this.with = cloned;
|
|
209
217
|
}];
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
once("append")(this, initialComment.bind(this, renders, "repeat", expression));
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
|
-
var comment = function (elements) {
|
|
217
|
-
for (var cx = elements.length - 2; cx > 1; cx -= 2) {
|
|
218
|
-
var e = elements[cx];
|
|
219
|
-
if (e.previousSibling === this) var c = this;
|
|
220
|
-
else {
|
|
221
|
-
var c = document.createComment('else' + (cx < elements.length - 2 ? "if .." : ''));
|
|
222
|
-
e.parentNode.insertBefore(c, e);
|
|
223
|
-
}
|
|
224
|
-
elements.splice(cx, 0, c);
|
|
225
|
-
remove(e);
|
|
226
|
-
}
|
|
218
|
+
var comment = createComment.call(this, renders, 'repeat', expression);
|
|
219
|
+
initialComment(comment);
|
|
220
|
+
return comment;
|
|
227
221
|
};
|
|
228
222
|
var initIf = function (ifs) {
|
|
229
223
|
for (var s of ifs) {
|
|
230
|
-
|
|
231
|
-
if (s.parent) {
|
|
232
|
-
initialComment.call(s[0], s.renders, "if", s.comment);
|
|
233
|
-
} else {
|
|
234
|
-
once("append")(s[0], initialComment.bind(s[0], s.renders, "if", s.comment));
|
|
235
|
-
}
|
|
224
|
+
initialComment(s[0]);
|
|
236
225
|
}
|
|
237
226
|
};
|
|
238
227
|
var createIf = function (search, id = 0) {
|
|
@@ -246,7 +235,7 @@ var createIf = function (search, id = 0) {
|
|
|
246
235
|
elements.comment = search[1];
|
|
247
236
|
elements.renders = [function () {
|
|
248
237
|
var shouldMount = -1;
|
|
249
|
-
for (var cx = 0, dx = elements.length; cx < dx; cx +=
|
|
238
|
+
for (var cx = 0, dx = elements.length; cx < dx; cx += 2) {
|
|
250
239
|
var getter = elements[cx + 1];
|
|
251
240
|
if (!getter || getter()) {
|
|
252
241
|
shouldMount = cx;
|
|
@@ -255,21 +244,23 @@ var createIf = function (search, id = 0) {
|
|
|
255
244
|
}
|
|
256
245
|
if (savedValue === shouldMount) return;
|
|
257
246
|
savedValue = shouldMount;
|
|
258
|
-
for (var cx = 0, dx = elements.length; cx < dx; cx +=
|
|
259
|
-
var
|
|
247
|
+
for (var cx = 0, dx = elements.length; cx < dx; cx += 2) {
|
|
248
|
+
var c = elements[cx];
|
|
260
249
|
if (cx === shouldMount) {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
250
|
+
var e = c.template;
|
|
251
|
+
appendChild.after(c, e);
|
|
252
|
+
if (e.renderid < 0) {
|
|
253
|
+
e.renderid = id;
|
|
254
|
+
c.template = render(e, this.$scope, this.$parentScopes);
|
|
265
255
|
}
|
|
266
256
|
}
|
|
267
257
|
else {
|
|
268
|
-
remove(
|
|
258
|
+
remove(c.template);
|
|
269
259
|
}
|
|
270
260
|
}
|
|
271
261
|
|
|
272
262
|
}];
|
|
263
|
+
return elements[0] = createComment.call(element, elements.renders, 'if', elements.comment);
|
|
273
264
|
};
|
|
274
265
|
var parseIfWithRepeat = function (ifExpression, repeatExpression) {
|
|
275
266
|
var repeater = parseRepeat(repeatExpression);
|
|
@@ -350,17 +341,17 @@ var createStructure = function ({ name: ifkey, key, value: ifexp } = {}, { name:
|
|
|
350
341
|
}
|
|
351
342
|
if (before.length > 0) {
|
|
352
343
|
// 懒渲染
|
|
353
|
-
createIf.call(element, [context, before.join("&&")], null);
|
|
344
|
+
return createIf.call(element, [context, before.join("&&")], null);
|
|
354
345
|
} else {
|
|
355
346
|
element.removeAttribute(forkey);
|
|
356
|
-
createRepeat.call(element, [context, repeat], null);
|
|
347
|
+
return createRepeat.call(element, [context, repeat], null);
|
|
357
348
|
}
|
|
358
349
|
};
|
|
359
350
|
|
|
360
351
|
var if_top = [];
|
|
361
352
|
var structures = {
|
|
362
353
|
"if"(search) {
|
|
363
|
-
createIf.call(this, search);
|
|
354
|
+
return createIf.call(this, search);
|
|
364
355
|
},
|
|
365
356
|
"else"(search) {
|
|
366
357
|
for (var cx = if_top.length - 1; cx >= 0; cx--) {
|
|
@@ -374,10 +365,11 @@ var structures = {
|
|
|
374
365
|
if (search && search[1]) {
|
|
375
366
|
var getter = createGetter(search).bind(this);
|
|
376
367
|
}
|
|
377
|
-
|
|
368
|
+
var comment = createComment.call(this, undefined, search[1] ? 'elseif' : 'else', search[1]);
|
|
369
|
+
top.push(comment, getter);
|
|
378
370
|
},
|
|
379
371
|
repeat(search) {
|
|
380
|
-
createRepeat.call(this, search);
|
|
372
|
+
return createRepeat.call(this, search);
|
|
381
373
|
},
|
|
382
374
|
};
|
|
383
375
|
structures["else-if"] = structures.elseif = structures.else;
|
|
@@ -629,7 +621,7 @@ function getFromScopes(key, scope, parentScopes) {
|
|
|
629
621
|
|
|
630
622
|
function renderElement(element, scope = element.$scope, parentScopes = element.$parentScopes, once) {
|
|
631
623
|
if (!isNode(element) && element.length) {
|
|
632
|
-
return
|
|
624
|
+
return Array.prototype.slice.call(element, 0, element.length).map(function (element) {
|
|
633
625
|
return renderElement(element, scope, parentScopes, once);
|
|
634
626
|
});
|
|
635
627
|
}
|
|
@@ -637,19 +629,20 @@ function renderElement(element, scope = element.$scope, parentScopes = element.$
|
|
|
637
629
|
return element;
|
|
638
630
|
}
|
|
639
631
|
if (!isNumber(element.renderid)) {
|
|
640
|
-
renderStructure(element, scope, parentScopes, once);
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
if (elementid) {
|
|
644
|
-
if (scope[elementid]) {
|
|
645
|
-
if (scope[elementid] !== element) throw new Error("同一个id不能使用两次:" + elementid);
|
|
646
|
-
} else {
|
|
647
|
-
scope[elementid] = element;
|
|
632
|
+
let element1 = renderStructure(element, scope, parentScopes, once);
|
|
633
|
+
if (element1 !== element) {
|
|
634
|
+
element = element1;
|
|
648
635
|
}
|
|
636
|
+
if (!element) return;
|
|
649
637
|
}
|
|
650
|
-
if (element.renderid < 0) {
|
|
638
|
+
if (element.renderid < 0 || element.nodeType !== 1) {
|
|
651
639
|
return element;
|
|
652
640
|
}
|
|
641
|
+
var elementid = element.getAttribute("renderid") || element.getAttribute("elementid") || element.getAttribute("id");
|
|
642
|
+
if (elementid) {
|
|
643
|
+
if (scope[elementid] && scope[elementid] !== element) throw new Error("同一个id不能使用两次:" + elementid);
|
|
644
|
+
scope[elementid] = element;
|
|
645
|
+
}
|
|
653
646
|
var isFirstRender = !element.renderid;
|
|
654
647
|
|
|
655
648
|
if (isFirstRender) {
|
|
@@ -842,7 +835,8 @@ function renderStructure(element, scope, parentScopes = [], once) {
|
|
|
842
835
|
if (props["zimoli"] || props["fresh"] || props["once"]) once = true;
|
|
843
836
|
else if (props["refresh"] || props["digest"] || props["mount"]) once = false;
|
|
844
837
|
if (!element.$struct) element.$struct = { ons, copys, binds, attrs: attr1, props, context: withContext, ids, once };
|
|
845
|
-
if (element.renderid <= -1) createStructure.call(element, types.if, types.repeat, withContext);
|
|
838
|
+
if (element.renderid <= -1) return createStructure.call(element, types.if, types.repeat, withContext);
|
|
839
|
+
return element;
|
|
846
840
|
}
|
|
847
841
|
var eagermount = false, renderlock = false;
|
|
848
842
|
function render(element, scope, parentScopes, lazy = true) {
|