Browse Source

add.连接口的第三天,504了

chen xueyi 2 years ago
parent
commit
d7a64dc520
4 changed files with 133 additions and 82 deletions
  1. 50 13
      src/components/TCFinalList.vue
  2. 73 58
      src/components/TCList.vue
  3. 3 9
      src/components/Upload.vue
  4. 7 2
      src/pinia/docx.ts

+ 50 - 13
src/components/TCFinalList.vue

@@ -1,5 +1,4 @@
 
-
 <style scoped>
 .button-container {
   display: flex;
@@ -17,23 +16,31 @@
 import * as XLSX from 'xlsx'
 import { useRouter } from 'vue-router';
 import { useDocxStore } from '../pinia/docx'
-import {ref} from "vue";
+import {onMounted, ref} from "vue";
 import axios, {AxiosResponse, AxiosError, AxiosRequestConfig} from 'axios';
 
-const useStore = useDocxStore()
+
 const token = 'sk-HcDTZ2PXVVKd7wkLBGhaf2S3YxZ5Jr7G7SBO974cZdQ='
-type docxList = {
-  docxName: String,
-  docxMessageList?: Array<object>
-}
 const itemIndex = ref(0)
-const docxList = ref<docxList[]>([])
-docxList.value = useStore.DocxList
-let tableData
+type testCase = {
+     编号: String,
+     用例标题: String,
+     前置条件: String,
+     步骤描述: String,
+     预期结果: String,
+}
+
+let tableData: testCase[] = []
 //生成完整测试用例
 const docxMessage = (index: number) => {
   itemIndex.value = index
+}
+
+onMounted(() => {
+  parse()
 
+});
+function parse() {
   interface InputVariable {
     name: string;
     value: string;
@@ -65,10 +72,10 @@ const docxMessage = (index: number) => {
 
   axios(fullConfig)
       .then((response: AxiosResponse<any>) => {
-        console.log(JSON.stringify(response.data));
-
+        console.log(JSON.stringify(response.data.output));
+        const parsedOutput = JSON.stringify(JSON.parse(response.data.output)).replace(/"```json\\n/g, '').replace(/\\n/g, '').replace(/\\/g, '').replace(/ /g,'');
         //Todo:更新table
-        tableData = JSON.stringify(response.data)
+        tableData = parseTestCases(parsedOutput);
       })
       .catch((error: AxiosError<any>) => {
         console.log(error);
@@ -77,6 +84,36 @@ const docxMessage = (index: number) => {
 
 }
 
+//解析后端传回的测试用例数据
+function parseTestCases(testCaseString: string): any[] {
+  const regex = /\{"编号":"([^"]*)","用例标题":"([^"]*)","前置条件":"([^"]*)","步骤描述":"([^"]*)","预期结果":"([^"]*)"\}/g;
+  let match;
+
+  // 使用正则表达式循环查找匹配项
+  while ((match = regex.exec(testCaseString)) !== null) {
+
+    // 提取编号、用例标题和简短描述
+    const number = match[1];
+    const title = match[2];
+    const front = match[3];
+    const description = match[4];
+    const result = match[5];
+
+    // 创建一个对象来保存用例信息,并添加到数组中
+    tableData.push({
+      编号: number,
+      用例标题: title,
+      前置条件: front,
+      步骤描述:description,
+      预期结果:result
+    });
+  }
+
+
+  return tableData;
+}
+
+
 // const tableData = [
 //   {
 //     编号: '2016',

+ 73 - 58
src/components/TCList.vue

@@ -3,8 +3,9 @@ import { ref,onMounted} from "vue";
 import { useRouter } from 'vue-router';
 import { useDocxStore } from '../pinia/docx'
 import axios, {AxiosResponse, AxiosError, AxiosRequestConfig} from 'axios';
-import { ElMessage } from 'element-plus'
+import {ElLoading, ElMessage} from 'element-plus'
 import * as echarts from 'echarts';
+import dayjs from 'dayjs'
 const useStore = useDocxStore()
 const token = 'sk-HcDTZ2PXVVKd7wkLBGhaf2S3YxZ5Jr7G7SBO974cZdQ='
 
@@ -24,6 +25,9 @@ onMounted(()=>{
 })
 
 
+type Action = {
+  description: String,
+}
 type docxList = {
   docxName: String,
   docxMessageList?: Array<object>
@@ -35,26 +39,37 @@ const textarea = ref('')
 
 
 //历史操作记录
-type ActionList = {
-   docxName: String;
-   description: string;
- };
-
-const actionList = ref<ActionList[]>([]);
-actionList.value = [
-    {
-      docxName: "文件名",
-      description: "操作记录",
-
-}
-];
-
+const actionList = ref<any>([]);
+actionList.value = useStore.DocxList[itemIndex.value].actionList
 
 interface InputVariable {
   name: string;
   value: string;
 }
 
+function parseTestCases(testCaseString: string): any[] {
+  const testCases: any[] = [];
+  const regex = /\{"编号":"([^"]*)","用例标题":"([^"]*)","简短描述":"([^"]*)"\}/g;
+  let match;
+
+  // 使用正则表达式循环查找匹配项
+  while ((match = regex.exec(testCaseString)) !== null) {
+    // 提取编号、用例标题和简短描述
+    const number = match[1];
+    const title = match[2];
+    const description = match[3];
+
+    // 创建一个对象来保存用例信息,并添加到数组中
+    testCases.push({
+      编号: number,
+      用例标题: title,
+      简短描述: description
+    });
+  }
+
+  return testCases;
+}
+
 const testCase = ref<any>([]);
 // 默认展示第一个列表
 testCase.value = useStore.DocxList[itemIndex.value].docxMessageList
@@ -68,10 +83,9 @@ const docxMessage = (index: number) => {
 //细化用例
 const handleImproveButton = (p: { row: any }) => {
   console.log(p.row);
-  let improve_id = p.row.id;
+  let improve_id = p.row.id+1;
 
   //调接口
-
   const data: {
     inputVariables: InputVariable[];
     volumeName: string;
@@ -102,27 +116,26 @@ const handleImproveButton = (p: { row: any }) => {
 
   axios(config)
       .then((response: AxiosResponse<any>) => {
-        console.log(JSON.stringify(response.data));
+        console.log(response.data.output);
+        const output = response.data.output;
+        const parsedOutput = JSON.stringify(JSON.parse(output)).replace(/"```json\\n/g, '').replace(/\\n/g, '').replace(/\\/g, '').replace(/ /g,'');
+        //更新用例列表
+        useStore.DocxList[itemIndex.value].docxMessageList = parseTestCases(parsedOutput);
+        //更新操作记录
+        useStore.DocxList[itemIndex.value].actionList.push({
+          description: "细化用例"+improve_id
+        });
       })
       .catch((error: AxiosError<any>) => {
         console.log(error);
       });
-  //Todo:更新用例列表
-
-  //更新操作记录
-  actionList.value.push({
-    docxName: useStore.DocxList[itemIndex.value].docxName,
-    description: "细化用例"+improve_id,
-  })
 };
 
 // 删除用例
-const deteleList = (scope: any) => {
-  const obj: any = {
-    id: scope.row.id,
-    index: itemIndex.value
-  }
-  let delete_id = scope.row.id;
+const deteleList = (scope: { row: any }) => {
+
+  const delete_id = scope.row.id+1;
+  console.log(delete_id)
   const data: {
     inputVariables: InputVariable[];
     volumeName: string;
@@ -153,25 +166,27 @@ const deteleList = (scope: any) => {
 
   axios(deleteConfig)
       .then((response: AxiosResponse<any>) => {
-        console.log(JSON.stringify(response.data));
+        console.log(response.data.output);
+        const output = response.data.output;
+        const parsedOutput = JSON.stringify(JSON.parse(output)).replace(/"```json\\n/g, '').replace(/\\n/g, '').replace(/\\/g, '').replace(/ /g,'');
+
+        //更新用例列表
+        useStore.DocxList[itemIndex.value].docxMessageList = parseTestCases(parsedOutput);
+        //更新操作记录
+        useStore.DocxList[itemIndex.value].actionList.push({
+          description: "删除用例"+delete_id
+        });
       })
       .catch((error: AxiosError<any>) => {
         console.log(error);
       });
-  //Todo:更新用例列表
-  useStore.DeteleDocxList(obj)
-  //更新操作列表
-  actionList.value.push({
-    docxName: useStore.DocxList[itemIndex.value].docxName,
-    description: "删除用例"+delete_id,
-
-  })
-  testCase.value = useStore.DocxList[itemIndex.value].docxMessageList
+
 }
 
 //添加用例
 const addDocxList = () => {
   if (textarea.value !== '') {
+    const loadingInstance1 = ElLoading.service({ fullscreen: true })
     //调用接口
     const data: {
       inputVariables: InputVariable[];
@@ -204,27 +219,27 @@ const addDocxList = () => {
     axios(addConfig)
         .then((response: AxiosResponse<any>) => {
           console.log(JSON.stringify(response.data));
+          const output = response.data.output;
+          const parsedOutput = JSON.stringify(JSON.parse(output)).replace(/"```json\\n/g, '').replace(/\\n/g, '').replace(/\\/g, '').replace(/ /g,'');
+          //更新用例列表
+          useStore.DocxList[itemIndex.value].docxMessageList = parseTestCases(parsedOutput);
+          //更新操作记录
+
+          useStore.DocxList[itemIndex.value].actionList.push({
+            description: "添加用例"
+          });
+          loadingInstance1.close()
+          ElMessage({
+            message: '添加成功',
+            type: 'success'
+          })
+          textarea.value = ''
         })
         .catch((error: AxiosError<any>) => {
           console.log(error);
         });
-    //Todo:更新用例列表
-    let new_id: any = useStore.DocxList[itemIndex.value].docxMessageList?.length+1
-    useStore.DocxList[itemIndex.value].docxMessageList?.push({
-      id: new_id,
-      description: textarea.value
-    })
-    //更新操作列表
-    actionList.value.push({
-      docxName: useStore.DocxList[itemIndex.value].docxName,
-      description: "新增用例"+new_id,
 
-    })
-    ElMessage({
-      message: '添加成功',
-      type: 'success'
-    })
-    textarea.value = ''
+
   } else {
     ElMessage({
       message: '用例描述不能为空',
@@ -352,7 +367,7 @@ function Showecharts() {
             <el-timeline>
               <el-timeline-item v-for="(activity, index) in actionList" :key="index" :timestamp="activity.time"
                 size=large>
-                {{ activity.docxName+"+"+activity.description }}
+                {{ activity.description }}
               </el-timeline-item>
             </el-timeline>
           </div>

+ 3 - 9
src/components/Upload.vue

@@ -56,9 +56,9 @@ import FormData from 'form-data';
 import * as fs from 'fs';
 import { assert } from 'chai';
 
-const fullscreenLoading = ref(false)
+
 const useStore = useDocxStore()
-// const parsedContent = ref('')
+
 const router = useRouter()
 const uploadInput = ref<HTMLDivElement | null>(null);
 
@@ -139,17 +139,11 @@ const dealfilechange = async (event: Event) => {
 
               axios(processConfig)
                    .then((response) => {
-                     console.log(response.data.output.type)
+                     console.log(response.data.output)
                      const output = response.data.output
                      const parsedOutput = JSON.stringify(JSON.parse(output)).replace(/"```json\\n/g, '').replace(/\\n/g, '').replace(/\\/g, '').replace(/ /g,'');
                      const testCaseList = parseTestCases(parsedOutput)
-
-
-                     //Todo:更新用例列表
                      useStore.DocxList.push({ docxName: file.name, docxMessageList: testCaseList, time: dayjs().format('YYYY-MM-DD HH:mm:ss') })
-
-                     const trial = ref(0)
-                     console.log(useStore.DocxList[trial.value].docxMessageList)
                      loadingInstance1.close()
                      ElMessage({
                        message: '测试用例已生成,请点击确定跳转',

+ 7 - 2
src/pinia/docx.ts

@@ -3,10 +3,15 @@ import { ref } from 'vue'
 import dayjs from 'dayjs'
 import { ElMessage } from 'element-plus'
 
+
+type Action = {
+    description: String,
+}
 interface DocxList {
-    docxName: String
+    docxName: String,
     docxMessageList?: Array<object>,
-    time?:String
+    time?:String,
+    actionList?: ref<Action[]>
 }