Browse Source

静态数据测试没问题,想在首页展示所有用例的时候已归档的在card右上方加个标签

chen xueyi 2 years ago
parent
commit
e7e9fc0151
3 changed files with 142 additions and 86 deletions
  1. 132 59
      src/components/TCList.vue
  2. 9 26
      src/components/Upload.vue
  3. 1 1
      src/pinia/docx.ts

+ 132 - 59
src/components/TCList.vue

@@ -15,17 +15,7 @@ const router = useRouter();
 const route = useRoute();
 console.log(route.query.id)
 
-const temp1 = [
-  {
-    "编号": "TC001.1",
-    "用例标题": "用户未登录",
-    "简短描述": "验证用户未登录时无法访问新增挡板页面"
-  },
-  {
-    "编号": "TC002.1",
-    "用例标题": "用户登录",
-    "简短描述": "验证用户登录后能否访问挡板设置"
-  },
+const temp1 = [{"编号": "TC001.1", "用例标题": "用户未登录", "简短描述": "验证用户未登录时无法访问新增挡板页面"}, {"编号": "TC002.1", "用例标题": "用户登录", "简短描述": "验证用户登录后能否访问挡板设置"},
   {
     "编号": "TC003.1",
     "用例标题": "访问挡板配置",
@@ -199,20 +189,51 @@ const handleImproveButton = (p: { row: any }) => {
 
   axios(config)
       .then((response: AxiosResponse<any>) => {
+  //const test = " [{\"编号\":\"TC001.1\", \"用例标题\": \"用户未登录\", \"简短描述\": \"验证用户未登录时无法访问新增挡板页面\"}, {\"编号\": \"TC002.1\", \"用例标题\": \"用户登录\", \"简短描述\": \"验证用户登录后能否访问挡板设置\"}]"
         console.log(response.data.output);
         const output = JSON.stringify(JSON.parse(response.data.output))
-        //更新用例列表
-        useStore.DocxList[itemIndex.value].docxMessageList = parseOutput(output);
-        testCase.value = useStore.DocxList[itemIndex.value].docxMessageList;
-        //更新操作记录
-        console.log(actionList.value)
-        useStore.DocxList[itemIndex.value].actionList.push({
-          description: "细化用例 "+improve_id,
-          time: dayjs().format('YYYY-MM-DD HH:mm:ss')
-        })
-        console.log(useStore.DocxList[itemIndex.value].actionList)
-        actionList.value = useStore.DocxList[itemIndex.value].actionList;
-        console.log(actionList.value)
+        console.log(output)
+        for (let item of useStore.taskList){
+          console.log(item.testCaseListId)
+          if(item.testCaseListId == itemIndex.value){
+            const improveList = parseOutput(output)
+            //更新用例列表
+            item.testCaseList = JSON.stringify(improveList)
+            console.log(item)
+            testCase.value = improveList
+            //更新操作记录
+            let lastActionList: Action[] =  JSON.parse(item.actionList)
+            const action = {description: "细化用例 "+improve_id, times: dayjs().format('YYYY-MM-DD HH:mm:ss')}
+            lastActionList.push(action)
+            item.actionList = JSON.stringify(lastActionList)
+            actionList.value = JSON.parse(item.actionList)
+            //写进数据库
+            axios({
+              url: "http://localhost:8081/testCaseList/modify",               // 请求地址
+              method: "post",                       // 请求方法
+              headers: {                            // 请求头
+                "Content-Type": "application/json",
+              },
+              data: {                             // 请求参数
+                userId: item.userId,
+                creatTime: item.creatTime,
+                docxName: item.docxName,
+                testCaseList: item.testCaseList,
+                actionList: item.actionList,
+                tcFinalList: item.tcFinalList
+              },
+            }).then((res) => {
+              if(res.data.msg !== "更新成功!"){
+                ElMessage({
+                  message: '数据库出错',
+                  type: 'warning'
+                });
+              }
+            })
+            }
+
+          }
+        useStore.saveTaskList()
         loadingImprove.close()
       })
       .catch((error: AxiosError<any>) => {
@@ -259,26 +280,56 @@ const deteleList = (scope: { row: any }) => {
   axios(deleteConfig)
       .then((response: AxiosResponse<any>) => {
         console.log(response.data.output);
+  //const test = " [{\"编号\":\"TC001.1\", \"用例标题\": \"用户未登录\", \"简短描述\": \"验证用户未登录时无法访问新增挡板页面\"}, {\"编号\": \"TC002.1\", \"用例标题\": \"用户登录\", \"简短描述\": \"验证用户登录后能否访问挡板设置\"}]"
+
         const output = JSON.stringify(JSON.parse(response.data.output))
-        //更新用例列表
-        useStore.DocxList[itemIndex.value].docxMessageList = parseOutput(output);
-        testCase.value = useStore.DocxList[itemIndex.value].docxMessageList;
-        //更新操作记录
-        useStore.DocxList[itemIndex.value].actionList.push({
-          description: "删除用例 "+delete_id,
-          time: dayjs().format('YYYY-MM-DD HH:mm:ss')
-        })
-        useStore.saveDocxList()
-        console.log(useStore.DocxList[itemIndex.value].actionList)
-        actionList.value = useStore.DocxList[itemIndex.value].actionList;
-        useStore.saveDocxList()
-        console.log(actionList.value)
+        console.log(output)
+        for (let item of useStore.taskList){
+          console.log(item.testCaseListId)
+          if(item.testCaseListId == itemIndex.value){
+            const improveList = parseOutput(output)
+            //更新用例列表
+            item.testCaseList = JSON.stringify(improveList)
+            console.log(item)
+            testCase.value = improveList
+            //更新操作记录
+            let lastActionList: Action[] =  JSON.parse(item.actionList)
+            const action = {description: "删除用例 "+delete_id, times: dayjs().format('YYYY-MM-DD HH:mm:ss')}
+            lastActionList.push(action)
+            item.actionList = JSON.stringify(lastActionList)
+            actionList.value = JSON.parse(item.actionList)
+            //写进数据库
+            axios({
+              url: "http://localhost:8081/testCaseList/modify",               // 请求地址
+              method: "post",                       // 请求方法
+              headers: {                            // 请求头
+                "Content-Type": "application/json",
+              },
+              data: {                             // 请求参数
+                userId: item.userId,
+                creatTime: item.creatTime,
+                docxName: item.docxName,
+                testCaseList: item.testCaseList,
+                actionList: item.actionList,
+                tcFinalList: item.tcFinalList
+              },
+            }).then((res) => {
+              if(res.data.msg !== "更新成功!"){
+                ElMessage({
+                  message: '数据库出错',
+                  type: 'warning'
+                });
+              }
+            })
+          }
+
+        }
+        useStore.saveTaskList()
         loadingDelete.close()
       })
       .catch((error: AxiosError<any>) => {
         console.log(error);
       });
-
 }
 
 //添加用例
@@ -319,29 +370,51 @@ const addDocxList = () => {
 
     axios(addConfig)
         .then((response: AxiosResponse<any>) => {
-          console.log(JSON.stringify(response.data));
+          console.log(response.data.output);
           const output = JSON.stringify(JSON.parse(response.data.output))
-
-          //更新用例列表
-          useStore.DocxList[itemIndex.value].docxMessageList = parseOutput(output);
-          useStore.saveDocxList()
-          testCase.value = useStore.DocxList[itemIndex.value].docxMessageList
-          //更新操作记录
-          useStore.DocxList[itemIndex.value].actionList.push({
-            description: "添加用例 ",
-            time: dayjs().format('YYYY-MM-DD HH:mm:ss')
-          })
-          console.log(useStore.DocxList[itemIndex.value].actionList)
-          useStore.saveDocxList()
-          actionList.value = useStore.DocxList[itemIndex.value].actionList;
-
-          console.log(actionList.value)
+          console.log(output)
+          for (let item of useStore.taskList){
+            console.log(item.testCaseListId)
+            if(item.testCaseListId == itemIndex.value){
+              const improveList = parseOutput(output)
+              //更新用例列表
+              item.testCaseList = JSON.stringify(improveList)
+              console.log(item)
+              testCase.value = improveList
+              //更新操作记录
+              let lastActionList: Action[] =  JSON.parse(item.actionList)
+              const action = {description: "添加用例 ", times: dayjs().format('YYYY-MM-DD HH:mm:ss')}
+              lastActionList.push(action)
+              item.actionList = JSON.stringify(lastActionList)
+              actionList.value = JSON.parse(item.actionList)
+              //写进数据库
+              axios({
+                url: "http://localhost:8081/testCaseList/modify",               // 请求地址
+                method: "post",                       // 请求方法
+                headers: {                            // 请求头
+                  "Content-Type": "application/json",
+                },
+                data: {                             // 请求参数
+                  userId: item.userId,
+                  creatTime: item.creatTime,
+                  docxName: item.docxName,
+                  testCaseList: item.testCaseList,
+                  actionList: item.actionList,
+                  tcFinalList: item.tcFinalList
+                },
+              }).then((res) => {
+                if(res.data.msg !== "更新成功!"){
+                  ElMessage({
+                    message: '数据库出错',
+                    type: 'warning'
+                  });
+                }
+              })
+            }
+
+          }
+          useStore.saveTaskList()
           loadingAdd.close()
-          ElMessage({
-            message: '添加成功',
-            type: 'success'
-          })
-          textarea.value = ''
         })
         .catch((error: AxiosError<any>) => {
           console.log(error);
@@ -457,7 +530,7 @@ const addDocxList = () => {
           <div class="header-Box">
 
             <el-timeline>
-              <el-timeline-item v-for="(action, index) in actionList" :key="index" :timestamp="action.time"
+              <el-timeline-item v-for="(action, index) in actionList" :key="index" :timestamp="action.times"
                 size=large>
                 {{ action.description }}
               </el-timeline-item>

+ 9 - 26
src/components/Upload.vue

@@ -12,35 +12,17 @@
             </div>
           </el-form-item>
           <span>文件仅限txt格式<br/>这里应该还有点信息提示,暂时没想好写啥,或者配置</span>
-<!--          <el-button type="Primary" style="width:100%; color:#409eff; margin-top:1vw;" plain="true"-->
-<!--            @click="closeShowBox">确定-->
-<!--          </el-button>-->
+
         </el-form>
      </div>
-<!--    </transition>-->
+
     <el-container>
       <el-main>
         <span style="color:#020a13; font-size: x-large">新建生成测试用例任务</span>
         <span style="white-space: pre-wrap"><br/>请上传需求文档</span>
-<!--        <el-icon class="el-icon&#45;&#45;upload"><upload-filled /></el-icon>-->
-<!--        <div class="el-upload__text">-->
-<!--          <em>Click to upload</em>-->
-<!--          <br>-->
-<!--          txt files with a size less than 500kb-->
-<!--        </div>-->
-<!--        <template #tip>-->
-<!--          <div class="el-upload__tip">-->
-<!--            word files with a size less than 500kb-->
-<!--          </div>-->
-<!--        </template>-->
+
       </el-main>
-<!--      <el-footer>-->
-<!--        <el-button type="primary" @click="gotoTargetPage">下一步-->
-<!--          <el-icon class="el-icon&#45;&#45;right">-->
-<!--            <ArrowRight />-->
-<!--          </el-icon>-->
-<!--        </el-button>-->
-<!--      </el-footer>-->
+
     </el-container>
   </div>
 </template>
@@ -139,7 +121,7 @@ const dealfilechange = async (event: Event) => {
                 data: data2,
               };
 
-
+              const action = [{description: "生成用例",time: dayjs().format('YYYY-MM-DD HH:mm:ss')}]
               axios(processConfig)
                    .then((response) => {
                      console.log(response.data.output)
@@ -152,7 +134,7 @@ const dealfilechange = async (event: Event) => {
                      console.log(parsedOutput)
                      const testCaseArray = JSON.parse(parsedOutput);
                      console.log(testCaseArray)
-                     useStore.DocxList.push({docxName: file.name, docxMessageList: testCaseArray, time: dayjs().format('YYYY-MM-DD HH:mm:ss'), actionList: [{description: "生成用例",time: dayjs().format('YYYY-MM-DD HH:mm:ss')}], testCaseList: []})
+                     useStore.DocxList.push({docxName: file.name, docxMessageList: testCaseArray, time: dayjs().format('YYYY-MM-DD HH:mm:ss'), actionList: action, testCaseList: []})
                      //持久化存储
                      useStore.saveDocxList()
                      //添加进数据库
@@ -167,7 +149,7 @@ const dealfilechange = async (event: Event) => {
                          creatTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
                          docxName: file.name,
                          testCaseList: parsedOutput,
-                         actionList: "[{description: '生成用例',time: dayjs().format('YYYY-MM-DD HH:mm:ss')}]"
+                         actionList: JSON.stringify(action)
                        },
                      }).then((res) => {
                        if(res.data.msg !== "添加成功!"){
@@ -186,7 +168,8 @@ const dealfilechange = async (event: Event) => {
                              user_id: Number(useStore.userInfo.user_id)
                            },
                          }).then((res) => {
-                           sessionStorage.setItem("taskList", JSON.stringify(res.data.data));
+                           localStorage.setItem("taskList", JSON.stringify(res.data.data));
+
                          });
                        }
                      });

+ 1 - 1
src/pinia/docx.ts

@@ -43,7 +43,7 @@ export const useDocxStore = defineStore('docx',  {
             localStorage.setItem('docxList', JSON.stringify(this.DocxList));
         },
         async saveTaskList() {
-            localStorage.setItem('docxList', JSON.stringify(this.DocxList));
+            localStorage.setItem('taskList', JSON.stringify(this.taskList));
         },
 
     },