Browse Source

'文件上传'

蒋珅 1 year ago
parent
commit
87efb75aed
2 changed files with 101 additions and 73 deletions
  1. 86 58
      src/pages/buildTable/create/index.vue
  2. 15 15
      src/router/index.js

+ 86 - 58
src/pages/buildTable/create/index.vue

@@ -1,7 +1,7 @@
 <script setup name="prepare">
 import treeCop from "@/components/tree.vue";
 import { useRouter } from "vue-router";
-import { ElMessage, ElMessageBox } from "element-plus";
+import { ElMessage, ElMessageBox, genFileId } from "element-plus";
 import { onMounted, ref, reactive, onActivated, nextTick } from "vue";
 
 import {
@@ -166,22 +166,24 @@ const funCurrentChange = async ({ current, currentNode }) => {
   tableData.value = newdata;
   console.log("66b", tableData.value);
 
-  const ros = await request.post(
-    "/rest/sql",
-    `SELECT DISTINCT station FROM ${databaseName}.${tableName}`
-  );
-  // console.log('69966', ros);
-  let nbdata = [];
-  ros.data.forEach((ele) => {
-    ele?.[0] && nbdata.push(ele[0]);
-  });
-  // console.log(55555,nbdata);
+  if (stationList.value == "") {
+    const ros = await request.post(
+      "/rest/sql",
+      `SELECT DISTINCT station FROM ${databaseName}.${tableName}`
+    );
+    // console.log('69966', ros);
+    let nbdata = [];
+    ros.data.forEach((ele) => {
+      ele?.[0] && nbdata.push(ele[0]);
+    });
+    // console.log(55555,nbdata);
 
-  stationList.value = nbdata;
+    stationList.value = nbdata;
 
-  // console.log(7777777777, stationList.value);
-  if (stationList.value.length) {
-    queryForm.station = stationList.value[0];
+    // console.log(7777777777, stationList.value);
+    if (stationList.value.length) {
+      queryForm.station = stationList.value[0];
+    }
   }
 };
 
@@ -279,10 +281,38 @@ const exportDepReceRank = () => {
   exportMethod(myObj);
 };
 
-const upload = ref();
+//存储文件变量
+let fileUplod = ref(null);
+function changeUpload(UploadFile, uploadFiles) {
+  fileUplod.value = UploadFile.raw;
+          console.log("996", fileUplod.value);
+
+}
+function beforeUpload(file) {
+  // fileUplod.value = file;
+  //  console.log("996", file);
+  const isXLSX =
+    file.type ===
+    "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
+  const isLt5M = file.size / 1024 / 1024 < 5;
+
+  if (!isXLSX) {
+    ElMessage.error("上传Excel文件只能是 xlsx 格式!");
+  }
+  if (!isLt5M) {
+    ElMessage.error("上传Excel文件大小不能超过 5MB!");
+  }
+  return isXLSX && isLt5M;
+}
+// 上传文件
 const fslist = async (urlKey) => {
+  // upload.value.submit()
+  let formData =new FormData()
+  formData.append("excelFile",fileUplod.value)
+  // formData.get("excelFile")
+  console.log(formData);
   const requestUrl = config[urlKey];
-  const res = await request.post(`${requestUrl}/taos/uploadexcel`);
+  const res = await request.post(`${requestUrl}/taos/uploadexcel`, formData);
   console.log("nbnbnbnbn", res);
 };
 
@@ -302,7 +332,6 @@ const dbclick = (a) => {
 };
 
 /**table 开始 */
-// const tableShowId = ref("");
 const tableName = ref("");
 const tableLoading = ref(false);
 let tableData = ref([]);
@@ -409,7 +438,7 @@ const handleEdit = (index) => {
   formlist.beilv = tableData.value[editIndex.value].rate;
   formlist.beizhu = tableData.value[editIndex.value].remark;
 };
-    
+
 const queren = () => {
   dialogFormVisible.value = false;
   tableData.value[editIndex.value].point = formlist.cedian;
@@ -423,57 +452,52 @@ const queren = () => {
 };
 
 //删除
-const handleDelete = (index) => {
-  editIndex.value = index;
-  tableData.value.splice(editIndex.value, 1);
-};
+// const handleDelete = (index) => {
+//   editIndex.value = index;
+//   tableData.value.splice(editIndex.value, 1);
+// };
 
 //  选中
 let selectedRows = reactive([]);
 const handleSelectionChange = (selection) => {
   console.log("991", selection);
   selectedRows = selection;
-  console.log("992", selectedRows);
+  // console.log("992", selectedRows);
 };
 
 // 选中删除
 const bdhandleDelete = () => {
-  ElMessageBox.confirm(
-    '确认要删除吗?',
-    'Warning',
-    {
-      confirmButtonText: '确定',
-      cancelButtonText: '取消',
-      type: 'warning',
-    }
-  )
+  ElMessageBox.confirm("确认要删除吗?", "Warning", {
+    confirmButtonText: "确定",
+    cancelButtonText: "取消",
+    type: "warning",
+  })
     .then(() => {
       ElMessage({
-        type: 'success',
-        message: '删除成功',
-      })
-       selectedRows.forEach((selectedRows) => {
-       const index = tableData.value.indexOf(selectedRows); // 获取选中数据在原数组中的索引
-       if (index > -1) {
-       tableData.value.splice(index, 1); // 从原数组中删除选中的数据
-    }
-  });
+        type: "success",
+        message: "删除成功",
+      });
+      selectedRows.forEach((selectedRows) => {
+        const index = tableData.value.indexOf(selectedRows); // 获取选中数据在原数组中的索引
+        if (index > -1) {
+          tableData.value.splice(index, 1); // 从原数组中删除选中的数据
+        }
+      });
     })
     .catch(() => {
       ElMessage({
-        type: 'info',
-        message: '删除失败',
-      })
-    })
+        type: "info",
+        message: "删除失败",
+      });
+    });
 };
