xy 2 years ago
parent a801fb04ce
commit 3fbfb4ce34

@ -12,5 +12,6 @@ module.exports = {
* @type {boolean} true | false * @type {boolean} true | false
* @description Whether show the logo in sidebar * @description Whether show the logo in sidebar
*/ */
sidebarLogo: false sidebarLogo: false,
uploadSize: 1024 * 1024 * 20,
} }

@ -2,9 +2,10 @@ import formBuilderMap from "./formBuilderMap";
import { CreateElement, VNode } from "vue"; import { CreateElement, VNode } from "vue";
import moment from "moment"; import moment from "moment";
import { getToken } from "@/utils/auth"; import { getToken } from "@/utils/auth";
import { deepCopy } from "@/utils/index"; import {deepCopy, formatFileSize, formatTime} from "@/utils/index";
import axios from 'axios' import { uploadSize } from "@/settings";
import { flowList } from "@/api/flow" import axios from 'axios';
import { flowList } from "@/api/flow";
/** /**
* @param {String} device 'desktop' or 'mobile' * @param {String} device 'desktop' or 'mobile'
* @param {Object} info field参数 * @param {Object} info field参数
@ -258,18 +259,20 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab
'progress-text': "{percent}%", 'progress-text': "{percent}%",
'more-config': { maxCount: 1, layout: 'horizontal' }, 'more-config': { maxCount: 1, layout: 'horizontal' },
'show-button-text': false, 'show-button-text': false,
'limit-size': 20, 'limit-size': uploadSize / 1024 / 1024, // vxeupload 单位Mb
'limit-count': info.multiple ? 20 : 1, 'limit-count': info.multiple ? 20 : 1,
multiple: !!info.multiple, multiple: !!info.multiple,
readonly: pReadable, readonly: pReadable,
'upload-method': ({ file }) => { 'upload-method': ({ file }) => {
const formData = new FormData() const formData = new FormData()
formData.append('file', file) formData.append('file', file)
window.$_uploading = true
return axios.post(process.env.VUE_APP_UPLOAD_API, formData, { return axios.post(process.env.VUE_APP_UPLOAD_API, formData, {
headers: { headers: {
Authorization: `Bearer ${getToken()}`, Authorization: `Bearer ${getToken()}`,
} }
}).then((response) => { }).then((response) => {
window.$_uploading = false
if (response.status === 200 && !response.data.code) { if (response.status === 200 && !response.data.code) {
if (!(row[info.name] instanceof Array)) { if (!(row[info.name] instanceof Array)) {
row[info.name] = [] row[info.name] = []
@ -282,6 +285,8 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab
} else { } else {
this.$message.error("上传失败") this.$message.error("上传失败")
} }
}).catch(err => {
window.$_uploading = false
}) })
} }
} }
@ -299,17 +304,24 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab
"application/msword,image/jpeg,application/pdf,image/png,application/vnd.ms-powerpoint,text/plain,application/x-zip-compressed,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document", "application/msword,image/jpeg,application/pdf,image/png,application/vnd.ms-powerpoint,text/plain,application/x-zip-compressed,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document",
multiple: !!info.multiple, multiple: !!info.multiple,
limit: info.multiple ? 20 : 1, limit: info.multiple ? 20 : 1,
fileList: this.form[info.name], fileList: this.form[info.name].map(i => {
if (i.hasOwnProperty('original_name')) {
i.name = i.original_name
}
return i
}),
beforeUpload: (file) => { beforeUpload: (file) => {
if (file.size / 1024 / 1024 > 20) { if (file.size > uploadSize) {
this.$message({ this.$message({
type: "warning", type: "warning",
message: "上传图片大小超过20Mb", message: `上传图片大小超过${formatFileSize(uploadSize)}`,
}); });
return false; return false;
} }
window.$_uploading = true
}, },
onSuccess: (response, file, fileList) => { onSuccess: (response, file, fileList) => {
window.$_uploading = false
fileList.forEach((file) => { fileList.forEach((file) => {
if (file.response?.data && !file.response?.code) { if (file.response?.data && !file.response?.code) {
file.response = file.response.data; file.response = file.response.data;
@ -321,6 +333,7 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab
this.form[info.name] = fileList this.form[info.name] = fileList
}, },
onError: (err, file, fileList) => { onError: (err, file, fileList) => {
window.$_uploading = false
this.form[info.name] = fileList this.form[info.name] = fileList
this.$message({ this.$message({
type: "warning", type: "warning",
@ -357,7 +370,7 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab
} }
} }
}, },
file.name file.original_name || file.name
), ),
]), ]),
h("i", { h("i", {
@ -391,7 +404,7 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab
class: "el-upload__tip", class: "el-upload__tip",
slot: "tip", slot: "tip",
}, },
"文件不超过20Mb" `文件不超过${formatFileSize(uploadSize)}`
), ),
] ]
); );
@ -795,10 +808,11 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab
{ {
props: { props: {
value: row[info.name], value: row[info.name],
'name-field': 'original_name',
'progress-text': "{percent}%", 'progress-text': "{percent}%",
'more-config': { maxCount: 1, layout: 'horizontal' }, 'more-config': { maxCount: 1, layout: 'horizontal' },
'show-button-text': false, 'show-button-text': false,
'limit-size': 20, 'limit-size': uploadSize / 1024 / 1024, //vxe upload单位为Mb
'limit-count': info.multiple ? 20 : 1, 'limit-count': info.multiple ? 20 : 1,
readonly: true readonly: true
} }
@ -816,7 +830,12 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab
accept: accept:
"application/msword,image/jpeg,application/pdf,image/png,application/vnd.ms-powerpoint,text/plain,application/x-zip-compressed,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document", "application/msword,image/jpeg,application/pdf,image/png,application/vnd.ms-powerpoint,text/plain,application/x-zip-compressed,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document",
multiple: true, multiple: true,
fileList: (this.form[info.name] instanceof Array) ? this.form[info.name] : [], fileList: (this.form[info.name] instanceof Array) ? this.form[info.name].map(i => {
if (i.hasOwnProperty('original_name')) {
i.name = i.original_name
}
return i
}) : [],
}, },
scopedSlots: { scopedSlots: {
file: (scope) => { file: (scope) => {
@ -1086,17 +1105,29 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab
accept: accept:
"application/msword,image/jpeg,application/pdf,image/png,application/vnd.ms-powerpoint,text/plain,application/x-zip-compressed,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document", "application/msword,image/jpeg,application/pdf,image/png,application/vnd.ms-powerpoint,text/plain,application/x-zip-compressed,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document",
multiple: !!info.multiple, multiple: !!info.multiple,
fileList: row ? row[info.name] : this.form[info.name], fileList: row ? row[info.name].map(i => {
if (i.hasOwnProperty('original_name')) {
i.name = i.original_name
}
return i
}) : this.form[info.name].map(i => {
if (i.hasOwnProperty('original_name')) {
i.name = i.original_name
}
return i
}),
beforeUpload: (file) => { beforeUpload: (file) => {
if (file.size / 1024 / 1024 > 20) { if (file.size > uploadSize) {
this.$message({ this.$message({
type: "warning", type: "warning",
message: "上传图片大小超过20Mb", message: `上传图片大小超过${formatFileSize(uploadSize)}`,
}); });
return false; return false;
} }
window.$_uploading = true
}, },
onSuccess: (response, file, fileList) => { onSuccess: (response, file, fileList) => {
window.$_uploading = false
fileList.forEach((file) => { fileList.forEach((file) => {
if (file.response?.data && !file.response?.code) { if (file.response?.data && !file.response?.code) {
file.response = file.response.data; file.response = file.response.data;
@ -1108,6 +1139,7 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab
row ? row[info.name] = fileList : this.form[info.name] = fileList; row ? row[info.name] = fileList : this.form[info.name] = fileList;
}, },
onError: (err, file, fileList) => { onError: (err, file, fileList) => {
window.$_uploading = false
row ? row[info.name] = fileList : this.form[info.name] = fileList; row ? row[info.name] = fileList : this.form[info.name] = fileList;
this.$message({ this.$message({
type: "warning", type: "warning",
@ -1183,7 +1215,7 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab
class: "el-upload__tip", class: "el-upload__tip",
slot: "tip", slot: "tip",
}, },
"文件不超过20Mb" `文件不超过${formatFileSize(uploadSize)}`
), ),
] ]
) )
@ -1397,7 +1429,7 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab
} }
} }
}, },
file.name file.original_name || file.name
), ),
])) ]))
); );

@ -203,3 +203,16 @@ export function parseMoney(money, precision = 2) {
export function generateRandomString() { export function generateRandomString() {
return Math.random().toString(36).substring(2, 34)+new Date().getTime(); return Math.random().toString(36).substring(2, 34)+new Date().getTime();
} }
export function formatFileSize(size) {
if (size < 1024 * 1024) {
const temp = size / 1024;
return temp.toFixed(2) + "KB";
} else if (size < 1024 * 1024 * 1024) {
const temp = size / (1024 * 1024);
return temp.toFixed(2) + "MB";
} else {
const temp = size / (1024 * 1024 * 1024);
return temp.toFixed(2) + "GB";
}
}

@ -45,8 +45,8 @@
:fullscreen="$store.getters.device === 'mobile'" :fullscreen="$store.getters.device === 'mobile'"
> >
<div style="line-height: 3;color: #333;font-weight: 600;">打卡照片</div> <div style="line-height: 3;color: #333;font-weight: 600;">打卡照片</div>
<van-uploader capture="camera" :max-size="20 * 1024 * 1024" preview-size="140px" :max-count="1" v-model="fileList" @delete="imageId = ''"/> <van-uploader capture="camera" :max-size="uploadSize" preview-size="140px" :max-count="1" v-model="fileList" @delete="imageId = ''"/>
<p>照片大小不能超过20Mb</p> <p>照片大小不能超过{{ formatFileSize(uploadSize) }}</p>
<div style="line-height: 3;color: #333;font-weight: 600;">描述</div> <div style="line-height: 3;color: #333;font-weight: 600;">描述</div>
<el-input v-model="remark" type="textarea" :autosize="{ minRows: 2 }"></el-input> <el-input v-model="remark" type="textarea" :autosize="{ minRows: 2 }"></el-input>
@ -63,19 +63,20 @@
<script> <script>
import { index, save } from '@/api/onDutySchedules' import { index, save } from '@/api/onDutySchedules'
import { sign, preDistance } from '@/api/attendance' import { sign, preDistance } from '@/api/attendance'
import { throttle } from '@/utils' import { throttle, formatFileSize } from '@/utils'
import { getToken } from '@/utils/auth' import { getToken } from '@/utils/auth'
import MonthStatics from './components/MonthStatics' import MonthStatics from './components/MonthStatics'
import axios from "axios"; import axios from "axios";
import * as uni from "@/assets/uni.webview.1.5.6"; import * as uni from "@/assets/uni.webview.1.5.6";
import { PopupManager } from "element-ui/lib/utils/popup"; import { PopupManager } from "element-ui/lib/utils/popup";
import { uploadSize } from "@/settings"
export default { export default {
components: { components: {
MonthStatics MonthStatics
}, },
data() { data() {
return { return {
uploadSize,
isInUni: false, isInUni: false,
// start // start
loading: false, loading: false,
@ -112,6 +113,7 @@ export default {
} }
}, },
methods: { methods: {
formatFileSize,
uploadFile(file) { uploadFile(file) {
const _this = this const _this = this
let data = new FormData() let data = new FormData()
@ -130,6 +132,7 @@ export default {
} }
this.imageId = res.data.data.id this.imageId = res.data.data.id
} }
}).catch(err => {
}) })
}, },
outClockIn: throttle(async function() { outClockIn: throttle(async function() {

@ -230,7 +230,7 @@
<el-table-column <el-table-column
label="操作" label="操作"
header-align="center" header-align="center"
min-width="150" width="150"
fixed="right" fixed="right"
> >
<template #default="{ row }"> <template #default="{ row }">

@ -39,10 +39,11 @@
:before-upload="beforeUpload" :before-upload="beforeUpload"
:on-success="uploadSuccess" :on-success="uploadSuccess"
:on-remove="uploadRemove" :on-remove="uploadRemove"
:on-error="uploadError"
multiple multiple
:file-list="fileList"> :file-list="fileList">
<el-button size="small" type="primary">点击上传</el-button> <el-button size="small" type="primary">点击上传</el-button>
<div slot="tip" class="el-upload__tip">上传文件不超过10Mb</div> <div slot="tip" class="el-upload__tip">上传文件不超过{{ formatFileSize(uploadSize) }}</div>
</el-upload> </el-upload>
</el-form-item> </el-form-item>
<el-form-item label="排序" prop="myindex"> <el-form-item label="排序" prop="myindex">
@ -61,6 +62,8 @@
import { getToken } from '@/utils/auth' import { getToken } from '@/utils/auth'
import { save } from '@/api/document' import { save } from '@/api/document'
import { PopupManager } from "element-ui/lib/utils/popup"; import { PopupManager } from "element-ui/lib/utils/popup";
import { uploadSize } from "@/settings"
import { formatFileSize } from "@/utils"
export default { export default {
props: { props: {
list: { list: {
@ -79,6 +82,7 @@ export default {
}, },
data() { data() {
return { return {
uploadSize,
action: process.env.VUE_APP_UPLOAD_API, action: process.env.VUE_APP_UPLOAD_API,
fileList: [], fileList: [],
@ -108,30 +112,43 @@ export default {
isShow(newVal) { isShow(newVal) {
if(newVal) { if(newVal) {
this.zIndex = PopupManager.nextZIndex() this.zIndex = PopupManager.nextZIndex()
} else {
this.fileList = []
} }
} }
}, },
methods: { methods: {
formatFileSize,
getToken, getToken,
uploadRemove(file, fileList) { uploadRemove(file, fileList) {
this.fileList = fileList this.fileList = fileList
}, },
beforeUpload(file) { beforeUpload(file) {
const isLt10M = file.size / 1024 / 1024 < 10 const isLt = file.size < uploadSize
if (!isLt10M) { if (!isLt) {
this.$message.error('上传文件大小不能超过 10MB!') this.$message.error(`上传文件大小不能超过${formatFileSize(uploadSize)}!`)
} else {
window.$_uploading = true
} }
return isLt10M return isLt
}, },
uploadSuccess(response, file, fileList) { uploadSuccess(response, file, fileList) {
window.$_uploading = false
if (response.code) { if (response.code) {
fileList.splice(fileList.indexOf(file), 1) fileList.splice(fileList.indexOf(file), 1)
this.$message.warning(response.msg) this.$message.warning(response.msg)
} }
this.fileList = fileList this.fileList = fileList
}, },
uploadError() {
window.$_uploading = false
},
submit() { submit() {
if (window.$_uploading) {
this.$message.warning("文件正在上传中")
return
}
this.$refs['elForm'].validate(async valid => { this.$refs['elForm'].validate(async valid => {
if (valid) { if (valid) {
this.loading = true this.loading = true

@ -47,7 +47,7 @@
<vxe-column field="name" title="名称" width="160" align="center" :edit-render="{ name: 'input', attrs: { type: 'text' } }" /> <vxe-column field="name" title="名称" width="160" align="center" :edit-render="{ name: 'input', attrs: { type: 'text' } }" />
<vxe-column field="file.original_name" title="文件" min-width="180" header-align="center" align="left" :edit-render="{}"> <vxe-column field="file.original_name" title="文件" min-width="180" header-align="center" align="left" :edit-render="{}">
<template #edit="{ row }"> <template #edit="{ row }">
<vxe-upload v-model="row.file" progress-text="{percent}%" :more-config="{ maxCount: 1, layout: 'horizontal' }" :limit-size="20" :show-button-text="false" :upload-method="({file}) => uploadMethod(file, row)"></vxe-upload> <vxe-upload v-model="row.file" name-field="original_name" progress-text="{percent}%" :more-config="{ maxCount: 1, layout: 'horizontal' }" :limit-size="uploadSize / 1024 / 1024" :show-button-text="false" :upload-method="({file}) => uploadMethod(file, row)"></vxe-upload>
</template> </template>
</vxe-column> </vxe-column>
<vxe-column field="operate" title="操作" min-width="240"> <vxe-column field="operate" title="操作" min-width="240">
@ -94,12 +94,15 @@ import { menuIndex, index, destroy, save } from '@/api/document'
import { deepCopy } from "@/utils"; import { deepCopy } from "@/utils";
import axios from "axios"; import axios from "axios";
import { getToken } from "@/utils/auth"; import { getToken } from "@/utils/auth";
import { uploadSize } from "@/settings";
import { formatFileSize } from "@/utils"
export default { export default {
components: { components: {
AddDocument AddDocument
}, },
data() { data() {
return { return {
uploadSize,
filterText: '', filterText: '',
isShowAdd: false, isShowAdd: false,
loading: false, loading: false,
@ -145,6 +148,7 @@ export default {
this.getList() this.getList()
}, },
methods: { methods: {
formatFileSize,
preview(row) { preview(row) {
this.$bus.$emit('online-file', row.file?.url) this.$bus.$emit('online-file', row.file?.url)
}, },
@ -162,17 +166,21 @@ export default {
uploadMethod(file, row) { uploadMethod(file, row) {
const formData = new FormData() const formData = new FormData()
formData.append('file', file) formData.append('file', file)
window.$_uploading = true
return axios.post(process.env.VUE_APP_UPLOAD_API, formData, { return axios.post(process.env.VUE_APP_UPLOAD_API, formData, {
headers: { headers: {
Authorization: `Bearer ${getToken()}`, Authorization: `Bearer ${getToken()}`,
} }
}).then((response) => { }).then((response) => {
window.$_uploading = false
if (response.status === 200 && !response.data.code) { if (response.status === 200 && !response.data.code) {
row.file_id = response.data.data.id row.file_id = response.data.data.id
row.file = response.data.data row.file = response.data.data
} else { } else {
this.$message.error("上传失败") this.$message.error("上传失败")
} }
}).catch(err => {
window.$_uploading = false
}) })
}, },
@ -210,6 +218,10 @@ export default {
} }
}, },
async saveRowEvent(row) { async saveRowEvent(row) {
if (window.$_uploading) {
this.$message.warning("文件正在上传中")
return
}
try { try {
const errMap = await this.$refs['table'].validate() const errMap = await this.$refs['table'].validate()
if (errMap) { if (errMap) {

@ -685,6 +685,10 @@ export default {
}, },
async submit(type) { async submit(type) {
if (window.$_uploading) {
this.$message.warning("文件正在上传中")
return
}
let copyForm; let copyForm;
if (this.device === "desktop") { if (this.device === "desktop") {
try { try {

@ -76,6 +76,7 @@
:before-upload="beforeUpload" :before-upload="beforeUpload"
:on-success="uploadSuccess" :on-success="uploadSuccess"
:on-remove="uploadRemove" :on-remove="uploadRemove"
:on-error="uploadError"
multiple multiple
:file-list="fileList" :file-list="fileList"
> >
@ -119,7 +120,9 @@
import { getToken } from "@/utils/auth"; import { getToken } from "@/utils/auth";
import { save } from "@/api/meeting"; import { save } from "@/api/meeting";
import { PopupManager } from "element-ui/lib/utils/popup"; import { PopupManager } from "element-ui/lib/utils/popup";
import { userListNoAuth as index } from '@/api/common' import { userListNoAuth as index } from '@/api/common';
import { uploadSize } from "@/settings";
import { formatFileSize } from "@/utils"
export default { export default {
props: { props: {
type: { type: {
@ -139,6 +142,7 @@ export default {
}, },
data() { data() {
return { return {
uploadSize,
users: [], users: [],
zIndex: PopupManager.nextZIndex(), zIndex: PopupManager.nextZIndex(),
loading: false, loading: false,
@ -187,6 +191,7 @@ export default {
this.getUsers() this.getUsers()
}, },
methods: { methods: {
formatFileSize,
getDetail (data) { getDetail (data) {
for (let key in this.form) { for (let key in this.form) {
this.form[key] = data[key] this.form[key] = data[key]
@ -204,22 +209,32 @@ export default {
this.fileList = fileList this.fileList = fileList
}, },
beforeUpload(file) { beforeUpload(file) {
const isLt10M = file.size / 1024 / 1024 < 10 const isLt = file.size < uploadSize
if (!isLt10M) { if (!isLt) {
this.$message.error('上传文件大小不能超过 10MB!') this.$message.error(`上传文件大小不能超过${formatFileSize(uploadSize)}!`)
} else {
window.$_uploading = true
} }
return isLt10M return isLt
}, },
uploadSuccess(response, file, fileList) { uploadSuccess(response, file, fileList) {
window.$_uploading = false
if (response.code) { if (response.code) {
fileList.splice(fileList.indexOf(file), 1) fileList.splice(fileList.indexOf(file), 1)
this.$message.warning(response.msg) this.$message.warning(response.msg)
} }
this.fileList = fileList this.fileList = fileList
}, },
uploadError() {
window.$_uploading = false
},
getToken, getToken,
submit() { submit() {
if (window.$_uploading) {
this.$message.warning("文件正在上传中")
return
}
this.$refs["elForm"].validate(async (valid) => { this.$refs["elForm"].validate(async (valid) => {
if (valid) { if (valid) {
this.loading = true; this.loading = true;

@ -98,10 +98,10 @@
</vxe-column> </vxe-column>
<vxe-column field="files_details" title="附件" min-width="180" header-align="center" align="left" :edit-render="{}"> <vxe-column field="files_details" title="附件" min-width="180" header-align="center" align="left" :edit-render="{}">
<template #default="{ row }"> <template #default="{ row }">
<vxe-upload v-model="row.files_details" readonly progress-text="{percent}%" :more-config="{ maxCount: 1, layout: 'horizontal' }" :show-button-text="false" /> <vxe-upload v-model="row.files_details" name-field="original_name" readonly progress-text="{percent}%" :more-config="{ maxCount: 1, layout: 'horizontal' }" :show-button-text="false" />
</template> </template>
<template #edit="{ row }"> <template #edit="{ row }">
<vxe-upload v-model="row.files_details" progress-text="{percent}%" :more-config="{ maxCount: 1, layout: 'horizontal' }" :limit-size="20" :show-button-text="false" :upload-method="({file}) => uploadMethod(file, row)" /> <vxe-upload v-model="row.files_details" name-field="original_name" progress-text="{percent}%" :more-config="{ maxCount: 1, layout: 'horizontal' }" :limit-size="uploadSize / 1024 / 1024" :show-button-text="false" :upload-method="({file}) => uploadMethod(file, row)" />
</template> </template>
</vxe-column> </vxe-column>
<vxe-column field="meeting_status" title="审核状态" align="center" :formatter="({ cellValue }) => ['待审核','通过','未通过'][cellValue]" width="100" /> <vxe-column field="meeting_status" title="审核状态" align="center" :formatter="({ cellValue }) => ['待审核','通过','未通过'][cellValue]" width="100" />
@ -176,7 +176,9 @@ import { index as meetingRoomIndex } from "@/api/meetingRoom";
import AddMeeting from "./components/AddMeeting.vue"; import AddMeeting from "./components/AddMeeting.vue";
import UserPicker from "@/components/UserPicker/index.vue"; import UserPicker from "@/components/UserPicker/index.vue";
import axios from "axios"; import axios from "axios";
import {getToken} from "@/utils/auth"; import { getToken } from "@/utils/auth";
import { uploadSize } from '@/settings';
import { formatFileSize } from '@/utils'
export default { export default {
components: { components: {
@ -185,6 +187,7 @@ export default {
}, },
data() { data() {
return { return {
uploadSize,
examineKey: 0, examineKey: 0,
isShowAdd: false, isShowAdd: false,
isShowType: 'add', isShowType: 'add',
@ -232,14 +235,17 @@ export default {
this.bindToolbar() this.bindToolbar()
}, },
methods: { methods: {
formatFileSize,
uploadMethod(file, row) { uploadMethod(file, row) {
const formData = new FormData() const formData = new FormData()
formData.append('file', file) formData.append('file', file)
window.$_uploading = true
return axios.post(process.env.VUE_APP_UPLOAD_API, formData, { return axios.post(process.env.VUE_APP_UPLOAD_API, formData, {
headers: { headers: {
Authorization: `Bearer ${getToken()}`, Authorization: `Bearer ${getToken()}`,
} }
}).then((response) => { }).then((response) => {
window.$_uploading = false
if (response.status === 200 && !response.data.code) { if (response.status === 200 && !response.data.code) {
if (!(this.form['files_details'] instanceof Array)) { if (!(this.form['files_details'] instanceof Array)) {
this.form['files_details'] = [] this.form['files_details'] = []
@ -252,6 +258,8 @@ export default {
} else { } else {
this.$message.error("上传失败") this.$message.error("上传失败")
} }
}).catch(err => {
window.$_uploading = false
}) })
}, },
bindToolbar() { bindToolbar() {
@ -302,6 +310,10 @@ export default {
}, },
async saveRowEvent(row) { async saveRowEvent(row) {
if (window.$_uploading) {
this.$message.warning("文件正在上传中")
return
}
try { try {
const errMap = await this.$refs["table"].validate(); const errMap = await this.$refs["table"].validate();
if (errMap) { if (errMap) {

Loading…
Cancel
Save