From 08a6567e23d5a6b8364cf97558e959ac9320b4fe Mon Sep 17 00:00:00 2001 From: toesbieya <1647775459@qq.com> Date: Wed, 27 May 2020 20:46:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=8A=E4=BC=A0=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E6=94=B9=E5=86=99=20=E4=BF=AE=E5=A4=8Ddialog=E5=85=B3?= =?UTF-8?q?=E9=97=AD=E4=BA=8B=E4=BB=B6=E8=A7=A6=E5=8F=91=E4=B8=A4=E6=AC=A1?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bizComponents/RegionSelector/index.vue | 6 +- vue/src/bizComponents/UploadFile/index.vue | 88 +++++-------------- vue/src/config/request.js | 2 +- vue/src/mixins/bizDocumentDialogMixin.js | 12 +-- vue/src/mixins/dialogMixin.js | 7 ++ vue/src/utils/file.js | 23 +++-- .../inbound/components/EditDialog.vue | 2 +- .../inbound/components/OrderSelector.vue | 7 +- .../purchase/order/components/EditDialog.vue | 4 +- .../order/components/SupplierSelector.vue | 9 +- .../order/components/CustomerSelector.vue | 9 +- .../sell/order/components/EditDialog.vue | 4 +- .../sell/order/components/StockSelector.vue | 7 +- .../sell/outbound/components/EditDialog.vue | 2 +- .../outbound/components/OrderSelector.vue | 7 +- .../outbound/components/StockSelector.vue | 6 +- vue/src/views/stock/current/DetailDialog.vue | 4 +- vue/src/views/system/customer/EditDialog.vue | 6 +- .../department/components/EditDialog.vue | 6 +- vue/src/views/system/resource/EditDialog.vue | 6 +- .../system/role/components/EditDialog.vue | 6 +- vue/src/views/system/supplier/EditDialog.vue | 6 +- .../system/user/components/EditDialog.vue | 10 +-- .../views/userCenter/components/Account.vue | 8 +- .../views/userCenter/components/Avatar.vue | 8 +- 25 files changed, 128 insertions(+), 127 deletions(-) create mode 100644 vue/src/mixins/dialogMixin.js diff --git a/vue/src/bizComponents/RegionSelector/index.vue b/vue/src/bizComponents/RegionSelector/index.vue index bb3983d..998183d 100644 --- a/vue/src/bizComponents/RegionSelector/index.vue +++ b/vue/src/bizComponents/RegionSelector/index.vue @@ -6,7 +6,7 @@ title="选择行政区域" width="30%" top="50px" - @close="$emit('input', false)" + @close="closeDialog" > import {mapState} from 'vuex' + import dialogMixin from "@/mixins/dialogMixin" import {createLimitTree, getNodeId} from "@/utils/tree" export default { name: "RegionSelector", + mixins: [dialogMixin], props: { value: Boolean, limit: Boolean, @@ -53,7 +55,7 @@ let ids = getNodeId(obj.children) ids.unshift(obj.id) this.$emit('select', obj, ids) - this.$emit('input', false) + this.closeDialog() }, init() { this.loading = true diff --git a/vue/src/bizComponents/UploadFile/index.vue b/vue/src/bizComponents/UploadFile/index.vue index 59060c3..0ef9ae0 100644 --- a/vue/src/bizComponents/UploadFile/index.vue +++ b/vue/src/bizComponents/UploadFile/index.vue @@ -44,11 +44,12 @@ * 传入fileList自动拼接七牛云外链前缀 * success、remove事件中的file.url均不带七牛云外链前缀 * */ - import {attachmentPrefix, attachmentUploadUrl} from '@/config' + import axios from 'axios' + import {attachmentPrefix} from '@/config' import {elError} from "@/utils/message" - import {isEmpty, timeFormat} from '@/utils' + import {isEmpty} from '@/utils' import {isImage} from "@/utils/validate" - import {deleteUpload, download, getToken, autoCompleteUrl} from "@/utils/file" + import {deleteUpload, download, upload, autoCompleteUrl} from "@/utils/file" import {numberFormatter} from "@/filter" export default { @@ -117,8 +118,10 @@ //附件移除时,仅当非本次上传时触发remove事件 remove(file) { //区分是否为本次新上传,以及是否上传成功 + //若不是新上传的 if (!file.raw) this.$emit('remove', {...file, url: file.url.replace(attachmentPrefix, '')}) - else if (!file.response.err) deleteUpload(file.raw.key) + //判断是否上传成功(有可能是正在上传) + else if (file.response && !file.response.err) deleteUpload(file.raw.key) this.$refs.upload.handleRemove(file) let index = this.data.findIndex(i => i.url === file.url) @@ -141,8 +144,9 @@ elError(`最多只能上传${this.limit}个文件`) }, - //新附件上传成功,触发success事件 + //新附件上传成功,触发success事件,记录文件key success(res, file) { + file.raw.key = res.key this.data.push(file) this.$emit('success', file, res) }, @@ -165,75 +169,31 @@ elError(`${file.name}的大小超出${numberFormatter(maxSize)}`) return false } - return getToken() + /*return getToken() .then(token => { let now = new Date() file.token = token file.key = timeFormat('yyyy/MM/dd/', now) + now.getTime() + '/' + file.name - }) + })*/ }, - //由element源码修改,https://github.com/ElemeFE/element/blob/dev/packages/upload/src/ajax.js httpRequest(option) { - const xhr = new XMLHttpRequest() - - xhr.upload.onprogress = function progress(e) { - if (e.total > 0) { - e.percent = (Number)((e.loaded / e.total * 100).toFixed(2)) - } - option.onProgress(e) - } - - const formData = new FormData() - - //设置七牛云的要求字段 - formData.append("token", option.file.token) - formData.append("key", option.file.key) - - formData.append(option.filename, option.file, option.file.name) - - xhr.onerror = function error(e) { - option.onError(e) - } - - xhr.onload = function onload() { - if (xhr.status < 200 || xhr.status >= 300) { - return option.onError(getError(attachmentUploadUrl, option, xhr)) - } - - option.onSuccess(getBody(xhr)) - } - - xhr.open('post', attachmentUploadUrl, true) - - xhr.send(formData) - return xhr + const CancelToken = axios.CancelToken + const source = CancelToken.source() + const promise = upload(option.file, option.file.name, { + onUploadProgress(e) { + if (e.total > 0) { + e.percent = (Number)((e.loaded / e.total * 100).toFixed(2)) + } + option.onProgress(e) + }, + cancelToken: source.token + }) + promise.abort = source.cancel + return promise } } } - - function getError(action, option, xhr) { - let msg - if (xhr.response) msg = `${xhr.response.error || xhr.response}` - else if (xhr.responseText) msg = `${xhr.responseText}` - else msg = `fail to post ${action} ${xhr.status}` - const err = new Error(msg) - err.status = xhr.status - err.method = 'post' - err.url = action - return err - } - - function getBody(xhr) { - const text = xhr.responseText || xhr.response - if (!text) return text - try { - return JSON.parse(text) - } - catch (e) { - return text - } - }