message-box.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191
  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, { enumerable: true, get: getter });
  41. /******/ }
  42. /******/ };
  43. /******/
  44. /******/ // define __esModule on exports
  45. /******/ __webpack_require__.r = function(exports) {
  46. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  47. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  48. /******/ }
  49. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  50. /******/ };
  51. /******/
  52. /******/ // create a fake namespace object
  53. /******/ // mode & 1: value is a module id, require it
  54. /******/ // mode & 2: merge all properties of value into the ns
  55. /******/ // mode & 4: return value when already ns object
  56. /******/ // mode & 8|1: behave like require
  57. /******/ __webpack_require__.t = function(value, mode) {
  58. /******/ if(mode & 1) value = __webpack_require__(value);
  59. /******/ if(mode & 8) return value;
  60. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  61. /******/ var ns = Object.create(null);
  62. /******/ __webpack_require__.r(ns);
  63. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  64. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  65. /******/ return ns;
  66. /******/ };
  67. /******/
  68. /******/ // getDefaultExport function for compatibility with non-harmony modules
  69. /******/ __webpack_require__.n = function(module) {
  70. /******/ var getter = module && module.__esModule ?
  71. /******/ function getDefault() { return module['default']; } :
  72. /******/ function getModuleExports() { return module; };
  73. /******/ __webpack_require__.d(getter, 'a', getter);
  74. /******/ return getter;
  75. /******/ };
  76. /******/
  77. /******/ // Object.prototype.hasOwnProperty.call
  78. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  79. /******/
  80. /******/ // __webpack_public_path__
  81. /******/ __webpack_require__.p = "/dist/";
  82. /******/
  83. /******/
  84. /******/ // Load entry module and return exports
  85. /******/ return __webpack_require__(__webpack_require__.s = 77);
  86. /******/ })
  87. /************************************************************************/
  88. /******/ ({
  89. /***/ 0:
  90. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  91. "use strict";
  92. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return normalizeComponent; });
  93. /* globals __VUE_SSR_CONTEXT__ */
  94. // IMPORTANT: Do NOT use ES2015 features in this file (except for modules).
  95. // This module is a runtime utility for cleaner component module output and will
  96. // be included in the final webpack user bundle.
  97. function normalizeComponent (
  98. scriptExports,
  99. render,
  100. staticRenderFns,
  101. functionalTemplate,
  102. injectStyles,
  103. scopeId,
  104. moduleIdentifier, /* server only */
  105. shadowMode /* vue-cli only */
  106. ) {
  107. // Vue.extend constructor export interop
  108. var options = typeof scriptExports === 'function'
  109. ? scriptExports.options
  110. : scriptExports
  111. // render functions
  112. if (render) {
  113. options.render = render
  114. options.staticRenderFns = staticRenderFns
  115. options._compiled = true
  116. }
  117. // functional template
  118. if (functionalTemplate) {
  119. options.functional = true
  120. }
  121. // scopedId
  122. if (scopeId) {
  123. options._scopeId = 'data-v-' + scopeId
  124. }
  125. var hook
  126. if (moduleIdentifier) { // server build
  127. hook = function (context) {
  128. // 2.3 injection
  129. context =
  130. context || // cached call
  131. (this.$vnode && this.$vnode.ssrContext) || // stateful
  132. (this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext) // functional
  133. // 2.2 with runInNewContext: true
  134. if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
  135. context = __VUE_SSR_CONTEXT__
  136. }
  137. // inject component styles
  138. if (injectStyles) {
  139. injectStyles.call(this, context)
  140. }
  141. // register component module identifier for async chunk inferrence
  142. if (context && context._registeredComponents) {
  143. context._registeredComponents.add(moduleIdentifier)
  144. }
  145. }
  146. // used by ssr in case component is cached and beforeCreate
  147. // never gets called
  148. options._ssrRegister = hook
  149. } else if (injectStyles) {
  150. hook = shadowMode
  151. ? function () { injectStyles.call(this, this.$root.$options.shadowRoot) }
  152. : injectStyles
  153. }
  154. if (hook) {
  155. if (options.functional) {
  156. // for template-only hot-reload because in that case the render fn doesn't
  157. // go through the normalizer
  158. options._injectStyles = hook
  159. // register for functioal component in vue file
  160. var originalRender = options.render
  161. options.render = function renderWithStyleInjection (h, context) {
  162. hook.call(context)
  163. return originalRender(h, context)
  164. }
  165. } else {
  166. // inject component registration as beforeCreate hook
  167. var existing = options.beforeCreate
  168. options.beforeCreate = existing
  169. ? [].concat(existing, hook)
  170. : [hook]
  171. }
  172. }
  173. return {
  174. exports: scriptExports,
  175. options: options
  176. }
  177. }
  178. /***/ }),
  179. /***/ 10:
  180. /***/ (function(module, exports) {
  181. module.exports = require("element-ui/lib/input");
  182. /***/ }),
  183. /***/ 13:
  184. /***/ (function(module, exports) {
  185. module.exports = require("element-ui/lib/button");
  186. /***/ }),
  187. /***/ 15:
  188. /***/ (function(module, exports) {
  189. module.exports = require("element-ui/lib/utils/popup");
  190. /***/ }),
  191. /***/ 19:
  192. /***/ (function(module, exports) {
  193. module.exports = require("element-ui/lib/locale");
  194. /***/ }),
  195. /***/ 2:
  196. /***/ (function(module, exports) {
  197. module.exports = require("element-ui/lib/utils/dom");
  198. /***/ }),
  199. /***/ 23:
  200. /***/ (function(module, exports) {
  201. module.exports = require("element-ui/lib/utils/vdom");
  202. /***/ }),
  203. /***/ 47:
  204. /***/ (function(module, exports) {
  205. module.exports = require("element-ui/lib/utils/aria-dialog");
  206. /***/ }),
  207. /***/ 6:
  208. /***/ (function(module, exports) {
  209. module.exports = require("element-ui/lib/mixins/locale");
  210. /***/ }),
  211. /***/ 7:
  212. /***/ (function(module, exports) {
  213. module.exports = require("vue");
  214. /***/ }),
  215. /***/ 77:
  216. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  217. "use strict";
  218. __webpack_require__.r(__webpack_exports__);
  219. // EXTERNAL MODULE: external "vue"
  220. var external_vue_ = __webpack_require__(7);
  221. var external_vue_default = /*#__PURE__*/__webpack_require__.n(external_vue_);
  222. // CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./packages/message-box/src/main.vue?vue&type=template&id=6b29b012&
  223. var render = function() {
  224. var _vm = this
  225. var _h = _vm.$createElement
  226. var _c = _vm._self._c || _h
  227. return _c("transition", { attrs: { name: "msgbox-fade" } }, [
  228. _c(
  229. "div",
  230. {
  231. directives: [
  232. {
  233. name: "show",
  234. rawName: "v-show",
  235. value: _vm.visible,
  236. expression: "visible"
  237. }
  238. ],
  239. staticClass: "el-message-box__wrapper",
  240. attrs: {
  241. tabindex: "-1",
  242. role: "dialog",
  243. "aria-modal": "true",
  244. "aria-label": _vm.title || "dialog"
  245. },
  246. on: {
  247. click: function($event) {
  248. if ($event.target !== $event.currentTarget) {
  249. return null
  250. }
  251. return _vm.handleWrapperClick($event)
  252. }
  253. }
  254. },
  255. [
  256. _c(
  257. "div",
  258. {
  259. staticClass: "el-message-box",
  260. class: [_vm.customClass, _vm.center && "el-message-box--center"]
  261. },
  262. [
  263. _vm.title !== null
  264. ? _c("div", { staticClass: "el-message-box__header" }, [
  265. _c("div", { staticClass: "el-message-box__title" }, [
  266. _vm.icon && _vm.center
  267. ? _c("div", {
  268. class: ["el-message-box__status", _vm.icon]
  269. })
  270. : _vm._e(),
  271. _c("span", [_vm._v(_vm._s(_vm.title))])
  272. ]),
  273. _vm.showClose
  274. ? _c(
  275. "button",
  276. {
  277. staticClass: "el-message-box__headerbtn",
  278. attrs: { type: "button", "aria-label": "Close" },
  279. on: {
  280. click: function($event) {
  281. _vm.handleAction(
  282. _vm.distinguishCancelAndClose
  283. ? "close"
  284. : "cancel"
  285. )
  286. },
  287. keydown: function($event) {
  288. if (
  289. !("button" in $event) &&
  290. _vm._k(
  291. $event.keyCode,
  292. "enter",
  293. 13,
  294. $event.key,
  295. "Enter"
  296. )
  297. ) {
  298. return null
  299. }
  300. _vm.handleAction(
  301. _vm.distinguishCancelAndClose
  302. ? "close"
  303. : "cancel"
  304. )
  305. }
  306. }
  307. },
  308. [
  309. _c("i", {
  310. staticClass: "el-message-box__close el-icon-close"
  311. })
  312. ]
  313. )
  314. : _vm._e()
  315. ])
  316. : _vm._e(),
  317. _c("div", { staticClass: "el-message-box__content" }, [
  318. _c("div", { staticClass: "el-message-box__container" }, [
  319. _vm.icon && !_vm.center && _vm.message !== ""
  320. ? _c("div", { class: ["el-message-box__status", _vm.icon] })
  321. : _vm._e(),
  322. _vm.message !== ""
  323. ? _c(
  324. "div",
  325. { staticClass: "el-message-box__message" },
  326. [
  327. _vm._t("default", [
  328. !_vm.dangerouslyUseHTMLString
  329. ? _c("p", [_vm._v(_vm._s(_vm.message))])
  330. : _c("p", {
  331. domProps: { innerHTML: _vm._s(_vm.message) }
  332. })
  333. ])
  334. ],
  335. 2
  336. )
  337. : _vm._e()
  338. ]),
  339. _c(
  340. "div",
  341. {
  342. directives: [
  343. {
  344. name: "show",
  345. rawName: "v-show",
  346. value: _vm.showInput,
  347. expression: "showInput"
  348. }
  349. ],
  350. staticClass: "el-message-box__input"
  351. },
  352. [
  353. _c("el-input", {
  354. ref: "input",
  355. attrs: {
  356. type: _vm.inputType,
  357. placeholder: _vm.inputPlaceholder
  358. },
  359. nativeOn: {
  360. keydown: function($event) {
  361. if (
  362. !("button" in $event) &&
  363. _vm._k(
  364. $event.keyCode,
  365. "enter",
  366. 13,
  367. $event.key,
  368. "Enter"
  369. )
  370. ) {
  371. return null
  372. }
  373. return _vm.handleInputEnter($event)
  374. }
  375. },
  376. model: {
  377. value: _vm.inputValue,
  378. callback: function($$v) {
  379. _vm.inputValue = $$v
  380. },
  381. expression: "inputValue"
  382. }
  383. }),
  384. _c(
  385. "div",
  386. {
  387. staticClass: "el-message-box__errormsg",
  388. style: {
  389. visibility: !!_vm.editorErrorMessage
  390. ? "visible"
  391. : "hidden"
  392. }
  393. },
  394. [_vm._v(_vm._s(_vm.editorErrorMessage))]
  395. )
  396. ],
  397. 1
  398. )
  399. ]),
  400. _c(
  401. "div",
  402. { staticClass: "el-message-box__btns" },
  403. [
  404. _vm.showCancelButton
  405. ? _c(
  406. "el-button",
  407. {
  408. class: [_vm.cancelButtonClasses],
  409. attrs: {
  410. loading: _vm.cancelButtonLoading,
  411. round: _vm.roundButton,
  412. size: "small"
  413. },
  414. on: {
  415. keydown: function($event) {
  416. if (
  417. !("button" in $event) &&
  418. _vm._k(
  419. $event.keyCode,
  420. "enter",
  421. 13,
  422. $event.key,
  423. "Enter"
  424. )
  425. ) {
  426. return null
  427. }
  428. _vm.handleAction("cancel")
  429. }
  430. },
  431. nativeOn: {
  432. click: function($event) {
  433. _vm.handleAction("cancel")
  434. }
  435. }
  436. },
  437. [
  438. _vm._v(
  439. "\n " +
  440. _vm._s(
  441. _vm.cancelButtonText ||
  442. _vm.t("el.messagebox.cancel")
  443. ) +
  444. "\n "
  445. )
  446. ]
  447. )
  448. : _vm._e(),
  449. _c(
  450. "el-button",
  451. {
  452. directives: [
  453. {
  454. name: "show",
  455. rawName: "v-show",
  456. value: _vm.showConfirmButton,
  457. expression: "showConfirmButton"
  458. }
  459. ],
  460. ref: "confirm",
  461. class: [_vm.confirmButtonClasses],
  462. attrs: {
  463. loading: _vm.confirmButtonLoading,
  464. round: _vm.roundButton,
  465. size: "small"
  466. },
  467. on: {
  468. keydown: function($event) {
  469. if (
  470. !("button" in $event) &&
  471. _vm._k(
  472. $event.keyCode,
  473. "enter",
  474. 13,
  475. $event.key,
  476. "Enter"
  477. )
  478. ) {
  479. return null
  480. }
  481. _vm.handleAction("confirm")
  482. }
  483. },
  484. nativeOn: {
  485. click: function($event) {
  486. _vm.handleAction("confirm")
  487. }
  488. }
  489. },
  490. [
  491. _vm._v(
  492. "\n " +
  493. _vm._s(
  494. _vm.confirmButtonText ||
  495. _vm.t("el.messagebox.confirm")
  496. ) +
  497. "\n "
  498. )
  499. ]
  500. )
  501. ],
  502. 1
  503. )
  504. ]
  505. )
  506. ]
  507. )
  508. ])
  509. }
  510. var staticRenderFns = []
  511. render._withStripped = true
  512. // CONCATENATED MODULE: ./packages/message-box/src/main.vue?vue&type=template&id=6b29b012&
  513. // EXTERNAL MODULE: external "element-ui/lib/utils/popup"
  514. var popup_ = __webpack_require__(15);
  515. var popup_default = /*#__PURE__*/__webpack_require__.n(popup_);
  516. // EXTERNAL MODULE: external "element-ui/lib/mixins/locale"
  517. var locale_ = __webpack_require__(6);
  518. var locale_default = /*#__PURE__*/__webpack_require__.n(locale_);
  519. // EXTERNAL MODULE: external "element-ui/lib/input"
  520. var input_ = __webpack_require__(10);
  521. var input_default = /*#__PURE__*/__webpack_require__.n(input_);
  522. // EXTERNAL MODULE: external "element-ui/lib/button"
  523. var button_ = __webpack_require__(13);
  524. var button_default = /*#__PURE__*/__webpack_require__.n(button_);
  525. // EXTERNAL MODULE: external "element-ui/lib/utils/dom"
  526. var dom_ = __webpack_require__(2);
  527. // EXTERNAL MODULE: external "element-ui/lib/locale"
  528. var lib_locale_ = __webpack_require__(19);
  529. // EXTERNAL MODULE: external "element-ui/lib/utils/aria-dialog"
  530. var aria_dialog_ = __webpack_require__(47);
  531. var aria_dialog_default = /*#__PURE__*/__webpack_require__.n(aria_dialog_);
  532. // CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/message-box/src/main.vue?vue&type=script&lang=js&
  533. //
  534. //
  535. //
  536. //
  537. //
  538. //
  539. //
  540. //
  541. //
  542. //
  543. //
  544. //
  545. //
  546. //
  547. //
  548. //
  549. //
  550. //
  551. //
  552. //
  553. //
  554. //
  555. //
  556. //
  557. //
  558. //
  559. //
  560. //
  561. //
  562. //
  563. //
  564. //
  565. //
  566. //
  567. //
  568. //
  569. //
  570. //
  571. //
  572. //
  573. //
  574. //
  575. //
  576. //
  577. //
  578. //
  579. //
  580. //
  581. //
  582. //
  583. //
  584. //
  585. //
  586. //
  587. //
  588. //
  589. //
  590. //
  591. //
  592. //
  593. //
  594. //
  595. //
  596. //
  597. //
  598. //
  599. //
  600. //
  601. //
  602. //
  603. //
  604. //
  605. //
  606. //
  607. //
  608. //
  609. //
  610. //
  611. //
  612. //
  613. var messageBox = void 0;
  614. var typeMap = {
  615. success: 'success',
  616. info: 'info',
  617. warning: 'warning',
  618. error: 'error'
  619. };
  620. /* harmony default export */ var mainvue_type_script_lang_js_ = ({
  621. mixins: [popup_default.a, locale_default.a],
  622. props: {
  623. modal: {
  624. default: true
  625. },
  626. lockScroll: {
  627. default: true
  628. },
  629. showClose: {
  630. type: Boolean,
  631. default: true
  632. },
  633. closeOnClickModal: {
  634. default: true
  635. },
  636. closeOnPressEscape: {
  637. default: true
  638. },
  639. closeOnHashChange: {
  640. default: true
  641. },
  642. center: {
  643. default: false,
  644. type: Boolean
  645. },
  646. roundButton: {
  647. default: false,
  648. type: Boolean
  649. }
  650. },
  651. components: {
  652. ElInput: input_default.a,
  653. ElButton: button_default.a
  654. },
  655. computed: {
  656. icon: function icon() {
  657. var type = this.type,
  658. iconClass = this.iconClass;
  659. return iconClass || (type && typeMap[type] ? 'el-icon-' + typeMap[type] : '');
  660. },
  661. confirmButtonClasses: function confirmButtonClasses() {
  662. return 'el-button--primary ' + this.confirmButtonClass;
  663. },
  664. cancelButtonClasses: function cancelButtonClasses() {
  665. return '' + this.cancelButtonClass;
  666. }
  667. },
  668. methods: {
  669. getSafeClose: function getSafeClose() {
  670. var _this = this;
  671. var currentId = this.uid;
  672. return function () {
  673. _this.$nextTick(function () {
  674. if (currentId === _this.uid) _this.doClose();
  675. });
  676. };
  677. },
  678. doClose: function doClose() {
  679. var _this2 = this;
  680. if (!this.visible) return;
  681. this.visible = false;
  682. this._closing = true;
  683. this.onClose && this.onClose();
  684. messageBox.closeDialog(); // 解绑
  685. if (this.lockScroll) {
  686. setTimeout(this.restoreBodyStyle, 200);
  687. }
  688. this.opened = false;
  689. this.doAfterClose();
  690. setTimeout(function () {
  691. if (_this2.action) _this2.callback(_this2.action, _this2);
  692. });
  693. },
  694. handleWrapperClick: function handleWrapperClick() {
  695. if (this.closeOnClickModal) {
  696. this.handleAction(this.distinguishCancelAndClose ? 'close' : 'cancel');
  697. }
  698. },
  699. handleInputEnter: function handleInputEnter() {
  700. if (this.inputType !== 'textarea') {
  701. return this.handleAction('confirm');
  702. }
  703. },
  704. handleAction: function handleAction(action) {
  705. if (this.$type === 'prompt' && action === 'confirm' && !this.validate()) {
  706. return;
  707. }
  708. this.action = action;
  709. if (typeof this.beforeClose === 'function') {
  710. this.close = this.getSafeClose();
  711. this.beforeClose(action, this, this.close);
  712. } else {
  713. this.doClose();
  714. }
  715. },
  716. validate: function validate() {
  717. if (this.$type === 'prompt') {
  718. var inputPattern = this.inputPattern;
  719. if (inputPattern && !inputPattern.test(this.inputValue || '')) {
  720. this.editorErrorMessage = this.inputErrorMessage || Object(lib_locale_["t"])('el.messagebox.error');
  721. Object(dom_["addClass"])(this.getInputElement(), 'invalid');
  722. return false;
  723. }
  724. var inputValidator = this.inputValidator;
  725. if (typeof inputValidator === 'function') {
  726. var validateResult = inputValidator(this.inputValue);
  727. if (validateResult === false) {
  728. this.editorErrorMessage = this.inputErrorMessage || Object(lib_locale_["t"])('el.messagebox.error');
  729. Object(dom_["addClass"])(this.getInputElement(), 'invalid');
  730. return false;
  731. }
  732. if (typeof validateResult === 'string') {
  733. this.editorErrorMessage = validateResult;
  734. Object(dom_["addClass"])(this.getInputElement(), 'invalid');
  735. return false;
  736. }
  737. }
  738. }
  739. this.editorErrorMessage = '';
  740. Object(dom_["removeClass"])(this.getInputElement(), 'invalid');
  741. return true;
  742. },
  743. getFirstFocus: function getFirstFocus() {
  744. var btn = this.$el.querySelector('.el-message-box__btns .el-button');
  745. var title = this.$el.querySelector('.el-message-box__btns .el-message-box__title');
  746. return btn || title;
  747. },
  748. getInputElement: function getInputElement() {
  749. var inputRefs = this.$refs.input.$refs;
  750. return inputRefs.input || inputRefs.textarea;
  751. },
  752. handleClose: function handleClose() {
  753. this.handleAction('close');
  754. }
  755. },
  756. watch: {
  757. inputValue: {
  758. immediate: true,
  759. handler: function handler(val) {
  760. var _this3 = this;
  761. this.$nextTick(function (_) {
  762. if (_this3.$type === 'prompt' && val !== null) {
  763. _this3.validate();
  764. }
  765. });
  766. }
  767. },
  768. visible: function visible(val) {
  769. var _this4 = this;
  770. if (val) {
  771. this.uid++;
  772. if (this.$type === 'alert' || this.$type === 'confirm') {
  773. this.$nextTick(function () {
  774. _this4.$refs.confirm.$el.focus();
  775. });
  776. }
  777. this.focusAfterClosed = document.activeElement;
  778. messageBox = new aria_dialog_default.a(this.$el, this.focusAfterClosed, this.getFirstFocus());
  779. }
  780. // prompt
  781. if (this.$type !== 'prompt') return;
  782. if (val) {
  783. setTimeout(function () {
  784. if (_this4.$refs.input && _this4.$refs.input.$el) {
  785. _this4.getInputElement().focus();
  786. }
  787. }, 500);
  788. } else {
  789. this.editorErrorMessage = '';
  790. Object(dom_["removeClass"])(this.getInputElement(), 'invalid');
  791. }
  792. }
  793. },
  794. mounted: function mounted() {
  795. var _this5 = this;
  796. this.$nextTick(function () {
  797. if (_this5.closeOnHashChange) {
  798. window.addEventListener('hashchange', _this5.close);
  799. }
  800. });
  801. },
  802. beforeDestroy: function beforeDestroy() {
  803. if (this.closeOnHashChange) {
  804. window.removeEventListener('hashchange', this.close);
  805. }
  806. setTimeout(function () {
  807. messageBox.closeDialog();
  808. });
  809. },
  810. data: function data() {
  811. return {
  812. uid: 1,
  813. title: undefined,
  814. message: '',
  815. type: '',
  816. iconClass: '',
  817. customClass: '',
  818. showInput: false,
  819. inputValue: null,
  820. inputPlaceholder: '',
  821. inputType: 'text',
  822. inputPattern: null,
  823. inputValidator: null,
  824. inputErrorMessage: '',
  825. showConfirmButton: true,
  826. showCancelButton: false,
  827. action: '',
  828. confirmButtonText: '',
  829. cancelButtonText: '',
  830. confirmButtonLoading: false,
  831. cancelButtonLoading: false,
  832. confirmButtonClass: '',
  833. confirmButtonDisabled: false,
  834. cancelButtonClass: '',
  835. editorErrorMessage: null,
  836. callback: null,
  837. dangerouslyUseHTMLString: false,
  838. focusAfterClosed: null,
  839. isOnComposition: false,
  840. distinguishCancelAndClose: false
  841. };
  842. }
  843. });
  844. // CONCATENATED MODULE: ./packages/message-box/src/main.vue?vue&type=script&lang=js&
  845. /* harmony default export */ var src_mainvue_type_script_lang_js_ = (mainvue_type_script_lang_js_);
  846. // EXTERNAL MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js
  847. var componentNormalizer = __webpack_require__(0);
  848. // CONCATENATED MODULE: ./packages/message-box/src/main.vue
  849. /* normalize component */
  850. var component = Object(componentNormalizer["a" /* default */])(
  851. src_mainvue_type_script_lang_js_,
  852. render,
  853. staticRenderFns,
  854. false,
  855. null,
  856. null,
  857. null
  858. )
  859. /* hot reload */
  860. if (false) { var api; }
  861. component.options.__file = "packages/message-box/src/main.vue"
  862. /* harmony default export */ var main = (component.exports);
  863. // EXTERNAL MODULE: external "element-ui/lib/utils/merge"
  864. var merge_ = __webpack_require__(9);
  865. var merge_default = /*#__PURE__*/__webpack_require__.n(merge_);
  866. // EXTERNAL MODULE: external "element-ui/lib/utils/vdom"
  867. var vdom_ = __webpack_require__(23);
  868. // CONCATENATED MODULE: ./packages/message-box/src/main.js
  869. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  870. var defaults = {
  871. title: null,
  872. message: '',
  873. type: '',
  874. iconClass: '',
  875. showInput: false,
  876. showClose: true,
  877. modalFade: true,
  878. lockScroll: true,
  879. closeOnClickModal: true,
  880. closeOnPressEscape: true,
  881. closeOnHashChange: true,
  882. inputValue: null,
  883. inputPlaceholder: '',
  884. inputType: 'text',
  885. inputPattern: null,
  886. inputValidator: null,
  887. inputErrorMessage: '',
  888. showConfirmButton: true,
  889. showCancelButton: false,
  890. confirmButtonPosition: 'right',
  891. confirmButtonHighlight: false,
  892. cancelButtonHighlight: false,
  893. confirmButtonText: '',
  894. cancelButtonText: '',
  895. confirmButtonClass: '',
  896. cancelButtonClass: '',
  897. customClass: '',
  898. beforeClose: null,
  899. dangerouslyUseHTMLString: false,
  900. center: false,
  901. roundButton: false,
  902. distinguishCancelAndClose: false
  903. };
  904. var MessageBoxConstructor = external_vue_default.a.extend(main);
  905. var currentMsg = void 0,
  906. instance = void 0;
  907. var msgQueue = [];
  908. var defaultCallback = function defaultCallback(action) {
  909. if (currentMsg) {
  910. var callback = currentMsg.callback;
  911. if (typeof callback === 'function') {
  912. if (instance.showInput) {
  913. callback(instance.inputValue, action);
  914. } else {
  915. callback(action);
  916. }
  917. }
  918. if (currentMsg.resolve) {
  919. if (action === 'confirm') {
  920. if (instance.showInput) {
  921. currentMsg.resolve({ value: instance.inputValue, action: action });
  922. } else {
  923. currentMsg.resolve(action);
  924. }
  925. } else if (currentMsg.reject && (action === 'cancel' || action === 'close')) {
  926. currentMsg.reject(action);
  927. }
  928. }
  929. }
  930. };
  931. var initInstance = function initInstance() {
  932. instance = new MessageBoxConstructor({
  933. el: document.createElement('div')
  934. });
  935. instance.callback = defaultCallback;
  936. };
  937. var main_showNextMsg = function showNextMsg() {
  938. if (!instance) {
  939. initInstance();
  940. }
  941. instance.action = '';
  942. if (!instance.visible || instance.closeTimer) {
  943. if (msgQueue.length > 0) {
  944. currentMsg = msgQueue.shift();
  945. var options = currentMsg.options;
  946. for (var prop in options) {
  947. if (options.hasOwnProperty(prop)) {
  948. instance[prop] = options[prop];
  949. }
  950. }
  951. if (options.callback === undefined) {
  952. instance.callback = defaultCallback;
  953. }
  954. var oldCb = instance.callback;
  955. instance.callback = function (action, instance) {
  956. oldCb(action, instance);
  957. showNextMsg();
  958. };
  959. if (Object(vdom_["isVNode"])(instance.message)) {
  960. instance.$slots.default = [instance.message];
  961. instance.message = null;
  962. } else {
  963. delete instance.$slots.default;
  964. }
  965. ['modal', 'showClose', 'closeOnClickModal', 'closeOnPressEscape', 'closeOnHashChange'].forEach(function (prop) {
  966. if (instance[prop] === undefined) {
  967. instance[prop] = true;
  968. }
  969. });
  970. document.body.appendChild(instance.$el);
  971. external_vue_default.a.nextTick(function () {
  972. instance.visible = true;
  973. });
  974. }
  975. }
  976. };
  977. var main_MessageBox = function MessageBox(options, callback) {
  978. if (external_vue_default.a.prototype.$isServer) return;
  979. if (typeof options === 'string' || Object(vdom_["isVNode"])(options)) {
  980. options = {
  981. message: options
  982. };
  983. if (typeof arguments[1] === 'string') {
  984. options.title = arguments[1];
  985. }
  986. } else if (options.callback && !callback) {
  987. callback = options.callback;
  988. }
  989. if (typeof Promise !== 'undefined') {
  990. return new Promise(function (resolve, reject) {
  991. // eslint-disable-line
  992. msgQueue.push({
  993. options: merge_default()({}, defaults, MessageBox.defaults, options),
  994. callback: callback,
  995. resolve: resolve,
  996. reject: reject
  997. });
  998. main_showNextMsg();
  999. });
  1000. } else {
  1001. msgQueue.push({
  1002. options: merge_default()({}, defaults, MessageBox.defaults, options),
  1003. callback: callback
  1004. });
  1005. main_showNextMsg();
  1006. }
  1007. };
  1008. main_MessageBox.setDefaults = function (defaults) {
  1009. main_MessageBox.defaults = defaults;
  1010. };
  1011. main_MessageBox.alert = function (message, title, options) {
  1012. if ((typeof title === 'undefined' ? 'undefined' : _typeof(title)) === 'object') {
  1013. options = title;
  1014. title = '';
  1015. } else if (title === undefined) {
  1016. title = '';
  1017. }
  1018. return main_MessageBox(merge_default()({
  1019. title: title,
  1020. message: message,
  1021. $type: 'alert',
  1022. closeOnPressEscape: false,
  1023. closeOnClickModal: false
  1024. }, options));
  1025. };
  1026. main_MessageBox.confirm = function (message, title, options) {
  1027. if ((typeof title === 'undefined' ? 'undefined' : _typeof(title)) === 'object') {
  1028. options = title;
  1029. title = '';
  1030. } else if (title === undefined) {
  1031. title = '';
  1032. }
  1033. return main_MessageBox(merge_default()({
  1034. title: title,
  1035. message: message,
  1036. $type: 'confirm',
  1037. showCancelButton: true
  1038. }, options));
  1039. };
  1040. main_MessageBox.prompt = function (message, title, options) {
  1041. if ((typeof title === 'undefined' ? 'undefined' : _typeof(title)) === 'object') {
  1042. options = title;
  1043. title = '';
  1044. } else if (title === undefined) {
  1045. title = '';
  1046. }
  1047. return main_MessageBox(merge_default()({
  1048. title: title,
  1049. message: message,
  1050. showCancelButton: true,
  1051. showInput: true,
  1052. $type: 'prompt'
  1053. }, options));
  1054. };
  1055. main_MessageBox.close = function () {
  1056. instance.doClose();
  1057. instance.visible = false;
  1058. msgQueue = [];
  1059. currentMsg = null;
  1060. };
  1061. /* harmony default export */ var src_main = (main_MessageBox);
  1062. // CONCATENATED MODULE: ./packages/message-box/index.js
  1063. /* harmony default export */ var message_box = __webpack_exports__["default"] = (src_main);
  1064. /***/ }),
  1065. /***/ 9:
  1066. /***/ (function(module, exports) {
  1067. module.exports = require("element-ui/lib/utils/merge");
  1068. /***/ })
  1069. /******/ });