message-box.js 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184
  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 = 69);
  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. /***/ 12:
  180. /***/ (function(module, exports) {
  181. module.exports = require("element-ui/lib/utils/popup");
  182. /***/ }),
  183. /***/ 15:
  184. /***/ (function(module, exports) {
  185. module.exports = require("element-ui/lib/button");
  186. /***/ }),
  187. /***/ 18:
  188. /***/ (function(module, exports) {
  189. module.exports = require("element-ui/lib/locale");
  190. /***/ }),
  191. /***/ 2:
  192. /***/ (function(module, exports) {
  193. module.exports = require("element-ui/lib/utils/dom");
  194. /***/ }),
  195. /***/ 20:
  196. /***/ (function(module, exports) {
  197. module.exports = require("element-ui/lib/utils/vdom");
  198. /***/ }),
  199. /***/ 44:
  200. /***/ (function(module, exports) {
  201. module.exports = require("element-ui/lib/utils/aria-dialog");
  202. /***/ }),
  203. /***/ 6:
  204. /***/ (function(module, exports) {
  205. module.exports = require("vue");
  206. /***/ }),
  207. /***/ 69:
  208. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  209. "use strict";
  210. __webpack_require__.r(__webpack_exports__);
  211. // EXTERNAL MODULE: external "vue"
  212. var external_vue_ = __webpack_require__(6);
  213. var external_vue_default = /*#__PURE__*/__webpack_require__.n(external_vue_);
  214. // 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&
  215. var render = function() {
  216. var _vm = this
  217. var _h = _vm.$createElement
  218. var _c = _vm._self._c || _h
  219. return _c("transition", { attrs: { name: "msgbox-fade" } }, [
  220. _c(
  221. "div",
  222. {
  223. directives: [
  224. {
  225. name: "show",
  226. rawName: "v-show",
  227. value: _vm.visible,
  228. expression: "visible"
  229. }
  230. ],
  231. staticClass: "el-message-box__wrapper",
  232. attrs: {
  233. tabindex: "-1",
  234. role: "dialog",
  235. "aria-modal": "true",
  236. "aria-label": _vm.title || "dialog"
  237. },
  238. on: {
  239. click: function($event) {
  240. if ($event.target !== $event.currentTarget) {
  241. return null
  242. }
  243. return _vm.handleWrapperClick($event)
  244. }
  245. }
  246. },
  247. [
  248. _c(
  249. "div",
  250. {
  251. staticClass: "el-message-box",
  252. class: [_vm.customClass, _vm.center && "el-message-box--center"]
  253. },
  254. [
  255. _vm.title !== null
  256. ? _c("div", { staticClass: "el-message-box__header" }, [
  257. _c("div", { staticClass: "el-message-box__title" }, [
  258. _vm.icon && _vm.center
  259. ? _c("div", {
  260. class: ["el-message-box__status", _vm.icon]
  261. })
  262. : _vm._e(),
  263. _c("span", [_vm._v(_vm._s(_vm.title))])
  264. ]),
  265. _vm.showClose
  266. ? _c(
  267. "button",
  268. {
  269. staticClass: "el-message-box__headerbtn",
  270. attrs: { type: "button", "aria-label": "Close" },
  271. on: {
  272. click: function($event) {
  273. _vm.handleAction(
  274. _vm.distinguishCancelAndClose
  275. ? "close"
  276. : "cancel"
  277. )
  278. },
  279. keydown: function($event) {
  280. if (
  281. !("button" in $event) &&
  282. _vm._k(
  283. $event.keyCode,
  284. "enter",
  285. 13,
  286. $event.key,
  287. "Enter"
  288. )
  289. ) {
  290. return null
  291. }
  292. _vm.handleAction(
  293. _vm.distinguishCancelAndClose
  294. ? "close"
  295. : "cancel"
  296. )
  297. }
  298. }
  299. },
  300. [
  301. _c("i", {
  302. staticClass: "el-message-box__close el-icon-close"
  303. })
  304. ]
  305. )
  306. : _vm._e()
  307. ])
  308. : _vm._e(),
  309. _c("div", { staticClass: "el-message-box__content" }, [
  310. _vm.icon && !_vm.center && _vm.message !== ""
  311. ? _c("div", { class: ["el-message-box__status", _vm.icon] })
  312. : _vm._e(),
  313. _vm.message !== ""
  314. ? _c(
  315. "div",
  316. { staticClass: "el-message-box__message" },
  317. [
  318. _vm._t("default", [
  319. !_vm.dangerouslyUseHTMLString
  320. ? _c("p", [_vm._v(_vm._s(_vm.message))])
  321. : _c("p", {
  322. domProps: { innerHTML: _vm._s(_vm.message) }
  323. })
  324. ])
  325. ],
  326. 2
  327. )
  328. : _vm._e(),
  329. _c(
  330. "div",
  331. {
  332. directives: [
  333. {
  334. name: "show",
  335. rawName: "v-show",
  336. value: _vm.showInput,
  337. expression: "showInput"
  338. }
  339. ],
  340. staticClass: "el-message-box__input"
  341. },
  342. [
  343. _c("el-input", {
  344. ref: "input",
  345. attrs: {
  346. type: _vm.inputType,
  347. placeholder: _vm.inputPlaceholder
  348. },
  349. nativeOn: {
  350. keydown: function($event) {
  351. if (
  352. !("button" in $event) &&
  353. _vm._k(
  354. $event.keyCode,
  355. "enter",
  356. 13,
  357. $event.key,
  358. "Enter"
  359. )
  360. ) {
  361. return null
  362. }
  363. return _vm.handleInputEnter($event)
  364. }
  365. },
  366. model: {
  367. value: _vm.inputValue,
  368. callback: function($$v) {
  369. _vm.inputValue = $$v
  370. },
  371. expression: "inputValue"
  372. }
  373. }),
  374. _c(
  375. "div",
  376. {
  377. staticClass: "el-message-box__errormsg",
  378. style: {
  379. visibility: !!_vm.editorErrorMessage
  380. ? "visible"
  381. : "hidden"
  382. }
  383. },
  384. [_vm._v(_vm._s(_vm.editorErrorMessage))]
  385. )
  386. ],
  387. 1
  388. )
  389. ]),
  390. _c(
  391. "div",
  392. { staticClass: "el-message-box__btns" },
  393. [
  394. _vm.showCancelButton
  395. ? _c(
  396. "el-button",
  397. {
  398. class: [_vm.cancelButtonClasses],
  399. attrs: {
  400. loading: _vm.cancelButtonLoading,
  401. round: _vm.roundButton,
  402. size: "small"
  403. },
  404. on: {
  405. keydown: function($event) {
  406. if (
  407. !("button" in $event) &&
  408. _vm._k(
  409. $event.keyCode,
  410. "enter",
  411. 13,
  412. $event.key,
  413. "Enter"
  414. )
  415. ) {
  416. return null
  417. }
  418. _vm.handleAction("cancel")
  419. }
  420. },
  421. nativeOn: {
  422. click: function($event) {
  423. _vm.handleAction("cancel")
  424. }
  425. }
  426. },
  427. [
  428. _vm._v(
  429. "\n " +
  430. _vm._s(
  431. _vm.cancelButtonText ||
  432. _vm.t("el.messagebox.cancel")
  433. ) +
  434. "\n "
  435. )
  436. ]
  437. )
  438. : _vm._e(),
  439. _c(
  440. "el-button",
  441. {
  442. directives: [
  443. {
  444. name: "show",
  445. rawName: "v-show",
  446. value: _vm.showConfirmButton,
  447. expression: "showConfirmButton"
  448. }
  449. ],
  450. ref: "confirm",
  451. class: [_vm.confirmButtonClasses],
  452. attrs: {
  453. loading: _vm.confirmButtonLoading,
  454. round: _vm.roundButton,
  455. size: "small"
  456. },
  457. on: {
  458. keydown: function($event) {
  459. if (
  460. !("button" in $event) &&
  461. _vm._k(
  462. $event.keyCode,
  463. "enter",
  464. 13,
  465. $event.key,
  466. "Enter"
  467. )
  468. ) {
  469. return null
  470. }
  471. _vm.handleAction("confirm")
  472. }
  473. },
  474. nativeOn: {
  475. click: function($event) {
  476. _vm.handleAction("confirm")
  477. }
  478. }
  479. },
  480. [
  481. _vm._v(
  482. "\n " +
  483. _vm._s(
  484. _vm.confirmButtonText ||
  485. _vm.t("el.messagebox.confirm")
  486. ) +
  487. "\n "
  488. )
  489. ]
  490. )
  491. ],
  492. 1
  493. )
  494. ]
  495. )
  496. ]
  497. )
  498. ])
  499. }
  500. var staticRenderFns = []
  501. render._withStripped = true
  502. // CONCATENATED MODULE: ./packages/message-box/src/main.vue?vue&type=template&id=6b29b012&
  503. // EXTERNAL MODULE: external "element-ui/lib/utils/popup"
  504. var popup_ = __webpack_require__(12);
  505. var popup_default = /*#__PURE__*/__webpack_require__.n(popup_);
  506. // EXTERNAL MODULE: external "element-ui/lib/mixins/locale"
  507. var locale_ = __webpack_require__(7);
  508. var locale_default = /*#__PURE__*/__webpack_require__.n(locale_);
  509. // EXTERNAL MODULE: external "element-ui/lib/input"
  510. var input_ = __webpack_require__(9);
  511. var input_default = /*#__PURE__*/__webpack_require__.n(input_);
  512. // EXTERNAL MODULE: external "element-ui/lib/button"
  513. var button_ = __webpack_require__(15);
  514. var button_default = /*#__PURE__*/__webpack_require__.n(button_);
  515. // EXTERNAL MODULE: external "element-ui/lib/utils/dom"
  516. var dom_ = __webpack_require__(2);
  517. // EXTERNAL MODULE: external "element-ui/lib/locale"
  518. var lib_locale_ = __webpack_require__(18);
  519. // EXTERNAL MODULE: external "element-ui/lib/utils/aria-dialog"
  520. var aria_dialog_ = __webpack_require__(44);
  521. var aria_dialog_default = /*#__PURE__*/__webpack_require__.n(aria_dialog_);
  522. // 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&
  523. //
  524. //
  525. //
  526. //
  527. //
  528. //
  529. //
  530. //
  531. //
  532. //
  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. var messageBox = void 0;
  602. var typeMap = {
  603. success: 'success',
  604. info: 'info',
  605. warning: 'warning',
  606. error: 'error'
  607. };
  608. /* harmony default export */ var mainvue_type_script_lang_js_ = ({
  609. mixins: [popup_default.a, locale_default.a],
  610. props: {
  611. modal: {
  612. default: true
  613. },
  614. lockScroll: {
  615. default: true
  616. },
  617. showClose: {
  618. type: Boolean,
  619. default: true
  620. },
  621. closeOnClickModal: {
  622. default: true
  623. },
  624. closeOnPressEscape: {
  625. default: true
  626. },
  627. closeOnHashChange: {
  628. default: true
  629. },
  630. center: {
  631. default: false,
  632. type: Boolean
  633. },
  634. roundButton: {
  635. default: false,
  636. type: Boolean
  637. }
  638. },
  639. components: {
  640. ElInput: input_default.a,
  641. ElButton: button_default.a
  642. },
  643. computed: {
  644. icon: function icon() {
  645. var type = this.type,
  646. iconClass = this.iconClass;
  647. return iconClass || (type && typeMap[type] ? 'el-icon-' + typeMap[type] : '');
  648. },
  649. confirmButtonClasses: function confirmButtonClasses() {
  650. return 'el-button--primary ' + this.confirmButtonClass;
  651. },
  652. cancelButtonClasses: function cancelButtonClasses() {
  653. return '' + this.cancelButtonClass;
  654. }
  655. },
  656. methods: {
  657. getSafeClose: function getSafeClose() {
  658. var _this = this;
  659. var currentId = this.uid;
  660. return function () {
  661. _this.$nextTick(function () {
  662. if (currentId === _this.uid) _this.doClose();
  663. });
  664. };
  665. },
  666. doClose: function doClose() {
  667. var _this2 = this;
  668. if (!this.visible) return;
  669. this.visible = false;
  670. this._closing = true;
  671. this.onClose && this.onClose();
  672. messageBox.closeDialog(); // 解绑
  673. if (this.lockScroll) {
  674. setTimeout(this.restoreBodyStyle, 200);
  675. }
  676. this.opened = false;
  677. this.doAfterClose();
  678. setTimeout(function () {
  679. if (_this2.action) _this2.callback(_this2.action, _this2);
  680. });
  681. },
  682. handleWrapperClick: function handleWrapperClick() {
  683. if (this.closeOnClickModal) {
  684. this.handleAction(this.distinguishCancelAndClose ? 'close' : 'cancel');
  685. }
  686. },
  687. handleInputEnter: function handleInputEnter() {
  688. if (this.inputType !== 'textarea') {
  689. return this.handleAction('confirm');
  690. }
  691. },
  692. handleAction: function handleAction(action) {
  693. if (this.$type === 'prompt' && action === 'confirm' && !this.validate()) {
  694. return;
  695. }
  696. this.action = action;
  697. if (typeof this.beforeClose === 'function') {
  698. this.close = this.getSafeClose();
  699. this.beforeClose(action, this, this.close);
  700. } else {
  701. this.doClose();
  702. }
  703. },
  704. validate: function validate() {
  705. if (this.$type === 'prompt') {
  706. var inputPattern = this.inputPattern;
  707. if (inputPattern && !inputPattern.test(this.inputValue || '')) {
  708. this.editorErrorMessage = this.inputErrorMessage || Object(lib_locale_["t"])('el.messagebox.error');
  709. Object(dom_["addClass"])(this.getInputElement(), 'invalid');
  710. return false;
  711. }
  712. var inputValidator = this.inputValidator;
  713. if (typeof inputValidator === 'function') {
  714. var validateResult = inputValidator(this.inputValue);
  715. if (validateResult === false) {
  716. this.editorErrorMessage = this.inputErrorMessage || Object(lib_locale_["t"])('el.messagebox.error');
  717. Object(dom_["addClass"])(this.getInputElement(), 'invalid');
  718. return false;
  719. }
  720. if (typeof validateResult === 'string') {
  721. this.editorErrorMessage = validateResult;
  722. Object(dom_["addClass"])(this.getInputElement(), 'invalid');
  723. return false;
  724. }
  725. }
  726. }
  727. this.editorErrorMessage = '';
  728. Object(dom_["removeClass"])(this.getInputElement(), 'invalid');
  729. return true;
  730. },
  731. getFirstFocus: function getFirstFocus() {
  732. var btn = this.$el.querySelector('.el-message-box__btns .el-button');
  733. var title = this.$el.querySelector('.el-message-box__btns .el-message-box__title');
  734. return btn || title;
  735. },
  736. getInputElement: function getInputElement() {
  737. var inputRefs = this.$refs.input.$refs;
  738. return inputRefs.input || inputRefs.textarea;
  739. }
  740. },
  741. watch: {
  742. inputValue: {
  743. immediate: true,
  744. handler: function handler(val) {
  745. var _this3 = this;
  746. this.$nextTick(function (_) {
  747. if (_this3.$type === 'prompt' && val !== null) {
  748. _this3.validate();
  749. }
  750. });
  751. }
  752. },
  753. visible: function visible(val) {
  754. var _this4 = this;
  755. if (val) {
  756. this.uid++;
  757. if (this.$type === 'alert' || this.$type === 'confirm') {
  758. this.$nextTick(function () {
  759. _this4.$refs.confirm.$el.focus();
  760. });
  761. }
  762. this.focusAfterClosed = document.activeElement;
  763. messageBox = new aria_dialog_default.a(this.$el, this.focusAfterClosed, this.getFirstFocus());
  764. }
  765. // prompt
  766. if (this.$type !== 'prompt') return;
  767. if (val) {
  768. setTimeout(function () {
  769. if (_this4.$refs.input && _this4.$refs.input.$el) {
  770. _this4.getInputElement().focus();
  771. }
  772. }, 500);
  773. } else {
  774. this.editorErrorMessage = '';
  775. Object(dom_["removeClass"])(this.getInputElement(), 'invalid');
  776. }
  777. }
  778. },
  779. mounted: function mounted() {
  780. var _this5 = this;
  781. this.$nextTick(function () {
  782. if (_this5.closeOnHashChange) {
  783. window.addEventListener('hashchange', _this5.close);
  784. }
  785. });
  786. },
  787. beforeDestroy: function beforeDestroy() {
  788. if (this.closeOnHashChange) {
  789. window.removeEventListener('hashchange', this.close);
  790. }
  791. setTimeout(function () {
  792. messageBox.closeDialog();
  793. });
  794. },
  795. data: function data() {
  796. return {
  797. uid: 1,
  798. title: undefined,
  799. message: '',
  800. type: '',
  801. iconClass: '',
  802. customClass: '',
  803. showInput: false,
  804. inputValue: null,
  805. inputPlaceholder: '',
  806. inputType: 'text',
  807. inputPattern: null,
  808. inputValidator: null,
  809. inputErrorMessage: '',
  810. showConfirmButton: true,
  811. showCancelButton: false,
  812. action: '',
  813. confirmButtonText: '',
  814. cancelButtonText: '',
  815. confirmButtonLoading: false,
  816. cancelButtonLoading: false,
  817. confirmButtonClass: '',
  818. confirmButtonDisabled: false,
  819. cancelButtonClass: '',
  820. editorErrorMessage: null,
  821. callback: null,
  822. dangerouslyUseHTMLString: false,
  823. focusAfterClosed: null,
  824. isOnComposition: false,
  825. distinguishCancelAndClose: false
  826. };
  827. }
  828. });
  829. // CONCATENATED MODULE: ./packages/message-box/src/main.vue?vue&type=script&lang=js&
  830. /* harmony default export */ var src_mainvue_type_script_lang_js_ = (mainvue_type_script_lang_js_);
  831. // EXTERNAL MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js
  832. var componentNormalizer = __webpack_require__(0);
  833. // CONCATENATED MODULE: ./packages/message-box/src/main.vue
  834. /* normalize component */
  835. var component = Object(componentNormalizer["a" /* default */])(
  836. src_mainvue_type_script_lang_js_,
  837. render,
  838. staticRenderFns,
  839. false,
  840. null,
  841. null,
  842. null
  843. )
  844. /* hot reload */
  845. if (false) { var api; }
  846. component.options.__file = "packages/message-box/src/main.vue"
  847. /* harmony default export */ var main = (component.exports);
  848. // EXTERNAL MODULE: external "element-ui/lib/utils/merge"
  849. var merge_ = __webpack_require__(8);
  850. var merge_default = /*#__PURE__*/__webpack_require__.n(merge_);
  851. // EXTERNAL MODULE: external "element-ui/lib/utils/vdom"
  852. var vdom_ = __webpack_require__(20);
  853. // CONCATENATED MODULE: ./packages/message-box/src/main.js
  854. 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; };
  855. var defaults = {
  856. title: null,
  857. message: '',
  858. type: '',
  859. iconClass: '',
  860. showInput: false,
  861. showClose: true,
  862. modalFade: true,
  863. lockScroll: true,
  864. closeOnClickModal: true,
  865. closeOnPressEscape: true,
  866. closeOnHashChange: true,
  867. inputValue: null,
  868. inputPlaceholder: '',
  869. inputType: 'text',
  870. inputPattern: null,
  871. inputValidator: null,
  872. inputErrorMessage: '',
  873. showConfirmButton: true,
  874. showCancelButton: false,
  875. confirmButtonPosition: 'right',
  876. confirmButtonHighlight: false,
  877. cancelButtonHighlight: false,
  878. confirmButtonText: '',
  879. cancelButtonText: '',
  880. confirmButtonClass: '',
  881. cancelButtonClass: '',
  882. customClass: '',
  883. beforeClose: null,
  884. dangerouslyUseHTMLString: false,
  885. center: false,
  886. roundButton: false,
  887. distinguishCancelAndClose: false
  888. };
  889. var MessageBoxConstructor = external_vue_default.a.extend(main);
  890. var currentMsg = void 0,
  891. instance = void 0;
  892. var msgQueue = [];
  893. var defaultCallback = function defaultCallback(action) {
  894. if (currentMsg) {
  895. var callback = currentMsg.callback;
  896. if (typeof callback === 'function') {
  897. if (instance.showInput) {
  898. callback(instance.inputValue, action);
  899. } else {
  900. callback(action);
  901. }
  902. }
  903. if (currentMsg.resolve) {
  904. if (action === 'confirm') {
  905. if (instance.showInput) {
  906. currentMsg.resolve({ value: instance.inputValue, action: action });
  907. } else {
  908. currentMsg.resolve(action);
  909. }
  910. } else if (currentMsg.reject && (action === 'cancel' || action === 'close')) {
  911. currentMsg.reject(action);
  912. }
  913. }
  914. }
  915. };
  916. var initInstance = function initInstance() {
  917. instance = new MessageBoxConstructor({
  918. el: document.createElement('div')
  919. });
  920. instance.callback = defaultCallback;
  921. };
  922. var main_showNextMsg = function showNextMsg() {
  923. if (!instance) {
  924. initInstance();
  925. }
  926. instance.action = '';
  927. if (!instance.visible || instance.closeTimer) {
  928. if (msgQueue.length > 0) {
  929. currentMsg = msgQueue.shift();
  930. var options = currentMsg.options;
  931. for (var prop in options) {
  932. if (options.hasOwnProperty(prop)) {
  933. instance[prop] = options[prop];
  934. }
  935. }
  936. if (options.callback === undefined) {
  937. instance.callback = defaultCallback;
  938. }
  939. var oldCb = instance.callback;
  940. instance.callback = function (action, instance) {
  941. oldCb(action, instance);
  942. showNextMsg();
  943. };
  944. if (Object(vdom_["isVNode"])(instance.message)) {
  945. instance.$slots.default = [instance.message];
  946. instance.message = null;
  947. } else {
  948. delete instance.$slots.default;
  949. }
  950. ['modal', 'showClose', 'closeOnClickModal', 'closeOnPressEscape', 'closeOnHashChange'].forEach(function (prop) {
  951. if (instance[prop] === undefined) {
  952. instance[prop] = true;
  953. }
  954. });
  955. document.body.appendChild(instance.$el);
  956. external_vue_default.a.nextTick(function () {
  957. instance.visible = true;
  958. });
  959. }
  960. }
  961. };
  962. var main_MessageBox = function MessageBox(options, callback) {
  963. if (external_vue_default.a.prototype.$isServer) return;
  964. if (typeof options === 'string' || Object(vdom_["isVNode"])(options)) {
  965. options = {
  966. message: options
  967. };
  968. if (typeof arguments[1] === 'string') {
  969. options.title = arguments[1];
  970. }
  971. } else if (options.callback && !callback) {
  972. callback = options.callback;
  973. }
  974. if (typeof Promise !== 'undefined') {
  975. return new Promise(function (resolve, reject) {
  976. // eslint-disable-line
  977. msgQueue.push({
  978. options: merge_default()({}, defaults, MessageBox.defaults, options),
  979. callback: callback,
  980. resolve: resolve,
  981. reject: reject
  982. });
  983. main_showNextMsg();
  984. });
  985. } else {
  986. msgQueue.push({
  987. options: merge_default()({}, defaults, MessageBox.defaults, options),
  988. callback: callback
  989. });
  990. main_showNextMsg();
  991. }
  992. };
  993. main_MessageBox.setDefaults = function (defaults) {
  994. main_MessageBox.defaults = defaults;
  995. };
  996. main_MessageBox.alert = function (message, title, options) {
  997. if ((typeof title === 'undefined' ? 'undefined' : _typeof(title)) === 'object') {
  998. options = title;
  999. title = '';
  1000. } else if (title === undefined) {
  1001. title = '';
  1002. }
  1003. return main_MessageBox(merge_default()({
  1004. title: title,
  1005. message: message,
  1006. $type: 'alert',
  1007. closeOnPressEscape: false,
  1008. closeOnClickModal: false
  1009. }, options));
  1010. };
  1011. main_MessageBox.confirm = 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: 'confirm',
  1022. showCancelButton: true
  1023. }, options));
  1024. };
  1025. main_MessageBox.prompt = function (message, title, options) {
  1026. if ((typeof title === 'undefined' ? 'undefined' : _typeof(title)) === 'object') {
  1027. options = title;
  1028. title = '';
  1029. } else if (title === undefined) {
  1030. title = '';
  1031. }
  1032. return main_MessageBox(merge_default()({
  1033. title: title,
  1034. message: message,
  1035. showCancelButton: true,
  1036. showInput: true,
  1037. $type: 'prompt'
  1038. }, options));
  1039. };
  1040. main_MessageBox.close = function () {
  1041. instance.doClose();
  1042. instance.visible = false;
  1043. msgQueue = [];
  1044. currentMsg = null;
  1045. };
  1046. /* harmony default export */ var src_main = (main_MessageBox);
  1047. // CONCATENATED MODULE: ./packages/message-box/index.js
  1048. /* harmony default export */ var message_box = __webpack_exports__["default"] = (src_main);
  1049. /***/ }),
  1050. /***/ 7:
  1051. /***/ (function(module, exports) {
  1052. module.exports = require("element-ui/lib/mixins/locale");
  1053. /***/ }),
  1054. /***/ 8:
  1055. /***/ (function(module, exports) {
  1056. module.exports = require("element-ui/lib/utils/merge");
  1057. /***/ }),
  1058. /***/ 9:
  1059. /***/ (function(module, exports) {
  1060. module.exports = require("element-ui/lib/input");
  1061. /***/ })
  1062. /******/ });