Просмотр исходного кода

add.接口返回数据偶尔格式不一致

chen xueyi 2 лет назад
Родитель
Сommit
83c0838fde
7 измененных файлов с 107 добавлено и 114 удалено
  1. 9 0
      package-lock.json
  2. 1 0
      package.json
  3. 51 37
      src/components/TCFinalList.vue
  4. 5 10
      src/components/TCList.vue
  5. 11 32
      src/components/Upload.vue
  6. 4 2
      src/main.ts
  7. 26 33
      src/pinia/docx.ts

+ 9 - 0
package-lock.json

@@ -16,6 +16,7 @@
         "form-data": "^4.0.0",
         "mammoth": "^1.7.1",
         "pinia": "^2.1.7",
+        "pinia-plugin-persistedstate": "^3.2.1",
         "vue": "^3.4.19",
         "vue-router": "^4.3.0",
         "xlsx": "^0.18.5"
@@ -1900,6 +1901,14 @@
         }
       }
     },
+    "node_modules/pinia-plugin-persistedstate": {
+      "version": "3.2.1",
+      "resolved": "https://registry.npmmirror.com/pinia-plugin-persistedstate/-/pinia-plugin-persistedstate-3.2.1.tgz",
+      "integrity": "sha512-MK++8LRUsGF7r45PjBFES82ISnPzyO6IZx3CH5vyPseFLZCk1g2kgx6l/nW8pEBKxxd4do0P6bJw+mUSZIEZUQ==",
+      "peerDependencies": {
+        "pinia": "^2.0.0"
+      }
+    },
     "node_modules/pinia/node_modules/vue-demi": {
       "version": "0.14.7",
       "resolved": "https://registry.npmmirror.com/vue-demi/-/vue-demi-0.14.7.tgz",

+ 1 - 0
package.json

@@ -17,6 +17,7 @@
     "form-data": "^4.0.0",
     "mammoth": "^1.7.1",
     "pinia": "^2.1.7",
+    "pinia-plugin-persistedstate": "^3.2.1",
     "vue": "^3.4.19",
     "vue-router": "^4.3.0",
     "xlsx": "^0.18.5"

Разница между файлами не показана из-за своего большого размера
+ 51 - 37
src/components/TCFinalList.vue


Разница между файлами не показана из-за своего большого размера
+ 5 - 10
src/components/TCList.vue


+ 11 - 32
src/components/Upload.vue

@@ -71,7 +71,7 @@ export interface InputVariable {
 export interface TestCase {
   编号: string;
   用例标题: string;
-  简短描述: string;
+  描述: string;
 };
 
 
@@ -88,7 +88,6 @@ const dealfilechange = async (event: Event) => {
         //调用上传接口
         const data = new FormData()
         data.append('file',file)
-
         const uploadConfig: AxiosRequestConfig = {
           method: 'put',
           url: 'http://47.120.7.208:8000/api/volumes/2/files?path=.',
@@ -105,11 +104,10 @@ const dealfilechange = async (event: Event) => {
               let file_id = uploadResponse.data.id;
               console.log(file_id);
               console.log(JSON.stringify(uploadResponse.data));
-
               // 上传文件成功,现在可以调用处理接口
               const loadingInstance1 = ElLoading.service({
                 fullscreen: true,
-                text: file.name + " 处理中"
+                text: file.name + " 生成测试用例中"
               })
               const data2: {
                 inputVariables: InputVariable[];
@@ -144,14 +142,18 @@ const dealfilechange = async (event: Event) => {
                    .then((response) => {
                      console.log(response.data.output)
                      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,'');
+                     const leftIndex = output.indexOf("[")
+                     const rightIndex = output.indexOf("]")
+
+                     const parsedOutput = output.substring(leftIndex,rightIndex+1).replace(/\\n/g, '').replace(/\\/g, '').replace(/ /g,'')
 
                      console.log(parsedOutput)
-                     const testCaseArray: TestCase[] = JSON.parse(parsedOutput) as TestCase[];
+                     //const testCaseArray: TestCase[] = JSON.parse(parsedOutput) as TestCase[];
+                     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')}] })
+                     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.saveDocxList()
                      loadingInstance1.close()
                      ElMessage({
                        message: '测试用例已生成,请点击确定跳转',
@@ -205,29 +207,6 @@ 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>
 
 

+ 4 - 2
src/main.ts

@@ -5,11 +5,13 @@ import ElementPlus from 'element-plus'
 import 'element-plus/dist/index.css'
 import router from './router'
 import { createPinia } from 'pinia'
+import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
 const pinia = createPinia()
 const app = createApp(App)
-app.use(pinia)
+
+pinia.use(piniaPluginPersistedstate);//pinia数据持久化
 app.use(router)
 app.use(ElementPlus)
-app.mount('#app')
+app.use(pinia).mount('#app')
 
 

+ 26 - 33
src/pinia/docx.ts

@@ -7,50 +7,43 @@ import { ElMessage } from 'element-plus'
 export interface Action {
     description: String,
     times?: String
-
+}
+type testCase = {
+    编号: String,
+    用例标题?: String,
+    前置条件?: String,
+    步骤描述?: String,
+    预期结果?: String
 }
 export interface DocxList {
     docxName: String,
     docxMessageList?: Array<object>,
     time?:String,
     actionList?: Action[],
+    testCaseList?: testCase[]
 }
 
-
 interface obj {
     id: Number,
     index: Number
 }
-export const useDocxStore = defineStore('docx', () => {
-    const DocxList = ref<DocxList[]>([])
-    // DocxList.value = [{
-    //     docxName: "Example Document",
-    //     docxMessageList: [],
-    //     time: "2023-04-01T10:00:00",
-    //     actionList: [{
-    //         description: "生成用例"
-    //
-    //     }]
-    // }]
+export const useDocxStore = defineStore('docx',  {
+
+    state: () => {
+        let DocxList = ref<DocxList[]>([])
+        const storedDocxList = localStorage.getItem('docxList');
+        if (storedDocxList) {
+            DocxList = JSON.parse(storedDocxList);
+        }
+        return { DocxList };
+    },
+    persist: true,
+    actions: {
+
+        async saveDocxList() {
+            localStorage.setItem('docxList', JSON.stringify(this.DocxList));
+        },
+    },
 
-    const DeteleDocxList = (obj: obj) => {
-        // 删除列表
-        DocxList.value[obj.index].docxMessageList= DocxList.value[obj.index].docxMessageList.filter(item => {
-            return item.id !== obj.id
-        })
-       ElMessage({
-        type:'success',
-        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 }
-})
+});

Некоторые файлы не были показаны из-за большого количества измененных файлов