Browse Source

导入

master
zhangli 1 year ago
parent
commit
bac0cb193a
  1. 4
      src/components/Form/src/Form.vue
  2. 90
      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 // label
labelWidth: propTypes.oneOfType([String, Number]).def('auto'), labelWidth: propTypes.oneOfType([String, Number]).def('auto'),
// loading add by // loading add by
vLoading: propTypes.bool.def(false) vLoading: propTypes.bool.def(false),
labelPosition: propTypes.string.def('left'),
}, },
emits: ['register'], emits: ['register'],
setup(props, { slots, expose, emit }) { setup(props, { slots, expose, emit }) {
@ -285,6 +286,7 @@ export default defineComponent({
model={props.isCustom ? props.model : formModel} model={props.isCustom ? props.model : formModel}
class={prefixCls} class={prefixCls}
v-loading={props.vLoading} v-loading={props.vLoading}
label-position={props.labelPosition}
> >
{{ {{
// //

90
src/components/ImportForm/src/ImportForm.vue

@ -61,8 +61,8 @@
<script lang="ts" setup> <script lang="ts" setup>
// import * as UserApi from '@/api/system/user' // import * as UserApi from '@/api/system/user'
import { getAccessToken, getTenantId } from '@/utils/auth' import { getAccessToken, getTenantId } from '@/utils/auth'
import {ElMessageBox } from 'element-plus'
import download from '@/utils/download' import download from '@/utils/download'
import { log } from 'console'
defineOptions({ name: 'ImportForm' }) defineOptions({ name: 'ImportForm' })
@ -160,35 +160,77 @@ const submitForm = async () => {
/** 文件上传成功 */ /** 文件上传成功 */
const emits = defineEmits(['success']) const emits = defineEmits(['success'])
const submitFormSuccess = (response: any) => { const submitFormSuccess = (response: any) => {
if (response.code !== 0) {
message.error(response.msg) formLoading.value = true
formLoading.value = false var byteString = atob(response)
return var arrayBuffer = new ArrayBuffer(byteString.length) //
} var intArray = new Uint8Array(arrayBuffer) //
// for (var i = 0; i < byteString.length; i++) {
const data = response.data intArray[i] = byteString.charCodeAt(i)
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 + ';' const file = new Blob([intArray], { type: '' })
for (const name of data[update]) { // // headsfilename
text += '< ' + name + ' >' // 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())
})
} }
text += '更新失败数量:' + Object.keys(data[failure]).length + ';' }else{
for (const name in data[failure]) { message.success('导入成功')
text += '< ' + name + ': ' + data[failure][name] + ' >'
} }
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') emits('success')
dialogVisible.value = false dialogVisible.value = false
} }
/** 上传错误提示 */ /** 上传错误提示 */
const submitFormError = (): void => { const submitFormError = (): void => {
message.error('上传失败,请您重新上传!') message.error('上传失败,请您重新上传!')
@ -210,6 +252,10 @@ const handleExceed = (): void => {
/** 下载模板操作 */ /** 下载模板操作 */
const importTemplate = () => { const importTemplate = () => {
const res = importTemplateData.value.templateUrl const res = importTemplateData.value.templateUrl
console.log(1);
console.log(res);
console.log(1);
download.excel(res, importTemplateData.value.templateTitle) download.excel(res, importTemplateData.value.templateTitle)
} }
</script> </script>

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

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

Loading…
Cancel
Save