Selaa lähdekoodia

增加输入导入组件

yanglzh 2 vuotta sitten
vanhempi
sitoutus
ed019cb5f3

+ 1 - 0
src/api/heatStation/index.ts

@@ -5,6 +5,7 @@ export default {
     getList: (params: object) => get('/region/loop/list', params),
     add: (data: object) => post('/region/loop/add', data),
     export: (params: object) => file('/region/loop/export', params), // 环路列表导出
+    upload: (params: object) => file('/region/loop/import', params), // 环路列表导出
     edit: (data: object) => put('/region/loop/edit', data),
     del: (id: number) => del('/region/loop/del', { id }),
     detail: (id: number) => get('/region/loop/getInfoById', { id }),

+ 56 - 0
src/components/upload/button.vue

@@ -0,0 +1,56 @@
+<template>
+	<el-upload
+		:accept="accept"
+		:limit="1"
+		:headers="headers"
+		:before-upload="beforeAvatarUpload"
+		:action="uploadUrl"
+		:on-success="updateImg"
+	>
+		<el-button>
+			<el-icon> <ele-Upload /> </el-icon>
+			数据导入
+		</el-button>
+	</el-upload>
+</template>
+
+<script lang="ts" setup>
+import { ref } from 'vue';
+import { ElMessage } from 'element-plus';
+import type { UploadProps } from 'element-plus';
+import getOrigin from '/@/utils/origin';
+
+
+const headers = {
+	Authorization: 'Bearer ' + JSON.parse(sessionStorage.token),
+};
+
+const emit = defineEmits(['setImg', 'setImgs']);
+
+const props = defineProps({
+	accept: {
+		type: String,
+		default: '.xls,.xlsx',
+	},
+	url: {
+		type: String,
+		default: '/api/v1/region/loop/import',
+	},
+});
+
+const uploadUrl: string = getOrigin(import.meta.env.VITE_API_URL + props.url);
+
+
+const updateImg = (m1, m2) => {
+	console.log(m1)
+	console.log(m2)
+};
+
+const beforeAvatarUpload: UploadProps['beforeUpload'] = (rawFile) => {
+	if (rawFile.size / 1024 / 1024 > 2) {
+		ElMessage.error('文件不能超过2MB!');
+		return false;
+	}
+	return true;
+};
+</script>

+ 3 - 1
src/views/heating/heatStation/heatStation/index.vue

@@ -32,6 +32,7 @@
 							<el-icon> <ele-Download /> </el-icon>
 							数据导出
 						</el-button>
+						<uploadBtn></uploadBtn>
 						<!-- <el-button size="default" type="danger" class="ml10" @click="onRowDel(null)">
               <el-icon>
                 <ele-Delete />
@@ -89,6 +90,7 @@ import { toRefs, reactive, onMounted, ref, defineComponent } from 'vue';
 import { ElMessageBox, ElMessage, FormInstance } from 'element-plus';
 import EditDic from './component/edit.vue';
 import Detail from './component/detail.vue';
+import uploadBtn from '/@/components/upload/button.vue';
 import api from '/@/api/heatStation';
 import downloadFile from '/@/utils/download';
 
@@ -122,7 +124,7 @@ interface TableDataState {
 
 export default defineComponent({
 	name: 'heatStation',
-	components: { EditDic, Detail },
+	components: { EditDic, Detail, uploadBtn },
 	setup() {
 		const addDicRef = ref();
 		const editDicRef = ref();