notification.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. module.exports =
  2. /******/ (function(modules) { // webpackBootstrap
  3. /******/ // The module cache
  4. /******/ var installedModules = {};
  5. /******/ // The require function
  6. /******/ function __webpack_require__(moduleId) {
  7. /******/ // Check if module is in cache
  8. /******/ if(installedModules[moduleId])
  9. /******/ return installedModules[moduleId].exports;
  10. /******/ // Create a new module (and put it into the cache)
  11. /******/ var module = installedModules[moduleId] = {
  12. /******/ exports: {},
  13. /******/ id: moduleId,
  14. /******/ loaded: false
  15. /******/ };
  16. /******/ // Execute the module function
  17. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  18. /******/ // Flag the module as loaded
  19. /******/ module.loaded = true;
  20. /******/ // Return the exports of the module
  21. /******/ return module.exports;
  22. /******/ }
  23. /******/ // expose the modules object (__webpack_modules__)
  24. /******/ __webpack_require__.m = modules;
  25. /******/ // expose the module cache
  26. /******/ __webpack_require__.c = installedModules;
  27. /******/ // __webpack_public_path__
  28. /******/ __webpack_require__.p = "/dist/";
  29. /******/ // Load entry module and return exports
  30. /******/ return __webpack_require__(0);
  31. /******/ })
  32. /************************************************************************/
  33. /******/ ({
  34. /***/ 0:
  35. /***/ function(module, exports, __webpack_require__) {
  36. module.exports = __webpack_require__(204);
  37. /***/ },
  38. /***/ 3:
  39. /***/ function(module, exports) {
  40. module.exports = function normalizeComponent (
  41. rawScriptExports,
  42. compiledTemplate,
  43. scopeId,
  44. cssModules
  45. ) {
  46. var esModule
  47. var scriptExports = rawScriptExports = rawScriptExports || {}
  48. // ES6 modules interop
  49. var type = typeof rawScriptExports.default
  50. if (type === 'object' || type === 'function') {
  51. esModule = rawScriptExports
  52. scriptExports = rawScriptExports.default
  53. }
  54. // Vue.extend constructor export interop
  55. var options = typeof scriptExports === 'function'
  56. ? scriptExports.options
  57. : scriptExports
  58. // render functions
  59. if (compiledTemplate) {
  60. options.render = compiledTemplate.render
  61. options.staticRenderFns = compiledTemplate.staticRenderFns
  62. }
  63. // scopedId
  64. if (scopeId) {
  65. options._scopeId = scopeId
  66. }
  67. // inject cssModules
  68. if (cssModules) {
  69. var computed = options.computed || (options.computed = {})
  70. Object.keys(cssModules).forEach(function (key) {
  71. var module = cssModules[key]
  72. computed[key] = function () { return module }
  73. })
  74. }
  75. return {
  76. esModule: esModule,
  77. exports: scriptExports,
  78. options: options
  79. }
  80. }
  81. /***/ },
  82. /***/ 56:
  83. /***/ function(module, exports) {
  84. module.exports = require("vue");
  85. /***/ },
  86. /***/ 132:
  87. /***/ function(module, exports) {
  88. module.exports = require("element-ui/lib/utils/popup");
  89. /***/ },
  90. /***/ 204:
  91. /***/ function(module, exports, __webpack_require__) {
  92. 'use strict';
  93. exports.__esModule = true;
  94. var _main = __webpack_require__(205);
  95. var _main2 = _interopRequireDefault(_main);
  96. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  97. exports.default = _main2.default;
  98. /***/ },
  99. /***/ 205:
  100. /***/ function(module, exports, __webpack_require__) {
  101. 'use strict';
  102. exports.__esModule = true;
  103. var _vue = __webpack_require__(56);
  104. var _vue2 = _interopRequireDefault(_vue);
  105. var _popup = __webpack_require__(132);
  106. var _vdom = __webpack_require__(206);
  107. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  108. var NotificationConstructor = _vue2.default.extend(__webpack_require__(207));
  109. var instance = void 0;
  110. var instances = [];
  111. var seed = 1;
  112. var Notification = function Notification(options) {
  113. if (_vue2.default.prototype.$isServer) return;
  114. options = options || {};
  115. var userOnClose = options.onClose;
  116. var id = 'notification_' + seed++;
  117. options.onClose = function () {
  118. Notification.close(id, userOnClose);
  119. };
  120. instance = new NotificationConstructor({
  121. data: options
  122. });
  123. if ((0, _vdom.isVNode)(options.message)) {
  124. instance.$slots.default = [options.message];
  125. options.message = '';
  126. }
  127. instance.id = id;
  128. instance.vm = instance.$mount();
  129. document.body.appendChild(instance.vm.$el);
  130. instance.vm.visible = true;
  131. instance.dom = instance.vm.$el;
  132. instance.dom.style.zIndex = _popup.PopupManager.nextZIndex();
  133. var offset = options.offset || 0;
  134. var topDist = offset;
  135. for (var i = 0, len = instances.length; i < len; i++) {
  136. topDist += instances[i].$el.offsetHeight + 16;
  137. }
  138. topDist += 16;
  139. instance.top = topDist;
  140. instances.push(instance);
  141. return instance.vm;
  142. };
  143. ['success', 'warning', 'info', 'error'].forEach(function (type) {
  144. Notification[type] = function (options) {
  145. if (typeof options === 'string' || (0, _vdom.isVNode)(options)) {
  146. options = {
  147. message: options
  148. };
  149. }
  150. options.type = type;
  151. return Notification(options);
  152. };
  153. });
  154. Notification.close = function (id, userOnClose) {
  155. var index = void 0;
  156. var removedHeight = void 0;
  157. for (var i = 0, len = instances.length; i < len; i++) {
  158. if (id === instances[i].id) {
  159. if (typeof userOnClose === 'function') {
  160. userOnClose(instances[i]);
  161. }
  162. index = i;
  163. removedHeight = instances[i].dom.offsetHeight;
  164. instances.splice(i, 1);
  165. break;
  166. }
  167. }
  168. if (len > 1) {
  169. for (i = index; i < len - 1; i++) {
  170. instances[i].dom.style.top = parseInt(instances[i].dom.style.top, 10) - removedHeight - 16 + 'px';
  171. }
  172. }
  173. };
  174. exports.default = Notification;
  175. /***/ },
  176. /***/ 206:
  177. /***/ function(module, exports) {
  178. module.exports = require("element-ui/lib/utils/vdom");
  179. /***/ },
  180. /***/ 207:
  181. /***/ function(module, exports, __webpack_require__) {
  182. var Component = __webpack_require__(3)(
  183. /* script */
  184. __webpack_require__(208),
  185. /* template */
  186. __webpack_require__(209),
  187. /* scopeId */
  188. null,
  189. /* cssModules */
  190. null
  191. )
  192. module.exports = Component.exports
  193. /***/ },
  194. /***/ 208:
  195. /***/ function(module, exports) {
  196. 'use strict';
  197. exports.__esModule = true;
  198. //
  199. //
  200. //
  201. //
  202. //
  203. //
  204. //
  205. //
  206. //
  207. //
  208. //
  209. //
  210. //
  211. //
  212. //
  213. //
  214. //
  215. //
  216. //
  217. //
  218. //
  219. //
  220. //
  221. var typeMap = {
  222. success: 'circle-check',
  223. info: 'information',
  224. warning: 'warning',
  225. error: 'circle-cross'
  226. };
  227. exports.default = {
  228. data: function data() {
  229. return {
  230. visible: false,
  231. title: '',
  232. message: '',
  233. duration: 4500,
  234. type: '',
  235. customClass: '',
  236. iconClass: '',
  237. onClose: null,
  238. closed: false,
  239. top: null,
  240. timer: null
  241. };
  242. },
  243. computed: {
  244. typeClass: function typeClass() {
  245. return this.type && typeMap[this.type] ? 'el-icon-' + typeMap[this.type] : '';
  246. }
  247. },
  248. watch: {
  249. closed: function closed(newVal) {
  250. if (newVal) {
  251. this.visible = false;
  252. this.$el.addEventListener('transitionend', this.destroyElement);
  253. }
  254. }
  255. },
  256. methods: {
  257. destroyElement: function destroyElement() {
  258. this.$el.removeEventListener('transitionend', this.destroyElement);
  259. this.$destroy(true);
  260. this.$el.parentNode.removeChild(this.$el);
  261. },
  262. close: function close() {
  263. this.closed = true;
  264. if (typeof this.onClose === 'function') {
  265. this.onClose();
  266. }
  267. },
  268. clearTimer: function clearTimer() {
  269. clearTimeout(this.timer);
  270. },
  271. startTimer: function startTimer() {
  272. var _this = this;
  273. if (this.duration > 0) {
  274. this.timer = setTimeout(function () {
  275. if (!_this.closed) {
  276. _this.close();
  277. }
  278. }, this.duration);
  279. }
  280. }
  281. },
  282. mounted: function mounted() {
  283. var _this2 = this;
  284. if (this.duration > 0) {
  285. this.timer = setTimeout(function () {
  286. if (!_this2.closed) {
  287. _this2.close();
  288. }
  289. }, this.duration);
  290. }
  291. }
  292. };
  293. /***/ },
  294. /***/ 209:
  295. /***/ function(module, exports) {
  296. module.exports={render:function (){var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;
  297. return _c('transition', {
  298. attrs: {
  299. "name": "el-notification-fade"
  300. }
  301. }, [_c('div', {
  302. directives: [{
  303. name: "show",
  304. rawName: "v-show",
  305. value: (_vm.visible),
  306. expression: "visible"
  307. }],
  308. staticClass: "el-notification",
  309. class: _vm.customClass,
  310. style: ({
  311. top: _vm.top ? _vm.top + 'px' : 'auto'
  312. }),
  313. on: {
  314. "mouseenter": function($event) {
  315. _vm.clearTimer()
  316. },
  317. "mouseleave": function($event) {
  318. _vm.startTimer()
  319. }
  320. }
  321. }, [(_vm.type || _vm.iconClass) ? _c('i', {
  322. staticClass: "el-notification__icon",
  323. class: [_vm.typeClass, _vm.iconClass]
  324. }) : _vm._e(), _c('div', {
  325. staticClass: "el-notification__group",
  326. class: {
  327. 'is-with-icon': _vm.typeClass || _vm.iconClass
  328. }
  329. }, [_c('h2', {
  330. staticClass: "el-notification__title",
  331. domProps: {
  332. "textContent": _vm._s(_vm.title)
  333. }
  334. }), _c('div', {
  335. staticClass: "el-notification__content"
  336. }, [_vm._t("default", [_vm._v(_vm._s(_vm.message))])], 2), _c('div', {
  337. staticClass: "el-notification__closeBtn el-icon-close",
  338. on: {
  339. "click": _vm.close
  340. }
  341. })])])])
  342. },staticRenderFns: []}
  343. /***/ }
  344. /******/ });