luowei 2 år sedan
förälder
incheckning
5abf256a27
2 ändrade filer med 77 tillägg och 15 borttagningar
  1. 6 0
      src/api/system/device.js
  2. 71 15
      src/views/system/device/index.vue

+ 6 - 0
src/api/system/device.js

@@ -32,6 +32,12 @@ export function getHostByOrgId(orgId) {
     method: 'get'
   })
 }
+export function downInCharge() {
+  return request({
+    url: '/system/device/downInChargeOfTemplate',
+    method: 'get'
+  })
+}
 // 新增【请填写功能名称】
 export function addDevice(data) {
   return request({

+ 71 - 15
src/views/system/device/index.vue

@@ -38,6 +38,14 @@
 
           <el-row :gutter="10" class="mb8">
             <el-col :span="1.5">
+              <el-button type="info" plain icon="el-icon-upload2" size="mini" @click="handleImport"
+                v-hasPermi="['system:device:import']">导入</el-button>
+            </el-col>
+               <el-col :span="1.5">
+              <el-button type="info" plain icon="el-icon-upload2" size="mini" @click="handleOut"
+                v-hasPermi="['system:device:import']">导出模版</el-button>
+            </el-col>
+            <el-col :span="1.5">
            
                 <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['system:device:add']">新增</el-button>
             </el-col>
@@ -89,23 +97,11 @@
   
     
    
- 
+
 
     <!-- 添加或修改【请填写功能名称】对话框 -->
     <el-dialog :title="title" :visible="open" width="800px" append-to-body @close="cancel">
       <el-form ref="form" :model="form" :rules="rules" label-width="80px">
-        <!-- <el-row>
-          <el-col :span="24">
-            <el-form-item label="所属机构" prop="orgId">
-              <tree-select style="width: 100%" v-model="form.orgId" :options="deptOptions" :show-count="true"
-                :normalizer="tenantIdnormalizer" placeholder="请选择归属机构" @select="changeSelect">
-              </tree-select>
-            </el-form-item>
-          </el-col>
-        </el-row> -->
-        <!-- <el-form-item label="所属机构" prop="orgId">
-          <orgDropDown v-model="form.orgId" placeholder="选择所属机构" @select="onOrgSelect" />
-        </el-form-item> -->
         <el-row>
           <el-col :span="20">
             <el-form-item label="所属机构" prop="orgId">
@@ -191,10 +187,25 @@
       </div>
     </el-dialog>
 
+        <!-- 设备导入对话框 -->
+        <DialogCom :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
+      <el-upload ref="upload" :limit="1" accept=".xlsx, .xls" :headers="upload.headers"
+        :action="upload.url " :disabled="upload.isUploading"
+        :on-progress="handleFileUploadProgress" :on-success="handleFileSuccess" :auto-upload="false" drag>
+        <i class="el-icon-upload"></i>
+        <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
+  
+      </el-upload>
+      <div slot="footer" class="dialog-footer">
+        <el-button type="primary" @click="submitFileForm">确 定</el-button>
+        <el-button @click="upload.open = false">取 消</el-button>
+      </div>
+    </DialogCom>
   </div>
 </template>
 
 <script>
+import { getToken } from "@/utils/auth";
 import orgDropDown from "../../../components/orgTree/orgDropDown.vue";
 import OrgTree from "@/components/orgTree";
 import tableList from '@/mixins/tableList'
@@ -202,7 +213,7 @@ import treeselect from '@riophae/vue-treeselect'
 import "@riophae/vue-treeselect/dist/vue-treeselect.css";
 import { deptTreeSelect } from "@/api/system/public";
 import { getDeviceType } from "@/api/system/dict/data";
-import { listDevice, getDevice, delDevice, addDevice, updateDevice, getHostByOrgId } from "@/api/system/device";
+import { listDevice, getDevice, delDevice, addDevice, updateDevice, getHostByOrgId ,downInCharge} from "@/api/system/device";
 export default {
   /** 引入基础minxins*/
   mixins: [tableList],
@@ -287,6 +298,20 @@ export default {
         channel: null,
         checkSub: true
       },
+        // 设备导入参数
+        upload: {
+        // 是否显示弹出层(用户导入)
+        open: false,
+        // 弹出层标题(用户导入)
+        title: "",
+        // 是否禁用上传
+        isUploading: false,
+       
+        // 设置上传的请求头部
+        headers: { Authorization: "Bearer " + getToken() },
+        // 上传的地址
+        url: process.env.VUE_APP_BASE_API + "/system/device/importData",
+      },
       // 表单参数
       form: {
         orgId: null,
@@ -326,6 +351,29 @@ export default {
       debugger
       this.form.orgName = node.name;
     },
+        // 文件上传中处理
+        handleFileUploadProgress(event, file, fileList) {
+      this.upload.isUploading = true;
+    },
+    handleImport() {
+      this.upload.title = "设备导入";
+      this.upload.open = true;
+    },
+   
+      // 文件上传成功处理
+      handleFileSuccess(response, file, fileList) {
+      this.upload.open = false;
+      this.upload.isUploading = false;
+      this.$refs.upload.clearFiles();
+      this.$alert(
+        "<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" +
+        response.msg +
+        "</div>",
+        "导入结果",
+        { dangerouslyUseHTMLString: true }
+      );
+      this.getList();
+    },
     getDefaultOrg(org){
       this.orgName = org.name;
     },
@@ -371,7 +419,11 @@ export default {
         this.hostList = response.data;
       })
     },
-
+    handleOut(){
+      this.download('system/device/downInChargeOfTemplate', {
+        ...this.queryParams
+      }, `${this.orgName+'-设备导入-'+this.formatTime(new Date(),'YYYYMMhh')}.xlsx`)
+    },
     /** 查询【请填写功能名称】列表 */
     getList() {
       this.loading = true;
@@ -515,6 +567,10 @@ export default {
         this.$modal.msgSuccess("删除成功");
       }).catch(() => { });
     },
+        // 提交上传文件
+        submitFileForm() {
+      this.$refs.upload.submit();
+    },
     /** 导出按钮操作 */
     handleExport() {
       this.download('system/device/export', {