Browse Source

工位导入demo代码

master
chenfang 1 year ago
parent
commit
2c92d3e9bc
  1. 134
      src/views/wms/workstation/WorkstationImportForm.vue
  2. 1
      src/views/wms/workstation/index.vue

134
src/views/wms/workstation/WorkstationImportForm.vue

@ -0,0 +1,134 @@
<template>
<Dialog v-model="dialogVisible" title="工位信息导入" width="400">
<el-upload
ref="uploadRef"
v-model:file-list="fileList"
:action="importUrl + '?updateSupport=' + updateSupport"
:auto-upload="false"
:disabled="formLoading"
:headers="uploadHeaders"
:limit="1"
:on-error="submitFormError"
:on-exceed="handleExceed"
:on-success="submitFormSuccess"
accept=".xlsx, .xls"
drag
>
<Icon icon="ep:upload" />
<div class="el-upload__text">将文件拖到此处<em>点击上传</em></div>
<template #tip>
<div class="el-upload__tip text-center">
<div class="el-upload__tip">
<el-checkbox v-model="updateSupport" />
是否更新已经存在的工位信息数据
</div>
<span>仅允许导入 xlsxlsx 格式文件</span>
<el-link
:underline="false"
style="font-size: 12px; vertical-align: baseline"
type="primary"
@click="importTemplate"
>
下载模板
</el-link>
</div>
</template>
</el-upload>
<template #footer>
<el-button :disabled="formLoading" type="primary" @click="submitForm"> </el-button>
<el-button @click="dialogVisible = false"> </el-button>
</template>
</Dialog>
</template>
<script lang="ts" setup>
import * as WorkstationApi from '@/api/wms/workstation'
import { getAccessToken, getTenantId } from '@/utils/auth'
import download from '@/utils/download'
defineOptions({ name: 'WmsItembasicImportForm' })
const message = useMessage() //
const dialogVisible = ref(false) //
const formLoading = ref(false) //
const uploadRef = ref()
const importUrl =
import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_URL + '/wms/workstation/import'
const uploadHeaders = ref() // Header
const fileList = ref([]) //
const updateSupport = ref(0) //
/** 打开弹窗 */
const open = () => {
dialogVisible.value = true
resetForm()
}
defineExpose({ open }) // open
/** 提交表单 */
const submitForm = async () => {
if (fileList.value.length == 0) {
message.error('请上传文件')
return
}
//
uploadHeaders.value = {
Authorization: 'Bearer ' + getAccessToken(),
'tenant-id': getTenantId()
}
formLoading.value = true
uploadRef.value!.submit()
}
/** 文件上传成功 */
const emits = defineEmits(['success'])
const submitFormSuccess = (response: any) => {
if (response.code !== 0) {
message.error(response.msg)
formLoading.value = false
return
}
//
// const data = response.data
// console.log(data)
// let text = '' + data.createUsernames.length + ';'
// for (let username of data.createUsernames) {
// text += '< ' + username + ' >'
// }
// text += '' + data.updateUsernames.length + ';'
// for (const username of data.updateUsernames) {
// text += '< ' + username + ' >'
// }
// text += '' + Object.keys(data.failureUsernames).length + ';'
// for (const username in data.failureUsernames) {
// text += '< ' + username + ': ' + data.failureUsernames[username] + ' >'
// }
// message.alert(text)
//
emits('success')
}
/** 上传错误提示 */
const submitFormError = (): void => {
message.error('上传失败,请您重新上传!')
formLoading.value = false
}
/** 重置表单 */
const resetForm = () => {
//
formLoading.value = false
uploadRef.value?.clearFiles()
}
/** 文件数超出提示 */
const handleExceed = (): void => {
message.error('最多只能上传一个文件!')
}
/** 下载模板操作 */
const importTemplate = async () => {
const res = await WorkstationApi.importWorkstationTemplate()
download.excel(res, '工位信息导入模版.xls')
}
</script>

1
src/views/wms/workstation/index.vue

@ -316,6 +316,7 @@ const handleImport = () => {
/** 添加/修改操作 */
const formRef = ref()
const openForm = (type: string, id?: number) => {
console.log(id)
formRef.value.open(type, id)
}

Loading…
Cancel
Save