✨ init Project
This commit is contained in:
75
src/components/exportExcel/exportExcel.vue
Normal file
75
src/components/exportExcel/exportExcel.vue
Normal file
@@ -0,0 +1,75 @@
|
||||
<template>
|
||||
<el-button type="primary" icon="download" @click="exportExcelFunc"
|
||||
>导出</el-button
|
||||
>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
|
||||
import { exportExcel } from '@/api/exportTemplate'
|
||||
|
||||
const props = defineProps({
|
||||
templateId: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
condition: {
|
||||
type: Object,
|
||||
default: () => ({})
|
||||
},
|
||||
limit: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
offset: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
order: {
|
||||
type: String,
|
||||
default: ''
|
||||
}
|
||||
})
|
||||
|
||||
import { ElMessage } from 'element-plus'
|
||||
|
||||
const exportExcelFunc = async () => {
|
||||
if (props.templateId === '') {
|
||||
ElMessage.error('组件未设置模板ID')
|
||||
return
|
||||
}
|
||||
let baseUrl = import.meta.env.VITE_BASE_API
|
||||
if (baseUrl === "/"){
|
||||
baseUrl = ""
|
||||
}
|
||||
const paramsCopy = JSON.parse(JSON.stringify(props.condition))
|
||||
if (props.limit) {
|
||||
paramsCopy.limit = props.limit
|
||||
}
|
||||
if (props.offset) {
|
||||
paramsCopy.offset = props.offset
|
||||
}
|
||||
if (props.order) {
|
||||
paramsCopy.order = props.order
|
||||
}
|
||||
const params = Object.entries(paramsCopy)
|
||||
.map(
|
||||
([key, value]) =>
|
||||
`${encodeURIComponent(key)}=${encodeURIComponent(value)}`
|
||||
)
|
||||
.join('&')
|
||||
|
||||
const res = await exportExcel({
|
||||
templateID: props.templateId,
|
||||
params
|
||||
})
|
||||
|
||||
if(res.code === 0){
|
||||
ElMessage.success('创建导出任务成功,开始下载')
|
||||
const url = `${baseUrl}${res.data}`
|
||||
window.open(url, '_blank')
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
</script>
|
||||
40
src/components/exportExcel/exportTemplate.vue
Normal file
40
src/components/exportExcel/exportTemplate.vue
Normal file
@@ -0,0 +1,40 @@
|
||||
<template>
|
||||
<el-button type="primary" icon="download" @click="exportTemplateFunc"
|
||||
>下载模板</el-button
|
||||
>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ElMessage } from 'element-plus'
|
||||
import {exportTemplate} from "@/api/exportTemplate";
|
||||
|
||||
const props = defineProps({
|
||||
templateId: {
|
||||
type: String,
|
||||
required: true
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
const exportTemplateFunc = async () => {
|
||||
if (props.templateId === '') {
|
||||
ElMessage.error('组件未设置模板ID')
|
||||
return
|
||||
}
|
||||
let baseUrl = import.meta.env.VITE_BASE_API
|
||||
if (baseUrl === "/"){
|
||||
baseUrl = ""
|
||||
}
|
||||
|
||||
const res = await exportTemplate({
|
||||
templateID: props.templateId
|
||||
})
|
||||
|
||||
if(res.code === 0){
|
||||
ElMessage.success('创建导出任务成功,开始下载')
|
||||
const url = `${baseUrl}${res.data}`
|
||||
window.open(url, '_blank')
|
||||
}
|
||||
|
||||
}
|
||||
</script>
|
||||
45
src/components/exportExcel/importExcel.vue
Normal file
45
src/components/exportExcel/importExcel.vue
Normal file
@@ -0,0 +1,45 @@
|
||||
<template>
|
||||
<el-upload
|
||||
:action="url"
|
||||
:show-file-list="false"
|
||||
:on-success="handleSuccess"
|
||||
:multiple="false"
|
||||
:headers="{'x-token': token}"
|
||||
>
|
||||
<el-button type="primary" icon="upload" class="ml-3"> 导入 </el-button>
|
||||
</el-upload>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { useUserStore } from "@/pinia";
|
||||
|
||||
let baseUrl = import.meta.env.VITE_BASE_API
|
||||
if (baseUrl === "/"){
|
||||
baseUrl = ""
|
||||
}
|
||||
|
||||
const props = defineProps({
|
||||
templateId: {
|
||||
type: String,
|
||||
required: true
|
||||
}
|
||||
})
|
||||
|
||||
const userStore = useUserStore()
|
||||
|
||||
const token = userStore.token
|
||||
|
||||
const emit = defineEmits(['on-success'])
|
||||
|
||||
const url = `${baseUrl}/sysExportTemplate/importExcel?templateID=${props.templateId}`
|
||||
|
||||
const handleSuccess = (res) => {
|
||||
if (res.code === 0) {
|
||||
ElMessage.success('导入成功')
|
||||
emit('on-success')
|
||||
} else {
|
||||
ElMessage.error(res.msg)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user