Forráskód Böngészése

添加导入产品功能

yangg 5 hónapja
szülő
commit
e15ab0f31a
1 módosított fájl, 61 hozzáadás és 10 törlés
  1. 61 10
      ui/src/views/ProductMent/ProductManagement.vue

+ 61 - 10
ui/src/views/ProductMent/ProductManagement.vue

@@ -61,13 +61,26 @@
             </el-form-item>
           </el-form>
         </div>
-        <el-button type="primary" @click="handleAddProduct">新建产品</el-button>
+        <div class="button-group">
+          <el-button type="primary" @click="handleAddProduct"
+            >新建产品</el-button
+          >
+          <el-upload
+            class="upload-demo"
+            action="#"
+            :http-request="handleFileUpload"
+            :show-file-list="false"
+            accept=".txt"
+          >
+            <el-button type="primary">导入产品</el-button>
+          </el-upload>
+        </div>
       </div>
 
       <el-table :data="productList">
         <el-table-column prop="dcp_oa_code" label="OA编号" />
-        <el-table-column 
-          prop="dcp_p_no" 
+        <el-table-column
+          prop="dcp_p_no"
           label="产品应用编号"
           show-overflow-tooltip
           :min-width="120"
@@ -173,15 +186,17 @@
   
   <script>
 import { productList, deleteProduct } from "@/api/ProductMent/product";
+import axios from "axios";
+const baseURL = process.env.VUE_APP_BASE_API;
 export default {
   name: "ProductManagement",
   data() {
     return {
       searchForm: {
-        dcp_p_no: '',
-        dcp_name: '',
-        dcp_model: '',
-        dcp_oa_code: ''
+        dcp_p_no: "",
+        dcp_name: "",
+        dcp_model: "",
+        dcp_oa_code: "",
       },
       categoryData: [
         {
@@ -271,7 +286,7 @@ export default {
         const params = {
           pageNum: this.pagination.currentPage,
           pageSize: this.pagination.pageSize,
-          ...this.searchForm  // 展开所有搜索条件
+          ...this.searchForm, // 展开所有搜索条件
         };
 
         productList(params).then((res) => {
@@ -417,12 +432,39 @@ export default {
       // 重置表单引用
       this.$refs.searchForm.resetFields();
       // 手动清空 searchForm 对象的所有属性
-      Object.keys(this.searchForm).forEach(key => {
-        this.searchForm[key] = '';
+      Object.keys(this.searchForm).forEach((key) => {
+        this.searchForm[key] = "";
       });
       this.pagination.currentPage = 1;
       this.fetchProductList();
     },
+
+    // 添加文件上传方法
+    async handleFileUpload(file) {
+      try {
+        const formData = new FormData();
+        formData.append("file", file.file);
+
+        const response = await axios.post(
+          `${baseURL}/product/export/json`,
+          formData,
+          {
+            headers: {
+              "Content-Type": "multipart/form-data",
+            },
+          }
+        );
+
+        if (response.data.code === 200) {
+          this.$message.success("导入成功");
+          this.fetchProductList(); // 刷新产品列表
+        } else {
+          this.$message.error(response.data.msg || "导入失败");
+        }
+      } catch (error) {
+        this.$message.error("导入失败:" + error.message);
+      }
+    },
   },
 };
 </script>
@@ -501,4 +543,13 @@ export default {
   overflow: hidden;
   text-overflow: ellipsis;
 }
+
+.button-group {
+  display: flex;
+  gap: 10px;
+}
+
+.upload-demo {
+  display: inline-block;
+}
 </style>