efront 3.3.8 → 3.4.0

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,3 @@
1
+ ./aapi/ authorization:
2
+ login: options /::login-:a
3
+ run: options /:::run
@@ -0,0 +1,9 @@
1
+ <div head>
2
+ 请输入服务器密码
3
+ </div>
4
+ <div body>
5
+ <field ng-repeat="f in fields" ng-src="[f,data]"></field>
6
+ </div>
7
+ <div foot>
8
+ <button pending.="pending" type="submit">登录</button>
9
+ </div>
@@ -0,0 +1,29 @@
1
+ var fields = refilm`
2
+ 密码/password* password
3
+ `;
4
+
5
+ function main() {
6
+ var page = view();
7
+ page.innerHTML = login;
8
+ drag.on(page);
9
+ on("append")(page, function () {
10
+ move.bindPosition(page, [.5, .5]);
11
+ });
12
+ renderWithDefaults(page, { fields, data: {}, pending: false });
13
+ on("submit")(page, async function () {
14
+ var { password } = submit(fields, this.$scope.data);
15
+ this.$scope.pending = true;
16
+ page.disabled = true;
17
+ try {
18
+ var info = await data.from("login", {
19
+ a: encode62.timeencode(encode62.geta(password))
20
+ }).loading_promise;
21
+ info = encode62.timeupdate(info);
22
+ data.setSource({ authorization: info });
23
+ go('/home/main')
24
+ } catch {
25
+ }
26
+ this.$scope.pending = false;
27
+ })
28
+ return page;
29
+ }
@@ -0,0 +1,11 @@
1
+ & {
2
+ position: absolute;
3
+ }
4
+
5
+ [foot],
6
+ [head] {
7
+ text-align: center;
8
+ }
9
+ .button{
10
+ padding: 0px 40px;
11
+ }
@@ -0,0 +1,13 @@
1
+ <div>
2
+ 已登录到服务器,您可以进行如下操作
3
+ </div>
4
+ <block>
5
+ <padding>
6
+ 清理服务器缓存 <btn @click="run('clear-cache',this)">清理</btn>
7
+ </padding>
8
+ </block>
9
+ <block>
10
+ <padding>
11
+ 退出登录 <btn @click="logout()">退出</btn>
12
+ </padding>
13
+ </block>
@@ -0,0 +1,22 @@
1
+ function main() {
2
+ var page = div();
3
+ page.innerHTML = template;
4
+ renderWithDefaults(page, {
5
+ status: [],
6
+ async run(id, target) {
7
+ target.setAttribute('pending', '')
8
+ try {
9
+ var info = await data.from("run", {
10
+ run: id
11
+ }).loading_promise;
12
+ if (info) alert(info, 'pass');
13
+ } catch { }
14
+ target.removeAttribute('pending');
15
+ },
16
+ logout() {
17
+ data.setSource('authorization', null);
18
+ go('/auth/login');
19
+ }
20
+ });
21
+ return page;
22
+ }
@@ -0,0 +1,8 @@
1
+ &{
2
+ line-height: 28px;
3
+ }
4
+ btn{
5
+ padding: 0 16px;
6
+ vertical-align: top;
7
+ margin-left: 20px;
8
+ }
@@ -0,0 +1,41 @@
1
+ <!DOCTYPE html>
2
+ <!--
3
+ http://efront.cc
4
+ -->
5
+ <html lang="zh-CN">
6
+
7
+ <head>
8
+ <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
9
+ <meta charset="utf-8" />
10
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
11
+ <link rel="Shortcut Icon" href="/favicon.ico" type="image/x-icon" />
12
+ <meta name="viewport" content="initial-scale=1,maximum-scale=1,width=device-width" />
13
+ <title>Efront 服务器管控平台</title>
14
+ <script deleteoncompile efrontloader>
15
+ // 若要在开发环境使用内置组件,请保留此script标签中的代码,在编译发布时,这里的代码会自动删除
16
+ </script>
17
+ <style>
18
+ html {
19
+ height: 100%;
20
+ font-family: "SF Pro SC", "SF Pro Text", "SF Pro Icons", "PingFang SC", "Helvetica Neue", "Helvetica", "Arial", sans-serif;
21
+ }
22
+
23
+ *,
24
+ ::before,
25
+ ::after {
26
+ box-sizing: border-box;
27
+ }
28
+
29
+ body {
30
+ border: none;
31
+ margin: 0;
32
+ padding: 0;
33
+ height: 100%;
34
+ overflow: hidden;
35
+ }
36
+ </style>
37
+ </head>
38
+
39
+ <body scroll=no max-render=1440 main-path="/main"></body>
40
+
41
+ </html>
@@ -0,0 +1,13 @@
1
+ if (data.getSource('authorization')) {
2
+ zimoli("/home/main");
3
+ }
4
+ else {
5
+ zimoli("/auth/login");
6
+ }
7
+ data.loadConfig("api.yml");
8
+ setInterval(function () {
9
+ var auth = data.getSource('authorization');
10
+ if (!auth) return;
11
+ var auth1 = encode62.timeupdate(auth);
12
+ if (auth1 !== auth) data.setSource("authorization", auth1);
13
+ }, 2000);
@@ -260,8 +260,16 @@ function parse(piece) {
260
260
  }
