|
|
@@ -4,16 +4,31 @@
|
|
|
<!-- <transition name="el-fade-in-linear">-->
|
|
|
<div class="PrupBox">
|
|
|
<el-form label-width="80px" style="max-width:350px; margin:0 auto; margin-top:5vw;">
|
|
|
-
|
|
|
<el-form-item label="上传文件:" style="white-space: pre-wrap; ">
|
|
|
<div class="boxjia" @click="uploadDocx">
|
|
|
- <input ref='uploadInput' type="file" class="dl-none" name="icon" @change="dealfilechange"
|
|
|
+ <input ref='uploadInput' type="file" class="dl-none" name="icon" @change="upload"
|
|
|
style="display:none;" accept=".txt" multiple />
|
|
|
</div>
|
|
|
</el-form-item>
|
|
|
<span>文件仅限txt格式<br/>这里应该还有点信息提示,暂时没想好写啥,或者配置</span>
|
|
|
-
|
|
|
</el-form>
|
|
|
+ <el-dialog v-model="dialogTableVisible" title="信息确认" width=100% height=100%>
|
|
|
+ <el-form ref="formRef" label-width="80px" style="height: 100%">
|
|
|
+ <el-form-item label="需求文档">
|
|
|
+ <el-input type="textarea" v-model="fileContent" ></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="提示词">
|
|
|
+ <el-input type="textarea" v-model="tip"></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ <template #footer>
|
|
|
+ <div class="dialog-footer">
|
|
|
+ <el-button type="primary" @click="dealFile">
|
|
|
+ 确认
|
|
|
+ </el-button>
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+ </el-dialog>
|
|
|
</div>
|
|
|
|
|
|
<el-container>
|
|
|
@@ -31,21 +46,26 @@
|
|
|
import dayjs from 'dayjs'
|
|
|
import { ArrowRight } from '@element-plus/icons-vue';
|
|
|
import { useRouter } from 'vue-router';
|
|
|
-import { ref } from 'vue'
|
|
|
+import {reactive, ref} from 'vue'
|
|
|
import { useDocxStore } from '../pinia/docx'
|
|
|
-import { ElMessage } from 'element-plus';
|
|
|
+import { ElMessage , ElMessageBox } from 'element-plus';
|
|
|
import { ElLoading } from 'element-plus'
|
|
|
import axios, {AxiosError, AxiosRequestConfig, AxiosResponse} from "axios";
|
|
|
import FormData from 'form-data';
|
|
|
|
|
|
+
|
|
|
const useStore = useDocxStore()
|
|
|
|
|
|
const router = useRouter()
|
|
|
const uploadInput = ref<HTMLDivElement | null>(null);
|
|
|
|
|
|
-const showBox = ref(false)
|
|
|
-const token = 'sk-HcDTZ2PXVVKd7wkLBGhaf2S3YxZ5Jr7G7SBO974cZdQ='
|
|
|
|
|
|
+const token = 'sk-HcDTZ2PXVVKd7wkLBGhaf2S3YxZ5Jr7G7SBO974cZdQ='
|
|
|
+const dialogTableVisible = ref(false)
|
|
|
+const formData = ref({
|
|
|
+ input1: '',
|
|
|
+ input2: '',
|
|
|
+});
|
|
|
|
|
|
export interface InputVariable {
|
|
|
name: string;
|
|
|
@@ -58,10 +78,164 @@ export interface TestCase {
|
|
|
描述: string;
|
|
|
};
|
|
|
|
|
|
+const fileContent = ref("")
|
|
|
+const tip = ref("你是一位经验丰富的测试用例编写人员,请识别该需求文档中可能包含的全部测试用例,给出测试用例列表(包含编号、用例标题和对应的简短描述),结果以json格式返回。")
|
|
|
+const upload = 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];
|
|
|
+ // 检查文件扩展名是否以 .txt 结尾
|
|
|
+ const fileExtension = file.name.toLowerCase().split('.').pop();
|
|
|
+ if (fileExtension === 'txt') {
|
|
|
+ console.log(file);
|
|
|
+ //调用上传接口
|
|
|
+ const data = new FormData()
|
|
|
+ data.append('file', file)
|
|
|
+ fileContent.value = (await file.text()).toString()
|
|
|
+ console.log(fileContent.value)
|
|
|
+
|
|
|
+ const uploadConfig: AxiosRequestConfig = {
|
|
|
+ method: 'put',
|
|
|
+ url: 'http://47.120.7.208:8000/api/volumes/2/files?path=.',
|
|
|
+ headers: {
|
|
|
+ 'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
|
|
+ ...data.getHeaders ? data.getHeaders() : {'Content-Type': 'multipart/form-data'},
|
|
|
+ 'Authorization': `Bearer ${token}`,
|
|
|
+ },
|
|
|
+ data: data,
|
|
|
+ };
|
|
|
|
|
|
+ axios(uploadConfig)
|
|
|
+ .then((uploadResponse: AxiosResponse<any>) => {
|
|
|
+ let file_id = uploadResponse.data.id;
|
|
|
+ console.log(file_id);
|
|
|
+ console.log(JSON.stringify(uploadResponse.data));
|
|
|
+ ElMessage({
|
|
|
+ message: '上传文件成功,请确认本次任务信息',
|
|
|
+ type: 'success'
|
|
|
+ });
|
|
|
+
|
|
|
+ dialogTableVisible.value = true
|
|
|
+ })
|
|
|
+ }else {
|
|
|
+ ElMessage({
|
|
|
+ message: '请上传.txt文件',
|
|
|
+ type: 'warning'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ ElMessage({
|
|
|
+ message: '你还没有选择文件',
|
|
|
+ type: 'error'
|
|
|
+ })
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function dealFile(){
|
|
|
+ dialogTableVisible.value = false;
|
|
|
+ const loadingInstance1 = ElLoading.service({
|
|
|
+ fullscreen: true,
|
|
|
+ text: "生成测试用例中"
|
|
|
+ })
|
|
|
+
|
|
|
+ // const data2: {
|
|
|
+ // inputVariables: InputVariable[];
|
|
|
+ // volumeName: string;
|
|
|
+ // } = {
|
|
|
+ // inputVariables: [
|
|
|
+ // {
|
|
|
+ // name: "filePath",
|
|
|
+ // value: file.name,
|
|
|
+ // },
|
|
|
+ // {
|
|
|
+ // name: "conversationId",
|
|
|
+ // value: "7",
|
|
|
+ // },
|
|
|
+ // ],
|
|
|
+ // volumeName: "文字测试用例生成",
|
|
|
+ // };
|
|
|
+ //
|
|
|
+ // const processConfig: axios.AxiosRequestConfig = {
|
|
|
+ // method: 'post',
|
|
|
+ // url: 'http://47.120.7.208:8000/api/executions?versionId=12&isAsync=false',
|
|
|
+ // headers: {
|
|
|
+ // 'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
|
|
+ // 'Content-Type': 'application/json',
|
|
|
+ // 'Authorization': `Bearer ${token}`,
|
|
|
+ // },
|
|
|
+ // data: data2,
|
|
|
+ // };
|
|
|
+ //
|
|
|
+ // const action = [{description: "生成用例",times: dayjs().format('YYYY-MM-DD HH:mm:ss')}]
|
|
|
+ // axios(processConfig)
|
|
|
+ // .then((response) => {
|
|
|
+ // console.log(response.data.output)
|
|
|
+ // const output = JSON.stringify(JSON.parse(response.data.output))
|
|
|
+ // 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 = JSON.parse(parsedOutput);
|
|
|
+ // console.log(testCaseArray)
|
|
|
+ // useStore.DocxList.push({docxName: file.name, docxMessageList: testCaseArray, time: dayjs().format('YYYY-MM-DD HH:mm:ss'), actionList: action, testCaseList: []})
|
|
|
+ // //持久化存储
|
|
|
+ // useStore.saveDocxList()
|
|
|
+ // //添加进数据库
|
|
|
+ // axios({
|
|
|
+ // url: "http://localhost:8081/testCaseList/add", // 请求地址
|
|
|
+ // method: "post", // 请求方法
|
|
|
+ // headers: { // 请求头
|
|
|
+ // "Content-Type": "application/json",
|
|
|
+ // },
|
|
|
+ // data: { // 请求参数
|
|
|
+ // userId: Number(useStore.userInfo.user_id),
|
|
|
+ // creatTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
|
|
+ // docxName: file.name,
|
|
|
+ // testCaseList: parsedOutput,
|
|
|
+ // actionList: JSON.stringify(action)
|
|
|
+ // },
|
|
|
+ // }).then((res) => {
|
|
|
+ // if(res.data.msg !== "添加成功!"){
|
|
|
+ // ElMessage({
|
|
|
+ // message: '数据库出错',
|
|
|
+ // type: 'warning'
|
|
|
+ // });
|
|
|
+ // }else{
|
|
|
+ // axios({
|
|
|
+ // url: "http://localhost:8081/testCaseList/testList", // 请求地址
|
|
|
+ // method: "post", // 请求方法
|
|
|
+ // headers: { // 请求头
|
|
|
+ // "Content-Type": "application/json",
|
|
|
+ // },
|
|
|
+ // params: { // 请求参数
|
|
|
+ // user_id: Number(useStore.userInfo.user_id)
|
|
|
+ // },
|
|
|
+ // }).then((res) => {
|
|
|
+ // localStorage.setItem("taskList", JSON.stringify(res.data.data));
|
|
|
+ //
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ loadingInstance1.close()
|
|
|
+ ElMessage({
|
|
|
+ message: '测试用例已生成,即将跳转',
|
|
|
+ type: 'success'
|
|
|
+ });
|
|
|
+ // })
|
|
|
+ // .catch((error) => {
|
|
|
+ // console.log(error);
|
|
|
+ // });
|
|
|
+}
|
|
|
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];
|
|
|
@@ -72,6 +246,10 @@ const dealfilechange = async (event: Event) => {
|
|
|
//调用上传接口
|
|
|
const data = new FormData()
|
|
|
data.append('file',file)
|
|
|
+ fileContent.value = (await file.text()).toString()
|
|
|
+ console.log(fileContent.value)
|
|
|
+
|
|
|
+ dialogTableVisible.value = true
|
|
|
const uploadConfig: AxiosRequestConfig = {
|
|
|
method: 'put',
|
|
|
url: 'http://47.120.7.208:8000/api/volumes/2/files?path=.',
|
|
|
@@ -89,102 +267,104 @@ const dealfilechange = async (event: Event) => {
|
|
|
console.log(file_id);
|
|
|
console.log(JSON.stringify(uploadResponse.data));
|
|
|
// 上传文件成功,现在可以调用处理接口
|
|
|
+
|
|
|
const loadingInstance1 = ElLoading.service({
|
|
|
fullscreen: true,
|
|
|
text: file.name + " 生成测试用例中"
|
|
|
})
|
|
|
- const data2: {
|
|
|
- inputVariables: InputVariable[];
|
|
|
- volumeName: string;
|
|
|
- } = {
|
|
|
- inputVariables: [
|
|
|
- {
|
|
|
- name: "filePath",
|
|
|
- value: file.name,
|
|
|
- },
|
|
|
- {
|
|
|
- name: "conversationId",
|
|
|
- value: "7",
|
|
|
- },
|
|
|
- ],
|
|
|
- volumeName: "文字测试用例生成",
|
|
|
- };
|
|
|
-
|
|
|
- const processConfig: axios.AxiosRequestConfig = {
|
|
|
- method: 'post',
|
|
|
- url: 'http://47.120.7.208:8000/api/executions?versionId=12&isAsync=false',
|
|
|
- headers: {
|
|
|
- 'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
|
|
- 'Content-Type': 'application/json',
|
|
|
- 'Authorization': `Bearer ${token}`,
|
|
|
- },
|
|
|
- data: data2,
|
|
|
- };
|
|
|
-
|
|
|
- const action = [{description: "生成用例",times: dayjs().format('YYYY-MM-DD HH:mm:ss')}]
|
|
|
- axios(processConfig)
|
|
|
- .then((response) => {
|
|
|
- console.log(response.data.output)
|
|
|
- const output = JSON.stringify(JSON.parse(response.data.output))
|
|
|
- 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 = JSON.parse(parsedOutput);
|
|
|
- console.log(testCaseArray)
|
|
|
- useStore.DocxList.push({docxName: file.name, docxMessageList: testCaseArray, time: dayjs().format('YYYY-MM-DD HH:mm:ss'), actionList: action, testCaseList: []})
|
|
|
- //持久化存储
|
|
|
- useStore.saveDocxList()
|
|
|
- //添加进数据库
|
|
|
- axios({
|
|
|
- url: "http://localhost:8081/testCaseList/add", // 请求地址
|
|
|
- method: "post", // 请求方法
|
|
|
- headers: { // 请求头
|
|
|
- "Content-Type": "application/json",
|
|
|
- },
|
|
|
- data: { // 请求参数
|
|
|
- userId: Number(useStore.userInfo.user_id),
|
|
|
- creatTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
|
|
- docxName: file.name,
|
|
|
- testCaseList: parsedOutput,
|
|
|
- actionList: JSON.stringify(action)
|
|
|
- },
|
|
|
- }).then((res) => {
|
|
|
- if(res.data.msg !== "添加成功!"){
|
|
|
- ElMessage({
|
|
|
- message: '数据库出错',
|
|
|
- type: 'warning'
|
|
|
- });
|
|
|
- }else{
|
|
|
- axios({
|
|
|
- url: "http://localhost:8081/testCaseList/testList", // 请求地址
|
|
|
- method: "post", // 请求方法
|
|
|
- headers: { // 请求头
|
|
|
- "Content-Type": "application/json",
|
|
|
- },
|
|
|
- params: { // 请求参数
|
|
|
- user_id: Number(useStore.userInfo.user_id)
|
|
|
- },
|
|
|
- }).then((res) => {
|
|
|
- localStorage.setItem("taskList", JSON.stringify(res.data.data));
|
|
|
-
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
+
|
|
|
+ // const data2: {
|
|
|
+ // inputVariables: InputVariable[];
|
|
|
+ // volumeName: string;
|
|
|
+ // } = {
|
|
|
+ // inputVariables: [
|
|
|
+ // {
|
|
|
+ // name: "filePath",
|
|
|
+ // value: file.name,
|
|
|
+ // },
|
|
|
+ // {
|
|
|
+ // name: "conversationId",
|
|
|
+ // value: "7",
|
|
|
+ // },
|
|
|
+ // ],
|
|
|
+ // volumeName: "文字测试用例生成",
|
|
|
+ // };
|
|
|
+ //
|
|
|
+ // const processConfig: axios.AxiosRequestConfig = {
|
|
|
+ // method: 'post',
|
|
|
+ // url: 'http://47.120.7.208:8000/api/executions?versionId=12&isAsync=false',
|
|
|
+ // headers: {
|
|
|
+ // 'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
|
|
+ // 'Content-Type': 'application/json',
|
|
|
+ // 'Authorization': `Bearer ${token}`,
|
|
|
+ // },
|
|
|
+ // data: data2,
|
|
|
+ // };
|
|
|
+ //
|
|
|
+ // const action = [{description: "生成用例",times: dayjs().format('YYYY-MM-DD HH:mm:ss')}]
|
|
|
+ // axios(processConfig)
|
|
|
+ // .then((response) => {
|
|
|
+ // console.log(response.data.output)
|
|
|
+ // const output = JSON.stringify(JSON.parse(response.data.output))
|
|
|
+ // 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 = JSON.parse(parsedOutput);
|
|
|
+ // console.log(testCaseArray)
|
|
|
+ // useStore.DocxList.push({docxName: file.name, docxMessageList: testCaseArray, time: dayjs().format('YYYY-MM-DD HH:mm:ss'), actionList: action, testCaseList: []})
|
|
|
+ // //持久化存储
|
|
|
+ // useStore.saveDocxList()
|
|
|
+ // //添加进数据库
|
|
|
+ // axios({
|
|
|
+ // url: "http://localhost:8081/testCaseList/add", // 请求地址
|
|
|
+ // method: "post", // 请求方法
|
|
|
+ // headers: { // 请求头
|
|
|
+ // "Content-Type": "application/json",
|
|
|
+ // },
|
|
|
+ // data: { // 请求参数
|
|
|
+ // userId: Number(useStore.userInfo.user_id),
|
|
|
+ // creatTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
|
|
+ // docxName: file.name,
|
|
|
+ // testCaseList: parsedOutput,
|
|
|
+ // actionList: JSON.stringify(action)
|
|
|
+ // },
|
|
|
+ // }).then((res) => {
|
|
|
+ // if(res.data.msg !== "添加成功!"){
|
|
|
+ // ElMessage({
|
|
|
+ // message: '数据库出错',
|
|
|
+ // type: 'warning'
|
|
|
+ // });
|
|
|
+ // }else{
|
|
|
+ // axios({
|
|
|
+ // url: "http://localhost:8081/testCaseList/testList", // 请求地址
|
|
|
+ // method: "post", // 请求方法
|
|
|
+ // headers: { // 请求头
|
|
|
+ // "Content-Type": "application/json",
|
|
|
+ // },
|
|
|
+ // params: { // 请求参数
|
|
|
+ // user_id: Number(useStore.userInfo.user_id)
|
|
|
+ // },
|
|
|
+ // }).then((res) => {
|
|
|
+ // localStorage.setItem("taskList", JSON.stringify(res.data.data));
|
|
|
+ //
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+ // });
|
|
|
loadingInstance1.close()
|
|
|
ElMessage({
|
|
|
message: '测试用例已生成,即将跳转',
|
|
|
type: 'success'
|
|
|
});
|
|
|
|
|
|
- })
|
|
|
- .catch((error) => {
|
|
|
- console.log(error);
|
|
|
- });
|
|
|
+ // })
|
|
|
+ // .catch((error) => {
|
|
|
+ // console.log(error);
|
|
|
+ // });
|
|
|
|
|
|
- })
|
|
|
+ })
|
|
|
ElMessage({
|
|
|
message: '上传文件成功,正在为您生成测试用例',
|
|
|
type: 'success'
|
|
|
@@ -225,8 +405,8 @@ function uploadDocx() {
|
|
|
top: 50%;
|
|
|
left: 50%;
|
|
|
transform: translate(-50%, -50%);
|
|
|
- width: 50vw;
|
|
|
- height: 50vh;
|
|
|
+ width: 70%;
|
|
|
+ height: 70%;
|
|
|
background-color: #fff;
|
|
|
border-radius: 10px;
|
|
|
border: 1px solid #efefef;
|
|
|
@@ -240,4 +420,6 @@ function uploadDocx() {
|
|
|
background-size: 50%;
|
|
|
border: 1px solid #efefef;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
</style>
|