瀏覽代碼

add.api连接,接口数据解析完成,可以展示用例表格

chen xueyi 2 年之前
父節點
當前提交
aa3ad0a070
共有 7 個文件被更改,包括 167 次插入40 次删除
  1. 71 0
      package-lock.json
  2. 1 0
      package.json
  3. 1 1
      src/components/TCFinalList.vue
  4. 17 14
      src/components/TCList.vue
  5. 66 21
      src/components/Upload.vue
  6. 5 3
      src/pinia/docx.ts
  7. 6 1
      tsconfig.json

+ 71 - 0
package-lock.json

@@ -23,6 +23,7 @@
       "devDependencies": {
         "@types/node": "^20.12.6",
         "@vitejs/plugin-vue": "^5.0.4",
+        "chai": "^5.1.0",
         "typescript": "^5.2.2",
         "unplugin-auto-import": "^0.17.5",
         "unplugin-vue-components": "^0.26.0",
@@ -1023,6 +1024,15 @@
         "sprintf-js": "~1.0.2"
       }
     },
+    "node_modules/assertion-error": {
+      "version": "2.0.1",
+      "resolved": "https://registry.npmmirror.com/assertion-error/-/assertion-error-2.0.1.tgz",
+      "integrity": "sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==",
+      "dev": true,
+      "engines": {
+        "node": ">=12"
+      }
+    },
     "node_modules/async-validator": {
       "version": "4.2.5",
       "resolved": "https://registry.npmjs.org/async-validator/-/async-validator-4.2.5.tgz",
@@ -1101,6 +1111,31 @@
         "node": ">=0.8"
       }
     },
+    "node_modules/chai": {
+      "version": "5.1.0",
+      "resolved": "https://registry.npmmirror.com/chai/-/chai-5.1.0.tgz",
+      "integrity": "sha512-kDZ7MZyM6Q1DhR9jy7dalKohXQ2yrlXkk59CR52aRKxJrobmlBNqnFQxX9xOX8w+4mz8SYlKJa/7D7ddltFXCw==",
+      "dev": true,
+      "dependencies": {
+        "assertion-error": "^2.0.1",
+        "check-error": "^2.0.0",
+        "deep-eql": "^5.0.1",
+        "loupe": "^3.1.0",
+        "pathval": "^2.0.0"
+      },
+      "engines": {
+        "node": ">=12"
+      }
+    },
+    "node_modules/check-error": {
+      "version": "2.0.0",
+      "resolved": "https://registry.npmmirror.com/check-error/-/check-error-2.0.0.tgz",
+      "integrity": "sha512-tjLAOBHKVxtPoHe/SA7kNOMvhCRdCJ3vETdeY0RuAc9popf+hyaSV6ZEg9hr4cpWF7jmo/JSWEnLDrnijS9Tog==",
+      "dev": true,
+      "engines": {
+        "node": ">= 16"
+      }
+    },
     "node_modules/chokidar": {
       "version": "3.6.0",
       "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz",
@@ -1199,6 +1234,15 @@
         }
       }
     },
+    "node_modules/deep-eql": {
+      "version": "5.0.1",
+      "resolved": "https://registry.npmmirror.com/deep-eql/-/deep-eql-5.0.1.tgz",
+      "integrity": "sha512-nwQCf6ne2gez3o1MxWifqkciwt0zhl0LO1/UwVu4uMBuPmflWM4oQ70XMqHqnBJA+nhzncaqL9HVL6KkHJ28lw==",
+      "dev": true,
+      "engines": {
+        "node": ">=6"
+      }
+    },
     "node_modules/delayed-stream": {
       "version": "1.0.0",
       "resolved": "https://registry.npmmirror.com/delayed-stream/-/delayed-stream-1.0.0.tgz",
@@ -1419,6 +1463,15 @@
         "url": "https://github.com/sponsors/ljharb"
       }
     },
+    "node_modules/get-func-name": {
+      "version": "2.0.2",
+      "resolved": "https://registry.npmmirror.com/get-func-name/-/get-func-name-2.0.2.tgz",
+      "integrity": "sha512-8vXOvuE167CtIc3OyItco7N/dpRtBbYOsPsXCz7X/PMnlGjYjSGuZJgM1Y7mmew7BKf9BqvLX2tnOVy1BBUsxQ==",
+      "dev": true,
+      "engines": {
+        "node": "*"
+      }
+    },
     "node_modules/glob-parent": {
       "version": "5.1.2",
       "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz",
@@ -1592,6 +1645,15 @@
         "underscore": "^1.13.1"
       }
     },
