Ver Fonte

温湿度导入功能

luoaoxuan há 1 ano atrás
pai
commit
30170d8cd3

+ 18 - 0
src/api/upload/zip.js

@@ -0,0 +1,18 @@
+import request from '@/utils/request'
+import { BUSINESS_BASE_URL } from '@/api/baseUrl'
+
+/**
+ * 导入文件
+ * @param {*} file
+ */
+export function importZip (file) {
+    const data = new FormData() // 创建form对象
+    data.append('file', file)
+    return request({
+        url: BUSINESS_BASE_URL() + '/thirtyparty/humiture/importHumiture',
+        method: 'post',
+        data: data,
+        isLoading: true,
+        gateway: true
+    })
+}

+ 30 - 6
src/business/platform/data/templaterender/templates/list.vue

@@ -268,6 +268,12 @@
             @close="(visible) => (importTableDialogVisible = visible)"
             @action-event="handleImportTableActionEvent"
         />
+        <import-zip
+            :visible="importZipDialogVisible"
+            title="导入"
+            @close="(visible) => (importZipDialogVisible = visible)"
+            @action-event="handleImportZipActionEvent"
+        />
 
         <xlsxFile
             v-if="xlsxFileVisible"
@@ -322,7 +328,7 @@ import IbpsImportColumnsDialog from '../components/import-columns-dialog'
 import CustomDataDisplayMixin from '@/business/platform/system/mixins/customDataDisplay'
 import FormPrintTemplate from '@/business/platform/form/form-print/template'
 import importTable from '@/business/platform/form/formrender/dynamic-form/components/import-table'
-
+import importZip from '@/business/platform/form/formrender/dynamic-form/components/import-zip.vue'
 import JTemplate from '../utils/JTemplate' // 自定义脚本
 import JDialogTemplate from '../utils/JDialogTemplate' // 对话框自定义脚本
 
@@ -335,7 +341,7 @@ import Vue from 'vue'
 Vue.component('ibps-data-template-render-dialog', () => import('@/business/platform/data/templaterender/preview/dialog.vue'))
 import xlsxFile from '@/business/platform/data/templaterender/templates/compenent/xlsxFile.vue'
 import generalModules from '@/views/system/jbdScan/generalModules.vue'
-
+import { importZip as importzip } from '@/api/upload/zip'
 export default {
     name: 'list',
     components: {
@@ -354,6 +360,7 @@ export default {
         DictionaryFormat,
         Scan,
         importTable,
+        importZip,
         Print: () => import('../components/print'),
         LabelPrint: () => import('../components/labelPrint'),
         xlsxFile,
@@ -468,6 +475,7 @@ export default {
             printList: [],
 
             importTableDialogVisible: false,
+            importZipDialogVisible: false,
             position: null,
             importList: [],
             importValue: null,
@@ -1812,10 +1820,19 @@ export default {
         },
 
         // 自定义导入  小林
-        handleImport (data = []) {
-            this.importList = data
-            this.importValue = this.getKeys(this.importList)
-            this.importTableDialogVisible = true
+        handleImport (data = [], type = 'excel') {
+            switch (type) {
+                case 'excel':
+                    this.importList = data
+                    this.importValue = this.getKeys(this.importList)
+                    this.importTableDialogVisible = true
+                    break
+                case 'zip':
+                    this.importZipDialogVisible = true
+                    break
+                default:
+                    break
+            }
         },
         handleImportTableActionEvent (file, options) {
             this.loading = false
@@ -1837,6 +1854,13 @@ export default {
                 // ActionUtils.success('导入成功')
             })
         },
+        async handleImportZipActionEvent (file, options) {
+            // 调用上传接口
+            await importzip(file)
+            this.importZipDialogVisible = false
+            this.search()
+            ActionUtils.success('导入成功')
+        },
         setValue (data) {
             return Object.values(data).reduce((obj, item) => {
                 obj[item] = ''

+ 131 - 0
src/business/platform/form/formrender/dynamic-form/components/import-zip.vue

@@ -0,0 +1,131 @@
+<template>
+    <el-dialog
+        :title="title"
+        :visible.sync="dialogVisible"
+        :close-on-click-modal="false"
+        :close-on-press-escape="false"
+        append-to-body
+        class="dialog"
+        @opened="openedDialog"
+        @close="closeDialog"
+    >
+        <el-form
+            ref="importForm"
+            v-loading="dialogLoading"
+            :element-loading-text="$t('common.loading')"
+            :label-width="formLabelWidth"
+            class="import-form"
+            @submit.native.prevent
+        >
+
+            <el-form-item label="选择文件:" required>
+                <el-upload
+                    ref="upload"
+                    action="https://www.bpmhome.cn/post"
+                    accept=".zip"
+                    :file-list="fileList"
+                    :on-change="handleChange"
+                    :before-upload="handleUpload"
+                    :auto-upload="false"
+                >
+                    <el-button type="primary" icon="el-icon-upload">选择文件</el-button>
+                    <div slot="tip" class="el-upload__tip"> 请导入Zip文件</div>
+                </el-upload>
+            </el-form-item>
+            <!-- <el-form-item label="格式数据:">
+        <el-switch
+          v-model="options.raw"
+          active-text="原始"
+          inactive-text="格式化"
+        />
+      </el-form-item> -->
+        </el-form>
+        <div slot="footer" class="el-dialog--center">
+            <ibps-toolbar
+                :actions="toolbars"
+                @action-event="handleActionEvent"
+            />
+        </div>
+    </el-dialog>
+</template>
+
+<script>
+import ActionUtils from '@/utils/action'
+
+export default {
+    props: {
+        visible: {
+            type: Boolean,
+            default: false
+        },
+        title: {
+            type: String
+        }
+    },
+    data () {
+        return {
+            formName: 'importForm',
+            formLabelWidth: '120px',
+            dialogVisible: this.visible,
+            dialogLoading: false,
+            fileList: [],
+            options: {
+                raw: false
+            },
+            toolbars: [
+                { key: 'import' },
+                { key: 'cancel' }
+            ]
+        }
+    },
+    watch: {
+        visible: {
+            handler: function (val, oldVal) {
+                this.dialogVisible = this.visible
+            },
+            immediate: true
+        }
+    },
+    methods: {
+        openedDialog () {
+            this.fileList = []
+        },
+        handleActionEvent ({ key }) {
+            switch (key) {
+                case 'import':
+                    this.handleImport()
+                    break
+                case 'cancel':
+                    this.closeDialog()
+                    break
+                default:
+                    break
+            }
+        },
+        handleChange (file, fileList) {
+            if (fileList.length > 1) {
+                fileList.splice(0, 1)
+            }
+        },
+        handleUpload (file) {
+            // this.file = file
+            // 判断是否是Excel
+        },
+        async handleImport () {
+            const files = this.$refs['upload'].uploadFiles
+            if (this.$utils.isEmpty(files)) {
+                ActionUtils.warning('请上传要导入的文件')
+                return
+            }
+            console.log(files[0].raw)
+            this.$emit('action-event', files[0].raw, this.options)
+        },
+        // 关闭当前窗口
+        closeDialog () {
+            this.$emit('close', false)
+            this.$refs[this.formName].resetFields()
+        }
+    }
+
+}
+</script>