|
@@ -1,7 +1,6 @@
|
|
|
<template>
|
|
|
- <el-upload ref="uploadRef" class="hc-upload-border approach" drag :action="action" :headers="getTokenHeader()" :data="uploadData" :accept="accept" :disabled="uploadDisabled" :limit="1" :show-file-list="false"
|
|
|
- :before-upload="beforeUpload" :on-exceed="uploadExceed" :on-progress="uploadprogress" :on-success="uploadSuccess" :on-error="uploadError" :on-change="uploadChange" :auto-upload="false">
|
|
|
-
|
|
|
+ <el-upload ref="uploadRef" class="hc-upload-border approach" drag :action="api + action" :headers="getTokenHeader()" :data="uploadData" :accept="accept" :disabled="uploadDisabled" :limit="1" :show-file-list="false"
|
|
|
+ :before-upload="beforeUpload" :on-exceed="uploadExceed" :on-progress="uploadprogress" :on-success="uploadSuccess" :on-error="uploadError" :on-change="uploadChange" :auto-upload="autoUpload">
|
|
|
<div class="hc-upload-loading upload-file-info" v-loading="uploadDisabled" element-loading-text="上传中...">
|
|
|
<template v-if="uploadFileInfo?.name">
|
|
|
<HcIcon name="file-text" class="upload-file-icon"/>
|
|
@@ -14,21 +13,41 @@
|
|
|
</div>
|
|
|
|
|
|
<template #tip>
|
|
|
- <div class="el-upload__tip">允许格式:excel, 文件大小 小于 60MB</div>
|
|
|
+ <div class="el-upload__tip">允许格式:{{formatTip}}, 文件大小 小于 {{size}}MB</div>
|
|
|
</template>
|
|
|
</el-upload>
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
-import {ref,watch,onMounted} from "vue";
|
|
|
+import {ref,watch} from "vue";
|
|
|
import {getTokenHeader} from '~src/api/request/header';
|
|
|
-import {getObjValue, isSize} from "vue-utils-plus"
|
|
|
+import {isSize} from "vue-utils-plus"
|
|
|
import {genFileId} from "element-plus";
|
|
|
const props = defineProps({
|
|
|
datas: {
|
|
|
type: Object,
|
|
|
default: () => ({})
|
|
|
},
|
|
|
+ action: {
|
|
|
+ type: String,
|
|
|
+ default: "mobilization/read-excel"
|
|
|
+ },
|
|
|
+ accept: {
|
|
|
+ type: String,
|
|
|
+ default: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
|
+ },
|
|
|
+ size: {
|
|
|
+ type: Number,
|
|
|
+ default: 20
|
|
|
+ },
|
|
|
+ formatTip: {
|
|
|
+ type: String,
|
|
|
+ default: "excel"
|
|
|
+ },
|
|
|
+ autoUpload: {
|
|
|
+ type: Boolean,
|
|
|
+ default: true
|
|
|
+ },
|
|
|
})
|
|
|
|
|
|
//变量
|
|
@@ -37,8 +56,7 @@ const uploadData = ref(props.datas)
|
|
|
const uploadFileInfo = ref({})
|
|
|
const uploadDisabled = ref(false)
|
|
|
|
|
|
-const action = '/api/blade-manager/exceltab/add-buss-file';
|
|
|
-const accept = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel';
|
|
|
+const api = '/api/blade-business/device/';
|
|
|
|
|
|
//监听
|
|
|
watch(() => [
|
|
@@ -47,16 +65,15 @@ watch(() => [
|
|
|
uploadData.value = datas
|
|
|
})
|
|
|
|
|
|
-
|
|
|
//事件
|
|
|
const emit = defineEmits(['progress', 'finished', 'change'])
|
|
|
|
|
|
//上传前
|
|
|
const beforeUpload = async (file) => {
|
|
|
- if (isSize(file?.size,60)) {
|
|
|
+ if (isSize(file?.size, props.size)) {
|
|
|
return true;
|
|
|
} else {
|
|
|
- window?.$message?.warning('文件大小, 不能过60M!');
|
|
|
+ window?.$message?.warning('文件大小, 不能过' + props.size + 'M!');
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
@@ -76,29 +93,26 @@ const uploadprogress = () => {
|
|
|
}
|
|
|
|
|
|
//上传完成
|
|
|
-const uploadSuccess = (res) => {
|
|
|
+const uploadSuccess = ({code, data}) => {
|
|
|
uploadDisabled.value = false
|
|
|
emit('progress', false)
|
|
|
- emit('finished', {
|
|
|
- type: 'success',
|
|
|
- data: getObjValue(res?.data)
|
|
|
- })
|
|
|
+ if (code === 200) {
|
|
|
+ window?.$message?.success('上传成功');
|
|
|
+ emit('finished', data)
|
|
|
+ } else {
|
|
|
+ window?.$message?.error('上传失败');
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//上传失败
|
|
|
-const uploadError = (res) => {
|
|
|
+const uploadError = () => {
|
|
|
uploadDisabled.value = false
|
|
|
emit('progress', false)
|
|
|
- emit('finished', {
|
|
|
- type: 'error',
|
|
|
- data: getObjValue(res?.data)
|
|
|
- })
|
|
|
- window?.$message?.error('导入失败');
|
|
|
+ window?.$message?.error('上传失败');
|
|
|
}
|
|
|
|
|
|
//文件改变时
|
|
|
const uploadChange = (file) => {
|
|
|
- console.log(file)
|
|
|
uploadFileInfo.value = file
|
|
|
emit('change', file)
|
|
|
}
|