0909
This commit is contained in:
@ -5,7 +5,7 @@ VITE_APP_TITLE = 煤科建管平台
|
||||
VITE_APP_ENV = 'development'
|
||||
|
||||
# 开发环境
|
||||
VITE_APP_BASE_API = 'http://192.168.110.180:8899'
|
||||
VITE_APP_BASE_API = 'http://192.168.110.149:8899'
|
||||
# 李陈杰 209
|
||||
# VITE_APP_BASE_API = 'http://192.168.110.209:8899'
|
||||
# 曾涛
|
||||
|
BIN
public/xx.xlsx
Normal file
BIN
public/xx.xlsx
Normal file
Binary file not shown.
@ -61,3 +61,22 @@ export const delSupplierInput = (id: string | number | Array<string | number>) =
|
||||
method: 'delete'
|
||||
});
|
||||
};
|
||||
//导入供商入库
|
||||
export const leadingIn = (formData: FormData, projectId) => {
|
||||
return request({
|
||||
url: '/supplierInput/supplierInput/import?projectId=' + projectId,
|
||||
method: 'post',
|
||||
data: formData,
|
||||
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data'
|
||||
}
|
||||
});
|
||||
};
|
||||
//导入供商出库
|
||||
export const leadingOut = () => {
|
||||
return request({
|
||||
url: '/supplierInput/supplierInput/export',
|
||||
method: 'post'
|
||||
});
|
||||
};
|
||||
|
@ -31,9 +31,14 @@
|
||||
<el-col :span="1.5">
|
||||
<el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['supplierInput:supplierInput:add']">新增</el-button>
|
||||
</el-col>
|
||||
<!-- <el-col :span="1.5">
|
||||
<el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['supplierInput:supplierInput:export']">导出</el-button>
|
||||
</el-col> -->
|
||||
<el-col :span="1.5">
|
||||
<el-button type="warning" plain icon="Upload" @click="handleImport" v-hasPermi="['supplierInput:supplierInput:import']">导入</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['supplierInput:supplierInput:export']"
|
||||
>导出模板</el-button
|
||||
>
|
||||
</el-col>
|
||||
<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
|
||||
</el-row>
|
||||
</template>
|
||||
@ -309,7 +314,14 @@
|
||||
<script setup name="SupplierInput" lang="ts">
|
||||
import { ComponentInternalInstance, getCurrentInstance, onMounted, ref, reactive, toRefs, computed } from 'vue';
|
||||
import { ElFormInstance } from 'element-plus';
|
||||
import { listSupplierInput, getSupplierInput, delSupplierInput, updateSupplierInput } from '@/api/supplierInput/supplierInput/index';
|
||||
import {
|
||||
listSupplierInput,
|
||||
getSupplierInput,
|
||||
delSupplierInput,
|
||||
updateSupplierInput,
|
||||
leadingIn,
|
||||
leadingOut
|
||||
} from '@/api/supplierInput/supplierInput/index';
|
||||
import { SupplierInputVO, SupplierInputQuery, SupplierInputForm, PageData, DialogOption } from '@/api/supplierInput/supplierInput/types';
|
||||
import Pagination from '@/components/Pagination/index.vue';
|
||||
import RightToolbar from '@/components/RightToolbar/index.vue';
|
||||
@ -688,9 +700,77 @@ const handleDelete = async (row?: SupplierInputVO) => {
|
||||
}
|
||||
};
|
||||
|
||||
/** 导出操作 */
|
||||
/** 导出操作(下载静态模板文件) */
|
||||
const handleExport = () => {
|
||||
proxy?.download('supplierInput/supplierInput/export', { ...queryParams.value }, `supplierInput_${new Date().getTime()}.xlsx`);
|
||||
try {
|
||||
// 创建a标签并直接下载public目录下的静态文件
|
||||
const link = document.createElement('a');
|
||||
link.href = '/xx.xlsx'; // 使用public目录下现有的Excel文件作为模板
|
||||
link.download = '供应商导入模板.xlsx';
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
// 清理DOM元素
|
||||
setTimeout(() => {
|
||||
document.body.removeChild(link);
|
||||
}, 100);
|
||||
} catch (error) {
|
||||
proxy?.$modal.msgError('模板下载失败,请重试');
|
||||
}
|
||||
};
|
||||
|
||||
/** 导入操作 */
|
||||
const handleImport = () => {
|
||||
// 创建一个隐藏的input[type=file]元素
|
||||
const input = document.createElement('input');
|
||||
input.type = 'file';
|
||||
input.accept = '.xlsx,.xls'; // 限定只能导入excel文件
|
||||
input.style.display = 'none';
|
||||
|
||||
// 监听文件选择事件
|
||||
input.onchange = async (e: Event) => {
|
||||
const target = e.target as HTMLInputElement;
|
||||
const file = target.files?.[0];
|
||||
|
||||
if (file) {
|
||||
// 检查文件类型是否为Excel
|
||||
const isValidType = file.name.endsWith('.xlsx') || file.name.endsWith('.xls');
|
||||
if (!isValidType) {
|
||||
proxy?.$modal.msgError('请选择Excel文件(.xlsx或.xls)');
|
||||
return;
|
||||
}
|
||||
|
||||
// 创建FormData并添加文件
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
|
||||
try {
|
||||
// 显示加载状态
|
||||
loading.value = true;
|
||||
// 调用导入接口
|
||||
const res = await leadingIn(formData, queryParams.value.projectId);
|
||||
console.log('111111111111', queryParams.value.projectId);
|
||||
|
||||
if (res.code === 200) {
|
||||
proxy?.$modal.msgSuccess('导入成功');
|
||||
// 刷新列表
|
||||
getList();
|
||||
} else {
|
||||
proxy?.$modal.msgError(res.msg || '导入失败');
|
||||
}
|
||||
} catch (error) {
|
||||
proxy?.$modal.msgError('导入失败,请重试');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 清除input元素
|
||||
input.remove();
|
||||
};
|
||||
|
||||
// 触发文件选择对话框
|
||||
document.body.appendChild(input);
|
||||
input.click();
|
||||
};
|
||||
//调用projectId并获取列表
|
||||
onMounted(() => {
|
||||
|
Reference in New Issue
Block a user