261
261
  var [name, type, options] = piece, key, repeat;
262
262
  if (piece.length === 1 && isObject(name)) {
263
- var { name, needs, type, key, size, unit, endwith, ratio, value, repeat, comment, options } = name;
263
+ var { name, needs, required, checks, type, key, size, unit, endwith, ratio, value, repeat, comment, options } = name;
264
264
  } else {
265
+ var is_require = a => {
266
+ if (/^\*|\*$/.test(a)) {
267
+ required = true;
268
+ return a.replace(/^\*|\*$/, '');
269
+ }
270
+ return a;
271
+ };
272
+ type = is_require(type);
265
273
  if (typeof name === 'string') {
266
274
  if (!isContainer) {
267
275
  if (!type) {
@@ -362,14 +370,17 @@ function parse(piece) {
362
370
  type = type.slice(1);
363
371
  }
364
372
  if (typeof options === "string") {
373
+ options = is_require(options);
365
374
  var needUnfold = /^\[|\]$/.test(options);
366
375
  options = options.replace(/^\[|\]$/g, '');
367
376
  if (/,/.test(options)) options = scanSlant(options, ',');
368
377
  else options = scanSlant(options, "");
369
378
  if (needUnfold) unfoldOptions(size, options);
370
379
  }
380
+ name = is_require(name);
381
+ key = is_require(key);
371
382
  }
372
- var field = { name, needs, type, key, size, unit, endwith, ratio, value, repeat, comment, options };
383
+ var field = { name, checks, required, needs, type, key, size, unit, endwith, ratio, value, repeat, comment, options };
373
384
  var parent = piecepath[piecepath.length - 1];
374
385
  if (parent) {
375
386
  field.parent = parent;
@@ -0,0 +1,10 @@
1
+ function valid(field, data) {
2
+ var error;
3
+ if (isEmpty(data[field.key])) {
4
+ if (field.required) {
5
+ return "empty";
6
+ }
7
+ return;
8
+ }
9
+ return error;
10
+ }
@@ -15,6 +15,7 @@ var number_reg = /^[\+\-]?(0x[0-9a-f]+|0b\d+|0o\d+|(\d*\.\d+|\d+\.?)(e[\+\-]?\d+
15
15
  var skipAssignment = function (o) {
16
16
  var needpunc = false;
17
17
  var o0 = o;
18
+ var qcount = 0;
18
19
  loop: while (o) switch (o.type) {
19
20
  case STAMP:
20
21
  switch (o.text) {
@@ -32,6 +33,17 @@ var skipAssignment = function (o) {
32
33
  o = o.next;
33
34
  needpunc = false;
34
35
  break;
36
+ case "?":
37
+ qcount++;
38
+ needpunc = false;
39
+ o = o.next;
40
+ break;
41
+ case ":":
42
+ qcount--;
43
+ if (qcount < 0) break loop;
44
+ needpunc = false;
45
+ o = o.next;
46
+ break;
35
47
  default:
36
48
  if (/^[!~\+\-]+$/.test(o.text)) {
37
49
  needpunc = false;
@@ -7,7 +7,7 @@ src.split("").forEach((s, i) => map[s] = i);
7
7
  function encode62(string) {
8
8
  string = String(string)
9
9
  string = string.length + string + "2017-08-19";
10
- var buff = Buffer.from(src);
10
+ var buff = src.split('');
11
11
  for (var cx = 0, dx = buff.length + src.length, sl = string.length, cl = buff.length; cx < dx; cx++) {
12
12
  var s1 = string.charCodeAt(cx % sl) % cl;
13
13
  var s2 = cx % cl;
@@ -15,7 +15,7 @@ function encode62(string) {
15
15
  buff[s1] = buff[s2];
16
16
  buff[s2] = btemp;
17
17
  }
18
- return buff.toString();
18
+ return buff.join('');
19
19
  };
20
20
 
21
21
 
@@ -35,9 +35,23 @@ Object.assign(encode62, {
35
35
  },
36
36
  timeencode(string) {
37
37
  var { time_delta } = this;
38
- var time_stamp = +new Date();
38
+ var time_free = time_delta / 6 | 0;
39
+ var time_stamp = +new Date() - time_free;
39
40
  var time_rest = time_stamp % time_delta;
40
- return this.encode62(string, time_stamp.toString(36)) + time_rest.toString(36).padStart(time_delta.toString(36).length, '0');
41
+ var time_rest_str = time_rest.toString(36);
42
+ var time_delta_str = time_delta.toString(36);
43
+ return this.encode62(string, time_stamp.toString(36)) + repeat("0", time_delta_str.length - time_rest_str.length) + time_rest_str;
44
+ },
45
+ timeupdate(string) {
46
+ var { time_delta } = this;
47
+ var time_rest = string.slice(string.length - time_delta.toString(36).length, string.length);
48
+ var time_start = parseInt((new Date() - parseInt(time_rest, 36)) / time_delta) * time_delta;
49
+ var time_stamp = time_start + parseInt(time_rest, 36);
50
+ if (time_stamp + (time_delta >> 1) > +new Date()) {
51
+ return string;
52
+ } else {
53
+ return this.timeencode(this.timedecode(string));
54
+ }
41
55
  },
42
56
  encode62(data, sign) {
43
57
  if (!sign) return data;
@@ -53,15 +67,6 @@ Object.assign(encode62, {
53
67
  });
54
68
  return result;
55
69
  },
56
- encode(data, sign) {
57
- if (!sign) return data;
58
- var result = Buffer.from(data);
59
- sign = Buffer.from(sign);
60
- for (var cx = 0, dx = data.length; cx < dx; cx++) {
61
- result[cx] = result[cx] ^ sign[cx % sign.length];
62
- }
63
- return result;
64
- },
65
70
  decode(data, sign) {
66
71
  if (!sign) return data;
67
72
  var result = Buffer.from(data);
@@ -75,7 +80,7 @@ Object.assign(encode62, {
75
80
  return encode62(string);
76
81
  },
77
82
  genb() {
78
- return encode62(Date.now() + "" + Math.random());
83
+ return encode62(Date.now() * Math.random() + "" + Math.random().toString(36) + Math.random().toString(36).toUpperCase());
79
84
  },
80
85
  huan(x, y) {
81
86
  return x.split("").map(s => y[map[s]]).join("");
@@ -90,24 +95,9 @@ Object.assign(encode62, {
90
95
  y.split("").forEach((a, j) => y_map[a] = j);
91
96
  return z.split("").map(c => src[y_map[c]]).join("");
92
97
  },
93
- ab2c(a, b) {
94
- return this.huan(a, b);
95
- },
96
- ba2d(a, b) {
97
- return this.huan(b, a);
98
- },
99
- ca2b(c, a) {
100
- return this.yuan(c, a);
101
- },
102
- cb2a(c, b) {
103
- return this.suan(c, b);
104
- },
105
- da2b(d, a) {
106
- return this.suan(d, a);
107
- },
108
- db2a(d, b) {
109
- return this.yuan(d, b);
110
- }
111
98
  });
112
-
99
+ encode62.ab2c = encode62.ba2d = encode62.huan;
100
+ encode62.db2a = encode62.ca2b = encode62.yuan;
101
+ encode62.da2b = encode62.cb2a = encode62.suan;
102
+ encode62.encode = encode62.decode;
113
103
  encode62.decode62 = encode62.encode62;
@@ -32,7 +32,8 @@ describe("encode62_test", function () {
32
32
  c = encode62.ab2c(a, b);
33
33
  });
34
34
  it("ba2d", function () {
35
- d = encode62.ba2d(a, b);
35
+ // 注意,参数顺序已变更
36
+ d = encode62.ba2d(b, a);
36
37
  });
37
38
  it("ca2b", function () {
38
39
  expect(encode62.ca2b(c, a)).to.be.eq(b);
@@ -1,9 +1,13 @@
1
1
  var styles = {
2
- log: "#2a53cd",
3
- info: "#228B22",
4
- warn: "#dd6a16",
5
- error: "#dc352e"
2
+ blue: "#2a53cd",
3
+ green: "#228B22",
4
+ orange: "#dd6a16",
5
+ red: "#dc352e"
6
6
  };
7
+ styles.success = styles.pass = styles.green;
8
+ styles.info = styles.blue;
9
+ styles.error = styles.danger = styles.red;
10
+ styles.warn = styles.orange;
7
11
  var alerts = [];
8
12
  var clean = Cleanup(alerts);
9
13
  var build = function () {
@@ -323,7 +323,7 @@ function addDirect(a) {
323
323
  if (typeof a === 'string' || a instanceof RegExp) cors_hosts.push(a);
324
324
  }
325
325
  function notCross(domain) {
326
- if (location_host === domain.slice(0, location_host.length)) return true;
326
+ if (location_host === domain.slice(0, location_host.length) || !/^https?\:\/\/|^s?\/\//.test(domain)) return true;
327
327
  for (var cx = 0, dx = cors_hosts.length; cx < dx; cx++) {
328
328
  var host = cors_hosts[cx];
329
329
  if (host instanceof RegExp) {
@@ -166,6 +166,7 @@ function cssTargetStyleSheet(stylesheet, innerCss) {
166
166
  * @param {|string} oValue
167
167
  */
168
168
  var css = function (target, oStyle, oValue) {
169
+ if (!oStyle) return;
169
170
  if (isElement(target)) {
170
171
  if (/^style$/i.test(target.tagName)) {
171
172
  cssTargetStyleSheet(target, oStyle, oValue);
@@ -269,9 +269,9 @@ function parseConfig(api) {
269
269
  });
270
270
  return '';
271
271
  });
272
- url.replace(/[\?\#][\s\S]*$/, '').replace(/\:\w+/g, function (p) {
272
+ url.replace(/[\?\#][\s\S]*$/, '').replace(/([\:\\]\:|\:\w+)/g, function (p) {
273
273
  p = p.slice(1);
274
- if (!required[p]) {
274
+ if (!required[p] && p !== ':') {
275
275
  required.push(p);
276
276
  required[p] = p;
277
277
  }
@@ -495,8 +495,9 @@ var privates = {
495
495
  var coinmethod = method.slice(0, spliterIndex).toLowerCase();
496
496
  var realmethod = coinmethod.replace(/\W+$/g, '');
497
497
  var rest = [];
498
- var uri = url.replace(/#[\s\S]*$/, "").replace(/\:[a-z\_][\w]*/gi, function (d) {
498
+ var uri = url.replace(/#[\s\S]*$/, "").replace(/[\\\:]\:|\:[a-z\_][\w]*/gi, function (d) {
499
499
  d = d.slice(1);
500
+ if (d === ":") return d;
500
501
  rest.push(d);
501
502
  return seekResponse(params, d) || '';
502
503
  });
@@ -912,6 +913,10 @@ var data = {
912
913
  localStorage.setItem(sourceDataId, JSAM.stringify(dataSourceMap));
913
914
  }
914
915
  },
916
+ getSource(sourceid) {
917
+ if (sourceid) return dataSourceMap[sourceid];
918
+ return dataSourceMap;
919
+ },
915
920
  clearSource() {
916
921
  localStorage.removeItem(sourceDataId);
917
922
  sessionStorage.removeItem(sourceDataId);
@@ -5,6 +5,19 @@ var encode62 = {
5
5
  src,
6
6
  map,
7
7
  time_delta: parseInt("zzzzz", 36),
8
+ geta(string) {
9
+ string = String(string)
10
+ string = string.length + string + "2017-08-19";
11
+ var buff = src.split('');
12
+ for (var cx = 0, dx = buff.length + src.length, sl = string.length, cl = buff.length; cx < dx; cx++) {
13
+ var s1 = string.charCodeAt(cx % sl) % cl;
14
+ var s2 = cx % cl;
15
+ var btemp = buff[s1];
16
+ buff[s1] = buff[s2];
17
+ buff[s2] = btemp;
18
+ }
19
+ return buff.join('');
20
+ },
8
21
  timedecode(string) {
9
22
  var { time_delta } = this;
10
23
  var time_rest = string.slice(string.length - time_delta.toString(36).length, string.length);
@@ -1,8 +1,10 @@
1
1
  <div class="head">
2
2
  <span ng-bind=field.name></span>
3
+ <span class="required" ng-if="field.required">*</span>
3
4
  </div>
4
5
  <div class="body">
5
6
  <model _data=data _field=field></model>
7
+ <span class="error" ng-bind="error"></span>
6
8
  </div>
7
9
  <div class="foot" ng-if="field.msg">
8
10
  <span ng-bind=field.msg></span>
@@ -1,19 +1,43 @@
1
1
  function main(elem) {
2
- var result = elem;
3
- if (isElement(elem) && elem.hasAttribute("ng-src")) {
4
- elem = option(elem);
5
- care(elem, function (p) {
6
- var [f, data] = p;
7
- elem.innerHTML = field;
8
- render(elem, {
9
- model,
10
- data,
11
- field: f
12
- });
13
- }, false);
14
- } else {
15
- result = option.apply(null, arguments);
16
- }
17
- result.removeAttribute("tabindex");
18
- return result;
2
+ elem = option.apply(null, arguments);
3
+ var scope = {};
4
+ care(elem, function (p) {
5
+ if (elem.childNodes.length) return;
6
+ var [f, data] = p;
7
+ elem.innerHTML = field;
8
+ render(elem, scope = {
9
+ model,
10
+ data,
11
+ error: null,
12
+ field: f
13
+ });
14
+ elem.oldValue = data[f.key];
15
+ elem.setAttribute("field", f.key);
16
+ }, false);
17
+ elem.setAttribute("field", '');
18
+ elem.renders = [function () {
19
+ if (!this.src) return;
20
+ var [f, data] = this.src;
21
+ if (!f || !data) return;
22
+ var v = data[f.key];
23
+ if (!this.checked) if (v === this.oldValue || isEmpty(this.oldValue) && isEmpty(v)) return;
24
+ this.checked = false;
25
+ this.setAttribute("dirty", '');
26
+ var error = valid(f, data);
27
+ if (error) {
28
+ this.setAttribute("error", error);
29
+ switch (error) {
30
+ case "empty":
31
+ scope.error = `${f.name}是必填字段!`;
32
+ break;
33
+ }
34
+ }
35
+ else {
36
+ this.removeAttribute('error');
37
+ scope.error = null;
38
+ }
39
+ this.oldValue = data[f.key];
40
+ }]
41
+ elem.removeAttribute("tabindex");
42
+ return elem;
19
43
  }
@@ -32,4 +32,23 @@
32
32
 
33
33
  .input {
34
34
  width: 100%;
35
+ }
36
+
37
+ .required {
38
+ color: #c24;
39
+ display: inline-block;
40
+ }
41
+
42
+ &.error,
43
+ &[error] {
44
+ background: #f322;
45
+
46
+ model>* {
47
+ background: #f322;
48
+ border-color: #f32;
49
+ outline: 1px solid #f32;
50
+ }
51
+ .error{
52
+ color:#c32;
53
+ }
35
54
  }
@@ -2,5 +2,13 @@ function form(elem) {
2
2
  if (!elem) {
3
3
  elem = document.createElement("form");
4
4
  }
5
+ if (/form/i.test(elem.tagName)) {
6
+ on("submit")(elem, function (event) {
7
+ event.preventDefault();
8
+ var fields = elem.querySelectorAll(".field");
9
+ for (var f of fields) f.checked = true;
10
+ render.refresh();
11
+ });
12
+ }
5
13
  return elem;
6
14
  }
@@ -38,6 +38,7 @@ var constructors = {
38
38
  input,
39
39
  raw: input,
40
40
  row: textarea,
41
+ password,
41
42
  text: textarea,
42
43
  date() {
43
44
  var elem = document.createElement("input");