Przeglądaj źródła

add.生成完整用例并导出表格格式方面有点问题,需要微调

chen xueyi 2 lat temu
rodzic
commit
4e18f5daf8
4 zmienionych plików z 141 dodań i 111 usunięć
  1. 22 15
      src/components/TCFinalList.vue
  2. 69 70
      src/components/TCList.vue
  3. 29 22
      src/components/Upload.vue
  4. 21 4
      src/pinia/docx.ts

Plik diff jest za duży
+ 22 - 15
src/components/TCFinalList.vue


+ 69 - 70
src/components/TCList.vue

@@ -1,9 +1,10 @@
 <script setup lang="ts">
 import { ref,onMounted} from "vue";
 import { useRouter } from 'vue-router';
-import { useDocxStore } from '../pinia/docx'
+import { DocxList,Action,useDocxStore } from '../pinia/docx'
 import axios, {AxiosResponse, AxiosError, AxiosRequestConfig} from 'axios';
 import {ElLoading, ElMessage} from 'element-plus'
+import {TestCase,InputVariable} from './upload.vue'
 import * as echarts from 'echarts';
 import dayjs from 'dayjs'
 const useStore = useDocxStore()
@@ -18,63 +19,42 @@ const gotoNextPage = () => {
   router.push('/tcFinalList');
 };
 
-
 onMounted(()=>{
   Showecharts()
-
 })
 
-
-type docxList = {
-  docxName: String,
-  docxMessageList?: Array<object>
-}
-const docxList = ref<docxList[]>([])
+const docxList = ref<DocxList[]>([])
 docxList.value = useStore.DocxList
 const itemIndex = ref(0)
 const textarea = ref('')
 
-
 //历史操作记录
-const actionList = ref<any>([]);
-
-// actionList.value = [{
-//   description: "操作记录"
-// }]
-
-interface InputVariable {
-  name: string;
-  value: string;
-}
+const actionList = ref<Action[]>([])
+console.log(useStore.DocxList[itemIndex.value])
+actionList.value = useStore.DocxList[itemIndex.value].actionList;
+console.log(actionList.value)
+useStore.DocxList[itemIndex.value].actionList.push({
+  description: "测试",
+  time: dayjs().format('YYYY-MM-DD HH:mm:ss')
+})
 
