notification.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. module.exports =
  2. /******/ (function(modules) { // webpackBootstrap
  3. /******/ // The module cache
  4. /******/ var installedModules = {};
  5. /******/
  6. /******/ // The require function
  7. /******/ function __webpack_require__(moduleId) {
  8. /******/
  9. /******/ // Check if module is in cache
  10. /******/ if(installedModules[moduleId]) {
  11. /******/ return installedModules[moduleId].exports;
  12. /******/ }
  13. /******/ // Create a new module (and put it into the cache)
  14. /******/ var module = installedModules[moduleId] = {
  15. /******/ i: moduleId,
  16. /******/ l: false,
  17. /******/ exports: {}
  18. /******/ };
  19. /******/
  20. /******/ // Execute the module function
  21. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  22. /******/
  23. /******/ // Flag the module as loaded
  24. /******/ module.l = true;
  25. /******/
  26. /******/ // Return the exports of the module
  27. /******/ return module.exports;
  28. /******/ }
  29. /******/
  30. /******/
  31. /******/ // expose the modules object (__webpack_modules__)
  32. /******/ __webpack_require__.m = modules;
  33. /******/
  34. /******/ // expose the module cache
  35. /******/ __webpack_require__.c = installedModules;
  36. /******/
  37. /******/ // define getter function for harmony exports
  38. /******/ __webpack_require__.d = function(exports, name, getter) {
  39. /******/ if(!__webpack_require__.o(exports, name)) {
  40. /******/ Object.defineProperty(exports, name, {
  41. /******/ configurable: false,
  42. /******/ enumerable: true,
  43. /******/ get: getter
  44. /******/ });
  45. /******/ }
  46. /******/ };
  47. /******/
  48. /******/ // getDefaultExport function for compatibility with non-harmony modules
  49. /******/ __webpack_require__.n = function(module) {
  50. /******/ var getter = module && module.__esModule ?
  51. /******/ function getDefault() { return module['default']; } :
  52. /******/ function getModuleExports() { return module; };
  53. /******/ __webpack_require__.d(getter, 'a', getter);
  54. /******/ return getter;
  55. /******/ };
  56. /******/
  57. /******/ // Object.prototype.hasOwnProperty.call
  58. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  59. /******/
  60. /******/ // __webpack_public_path__
  61. /******/ __webpack_require__.p = "/dist/";
  62. /******/
  63. /******/ // Load entry module and return exports
  64. /******/ return __webpack_require__(__webpack_require__.s = 300);
  65. /******/ })
  66. /************************************************************************/
  67. /******/ ({
  68. /***/ 0:
  69. /***/ (function(module, exports) {
  70. /* globals __VUE_SSR_CONTEXT__ */
  71. // IMPORTANT: Do NOT use ES2015 features in this file.
  72. // This module is a runtime utility for cleaner component module output and will
  73. // be included in the final webpack user bundle.
  74. module.exports = function normalizeComponent (
  75. rawScriptExports,
  76. compiledTemplate,
  77. functionalTemplate,
  78. injectStyles,
  79. scopeId,
  80. moduleIdentifier /* server only */
  81. ) {
  82. var esModule
  83. var scriptExports = rawScriptExports = rawScriptExports || {}
  84. // ES6 modules interop
  85. var type = typeof rawScriptExports.default
  86. if (type === 'object' || type === 'function') {
  87. esModule = rawScriptExports
  88. scriptExports = rawScriptExports.default
  89. }
  90. // Vue.extend constructor export interop
  91. var options = typeof scriptExports === 'function'
  92. ? scriptExports.options
  93. : scriptExports
  94. // render functions
  95. if (compiledTemplate) {
  96. options.render = compiledTemplate.render
  97. options.staticRenderFns = compiledTemplate.staticRenderFns
  98. options._compiled = true
  99. }
  100. // functional template
  101. if (functionalTemplate) {
  102. options.functional = true
  103. }
  104. // scopedId
  105. if (scopeId) {
  106. options._scopeId = scopeId
  107. }
  108. var hook
  109. if (moduleIdentifier) { // server build
  110. hook = function (context) {
  111. // 2.3 injection
  112. context =
  113. context || // cached call
  114. (this.$vnode && this.$vnode.ssrContext) || // stateful
  115. (this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext) // functional
  116. // 2.2 with runInNewContext: true
  117. if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
  118. context = __VUE_SSR_CONTEXT__
  119. }
  120. // inject component styles
  121. if (injectStyles) {
  122. injectStyles.call(this, context)
  123. }
  124. // register component module identifier for async chunk inferrence
  125. if (context && context._registeredComponents) {
  126. context._registeredComponents.add(moduleIdentifier)
  127. }
  128. }
  129. // used by ssr in case component is cached and beforeCreate
  130. // never gets called
  131. options._ssrRegister = hook
  132. } else if (injectStyles) {
  133. hook = injectStyles
  134. }
  135. if (hook) {
  136. var functional = options.functional
  137. var existing = functional
  138. ? options.render
  139. : options.beforeCreate
  140. if (!functional) {
  141. // inject component registration as beforeCreate hook
  142. options.beforeCreate = existing
  143. ? [].concat(existing, hook)
  144. : [hook]
  145. } else {
  146. // for template-only hot-reload because in that case the render fn doesn't
  147. // go through the normalizer
  148. options._injectStyles = hook
  149. // register for functioal component in vue file
  150. options.render = function renderWithStyleInjection (h, context) {
  151. hook.call(context)
  152. return existing(h, context)
  153. }
  154. }
  155. }
  156. return {
  157. esModule: esModule,
  158. exports: scriptExports,
  159. options: options
  160. }
  161. }
  162. /***/ }),
  163. /***/ 17:
  164. /***/ (function(module, exports) {
  165. module.exports = require("element-ui/lib/utils/popup");
  166. /***/ }),
  167. /***/ 20:
  168. /***/ (function(module, exports) {
  169. module.exports = require("element-ui/lib/utils/vdom");
  170. /***/ }),
  171. /***/ 300:
  172. /***/ (function(module, exports, __webpack_require__) {
  173. module.exports = __webpack_require__(301);
  174. /***/ }),
  175. /***/ 301:
  176. /***/ (function(module, exports, __webpack_require__) {
  177. "use strict";
  178. exports.__esModule = true;
  179. var _main = __webpack_require__(302);
  180. var _main2 = _interopRequireDefault(_main);
  181. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  182. exports.default = _main2.default;
  183. /***/ }),
  184. /***/ 302:
  185. /***/ (function(module, exports, __webpack_require__) {
  186. "use strict";
  187. exports.__esModule = true;
  188. var _vue = __webpack_require__(5);
  189. var _vue2 = _interopRequireDefault(_vue);
  190. var _main = __webpack_require__(303);
  191. var _main2 = _interopRequireDefault(_main);
  192. var _popup = __webpack_require__(17);
  193. var _vdom = __webpack_require__(20);
  194. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  195. var NotificationConstructor = _vue2.default.extend(_main2.default);
  196. var instance = void 0;
  197. var instances = [];
  198. var seed = 1;
  199. var Notification = function Notification(options) {
  200. if (_vue2.default.prototype.$isServer) return;
  201. options = options || {};
  202. var userOnClose = options.onClose;
  203. var id = 'notification_' + seed++;
  204. var position = options.position || 'top-right';
  205. options.onClose = function () {
  206. Notification.close(id, userOnClose);
  207. };
  208. instance = new NotificationConstructor({
  209. data: options
  210. });
  211. if ((0, _vdom.isVNode)(options.message)) {
  212. instance.$slots.default = [options.message];
  213. options.message = '';
  214. }
  215. instance.id = id;
  216. instance.vm = instance.$mount();
  217. document.body.appendChild(instance.vm.$el);
  218. instance.vm.visible = true;
  219. instance.dom = instance.vm.$el;
  220. instance.dom.style.zIndex = _popup.PopupManager.nextZIndex();
  221. var verticalOffset = options.offset || 0;
  222. instances.filter(function (item) {
  223. return item.position === position;
  224. }).forEach(function (item) {
  225. verticalOffset += item.$el.offsetHeight + 16;
  226. });
  227. verticalOffset += 16;
  228. instance.verticalOffset = verticalOffset;
  229. instances.push(instance);
  230. return instance.vm;
  231. };
  232. ['success', 'warning', 'info', 'error'].forEach(function (type) {
  233. Notification[type] = function (options) {
  234. if (typeof options === 'string' || (0, _vdom.isVNode)(options)) {
  235. options = {
  236. message: options
  237. };
  238. }
  239. options.type = type;
  240. return Notification(options);
  241. };
  242. });
  243. Notification.close = function (id, userOnClose) {
  244. var index = -1;
  245. var len = instances.length;
  246. var instance = instances.filter(function (instance, i) {
  247. if (instance.id === id) {
  248. index = i;
  249. return true;
  250. }
  251. return false;
  252. })[0];
  253. if (!instance) return;
  254. if (typeof userOnClose === 'function') {
  255. userOnClose(instance);
  256. }
  257. instances.splice(index, 1);
  258. if (len <= 1) return;
  259. var position = instance.position;
  260. var removedHeight = instance.dom.offsetHeight;
  261. for (var i = index; i < len - 1; i++) {
  262. if (instances[i].position === position) {
  263. instances[i].dom.style[instance.verticalProperty] = parseInt(instances[i].dom.style[instance.verticalProperty], 10) - removedHeight - 16 + 'px';
  264. }
  265. }
  266. };
  267. exports.default = Notification;
  268. /***/ }),
  269. /***/ 303:
  270. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  271. "use strict";
  272. Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
  273. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_main_vue__ = __webpack_require__(304);
  274. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_main_vue___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_main_vue__);
  275. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__node_modules_vue_loader_lib_template_compiler_index_id_data_v_1951fd63_hasScoped_false_preserveWhitespace_false_buble_transforms_node_modules_vue_loader_lib_selector_type_template_index_0_main_vue__ = __webpack_require__(305);
  276. var normalizeComponent = __webpack_require__(0)
  277. /* script */
  278. /* template */
  279. /* template functional */
  280. var __vue_template_functional__ = false
  281. /* styles */
  282. var __vue_styles__ = null
  283. /* scopeId */
  284. var __vue_scopeId__ = null
  285. /* moduleIdentifier (server only) */
  286. var __vue_module_identifier__ = null
  287. var Component = normalizeComponent(
  288. __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_main_vue___default.a,
  289. __WEBPACK_IMPORTED_MODULE_1__node_modules_vue_loader_lib_template_compiler_index_id_data_v_1951fd63_hasScoped_false_preserveWhitespace_false_buble_transforms_node_modules_vue_loader_lib_selector_type_template_index_0_main_vue__["a" /* default */],
  290. __vue_template_functional__,
  291. __vue_styles__,
  292. __vue_scopeId__,
  293. __vue_module_identifier__
  294. )
  295. /* harmony default export */ __webpack_exports__["default"] = (Component.exports);
  296. /***/ }),
  297. /***/ 304:
  298. /***/ (function(module, exports, __webpack_require__) {
  299. "use strict";
  300. exports.__esModule = true;
  301. //
  302. //
  303. //
  304. //
  305. //
  306. //
  307. //
  308. //
  309. //
  310. //
  311. //
  312. //
  313. //
  314. //
  315. //
  316. //
  317. //
  318. //
  319. //
  320. //
  321. //
  322. //
  323. //
  324. //
  325. //
  326. //
  327. //
  328. //
  329. //
  330. //
  331. //
  332. //
  333. //
  334. var typeMap = {
  335. success: 'success',
  336. info: 'info',
  337. warning: 'warning',
  338. error: 'error'
  339. };
  340. exports.default = {
  341. data: function data() {
  342. return {
  343. visible: false,
  344. title: '',
  345. message: '',
  346. duration: 4500,
  347. type: '',
  348. showClose: true,
  349. customClass: '',
  350. iconClass: '',
  351. onClose: null,
  352. onClick: null,
  353. closed: false,
  354. verticalOffset: 0,
  355. timer: null,
  356. dangerouslyUseHTMLString: false,
  357. position: 'top-right'
  358. };
  359. },
  360. computed: {
  361. typeClass: function typeClass() {
  362. return this.type && typeMap[this.type] ? 'el-icon-' + typeMap[this.type] : '';
  363. },
  364. horizontalClass: function horizontalClass() {
  365. return this.position.indexOf('right') > -1 ? 'right' : 'left';
  366. },
  367. verticalProperty: function verticalProperty() {
  368. return (/^top-/.test(this.position) ? 'top' : 'bottom'
  369. );
  370. },
  371. positionStyle: function positionStyle() {
  372. var _ref;
  373. return _ref = {}, _ref[this.verticalProperty] = this.verticalOffset + 'px', _ref;
  374. }
  375. },
  376. watch: {
  377. closed: function closed(newVal) {
  378. if (newVal) {
  379. this.visible = false;
  380. this.$el.addEventListener('transitionend', this.destroyElement);
  381. }
  382. }
  383. },
  384. methods: {
  385. destroyElement: function destroyElement() {
  386. this.$el.removeEventListener('transitionend', this.destroyElement);
  387. this.$destroy(true);
  388. this.$el.parentNode.removeChild(this.$el);
  389. },
  390. click: function click() {
  391. if (typeof this.onClick === 'function') {
  392. this.onClick();
  393. }
  394. },
  395. close: function close() {
  396. this.closed = true;
  397. if (typeof this.onClose === 'function') {
  398. this.onClose();
  399. }
  400. },
  401. clearTimer: function clearTimer() {
  402. clearTimeout(this.timer);
  403. },
  404. startTimer: function startTimer() {
  405. var _this = this;
  406. if (this.duration > 0) {
  407. this.timer = setTimeout(function () {
  408. if (!_this.closed) {
  409. _this.close();
  410. }
  411. }, this.duration);
  412. }
  413. },
  414. keydown: function keydown(e) {
  415. if (e.keyCode === 46 || e.keyCode === 8) {
  416. this.clearTimer(); // detele 取消倒计时
  417. } else if (e.keyCode === 27) {
  418. // esc关闭消息
  419. if (!this.closed) {
  420. this.close();
  421. }
  422. } else {
  423. this.startTimer(); // 恢复倒计时
  424. }
  425. }
  426. },
  427. mounted: function mounted() {
  428. var _this2 = this;
  429. if (this.duration > 0) {
  430. this.timer = setTimeout(function () {
  431. if (!_this2.closed) {
  432. _this2.close();
  433. }
  434. }, this.duration);
  435. }
  436. document.addEventListener('keydown', this.keydown);
  437. },
  438. beforeDestroy: function beforeDestroy() {
  439. document.removeEventListener('keydown', this.keydown);
  440. }
  441. };
  442. /***/ }),
  443. /***/ 305:
  444. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  445. "use strict";
  446. var render = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('transition',{attrs:{"name":"el-notification-fade"}},[_c('div',{directives:[{name:"show",rawName:"v-show",value:(_vm.visible),expression:"visible"}],class:['el-notification', _vm.customClass, _vm.horizontalClass],style:(_vm.positionStyle),attrs:{"role":"alert"},on:{"mouseenter":function($event){_vm.clearTimer()},"mouseleave":function($event){_vm.startTimer()},"click":_vm.click}},[(_vm.type || _vm.iconClass)?_c('i',{staticClass:"el-notification__icon",class:[ _vm.typeClass, _vm.iconClass ]}):_vm._e(),_c('div',{staticClass:"el-notification__group",class:{ 'is-with-icon': _vm.typeClass || _vm.iconClass }},[_c('h2',{staticClass:"el-notification__title",domProps:{"textContent":_vm._s(_vm.title)}}),_c('div',{staticClass:"el-notification__content"},[_vm._t("default",[(!_vm.dangerouslyUseHTMLString)?_c('p',[_vm._v(_vm._s(_vm.message))]):_c('p',{domProps:{"innerHTML":_vm._s(_vm.message)}})])],2),(_vm.showClose)?_c('div',{staticClass:"el-notification__closeBtn el-icon-close",on:{"click":function($event){$event.stopPropagation();_vm.close($event)}}}):_vm._e()])])])}
  447. var staticRenderFns = []
  448. var esExports = { render: render, staticRenderFns: staticRenderFns }
  449. /* harmony default export */ __webpack_exports__["a"] = (esExports);
  450. /***/ }),
  451. /***/ 5:
  452. /***/ (function(module, exports) {
  453. module.exports = require("vue");
  454. /***/ })
  455. /******/ });