|
|
@@ -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>
|
|
|
|
|
|
|