+    "node_modules/loupe": {
+      "version": "3.1.0",
+      "resolved": "https://registry.npmmirror.com/loupe/-/loupe-3.1.0.tgz",
+      "integrity": "sha512-qKl+FrLXUhFuHUoDJG7f8P8gEMHq9NFS0c6ghXG1J0rldmZFQZoNVv/vyirE9qwCIhWZDsvEFd1sbFu3GvRQFg==",
+      "dev": true,
+      "dependencies": {
+        "get-func-name": "^2.0.1"
+      }
+    },
     "node_modules/lru-cache": {
       "version": "6.0.0",
       "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
@@ -1790,6 +1852,15 @@
       "integrity": "sha512-whLdWMYL2TwI08hn8/ZqAbrVemu0LNaNNJZX73O6qaIdCTfXutsLhMkjdENX0qhsQ9uIimo4/aQOmXkoon2nDQ==",
       "dev": true
     },
+    "node_modules/pathval": {
+      "version": "2.0.0",
+      "resolved": "https://registry.npmmirror.com/pathval/-/pathval-2.0.0.tgz",
+      "integrity": "sha512-vE7JKRyES09KiunauX7nd2Q9/L7lhok4smP9RZTDeD4MVs72Dp2qNFVz39Nz5a0FVEW0BJR6C0DYrq6unoziZA==",
+      "dev": true,
+      "engines": {
+        "node": ">= 14.16"
+      }
+    },
     "node_modules/picocolors": {
       "version": "1.0.0",
       "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz",

+ 1 - 0
package.json

@@ -24,6 +24,7 @@
   "devDependencies": {
     "@types/node": "^20.12.6",
     "@vitejs/plugin-vue": "^5.0.4",
+    "chai": "^5.1.0",
     "typescript": "^5.2.2",
     "unplugin-auto-import": "^0.17.5",
     "unplugin-vue-components": "^0.26.0",

+ 1 - 1
src/components/TCFinalList.vue

@@ -21,7 +21,7 @@ import {ref} from "vue";
 import axios, {AxiosResponse, AxiosError, AxiosRequestConfig} from 'axios';
 
 const useStore = useDocxStore()
-const token = 'sk-rZoIsfohUX3K0TbSV+GXetuk7T4OwG3d8LyHFYxsutg='
+const token = 'sk-HcDTZ2PXVVKd7wkLBGhaf2S3YxZ5Jr7G7SBO974cZdQ='
 type docxList = {
   docxName: String,
   docxMessageList?: Array<object>

+ 17 - 14
src/components/TCList.vue

@@ -6,10 +6,21 @@ import axios, {AxiosResponse, AxiosError, AxiosRequestConfig} from 'axios';
 import { ElMessage } from 'element-plus'
 import * as echarts from 'echarts';
 const useStore = useDocxStore()
-const token = 'sk-rZoIsfohUX3K0TbSV+GXetuk7T4OwG3d8LyHFYxsutg='
+const token = 'sk-HcDTZ2PXVVKd7wkLBGhaf2S3YxZ5Jr7G7SBO974cZdQ='
+
+//关于路由
+const router = useRouter();
+const gotoLastPage = () => {
+  router.push('/upload');
+};
+const gotoNextPage = () => {
+  router.push('/tcFinalList');
+};
+
 
 onMounted(()=>{
   Showecharts()
+
 })
 
 
@@ -29,7 +40,7 @@ type ActionList = {
    description: string;
  };
 
-let actionList = ref<ActionList[]>([]);
+const actionList = ref<ActionList[]>([]);
 actionList.value = [
     {
       docxName: "文件名",
@@ -47,15 +58,7 @@ interface InputVariable {
 const testCase = ref<any>([]);
 // 默认展示第一个列表
 testCase.value = useStore.DocxList[itemIndex.value].docxMessageList
-
-//关于路由
-const router = useRouter();
-const gotoLastPage = () => {
-  router.push('/upload');
-};
-const gotoNextPage = () => {
-  router.push('/tcFinalList');
-};
+console.log(testCase)
 
 const docxMessage = (index: number) => {
   itemIndex.value = index
@@ -313,9 +316,9 @@ function Showecharts() {
               </el-row>
               <el-col class="container">
                 <el-table :data="testCase" style="width: 100%" border>
-                  <el-table-column label="编号" type="index" width="60" />
-                  <el-table-column label="用例标题" prop="title" min-width="200" />
-                  <el-table-column show-overflow-tooltip label="用例描述" prop="description" min-width="150" />
+                  <el-table-column label="编号" prop="编号" width="80" />
+                  <el-table-column label="用例标题" prop="用例标题" min-width="200" />
+                  <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>

+ 66 - 21
src/components/Upload.vue

@@ -7,8 +7,9 @@
 
           <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=".docx" multiple />
+                style="display:none;" accept=".txt" multiple />
             </div>
           </el-form-item>
           <el-button type="Primary" style="width:100%; color:#409eff; margin-top:1vw;" plain="true"
@@ -49,38 +50,43 @@ import { useRouter } from 'vue-router';
 import { ref } from 'vue'
 import { useDocxStore } from '../pinia/docx'
 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 fullscreenLoading = ref(false)
 const useStore = useDocxStore()
 // const parsedContent = ref('')
 const router = useRouter()
 const uploadInput = ref<HTMLDivElement | null>(null);
+
 const showBox = ref(false)
-const token = 'sk-rZoIsfohUX3K0TbSV+GXetuk7T4OwG3d8LyHFYxsutg='
-// const form = reactive({
-//   title: '',
-//   message: ''
-// })
+const token = 'sk-HcDTZ2PXVVKd7wkLBGhaf2S3YxZ5Jr7G7SBO974cZdQ='
+
 
 interface InputVariable {
   name: string;
   value: string;
 }
 
+
+
 const dealfilechange = async (event: Event) => {
   const target = event.target as HTMLInputElement;
   const files = target.files;
   if (files && files.length > 0) {
     for (let i = 0; i < files.length; i++) {
       const file = files[i];
-      // 检查文件扩展名是否以 .docx 结尾
+      // 检查文件扩展名是否以 .txt 结尾
       const fileExtension = file.name.toLowerCase().split('.').pop();
-      if (fileExtension === 'docx') {
-        console.log(file.name);
-        useStore.DocxList.unshift({ docxName: file.name, docxMessageList: [], time: dayjs().format('YYYY-MM-DD HH:mm:ss') })
+      if (fileExtension === 'txt') {
+        console.log(file);
+
         //调用上传接口
         const data = new FormData()
+
         data.append('file',file)
 
         const uploadConfig: AxiosRequestConfig = {
@@ -101,6 +107,7 @@ const dealfilechange = async (event: Event) => {
               console.log(JSON.stringify(uploadResponse.data));
 
               // 上传文件成功,现在可以调用处理接口
+              const loadingInstance1 = ElLoading.service({ fullscreen: true })
               const data2: {
                 inputVariables: InputVariable[];
                 volumeName: string;
@@ -129,28 +136,41 @@ const dealfilechange = async (event: Event) => {
                 data: data2,
               };
 
+
               axios(processConfig)
-                  .then((response) => {
-                    console.log(JSON.stringify(response.data));
-                    //Todo:更新用例列表
-                  })
-                  .catch((error) => {
-                    console.log(error);
-                  });
-              //向docxMessageList中添加同理列表
+                   .then((response) => {
+                     console.log(response.data.output.type)
+                     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: '测试用例已生成,请点击确定跳转',
+                       type: 'success'
+                     });
+
+                   })
+                   .catch((error) => {
+                     console.log(error);
+                   });
+
+             })
         ElMessage({
-          message: '上传文件成功',
+          message: '上传文件成功,正在为您生成测试用例',
           type: 'success'
         });
 
 
       } else {
         ElMessage({
-          message: '请上传.docx文件',
+          message: '请上传.txt文件',
           type: 'warning'
         })
       }
@@ -175,6 +195,7 @@ const gotoTargetPage = () => {
 };
 
 function closeShowBox() {
+
   showBox.value = false
 }
 
@@ -182,6 +203,30 @@ function uploadDocx() {
   uploadInput.value.click()
 }
 
+//解析后端传回的测试用例数据
+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;
+}
+
 </script>
 
 

+ 5 - 3
src/pinia/docx.ts

@@ -2,12 +2,14 @@ import { defineStore } from "pinia"
 import { ref } from 'vue'
 import dayjs from 'dayjs'
 import { ElMessage } from 'element-plus'
+
 interface DocxList {
-    docxName: String,
-    time?:String,
-    docxMessageList?: Array<object>
+    docxName: String
+    docxMessageList?: Array<object>,
+    time?:String
 }
 
+
 interface obj {
     id: Number,
     index: Number

+ 6 - 1
tsconfig.json

@@ -20,6 +20,11 @@
     "noUnusedParameters": true,
     "noFallthroughCasesInSwitch": true
   },
-  "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"],
+  "include": [
+    "src/**/*.ts",
+    "src/**/*.tsx",
+    "src/**/*.vue",
+    "node_modules/unplugin-auto-import/auto-imports.d.ts"
+  ],
   "references": [{ "path": "./tsconfig.node.json" }]
 }