loading.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  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__(170);
  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. /***/ 117:
  87. /***/ function(module, exports) {
  88. module.exports = require("element-ui/lib/utils/dom");
  89. /***/ },
  90. /***/ 164:
  91. /***/ function(module, exports) {
  92. module.exports = require("element-ui/lib/utils/merge");
  93. /***/ },
  94. /***/ 170:
  95. /***/ function(module, exports, __webpack_require__) {
  96. 'use strict';
  97. exports.__esModule = true;
  98. var _directive = __webpack_require__(171);
  99. var _directive2 = _interopRequireDefault(_directive);
  100. var _index = __webpack_require__(175);
  101. var _index2 = _interopRequireDefault(_index);
  102. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  103. exports.default = {
  104. install: function install(Vue) {
  105. Vue.use(_directive2.default);
  106. Vue.prototype.$loading = _index2.default;
  107. },
  108. directive: _directive2.default,
  109. service: _index2.default
  110. };
  111. /***/ },
  112. /***/ 171:
  113. /***/ function(module, exports, __webpack_require__) {
  114. 'use strict';
  115. var _vue = __webpack_require__(56);
  116. var _vue2 = _interopRequireDefault(_vue);
  117. var _dom = __webpack_require__(117);
  118. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  119. var Mask = _vue2.default.extend(__webpack_require__(172));
  120. exports.install = function (Vue) {
  121. if (Vue.prototype.$isServer) return;
  122. var toggleLoading = function toggleLoading(el, binding) {
  123. if (binding.value) {
  124. Vue.nextTick(function () {
  125. if (binding.modifiers.fullscreen) {
  126. el.originalPosition = document.body.style.position;
  127. el.originalOverflow = document.body.style.overflow;
  128. (0, _dom.addClass)(el.mask, 'is-fullscreen');
  129. insertDom(document.body, el, binding);
  130. } else {
  131. (0, _dom.removeClass)(el.mask, 'is-fullscreen');
  132. if (binding.modifiers.body) {
  133. el.originalPosition = document.body.style.position;
  134. ['top', 'left'].forEach(function (property) {
  135. var scroll = property === 'top' ? 'scrollTop' : 'scrollLeft';
  136. el.maskStyle[property] = el.getBoundingClientRect()[property] + document.body[scroll] + document.documentElement[scroll] + 'px';
  137. });
  138. ['height', 'width'].forEach(function (property) {
  139. el.maskStyle[property] = el.getBoundingClientRect()[property] + 'px';
  140. });
  141. insertDom(document.body, el, binding);
  142. } else {
  143. el.originalPosition = el.style.position;
  144. insertDom(el, el, binding);
  145. }
  146. }
  147. });
  148. } else {
  149. if (el.domVisible) {
  150. el.instance.$on('after-leave', function (_) {
  151. el.domVisible = false;
  152. if (binding.modifiers.fullscreen && el.originalOverflow !== 'hidden') {
  153. document.body.style.overflow = el.originalOverflow;
  154. }
  155. if (binding.modifiers.fullscreen || binding.modifiers.body) {
  156. document.body.style.position = el.originalPosition;
  157. } else {
  158. el.style.position = el.originalPosition;
  159. }
  160. });
  161. el.instance.visible = false;
  162. }
  163. }
  164. };
  165. var insertDom = function insertDom(parent, el, binding) {
  166. if (!el.domVisible) {
  167. Object.keys(el.maskStyle).forEach(function (property) {
  168. el.mask.style[property] = el.maskStyle[property];
  169. });
  170. if (el.originalPosition !== 'absolute') {
  171. parent.style.position = 'relative';
  172. }
  173. if (binding.modifiers.fullscreen && binding.modifiers.lock) {
  174. parent.style.overflow = 'hidden';
  175. }
  176. el.domVisible = true;
  177. parent.appendChild(el.mask);
  178. Vue.nextTick(function () {
  179. el.instance.visible = true;
  180. });
  181. el.domInserted = true;
  182. }
  183. };
  184. Vue.directive('loading', {
  185. bind: function bind(el, binding) {
  186. var mask = new Mask({
  187. el: document.createElement('div'),
  188. data: {
  189. text: el.getAttribute('element-loading-text'),
  190. fullscreen: !!binding.modifiers.fullscreen
  191. }
  192. });
  193. el.instance = mask;
  194. el.mask = mask.$el;
  195. el.maskStyle = {};
  196. toggleLoading(el, binding);
  197. },
  198. update: function update(el, binding) {
  199. el.instance.setText(el.getAttribute('element-loading-text'));
  200. if (binding.oldValue !== binding.value) {
  201. toggleLoading(el, binding);
  202. }
  203. },
  204. unbind: function unbind(el, binding) {
  205. if (el.domInserted) {
  206. if (binding.modifiers.fullscreen || binding.modifiers.body) {
  207. document.body.removeChild(el.mask);
  208. } else {
  209. el.mask && el.mask.parentNode && el.mask.parentNode.removeChild(el.mask);
  210. }
  211. }
  212. }
  213. });
  214. };
  215. /***/ },
  216. /***/ 172:
  217. /***/ function(module, exports, __webpack_require__) {
  218. var Component = __webpack_require__(3)(
  219. /* script */
  220. __webpack_require__(173),
  221. /* template */
  222. __webpack_require__(174),
  223. /* scopeId */
  224. null,
  225. /* cssModules */
  226. null
  227. )
  228. module.exports = Component.exports
  229. /***/ },
  230. /***/ 173:
  231. /***/ function(module, exports) {
  232. 'use strict';
  233. exports.__esModule = true;
  234. //
  235. //
  236. //
  237. //
  238. //
  239. //
  240. //
  241. //
  242. //
  243. //
  244. //
  245. //
  246. //
  247. //
  248. //
  249. //
  250. exports.default = {
  251. data: function data() {
  252. return {
  253. text: null,
  254. fullscreen: true,
  255. visible: false,
  256. customClass: ''
  257. };
  258. },
  259. methods: {
  260. handleAfterLeave: function handleAfterLeave() {
  261. this.$emit('after-leave');
  262. },
  263. setText: function setText(text) {
  264. this.text = text;
  265. }
  266. }
  267. };
  268. /***/ },
  269. /***/ 174:
  270. /***/ function(module, exports) {
  271. module.exports={render:function (){var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;
  272. return _c('transition', {
  273. attrs: {
  274. "name": "el-loading-fade"
  275. },
  276. on: {
  277. "after-leave": _vm.handleAfterLeave
  278. }
  279. }, [_c('div', {
  280. directives: [{
  281. name: "show",
  282. rawName: "v-show",
  283. value: (_vm.visible),
  284. expression: "visible"
  285. }],
  286. staticClass: "el-loading-mask",
  287. class: [_vm.customClass, {
  288. 'is-fullscreen': _vm.fullscreen
  289. }]
  290. }, [_c('div', {
  291. staticClass: "el-loading-spinner"
  292. }, [_c('svg', {
  293. staticClass: "circular",
  294. attrs: {
  295. "viewBox": "25 25 50 50"
  296. }
  297. }, [_c('circle', {
  298. staticClass: "path",
  299. attrs: {
  300. "cx": "50",
  301. "cy": "50",
  302. "r": "20",
  303. "fill": "none"
  304. }
  305. })]), (_vm.text) ? _c('p', {
  306. staticClass: "el-loading-text"
  307. }, [_vm._v(_vm._s(_vm.text))]) : _vm._e()])])])
  308. },staticRenderFns: []}
  309. /***/ },
  310. /***/ 175:
  311. /***/ function(module, exports, __webpack_require__) {
  312. 'use strict';
  313. exports.__esModule = true;
  314. var _vue = __webpack_require__(56);
  315. var _vue2 = _interopRequireDefault(_vue);
  316. var _loading = __webpack_require__(172);
  317. var _loading2 = _interopRequireDefault(_loading);
  318. var _merge = __webpack_require__(164);
  319. var _merge2 = _interopRequireDefault(_merge);
  320. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  321. var LoadingConstructor = _vue2.default.extend(_loading2.default);
  322. var defaults = {
  323. text: null,
  324. fullscreen: true,
  325. body: false,
  326. lock: false,
  327. customClass: ''
  328. };
  329. var fullscreenLoading = void 0;
  330. LoadingConstructor.prototype.originalPosition = '';
  331. LoadingConstructor.prototype.originalOverflow = '';
  332. LoadingConstructor.prototype.close = function () {
  333. var _this = this;
  334. if (this.fullscreen && this.originalOverflow !== 'hidden') {
  335. document.body.style.overflow = this.originalOverflow;
  336. }
  337. if (this.fullscreen || this.body) {
  338. document.body.style.position = this.originalPosition;
  339. } else {
  340. this.target.style.position = this.originalPosition;
  341. }
  342. if (this.fullscreen) {
  343. fullscreenLoading = undefined;
  344. }
  345. this.$on('after-leave', function (_) {
  346. _this.$el && _this.$el.parentNode && _this.$el.parentNode.removeChild(_this.$el);
  347. _this.$destroy();
  348. });
  349. this.visible = false;
  350. };
  351. var addStyle = function addStyle(options, parent, instance) {
  352. var maskStyle = {};
  353. if (options.fullscreen) {
  354. instance.originalPosition = document.body.style.position;
  355. instance.originalOverflow = document.body.style.overflow;
  356. } else if (options.body) {
  357. instance.originalPosition = document.body.style.position;
  358. ['top', 'left'].forEach(function (property) {
  359. var scroll = property === 'top' ? 'scrollTop' : 'scrollLeft';
  360. maskStyle[property] = options.target.getBoundingClientRect()[property] + document.body[scroll] + document.documentElement[scroll] + 'px';
  361. });
  362. ['height', 'width'].forEach(function (property) {
  363. maskStyle[property] = options.target.getBoundingClientRect()[property] + 'px';
  364. });
  365. } else {
  366. instance.originalPosition = parent.style.position;
  367. }
  368. Object.keys(maskStyle).forEach(function (property) {
  369. instance.$el.style[property] = maskStyle[property];
  370. });
  371. };
  372. var Loading = function Loading() {
  373. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  374. if (_vue2.default.prototype.$isServer) return;
  375. options = (0, _merge2.default)({}, defaults, options);
  376. if (typeof options.target === 'string') {
  377. options.target = document.querySelector(options.target);
  378. }
  379. options.target = options.target || document.body;
  380. if (options.target !== document.body) {
  381. options.fullscreen = false;
  382. } else {
  383. options.body = true;
  384. }
  385. if (options.fullscreen && fullscreenLoading) {
  386. return fullscreenLoading;
  387. }
  388. var parent = options.body ? document.body : options.target;
  389. var instance = new LoadingConstructor({
  390. el: document.createElement('div'),
  391. data: options
  392. });
  393. addStyle(options, parent, instance);
  394. if (instance.originalPosition !== 'absolute') {
  395. parent.style.position = 'relative';
  396. }
  397. if (options.fullscreen && options.lock) {
  398. parent.style.overflow = 'hidden';
  399. }
  400. parent.appendChild(instance.$el);
  401. _vue2.default.nextTick(function () {
  402. instance.visible = true;
  403. });
  404. if (options.fullscreen) {
  405. fullscreenLoading = instance;
  406. }
  407. return instance;
  408. };
  409. exports.default = Loading;
  410. /***/ }
  411. /******/ });