Просмотр исходного кода

孙浩博,fixed:单文件数据集上传功能

seamew 1 год назад
Родитель
Сommit
c8a3106bf4

+ 1 - 1
config/index.js

@@ -24,7 +24,7 @@ module.exports = {
       }
     } : {
       '/proxyApi': {
-        target: 'http://demo.renren.io/renren-fast/',
+        target: 'http://localhost:8082/renren-fast/',
         changeOrigin: true,
         pathRewrite: {
           '^/proxyApi': '/'

+ 2 - 0
src/router/index.js

@@ -42,6 +42,8 @@ const mainRoutes = {
     // 创建数据集的路由
     { path: '/datasetstatus1-create', component: _import('modules/visi/create1'), name: 'create1', meta: { title: '创建静态数据集', isTab: false } },
     { path: '/datasetstatus2-create', component: _import('modules/visi/create2'), name: 'create2', meta: { title: '创建动态数据集', isTab: false } },
+    { path: '/datasetstatus3-create', component: _import('modules/visi/com/single-file-upLoad'), name: 'create3', meta: { title: '创建单文件数据集', isTab: false } },
+
 
     // 创建算法的路由
     { path: '/normalalg-create', component: _import('modules/alg/algcreate1'), name: 'algcreate1', meta: { title: '创建传统算法', isTab: false } },

+ 180 - 0
src/views/modules/visi/com/single-file-upLoad.vue

@@ -0,0 +1,180 @@
+<!--  -->
+<template>
+  <div>
+    <!--    面包屑,用来管理 首页>数据集管理>静态数据集,separator-class是设置面包屑中的分隔符>-->
+    <el-breadcrumb class="divi2" separator-class="el-icon-arrow-right">
+      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
+      <el-breadcrumb-item :to="{ path: '/visi-dataset' }">数据集管理</el-breadcrumb-item>
+      <el-breadcrumb-item>静态数据集</el-breadcrumb-item>
+    </el-breadcrumb>
+    <!--    el-divider是分割线-->
+    <el-divider class="divi"></el-divider>
+
+    <div class="container">
+      <div class="input-suffix">
+        <span>备注:</span>
+        <el-input
+          type="textarea"
+          :autosize="{ minRows: 2 }"
+          v-model="remark"
+          placeholder="请输入内容"
+          class="input"
+        ></el-input>
+      </div>
+      <el-upload
+        class="upload-demo"
+        drag
+        action=""
+        :file-list="fileList"
+        :limit="1"
+        :on-exceed="upLoadNumberWrong"
+        :on-change="handleChange"
+        :auto-upload="false"
+      >
+        <i class="el-icon-upload"></i>
+        <div class="el-upload__text">
+          将文件拖到此处,或
+          <em>点击上传</em>
+        </div>
+        <div class="tip" slot="tip">注意:只允许上传一个文件</div>
+      </el-upload>
+      <span class="bottom-element">
+        <el-button @click="close">取 消</el-button>
+        <el-button type="primary" @click="submit">确 定</el-button>
+      </span>
+    </div>
+  </div>
+</template>
+
+<script>
+import { Message } from "element-ui";
+
+export default {
+  name: "singleFileUpload",
+  data() {
+    return {
+      url: this.$http.adornUrl(`/dataset/staticup/upload?token=${this.$cookie.get("Algtoken")}`),
+      dataInfo: {
+        id: this.$store.state.user.id
+      },
+      fileList: [],
+      remark: ""
+    };
+  },
+  methods: {
+    close() {
+      this.$router.replace({ path: "/visi-dataset" });
+    },
+    upLoadNumberWrong() {
+      Message({
+        message: "单次只允许上传一个文件",
+        type: "error"
+      });
+    },
+    async submit() {
+      if (this.fileList.length > 0) {
+        console.log(this.fileList);
+        const formData = new FormData();
+        formData.append("file", this.fileList[0].raw); // 添加文件
+        // 将其他表单数据添加到 formData 对象中
+        let dataSet = {
+          datasetName: this.fileList[0].name,
+          uid: this.$store.state.user.id,
+          datasetStatus: 1,
+          remark: this.remark
+        };
+        formData.append("dataSet", JSON.stringify(dataSet));
+        const { data } = await this.$http({
+          url: this.$http.adornUrl("/dataset/staticup/uploadFile"),
+          method: "post",
+          data: formData,
+          headers: {
+            "Content-Type": "multipart/form-data"
+          },
+          timeout: undefined
+        });
+        Message({
+          message: "上传完毕",
+          type: "success"
+        });
+        this.$router.replace({ path: "/visi-dataset" });
+      } else {
+        Message({
+          message: "请先上传一个文件",
+          type: "error"
+        });
+      }
+    },
+    handleChange(file, fileList) {
+      console.log("fileList :>> ", fileList);
+      this.fileList = fileList.slice(-3);
+    },
+    unique(arr) {
+      var ss = [];
+      for (var i = 0; i < arr.length; i++) {
+        // ss[i] = arr[i].categoryName
+        ss[i] = arr[i];
+      }
+      return Array.from(new Set(ss));
+    }
+  }
+};
+</script>
+
+<style scoped>
+.input-suffix {
+  display: flex;
+  align-items: center; /* 垂直居中 */
+  justify-content: center; /* 水平居中 */
+  width: 30vw;
+  margin: 20px 0;
+}
+.input-suffix span {
+  width: 100px;
+  font-size: 20px;
+}
+.input {
+  flex: 1;
+}
+.container {
+  position: relative;
+  height: 50vh;
+  display: flex;
+  align-items: center; /* 垂直居中 */
+  justify-content: center; /* 水平居中 */
+  flex-direction: column;
+}
+.divi2 {
+  display: block;
+  height: 1px;
+  width: 100%;
+  position: relative;
+}
+
+.divi {
+  display: block;
+  height: 1px;
+  width: 100%;
+  margin: 24px 0;
+  background-color: #dcdfe6;
+}
+
+.bottom-element {
+  position: absolute;
+  bottom: 0;
+  right: 10%;
+}
+
+.tip {
+  margin-top: 20px;
+  text-align: center;
+  font-size: 20px;
+}
+.container >>> .el-upload-list .el-upload-list__item-name {
+  font-size: 20px; /* 设置文件名字体大小 */
+}
+
+.container >>> .el-upload-list .el-upload-list__item-actions {
+  font-size: 14px; /* 设置操作按钮字体大小 */
+}
+</style>

+ 3 - 0
src/views/modules/visi/create1.vue

@@ -1181,6 +1181,9 @@ export default {
       }).then(({data}) => {
         var ss = []
         for (var i = 0; i < data.list.length; i++) {
+          if (data.list[i].categoryName.includes("文件")) {
+            continue;
+          }
           ss[i] = data.list[i]
         }
         this.classification = Array.from(new Set(ss))

+ 6 - 2
src/views/modules/visi/dataset-add.vue

@@ -8,12 +8,13 @@
         <el-radio-group v-model="datasetStatus">
           <el-radio :label="1">静态数据集</el-radio>
           <el-radio :label="2">动态数据集</el-radio>
+          <el-radio :label="3">静态单文件</el-radio>
         </el-radio-group>
       </el-form-item>
     </el-form>
     <span slot="footer" class="dialog-footer">
       <el-button @click="visible = false">取消</el-button>
-      <el-button type="primary" @click="visible=false;creatDataSetHandle()">确定</el-button>
+      <el-button type="primary" @click="creatDataSetHandle()">确定</el-button>
     </span>
   </el-dialog>
 </template>
@@ -36,12 +37,15 @@ export default {
     },
     // 创建数据集处理函数
     creatDataSetHandle () {
+      this.visible = false;
       // 如果为静态数据集
       if (this.datasetStatus === 1) {
         this.$router.replace({ path: '/datasetstatus1-create' })
-      } else {
+      } else if (this.datasetStatus === 2) {
         // 如果为动态数据集
         this.$router.replace({ path: '/datasetstatus2-create' })
+      } else if (this.datasetStatus === 3) {
+        this.$router.replace({ path: '/datasetstatus3-create' })
       }
     }
   }