UNPKG

zcloud-ui

Version:

A Component Library for Vue.js.

847 lines (753 loc) 25.8 kB
module.exports = /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) { /******/ return installedModules[moduleId].exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ i: moduleId, /******/ l: false, /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.l = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // define getter function for harmony exports /******/ __webpack_require__.d = function(exports, name, getter) { /******/ if(!__webpack_require__.o(exports, name)) { /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); /******/ } /******/ }; /******/ /******/ // define __esModule on exports /******/ __webpack_require__.r = function(exports) { /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ /******/ // create a fake namespace object /******/ // mode & 1: value is a module id, require it /******/ // mode & 2: merge all properties of value into the ns /******/ // mode & 4: return value when already ns object /******/ // mode & 8|1: behave like require /******/ __webpack_require__.t = function(value, mode) { /******/ if(mode & 1) value = __webpack_require__(value); /******/ if(mode & 8) return value; /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; /******/ var ns = Object.create(null); /******/ __webpack_require__.r(ns); /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); /******/ return ns; /******/ }; /******/ /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function getDefault() { return module['default']; } : /******/ function getModuleExports() { return module; }; /******/ __webpack_require__.d(getter, 'a', getter); /******/ return getter; /******/ }; /******/ /******/ // Object.prototype.hasOwnProperty.call /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = "/"; /******/ /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(__webpack_require__.s = 85); /******/ }) /************************************************************************/ /******/ ({ /***/ 0: /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return normalizeComponent; }); /* globals __VUE_SSR_CONTEXT__ */ // IMPORTANT: Do NOT use ES2015 features in this file (except for modules). // This module is a runtime utility for cleaner component module output and will // be included in the final webpack user bundle. function normalizeComponent ( scriptExports, render, staticRenderFns, functionalTemplate, injectStyles, scopeId, moduleIdentifier, /* server only */ shadowMode /* vue-cli only */ ) { // Vue.extend constructor export interop var options = typeof scriptExports === 'function' ? scriptExports.options : scriptExports // render functions if (render) { options.render = render options.staticRenderFns = staticRenderFns options._compiled = true } // functional template if (functionalTemplate) { options.functional = true } // scopedId if (scopeId) { options._scopeId = 'data-v-' + scopeId } var hook if (moduleIdentifier) { // server build hook = function (context) { // 2.3 injection context = context || // cached call (this.$vnode && this.$vnode.ssrContext) || // stateful (this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext) // functional // 2.2 with runInNewContext: true if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') { context = __VUE_SSR_CONTEXT__ } // inject component styles if (injectStyles) { injectStyles.call(this, context) } // register component module identifier for async chunk inferrence if (context && context._registeredComponents) { context._registeredComponents.add(moduleIdentifier) } } // used by ssr in case component is cached and beforeCreate // never gets called options._ssrRegister = hook } else if (injectStyles) { hook = shadowMode ? function () { injectStyles.call( this, (options.functional ? this.parent : this).$root.$options.shadowRoot ) } : injectStyles } if (hook) { if (options.functional) { // for template-only hot-reload because in that case the render fn doesn't // go through the normalizer options._injectStyles = hook // register for functional component in vue file var originalRender = options.render options.render = function renderWithStyleInjection (h, context) { hook.call(context) return originalRender(h, context) } } else { // inject component registration as beforeCreate hook var existing = options.beforeCreate options.beforeCreate = existing ? [].concat(existing, hook) : [hook] } } return { exports: scriptExports, options: options } } /***/ }), /***/ 2: /***/ (function(module, exports) { module.exports = require("zcloud-ui/lib/config/index"); /***/ }), /***/ 5: /***/ (function(module, exports) { module.exports = require("zcloud-ui/lib/utils/global"); /***/ }), /***/ 85: /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; // ESM COMPAT FLAG __webpack_require__.r(__webpack_exports__); // CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./packages/excel-upload/src/main.vue?vue&type=template&id=10ac8ca8& var render = function() { var _vm = this var _h = _vm.$createElement var _c = _vm._self._c || _h return _c( "div", { staticClass: "zl-excel-upload" }, [ _c( "el-upload", { ref: "upload", staticClass: "upload-excel", class: _vm.classx, attrs: { action: _vm.action, "http-request": _vm.httpRequire, headers: _vm.headers, data: _vm.parmasData, "file-list": _vm.fileList, "list-type": "text", "on-success": _vm.success, "show-file-list": false, "on-error": _vm.errors, "before-upload": _vm.beforeUpload, limit: 2, multiple: _vm.multiple, drag: _vm.drag, "auto-upload": false, "on-change": _vm.onChange, "on-exceed": _vm.exceed } }, [ _vm._t("imgs"), _c("el-input", { staticClass: "w300 mgr5", attrs: { placeholder: "文件名", size: "small", readonly: true }, model: { value: _vm.fileName, callback: function($$v) { _vm.fileName = $$v }, expression: "fileName" } }), _c( "el-button", { staticClass: "btn-browse mgr5", attrs: { slot: "trigger", type: "primary", size: "small" }, slot: "trigger" }, [_vm._v("浏览...")] ), _vm.showImport ? _c( "el-button", { attrs: { size: "small", type: "primary", disabled: _vm.disBtn, loading: _vm.loading }, on: { click: _vm.submitUpload } }, [_vm._v("导入excel")] ) : _vm._e(), _vm.showDownTemplate ? _c( "el-button", { staticClass: "btn-down mgl5", attrs: { size: "small", icon: "el-icon-download" }, on: { click: function($event) { $event.stopPropagation() return _vm.downFile("template") } } }, [_vm._v("下载模板")] ) : _vm._e(), _vm._t("default") ], 2 ) ], 1 ) } var staticRenderFns = [] render._withStripped = true // CONCATENATED MODULE: ./packages/excel-upload/src/main.vue?vue&type=template&id=10ac8ca8& // EXTERNAL MODULE: external "zcloud-ui/lib/utils/global" var global_ = __webpack_require__(5); // EXTERNAL MODULE: external "zcloud-ui/lib/config/index" var index_ = __webpack_require__(2); // CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/excel-upload/src/main.vue?vue&type=script&lang=js& var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } // // // // // // // // // // // // // // action 配置 /* harmony default export */ var mainvue_type_script_lang_js_ = ({ name: 'ZlExcelUpload', data: function data() { return { ACTIONS: { 0: function _() { return index_["Environment"].UPLOAD_EXCEL + 'import'; }, 1: function _() { return index_["Environment"].FILE_URL + 'upload/addFiles'; } }, PARMASDATA: { 0: { importfile: '', fileName: '', resourceSize: '', fileSuffix: '', paramJson: '', serviceClass: '', method: 'importExcel', token: '' }, 1: _extends({ fileName: '', resourceSize: '', fileSuffix: '', cover: false }, index_["Environment"].FILE_UPLOAD_PARAMS) }, disBtn: true, loading: false, action: '', fileList: [], fileName: '', multiple: false, // 支持多张上传 headers: {}, // 添加请求头{} drag: false, // 是否支持拖拽上传 // eslint-disable-next-line vue/no-reserved-keys _downfile: '', // 下载模板地址 parmasData: { importfile: '', fileName: '', resourceSize: '', fileSuffix: '', paramJson: '', serviceClass: '', method: 'importExcel', token: '' } }; }, props: { // 签名上传需要先请求签名 beforeHttpRequire: { type: Function }, classx: { // 自定义class type: String }, params: { // 添加额外参数 type: Object, default: function _default() { return { importsParams: {}, downParams: '', downParamsErrorTips: '下载模板的Code不能为空' }; } }, fileMaxSize: { // 大小 type: [Number, String], default: '5' }, suffixWhite: { type: [String, Array], default: '' }, fileType: { // 支持的文件类型 type: Array, default: function _default() { return []; } }, token: { type: String, default: '' }, beforeSubmit: { type: Function }, showTips: { // 成功提示 type: Boolean, default: true }, message: { type: String, default: '请上传excel文件' }, mode: { // 上传模式 0为传统,1为附件上传,后端读取地址 type: Number, default: 0 }, showImport: { type: Boolean, default: true }, actionc: { // 用户自定义路径 type: String, default: '' }, showDownTemplate: { type: Boolean, default: false }, passiveLoading: { // 主动设置loading type: Boolean, default: false } }, created: function created() { // 是否用户自定义 if (this.actionc) { this.action = index_["Environment"].UPLOAD_EXCEL_CS + this.actionc; } else { this.action = this.ACTIONS[this.mode](); } this.parmasData = this.PARMASDATA[this.mode]; }, mounted: function mounted() { if (!this.beforeHttpRequire) { this.headers.Authorization = this.token || index_["Environment"].TOKEN; } }, methods: { // 下载模板文件 beforeDownFile: function beforeDownFile(params) { var _this = this; return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() { var api, res; return regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: api = index_["Environment"].EXCEL_DOWN_TEMPL_API; params.api = api; _context.next = 4; return _this.Http(api, { queryBean: params }, { inside: true }); case 4: res = _context.sent; if (res.rows && res.rows.length) { _this._downfile = index_["Environment"].IMAGE_DOWNLOAD + res.rows[0].filePath + ('?token=' + _this.headers.Authorization); } else { _this.$message.warning('模板下载异常'); } case 6: case 'end': return _context.stop(); } } }, _callee, _this); }))(); }, // 下载模板 downFile: function downFile(type) { var _this2 = this; return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() { var paramType, params, _data; return regeneratorRuntime.wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: paramType = _this2.getType(_this2.params.downParams); params = {}; if (!(paramType === 'String')) { _context2.next = 9; break; } params.downTemplCode = _this2.params.downParams; if (params.downTemplCode) { _context2.next = 7; break; } _this2.$message.warning(_this2.params.downParamsErrorTips); return _context2.abrupt('return'); case 7: _context2.next = 11; break; case 9: _this2.$message.warning('模板code必须是个字符串'); return _context2.abrupt('return'); case 11: _data = Object.assign({}, params); _context2.next = 14; return _this2.beforeDownFile(_data); case 14: Object(global_["downloadFileIf"])(_this2._downfile); case 15: case 'end': return _context2.stop(); } } }, _callee2, _this2); }))(); }, // 外部调用 submit: function submit() { this.submitUpload(); }, // 终止loading abortLoading: function abortLoading() { this.loading = false; }, // 开始 startLoading: function startLoading() { this.loading = true; }, submitUpload: function submitUpload() { var _this3 = this; this.loading = true; var files = this.$refs.upload.uploadFiles; if (!files.length) { this.$message.warning('请重新添加文件'); this.loading = false; return; } this.beforeSubmitEvnet(files[0]).then(function (res) { _this3.$refs.upload.submit(); }).catch(function (_) { _this3.loading = false; console.log('文件上传终止'); }); }, beforeSubmitEvnet: function beforeSubmitEvnet(file) { var _this4 = this; return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() { var parmasData; return regeneratorRuntime.wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: if (!_this4.beforeSubmit) { _context3.next = 8; break; } if (!(_this4.getType(_this4.beforeSubmit) === 'Function')) { _context3.next = 6; break; } _context3.next = 4; return _this4.beforeSubmit(); case 4: _context3.next = 8; break; case 6: _this4.loading = false; // eslint-disable-next-line no-new new Error('beforeSubmit 必须是函数'); case 8: parmasData = _this4.parmasData; parmasData.importfile = file.raw; parmasData.fileName = file.name; parmasData.resourceSize = file.size; parmasData.fileSuffix = file.name.split('.').reverse()[0]; if (!_this4.beforeHttpRequire) { parmasData.token = _this4.token || index_["Environment"].TOKEN; } Object.assign(parmasData, _this4.params.importsParams || {}); case 15: case 'end': return _context3.stop(); } } }, _callee3, _this4); }))(); }, getType: function getType(obj) { return Object.prototype.toString.call(obj).slice(8, -1); }, exceed: function exceed(file, fileList) { this.$message.error('超出可上传数量'); }, onChange: function onChange(file, fileList) { file.status === 'ready' && this.$emit('init'); // 初始化数据 if (!this.getFileType(file.name)) { this.$message.error(this.message); this.fileName = ''; return false; } this.$emit('onChange', file); this.$refs.upload.uploadFiles = [file]; this.fileName = file.name; this.disBtn = false; }, // 上传前 beforeUpload: function beforeUpload(file) { var fileSuffix = (file.name.split('.').pop() || '').toLowerCase(); // 文件类型 if (!this.getFileType(file.name)) { // this.$message.error(this.message); this.$message.error('暂不支持上传文件 ' + fileSuffix + ' 格式。'); this.$refs.upload.clearFiles(); this.fileName = ''; this.loading = false; return false; } // 文件大小 var fileMax = Number(this.fileMaxSize) * 1024 * 1024; if (file.size > fileMax) { this.$message.error('\u6587\u4EF6\u5927\u5C0F\u4E0D\u80FD\u8D85\u8FC7 ' + this.fileMaxSize + 'MB\u3002'); this.$refs.upload.clearFiles(); this.fileName = ''; this.loading = false; return false; } }, // 自定义上传文件 httpRequire: function httpRequire(content) { var _this5 = this; return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() { var formData, res, prom; return regeneratorRuntime.wrap(function _callee4$(_context4) { while (1) { switch (_context4.prev = _context4.next) { case 0: formData = new FormData(); content.file && formData.append('file', content.file); if (!_this5.beforeHttpRequire) { _context4.next = 10; break; } // 签名上传 console.log('进入签名上传'); _context4.next = 6; return _this5.beforeHttpRequire(content); case 6: res = _context4.sent; // res 是签名数组排序好的 [{key:'appkey',value:asa}] res.forEach(function (item) { // this.lookStr.push(item.key + '=' + item.value); formData.append(item.key, item.value); }); _context4.next = 11; break; case 10: Object.keys(_this5.parmasData).forEach(function (key) { formData.append(key, _this5.parmasData[key]); }); case 11: prom = new Promise(function (resolve, reject) { // 原生请求。axios试了下不太行 var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function () { if (xhttp.readyState === 4 && xhttp.status === 200) { var data = JSON.parse(xhttp.response); // 处理回调函数 resolve(data); } else if (xhttp.readyState === 4) { reject(); } }; // 同步请求 xhttp.open('POST', content.action, true); console.log('开始上传'); xhttp.send(formData); }); return _context4.abrupt('return', prom); case 13: case 'end': return _context4.stop(); } } }, _callee4, _this5); }))(); }, getFileType: function getFileType(names) { var suffixWhite = this.suffixWhite && typeof this.suffixWhite === 'string' ? this.suffixWhite.split(',') : this.suffixWhite instanceof Array ? this.suffixWhite : []; var name = (names.split('.').reverse()[0] || '').toLowerCase(); var fileType = ['xlsx', 'xls']; fileType = [].concat(fileType, [this.fileType], suffixWhite); return fileType.includes(name); }, // 上传失败错误 errors: function errors() { this.$message.error('文件导入失败'); this.loading = false; }, // 上传成功 success: function success(response, file, fileList) { var _this6 = this; if (response.code !== 0 || !response.success) { this.$message.error(response.msg || '导入失败'); this.fileName = ''; } if (response.code === 0 && response.success && this.showTips) { this.$message.success('导入成功!!'); } if (!this.passiveLoading) { this.loading = false; } this.$emit('upload', response.result, response); // 放到下个队列中去清空 setTimeout(function () { _this6.disBtn = true; _this6.$refs.upload && _this6.$refs.upload.clearFiles(); }, 0); } } }); // CONCATENATED MODULE: ./packages/excel-upload/src/main.vue?vue&type=script&lang=js& /* harmony default export */ var src_mainvue_type_script_lang_js_ = (mainvue_type_script_lang_js_); // EXTERNAL MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js var componentNormalizer = __webpack_require__(0); // CONCATENATED MODULE: ./packages/excel-upload/src/main.vue /* normalize component */ var component = Object(componentNormalizer["a" /* default */])( src_mainvue_type_script_lang_js_, render, staticRenderFns, false, null, null, null ) /* hot reload */ if (false) { var main_api; } component.options.__file = "packages/excel-upload/src/main.vue" /* harmony default export */ var main = (component.exports); // CONCATENATED MODULE: ./packages/excel-upload/index.js /* istanbul ignore next */ main.install = function (Vue) { Vue.component(main.name, main); }; /* harmony default export */ var excel_upload = __webpack_exports__["default"] = (main); /***/ }) /******/ });