Browse Source

导入

master
zhangli 1 year ago
parent
commit
d385a5e330
  1. 2
      src/components/Form/src/helper.ts
  2. 27
      src/components/ImportForm/src/ImportForm.vue
  3. 1
      src/types/components.d.ts
  4. 43
      src/utils/disposition/tableColumns.ts
  5. 2
      src/views/system/user/UserImportForm.vue
  6. 16
      src/views/wms/itembasic/ItembasicDetail.vue
  7. 35
      src/views/wms/itembasic/ItembasicForm.vue

2
src/components/Form/src/helper.ts

@ -21,6 +21,8 @@ export const setTextPlaceholder = (schema: FormSchema): PlaceholderModel => {
}
if (selectMap.includes(schema?.component as string)) {
// 一些范围选择器
console.log('type=' +schema?.componentProps?.type);
const twoTextMap = ['datetimerange', 'daterange', 'monthrange', 'datetimerange', 'daterange']
if (
twoTextMap.includes(

27
src/components/ImportForm/src/ImportForm.vue

@ -1,7 +1,7 @@
<!-- 导入组件 -->
<template>
<Dialog v-model="dialogVisible" title="导入" width="600">
<el-upload ref="uploadRef" v-model:file-list="fileList" :action="importUrl + '?updateSupport=' + updateSupport"
<el-upload ref="uploadRef" v-model:file-list="fileList" :action="importUrl + '?mode=' + mode + '&file=' + file + '&updatePart=' + updatePart"
: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">
@ -13,7 +13,7 @@
<div class="label h-32px mr-26px color-#acaeb3 font-size-14px" style="line-height:32px">导入模式</div>
<div class="">
<div class="radio">
<el-radio-group v-model="updateSupport">
<el-radio-group v-model="mode">
<el-radio :label="1" :disabled="updateIsDisable">更新</el-radio>
<el-radio :label="2" :disabled="appendIsDisable">追加</el-radio>
<el-radio :label="3" :disabled="coverIsDisable">覆盖</el-radio>
@ -31,7 +31,7 @@
<div class="label h-32px mr-26px color-#acaeb3 font-size-14px" style="line-height:32px">部分保存</div>
<div class="">
<div class="switch">
<el-switch v-model="isSaveAll" />
<el-switch v-model="updatePart" />
</div>
<div class="tips color-#acaeb3 font-size-14px">
@ -62,6 +62,7 @@
// import * as UserApi from '@/api/system/user'
import { getAccessToken, getTenantId } from '@/utils/auth'
import download from '@/utils/download'
import { log } from 'console'
defineOptions({ name: 'ImportForm' })
@ -74,6 +75,7 @@ const importUrl =
import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_URL + '/system/user/import'
const uploadHeaders = ref() // Header
const fileList = ref([]) //
const file = ref('')
@ -89,7 +91,7 @@ const fileList = ref([]) // 文件列表
default:'.xlsx,.xls'
},
// .1
updateSupport: {
mode: {
type: Number,
required: false,
default: 1
@ -113,18 +115,19 @@ const fileList = ref([]) // 文件列表
default: false
},
// ,
isSaveAll: {
updatePart: {
type: Boolean,
required: false,
default: true
},
})
const { importTemplateData, accept } = toRefs(props)
const updateSupport = ref(props.updateSupport)//.1
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 isSaveAll = ref(props.isSaveAll)//
const updatePart = ref(props.updatePart)//
/** 打开弹窗 */
const open = () => {
@ -135,10 +138,12 @@ 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(),
@ -171,8 +176,10 @@ const submitFormSuccess = (response: any) => {
text += '< ' + username + ': ' + data.failureUsernames[username] + ' >'
}
message.alert(text)
//
emits('success')
dialogVisible.value = false
}
/** 上传错误提示 */
@ -195,8 +202,8 @@ const handleExceed = (): void => {
/** 下载模板操作 */
const importTemplate = () => {
const res = importTemplateData.templateUrl
download.excel(res, importTemplateData.templateTitle)
const res = importTemplateData.value.templateUrl
download.excel(res, importTemplateData.value.templateTitle)
}
</script>

1
src/types/components.d.ts

@ -37,6 +37,7 @@ export type ColProps = {
export type ComponentOptions = {
label?: string
type?: string
value?: FormValueType
disabled?: boolean
key?: string | number

43
src/utils/disposition/tableColumns.ts

@ -42,10 +42,14 @@ export const ItemBasic = useCrudSchemas(reactive<CrudSchema[]>([
sort: 'custom',
dictType: DICT_TYPE.ITEM_STATUS,
dictClass: 'string',
isForm: true,
isSearch: true,
isTable: true,
table: {
width: 100
} ,
form: {
component: 'Select',
}
},
{
@ -82,6 +86,9 @@ export const ItemBasic = useCrudSchemas(reactive<CrudSchema[]>([
isTable: true,
table: {
width: 120
},
form: {
component: 'Switch',
}
},
{
@ -94,6 +101,9 @@ export const ItemBasic = useCrudSchemas(reactive<CrudSchema[]>([
isTable: true,
table: {
width: 100
},
form: {
component: 'Radio',
}
},
{
@ -106,6 +116,9 @@ export const ItemBasic = useCrudSchemas(reactive<CrudSchema[]>([
isTable: true,
table: {
width: 100
} ,
form: {
component: 'Radio',
}
},
{
@ -118,6 +131,9 @@ export const ItemBasic = useCrudSchemas(reactive<CrudSchema[]>([
isTable: true,
table: {
width: 120
} ,
form: {
component: 'Radio',
}
},
{
@ -130,6 +146,9 @@ export const ItemBasic = useCrudSchemas(reactive<CrudSchema[]>([
isTable: true,
table: {
width: 100
},
form: {
component: 'Radio',
}
},
{
@ -142,6 +161,9 @@ export const ItemBasic = useCrudSchemas(reactive<CrudSchema[]>([
isTable: true,
table: {
width: 100
} ,
form: {
component: 'Radio',
}
},
{
@ -242,7 +264,11 @@ export const ItemBasic = useCrudSchemas(reactive<CrudSchema[]>([
sort: 'custom',
table: {
width: 120
} },
},
form: {
component: 'InputNumber',
}
},
{
label: '是否可用',
field: 'available',
@ -253,6 +279,9 @@ export const ItemBasic = useCrudSchemas(reactive<CrudSchema[]>([
isTable: true,
table: {
width: 120
},
form: {
component: 'Radio',
}
},
{
@ -266,6 +295,13 @@ export const ItemBasic = useCrudSchemas(reactive<CrudSchema[]>([
},
table: {
width: 120
} ,
form: {
component: 'TimePicker',
componentProps: {
type: 'datetimerange',
// disabled:true,
}
}
},
{
@ -279,6 +315,11 @@ export const ItemBasic = useCrudSchemas(reactive<CrudSchema[]>([
},
table: {
width: 120
} ,
form: {
component: 'TimePicker',
// valueFormat: 'YYYY-MM-DD HH:mm:ss',
// format: 'YYYY-MM-DD HH:mm:ss',
}
},
{

2
src/views/system/user/UserImportForm.vue

@ -127,6 +127,8 @@ const handleExceed = (): void => {
/** 下载模板操作 */
const importTemplate = async () => {
console.log(await UserApi.importUserTemplate());
const res = await UserApi.importUserTemplate()
download.excel(res, '用户导入模版.xls')
}

16
src/views/wms/itembasic/ItembasicDetail.vue

@ -109,22 +109,26 @@ const changeRecordData = reactive({
}]
})
const detailData = ref("")//
onMounted(async () => {
//
detailData.value = await getItembasic(query.id)
})
//
const importTemplateData = reactive({
templateUrl: UserApi.importUserTemplate(),
templateUrl: '',
templateTitle: '导入模版99.xls'
})
onMounted(async () => {
//
detailData.value = await getItembasic(query.id)
importTemplateData.templateUrl = await UserApi.importUserTemplate()
})
//
const importSuccess = () => {
}
/** 搜索按钮操作 */
const handleQuery = () => {
importFormRef.value.open()
}
/** 重置按钮操作 */
@ -163,9 +167,7 @@ const current = ref(0)
const { tableObject, tableMethods } = useTable({
getListApi: ItembasicApi.getItembasicPage //
})
console.log(tableObject);
const change = (item, index) => {
console.log(item);
current.value = index
}

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

@ -1,17 +1,13 @@
<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" :is-col="true"/>
<Form ref="formRef" v-loading="formLoading" :rules="ItemBasicRules" :schema="ItemBasic.allSchemas.formSchema" :model="formData"
:is-col="true" />
</div>
<template #footer>
<!-- <el-button @click="submitForm" type="primary" :disabled="formLoading"> </el-button>
<el-button @click="dialogVisible = false"> </el-button> -->
<!-- 列表头部 -->
<TableHead
:HeadButttondata="Butttondata"
@buttonBaseClick="buttonBaseClick"
/>
<TableHead :HeadButttondata="Butttondata" @buttonBaseClick="buttonBaseClick" />
</template>
</Dialog>
@ -21,6 +17,7 @@ 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() //
@ -28,6 +25,7 @@ const message = useMessage() // 消息弹窗
const dialogVisible = ref(false) //
const dialogTitle = ref('') //
const formLoading = ref(false) // 12
const formData = ref('')
const formType = ref('') // create - update -
const formRef = ref() // Ref
@ -38,14 +36,16 @@ const open = async (type: string, id?: number) => {
formType.value = type
resetForm()
//
// if (id) {
// formLoading.value = true
// try {
// formData.value = await ItembasicApi.getItembasic(id)
// } finally {
// formLoading.value = false
// }
// }
if (id) {
formLoading.value = true
try {
const data = await ItembasicApi.getItembasic(id)
formRef.value.setValues(data)
} finally {
formLoading.value = false
}
}
}
defineExpose({ open }) // open
@ -126,7 +126,4 @@ const buttonBaseClick = (val, item) => {
}
</script>
<style scoped>
</style>
<style scoped></style>

Loading…
Cancel
Save