Browse Source

导入并执行任务

master_hella_20240701
zhaoxuebing 6 months ago
parent
commit
f31263e92f
  1. 339
      src/components/ImportForm/src/ImportDetailForm.vue
  2. 34
      src/views/wms/countManage/count/countJobMain/index.vue

339
src/components/ImportForm/src/ImportDetailForm.vue

@ -0,0 +1,339 @@
<!-- 导入组件 -->
<template>
<Dialog v-model="dialogVisible" :title="t('ts.导入')" width="600" :close-on-click-modal="false">
<el-upload
ref="uploadRef"
v-model:file-list="fileList"
:action="
importUrl +
'?mode=' +
mode +
'&file=' +
file +
'&updatePart=' +
updatePart +
'&outFile=' +
outFile +
'&extend=' + extend +
'&fromInventoryStatus=' + fromInventoryStatus +
'&toInventoryStatus=' + toInventoryStatus
"
:auto-upload="false"
:disabled="formLoading"
:headers="uploadHeaders"
:limit="1"
:on-error="submitFormError"
:on-exceed="handleExceed"
:on-success="submitFormSuccess"
:accept="accept"
drag
style="width: 300px; margin: 0 auto"
v-loading="formLoading"
>
<Icon icon="ep:upload-filled" color="#c0c4cc" :size="60" />
<div class="el-upload__text">{{t('ts.将文件拖到此处,或')}}<em>{{t('ts.点击上传')}}</em></div>
<template #tip>
<div class="el-upload__tip ml--126px mr--80px">
<div class="flex">
<div
class="label h-32px mr-26px color-#acaeb3 font-size-14px w-100px text-right"
style="line-height: 32px"
>{{t('ts.导入模式')}}</div
>
<div class="">
<div class="radio">
<el-radio-group v-model="mode">
<el-radio :label="1" :disabled="updateIsDisable">{{ t('ts.更新')}}</el-radio>
<!-- <el-radio :label="2" :disabled="appendIsDisable">{{ t('ts.追加') }}</el-radio>
<el-radio :label="3" :disabled="coverIsDisable">{{ t('ts.覆盖') }}</el-radio> -->
</el-radio-group>
</div>
<div class="tips color-#acaeb3 font-size-14px">
<div class="mt-2">{{t('ts.更新:新增并修改')}}</div>
<!-- <div class="mt-2">{{ t('ts.追加:只新增,不修改') }}</div>
<div class="mt-2">{{ t('ts.覆盖:只修改不新增') }}</div> -->
</div>
</div>
</div>
<div class="flex mt-16px">
<!-- <div
class="label h-32px mr-26px color-#acaeb3 font-size-14px w-100px text-right"
style="line-height: 32px"
>{{ t('ts.部分保存') }}</div
>
<div class="">
<div class="switch">
<el-switch v-model="updatePart" />
</div>
<div class="tips color-#acaeb3 font-size-14px">
<div class="mt-2">{{ t('ts.部分保存:如存在错误数据,正确数据正常导入') }}</div>
<div class="mt-2">{{ t('ts.全部保存:全部数据正确,才能导入') }}</div>
</div>
</div> -->
</div>
<div class="flex mt-16px" v-if="isShowOut">
<div
class="label h-32px mr-26px color-#acaeb3 font-size-14px w-100px text-right"
style="line-height: 32px"
>是否外部资源</div
>
<div class="">
<div class="switch">
<el-switch v-model="outFile" />
</div>
</div>
</div>
</div>
</template>
</el-upload>
<template #footer>
<div class="flex items-center">
<div class="flex-1 text-left">
<!-- <el-button type="primary" plain @click="importTemplate">
<Icon icon="ep:download" />
{{ t('ts.下载模板') }}
</el-button> -->
</div>
<el-button :disabled="formLoading" type="primary" @click="submitForm">{{ t('ts.确 ') }}</el-button>
<el-button @click="dialogVisible = false">{{ t('ts.取 消') }}</el-button>
</div>
</template>
</Dialog>
</template>
<script lang="ts" setup>
import { getAccessToken, getTenantId } from '@/utils/auth'
import download from '@/utils/download'
defineOptions({ name: 'ImportDetailForm' })
const { t } = useI18n()
const message = useMessage() //
const dialogVisible = ref(false) //
const formLoading = ref(false) //
const uploadRef = ref()
const uploadHeaders = ref() // Header
const fileList = ref([]) //
const file = ref('')
const props = defineProps({
importTemplateData: {
type: Object,
required: true
},
//
accept: {
type: String,
required: false,
default: '.xlsx,.xls'
},
// .1
mode: {
type: Number,
required: false,
default: 1
},
// ,
updateIsDisable: {
type: Boolean,
required: false,
default: false
},
// ,
appendIsDisable: {
type: Boolean,
required: false,
default: false
},
// ,
coverIsDisable: {
type: Boolean,
required: false,
default: false
},
// ,
updatePart: {
type: Boolean,
required: false,
default: false
},
url: {
type: String,
required: false
},
//
isShowOut: {
type: Boolean,
required: false,
default: false
},
outFile: {
type: Boolean,
required: false,
default: false
},
//
extend: {
type: String,
required: false,
default: ''
},
// TODO: cxm
fromInventoryStatus: {
type: String,
required: false,
default: ''
},
// TODO: cxm
toInventoryStatus: {
type: String,
required: false,
default: ''
}
})
const importTemplateData = ref(props.importTemplateData)
const accept = ref(props.accept)
const mode = ref(props.mode) //.1
const updateIsDisable = ref(props.updateIsDisable) //,
const appendIsDisable = ref(props.appendIsDisable) //,
const coverIsDisable = ref(props.coverIsDisable) //,
const updatePart = ref(props.updatePart) //
const outFile = ref(props.outFile) //
const importUrl = import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_URL + props.url
/** 打开弹窗 */
const open = () => {
dialogVisible.value = true
resetForm()
}
defineExpose({ open }) // open
/** 提交表单 */
const submitForm = async () => {
if (fileList.value.length == 0) {
message.error('请上传文件')
return
}
file.value = fileList.value[0].name
//
uploadHeaders.value = {
Authorization: 'Bearer ' + getAccessToken(),
'tenant-id': getTenantId()
}
formLoading.value = true
uploadRef.value!.submit()
}
/** 文件上传成功 */
const emits = defineEmits(['success'])
const submitFormSuccess = (response: any) => {
formLoading.value = true
console.log(response)
if (response) {
if (response.code == 500) {
uploadRef.value!.clearFiles()
message.error('导入失败')
formLoading.value = false
return
} else if (response.code == 0) {
if (response.data.errorCount > 0) {
message.confirm('文件中有部分数据导入失败,是否下载失败数据?').then(() => {
// download.excel(file, 'file_' + new Date().getTime())
// url
// const downloadElement = document.createElement('a')
// console.log(172, import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_URL + '/' + response.data.errorFile)
// console.log(172, import.meta.env.VITE_BASE_URL + '/admin-api/opt/profile/' + response.data.errorFile)
window.open(
import.meta.env.VITE_BASE_URL + '/admin-api' + response.data.errorFile,
'222'
)
// downloadElement.setAttribute('href', import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_URL + response.data.errorFile )
//
// downloadElement.click()
})
} else {
message.success('导入成功')
}
}else if(response.data == null){
message.error(response.msg)
}
}
// if (response.code !== 0) {
// message.error(response.msg)
// formLoading.value = false
// return
// }
// //
// const data = response.data
// const create = response.data.importResult[0]
// const update = response.data.importResult[1]
// const failure = response.data.importResult[2]
// let text = '' + data[create].length + ';'
// for (let name of data[create]) {
// text += '< ' + name + ' >'
// }
// text += '' + data[update].length + ';'
// for (const name of data[update]) {
// text += '< ' + name + ' >'
// }
// text += '' + Object.keys(data[failure]).length + ';'
// for (const name in data[failure]) {
// text += '< ' + name + ': ' + data[failure][name] + ' >'
// }
// message.alert(text)
//
formLoading.value = false
emits('success')
dialogVisible.value = false
}
/** 上传错误提示 */
const submitFormError = (): void => {
message.error('上传失败,请您重新上传!')
formLoading.value = false
}
/** 重置表单 */
const resetForm = () => {
//
formLoading.value = false
uploadRef.value?.clearFiles()
fileList.value = []
}
/** 文件数超出提示 */
const handleExceed = (): void => {
message.error('最多只能上传一个文件!')
}
/** 下载模板操作 */
const importTemplate = () => {
const res = importTemplateData.value.templateUrl
download.excel(res, importTemplateData.value.templateTitle)
}
</script>
<style scoped lang="scss">
.tips {
div {
position: relative;
padding-left: 22px;
&::before {
width: 4px;
height: 4px;
border-radius: 50%;
content: '';
background: #c2c2c2;
position: absolute;
top: 50%;
margin-top: -2px;
left: 4px;
}
}
}
</style>

