Przeglądaj źródła

Merge branch 'master' of http://192.168.4.246:3000/zhangs/surveyMaker

zhangwf 5 lat temu
rodzic
commit
b6cd136eac

+ 12 - 1
src/api/test.js

@@ -1,9 +1,20 @@
 import * as http from '../util/http'
 
+// 测试列表分页查询
 const testList = (param) => {
   return http.post('/testTheme/testList', param)
 }
 
+// 删除测试
+const deleteTest = (param) => {
+  return http.post('/testTheme/deleteTest', param)
+}
+// 复制测试
+const copyTest = (param) => {
+  return http.post('/testTheme/copyTest', param)
+}
+
+
 module.exports = {
-  testList
+  testList, deleteTest, copyTest
 }

BIN
src/assets/images/picture-error.png


+ 28 - 21
src/views/myHistoryTest/myHistoryTest.html

@@ -1,26 +1,24 @@
-<div class="page">
+<div class="page" style="overflow:auto">
   <!-- 头部 -->
   <HeaderMain></HeaderMain>
   <!-- 工具栏 -->
   <div class="history-tools">
     <div class="left">
-      <el-dropdown trigger="click">
-        <el-button type="primary">所属项目 <i class="el-icon-caret-bottom icon-right"></i>
+      <el-dropdown trigger="click" @command="projectCommand">
+        <el-button type="primary">{{ownHouseName}} <i class="el-icon-caret-bottom icon-right"></i>
         </el-button>
         <el-dropdown-menu slot="dropdown">
-          <el-dropdown-item>黄金糕黄金糕黄金糕</el-dropdown-item>
-          <el-dropdown-item>狮子头</el-dropdown-item>
-          <el-dropdown-item>螺蛳粉</el-dropdown-item>
-          <el-dropdown-item>双皮奶</el-dropdown-item>
-          <el-dropdown-item>蚵仔煎</el-dropdown-item>
+          <el-dropdown-item>全部</el-dropdown-item>
+          <el-dropdown-item v-for="(item,index) in houseList" :key="item.houseId" :command="item">
+            {{item.houseName}}</el-dropdown-item>
         </el-dropdown-menu>
       </el-dropdown>
-      <el-dropdown trigger="click">
-        <el-button type="primary">更新时间 <i class="el-icon-caret-bottom icon-right"></i>
+      <el-dropdown trigger="click" @command="orderCommand">
+        <el-button type="primary">{{currOrderName}} <i class="el-icon-caret-bottom icon-right"></i>
         </el-button>
         <el-dropdown-menu slot="dropdown">
-          <el-dropdown-item>按创建时间排序</el-dropdown-item>
-          <el-dropdown-item>按更新时间排序</el-dropdown-item>
+          <el-dropdown-item v-for="(item,index) in orderList" :key="item.orderType" :command="item">{{item.orderName}}
+          </el-dropdown-item>
         </el-dropdown-menu>
       </el-dropdown>
     </div>
@@ -29,20 +27,27 @@
     </div>
   </div>
   <!-- 列表 -->
-  <div class="test-list">
-    <div class="item" v-for="(item,index) in lists" :key="item.index" :class="{ itemCopy: isCopy && index == 0 }">
+  <div class="test-list" v-infinite-scroll="load" infinite-scroll-disabled="disabled">
+    <div class="item" v-for="(item,index) in pageModel.resultSet" :key="item.created"
+      :class="{ itemCopy: isCopy && index == 0 }">
+      <!-- <img  mode="" :src="" alt=""> -->
+      <el-image class="item-img" :src="item.coverImg">
+        <div slot="error" class="outline">
+          <img class="item-img-outline" src="../../assets/images/picture-error.png" alt="">
+          <!-- <i class="el-icon-picture-outline"></i> -->
+        </div>
+      </el-image>
       <div class="tools">
-        <img class="item-img delete" src="" alt="" @click="deleteTest(index)">
-        <img class="item-img copy" src="" alt="" @click="copyTest">
+        <img v-if="item.canDelete" class="item-img delete" src="" alt="" @click="deleteTest(item)">
+        <img class="item-img copy" src="" alt="" @click="copyTest(item)">
         <img class="item-img share" src="" alt="" @click="shareTest()">
         <img class="item-img edit" src="" alt="" @click="editTest" style="float:right;margin-right:10px;">
       </div>
-      <img class="item-img" mode="" src="https://dm.static.elab-plus.com/diaoyanbao/coverImg/GT95_preview.jpg" alt="">
-      <div class="title">定制你的家具香气{{item.index}}</div>
-      <div class="desc">无锡WIII</div>
+      <div class="title">{{item.title}}</div>
+      <div class="desc">{{item.ownHouseName}}</div>
       <div class="bottom">
-        <span>共21题</span>
-        <span>1天前</span>
+        <span>共{{item.questionCount}}题</span>
+        <span>{{item.created}}</span>
       </div>
     </div>
     <div class="item add" @click="createTest">
@@ -50,6 +55,8 @@
       <span>创建测试</span>
     </div>
   </div>
+  <div v-if="loading" class="loading">加载中...</div>
+  <div v-if="noMore" class="loading">没有更多了</div>
   <!-- 分享设置 -->
   <ShareSetting v-show="isShareSetting" :close="closeShare"></ShareSetting>
 </div>

+ 95 - 18
src/views/myHistoryTest/myHistoryTest.js

@@ -1,5 +1,8 @@
 import HeaderMain from "../../components/HeaderMain";
 import ShareSetting from "../../components/ShareSetting";
