nv-basic-bw 1.0.4 → 1.0.6

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.
Files changed (3) hide show
  1. package/index.js +4 -4
  2. package/package.json +1 -1
  3. package/ui.js +55 -17
package/index.js CHANGED
@@ -527,13 +527,13 @@ const _attr = require("./attr");
527
527
  const _wait = require("./wait");
528
528
  const _ele_getter = require("./ele-getter");
529
529
  const _cls_accessor = require("./cls-accessor");
530
- const _ui = require("./ui");
530
+ const _ui_util = require("./ui-util");
531
531
 
532
- visit._attr = _attr;
533
- visit._wait = _wait;
532
+ visit._attr = _attr;
533
+ visit._wait = _wait;
534
534
  visit._ele_getter = _ele_getter;
535
535
  visit._cls_accessor = _cls_accessor;
536
- visit._ui = _ui;
536
+ visit._ui = _ui;
537
537
 
538
538
  const _nvison = require("nvison");
539
539
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nv-basic-bw",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
package/ui.js CHANGED
@@ -1,18 +1,19 @@
1
- const popmsg = (message, type = 'error', delay = 1000) => {
2
- const ALERT_COLORS = {
3
- success: '#38a169',
4
- error: '#e53e3e',
5
- warning: '#d69e2e',
6
- loading: '#3182ce',
7
- info: '#667eea'
8
- };
9
- const crest_simple_alert_css = (type) => `
1
+ const SIMPLE_ALERT_COLORS = {
2
+ success: '#38a169',
3
+ error: '#e53e3e',
4
+ warning: '#d69e2e',
5
+ loading: '#3182ce',
6
+ info: '#667eea'
7
+ };
8
+
9
+
10
+ const crest_simple_alert_css = (type) => `
10
11
  position: fixed;
11
12
  top: 50%;
12
13
  left: 50%;
13
14
  width: 300px;
14
15
  height:80px;
15
- background: ${ALERT_COLORS[type] || ALERT_COLORS.info};
16
+ background: ${SIMPLE_ALERT_COLORS[type] || SIMPLE_ALERT_COLORS.info};
16
17
  color: white;
17
18
  padding: 12px 20px;
18
19
  border-radius: 8px;
@@ -25,18 +26,55 @@ const popmsg = (message, type = 'error', delay = 1000) => {
25
26
  justify-content: center;
26
27
  font-size: r0px; /* 字体变大 */
27
28
  `;
29
+
30
+ const creat_simple_alert_ele = (type, message) => {
28
31
  const alertDiv = document.createElement('div');
29
32
  alertDiv.style.cssText = crest_simple_alert_css(type);
30
33
  alertDiv.textContent = message;
31
34
  document.body.appendChild(alertDiv);
32
- setTimeout(() => {
33
- if (document.body.contains(alertDiv)) {
34
- document.body.removeChild(alertDiv);
35
- }
36
- }, delay);
35
+ return alertDiv;
37
36
  }
38
37
 
38
+ class SimpleAlert {
39
+ tasks = {};
40
+ del(src) {
41
+ let d = this.tasks[src];
42
+ if (!d) return;
43
+ let {
44
+ init_timer,
45
+ duration_timer,
46
+ ele
47
+ } = d;
48
+ clearTimeout(init_timer);
49
+ clearTimeout(duration_timer);
50
+ if (ele && document.body.contains(ele)) {
51
+ document.body.removeChild(ele);
52
+ }
53
+ delete this.tasks[src];
54
+ }
55
+ add(src, message, type='error', duration = 1000, init_delay=100) {
56
+ this.del(src);
57
+ let d = {};
58
+ this.tasks[src] = d;
59
+ d.init_timer = setTimeout(() => {
60
+ d.ele = creat_simple_alert_ele(type, message);
61
+ d.duration_timer = setTimeout(() => {this.del(src);}, duration);
62
+ }, init_delay);
63
+ }
64
+ }
65
+ const creat_simple_alert = () => new SimpleAlert();
66
+ const simple_alert_g = creat_simple_alert();
67
+ const simple_alert = (src,message, type = 'error', duration = 1000,init_delay=100) => {
68
+ simple_alert_g.add(src,message, type, duration,init_delay);
69
+ }
70
+ const cancel_simple_alert = (src) =>{
71
+ simple_alert_g.del(src);
72
+ }
39
73
 
40
74
  module.exports = {
41
- popmsg,
42
- }
75
+ SimpleAlert,
76
+ creat_simple_alert,
77
+ simple_alert,
78
+ cancel_simple_alert
79
+ };
80
+