-   
-  
+
 /**mounted */
 onMounted(() => {
   tableHeight.value = window.innerHeight - 260 + "px";
   excelHeight.value = window.innerHeight - 260 + "px";
   treeHeight.value = window.innerHeight - 260 + "px";
-  window.addEventListener("resize", () => {  
+  window.addEventListener("resize", () => {
     tableHeight.value = window.innerHeight - 260 + "px";
     excelHeight.value = window.innerHeight - 260 + "px";
     treeHeight.value = window.innerHeight - 260 + "px";
@@ -524,28 +548,33 @@ onActivated(() => {
         </el-form-item>
       </el-form>
       <el-upload
-        ref="upload"
         class="upload-demo"
-        action="http://192.168.10.9:5087/taos/uploadexcel"
+        action="#"
         :limit="1"
+        :on-change="changeUpload"
+        name="fileData"
         :on-exceed="handleExceed"
+        :before-upload="beforeUpload"
         :auto-upload="false"
       >
         <template #trigger>
           <el-button type="primary">选择文件</el-button>
         </template>
       </el-upload>
-      
+      <!-- 提交文件所上传的文件 -->
       <el-form-item class="!mb-0 ml-5">
         <el-button @click="fslist('redisURL')" type="success">上传</el-button>
       </el-form-item>
       <el-form-item class="!mb-0 ml-5">
-        <el-button @click="exportDepReceRank" type="primary">下载建点、修改点模板</el-button>
+        <el-button @click="exportDepReceRank" type="primary"
+          >下载建点、修改点模板</el-button
+        >
       </el-form-item>
     </div>
 
     <div
-      class="relative shadow rounded-[6px] shadow-blue-500 px-[10px] pt-[20px] pb-[10px]">
+      class="relative shadow rounded-[6px] shadow-blue-500 px-[10px] pt-[20px] pb-[10px]"
+    >
       <el-row :gutter="10">
         <el-col :span="4">
           <tree-cop
@@ -558,7 +587,7 @@ onActivated(() => {
           </tree-cop>
         </el-col>
 
-        <el-col :span="20">
+        <el-col :span="19">
           <div>
             <el-scrollbar max-height="650px">
               <el-table
@@ -618,12 +647,12 @@ onActivated(() => {
                       @click="handleEdit(scope.$index, scope.row)"
                     />
 
-                    <el-button
+                    <!-- <el-button
                       type="danger"
                       :icon="Delete"
                       circle
                       @click="handleDelete(scope.$index, scope.row)"
-                    />
+                    /> -->
                   </template>
                 </el-table-column>
               </el-table>
@@ -675,6 +704,5 @@ onActivated(() => {
         </span>
       </template>
     </el-dialog>
-  
   </div>
 </template>

+ 15 - 15
src/router/index.js

@@ -95,19 +95,19 @@ const routes = [{
             ]
         },
         
-        // {
-        //     icon: 'iconfont iconbaojingpeizhi',
-        //     path: '/look',
-        //     name: 'look',
-        //     redirect: '/look/create',
-        //     meta: {
-        //         title: '高级查询',
-        //     },
-        //     component: () =>
-        //         import(
-        //             '../pages/routerViewss.vue'
-        //         ),
-        //     children: [
+        {
+            icon: 'iconfont iconbaojingpeizhi',
+            path: '/look',
+            name: 'look',
+            redirect: '/look/create',
+            meta: {
+                title: '高级查询',
+            },
+            component: () =>
+                import(
+                    '../pages/routerViewss.vue'
+                ),
+            children: [
                 {
                     icon: 'el-icon-s-home',
                     path: '/look/create',
@@ -120,8 +120,8 @@ const routes = [{
                             '../pages/look/create/index.vue'
                         ),
                 }
-        //     ]
-        // },
+            ]
+        },
 
      
         //  {