Compare commits
3 Commits
8a47183662
...
3bf6f53367
| Author | SHA1 | Date | |
|---|---|---|---|
| 3bf6f53367 | |||
| 238f7bb4ad | |||
|
|
dca942bc8f |
@@ -82,6 +82,32 @@ export function deleteCase(projectId, caseId) {
|
||||
})
|
||||
}
|
||||
|
||||
/** 恢复状态为 0 的用例为正常(1),POST body: { caseIds: number[] } */
|
||||
export function restoreCases(caseIds) {
|
||||
const raw = Array.isArray(caseIds) ? caseIds : [caseIds]
|
||||
const caseIdsNorm = raw
|
||||
.map(id => Number(id))
|
||||
.filter(id => Number.isFinite(id) && id > 0)
|
||||
return request({
|
||||
url: '/case/restore',
|
||||
method: 'post',
|
||||
data: { caseIds: caseIdsNorm }
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据手工用例生成 UI / 接口自动化脚本(字段均为驼峰)。
|
||||
* 典型 body:projectId, caseId, automationType, prompt, caseKey, moduleName, productName,
|
||||
* projectName, steps, expectedResults
|
||||
*/
|
||||
export function generateCaseAutomation(data) {
|
||||
return request({
|
||||
url: '/case/generate-automation',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
export function createCaseSnapshot(projectId, caseId) {
|
||||
return request({
|
||||
url: '/case/snapshot/create',
|
||||
|
||||
107
src/api/documentApi.js
Normal file
107
src/api/documentApi.js
Normal file
@@ -0,0 +1,107 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
/** 文档列表 */
|
||||
export function getDocumentList(params) {
|
||||
return request({
|
||||
url: '/document/list',
|
||||
method: 'get',
|
||||
params
|
||||
})
|
||||
}
|
||||
|
||||
/** 文档详情 */
|
||||
export function getDocumentDetail(params) {
|
||||
return request({
|
||||
url: '/document/detail',
|
||||
method: 'get',
|
||||
params
|
||||
})
|
||||
}
|
||||
|
||||
/** 上传 PDF(multipart,单文件一次请求) */
|
||||
export function uploadDocumentPdf({ file, productId, projectId, createdBy }) {
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
formData.append('productId', productId)
|
||||
formData.append('projectId', projectId)
|
||||
if (createdBy != null && createdBy !== '') {
|
||||
formData.append('createdBy', createdBy)
|
||||
}
|
||||
return request({
|
||||
url: '/document/upload',
|
||||
method: 'post',
|
||||
data: formData
|
||||
})
|
||||
}
|
||||
|
||||
/** 创建文档 */
|
||||
export function createDocument(data) {
|
||||
return request({
|
||||
url: '/document/create',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
/** 更新文档 */
|
||||
export function updateDocument(data) {
|
||||
return request({
|
||||
url: '/document/update',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
/** 删除文档 */
|
||||
export function deleteDocument(data) {
|
||||
return request({
|
||||
url: '/document/delete',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
/** 刷新飞书文档 */
|
||||
export function refreshDocument(data) {
|
||||
return request({
|
||||
url: '/document/refresh',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
/** 生成测试用例(预览) */
|
||||
export function generateDocumentCases(data) {
|
||||
return request({
|
||||
url: '/document/generate-cases',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
/** 模块匹配 */
|
||||
export function matchDocumentModules(data) {
|
||||
return request({
|
||||
url: '/document/match-modules',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
/** 导入测试用例 */
|
||||
export function importDocumentCases(data) {
|
||||
return request({
|
||||
url: '/document/import-cases',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
/** 批量创建模块 */
|
||||
export function batchCreateDocumentModules(data) {
|
||||
return request({
|
||||
url: '/document/batch-create-modules',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
43
src/api/skillRuleApi.js
Normal file
43
src/api/skillRuleApi.js
Normal file
@@ -0,0 +1,43 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
/** Skill */
|
||||
export function getSkillList(params) {
|
||||
return request({ url: '/skill/list', method: 'get', params: params || {} })
|
||||
}
|
||||
|
||||
export function getSkillDetail(skillId) {
|
||||
return request({ url: '/skill/detail', method: 'get', params: { skillId } })
|
||||
}
|
||||
|
||||
export function createSkill(data) {
|
||||
return request({ url: '/skill/create', method: 'post', data })
|
||||
}
|
||||
|
||||
export function updateSkill(data) {
|
||||
return request({ url: '/skill/update', method: 'post', data })
|
||||
}
|
||||
|
||||
export function deleteSkill(skillId) {
|
||||
return request({ url: '/skill/delete', method: 'post', data: { skillId } })
|
||||
}
|
||||
|
||||
/** Business rule */
|
||||
export function getBusinessRuleList(params) {
|
||||
return request({ url: '/business-rule/list', method: 'get', params: params || {} })
|
||||
}
|
||||
|
||||
export function getBusinessRuleDetail(ruleId) {
|
||||
return request({ url: '/business-rule/detail', method: 'get', params: { ruleId } })
|
||||
}
|
||||
|
||||
export function createBusinessRule(data) {
|
||||
return request({ url: '/business-rule/create', method: 'post', data })
|
||||
}
|
||||
|
||||
export function updateBusinessRule(data) {
|
||||
return request({ url: '/business-rule/update', method: 'post', data })
|
||||
}
|
||||
|
||||
export function deleteBusinessRule(ruleId) {
|
||||
return request({ url: '/business-rule/delete', method: 'post', data: { ruleId } })
|
||||
}
|
||||
@@ -97,11 +97,12 @@ export default {
|
||||
const filteredMenus = this.filterMenus(this.userMenus)
|
||||
const menus = this.renameTestPlatformToCycle(filteredMenus)
|
||||
const sorted = this.sortMenusByProductOrder(menus)
|
||||
const hasHome = sorted.some(menu => menu.path === '/effekt' || menu.name === '首页')
|
||||
const withSkillMenu = this.injectBusinessSkillConfigMenu(sorted)
|
||||
const hasHome = withSkillMenu.some(menu => menu.path === '/effekt' || menu.name === '首页')
|
||||
if (hasHome) {
|
||||
return sorted
|
||||
return withSkillMenu
|
||||
}
|
||||
return [homeMenu, ...sorted]
|
||||
return [homeMenu, ...withSkillMenu]
|
||||
},
|
||||
displayName() {
|
||||
if (!this.currentUser) {
|
||||
@@ -129,6 +130,7 @@ export default {
|
||||
'/system/user': '/system/user',
|
||||
'/system/menu': '/system/menu',
|
||||
'/system/permission': '/system/permission',
|
||||
'/test-platform/skill-rules': '/test-platform/skill-rules',
|
||||
'/bug': '/bug/list',
|
||||
'/bug/list': '/bug/list',
|
||||
'/bug/detail': '/bug/detail',
|
||||
@@ -166,6 +168,7 @@ export default {
|
||||
'产品管理': 'el-icon-box',
|
||||
'项目管理': 'el-icon-s-management',
|
||||
'用例管理': 'el-icon-document',
|
||||
'业务技能配置': 'el-icon-collection',
|
||||
'测试计划': 'el-icon-date',
|
||||
'测试报告': 'el-icon-data-line',
|
||||
'测试工具': 'el-icon-s-tools',
|
||||
@@ -216,6 +219,59 @@ export default {
|
||||
return Object.assign({}, item, { name, children })
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 在「用例周期」分组下、「用例管理」上方插入「业务技能配置」(与后端菜单并存时去重)。
|
||||
*/
|
||||
injectBusinessSkillConfigMenu(menus) {
|
||||
const INJECT_PATH = '/test-platform/skill-rules'
|
||||
const INJECT_KEY = '__inject_business_skill__'
|
||||
const makeItem = () => ({
|
||||
name: '业务技能配置',
|
||||
path: INJECT_PATH,
|
||||
icon: 'el-icon-collection',
|
||||
menuId: INJECT_KEY,
|
||||
id: INJECT_KEY,
|
||||
visible: 1,
|
||||
status: 1,
|
||||
children: []
|
||||
})
|
||||
const hasInjected = list =>
|
||||
(list || []).some(c => c.path === INJECT_PATH || c.menuId === INJECT_KEY || c.id === INJECT_KEY)
|
||||
const mergeCycleChildren = children => {
|
||||
if (!children || !children.length) return children || []
|
||||
if (hasInjected(children)) {
|
||||
return children.map(c =>
|
||||
c.children && c.children.length
|
||||
? Object.assign({}, c, { children: this.injectBusinessSkillConfigMenu(c.children) })
|
||||
: c
|
||||
)
|
||||
}
|
||||
const next = children.map(c =>
|
||||
c.children && c.children.length
|
||||
? Object.assign({}, c, { children: this.injectBusinessSkillConfigMenu(c.children) })
|
||||
: c
|
||||
)
|
||||
const idx = next.findIndex(c => {
|
||||
const p = String(c.path || '')
|
||||
return p === '/test-platform/case' || c.name === '用例管理'
|
||||
})
|
||||
if (idx >= 0) {
|
||||
next.splice(idx, 0, makeItem())
|
||||
} else {
|
||||
next.unshift(makeItem())
|
||||
}
|
||||
return next
|
||||
}
|
||||
return (menus || []).map(item => {
|
||||
if (item.name === '用例周期' && item.children && item.children.length) {
|
||||
return Object.assign({}, item, { children: mergeCycleChildren(item.children.slice()) })
|
||||
}
|
||||
if (item.children && item.children.length) {
|
||||
return Object.assign({}, item, { children: this.injectBusinessSkillConfigMenu(item.children) })
|
||||
}
|
||||
return item
|
||||
})
|
||||
},
|
||||
/** 左侧栏顶级顺序:首页 → 用例周期 → Bug管理 → 造数 → 系统管理 → 其它 */
|
||||
representativeMenuPath(menu) {
|
||||
const direct = String((menu && menu.path) || '').trim()
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
<el-option v-for="item in moduleOptions" :key="item.id" :label="item.name" :value="item.id"></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="用例编号">
|
||||
<el-form-item v-if="form.id" label="用例编号">
|
||||
<el-input v-model="form.caseKey" placeholder="不填则由后端自动生成"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="标题" prop="title">
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
999
src/components/TestPlatform/Case/DocumentSourcePanel.vue
Normal file
999
src/components/TestPlatform/Case/DocumentSourcePanel.vue
Normal file
@@ -0,0 +1,999 @@
|
||||
<template>
|
||||
<div class="document-source-panel">
|
||||
<div v-if="!compact" class="document-source-main">
|
||||
<div class="document-source-head">
|
||||
<span class="document-source-title">文档源</span>
|
||||
<span class="document-source-hint">PRD / 飞书</span>
|
||||
</div>
|
||||
|
||||
<el-form :inline="true" size="mini" class="document-source-filters" @submit.native.prevent>
|
||||
<el-form-item label="类型">
|
||||
<el-select v-model="docQuery.type" clearable placeholder="全部" style="width: 88px;">
|
||||
<el-option label="PDF" :value="1"></el-option>
|
||||
<el-option label="飞书" :value="2"></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="状态">
|
||||
<el-select v-model="docQuery.status" clearable placeholder="全部" style="width: 100px;">
|
||||
<el-option label="待解析" :value="0"></el-option>
|
||||
<el-option label="已解析" :value="1"></el-option>
|
||||
<el-option label="已生成用例" :value="2"></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="关键词">
|
||||
<el-input
|
||||
v-model="docQuery.keyword"
|
||||
clearable
|
||||
placeholder="来源"
|
||||
style="width: 120px;"
|
||||
@keyup.enter.native="handleDocSearch">
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" :disabled="!projectId" @click="handleDocSearch">查询</el-button>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button size="mini" :disabled="!projectId" @click="openCreateDialog">新建</el-button>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button size="mini" :disabled="!projectId" @click="openBatchModuleDialog">批量建模块</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<el-table
|
||||
ref="docTable"
|
||||
v-loading="docLoading"
|
||||
:data="docTableData"
|
||||
border
|
||||
size="small"
|
||||
:height="tableHeight"
|
||||
highlight-current-row
|
||||
class="document-source-table"
|
||||
:empty-text="projectId ? '暂无文档' : '请先选择项目'"
|
||||
@row-click="handleDocRowClick">
|
||||
<el-table-column prop="id" label="ID" width="56"></el-table-column>
|
||||
<el-table-column label="类型" width="72">
|
||||
<template slot-scope="scope">
|
||||
<el-tag size="mini" :type="scope.row.type === 2 ? 'warning' : 'info'">{{ formatDocType(scope.row.type) }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="状态" width="88">
|
||||
<template slot-scope="scope">
|
||||
<el-tag size="mini" :type="docStatusTagType(scope.row.status)">{{ formatDocStatus(scope.row.status) }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="来源" min-width="100" show-overflow-tooltip>
|
||||
<template slot-scope="scope">{{ scope.row.source }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="updated_time" label="更新时间" width="136" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column label="操作" width="120" fixed="right">
|
||||
<template slot-scope="scope">
|
||||
<el-button type="text" size="mini" @click.stop="openDetail(scope.row)">详情</el-button>
|
||||
<el-dropdown trigger="click" @command="cmd => handleDocCommand(cmd, scope.row)">
|
||||
<el-button type="text" size="mini">更多</el-button>
|
||||
<el-dropdown-menu slot="dropdown">
|
||||
<el-dropdown-item v-if="scope.row.type === 2" command="refresh">刷新飞书</el-dropdown-item>
|
||||
<el-dropdown-item command="generate">生成用例</el-dropdown-item>
|
||||
<el-dropdown-item command="edit">编辑</el-dropdown-item>
|
||||
<el-dropdown-item command="delete" divided>删除</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</el-dropdown>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<div class="document-source-pagination">
|
||||
<el-pagination
|
||||
small
|
||||
layout="total, prev, pager, next"
|
||||
:current-page="docPageNo"
|
||||
:page-size="docPageSize"
|
||||
:total="docTotal"
|
||||
@current-change="handleDocPageChange">
|
||||
</el-pagination>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 详情 -->
|
||||
<el-drawer title="文档详情" :visible.sync="detailVisible" direction="rtl" size="480px" append-to-body>
|
||||
<div v-loading="detailLoading" class="document-detail-body">
|
||||
<template v-if="detailRecord">
|
||||
<el-descriptions :column="1" size="small" border>
|
||||
<el-descriptions-item label="ID">{{ detailRecord.id }}</el-descriptions-item>
|
||||
<el-descriptions-item label="类型">{{ formatDocType(detailRecord.type) }}</el-descriptions-item>
|
||||
<el-descriptions-item label="状态">{{ formatDocStatus(detailRecord.status) }}</el-descriptions-item>
|
||||
<el-descriptions-item label="来源">{{ detailRecord.source }}</el-descriptions-item>
|
||||
<el-descriptions-item label="版本">{{ detailRecord.version }}</el-descriptions-item>
|
||||
<el-descriptions-item label="AI 模型">{{ detailRecord.ai_model || '—' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="创建时间">{{ detailRecord.created_time }}</el-descriptions-item>
|
||||
<el-descriptions-item label="更新时间">{{ detailRecord.updated_time }}</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
<div class="document-detail-content-label">内容</div>
|
||||
<el-input v-model="detailContentDisplay" type="textarea" :rows="14" readonly></el-input>
|
||||
</template>
|
||||
</div>
|
||||
</el-drawer>
|
||||
|
||||
<!-- 新建 -->
|
||||
<el-dialog title="新建文档" :visible.sync="createVisible" width="560px" append-to-body @close="resetCreateForm">
|
||||
<el-form ref="createFormRef" :model="createForm" :rules="createRules" label-width="96px" size="small">
|
||||
<el-form-item label="类型" prop="type">
|
||||
<el-select v-model="createForm.type" style="width: 100%;" @change="onCreateTypeChange">
|
||||
<el-option label="PDF" :value="1"></el-option>
|
||||
<el-option label="飞书链接" :value="2"></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<template v-if="createForm.type === 1">
|
||||
<el-form-item label="PDF 上传">
|
||||
<div class="pdf-upload-row">
|
||||
<el-button size="small" type="primary" plain :disabled="!projectId" @click="triggerPdfMultiSelect">选择 PDF(可多选)</el-button>
|
||||
<span class="pdf-upload-hint">每个文件将单独请求上传接口</span>
|
||||
</div>
|
||||
<input
|
||||
ref="pdfMultiInput"
|
||||
type="file"
|
||||
class="hidden-pdf-input"
|
||||
multiple
|
||||
accept=".pdf,application/pdf"
|
||||
@change="onPdfMultiInputChange">
|
||||
<ul v-if="pdfPendingFiles.length" class="pdf-pending-list">
|
||||
<li v-for="(f, idx) in pdfPendingFiles" :key="idx + f.name + f.size" class="pdf-pending-item">
|
||||
<span class="pdf-pending-name">{{ f.name }}</span>
|
||||
<span class="pdf-pending-size">({{ formatFileSize(f.size) }})</span>
|
||||
<el-button type="text" size="mini" @click="removePdfPending(idx)">移除</el-button>
|
||||
</li>
|
||||
</ul>
|
||||
<p v-else class="pdf-upload-empty">未选择文件</p>
|
||||
</el-form-item>
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<el-form-item label="来源" prop="source">
|
||||
<el-input v-model="createForm.source" placeholder="飞书文档链接"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="内容">
|
||||
<el-input v-model="createForm.content" type="textarea" :rows="4" placeholder="可选"></el-input>
|
||||
</el-form-item>
|
||||
</template>
|
||||
</el-form>
|
||||
<span slot="footer">
|
||||
<el-button size="small" @click="createVisible = false">取消</el-button>
|
||||
<template v-if="createForm.type === 1">
|
||||
<el-button
|
||||
type="primary"
|
||||
size="small"
|
||||
:loading="pdfUploading"
|
||||
:disabled="!pdfPendingFiles.length || !projectId"
|
||||
@click="submitAllPdfUploads">
|
||||
上传全部
|
||||
</el-button>
|
||||
</template>
|
||||
<el-button v-else type="primary" size="small" :loading="createSubmitting" @click="submitCreate">确定</el-button>
|
||||
</span>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 编辑 -->
|
||||
<el-dialog title="编辑文档" :visible.sync="editVisible" width="520px" append-to-body @close="resetEditForm">
|
||||
<el-form ref="editFormRef" :model="editForm" label-width="96px" size="small">
|
||||
<el-form-item label="类型">
|
||||
<el-select v-model="editForm.type" style="width: 100%;">
|
||||
<el-option label="PDF" :value="1"></el-option>
|
||||
<el-option label="飞书链接" :value="2"></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="来源">
|
||||
<el-input v-model="editForm.source"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="内容">
|
||||
<el-input v-model="editForm.content" type="textarea" :rows="5"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="AI 模型">
|
||||
<el-input v-model="editForm.ai_model" placeholder="可选"></el-input>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<span slot="footer">
|
||||
<el-button size="small" @click="editVisible = false">取消</el-button>
|
||||
<el-button type="primary" size="small" :loading="editSubmitting" @click="submitEdit">保存</el-button>
|
||||
</span>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 生成 / 匹配 / 导入 -->
|
||||
<el-drawer
|
||||
title="从文档生成用例"
|
||||
:visible.sync="generateVisible"
|
||||
direction="rtl"
|
||||
size="640px"
|
||||
append-to-body
|
||||
@close="resetGenerateState">
|
||||
<div v-if="activeDocument" class="generate-drawer-head">
|
||||
<el-tag size="small">文档 #{{ activeDocument.id }}</el-tag>
|
||||
<span class="generate-drawer-source">{{ activeDocument.source }}</span>
|
||||
</div>
|
||||
<el-form :inline="true" size="small" class="generate-form">
|
||||
<el-form-item label="默认优先级">
|
||||
<el-select v-model="genForm.priority" style="width: 100px;">
|
||||
<el-option label="P0" :value="1"></el-option>
|
||||
<el-option label="P1" :value="2"></el-option>
|
||||
<el-option label="P2" :value="3"></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="用例类型">
|
||||
<el-input-number v-model="genForm.caseType" :min="1" :max="99" size="small"></el-input-number>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" :loading="generateLoading" @click="runGenerate">生成预览</el-button>
|
||||
<el-button :loading="matchLoading" :disabled="!previewCases.length" @click="runMatch">匹配模块</el-button>
|
||||
<el-button type="success" :loading="importLoading" :disabled="!previewCases.length" @click="runImport">导入选中</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<el-table :data="previewCases" border size="small" max-height="420">
|
||||
<el-table-column width="48">
|
||||
<template slot-scope="scope">
|
||||
<el-checkbox v-model="scope.row.selected"></el-checkbox>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="title" label="标题" min-width="120" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column label="模块" width="120">
|
||||
<template slot-scope="scope">
|
||||
<span>{{ scope.row.module_name || '—' }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="模块ID" width="88">
|
||||
<template slot-scope="scope">
|
||||
<el-input v-model.number="scope.row.module_id" size="mini" placeholder="必填"></el-input>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<p v-if="previewTotal" class="generate-total-hint">共 {{ previewTotal }} 条预览(导入前请为每行填写模块ID)</p>
|
||||
</el-drawer>
|
||||
|
||||
<!-- 批量建模块 -->
|
||||
<el-dialog title="批量创建模块" :visible.sync="batchModuleVisible" width="480px" append-to-body>
|
||||
<p class="batch-module-tip">每行一个模块名称,将创建在当前项目下。</p>
|
||||
<el-input v-model="batchModuleText" type="textarea" :rows="8" placeholder="例如:用户管理 订单中心"></el-input>
|
||||
<span slot="footer">
|
||||
<el-button size="small" @click="batchModuleVisible = false">取消</el-button>
|
||||
<el-button type="primary" size="small" :loading="batchModuleSubmitting" @click="submitBatchModules">创建</el-button>
|
||||
</span>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { mapState } from 'vuex'
|
||||
import {
|
||||
getDocumentList,
|
||||
getDocumentDetail,
|
||||
uploadDocumentPdf,
|
||||
createDocument,
|
||||
updateDocument,
|
||||
deleteDocument,
|
||||
refreshDocument,
|
||||
generateDocumentCases,
|
||||
matchDocumentModules,
|
||||
importDocumentCases,
|
||||
batchCreateDocumentModules
|
||||
} from '@/api/documentApi'
|
||||
|
||||
export default {
|
||||
name: 'DocumentSourcePanel',
|
||||
props: {
|
||||
productId: {
|
||||
type: [Number, String],
|
||||
default: ''
|
||||
},
|
||||
projectId: {
|
||||
type: [Number, String],
|
||||
default: ''
|
||||
},
|
||||
/** 文档列表表格高度(独立 Tab 可传更大值) */
|
||||
tableHeight: {
|
||||
type: [Number, String],
|
||||
default: 360
|
||||
},
|
||||
/** 仅保留新建/编辑等弹窗,不展示列表与筛选;不自动请求文档列表 */
|
||||
compact: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
docQuery: {
|
||||
type: '',
|
||||
status: '',
|
||||
keyword: ''
|
||||
},
|
||||
docPageNo: 1,
|
||||
docPageSize: 10,
|
||||
docTotal: 0,
|
||||
docTableData: [],
|
||||
docLoading: false,
|
||||
detailVisible: false,
|
||||
detailLoading: false,
|
||||
detailRecord: null,
|
||||
createVisible: false,
|
||||
createSubmitting: false,
|
||||
pdfUploading: false,
|
||||
pdfPendingFiles: [],
|
||||
createForm: {
|
||||
type: 1,
|
||||
source: '',
|
||||
content: ''
|
||||
},
|
||||
createRules: {
|
||||
source: [{ required: true, message: '请输入飞书链接', trigger: 'blur' }]
|
||||
},
|
||||
editVisible: false,
|
||||
editSubmitting: false,
|
||||
editForm: {
|
||||
documentId: null,
|
||||
type: 1,
|
||||
source: '',
|
||||
content: '',
|
||||
ai_model: ''
|
||||
},
|
||||
generateVisible: false,
|
||||
generateLoading: false,
|
||||
matchLoading: false,
|
||||
importLoading: false,
|
||||
activeDocument: null,
|
||||
genForm: {
|
||||
priority: 2,
|
||||
caseType: 1
|
||||
},
|
||||
previewCases: [],
|
||||
previewTotal: 0,
|
||||
batchModuleVisible: false,
|
||||
batchModuleText: '',
|
||||
batchModuleSubmitting: false
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
...mapState(['currentUser']),
|
||||
detailContentDisplay() {
|
||||
if (!this.detailRecord) return ''
|
||||
return this.detailRecord.content || ''
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
projectId: {
|
||||
immediate: true,
|
||||
handler(val) {
|
||||
this.docPageNo = 1
|
||||
if (this.compact) {
|
||||
if (!val) {
|
||||
this.docTableData = []
|
||||
this.docTotal = 0
|
||||
}
|
||||
return
|
||||
}
|
||||
if (val) {
|
||||
this.fetchDocuments()
|
||||
} else {
|
||||
this.docTableData = []
|
||||
this.docTotal = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
formatDocType(type) {
|
||||
if (type === 2) return '飞书'
|
||||
if (type === 1) return 'PDF'
|
||||
return '—'
|
||||
},
|
||||
formatDocStatus(status) {
|
||||
const map = { 0: '待解析', 1: '已解析', 2: '已生成用例' }
|
||||
return map[status] !== undefined ? map[status] : '—'
|
||||
},
|
||||
docStatusTagType(status) {
|
||||
if (status === 0) return 'info'
|
||||
if (status === 1) return 'success'
|
||||
if (status === 2) return 'warning'
|
||||
return ''
|
||||
},
|
||||
cleanParams(obj) {
|
||||
return Object.keys(obj || {}).reduce((acc, key) => {
|
||||
const v = obj[key]
|
||||
if (v !== '' && v !== undefined && v !== null) {
|
||||
acc[key] = v
|
||||
}
|
||||
return acc
|
||||
}, {})
|
||||
},
|
||||
fetchDocuments() {
|
||||
if (!this.projectId) {
|
||||
this.docTableData = []
|
||||
this.docTotal = 0
|
||||
return
|
||||
}
|
||||
this.docLoading = true
|
||||
const params = this.cleanParams({
|
||||
productId: this.productId || undefined,
|
||||
projectId: this.projectId,
|
||||
type: this.docQuery.type,
|
||||
status: this.docQuery.status,
|
||||
keyword: this.docQuery.keyword,
|
||||
pageNo: this.docPageNo,
|
||||
pageSize: this.docPageSize
|
||||
})
|
||||
getDocumentList(params)
|
||||
.then(res => {
|
||||
const data = (res && res.data) || res || {}
|
||||
const list = data.list || data.items || []
|
||||
this.docTableData = Array.isArray(list) ? list : []
|
||||
this.docTotal = Number(data.total || 0)
|
||||
})
|
||||
.catch(() => {
|
||||
this.docTableData = []
|
||||
this.docTotal = 0
|
||||
})
|
||||
.finally(() => {
|
||||
this.docLoading = false
|
||||
})
|
||||
},
|
||||
handleDocSearch() {
|
||||
this.docPageNo = 1
|
||||
this.fetchDocuments()
|
||||
},
|
||||
handleDocPageChange(p) {
|
||||
this.docPageNo = p
|
||||
this.fetchDocuments()
|
||||
},
|
||||
handleDocRowClick(row) {
|
||||
if (this.compact || !this.$refs.docTable) return
|
||||
if (this.$refs.docTable.setCurrentRow) {
|
||||
this.$refs.docTable.setCurrentRow(row)
|
||||
}
|
||||
},
|
||||
syncDocumentListAfterMutation() {
|
||||
if (this.compact) {
|
||||
this.$emit('document-changed')
|
||||
} else {
|
||||
this.fetchDocuments()
|
||||
}
|
||||
},
|
||||
openDetail(row) {
|
||||
this.detailVisible = true
|
||||
this.detailRecord = Object.assign({}, row)
|
||||
this.detailLoading = true
|
||||
getDocumentDetail({ documentId: row.id })
|
||||
.then(res => {
|
||||
const data = (res && res.data) || res || {}
|
||||
this.detailRecord = data
|
||||
})
|
||||
.catch(() => {})
|
||||
.finally(() => {
|
||||
this.detailLoading = false
|
||||
})
|
||||
},
|
||||
openCreateDialog() {
|
||||
if (!this.productId || !this.projectId) {
|
||||
this.$message.warning('请先选择产品与项目')
|
||||
return
|
||||
}
|
||||
this.createForm = {
|
||||
type: 1,
|
||||
source: '',
|
||||
content: ''
|
||||
}
|
||||
this.pdfPendingFiles = []
|
||||
this.createVisible = true
|
||||
this.$nextTick(() => {
|
||||
this.$refs.createFormRef && this.$refs.createFormRef.clearValidate()
|
||||
})
|
||||
},
|
||||
resetCreateForm() {
|
||||
this.createForm = { type: 1, source: '', content: '' }
|
||||
this.pdfPendingFiles = []
|
||||
if (this.$refs.pdfMultiInput) {
|
||||
this.$refs.pdfMultiInput.value = ''
|
||||
}
|
||||
},
|
||||
onCreateTypeChange() {
|
||||
this.pdfPendingFiles = []
|
||||
if (this.$refs.pdfMultiInput) {
|
||||
this.$refs.pdfMultiInput.value = ''
|
||||
}
|
||||
this.$nextTick(() => {
|
||||
this.$refs.createFormRef && this.$refs.createFormRef.clearValidate()
|
||||
})
|
||||
},
|
||||
triggerPdfMultiSelect() {
|
||||
this.$refs.pdfMultiInput && this.$refs.pdfMultiInput.click()
|
||||
},
|
||||
onPdfMultiInputChange(e) {
|
||||
const input = e && e.target
|
||||
const picked = input && input.files ? Array.from(input.files) : []
|
||||
if (input) {
|
||||
input.value = ''
|
||||
}
|
||||
const pdfs = picked.filter(f => {
|
||||
const name = String(f.name || '').toLowerCase()
|
||||
return name.endsWith('.pdf') || f.type === 'application/pdf'
|
||||
})
|
||||
if (picked.length && pdfs.length < picked.length) {
|
||||
this.$message.warning('已忽略非 PDF 文件')
|
||||
}
|
||||
const seen = new Set(this.pdfPendingFiles.map(x => `${x.name}_${x.size}`))
|
||||
pdfs.forEach(f => {
|
||||
const key = `${f.name}_${f.size}`
|
||||
if (!seen.has(key)) {
|
||||
seen.add(key)
|
||||
this.pdfPendingFiles.push(f)
|
||||
}
|
||||
})
|
||||
},
|
||||
removePdfPending(index) {
|
||||
this.pdfPendingFiles.splice(index, 1)
|
||||
},
|
||||
formatFileSize(bytes) {
|
||||
const n = Number(bytes)
|
||||
if (!Number.isFinite(n) || n < 0) return '—'
|
||||
if (n < 1024) return `${n} B`
|
||||
if (n < 1024 * 1024) return `${(n / 1024).toFixed(1)} KB`
|
||||
return `${(n / 1024 / 1024).toFixed(1)} MB`
|
||||
},
|
||||
async submitAllPdfUploads() {
|
||||
if (!this.productId || !this.projectId) {
|
||||
this.$message.warning('请先选择产品与项目')
|
||||
return
|
||||
}
|
||||
const files = this.pdfPendingFiles.slice()
|
||||
if (!files.length) {
|
||||
this.$message.warning('请先选择 PDF 文件')
|
||||
return
|
||||
}
|
||||
const productId = Number(this.productId)
|
||||
const projectId = Number(this.projectId)
|
||||
const createdBy = this.currentUser && this.currentUser.id ? this.currentUser.id : undefined
|
||||
this.pdfUploading = true
|
||||
const failed = []
|
||||
let ok = 0
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
const file = files[i]
|
||||
try {
|
||||
await uploadDocumentPdf({ file, productId, projectId, createdBy })
|
||||
ok += 1
|
||||
} catch (e) {
|
||||
failed.push(file)
|
||||
}
|
||||
}
|
||||
this.pdfUploading = false
|
||||
this.pdfPendingFiles = failed
|
||||
if (ok) {
|
||||
this.syncDocumentListAfterMutation()
|
||||
}
|
||||
if (ok && !failed.length) {
|
||||
this.$message.success(`已上传 ${ok} 个 PDF`)
|
||||
this.createVisible = false
|
||||
} else if (ok && failed.length) {
|
||||
this.$message.warning(`成功 ${ok} 个,失败 ${failed.length} 个;失败项仍留在列表中,可修正后重试`)
|
||||
} else {
|
||||
this.$message.error('上传失败,请检查网络或文件后重试')
|
||||
}
|
||||
},
|
||||
submitCreate() {
|
||||
if (this.createForm.type === 1) {
|
||||
this.$message.info('PDF 请使用「选择 PDF」并点击「上传全部」')
|
||||
return
|
||||
}
|
||||
this.$refs.createFormRef.validate(valid => {
|
||||
if (!valid) return
|
||||
this.createSubmitting = true
|
||||
const payload = {
|
||||
productId: Number(this.productId),
|
||||
projectId: Number(this.projectId),
|
||||
type: this.createForm.type,
|
||||
source: this.createForm.source,
|
||||
content: this.createForm.content || undefined
|
||||
}
|
||||
if (this.currentUser && this.currentUser.id) {
|
||||
payload.createdBy = this.currentUser.id
|
||||
}
|
||||
createDocument(payload)
|
||||
.then(() => {
|
||||
this.$message.success('创建成功')
|
||||
this.createVisible = false
|
||||
this.syncDocumentListAfterMutation()
|
||||
})
|
||||
.finally(() => {
|
||||
this.createSubmitting = false
|
||||
})
|
||||
})
|
||||
},
|
||||
handleDocCommand(cmd, row) {
|
||||
if (cmd === 'refresh') {
|
||||
this.doRefresh(row)
|
||||
} else if (cmd === 'generate') {
|
||||
this.openGenerate(row)
|
||||
} else if (cmd === 'edit') {
|
||||
this.openEdit(row)
|
||||
} else if (cmd === 'delete') {
|
||||
this.doDelete(row)
|
||||
}
|
||||
},
|
||||
doRefresh(row) {
|
||||
this.$confirm('确认从飞书重新拉取内容?', '提示', { type: 'warning' })
|
||||
.then(() => {
|
||||
return refreshDocument({ documentId: row.id })
|
||||
})
|
||||
.then(() => {
|
||||
this.$message.success('已刷新')
|
||||
this.fetchDocuments()
|
||||
})
|
||||
.catch(() => {})
|
||||
},
|
||||
doDelete(row) {
|
||||
this.$confirm('确认删除该文档?', '提示', { type: 'warning' })
|
||||
.then(() => {
|
||||
return deleteDocument({ documentId: row.id })
|
||||
})
|
||||
.then(() => {
|
||||
this.$message.success('已删除')
|
||||
this.fetchDocuments()
|
||||
})
|
||||
.catch(() => {})
|
||||
},
|
||||
openEdit(row) {
|
||||
this.editForm = {
|
||||
documentId: row.id,
|
||||
type: row.type,
|
||||
source: row.source || '',
|
||||
content: row.content || '',
|
||||
ai_model: row.ai_model || ''
|
||||
}
|
||||
this.editVisible = true
|
||||
},
|
||||
resetEditForm() {
|
||||
this.editForm = { documentId: null, type: 1, source: '', content: '', ai_model: '' }
|
||||
},
|
||||
submitEdit() {
|
||||
if (!this.editForm.documentId) return
|
||||
this.editSubmitting = true
|
||||
updateDocument({
|
||||
documentId: this.editForm.documentId,
|
||||
type: this.editForm.type,
|
||||
source: this.editForm.source,
|
||||
content: this.editForm.content,
|
||||
ai_model: this.editForm.ai_model || undefined
|
||||
})
|
||||
.then(() => {
|
||||
this.$message.success('保存成功')
|
||||
this.editVisible = false
|
||||
this.fetchDocuments()
|
||||
})
|
||||
.finally(() => {
|
||||
this.editSubmitting = false
|
||||
})
|
||||
},
|
||||
openGenerate(row) {
|
||||
this.activeDocument = row
|
||||
this.previewCases = []
|
||||
this.previewTotal = 0
|
||||
this.genForm = { priority: 2, caseType: 1 }
|
||||
this.generateVisible = true
|
||||
},
|
||||
resetGenerateState() {
|
||||
this.activeDocument = null
|
||||
this.previewCases = []
|
||||
this.previewTotal = 0
|
||||
},
|
||||
runGenerate() {
|
||||
if (!this.activeDocument || !this.projectId) return
|
||||
this.generateLoading = true
|
||||
generateDocumentCases({
|
||||
documentIds: [this.activeDocument.id],
|
||||
projectId: Number(this.projectId),
|
||||
priority: this.genForm.priority,
|
||||
caseType: this.genForm.caseType,
|
||||
tags: ['AI生成']
|
||||
})
|
||||
.then(res => {
|
||||
const data = (res && res.data) || res || {}
|
||||
const list = data.cases || []
|
||||
this.previewTotal = Number(data.total || list.length || 0)
|
||||
this.previewCases = list.map(item =>
|
||||
Object.assign({}, item, {
|
||||
selected: true,
|
||||
module_id: item.module_id != null && item.module_id !== '' ? Number(item.module_id) : null,
|
||||
module_name: item.module_name || ''
|
||||
})
|
||||
)
|
||||
if (!this.previewCases.length) {
|
||||
this.$message.info('未返回预览用例')
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
this.generateLoading = false
|
||||
})
|
||||
},
|
||||
runMatch() {
|
||||
if (!this.activeDocument || !this.previewCases.length) return
|
||||
this.matchLoading = true
|
||||
const casesPayload = this.previewCases.map(c => ({
|
||||
title: c.title,
|
||||
precondition: c.precondition,
|
||||
steps: c.steps,
|
||||
expected_result: c.expected_result,
|
||||
priority: c.priority,
|
||||
case_type: c.case_type,
|
||||
tags: c.tags,
|
||||
module_name: c.module_name,
|
||||
module_id: c.module_id
|
||||
}))
|
||||
matchDocumentModules({
|
||||
documentId: this.activeDocument.id,
|
||||
cases: casesPayload
|
||||
})
|
||||
.then(res => {
|
||||
const data = (res && res.data) || res || []
|
||||
const arr = Array.isArray(data) ? data : []
|
||||
const byTitle = {}
|
||||
arr.forEach(row => {
|
||||
if (row && row.title) byTitle[row.title] = row
|
||||
})
|
||||
this.previewCases = this.previewCases.map(row => {
|
||||
const m = byTitle[row.title]
|
||||
if (m) {
|
||||
return Object.assign({}, row, {
|
||||
module_name: m.module_name != null ? m.module_name : row.module_name,
|
||||
module_id: m.module_id != null ? Number(m.module_id) : row.module_id
|
||||
})
|
||||
}
|
||||
return row
|
||||
})
|
||||
this.$message.success('匹配完成')
|
||||
})
|
||||
.finally(() => {
|
||||
this.matchLoading = false
|
||||
})
|
||||
},
|
||||
runImport() {
|
||||
if (!this.activeDocument || !this.currentUser || !this.currentUser.id) {
|
||||
this.$message.warning('未获取到当前用户,请重新登录')
|
||||
return
|
||||
}
|
||||
const selected = this.previewCases.filter(c => c.selected)
|
||||
if (!selected.length) {
|
||||
this.$message.warning('请至少选择一条用例')
|
||||
return
|
||||
}
|
||||
for (let i = 0; i < selected.length; i++) {
|
||||
const c = selected[i]
|
||||
if (!c.module_id && c.module_id !== 0) {
|
||||
this.$message.warning(`请填写模块ID:${c.title || ''}`)
|
||||
return
|
||||
}
|
||||
if (!c.title || !c.steps) {
|
||||
this.$message.warning('标题与步骤为必填')
|
||||
return
|
||||
}
|
||||
}
|
||||
const cases = selected.map(c => ({
|
||||
selected: true,
|
||||
module_id: Number(c.module_id),
|
||||
title: c.title,
|
||||
precondition: c.precondition || '',
|
||||
steps: c.steps,
|
||||
expected_result: c.expected_result || '',
|
||||
priority: c.priority != null ? Number(c.priority) : 2,
|
||||
case_type: c.case_type != null ? Number(c.case_type) : 1,
|
||||
tags: Array.isArray(c.tags) ? c.tags : ['AI生成']
|
||||
}))
|
||||
this.$confirm(
|
||||
'请确认已完成对预览用例的审核。导入选中行后将写入正式用例列表,是否继续?',
|
||||
'确认导入',
|
||||
{ type: 'warning', confirmButtonText: '确认导入' }
|
||||
)
|
||||
.then(() => {
|
||||
this.importLoading = true
|
||||
return importDocumentCases({
|
||||
documentId: this.activeDocument.id,
|
||||
userId: this.currentUser.id,
|
||||
cases
|
||||
})
|
||||
})
|
||||
.then(res => {
|
||||
if (!res) return
|
||||
const data = (res && res.data) || res || {}
|
||||
const n = data.successCount != null ? data.successCount : cases.length
|
||||
this.$message.success(`导入成功 ${n} 条`)
|
||||
this.generateVisible = false
|
||||
this.$emit('refresh-cases')
|
||||
})
|
||||
.catch(() => {})
|
||||
.finally(() => {
|
||||
this.importLoading = false
|
||||
})
|
||||
},
|
||||
openBatchModuleDialog() {
|
||||
if (!this.projectId) {
|
||||
this.$message.warning('请先选择项目')
|
||||
return
|
||||
}
|
||||
this.batchModuleText = ''
|
||||
this.batchModuleVisible = true
|
||||
},
|
||||
submitBatchModules() {
|
||||
const lines = String(this.batchModuleText || '')
|
||||
.split(/\r?\n/)
|
||||
.map(s => s.trim())
|
||||
.filter(Boolean)
|
||||
if (!lines.length) {
|
||||
this.$message.warning('请输入至少一个模块名称')
|
||||
return
|
||||
}
|
||||
this.batchModuleSubmitting = true
|
||||
batchCreateDocumentModules({
|
||||
projectId: Number(this.projectId),
|
||||
moduleNames: lines
|
||||
})
|
||||
.then(() => {
|
||||
this.$message.success('模块创建成功')
|
||||
this.batchModuleVisible = false
|
||||
this.$emit('refresh-modules')
|
||||
})
|
||||
.finally(() => {
|
||||
this.batchModuleSubmitting = false
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.document-source-panel {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.document-source-head {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
justify-content: space-between;
|
||||
padding: 0 2px 8px;
|
||||
border-bottom: 1px solid #e4e7ed;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.document-source-title {
|
||||
font-weight: 600;
|
||||
color: #303133;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.document-source-hint {
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
}
|
||||
|
||||
.document-source-filters {
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.document-source-filters /deep/ .el-form-item {
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.document-source-table {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.document-source-table /deep/ .el-table__body tr.current-row > td {
|
||||
background-color: #ecf5ff !important;
|
||||
}
|
||||
|
||||
.document-source-pagination {
|
||||
margin-top: 8px;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.document-detail-body {
|
||||
padding: 0 4px 16px;
|
||||
}
|
||||
|
||||
.document-detail-content-label {
|
||||
margin: 12px 0 6px;
|
||||
font-weight: 600;
|
||||
color: #606266;
|
||||
}
|
||||
|
||||
.generate-drawer-head {
|
||||
margin-bottom: 12px;
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.generate-drawer-source {
|
||||
font-size: 12px;
|
||||
color: #606266;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.generate-form {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.generate-total-hint {
|
||||
margin-top: 10px;
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
}
|
||||
|
||||
.batch-module-tip {
|
||||
font-size: 13px;
|
||||
color: #606266;
|
||||
margin: 0 0 8px;
|
||||
}
|
||||
|
||||
.hidden-pdf-input {
|
||||
position: absolute;
|
||||
width: 0;
|
||||
height: 0;
|
||||
opacity: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.pdf-upload-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.pdf-upload-hint {
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
}
|
||||
|
||||
.pdf-upload-empty {
|
||||
margin: 0;
|
||||
font-size: 12px;
|
||||
color: #c0c4cc;
|
||||
}
|
||||
|
||||
.pdf-pending-list {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
max-height: 200px;
|
||||
overflow: auto;
|
||||
border: 1px solid #ebeef5;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.pdf-pending-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 6px 10px;
|
||||
font-size: 13px;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.pdf-pending-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.pdf-pending-name {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
color: #303133;
|
||||
}
|
||||
|
||||
.pdf-pending-size {
|
||||
color: #909399;
|
||||
margin-right: 8px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -27,13 +27,13 @@
|
||||
style="margin-top: 12px;">
|
||||
<el-table-column prop="planCaseId" label="计划用例ID" width="120"></el-table-column>
|
||||
<el-table-column prop="caseKey" label="用例编号" min-width="120"></el-table-column>
|
||||
<el-table-column prop="caseTitle" label="用例名称" min-width="220"></el-table-column>
|
||||
<el-table-column label="自动化执行 Jenkins URL" min-width="180" show-overflow-tooltip>
|
||||
<template slot-scope="scope">
|
||||
<el-link v-if="scope.row.jenkinsUrl" :href="scope.row.jenkinsUrl" target="_blank" type="primary">打开</el-link>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
<el-table-column label="模块路径" min-width="200" show-overflow-tooltip>
|
||||
<template slot-scope="scope">{{ scope.row.modulePath || '—' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="模块名称" min-width="140" show-overflow-tooltip>
|
||||
<template slot-scope="scope">{{ scope.row.moduleName || '—' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="caseTitle" label="用例名称" min-width="220"></el-table-column>
|
||||
<el-table-column prop="actualResult" label="执行结果" min-width="180"></el-table-column>
|
||||
<el-table-column label="执行状态" width="110">
|
||||
<template slot-scope="scope">
|
||||
@@ -162,9 +162,10 @@ export default {
|
||||
statusLabel: this.formatExecuteStatus(item.status),
|
||||
actualResult: item.actual_result || item.actualResult || '',
|
||||
caseKey: item.case_key || item.caseKey || '',
|
||||
modulePath: item.module_path || item.modulePath || '',
|
||||
moduleName: item.module_name || item.moduleName || '',
|
||||
caseTitle: item.case_title || item.caseTitle || item.title || '',
|
||||
title: item.title || item.case_title || item.caseTitle || '',
|
||||
jenkinsUrl: item.jenkins_url || item.jenkinsUrl || ''
|
||||
title: item.title || item.case_title || item.caseTitle || ''
|
||||
}))
|
||||
})
|
||||
.catch(() => {
|
||||
|
||||
@@ -0,0 +1,820 @@
|
||||
<template>
|
||||
<div class="page-wrap">
|
||||
<page-section title="业务技能配置">
|
||||
<el-form :inline="true" size="small" class="filter-bar" @submit.native.prevent>
|
||||
<el-form-item label="产品">
|
||||
<el-select
|
||||
v-model="selectedProductId"
|
||||
filterable
|
||||
clearable
|
||||
placeholder="请选择产品"
|
||||
style="width: 200px;"
|
||||
@change="handleProductChange"
|
||||
@focus="loadProductOptions">
|
||||
<el-option v-for="p in productOptions" :key="p.id" :label="p.name" :value="p.id" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="项目">
|
||||
<el-select
|
||||
v-model="selectedProjectId"
|
||||
filterable
|
||||
clearable
|
||||
placeholder="请选择项目"
|
||||
style="width: 220px;"
|
||||
:disabled="!selectedProductId"
|
||||
@change="handleProjectChange">
|
||||
<el-option v-for="p in projectOptions" :key="p.id" :label="p.name" :value="p.id" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<el-tabs v-model="configActiveTab" class="skill-rule-tabs" style="margin-top: 8px;" @tab-click="onConfigTabClick">
|
||||
<el-tab-pane label="Skills 配置" name="skills">
|
||||
<el-form :inline="true" size="small" class="toolbar-form" @submit.native.prevent>
|
||||
<el-form-item label="模块">
|
||||
<el-select v-model="skillQuery.moduleId" clearable filterable placeholder="全部" style="width: 180px;" :disabled="!projectId">
|
||||
<el-option v-for="m in flatModuleOptions" :key="m.id" :label="m.name" :value="m.id" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="关键字">
|
||||
<el-input v-model="skillQuery.keyword" clearable style="width: 160px;" @keyup.enter.native="fetchSkillList" />
|
||||
</el-form-item>
|
||||
<el-form-item label="状态">
|
||||
<el-select v-model="skillQuery.status" clearable placeholder="全部" style="width: 100px;">
|
||||
<el-option v-for="o in statusOptions" :key="'s-' + o.value" :label="o.label" :value="o.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="类型">
|
||||
<el-select v-model="skillQuery.skillType" clearable placeholder="全部" style="width: 130px;">
|
||||
<el-option v-for="o in skillTypeOptions" :key="'t-' + o.value" :label="o.label" :value="o.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="风险">
|
||||
<el-select v-model="skillQuery.riskLevel" clearable placeholder="全部" style="width: 100px;">
|
||||
<el-option v-for="o in riskLevelOptions" :key="'r-' + o.value" :label="o.label" :value="o.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" :disabled="!projectId" @click="skillPageNo = 1; fetchSkillList()">查询</el-button>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button size="small" @click="resetSkillQuery">重置</el-button>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" size="small" plain :disabled="!projectId" @click="openSkillCreate">新建 Skill</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<el-table v-loading="skillLoading" :data="skillList" border size="small" style="margin-top: 8px;">
|
||||
<el-table-column prop="id" label="ID" width="72" />
|
||||
<el-table-column prop="name" label="名称" min-width="140" show-overflow-tooltip />
|
||||
<el-table-column prop="code" label="编码" min-width="120" show-overflow-tooltip />
|
||||
<el-table-column label="类型" width="100">
|
||||
<template slot-scope="scope">{{ formatSkillType(scope.row.skill_type) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="风险" width="88">
|
||||
<template slot-scope="scope">{{ formatRiskLevel(scope.row.risk_level) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="状态" width="88">
|
||||
<template slot-scope="scope">{{ formatConfigStatus(scope.row.status) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="标签" min-width="120" show-overflow-tooltip>
|
||||
<template slot-scope="scope">{{ formatTagsCol(scope.row.tags) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="updated_time" label="更新时间" min-width="150" show-overflow-tooltip />
|
||||
<el-table-column label="操作" width="140" fixed="right">
|
||||
<template slot-scope="scope">
|
||||
<el-button type="text" @click="openSkillEdit(scope.row)">编辑</el-button>
|
||||
<el-button type="text" style="color: #F56C6C;" @click="removeSkill(scope.row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div class="pager-wrap">
|
||||
<el-pagination
|
||||
:current-page="skillPageNo"
|
||||
:page-size="skillPageSize"
|
||||
:page-sizes="[10, 20, 50]"
|
||||
:total="skillTotal"
|
||||
layout="total, sizes, prev, pager, next"
|
||||
@size-change="onSkillSize"
|
||||
@current-change="onSkillPage" />
|
||||
</div>
|
||||
</el-tab-pane>
|
||||
|
||||
<el-tab-pane label="业务规则配置" name="rules">
|
||||
<el-form :inline="true" size="small" class="toolbar-form" @submit.native.prevent>
|
||||
<el-form-item label="模块">
|
||||
<el-select v-model="ruleQuery.moduleId" clearable filterable placeholder="全部" style="width: 180px;" :disabled="!projectId">
|
||||
<el-option v-for="m in flatModuleOptions" :key="'r-' + m.id" :label="m.name" :value="m.id" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="关键字">
|
||||
<el-input v-model="ruleQuery.keyword" clearable style="width: 160px;" @keyup.enter.native="fetchRuleList" />
|
||||
</el-form-item>
|
||||
<el-form-item label="状态">
|
||||
<el-select v-model="ruleQuery.status" clearable placeholder="全部" style="width: 100px;">
|
||||
<el-option v-for="o in statusOptions" :key="'rs-' + o.value" :label="o.label" :value="o.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="优先级">
|
||||
<el-select v-model="ruleQuery.priority" clearable placeholder="全部" style="width: 100px;">
|
||||
<el-option v-for="o in priorityOptions" :key="'p-' + o.value" :label="o.label" :value="o.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" :disabled="!projectId" @click="rulePageNo = 1; fetchRuleList()">查询</el-button>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button size="small" @click="resetRuleQuery">重置</el-button>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" size="small" plain :disabled="!projectId" @click="openRuleCreate">新建规则</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<el-table v-loading="ruleLoading" :data="ruleList" border size="small" style="margin-top: 8px;">
|
||||
<el-table-column prop="id" label="ID" width="72" />
|
||||
<el-table-column prop="name" label="名称" min-width="140" show-overflow-tooltip />
|
||||
<el-table-column prop="rule_code" label="规则编码" min-width="120" show-overflow-tooltip />
|
||||
<el-table-column label="优先级" width="100">
|
||||
<template slot-scope="scope">{{ formatPriority(scope.row.priority) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="状态" width="88">
|
||||
<template slot-scope="scope">{{ formatConfigStatus(scope.row.status) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="标签" min-width="120" show-overflow-tooltip>
|
||||
<template slot-scope="scope">{{ formatTagsCol(scope.row.tags) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="updated_time" label="更新时间" min-width="150" show-overflow-tooltip />
|
||||
<el-table-column label="操作" width="140" fixed="right">
|
||||
<template slot-scope="scope">
|
||||
<el-button type="text" @click="openRuleEdit(scope.row)">编辑</el-button>
|
||||
<el-button type="text" style="color: #F56C6C;" @click="removeRule(scope.row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div class="pager-wrap">
|
||||
<el-pagination
|
||||
:current-page="rulePageNo"
|
||||
:page-size="rulePageSize"
|
||||
:page-sizes="[10, 20, 50]"
|
||||
:total="ruleTotal"
|
||||
layout="total, sizes, prev, pager, next"
|
||||
@size-change="onRuleSize"
|
||||
@current-change="onRulePage" />
|
||||
</div>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</page-section>
|
||||
|
||||
<el-dialog :title="skillDialogMode === 'create' ? '新建 Skill' : '编辑 Skill'" :visible.sync="skillDialogVisible" width="720px" @close="resetSkillForm">
|
||||
<el-form ref="skillFormRef" :model="skillForm" :rules="skillFormActiveRules" label-width="120px" size="small">
|
||||
<el-form-item label="模块" prop="moduleId">
|
||||
<el-select v-model="skillForm.moduleId" clearable filterable placeholder="可选" style="width: 100%;" :disabled="!projectId">
|
||||
<el-option v-for="m in flatModuleOptions" :key="'sf-' + m.id" :label="m.name" :value="m.id" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="名称" prop="name">
|
||||
<el-input v-model="skillForm.name" />
|
||||
</el-form-item>
|
||||
<template v-if="skillDialogMode === 'edit'">
|
||||
<el-form-item label="编码">
|
||||
<el-input v-model="skillForm.code" disabled placeholder="创建后不可修改" />
|
||||
</el-form-item>
|
||||
<el-form-item label="触发条件" prop="triggerCondition">
|
||||
<el-input v-model="skillForm.triggerCondition" type="textarea" :rows="2" />
|
||||
</el-form-item>
|
||||
<el-form-item label="推理路径">
|
||||
<el-input v-model="skillForm.reasoningPath" type="textarea" :rows="2" />
|
||||
</el-form-item>
|
||||
<el-form-item label="输出规范">
|
||||
<el-input v-model="skillForm.outputSpec" type="textarea" :rows="2" />
|
||||
</el-form-item>
|
||||
</template>
|
||||
<el-form-item label="描述">
|
||||
<el-input v-model="skillForm.description" type="textarea" :rows="2" />
|
||||
</el-form-item>
|
||||
<el-form-item label="类型">
|
||||
<el-select v-model="skillForm.skillType" style="width: 100%;">
|
||||
<el-option v-for="o in skillTypeOptions" :key="'sfo-' + o.value" :label="o.label" :value="o.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="风险等级">
|
||||
<el-select v-model="skillForm.riskLevel" style="width: 100%;">
|
||||
<el-option v-for="o in riskLevelOptions" :key="'sfr-' + o.value" :label="o.label" :value="o.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="状态">
|
||||
<el-select v-model="skillForm.status" style="width: 100%;">
|
||||
<el-option v-for="o in statusOptions" :key="'sfs-' + o.value" :label="o.label" :value="o.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="标签">
|
||||
<el-select v-model="skillForm.tags" multiple filterable allow-create default-first-option placeholder="输入后回车可新增" style="width: 100%;" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<span slot="footer">
|
||||
<el-button size="small" @click="skillDialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" size="small" :loading="skillSubmitting" @click="submitSkill">保存</el-button>
|
||||
</span>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog :title="ruleDialogMode === 'create' ? '新建业务规则' : '编辑业务规则'" :visible.sync="ruleDialogVisible" width="720px" @close="resetRuleForm">
|
||||
<el-form ref="ruleFormRef" :model="ruleForm" :rules="ruleRules" label-width="120px" size="small">
|
||||
<el-form-item label="模块" prop="moduleId">
|
||||
<el-select v-model="ruleForm.moduleId" clearable filterable placeholder="可选" style="width: 100%;" :disabled="!projectId">
|
||||
<el-option v-for="m in flatModuleOptions" :key="'rf-' + m.id" :label="m.name" :value="m.id" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="名称" prop="name">
|
||||
<el-input v-model="ruleForm.name" />
|
||||
</el-form-item>
|
||||
<el-form-item v-if="ruleDialogMode === 'edit'" label="规则编码">
|
||||
<el-input v-model="ruleForm.ruleCode" disabled placeholder="由系统分配" />
|
||||
</el-form-item>
|
||||
<el-form-item label="规则内容" prop="ruleContent">
|
||||
<el-input v-model="ruleForm.ruleContent" type="textarea" :rows="3" />
|
||||
</el-form-item>
|
||||
<el-form-item label="适用场景">
|
||||
<el-input v-model="ruleForm.applicableScene" type="textarea" :rows="2" />
|
||||
</el-form-item>
|
||||
<el-form-item label="示例">
|
||||
<el-input v-model="ruleForm.example" type="textarea" :rows="2" />
|
||||
</el-form-item>
|
||||
<el-form-item label="优先级">
|
||||
<el-select v-model="ruleForm.priority" style="width: 100%;">
|
||||
<el-option v-for="o in priorityOptions" :key="'rfo-' + o.value" :label="o.label" :value="o.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="状态">
|
||||
<el-select v-model="ruleForm.status" style="width: 100%;">
|
||||
<el-option v-for="o in statusOptions" :key="'rfs-' + o.value" :label="o.label" :value="o.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="标签">
|
||||
<el-select v-model="ruleForm.tags" multiple filterable allow-create default-first-option placeholder="输入后回车可新增" style="width: 100%;" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<span slot="footer">
|
||||
<el-button size="small" @click="ruleDialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" size="small" :loading="ruleSubmitting" @click="submitRule">保存</el-button>
|
||||
</span>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import PageSection from '@/components/TestPlatform/common/PageSection'
|
||||
import { getModuleTree } from '@/api/caseApi'
|
||||
import {
|
||||
createSkill,
|
||||
createBusinessRule,
|
||||
deleteSkill,
|
||||
deleteBusinessRule,
|
||||
getSkillDetail,
|
||||
getSkillList,
|
||||
getBusinessRuleDetail,
|
||||
getBusinessRuleList,
|
||||
updateSkill,
|
||||
updateBusinessRule
|
||||
} from '@/api/skillRuleApi'
|
||||
import { getProductList } from '@/api/productApi'
|
||||
import { getProjectList } from '@/api/projectApi'
|
||||
import {
|
||||
readLastProductProjectCache,
|
||||
saveLastProductProjectCache,
|
||||
pickIdFromOptions
|
||||
} from '@/utils/lastProductProjectCache'
|
||||
|
||||
export default {
|
||||
name: 'BusinessSkillRuleConfig',
|
||||
components: { PageSection },
|
||||
data() {
|
||||
const routeTab = this.$route.query && this.$route.query.tab
|
||||
const initialTab =
|
||||
routeTab === 'rules' || routeTab === 'business-rules' ? 'rules' : 'skills'
|
||||
return {
|
||||
configActiveTab: initialTab,
|
||||
selectedProductId: '',
|
||||
selectedProjectId: '',
|
||||
productOptions: [],
|
||||
projectOptions: [],
|
||||
moduleTree: [],
|
||||
skillQuery: { moduleId: '', keyword: '', status: '', skillType: '', riskLevel: '' },
|
||||
skillPageNo: 1,
|
||||
skillPageSize: 20,
|
||||
skillList: [],
|
||||
skillTotal: 0,
|
||||
skillLoading: false,
|
||||
skillDialogVisible: false,
|
||||
skillDialogMode: 'create',
|
||||
skillSubmitting: false,
|
||||
skillForm: {},
|
||||
ruleQuery: { moduleId: '', keyword: '', status: '', priority: '' },
|
||||
rulePageNo: 1,
|
||||
rulePageSize: 20,
|
||||
ruleList: [],
|
||||
ruleTotal: 0,
|
||||
ruleLoading: false,
|
||||
ruleDialogVisible: false,
|
||||
ruleDialogMode: 'create',
|
||||
ruleSubmitting: false,
|
||||
ruleForm: {},
|
||||
ruleRules: {
|
||||
name: [{ required: true, message: '请输入名称', trigger: 'blur' }],
|
||||
ruleContent: [{ required: true, message: '请输入规则内容', trigger: 'blur' }]
|
||||
},
|
||||
statusOptions: [
|
||||
{ value: 1, label: '启用' },
|
||||
{ value: 2, label: '停用' },
|
||||
{ value: 3, label: '草稿' }
|
||||
],
|
||||
skillTypeOptions: [
|
||||
{ value: 1, label: '通用测试策略' },
|
||||
{ value: 2, label: '历史缺陷模式' },
|
||||
{ value: 3, label: '边界场景' },
|
||||
{ value: 4, label: '接口测试' },
|
||||
{ value: 5, label: 'UI 测试' },
|
||||
{ value: 6, label: '性能测试' },
|
||||
{ value: 7, label: '安全测试' },
|
||||
{ value: 8, label: '数据一致性' },
|
||||
{ value: 9, label: '并发/幂等' },
|
||||
{ value: 99, label: '其他' }
|
||||
],
|
||||
riskLevelOptions: [
|
||||
{ value: 0, label: '高风险' },
|
||||
{ value: 1, label: '中高风险' },
|
||||
{ value: 2, label: '中风险' },
|
||||
{ value: 3, label: '低风险' }
|
||||
],
|
||||
priorityOptions: [
|
||||
{ value: 0, label: '高优先级' },
|
||||
{ value: 1, label: '中高优先级' },
|
||||
{ value: 2, label: '中优先级' },
|
||||
{ value: 3, label: '低优先级' }
|
||||
]
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
projectId() {
|
||||
return this.selectedProjectId || ''
|
||||
},
|
||||
flatModuleOptions() {
|
||||
const out = []
|
||||
const walk = (list, prefix) => {
|
||||
;(list || []).forEach(item => {
|
||||
const name = prefix ? `${prefix} / ${item.name}` : item.name
|
||||
out.push({ id: item.id, name })
|
||||
const ch = item.children || item.child_list || item.childList || []
|
||||
if (Array.isArray(ch) && ch.length) walk(ch, name)
|
||||
})
|
||||
}
|
||||
walk(this.moduleTree, '')
|
||||
return out
|
||||
},
|
||||
skillFormActiveRules() {
|
||||
if (this.skillDialogMode === 'create') {
|
||||
return {
|
||||
name: [{ required: true, message: '请输入名称', trigger: 'blur' }]
|
||||
}
|
||||
}
|
||||
return {
|
||||
name: [{ required: true, message: '请输入名称', trigger: 'blur' }],
|
||||
triggerCondition: [{ required: true, message: '请输入触发条件', trigger: 'blur' }]
|
||||
}
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
'$route.query.tab'(val) {
|
||||
const next = val === 'rules' || val === 'business-rules' ? 'rules' : 'skills'
|
||||
if (this.configActiveTab !== next) {
|
||||
this.configActiveTab = next
|
||||
}
|
||||
if (!this.projectId) return
|
||||
if (next === 'rules') this.fetchRuleList()
|
||||
else this.fetchSkillList()
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.resetSkillFormModel()
|
||||
this.resetRuleFormModel()
|
||||
this.bootstrap()
|
||||
},
|
||||
methods: {
|
||||
cleanParams(obj) {
|
||||
const r = {}
|
||||
Object.keys(obj || {}).forEach(k => {
|
||||
const v = obj[k]
|
||||
if (v !== '' && v !== undefined && v !== null) r[k] = v
|
||||
})
|
||||
return r
|
||||
},
|
||||
/** 新建 Skill 时后端要求 code 唯一,由前端自动生成 */
|
||||
generateAutoSkillCode() {
|
||||
const t = Date.now()
|
||||
const r = Math.random().toString(36).slice(2, 10).toUpperCase()
|
||||
return `SKILL_AUTO_${t}_${r}`
|
||||
},
|
||||
onConfigTabClick(tab) {
|
||||
const name = tab && tab.name
|
||||
const q = Object.assign({}, this.$route.query || {})
|
||||
if (name === 'rules') {
|
||||
q.tab = 'rules'
|
||||
} else {
|
||||
delete q.tab
|
||||
}
|
||||
const prev = JSON.stringify(this.$route.query || {})
|
||||
const next = JSON.stringify(q)
|
||||
if (prev !== next) {
|
||||
this.$router.replace({ path: this.$route.path, query: q }).catch(() => {})
|
||||
}
|
||||
},
|
||||
formatTagsCol(tags) {
|
||||
if (Array.isArray(tags)) return tags.join('、')
|
||||
return tags || '—'
|
||||
},
|
||||
formatSkillType(v) {
|
||||
const o = this.skillTypeOptions.find(x => x.value === v)
|
||||
return o ? o.label : (v === undefined || v === null ? '—' : v)
|
||||
},
|
||||
formatRiskLevel(v) {
|
||||
const o = this.riskLevelOptions.find(x => x.value === v)
|
||||
return o ? o.label : (v === undefined || v === null ? '—' : v)
|
||||
},
|
||||
formatPriority(v) {
|
||||
const o = this.priorityOptions.find(x => x.value === v)
|
||||
return o ? o.label : (v === undefined || v === null ? '—' : v)
|
||||
},
|
||||
formatConfigStatus(v) {
|
||||
const o = this.statusOptions.find(x => x.value === v)
|
||||
return o ? o.label : (v === undefined || v === null ? '—' : v)
|
||||
},
|
||||
resetSkillFormModel() {
|
||||
this.skillForm = {
|
||||
skillId: null,
|
||||
moduleId: '',
|
||||
name: '',
|
||||
code: '',
|
||||
description: '',
|
||||
triggerCondition: '',
|
||||
reasoningPath: '',
|
||||
outputSpec: '',
|
||||
skillType: 1,
|
||||
riskLevel: 2,
|
||||
tags: [],
|
||||
status: 1
|
||||
}
|
||||
},
|
||||
resetRuleFormModel() {
|
||||
this.ruleForm = {
|
||||
ruleId: null,
|
||||
moduleId: '',
|
||||
name: '',
|
||||
ruleCode: '',
|
||||
ruleContent: '',
|
||||
applicableScene: '',
|
||||
example: '',
|
||||
priority: 2,
|
||||
tags: [],
|
||||
status: 1
|
||||
}
|
||||
},
|
||||
bootstrap() {
|
||||
this.loadProductOptions().then(() => {
|
||||
const routePid = this.$route.query.productId ? Number(this.$route.query.productId) : ''
|
||||
const routeProj = this.$route.query.projectId ? Number(this.$route.query.projectId) : ''
|
||||
if (routePid) {
|
||||
this.selectedProductId = routePid
|
||||
return this.loadProjectOptions(routePid).then(() => {
|
||||
if (routeProj) this.selectedProjectId = pickIdFromOptions(this.projectOptions, routeProj)
|
||||
})
|
||||
}
|
||||
const cached = readLastProductProjectCache()
|
||||
if (cached && cached.productId != null && cached.projectId != null) {
|
||||
this.selectedProductId = pickIdFromOptions(this.productOptions, cached.productId)
|
||||
return this.loadProjectOptions(this.selectedProductId).then(() => {
|
||||
this.selectedProjectId = pickIdFromOptions(this.projectOptions, cached.projectId)
|
||||
})
|
||||
}
|
||||
return Promise.resolve()
|
||||
}).then(() => {
|
||||
if (this.projectId) {
|
||||
this.loadModuleTree()
|
||||
if (this.configActiveTab === 'rules') this.fetchRuleList()
|
||||
else this.fetchSkillList()
|
||||
}
|
||||
})
|
||||
},
|
||||
loadProductOptions() {
|
||||
if (this.productOptions.length) return Promise.resolve()
|
||||
return getProductList({ pageNo: 1, pageSize: 1000, status: 1 }).then(res => {
|
||||
const data = (res && res.data) || res || {}
|
||||
this.productOptions = data.items || data.list || data.data || []
|
||||
}).catch(() => { this.productOptions = [] })
|
||||
},
|
||||
loadProjectOptions(productId) {
|
||||
if (!productId) {
|
||||
this.projectOptions = []
|
||||
return Promise.resolve()
|
||||
}
|
||||
return getProjectList({ pageNo: 1, pageSize: 1000, status: 1, productId }).then(res => {
|
||||
const data = (res && res.data) || res || {}
|
||||
this.projectOptions = data.items || data.list || data.data || []
|
||||
}).catch(() => { this.projectOptions = [] })
|
||||
},
|
||||
loadModuleTree() {
|
||||
if (!this.projectId) {
|
||||
this.moduleTree = []
|
||||
return
|
||||
}
|
||||
getModuleTree({ projectId: this.projectId }).then(res => {
|
||||
const data = (res && res.data) || res || {}
|
||||
const list = data.list || data.items || []
|
||||
this.moduleTree = Array.isArray(list) ? list : []
|
||||
}).catch(() => { this.moduleTree = [] })
|
||||
},
|
||||
handleProductChange() {
|
||||
this.selectedProjectId = ''
|
||||
this.projectOptions = []
|
||||
this.moduleTree = []
|
||||
this.skillList = []
|
||||
this.ruleList = []
|
||||
this.skillTotal = 0
|
||||
this.ruleTotal = 0
|
||||
this.loadProjectOptions(this.selectedProductId)
|
||||
},
|
||||
handleProjectChange() {
|
||||
if (this.selectedProductId && this.selectedProjectId) {
|
||||
saveLastProductProjectCache(this.selectedProductId, this.selectedProjectId)
|
||||
}
|
||||
this.skillPageNo = 1
|
||||
this.rulePageNo = 1
|
||||
this.loadModuleTree()
|
||||
if (this.projectId) {
|
||||
if (this.configActiveTab === 'rules') this.fetchRuleList()
|
||||
else this.fetchSkillList()
|
||||
} else {
|
||||
this.skillList = []
|
||||
this.ruleList = []
|
||||
this.skillTotal = 0
|
||||
this.ruleTotal = 0
|
||||
}
|
||||
},
|
||||
resetSkillQuery() {
|
||||
this.skillQuery = { moduleId: '', keyword: '', status: '', skillType: '', riskLevel: '' }
|
||||
this.skillPageNo = 1
|
||||
this.fetchSkillList()
|
||||
},
|
||||
resetRuleQuery() {
|
||||
this.ruleQuery = { moduleId: '', keyword: '', status: '', priority: '' }
|
||||
this.rulePageNo = 1
|
||||
this.fetchRuleList()
|
||||
},
|
||||
fetchSkillList() {
|
||||
if (!this.projectId) return
|
||||
this.skillLoading = true
|
||||
const params = this.cleanParams(Object.assign({}, this.skillQuery, {
|
||||
pageNo: this.skillPageNo,
|
||||
pageSize: this.skillPageSize,
|
||||
projectId: this.projectId
|
||||
}))
|
||||
getSkillList(params).then(res => {
|
||||
const data = (res && res.data) || res || {}
|
||||
const list = data.list || data.items || []
|
||||
this.skillList = Array.isArray(list) ? list : []
|
||||
this.skillTotal = Number(data.total || 0)
|
||||
}).catch(() => {
|
||||
this.skillList = []
|
||||
this.skillTotal = 0
|
||||
}).finally(() => { this.skillLoading = false })
|
||||
},
|
||||
fetchRuleList() {
|
||||
if (!this.projectId) return
|
||||
this.ruleLoading = true
|
||||
const params = this.cleanParams(Object.assign({}, this.ruleQuery, {
|
||||
pageNo: this.rulePageNo,
|
||||
pageSize: this.rulePageSize,
|
||||
projectId: this.projectId
|
||||
}))
|
||||
getBusinessRuleList(params).then(res => {
|
||||
const data = (res && res.data) || res || {}
|
||||
const list = data.list || data.items || []
|
||||
this.ruleList = Array.isArray(list) ? list : []
|
||||
this.ruleTotal = Number(data.total || 0)
|
||||
}).catch(() => {
|
||||
this.ruleList = []
|
||||
this.ruleTotal = 0
|
||||
}).finally(() => { this.ruleLoading = false })
|
||||
},
|
||||
onSkillSize(s) {
|
||||
this.skillPageSize = s
|
||||
this.skillPageNo = 1
|
||||
this.fetchSkillList()
|
||||
},
|
||||
onSkillPage(p) {
|
||||
this.skillPageNo = p
|
||||
this.fetchSkillList()
|
||||
},
|
||||
onRuleSize(s) {
|
||||
this.rulePageSize = s
|
||||
this.rulePageNo = 1
|
||||
this.fetchRuleList()
|
||||
},
|
||||
onRulePage(p) {
|
||||
this.rulePageNo = p
|
||||
this.fetchRuleList()
|
||||
},
|
||||
openSkillCreate() {
|
||||
if (!this.projectId) {
|
||||
this.$message.warning('请先选择项目')
|
||||
return
|
||||
}
|
||||
this.skillDialogMode = 'create'
|
||||
this.resetSkillFormModel()
|
||||
this.skillDialogVisible = true
|
||||
this.$nextTick(() => this.$refs.skillFormRef && this.$refs.skillFormRef.clearValidate())
|
||||
},
|
||||
openSkillEdit(row) {
|
||||
if (!row || !row.id) return
|
||||
getSkillDetail(row.id).then(res => {
|
||||
const d = (res && res.data) || res || {}
|
||||
this.skillDialogMode = 'edit'
|
||||
this.skillForm = {
|
||||
skillId: d.id,
|
||||
moduleId: d.module_id != null && d.module_id !== '' ? d.module_id : '',
|
||||
name: d.name || '',
|
||||
code: d.code || '',
|
||||
description: d.description || '',
|
||||
triggerCondition: d.trigger_condition || '',
|
||||
reasoningPath: d.reasoning_path || '',
|
||||
outputSpec: d.output_spec || '',
|
||||
skillType: d.skill_type !== undefined ? d.skill_type : 1,
|
||||
riskLevel: d.risk_level !== undefined ? d.risk_level : 2,
|
||||
tags: Array.isArray(d.tags) ? d.tags.slice() : [],
|
||||
status: d.status !== undefined ? d.status : 1
|
||||
}
|
||||
this.skillDialogVisible = true
|
||||
this.$nextTick(() => this.$refs.skillFormRef && this.$refs.skillFormRef.clearValidate())
|
||||
})
|
||||
},
|
||||
resetSkillForm() {
|
||||
this.resetSkillFormModel()
|
||||
},
|
||||
submitSkill() {
|
||||
const form = this.$refs.skillFormRef
|
||||
if (!form) return
|
||||
form.validate(valid => {
|
||||
if (!valid) return
|
||||
const tags = Array.isArray(this.skillForm.tags) ? this.skillForm.tags.filter(Boolean) : []
|
||||
this.skillSubmitting = true
|
||||
const done = () => { this.skillSubmitting = false }
|
||||
if (this.skillDialogMode === 'create') {
|
||||
createSkill(this.cleanParams({
|
||||
projectId: this.projectId,
|
||||
moduleId: this.skillForm.moduleId || undefined,
|
||||
name: this.skillForm.name,
|
||||
code: this.generateAutoSkillCode(),
|
||||
description: this.skillForm.description || undefined,
|
||||
triggerCondition: '由系统自动创建,可在编辑中完善。',
|
||||
skillType: this.skillForm.skillType,
|
||||
riskLevel: this.skillForm.riskLevel,
|
||||
tags,
|
||||
status: this.skillForm.status
|
||||
})).then(() => {
|
||||
this.$message.success('创建成功')
|
||||
this.skillDialogVisible = false
|
||||
this.fetchSkillList()
|
||||
}).finally(done)
|
||||
} else {
|
||||
updateSkill(this.cleanParams({
|
||||
skillId: this.skillForm.skillId,
|
||||
name: this.skillForm.name,
|
||||
description: this.skillForm.description || undefined,
|
||||
triggerCondition: this.skillForm.triggerCondition,
|
||||
reasoningPath: this.skillForm.reasoningPath || undefined,
|
||||
outputSpec: this.skillForm.outputSpec || undefined,
|
||||
skillType: this.skillForm.skillType,
|
||||
riskLevel: this.skillForm.riskLevel,
|
||||
tags,
|
||||
status: this.skillForm.status
|
||||
})).then(() => {
|
||||
this.$message.success('保存成功')
|
||||
this.skillDialogVisible = false
|
||||
this.fetchSkillList()
|
||||
}).finally(done)
|
||||
}
|
||||
})
|
||||
},
|
||||
removeSkill(row) {
|
||||
this.$confirm('确认删除该 Skill?', '提示', { type: 'warning' }).then(() => {
|
||||
deleteSkill(row.id).then(() => {
|
||||
this.$message.success('已删除')
|
||||
this.fetchSkillList()
|
||||
})
|
||||
}).catch(() => {})
|
||||
},
|
||||
openRuleCreate() {
|
||||
if (!this.projectId) {
|
||||
this.$message.warning('请先选择项目')
|
||||
return
|
||||
}
|
||||
this.ruleDialogMode = 'create'
|
||||
this.resetRuleFormModel()
|
||||
this.ruleDialogVisible = true
|
||||
this.$nextTick(() => this.$refs.ruleFormRef && this.$refs.ruleFormRef.clearValidate())
|
||||
},
|
||||
openRuleEdit(row) {
|
||||
if (!row || !row.id) return
|
||||
getBusinessRuleDetail(row.id).then(res => {
|
||||
const d = (res && res.data) || res || {}
|
||||
this.ruleDialogMode = 'edit'
|
||||
this.ruleForm = {
|
||||
ruleId: d.id,
|
||||
moduleId: d.module_id != null && d.module_id !== '' ? d.module_id : '',
|
||||
name: d.name || '',
|
||||
ruleCode: d.rule_code || '',
|
||||
ruleContent: d.rule_content || '',
|
||||
applicableScene: d.applicable_scene || '',
|
||||
example: d.example || '',
|
||||
priority: d.priority !== undefined ? d.priority : 2,
|
||||
tags: Array.isArray(d.tags) ? d.tags.slice() : [],
|
||||
status: d.status !== undefined ? d.status : 1
|
||||
}
|
||||
this.ruleDialogVisible = true
|
||||
this.$nextTick(() => this.$refs.ruleFormRef && this.$refs.ruleFormRef.clearValidate())
|
||||
})
|
||||
},
|
||||
resetRuleForm() {
|
||||
this.resetRuleFormModel()
|
||||
},
|
||||
submitRule() {
|
||||
const form = this.$refs.ruleFormRef
|
||||
if (!form) return
|
||||
form.validate(valid => {
|
||||
if (!valid) return
|
||||
const tags = Array.isArray(this.ruleForm.tags) ? this.ruleForm.tags.filter(Boolean) : []
|
||||
this.ruleSubmitting = true
|
||||
const done = () => { this.ruleSubmitting = false }
|
||||
if (this.ruleDialogMode === 'create') {
|
||||
createBusinessRule(this.cleanParams({
|
||||
projectId: this.projectId,
|
||||
moduleId: this.ruleForm.moduleId || undefined,
|
||||
name: this.ruleForm.name,
|
||||
ruleContent: this.ruleForm.ruleContent,
|
||||
applicableScene: this.ruleForm.applicableScene || undefined,
|
||||
example: this.ruleForm.example || undefined,
|
||||
priority: this.ruleForm.priority,
|
||||
tags,
|
||||
status: this.ruleForm.status
|
||||
})).then(() => {
|
||||
this.$message.success('创建成功')
|
||||
this.ruleDialogVisible = false
|
||||
this.fetchRuleList()
|
||||
}).finally(done)
|
||||
} else {
|
||||
updateBusinessRule(this.cleanParams({
|
||||
ruleId: this.ruleForm.ruleId,
|
||||
name: this.ruleForm.name,
|
||||
ruleContent: this.ruleForm.ruleContent,
|
||||
applicableScene: this.ruleForm.applicableScene || undefined,
|
||||
example: this.ruleForm.example || undefined,
|
||||
priority: this.ruleForm.priority,
|
||||
tags,
|
||||
status: this.ruleForm.status
|
||||
})).then(() => {
|
||||
this.$message.success('保存成功')
|
||||
this.ruleDialogVisible = false
|
||||
this.fetchRuleList()
|
||||
}).finally(done)
|
||||
}
|
||||
})
|
||||
},
|
||||
removeRule(row) {
|
||||
this.$confirm('确认删除该业务规则?', '提示', { type: 'warning' }).then(() => {
|
||||
deleteBusinessRule(row.id).then(() => {
|
||||
this.$message.success('已删除')
|
||||
this.fetchRuleList()
|
||||
})
|
||||
}).catch(() => {})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.page-wrap {
|
||||
padding: 20px;
|
||||
}
|
||||
.filter-bar {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.toolbar-form {
|
||||
margin-top: 0;
|
||||
}
|
||||
.pager-wrap {
|
||||
margin-top: 12px;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.skill-rule-tabs /deep/ .el-tabs__header {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
</style>
|
||||
@@ -96,6 +96,13 @@ export default new Router({
|
||||
Manage: (resolve) => require(['@/components/TestPlatform/Project/ProjectSettings'], resolve)
|
||||
}
|
||||
},
|
||||
{
|
||||
path: '/test-platform/skill-rules',
|
||||
name: 'BusinessSkillRuleConfig',
|
||||
components: {
|
||||
Manage: (resolve) => require(['@/components/TestPlatform/SkillRule/BusinessSkillRuleConfig'], resolve)
|
||||
}
|
||||
},
|
||||
{
|
||||
path: '/test-platform/case',
|
||||
name: 'CaseList',
|
||||
|
||||
@@ -41,7 +41,7 @@ export function normalizeUploadPathSlashes(url) {
|
||||
|
||||
/**
|
||||
* 静态资源(Bug 上传图)访问根,不含末尾 /
|
||||
* - 开发环境默认 http://localhost:5010(与后端文件服务常见端口一致)
|
||||
* - 开发环境默认 http://localhost:8881(与后端文件服务常见端口一致)
|
||||
* - 可在 index.html 里设置 window.__BUG_UPLOAD_ORIGIN__ 覆盖
|
||||
* - 打包时可配置 VUE_APP_BUG_UPLOAD_ORIGIN(需在 webpack DefinePlugin 中注入)
|
||||
*/
|
||||
@@ -56,14 +56,14 @@ export function getBugUploadStaticOrigin() {
|
||||
} catch (e) { /* ignore */ }
|
||||
try {
|
||||
if (typeof process !== 'undefined' && process.env && process.env.NODE_ENV === 'development') {
|
||||
return 'http://localhost:5010'
|
||||
return 'http://localhost:8881'
|
||||
}
|
||||
} catch (e2) { /* ignore */ }
|
||||
return ''
|
||||
}
|
||||
|
||||
/**
|
||||
* 浏览器实际加载图片用的地址:/uploads/... 在开发环境走 5010 端口
|
||||
* 浏览器实际加载图片用的地址:/uploads/... 在开发环境走 8881 端口
|
||||
* 存库仍可为接口返回的完整 URL,仅展示/预览时改写
|
||||
*/
|
||||
export function rewriteBugImageUrlForAccess(url) {
|
||||
@@ -155,7 +155,7 @@ export function isStepsLikelyHtml(s) {
|
||||
return /<\s*(p|div|br|img|span|ul|ol|li|h[1-6]|table|strong|em)\b/i.test(String(s || '').trim())
|
||||
}
|
||||
|
||||
/** 将 HTML 中 img 的 src 改写为可访问地址(开发环境 /uploads → 5010) */
|
||||
/** 将 HTML 中 img 的 src 改写为可访问地址(开发环境 /uploads → 8881) */
|
||||
export function rewriteImgSrcsInHtml(html) {
|
||||
return String(html || '').replace(/(<img\b[^>]*\bsrc\s*=\s*)(["'])([^"']*)\2/gi, function (_m, pre, q, src) {
|
||||
const fixed = rewriteBugImageUrlForAccess(normalizeUploadPathSlashes(src))
|
||||
|
||||
Reference in New Issue
Block a user