|
|
@@ -14,6 +14,8 @@
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
import * as XLSX from 'xlsx'
|
|
|
+
|
|
|
+import FileSaver from 'file-saver'
|
|
|
import { useRouter } from 'vue-router';
|
|
|
import { InputVariable } from './Upload.vue'
|
|
|
import {onMounted, ref} from "vue";
|
|
|
@@ -28,11 +30,7 @@ const docxList = ref<DocxList[]>([])
|
|
|
docxList.value = useStore.DocxList
|
|
|
const itemIndex = ref(0)
|
|
|
|
|
|
-interface Step {
|
|
|
- 步骤编号: String,
|
|
|
- 操作?: String,
|
|
|
- 预期结果?: String,
|
|
|
-}
|
|
|
+
|
|
|
// type testCase = {
|
|
|
// 编号: String,
|
|
|
// 用例标题?: String,
|
|
|
@@ -47,19 +45,19 @@ type testCase = {
|
|
|
预期结果?: String
|
|
|
}
|
|
|
const tableData = ref<any>([])
|
|
|
-
|
|
|
+//
|
|
|
//测试版
|
|
|
// const tableData = [{
|
|
|
// 编号: "001",
|
|
|
// 用例标题: "test",
|
|
|
// 前置条件: "String",
|
|
|
-// 步骤描述: "String",
|
|
|
-// 预期结果: "String"
|
|
|
+// 步骤描述: "在首页点击登录按钮",
|
|
|
+// 预期结果: "成功登录"
|
|
|
// },{
|
|
|
// 编号: "002",
|
|
|
// 用例标题: "test",
|
|
|
// 前置条件: "String",
|
|
|
-// 步骤描述: "String",
|
|
|
+// 步骤描述: "在首页点击登录按钮",
|
|
|
// 预期结果: "String"
|
|
|
// }]
|
|
|
const docxMessage = (index: number) => {
|
|
|
@@ -70,6 +68,12 @@ onMounted(() => {
|
|
|
parse()
|
|
|
|
|
|
});
|
|
|
+
|
|
|
+const router = useRouter();
|
|
|
+const gotoLastPage = () => {
|
|
|
+ router.push('/testcaseList');
|
|
|
+};
|
|
|
+
|
|
|
function parse() {
|
|
|
if(useStore.DocxList[itemIndex.value].testCaseList.length === 0){
|
|
|
const loading = ElLoading.service({
|
|
|
@@ -126,33 +130,55 @@ function parse() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+function descripRes(row: any) {
|
|
|
+ if(!Array.isArray(row.步骤描述)){
|
|
|
+ return row.步骤描述
|
|
|
+ }else{
|
|
|
+ let res = ''
|
|
|
+ for(const step of row.步骤描述){
|
|
|
+ res += (JSON.stringify(step).substring(1,JSON.stringify(step).indexOf(",")))
|
|
|
+ res += '\n'
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function predictRes(row: any) {
|
|
|
+
|
|
|
+ if(row.hasOwnProperty('预期结果')){
|
|
|
+ return row.预期结果
|
|
|
+ }else{
|
|
|
+ let res = ''
|
|
|
+ for(const step of row.步骤描述){
|
|
|
+ res += (JSON.stringify(step).substring(JSON.stringify(step).indexOf(",")+1,JSON.stringify(step).length-1))
|
|
|
+ res += '\n'
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ // 解析预期结果的方法
|
|
|
+
|
|
|
+}
|
|
|
|
|
|
-const router = useRouter();
|
|
|
-const gotoLastPage = () => {
|
|
|
- router.push('/testcaseList');
|
|
|
-};
|
|
|
|
|
|
const exportTestCase = async () => {
|
|
|
+ const indexOfDot = useStore.DocxList[itemIndex.value].docxName.indexOf(".")
|
|
|
+ const wb = XLSX.utils.table_to_book(document.querySelector('#tableData'));//关联dom节点
|
|
|
+ /* get binary string as output */
|
|
|
+ const wbout = XLSX.write(wb, {
|
|
|
+ bookType: 'xlsx',
|
|
|
+ bookSST: true,
|
|
|
+ type: 'array'
|
|
|
+ })
|
|
|
+ try {
|
|
|
+ FileSaver.saveAs(new Blob([wbout], {
|
|
|
+ type: 'application/octet-stream'
|
|
|
+ }), useStore.DocxList[itemIndex.value].docxName.substring(0,indexOfDot+1)+'xlsx')//自定义文件名
|
|
|
+ } catch (e) {
|
|
|
+ if (typeof console !== 'undefined') console.log(e, wbout);
|
|
|
+ }
|
|
|
+ return wbout
|
|
|
+
|
|
|
|
|
|
- // 导出 工作簿
|
|
|
- // 创建一个新的工作簿
|
|
|
- const wb = XLSX.utils.book_new();
|
|
|
- // 将表格数据转换为工作表
|
|
|
- const ws = XLSX.utils.json_to_sheet(tableData);
|
|
|
- // 将工作表添加到工作簿中
|
|
|
- XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
|
|
|
- // 将工作簿写入一个数组
|
|
|
- const wbout = XLSX.write(wb, { bookType: 'xlsx', type: 'array' });
|
|
|
- // 创建一个blob对象,用于下载
|
|
|
- const blob = new Blob([wbout], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8' });
|
|
|
-
|
|
|
- // 创建一个链接元素并模拟点击进行下载
|
|
|
- const link = document.createElement('a');
|
|
|
- link.href = URL.createObjectURL(blob);
|
|
|
- link.download = 'exported_data.xlsx';
|
|
|
- document.body.appendChild(link);
|
|
|
- link.click();
|
|
|
- document.body.removeChild(link);
|
|
|
}
|
|
|
</script>
|
|
|
|
|
|
@@ -176,22 +202,25 @@ const exportTestCase = async () => {
|
|
|
<el-container>
|
|
|
<el-main>
|
|
|
<el-card class="card">
|
|
|
- <el-table :data="tableData" border height="500" style="width: 100%">
|
|
|
- <el-table-column prop="编号" label="编号" width="120" />
|
|
|
- <el-table-column prop="用例标题" label="用例标题" width="120" />
|
|
|
- <el-table-column prop="前置条件" label="前置条件" width="300" />
|
|
|
- <el-table-column prop="步骤描述" label="步骤描述" width="300" />
|
|
|
- <el-table-column prop="预期结果" label="预期结果" width="300" />
|
|
|
-
|
|
|
-<!-- <el-table-column label="步骤描述">-->
|
|
|
+ <el-table :data="tableData" border height="500" style="width: 100%" id="tableData" >
|
|
|
+ <el-table-column prop="编号" label="编号" width="120" ></el-table-column>
|
|
|
+ <el-table-column prop="用例标题" label="用例标题" width="120"></el-table-column>
|
|
|
+ <el-table-column prop="前置条件" label="前置条件" width="120"></el-table-column>
|
|
|
+ <el-table-column show-overflow-tooltip prop="步骤描述" label="步骤描述" min-width="300" :formatter="descripRes" >
|
|
|
+<!-- <template #default="props">-->
|
|
|
+<!-- <div v-for="(step, index) in props.row.步骤描述" :key="index">-->
|
|
|
+<!-- <p>{{ JSON.stringify(step).substring(1,JSON.stringify(step).indexOf(","))}}</p>-->
|
|
|
+<!-- </div>-->
|
|
|
+<!-- </template>-->
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column show-overflow-tooltip prop="预期结果" label="预期结果" min-width="300" :formatter="predictRes" >
|
|
|
<!-- <template #default="props">-->
|
|
|
-<!-- <el-table :data="props.row.步骤描述">-->
|
|
|
-<!-- <el-table-column prop="步骤编号" label="步骤编号" />-->
|
|
|
-<!-- <el-table-column prop="操作" label="操作" />-->
|
|
|
-<!-- <el-table-column prop="预期结果" label="预期结果" />-->
|
|
|
-<!-- </el-table>-->
|
|
|
+<!-- <div v-for="(step, index) in props.row.步骤描述" :key="index">-->
|
|
|
+<!-- <p>{{ JSON.stringify(step).substring(JSON.stringify(step).indexOf(",")+1,JSON.stringify(step).length-1) }}</p>-->
|
|
|
+<!-- </div>-->
|
|
|
<!-- </template>-->
|
|
|
-<!-- </el-table-column>-->
|
|
|
+ </el-table-column>
|
|
|
+
|
|
|
|
|
|
</el-table>
|
|
|
</el-card>
|
|
|
@@ -210,11 +239,15 @@ const exportTestCase = async () => {
|
|
|
|
|
|
.card {
|
|
|
margin: 0;
|
|
|
-
|
|
|
width: 100%;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
|
+::v-deep .el-table .cell {
|
|
|
+ white-space: pre-line;
|
|
|
+}
|
|
|
+
|
|
|
.card-item {
|
|
|
margin: 0;
|
|
|
padding: 0;
|
|
|
@@ -224,6 +257,7 @@ const exportTestCase = async () => {
|
|
|
text-align: center;
|
|
|
background-color: #fcfcfc;
|
|
|
cursor: pointer;
|
|
|
+ white-space: pre-line;
|
|
|
}
|
|
|
|
|
|
|