34
src/views/wms/countManage/count/countJobMain/index.vue

@ -64,6 +64,19 @@
:searchTableParams="searchTableParams"
:apiPage="CountJobDetailApi.getCountJobDetailPage"
/>
<!-- 导入 -->
<ImportDetailForm
ref="importFormRef"
url="/wms/count-job-main/import"
:importTemplateData="importTemplateData"
@success="importSuccess"
:updateIsDisable="true"
:coverIsDisable="true"
:mode="1"
:extend="rowMasterIdRef"
/>
</template>
<script setup lang="ts">
@ -222,6 +235,8 @@ const buttonTableClick = async (val, row) => {
console.log('列表-操作按钮事件-承接')
} else if (val == 'exportCountJob'){//
handleExportCountJob(row.masterId,row.number)
} else if( val == 'importCountJob'){ //
handleImport(row.masterId)
}
}
@ -273,6 +288,25 @@ const handleExportCountJob = async (id: number,number: string) => {
}
}
/** 导入 */
const importFormRef = ref()
const rowMasterIdRef = ref('')
const handleImport = (id: string) => {
rowMasterIdRef.value = id;
importFormRef.value.open()
}
//
const importTemplateData = reactive({
templateUrl: '',
templateTitle: '盘点任务导入模版.xlsx'
})
//
const importSuccess = () => {
getList()
}
//
const searchFormClick = (searchData) => {
tableObject.params = {

Loading…
Cancel
Save