TCList.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. <script setup lang="ts">
  2. import { ref,onMounted} from "vue";
  3. import { useRouter } from 'vue-router';
  4. import { DocxList,Action,useDocxStore } from '../pinia/docx'
  5. import axios, {AxiosResponse, AxiosError, AxiosRequestConfig} from 'axios';
  6. import {ElLoading, ElMessage} from 'element-plus'
  7. import {TestCase,InputVariable} from './upload.vue'
  8. import * as echarts from 'echarts';
  9. import dayjs from 'dayjs'
  10. const useStore = useDocxStore()
  11. const token = 'sk-HcDTZ2PXVVKd7wkLBGhaf2S3YxZ5Jr7G7SBO974cZdQ='
  12. //关于路由
  13. const router = useRouter();
  14. const gotoLastPage = () => {
  15. router.push('/upload');
  16. };
  17. const gotoNextPage = () => {
  18. router.push('/tcFinalList');
  19. };
  20. onMounted(()=>{
  21. Showecharts()
  22. })
  23. const docxList = ref<DocxList[]>([])
  24. docxList.value = useStore.DocxList
  25. const itemIndex = ref(0)
  26. const textarea = ref('')
  27. //历史操作记录
  28. const actionList = ref<Action[]>([])
  29. console.log(useStore.DocxList[itemIndex.value])
  30. actionList.value = useStore.DocxList[itemIndex.value].actionList;
  31. console.log(actionList.value)
  32. useStore.DocxList[itemIndex.value].actionList.push({
  33. description: "测试",
  34. time: dayjs().format('YYYY-MM-DD HH:mm:ss')
  35. })
  36. console.log(useStore.DocxList[itemIndex.value].actionList)
  37. function parseOutput(output: string): any[] {
  38. const jsonIndex = output.indexOf("json")
  39. console.log(jsonIndex)
  40. const parsedOutput = output.substring(jsonIndex).replace(/json\\n/g, '').replace(/\\n/g, '').replace(/\\/g, '').replace(/ /g,'').replace(/```"/g,'');
  41. console.log(parsedOutput)
  42. const testCaseArray: TestCase[] = JSON.parse(parsedOutput) as TestCase[];
  43. console.log(testCaseArray)
  44. return testCaseArray;
  45. }
  46. const testCase = ref<any>([]);
  47. // 默认展示第一个列表
  48. testCase.value = useStore.DocxList[itemIndex.value].docxMessageList
  49. console.log(testCase.value)
  50. console.log(actionList.value)
  51. const docxMessage = (index: number) => {
  52. itemIndex.value = index
  53. testCase.value = useStore.DocxList[itemIndex.value].docxMessageList
  54. }
  55. //细化用例
  56. const handleImproveButton = (p: { row: any }) => {
  57. let improve_id = p.row.编号;
  58. console.log(improve_id)
  59. const loadingImprove = ElLoading.service({
  60. fullscreen: true,
  61. text: "细化用例 "+improve_id
  62. })
  63. //调接口
  64. const data: {
  65. inputVariables: InputVariable[];
  66. volumeName: string;
  67. } = {
  68. inputVariables: [
  69. {
  70. name: "testCaseId",
  71. value: improve_id,
  72. },
  73. {
  74. name: "conversationId",
  75. value: "7",
  76. },
  77. ],
  78. volumeName: "文字测试用例生成",
  79. };
  80. const config: AxiosRequestConfig = {
  81. method: 'post',
  82. url: 'http://47.120.7.208:8000/api/executions?versionId=13&isAsync=false',
  83. headers: {
  84. 'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
  85. 'Content-Type': 'application/json',
  86. 'Authorization': `Bearer ${token}`,
  87. },
  88. data: data,
  89. };
  90. axios(config)
  91. .then((response: AxiosResponse<any>) => {
  92. console.log(response.data.output);
  93. const output = JSON.stringify(JSON.parse(response.data.output))
  94. //更新用例列表
  95. useStore.DocxList[itemIndex.value].docxMessageList = parseOutput(output);
  96. testCase.value = useStore.DocxList[itemIndex.value].docxMessageList;
  97. //更新操作记录
  98. console.log(actionList.value)
  99. useStore.DocxList[itemIndex.value].actionList.push({
  100. description: "细化用例 "+improve_id,
  101. time: dayjs().format('YYYY-MM-DD HH:mm:ss')
  102. })
  103. console.log(useStore.DocxList[itemIndex.value].actionList)
  104. actionList.value = useStore.DocxList[itemIndex.value].actionList;
  105. console.log(actionList.value)
  106. loadingImprove.close()
  107. })
  108. .catch((error: AxiosError<any>) => {
  109. console.log(error);
  110. });
  111. };
  112. // 删除用例
  113. const deteleList = (scope: { row: any }) => {
  114. const delete_id = scope.row.编号;
  115. console.log(delete_id)
  116. const loadingDelete = ElLoading.service({
  117. fullscreen: true,
  118. text: "删除用例 "+delete_id
  119. })
  120. const data: {
  121. inputVariables: InputVariable[];
  122. volumeName: string;
  123. } = {
  124. inputVariables: [
  125. {
  126. name: "testCaseId",
  127. value: delete_id,
  128. },
  129. {
  130. name: "conversationId",
  131. value: "7",
  132. },
  133. ],
  134. volumeName: "文字测试用例生成",
  135. };
  136. const deleteConfig: AxiosRequestConfig = {
  137. method: 'post',
  138. url: 'http://47.120.7.208:8000/api/executions?versionId=14&isAsync=false',
  139. headers: {
  140. 'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
  141. 'Content-Type': 'application/json',
  142. 'Authorization': `Bearer ${token}`,
  143. },
  144. data: data,
  145. };
  146. axios(deleteConfig)
  147. .then((response: AxiosResponse<any>) => {
  148. console.log(response.data.output);
  149. const output = JSON.stringify(JSON.parse(response.data.output))
  150. //更新用例列表
  151. useStore.DocxList[itemIndex.value].docxMessageList = parseOutput(output);
  152. testCase.value = useStore.DocxList[itemIndex.value].docxMessageList;
  153. //更新操作记录
  154. useStore.DocxList[itemIndex.value].actionList.push({
  155. description: "删除用例 "+delete_id,
  156. time: dayjs().format('YYYY-MM-DD HH:mm:ss')
  157. })
  158. console.log(useStore.DocxList[itemIndex.value].actionList)
  159. actionList.value = useStore.DocxList[itemIndex.value].actionList;
  160. console.log(actionList.value)
  161. loadingDelete.close()
  162. })
  163. .catch((error: AxiosError<any>) => {
  164. console.log(error);
  165. });
  166. }
  167. //添加用例
  168. const addDocxList = () => {
  169. if (textarea.value !== '') {
  170. const loadingAdd = ElLoading.service({
  171. fullscreen: true,
  172. text: "增加内容生成用例中"
  173. })
  174. //调用接口
  175. const data: {
  176. inputVariables: InputVariable[];
  177. volumeName: string;
  178. } = {
  179. inputVariables: [
  180. {
  181. name: "testCaseToAdd",
  182. value: textarea.value,
  183. },
  184. {
  185. name: "conversationId",
  186. value: "7",
  187. },
  188. ],
  189. volumeName: "文字测试用例生成",
  190. };
  191. const addConfig: AxiosRequestConfig = {
  192. method: 'post',
  193. url: 'http://47.120.7.208:8000/api/executions?versionId=15&isAsync=false',
  194. headers: {
  195. 'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
  196. 'Content-Type': 'application/json',
  197. 'Authorization': `Bearer ${token}`,
  198. },
  199. data: data,
  200. };
  201. axios(addConfig)
  202. .then((response: AxiosResponse<any>) => {
  203. console.log(JSON.stringify(response.data));
  204. const output = JSON.stringify(JSON.parse(response.data.output))
  205. //更新用例列表
  206. useStore.DocxList[itemIndex.value].docxMessageList = parseOutput(output);
  207. testCase.value = useStore.DocxList[itemIndex.value].docxMessageList
  208. //更新操作记录
  209. useStore.DocxList[itemIndex.value].actionList.push({
  210. description: "添加用例 ",
  211. time: dayjs().format('YYYY-MM-DD HH:mm:ss')
  212. })
  213. console.log(useStore.DocxList[itemIndex.value].actionList)
  214. actionList.value = useStore.DocxList[itemIndex.value].actionList;
  215. console.log(actionList.value)
  216. loadingAdd.close()
  217. ElMessage({
  218. message: '添加成功',
  219. type: 'success'
  220. })
  221. textarea.value = ''
  222. })
  223. .catch((error: AxiosError<any>) => {
  224. console.log(error);
  225. });
  226. } else {
  227. ElMessage({
  228. message: '用例描述不能为空',
  229. type: 'error'
  230. })
  231. }
  232. }
  233. // echarts-bxo
  234. function Showecharts() {
  235. var chartDom = document.getElementById('pt');
  236. var myChart = echarts.init(chartDom);
  237. var option;
  238. option = {
  239. tooltip: {
  240. trigger: 'item'
  241. },
  242. legend: {
  243. top: '5%',
  244. left: 'center',
  245. textStyle:{
  246. fontSize:8
  247. }
  248. },
  249. series: [
  250. {
  251. name: 'Access From',
  252. type: 'pie',
  253. radius: ['40%', '70%'],
  254. avoidLabelOverlap: false,
  255. padAngle: 5,
  256. itemStyle: {
  257. borderRadius: 10
  258. },
  259. label: {
  260. show: false,
  261. position: 'center',
  262. fontSize:12
  263. },
  264. emphasis: {
  265. label: {
  266. show: true,
  267. fontSize: 40,
  268. fontWeight:700
  269. }
  270. },
  271. labelLine: {
  272. show: false
  273. },
  274. data: [
  275. { value:useStore.DocxList.length, name: '.docx文件'},
  276. {value:5,name:'.excel文件'},
  277. {value:6,name:'.ppd文件'}
  278. ]
  279. }
  280. ]
  281. };
  282. option && myChart.setOption(option);
  283. }
  284. </script>
  285. <template>
  286. <el-container>
  287. <el-aside width="200px" style="overflow: hidden; margin-right:20px;">
  288. <el-card style="width:100%; border:0;" body-style="padding:0; margin:0;">
  289. <template #header>
  290. <div class="card-header">
  291. <span>文件名</span>
  292. </div>
  293. </template>
  294. <div class="card-item" v-for="(item, index) in docxList" :key="index" @click="docxMessage(index)"
  295. :class="{ active: index == itemIndex }">
  296. {{ item.docxName }}
  297. </div>
  298. </el-card>
  299. </el-aside>
  300. <el-container>
  301. <el-main style="display:flex; overflow: hidden; margin:0; padding:0;">
  302. <div class="root">
  303. <el-card class="card">
  304. <el-scrollbar class="scrollbar">
  305. <el-row class="titleTagRow">
  306. <el-tag class="titleTag" type="primary" effect="light" size="large" round>当前用例列表</el-tag>
  307. </el-row>
  308. <el-col class="container">
  309. <el-table :data="testCase" style="width: 100%" border>
  310. <el-table-column label="编号" prop="编号" width="100" />
  311. <el-table-column label="用例标题" prop="用例标题" min-width="50" />
  312. <el-table-column show-overflow-tooltip label="简短描述" prop="描述" min-width="150" />
  313. <el-table-column width="60">
  314. <template #default="scope">
  315. <el-button type="primary" link size="small" @click="handleImproveButton(scope)">细化</el-button>
  316. </template>
  317. </el-table-column>
  318. <el-table-column width="60">
  319. <template #default="scope">
  320. <el-button type="primary" link size="small" @click="deteleList(scope)">删除</el-button>
  321. </template>
  322. </el-table-column>
  323. </el-table>
  324. </el-col>
  325. </el-scrollbar>
  326. <div class="Pop-upBox">
  327. </div>
  328. <el-row class="input-row">
  329. <div style="min-width: 400px; width: 100%;">
  330. <el-input v-model="textarea" style="min-width: 400px; width: 100%;" :rows="4" type="textarea"
  331. placeholder="请输入要补充的待测功能" />
  332. <div>
  333. <el-button type="primary" class="add-button" style="margin-top:2vw;"
  334. @click="addDocxList">增加</el-button>
  335. </div>
  336. </div>
  337. </el-row>
  338. </el-card>
  339. </div>
  340. <div class="timeline">
  341. <div class="header-Box">
  342. <span>操作记录</span>
  343. <el-timeline>
  344. <el-timeline-item v-for="(action, index) in actionList" :key="index" :timestamp="action.time"
  345. size=large>
  346. {{ action.description }}
  347. </el-timeline-item>
  348. </el-timeline>
  349. </div>
  350. <div class="charts-box">
  351. <div id="pt" style="width:100%; height:100%;"></div>
  352. </div>
  353. </div>
  354. </el-main>
  355. <el-footer>
  356. <div class="button-container">
  357. <el-button type="primary" class="custom-button" @click="gotoLastPage">上一步</el-button>
  358. <el-button type="primary" class="custom-button" @click="gotoNextPage">下一步</el-button>
  359. </div>
  360. </el-footer>
  361. </el-container>
  362. </el-container>
  363. </template>
  364. <style scoped>
  365. .button-container {
  366. margin-top: 2vw;
  367. display: flex;
  368. position: absolute;
  369. left: 50%;
  370. transform: translate(-50%);
  371. /* 让按钮之间的空间均匀分布 */
  372. }
  373. .custom-button {
  374. width: 100px;
  375. /* 设置按钮的宽度为相同的固定值 */
  376. }
  377. .input-row {
  378. padding: 1em 3em;
  379. display: flex;
  380. flex-wrap: nowrap;
  381. align-items: center;
  382. justify-content: center;
  383. }
  384. .add-button {
  385. margin: auto 2em;
  386. }
  387. .titleTag {
  388. height: 2em;
  389. width: 8em;
  390. margin-left: 3em;
  391. font-size: large;
  392. }
  393. .container {
  394. width: 60vw;
  395. padding: 1em 3em;
  396. }
  397. .rowContainer {
  398. display: flex;
  399. justify-content: center;
  400. margin: 1em 0;
  401. }
  402. .root {
  403. display: flex;
  404. justify-content: center;
  405. }
  406. .robotMessage {
  407. display: flex;
  408. flex-direction: row-reverse;
  409. align-items: flex-start;
  410. }
  411. .customerMessage {
  412. display: flex;
  413. flex-direction: row;
  414. align-items: flex-start;
  415. }
  416. .textArea {
  417. display: inline-block;
  418. width: 300px;
  419. }
  420. .card {
  421. margin: auto;
  422. }
  423. .scrollbar {
  424. height: 400px;
  425. width: fit-content;
  426. }
  427. .card-item {
  428. margin: 0;
  429. padding: 0;
  430. width: 100%;
  431. height: 10vh;
  432. line-height: 10vh;
  433. text-align: center;
  434. background-color: #fcfcfc;
  435. cursor: pointer;
  436. }
  437. .Pop-upBox {
  438. z-index: 999;
  439. position: absolute;
  440. }
  441. .active {
  442. background-color: #409eff;
  443. color: #fff;
  444. }
  445. .timeline {
  446. width: 30vw;
  447. height: 100vh;
  448. padding-top: 2%;
  449. }
  450. .header-Box {
  451. width: 100%;
  452. height: 45vh;
  453. overflow: hidden;
  454. overflow-y: auto;
  455. }
  456. .charts-box {
  457. width: 100%;
  458. height: 50vh;
  459. background-color:#fff;
  460. }
  461. /* 启用滚动条样式化,需要在浏览器设置中启用 */
  462. ::-webkit-scrollbar {
  463. width: 10px; /* 滚动条的宽度 */
  464. }
  465. /* 滚动条轨道 */
  466. ::-webkit-scrollbar-track {
  467. background: #f0f0f0; /* 滚动条轨道背景颜色 */
  468. }
  469. /* 滚动条滑块 */
  470. ::-webkit-scrollbar-thumb {
  471. background: #696969; /* 滚动条滑块颜色 */
  472. border-radius: 10px; /* 滑块边角弧度 */
  473. }
  474. /* 滑块悬停状态 */
  475. ::-webkit-scrollbar-thumb:hover {
  476. background: #555; /* 鼠标悬停在滑块上时的颜色 */
  477. }
  478. </style>