+import api from '../../api/test'
+import editorApi from '../../api/editor'
+
 export default {
   components: {
     HeaderMain, ShareSetting
@@ -28,7 +31,21 @@ export default {
         label: '广州'
       }],
       value: '',
-      lists: [{ index: 0 }, { index: 1 }, { index: 2 }, { index: 3 }, { index: 4 }, { index: 5 }, { index: 6 }, { index: 7 }, { index: 8 }, { index: 9 }, { index: 10 }, { index: 11 }, { index: 12 }, { index: 13 }, { index: 14 }, { index: 15 }, { index: 16 }, { index: 17 }, { index: 18 }, { index: 19 }]
+      pageModel: "",
+      loading: false,
+      houseList: [],
+      ownHouseName: "所属项目",
+      orderList: [{ orderName: "按创建时间排序", orderType: "created" }, { orderName: "按更新时间排序", orderType: "updated" }],
+      currOrderName: "更新时间",
+      currOrderType: ""
+    }
+  },
+  computed: {
+    noMore() {
+      return this.pageModel.count == this.pageModel.total && this.pageModel.total > 1
+    },
+    disabled() {
+      return this.loading || this.pageModel.count == this.pageModel.total
     }
   },
   watch: {
@@ -42,11 +59,56 @@ export default {
       }
     }
   },
+  created() {
+    this.houseList = [];
+    editorApi.houseList().then((res) => {
+      if (res.success) {
+        this.houseList = res.list;
+      }
+    });
+    this.getTestList(true);
+  },
   methods: {
+    load() {
+      this.getTestList(false);
+    },
+    getTestList(isFirst) {
+      this.loading = !isFirst
+      let data = {
+        "orderType": this.currOrderType,
+        "ownHouseName": this.ownHouseName == "所属项目" ? '' : this.ownHouseName,
+        "pageNo": isFirst ? 0 : this.pageModel.count + 1,
+      }
+      api.testList(data).then((res) => {
+        if (res.success) {
+          this.pageModel = res.pageModel;
+          console.log("success", this.pageModel);
+        } else {
+          console.log("error");
+        }
+        this.loading = false
+      })
+    },
+    projectCommand(command) {
+      if (this.houseList.indexOf(command) == -1) {
+        console.log("不存在");
+        this.ownHouseName = "所属项目";
+      } else {
+        console.log("存在", command.houseName);
+        this.ownHouseName = command.houseName;
+      }
+      this.getTestList(true);
+    },
+    orderCommand(command) {
+      console.log(command);
+      this.currOrderName = command.orderName;
+      this.currOrderType = command.orderType;
+      this.getTestList(true);
+    },
     createTest() {
       this.$router.push({ path: '/cncTestLists' });
     },
-    deleteTest(index) {
+    deleteTest(item) {
       const h = this.$createElement;
       this.$msgbox({
         title: '删除',
@@ -58,34 +120,49 @@ export default {
           if (action === 'confirm') {
             instance.confirmButtonLoading = true;
             instance.confirmButtonText = '执行中...';
-            setTimeout(() => {
-              done();
-              setTimeout(() => {
+            let data = {
+              "id": item._id,
+            }
+            api.deleteTest(data).then((res) => {
+              if (res.success) {
                 instance.confirmButtonLoading = false;
-              }, 300);
-            }, 3000);
+              } else {
+                done();
+              }
+            })
           } else {
             done();
           }
         }
       }).then(() => {
-        this.lists.splice(index, 1);
+        this.pageModel.resultSet.splice(index, 1);
         this.$message({
           type: 'success',
           message: '删除成功'
         });
       }).catch(() => { });
     },
-    copyTest() {
-      this.$message({
-        message: '复制成功',
-        type: 'success'
-      });
-      this.lists.unshift({ index: 100 });
-      this.isCopy = true;
-      setTimeout(() => {
-        this.isCopy = false;
-      }, 2000);
+    copyTest(item) {
+      let data = {
+        "id": item._id,
+        "operator": "测试"
+      }
+      api.copyTest(data).then((res) => {
+        if (res.success) {
+          this.$message({
+            message: '复制成功',
+            type: 'success'
+          });
+          this.pageModel.resultSet.unshift(res.single);
+          this.isCopy = true;
+          setTimeout(() => {
+            this.isCopy = false;
+          }, 2000);
+        } else {
+          this.$message.error('复制失败,请重试');
+        }
+      })
+
     },
     editTest() {
       this.$router.replace({ path: '/h5editor', query: { itemId: 0 } })

+ 25 - 0
src/views/myHistoryTest/myHistoryTest.scss

@@ -26,6 +26,11 @@
       background-color: #fff;
       border-color: #fff;
     }
+    .el-button--primary:focus,.el-button--primary:hover {
+      background: #4E5DFF;
+      border-color: #4E5DFF;
+      color: #fff;
+    }
     .icon-right {
       position: absolute;
       right: 10px;
@@ -115,7 +120,17 @@
       height:156px;
       border-radius:6px 6px 0px 0px;
       object-fit: cover;
+      display: flex;
+      justify-content: center;
+      align-items: center;
+      .item-img-outline{
+        width: 98px;
+        height: 69px;
+        object-fit: contain;
+      }
+      
     }
+    
     .title {
       flex-grow: 2;
       margin: 10px;
@@ -178,4 +193,14 @@
     visibility: hidden;
     color: red;
   }
+}
+.el-dropdown-menu{
+  max-height: 200px;
+  overflow-y: auto;
+}
+.loading ,.noMore{
+  text-align: center;
+  height: 40px;
+  line-height: 40px;
+  color: #4E5DFF;
 }