-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;
+console.log(useStore.DocxList[itemIndex.value].actionList)
+function parseOutput(output: string): any[] {
+  const jsonIndex = output.indexOf("json")
+  console.log(jsonIndex)
+  const parsedOutput = output.substring(jsonIndex).replace(/json\\n/g, '').replace(/\\n/g, '').replace(/\\/g, '').replace(/ /g,'').replace(/```"/g,'');
+  console.log(parsedOutput)
+  const testCaseArray: TestCase[] = JSON.parse(parsedOutput) as TestCase[];
+  console.log(testCaseArray)
+  return testCaseArray;
 }
 
 const testCase = ref<any>([]);
 // 默认展示第一个列表
 testCase.value = useStore.DocxList[itemIndex.value].docxMessageList
-console.log(testCase)
-
+console.log(testCase.value)
+console.log(actionList.value)
 const docxMessage = (index: number) => {
   itemIndex.value = index
   testCase.value = useStore.DocxList[itemIndex.value].docxMessageList
@@ -85,6 +65,10 @@ const handleImproveButton = (p: { row: any }) => {
 
   let improve_id = p.row.编号;
   console.log(improve_id)
+  const loadingImprove = ElLoading.service({
+    fullscreen: true,
+    text: "细化用例 "+improve_id
+  })
   //调接口
   const data: {
     inputVariables: InputVariable[];
@@ -117,15 +101,20 @@ const handleImproveButton = (p: { row: any }) => {
   axios(config)
       .then((response: AxiosResponse<any>) => {
         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 output = JSON.stringify(JSON.parse(response.data.output))
         //更新用例列表
-        useStore.DocxList[itemIndex.value].docxMessageList = parseTestCases(parsedOutput);
+        useStore.DocxList[itemIndex.value].docxMessageList = parseOutput(output);
         testCase.value = useStore.DocxList[itemIndex.value].docxMessageList;
         //更新操作记录
-        actionList.value.push({description: "细化用例"+improve_id});
-        useStore.DocxList[itemIndex.value].actionList = actionList;
-
+        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)
+        loadingImprove.close()
       })
       .catch((error: AxiosError<any>) => {
         console.log(error);
@@ -134,9 +123,12 @@ const handleImproveButton = (p: { row: any }) => {
 
 // 删除用例
 const deteleList = (scope: { row: any }) => {
-
   const delete_id = scope.row.编号;
   console.log(delete_id)
+  const loadingDelete = ElLoading.service({
+    fullscreen: true,
+    text: "删除用例 "+delete_id
+  })
   const data: {
     inputVariables: InputVariable[];
     volumeName: string;
@@ -168,15 +160,19 @@ const deteleList = (scope: { row: any }) => {
   axios(deleteConfig)
       .then((response: AxiosResponse<any>) => {
         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 output = JSON.stringify(JSON.parse(response.data.output))
         //更新用例列表
-        useStore.DocxList[itemIndex.value].docxMessageList = parseTestCases(parsedOutput);
+        useStore.DocxList[itemIndex.value].docxMessageList = parseOutput(output);
         testCase.value = useStore.DocxList[itemIndex.value].docxMessageList;
         //更新操作记录
-        actionList.value.push({description: "删除用例"+delete_id})
-        useStore.DocxList[itemIndex.value].actionList = actionList;
+        useStore.DocxList[itemIndex.value].actionList.push({
+          description: "删除用例 "+delete_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)
+        loadingDelete.close()
       })
       .catch((error: AxiosError<any>) => {
         console.log(error);
@@ -187,7 +183,10 @@ const deteleList = (scope: { row: any }) => {
 //添加用例
 const addDocxList = () => {
   if (textarea.value !== '') {
-    const loadingInstance1 = ElLoading.service({ fullscreen: true })
+    const loadingAdd = ElLoading.service({
+      fullscreen: true,
+      text: "增加内容生成用例中"
+    })
     //调用接口
     const data: {
       inputVariables: InputVariable[];
@@ -220,15 +219,20 @@ 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,'');
+          const output = JSON.stringify(JSON.parse(response.data.output))
+
           //更新用例列表
-          useStore.DocxList[itemIndex.value].docxMessageList = parseTestCases(parsedOutput);
+          useStore.DocxList[itemIndex.value].docxMessageList = parseOutput(output);
           testCase.value = useStore.DocxList[itemIndex.value].docxMessageList
           //更新操作记录
-          actionList.value.push({description: "添加用例"})
-          useStore.DocxList[itemIndex.value].actionList = actionList;
-          loadingInstance1.close()
+          useStore.DocxList[itemIndex.value].actionList.push({
+            description: "添加用例 ",
+            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)
+          loadingAdd.close()
           ElMessage({
             message: '添加成功',
             type: 'success'
@@ -238,8 +242,6 @@ const addDocxList = () => {
         .catch((error: AxiosError<any>) => {
           console.log(error);
         });
-
-
   } else {
     ElMessage({
       message: '用例描述不能为空',
@@ -247,7 +249,6 @@ const addDocxList = () => {
     })
   }
 }
-
 // echarts-bxo
 function Showecharts() {
   var chartDom = document.getElementById('pt');
@@ -298,9 +299,7 @@ function Showecharts() {
       }
     ]
   };
-
   option && myChart.setOption(option);
-
 }
 </script>
 
@@ -333,7 +332,7 @@ function Showecharts() {
                 <el-table :data="testCase" style="width: 100%" border>
                   <el-table-column label="编号"  prop="编号" width="100" />
                   <el-table-column label="用例标题" prop="用例标题" min-width="50" />
-                  <el-table-column show-overflow-tooltip label="简短描述" prop="简短描述" min-width="150" />
+                  <el-table-column show-overflow-tooltip label="简短描述" prop="描述" min-width="150" />
                   <el-table-column width="60">
                     <template #default="scope">
                       <el-button type="primary" link size="small" @click="handleImproveButton(scope)">细化</el-button>
@@ -366,9 +365,9 @@ function Showecharts() {
           <div class="header-Box">
             <span>操作记录</span>
             <el-timeline>
-              <el-timeline-item v-for="(activity, index) in actionList" :key="index" :timestamp="activity.time"
+              <el-timeline-item v-for="(action, index) in actionList" :key="index" :timestamp="action.time"
                 size=large>
-                {{ activity.description }}
+                {{ action.description }}
               </el-timeline-item>
             </el-timeline>
           </div>

+ 29 - 22
src/components/Upload.vue

@@ -7,7 +7,6 @@
 
           <el-form-item label="上传文件:">
             <div class="boxjia" @click="uploadDocx">
-
               <input ref='uploadInput' type="file" class="dl-none" name="icon" @change="dealfilechange"
                 style="display:none;" accept=".txt" multiple />
             </div>
@@ -23,13 +22,15 @@
         <span style="color:#409eff; cursor:pointer" @click="uploadFn">上传文件</span>
         <el-icon class="el-icon--upload"><upload-filled /></el-icon>
         <div class="el-upload__text">
-          Drop file here or <em>click to upload</em>
+          <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>
+<!--        <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">下一步
@@ -43,7 +44,6 @@
 </template>
 
 <script setup lang="ts">
-// import mammoth from "mammoth";
 import dayjs from 'dayjs'
 import { ArrowRight } from '@element-plus/icons-vue';
 import { useRouter } from 'vue-router';
@@ -53,9 +53,6 @@ import { ElMessage } from 'element-plus';
 import { ElLoading } from 'element-plus'
 import axios, {AxiosError, AxiosRequestConfig, AxiosResponse} from "axios";
 import FormData from 'form-data';
-import * as fs from 'fs';
-import { assert } from 'chai';
-
 
 const useStore = useDocxStore()
 
@@ -66,11 +63,16 @@ const showBox = ref(false)
 const token = 'sk-HcDTZ2PXVVKd7wkLBGhaf2S3YxZ5Jr7G7SBO974cZdQ='
 
 
-interface InputVariable {
+export interface InputVariable {
   name: string;
   value: string;
 }
 
+export interface TestCase {
+  编号: string;
+  用例标题: string;
+  简短描述: string;
+};
 
 
 const dealfilechange = async (event: Event) => {
@@ -83,10 +85,8 @@ const dealfilechange = async (event: Event) => {
       const fileExtension = file.name.toLowerCase().split('.').pop();
       if (fileExtension === 'txt') {
         console.log(file);
-
         //调用上传接口
         const data = new FormData()
-
         data.append('file',file)
 
         const uploadConfig: AxiosRequestConfig = {
@@ -107,7 +107,10 @@ const dealfilechange = async (event: Event) => {
               console.log(JSON.stringify(uploadResponse.data));
 
               // 上传文件成功,现在可以调用处理接口
-              const loadingInstance1 = ElLoading.service({ fullscreen: true })
+              const loadingInstance1 = ElLoading.service({
+                fullscreen: true,
+                text: file.name + " 处理中"
+              })
               const data2: {
                 inputVariables: InputVariable[];
                 volumeName: string;
@@ -140,10 +143,15 @@ const dealfilechange = async (event: Event) => {
               axios(processConfig)
                    .then((response) => {
                      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)
-                     useStore.DocxList.push({ docxName: file.name, docxMessageList: testCaseList, time: dayjs().format('YYYY-MM-DD HH:mm:ss') })
+                     const output = JSON.stringify(JSON.parse(response.data.output))
+                     const jsonIndex = output.indexOf("json")
+                     console.log(jsonIndex)
+                     const parsedOutput = output.substring(jsonIndex).replace(/json\\n/g, '').replace(/\\n/g, '').replace(/\\/g, '').replace(/ /g,'').replace(/```"/g,'');
+
+                     console.log(parsedOutput)
+                     const testCaseArray: TestCase[] = JSON.parse(parsedOutput) as TestCase[];
+                     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')}] })
                      loadingInstance1.close()
                      ElMessage({
                        message: '测试用例已生成,请点击确定跳转',
@@ -197,10 +205,10 @@ function uploadDocx() {
   uploadInput.value.click()
 }
 
-//解析后端传回的测试用例数据
+//解析后端传回的测试用例数据,已废弃
 function parseTestCases(testCaseString: string): any[] {
   const testCases: any[] = [];
-  const regex = /\{"编号":"([^"]*)","用例标题":"([^"]*)","简短描述":"([^"]*)"\}/g;
+  const regex = /\{"编号":"([^"]*)","用例标题":"([^"]*)","描述":"([^"]*)"\}/g;
   let match;
 
   // 使用正则表达式循环查找匹配项
@@ -220,7 +228,6 @@ function parseTestCases(testCaseString: string): any[] {
 
   return testCases;
 }
-
 </script>
 
 

+ 21 - 4
src/pinia/docx.ts

@@ -4,15 +4,16 @@ import dayjs from 'dayjs'
 import { ElMessage } from 'element-plus'
 
 
-type Action = {
+export interface Action {
     description: String,
+    times?: String
 
 }
-interface DocxList {
+export interface DocxList {
     docxName: String,
     docxMessageList?: Array<object>,
     time?:String,
-    actionList?: ref<Action[]>,
+    actionList?: Action[],
 }
 
 
@@ -22,7 +23,15 @@ interface obj {
 }
 export const useDocxStore = defineStore('docx', () => {
     const DocxList = ref<DocxList[]>([])
-
+    // DocxList.value = [{
+    //     docxName: "Example Document",
+    //     docxMessageList: [],
+    //     time: "2023-04-01T10:00:00",
+    //     actionList: [{
+    //         description: "生成用例"
+    //
+    //     }]
+    // }]
 
     const DeteleDocxList = (obj: obj) => {
         // 删除列表
@@ -34,6 +43,14 @@ export const useDocxStore = defineStore('docx', () => {
         message:'删除成功'
        })
     }
+    // const Act = (i: Number,descrip: String) => {
+    //     console.log(typeof DocxList.value[i].actionList)
+    //     DocxList.value[i].actionList.push({description: descrip,time: dayjs().format('YYYY-MM-DD HH:mm:ss')})
+    //     ElMessage({
+    //         type:'success',
+    //         message:'操作记录更新成功'
+    //     })
+    // }
 
     return { DocxList, DeteleDocxList }
 })

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików