xy 1 year ago
parent a801fb04ce
commit 3fbfb4ce34

@ -12,5 +12,6 @@ module.exports = {
* @type {boolean} true | false
* @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 moment from "moment";
import { getToken } from "@/utils/auth";
import { deepCopy } from "@/utils/index";
import axios from 'axios'
import { flowList } from "@/api/flow"
import {deepCopy, formatFileSize, formatTime} from "@/utils/index";
import { uploadSize } from "@/settings";
import axios from 'axios';
import { flowList } from "@/api/flow";
/**
* @param {String} device 'desktop' or 'mobile'
* @param {Object} info field参数
@ -258,18 +259,20 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab
'progress-text': "{percent}%",
'more-config': { maxCount: 1, layout: 'horizontal' },
'show-button-text': false,
'limit-size': 20,
'limit-size': uploadSize / 1024 / 1024, // vxeupload 单位Mb
'limit-count': info.multiple ? 20 : 1,
multiple: !!info.multiple,
readonly: pReadable,
'upload-method': ({ file }) => {
const formData = new FormData()
formData.append('file', file)
window.$_uploading = true
return axios.post(process.env.VUE_APP_UPLOAD_API, formData, {
headers: {
Authorization: `Bearer ${getToken()}`,
}
}).then((response) => {
window.$_uploading = false
if (response.status === 200 && !response.data.code) {
if (!(row[info.name] instanceof Array)) {
row[info.name] = []
@ -282,6 +285,8 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab
} else {
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",
multiple: !!info.multiple,
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) => {
if (file.size / 1024 / 1024 > 20) {
if (file.size > uploadSize) {
this.$message({
type: "warning",
message: "上传图片大小超过20Mb",
message: `上传图片大小超过${formatFileSize(uploadSize)}`,
});
return false;
}
window.$_uploading = true
},
onSuccess: (response, file, fileList) => {
window.$_uploading = false
fileList.forEach((file) => {
if (file.response?.data && !file.response?.code) {
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
},
onError: (err, file, fileList) => {
window.$_uploading = false
this.form[info.name] = fileList
this.$message({
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", {
@ -391,7 +404,7 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab
class: "el-upload__tip",
slot: "tip",
},
"文件不超过20Mb"
`文件不超过${formatFileSize(uploadSize)}`
),
]
);
@ -795,10 +808,11 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab
{
props: {
value: row[info.name],
'name-field': 'original_name',
'progress-text': "{percent}%",
'more-config': { maxCount: 1, layout: 'horizontal' },
'show-button-text': false,
'limit-size': 20,
'limit-size': uploadSize / 1024 / 1024, //vxe upload单位为Mb
'limit-count': info.multiple ? 20 : 1,
readonly: true
}
@ -816,7 +830,12 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab
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",
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: {
file: (scope) => {
@ -1086,17 +1105,29 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab
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",
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) => {
if (file.size / 1024 / 1024 > 20) {
if (file.size > uploadSize) {
this.$message({
type: "warning",
message: "上传图片大小超过20Mb",
message: `上传图片大小超过${formatFileSize(uploadSize)}`,
});
return false;
}
window.$_uploading = true
},
onSuccess: (response, file, fileList) => {
window.$_uploading = false
fileList.forEach((file) => {
if (file.response?.data && !file.response?.code) {
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;
},
onError: (err, file, fileList) => {
window.$_uploading = false
row ? row[info.name] = fileList : this.form[info.name] = fileList;
this.$message({
type: "warning",
@ -1183,7 +1215,7 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab
class: "el-upload__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() {
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'"
>
<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 = ''"/>
<p>照片大小不能超过20Mb</p>
<van-uploader capture="camera" :max-size="uploadSize" preview-size="140px" :max-count="1" v-model="fileList" @delete="imageId = ''"/>
<p>照片大小不能超过{{ formatFileSize(uploadSize) }}</p>
<div style="line-height: 3;color: #333;font-weight: 600;">描述</div>
<el-input v-model="remark" type="textarea" :autosize="{ minRows: 2 }"></el-input>
@ -63,19 +63,20 @@
<script>
import { index, save } from '@/api/onDutySchedules'
import { sign, preDistance } from '@/api/attendance'
import { throttle } from '@/utils'
import { throttle, formatFileSize } from '@/utils'
import { getToken } from '@/utils/auth'
import MonthStatics from './components/MonthStatics'
import axios from "axios";
import * as uni from "@/assets/uni.webview.1.5.6";
import { PopupManager } from "element-ui/lib/utils/popup";
import { uploadSize } from "@/settings"
export default {
components: {
MonthStatics
},
data() {
return {
uploadSize,
isInUni: false,
// start
loading: false,
@ -112,6 +113,7 @@ export default {
}
},
methods: {
formatFileSize,
uploadFile(file) {
const _this = this
let data = new FormData()
@ -130,6 +132,7 @@ export default {
}
this.imageId = res.data.data.id
}
}).catch(err => {
})
},
outClockIn: throttle(async function() {

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

@ -39,10 +39,11 @@
:before-upload="beforeUpload"
:on-success="uploadSuccess"
:on-remove="uploadRemove"
:on-error="uploadError"
multiple
:file-list="fileList">
<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-form-item>
<el-form-item label="排序" prop="myindex">
@ -61,6 +62,8 @@
import { getToken } from '@/utils/auth'
import { save } from '@/api/document'
import { PopupManager } from "element-ui/lib/utils/popup";
import { uploadSize } from "@/settings"
import { formatFileSize } from "@/utils"
export default {
props: {
list: {
@ -79,6 +82,7 @@ export default {
},
data() {
return {
uploadSize,
action: process.env.VUE_APP_UPLOAD_API,
fileList: [],
@ -108,30 +112,43 @@ export default {
isShow(newVal) {
if(newVal) {
this.zIndex = PopupManager.nextZIndex()
} else {
this.fileList = []
}
}
},
methods: {
formatFileSize,
getToken,
uploadRemove(file, fileList) {
this.fileList = fileList
},
beforeUpload(file) {
const isLt10M = file.size / 1024 / 1024 < 10
if (!isLt10M) {
this.$message.error('上传文件大小不能超过 10MB!')
const isLt = file.size < uploadSize
if (!isLt) {
this.$message.error(`上传文件大小不能超过${formatFileSize(uploadSize)}!`)
} else {
window.$_uploading = true
}
return isLt10M
return isLt
},
uploadSuccess(response, file, fileList) {
window.$_uploading = false
if (response.code) {
fileList.splice(fileList.indexOf(file), 1)
this.$message.warning(response.msg)
}
this.fileList = fileList
},
uploadError() {
window.$_uploading = false
},
submit() {
if (window.$_uploading) {
this.$message.warning("文件正在上传中")
return
}
this.$refs['elForm'].validate(async valid => {
if (valid) {
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="file.original_name" title="文件" min-width="180" header-align="center" align="left" :edit-render="{}">
<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>
</vxe-column>
<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 axios from "axios";
import { getToken } from "@/utils/auth";
import { uploadSize } from "@/settings";
import { formatFileSize } from "@/utils"
export default {
components: {
AddDocument
},
data() {
return {
uploadSize,
filterText: '',
isShowAdd: false,
loading: false,
@ -145,6 +148,7 @@ export default {
this.getList()
},
methods: {
formatFileSize,
preview(row) {
this.$bus.$emit('online-file', row.file?.url)
},
@ -162,17 +166,21 @@ export default {
uploadMethod(file, row) {
const formData = new FormData()
formData.append('file', file)
window.$_uploading = true
return axios.post(process.env.VUE_APP_UPLOAD_API, formData, {
headers: {
Authorization: `Bearer ${getToken()}`,
}
}).then((response) => {
window.$_uploading = false
if (response.status === 200 && !response.data.code) {
row.file_id = response.data.data.id
row.file = response.data.data
} else {
this.$message.error("上传失败")
}
}).catch(err => {
window.$_uploading = false
})
},
@ -210,6 +218,10 @@ export default {
}
},
async saveRowEvent(row) {
if (window.$_uploading) {
this.$message.warning("文件正在上传中")
return
}
try {
const errMap = await this.$refs['table'].validate()
if (errMap) {

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

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

@ -98,10 +98,10 @@
</vxe-column>
<vxe-column field="files_details" title="附件" min-width="180" header-align="center" align="left" :edit-render="{}">
<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 #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>
</vxe-column>
<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 UserPicker from "@/components/UserPicker/index.vue";
import axios from "axios";
import {getToken} from "@/utils/auth";
import { getToken } from "@/utils/auth";
import { uploadSize } from '@/settings';
import { formatFileSize } from '@/utils'
export default {
components: {
@ -185,6 +187,7 @@ export default {
},
data() {
return {
uploadSize,
examineKey: 0,
isShowAdd: false,
isShowType: 'add',
@ -232,14 +235,17 @@ export default {
this.bindToolbar()
},
methods: {
formatFileSize,
uploadMethod(file, row) {
const formData = new FormData()
formData.append('file', file)
window.$_uploading = true
return axios.post(process.env.VUE_APP_UPLOAD_API, formData, {
headers: {
Authorization: `Bearer ${getToken()}`,
}
}).then((response) => {
window.$_uploading = false
if (response.status === 200 && !response.data.code) {
if (!(this.form['files_details'] instanceof Array)) {
this.form['files_details'] = []
@ -252,6 +258,8 @@ export default {
} else {
this.$message.error("上传失败")
}
}).catch(err => {
window.$_uploading = false
})
},
bindToolbar() {
@ -302,6 +310,10 @@ export default {
},
async saveRowEvent(row) {
if (window.$_uploading) {
this.$message.warning("文件正在上传中")
return
}
try {
const errMap = await this.$refs["table"].validate();
if (errMap) {

Loading…
Cancel
Save