| src/api/productionManagement/productionProcess.js | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| src/components/Dialog/ImportDialog.vue | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| src/views/productionManagement/productionProcess/index.vue | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/api/productionManagement/productionProcess.js
@@ -48,4 +48,22 @@ url: "/productProcess/list", method: "get", }); } // å¯¼å ¥æ°æ® export function importData(data) { return request({ url: "/productProcess/importData", method: "post", data: data, }); } // ä¸è½½æ¨¡æ¿ export function downloadTemplate() { return request({ url: "/productProcess/downloadTemplate", method: "post", responseType: "blob", }); } src/components/Dialog/ImportDialog.vue
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,172 @@ <template> <el-dialog :title="title" v-model="dialogVisible" :width="width" :append-to-body="appendToBody" @close="handleClose" > <el-upload ref="uploadRef" :limit="limit" :accept="accept" :headers="headers" :action="action" :disabled="disabled" :before-upload="beforeUpload" :on-progress="onProgress" :on-success="onSuccess" :on-error="onError" :on-change="onChange" :auto-upload="autoUpload" drag > <el-icon class="el-icon--upload"><UploadFilled /></el-icon> <div class="el-upload__text">å°æä»¶æå°æ¤å¤ï¼æ<em>ç¹å»ä¸ä¼ </em></div> <template #tip> <div class="el-upload__tip text-center"> <span>{{ tipText }}</span> <el-link v-if="showDownloadTemplate" type="primary" :underline="false" style="font-size: 12px; vertical-align: baseline; margin-left: 5px;" @click="handleDownloadTemplate" >ä¸è½½æ¨¡æ¿</el-link > </div> </template> </el-upload> <template #footer> <div class="dialog-footer"> <el-button type="primary" @click="handleConfirm">ç¡® å®</el-button> <el-button @click="handleCancel">å æ¶</el-button> </div> </template> </el-dialog> </template> <script setup> import { computed, ref } from 'vue' import { UploadFilled } from '@element-plus/icons-vue' const props = defineProps({ modelValue: { type: Boolean, default: false }, title: { type: String, default: 'å¯¼å ¥' }, width: { type: String, default: '400px' }, appendToBody: { type: Boolean, default: true }, limit: { type: Number, default: 1 }, accept: { type: String, default: '.xlsx, .xls' }, headers: { type: Object, default: () => ({}) }, action: { type: String, required: true }, disabled: { type: Boolean, default: false }, autoUpload: { type: Boolean, default: false }, tipText: { type: String, default: 'ä» å è®¸å¯¼å ¥xlsãxlsxæ ¼å¼æä»¶ã' }, showDownloadTemplate: { type: Boolean, default: true }, beforeUpload: { type: Function, default: null }, onProgress: { type: Function, default: null }, onSuccess: { type: Function, default: null }, onError: { type: Function, default: null }, onChange: { type: Function, default: null } }) const emit = defineEmits(['update:modelValue', 'close', 'confirm', 'cancel', 'download-template']) const dialogVisible = computed({ get: () => props.modelValue, set: (val) => emit('update:modelValue', val) }) const uploadRef = ref(null) const handleClose = () => { emit('close') } const handleConfirm = () => { emit('confirm') } const submit = () => { if (uploadRef.value) { uploadRef.value.submit() } } const handleCancel = () => { emit('cancel') dialogVisible.value = false } const handleDownloadTemplate = () => { emit('download-template') } defineExpose({ uploadRef, submit, clearFiles: () => { if (uploadRef.value) { uploadRef.value.clearFiles() } } }) </script> <style scoped> .dialog-footer { text-align: center; } </style> src/views/productionManagement/productionProcess/index.vue
@@ -30,6 +30,7 @@ class="mb10"> <el-button type="primary" @click="showNewModal">æ°å¢å·¥åº</el-button> <el-button type="info" plain @click="handleImport">å¯¼å ¥</el-button> <el-button type="danger" @click="handleDelete" :disabled="selectedRows.length === 0" @@ -52,14 +53,29 @@ v-model:visible="isShowEditModal" :record="record" @completed="getList" /> <ImportDialog ref="importDialogRef" v-model="importDialogVisible" title="å¯¼å ¥å·¥åº" :action="importAction" :headers="importHeaders" :auto-upload="false" :on-success="handleImportSuccess" :on-error="handleImportError" @confirm="handleImportConfirm" @download-template="handleDownloadTemplate" @close="handleImportClose" /> </div> </template> <script setup> import { onMounted, ref } from "vue"; import { onMounted, ref, reactive, toRefs, getCurrentInstance } from "vue"; import NewProcess from "@/views/productionManagement/productionProcess/New.vue"; import EditProcess from "@/views/productionManagement/productionProcess/Edit.vue"; import { listPage, del } from "@/api/productionManagement/productionProcess.js"; import ImportDialog from "@/components/Dialog/ImportDialog.vue"; import { listPage, del, importData, downloadTemplate } from "@/api/productionManagement/productionProcess.js"; import { getToken } from "@/utils/auth"; const data = reactive({ searchForm: { @@ -113,12 +129,18 @@ const isShowNewModal = ref(false); const isShowEditModal = ref(false); const record = ref({}); const importDialogVisible = ref(false); const importDialogRef = ref(null); const page = reactive({ current: 1, size: 100, total: 0, }); const { proxy } = getCurrentInstance(); // å¯¼å ¥ç¸å ³é ç½® const importAction = import.meta.env.VITE_APP_BASE_API + "/productProcess/importData"; const importHeaders = { Authorization: "Bearer " + getToken() }; // æ¥è¯¢å表 /** æç´¢æé®æä½ */ @@ -200,6 +222,63 @@ } } // å¯¼å ¥ const handleImport = () => { importDialogVisible.value = true; }; // ç¡®è®¤å¯¼å ¥ const handleImportConfirm = () => { if (importDialogRef.value) { importDialogRef.value.submit(); } }; // å¯¼å ¥æå const handleImportSuccess = (response) => { if (response.code === 200) { proxy.$modal.msgSuccess("å¯¼å ¥æå"); importDialogVisible.value = false; if (importDialogRef.value) { importDialogRef.value.clearFiles(); } getList(); } else { proxy.$modal.msgError(response.msg || "å¯¼å ¥å¤±è´¥"); } }; // å¯¼å ¥å¤±è´¥ const handleImportError = (error) => { proxy.$modal.msgError("å¯¼å ¥å¤±è´¥ï¼" + (error.message || "æªç¥é误")); }; // å ³éå¯¼å ¥å¼¹çª const handleImportClose = () => { if (importDialogRef.value) { importDialogRef.value.clearFiles(); } }; // ä¸è½½æ¨¡æ¿ const handleDownloadTemplate = async () => { try { const res = await downloadTemplate(); const blob = new Blob([res], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", }); const url = window.URL.createObjectURL(blob); const link = document.createElement("a"); link.href = url; link.download = "å·¥åºå¯¼å ¥æ¨¡æ¿.xlsx"; link.click(); window.URL.revokeObjectURL(url); proxy.$modal.msgSuccess("模æ¿ä¸è½½æå"); } catch (error) { proxy.$modal.msgError("模æ¿ä¸è½½å¤±è´¥"); } }; // å¯¼åº // const handleOut = () => { // ElMessageBox.confirm("éä¸çå 容å°è¢«å¯¼åºï¼æ¯å¦ç¡®è®¤å¯¼åºï¼", "导åº", {