@94ai/nf-notification 3.1.37 → 3.1.38

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,10 @@
1
+ import NfNotification from './nf-notification.vue'
2
+ import { Vue2, PluginObject } from 'vue-demi'
3
+ import Main from './main'
4
+
5
+ NfNotification.install = (app: typeof Vue2) => {
6
+ app!.component('nf-notification', NfNotification)
7
+ app!.prototype.$openNotify = Main
8
+ }
9
+
10
+ export default NfNotification as typeof NfNotification & PluginObject<undefined>
@@ -0,0 +1,94 @@
1
+ import {Vue2} from 'vue-demi';
2
+ import Main from './nf-notification.vue';
3
+ import merge from 'element-ui/src/utils/merge';
4
+ import { PopupManager } from 'element-ui/src/utils/popup';
5
+ import { isVNode } from 'element-ui/src/utils/vdom';
6
+ const NotificationConstructor = Vue2!.extend(Main);
7
+
8
+ let instance: any;
9
+ let instances: any[] = [];
10
+ let seed = 1;
11
+
12
+ const Notification = function(options) {
13
+ if (Vue2!.prototype.$isServer) return;
14
+ options = merge({}, options);
15
+ const userOnClose = options.onClose;
16
+ const id = 'notification_' + seed++;
17
+ const position = options.position || 'top-right';
18
+
19
+ options.onClose = function() {
20
+ Notification.close(id, userOnClose);
21
+ };
22
+
23
+ instance = new NotificationConstructor({
24
+ data: options
25
+ });
26
+
27
+ if (isVNode(options.message)) {
28
+ instance.$slots.default = [options.message];
29
+ options.message = 'REPLACED_BY_VNODE';
30
+ }
31
+ instance.id = id;
32
+ instance.$mount();
33
+ document.body.appendChild(instance.$el);
34
+ instance.visible = true;
35
+ instance.dom = instance.$el;
36
+ instance.dom.style.zIndex = PopupManager.nextZIndex();
37
+
38
+ let verticalOffset = options.offset || 0;
39
+ instances.filter(item => item.position === position).forEach(item => {
40
+ verticalOffset += item.$el.offsetHeight + 16;
41
+ });
42
+ verticalOffset += 16;
43
+ instance.verticalOffset = verticalOffset;
44
+ instances.push(instance);
45
+ return instance;
46
+ };
47
+
48
+ ['success', 'warning', 'info', 'error'].forEach(type => {
49
+ Notification[type] = options => {
50
+ if (typeof options === 'string' || isVNode(options)) {
51
+ options = {
52
+ message: options
53
+ };
54
+ }
55
+ options.type = type;
56
+ return Notification(options);
57
+ };
58
+ });
59
+
60
+ Notification.close = function(id, userOnClose) {
61
+ let index = -1;
62
+ const len = instances.length;
63
+ const instance = instances.filter((instance, i) => {
64
+ if (instance.id === id) {
65
+ index = i;
66
+ return true;
67
+ }
68
+ return false;
69
+ })[0];
70
+ if (!instance) return;
71
+
72
+ if (typeof userOnClose === 'function') {
73
+ userOnClose(instance);
74
+ }
75
+ instances.splice(index, 1);
76
+
77
+ if (len <= 1) return;
78
+ const position = instance.position;
79
+ const removedHeight = instance.dom.offsetHeight;
80
+ for (let i = index; i < len - 1 ; i++) {
81
+ if (instances[i].position === position) {
82
+ instances[i].dom.style[instance.verticalProperty] =
83
+ parseInt(instances[i].dom.style[instance.verticalProperty], 10) - removedHeight - 16 + 'px';
84
+ }
85
+ }
86
+ };
87
+
88
+ Notification.closeAll = function() {
89
+ for (let i = instances.length - 1; i >= 0; i--) {
90
+ instances[i].close();
91
+ }
92
+ };
93
+
94
+ export default Notification;
@@ -0,0 +1,174 @@
1
+ <template>
2
+ <transition name="el-notification-fade">
3
+ <div
4
+ :class="['nf-notification', customClass, horizontalClass]"
5
+ v-show="visible"
6
+ :style="positionStyle"
7
+ @mouseenter="clearTimer()"
8
+ @mouseleave="startTimer()"
9
+ @click="click"
10
+ role="alert"
11
+ >
12
+ <i
13
+ class="nf-notification__icon"
14
+ :class="[ typeClass, iconClass ]"
15
+ v-if="type || iconClass">
16
+ </i>
17
+ <div class="nf-notification__group" :class="{ 'is-with-icon': typeClass || iconClass }">
18
+ <h2 class="nf-notification__title" v-text="title"></h2>
19
+ <div class="nf-notification__content" v-show="message">
20
+ <slot>
21
+ <p v-if="!dangerouslyUseHTMLString">{{ message }}</p>
22
+ <p v-else v-html="message"></p>
23
+ </slot>
24
+ </div>
25
+ <div class="nf-notification__btns" v-if="cancelButtonText || confirmButtonText">
26
+ <nf-button @click.stop="handleCancel">{{ cancelButtonText }}</nf-button>
27
+ <nf-button type="primary" @click.stop="handleConfirm">{{ confirmButtonText }}</nf-button>
28
+ </div>
29
+ <div
30
+ class="nf-notification__closeBtn el-icon-close"
31
+ v-if="showClose"
32
+ @click.stop="close"></div>
33
+ </div>
34
+ </div>
35
+ </transition>
36
+ </template>
37
+
38
+ <script>
39
+ import { defineComponent } from 'vue-demi'
40
+
41
+ const typeMap = {
42
+ success: 'success',
43
+ info: 'info',
44
+ warning: 'warning',
45
+ error: 'error'
46
+ }
47
+
48
+ export default defineComponent({
49
+ name: "nf-notification",
50
+ data() {
51
+ return {
52
+ visible: false,
53
+ title: '',
54
+ message: '',
55
+ duration: 4500,
56
+ type: '',
57
+ showClose: true,
58
+ customClass: '',
59
+ iconClass: '',
60
+ onClose: null,
61
+ onClick: null,
62
+ onCancel: null,
63
+ onConfirm: null,
64
+ closed: false,
65
+ verticalOffset: 0,
66
+ timer: null,
67
+ dangerouslyUseHTMLString: false,
68
+ position: 'top-right',
69
+ cancelButtonText: '',
70
+ confirmButtonText: ''
71
+ };
72
+ },
73
+
74
+ computed: {
75
+ typeClass() {
76
+ return this.type && typeMap[this.type] ? `el-icon-${ typeMap[this.type] }` : '';
77
+ },
78
+
79
+ horizontalClass() {
80
+ return this.position.indexOf('right') > -1 ? 'right' : 'left';
81
+ },
82
+
83
+ verticalProperty() {
84
+ return /^top-/.test(this.position) ? 'top' : 'bottom';
85
+ },
86
+
87
+ positionStyle() {
88
+ return {
89
+ [this.verticalProperty]: `${ this.verticalOffset }px`
90
+ };
91
+ }
92
+ },
93
+
94
+ watch: {
95
+ closed(newVal) {
96
+ if (newVal) {
97
+ this.visible = false;
98
+ this.$el.addEventListener('transitionend', this.destroyElement);
99
+ }
100
+ }
101
+ },
102
+
103
+ methods: {
104
+ destroyElement() {
105
+ this.$el.removeEventListener('transitionend', this.destroyElement);
106
+ this.$destroy(true);
107
+ this.$el.parentNode.removeChild(this.$el);
108
+ },
109
+
110
+ click() {
111
+ if (typeof this.onClick === 'function') {
112
+ this.onClick();
113
+ }
114
+ },
115
+
116
+ handleCancel() {
117
+ if (typeof this.onCancel === 'function') {
118
+ this.onCancel();
119
+ }
120
+ },
121
+
122
+ handleConfirm() {
123
+ if (typeof this.onConfirm === 'function') {
124
+ this.onConfirm();
125
+ }
126
+ },
127
+
128
+ close() {
129
+ this.closed = true;
130
+ if (typeof this.onClose === 'function') {
131
+ this.onClose();
132
+ }
133
+ },
134
+
135
+ clearTimer() {
136
+ clearTimeout(this.timer);
137
+ },
138
+
139
+ startTimer() {
140
+ if (this.duration > 0) {
141
+ this.timer = setTimeout(() => {
142
+ if (!this.closed) {
143
+ this.close();
144
+ }
145
+ }, this.duration);
146
+ }
147
+ },
148
+ keydown(e) {
149
+ if (e.keyCode === 46 || e.keyCode === 8) {
150
+ this.clearTimer(); // detele 取消倒计时
151
+ } else if (e.keyCode === 27) { // esc关闭消息
152
+ if (!this.closed) {
153
+ this.close();
154
+ }
155
+ } else {
156
+ this.startTimer(); // 恢复倒计时
157
+ }
158
+ }
159
+ },
160
+ mounted() {
161
+ if (this.duration > 0) {
162
+ this.timer = setTimeout(() => {
163
+ if (!this.closed) {
164
+ this.close();
165
+ }
166
+ }, this.duration);
167
+ }
168
+ document.addEventListener('keydown', this.keydown);
169
+ },
170
+ beforeDestroy() {
171
+ document.removeEventListener('keydown', this.keydown);
172
+ }
173
+ })
174
+ </script>
@@ -0,0 +1 @@
1
+ import '@94ai/nf-theme-chalk/lib/css/nf-notification.css'
@@ -0,0 +1 @@
1
+ import '@94ai/nf-theme-chalk/lib/nf-notification.scss'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@94ai/nf-notification",
3
- "version": "3.1.37",
3
+ "version": "3.1.38",
4
4
  "description": "> TODO: description",
5
5
  "keywords": [],
6
6
  "author": "zhongzhenjie <1476686104@qq.com>",
@@ -14,7 +14,7 @@
14
14
  "url": "http://94ai.gitlab.com/zoujiahe/common-ui.git"
15
15
  },
16
16
  "dependencies": {
17
- "@94ai/nf-theme-chalk": "^3.1.37",
17
+ "@94ai/nf-theme-chalk": "^1.0.0",
18
18
  "vue-demi": "^0.14.5"
19
19
  },
20
20
  "peerDependenciesMeta": {
@@ -30,5 +30,5 @@
30
30
  "types": "lib/index.d.ts",
31
31
  "main": "lib/nf-notification.cjs.js",
32
32
  "module": "lib/nf-notification.esm-bundler.js",
33
- "gitHead": "14dfc729b9988003d4686b414e1e9c0aaa7c4dcd"
33
+ "gitHead": "2b60696b405feafbbaeed385e5bcf666ceefbf2c"
34
34
  }