Browse Source

导入

master
zhangli 1 year ago
parent
commit
bac0cb193a
  1. 4
      src/components/Form/src/Form.vue
  2. 92
      src/components/ImportForm/src/ImportForm.vue
  3. 27
      src/views/wms/itembasic/ItembasicForm.vue

4
src/components/Form/src/Form.vue

@ -50,7 +50,8 @@ export default defineComponent({
// label
labelWidth: propTypes.oneOfType([String, Number]).def('auto'),
// loading add by
vLoading: propTypes.bool.def(false)
vLoading: propTypes.bool.def(false),
labelPosition: propTypes.string.def('left'),
},
emits: ['register'],
setup(props, { slots, expose, emit }) {
@ -285,6 +286,7 @@ export default defineComponent({
model={props.isCustom ? props.model : formModel}
class={prefixCls}
v-loading={props.vLoading}
label-position={props.labelPosition}
>
{{
//

92
src/components/ImportForm/src/ImportForm.vue

@ -61,8 +61,8 @@
<script lang="ts" setup>
// import * as UserApi from '@/api/system/user'
import { getAccessToken, getTenantId } from '@/utils/auth'
import {ElMessageBox } from 'element-plus'
import download from '@/utils/download'
import { log } from 'console'
defineOptions({ name: 'ImportForm' })
@ -160,35 +160,77 @@ const submitForm = async () => {
/** 文件上传成功 */
const emits = defineEmits(['success'])
const submitFormSuccess = (response: any) => {
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 + ' >'
formLoading.value = true
var byteString = atob(response)
var arrayBuffer = new ArrayBuffer(byteString.length) //
var intArray = new Uint8Array(arrayBuffer) //
for (var i = 0; i < byteString.length; i++) {
intArray[i] = byteString.charCodeAt(i)
}
text += '更新失败数量:' + Object.keys(data[failure]).length + ';'
for (const name in data[failure]) {
text += '< ' + name + ': ' + data[failure][name] + ' >'
const file = new Blob([intArray], { type: '' })
// // headsfilename
// const downloadElement = document.createElement('a')
// //
// const href = window.URL.createObjectURL(blob)
// downloadElement.href = href
// //
// downloadElement.download = '11'
// document.body.appendChild(downloadElement)
// //
// downloadElement.click()
// //
// document.body.removeChild(downloadElement)
// // blob
// window.URL.revokeObjectURL(href)
// console.log(2);
// console.log(response);
// const file = new Blob([response])
// console.log(file);
// console.log(2);
if(response){
if(response.code == 500){
message.error('导入失败')
return;
}else{
message.confirm('文件中有部分数据导入失败,是否下载失败数据?').then(() => {
download.excel(file, 'file_' + new Date().getTime())
})
}
}else{
message.success('导入成功')
}
message.alert(text)
// 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('上传失败,请您重新上传!')
@ -210,6 +252,10 @@ const handleExceed = (): void => {
/** 下载模板操作 */
const importTemplate = () => {
const res = importTemplateData.value.templateUrl
console.log(1);
console.log(res);
console.log(1);
download.excel(res, importTemplateData.value.templateTitle)
}
</script>

27
src/views/wms/itembasic/ItembasicForm.vue

@ -1,8 +1,11 @@
<template>
<Dialog :title="dialogTitle" v-model="dialogVisible">
<div class="p-20px m--10px" style="max-height: 500px;overflow-y: auto;">
<Form ref="formRef" v-loading="formLoading" :rules="ItemBasicRules" :schema="ItemBasic.allSchemas.formSchema" :model="formData"
:is-col="true" />
<Form ref="formRef" v-loading="formLoading" :rules="ItemBasicRules" :schema="ItemBasic.allSchemas.formSchema"
:model="formData" :is-col="true" />
<div class="table">
<Table :columns="columns" />
</div>
</div>
<template #footer>
@ -13,11 +16,9 @@
</Dialog>
</template>
<script setup lang="ts">
import { DICT_TYPE, getStrDictOptions, getIntDictOptions } from '@/utils/dict'
import * as ItembasicApi from '@/api/wms/itembasic'
import { ItemBasic, ItemBasicRules } from '@/utils/disposition/tableColumns.ts'
import * as defaultButtons from '@/utils/disposition/defaultButtons'
import { log } from 'console'
const { t } = useI18n() //
const message = useMessage() //
@ -123,6 +124,20 @@ const buttonBaseClick = (val, item) => {
dialogVisible.value = false
}
}
const columns = ref([{
label: '物品号',
}, {
label: '物品名称',
}, {
label: '单位',
}, {
label: '数量',
}])
</script>
<style scoped></style>
<style scoped>
.table {
border: 1px solid #dedede;
border-radius: 8px;
padding: 10px;
}
</style>

Loading…
Cancel
Save