You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
fu-hsi-web/src/views/ruleEngine/atomicIndex/components/EditAtomic.vue

340 lines
12 KiB
Vue

10 months ago
<!--
* @description: 编辑原子指标
* @fileName: EditAtomic
* @author: 17076
* @date: 2024/6/28-上午10:14
* @version: V1.0.0
-->
<template>
<cs-drawer
:drawer-option="drawerOption"
@onReset="handleReset"
@onSubmit="handleSubmit"
>
<template slot="content">
7 months ago
<div class="add-atomic">
<el-form ref="form" :model="ruleForm" :rules="rules" label-width="120px">
<el-form-item label="案件类型" prop="caseType">
<el-select v-model="ruleForm.caseType" :disabled="isView" placeholder="请选择案件类型" style="width: 100%">
<el-option
v-for="item in caseTypeOptions"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
</el-form-item>
<el-form-item label="原子指标名称" prop="name">
<el-input
v-model="ruleForm.name"
:disabled="isView"
placeholder="请输入原子指标名称"
8 months ago
/>
7 months ago
</el-form-item>
<el-form-item label="指标算法" prop="indexSource">
<el-radio-group v-model="ruleForm['indexSource']" :disabled="isEdit|| isView" @change="changeType">
<!-- <el-radio
7 months ago
v-for="item in sourceOptions"
:key="item.value"
:label="item.value"
>
{{ item.label }}
</el-radio> -->
<el-radio label="2">数据库查询</el-radio>
6 months ago
<el-radio label="5">结构化查询</el-radio>
<el-radio label="3">图谱生成</el-radio>
<el-radio label="4">大模型推理</el-radio>
6 months ago
<el-radio label="1">人工指定</el-radio>
7 months ago
</el-radio-group>
</el-form-item>
<el-form-item v-if="ruleForm['indexSource'] === '5'" label="查询语句" prop="promptId">
<div v-if="!isView" class="select-btn" @click="selectSql"></div>
<div v-if="selectInfo.promptName" class="sel-name">{{ `${selectInfo.promptName}` }}</div>
<!-- <div v-if="ruleForm['indexSource'] === '4'" class="sel-name">{{ `` }}</div>
<span v-if="ruleForm['indexSource'] === '3'" class="sel-desc">{{ `--` }}</span> -->
<div v-if="ruleForm['indexSource'] === '5' && selectInfo.extractAttributes.length > 0" class="select-model-list">
<div v-for="(item,index) in selectInfo.extractAttributes" :key="index" class="model-list-item">
<span>{{ item }}</span>
7 months ago
</div>
</div>
</el-form-item>
<el-form-item v-if="ruleForm.indexSource ==='2'" label="关联分类" prop="categoryIdPath">
<el-cascader v-model="ruleForm.categoryIdPath" :disabled="isView" style="width: 100%;" :props="defaultProps" :options="treeData" />
</el-form-item>
<!-- <el-form-item v-if="ruleForm['indexSource'] === '4'" label="prompt标签" prop="recordType">
7 months ago
<el-select v-model="ruleForm['recordType']" :disabled="isView" placeholder="请选择prompt标签" style="width: 100%">
<el-option
v-for="item in promptTagOptions"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
</el-form-item>
<el-form-item v-if="ruleForm['indexSource'] === '4'" label="prompt内容" prop="prompt">
<el-input
v-model="ruleForm.prompt"
:disabled="isView"
type="textarea"
:rows="5"
placeholder="请输入prompt内容"
/>
</el-form-item> -->
6 months ago
<el-form-item v-if="['2','3'].includes(ruleForm['indexSource'])" style="position: relative;" label="查询语句" prop="queryLang">
7 months ago
<el-input
v-model="ruleForm['queryLang']"
:disabled="isView"
type="textarea"
6 months ago
:rows="8"
7 months ago
placeholder="请输入查询语句"
10 months ago
/>
6 months ago
<div v-if="ruleForm.indexSource ==='3'" class="sql_btn" @click="handleDebug"></div>
7 months ago
</el-form-item>
8 months ago
7 months ago
<!-- <el-form-item label="判断结果" prop="judgeResult">-->
<!-- <el-select v-model="ruleForm['judgeResult']" :disabled="isView" placeholder="请选择判断结果" style="width: 100%">-->
<!-- <el-option-->
<!-- v-for="item in resultOptions"-->
<!-- :key="item.value"-->
<!-- :label="item.label"-->
<!-- :value="item.value"-->
<!-- />-->
<!-- </el-select>-->
<!-- </el-form-item>-->
<el-form-item label="原子指标说明" prop="remark">
<el-input
v-model="ruleForm.remark"
:disabled="isView"
type="textarea"
:rows="5"
placeholder="请输入原子指标说明"
/>
</el-form-item>
</el-form>
</div>
<SelectSql ref="SelectSqlRef" @submit="selectOk" />
6 months ago
<GraphDebug ref="GraphDebugRef" />
10 months ago
</template>
7 months ago
10 months ago
</cs-drawer>
</template>
<script>
import { addOrUpdAtomicIndex } from '@/api/atomicIndex'
8 months ago
import SelectSql from './SelectSql.vue'
import { getCaseEvidenceTree } from '@/api/caseDetails/evidence'
6 months ago
import GraphDebug from './GraphDebug.vue'
10 months ago
export default {
name: 'EditAtomic',
8 months ago
components: {
6 months ago
SelectSql,
GraphDebug
8 months ago
},
10 months ago
data() {
return {
drawerOption: {
show: false,
title: '指标配置',
width: '40%'
},
selectInfo: {
promptName: '',
promptId: '',
extractAttributes: []
}, // 选中的提示词
10 months ago
// 案件类型数据
caseTypeOptions: JSON.parse(sessionStorage.getItem('case_type')),
// prompt 标签数据
promptTagOptions: [],
// 指标来源数据
sourceOptions: JSON.parse(sessionStorage.getItem('index_source')),
// 判断结果数据
resultOptions: JSON.parse(sessionStorage.getItem('judge_result')),
// 规则配置表单
ruleForm: {
6 months ago
indexSource: '2',
caseType: '',
recordType: '',
prompt: '',
queryLang: '',
name: '',
remark: ''
10 months ago
},
id: '',
defaultProps: {
children: 'child',
label: 'categoryName',
value: 'id',
checkStrictly: true
},
10 months ago
rules: {
indexSource: [{ required: true, message: '指标算法不能为空!', trigger: 'blur' }],
caseType: [{ required: true, message: '案件类型不能为空!', trigger: 'blur' }],
recordType: [{ required: true, message: 'prompt标签不能为空!', trigger: 'blur' }],
prompt: [{ required: true, message: 'prompt内容不能为空!', trigger: 'blur' }],
queryLang: [{ required: true, message: '查询语句不能为空!', trigger: 'blur' }],
name: [{ required: true, message: '原子指标名称不能为空!', trigger: 'blur' }],
categoryIdPath: [{ required: true, message: '分类不能为空!', trigger: 'change' }],
promptId: [{ required: true, message: '查询语句不能为空!', trigger: 'change' }]
10 months ago
},
treeData: [],
10 months ago
// 是否是编辑
isEdit: false,
// 是否是查看
isView: false
}
},
methods: {
// 显示弹窗
show(data, isEdit) {
this.isEdit = isEdit
this.drawerOption.show = true
this.id = isEdit ? data.id : ''
this.selectInfo = {
promptName: '',
promptId: '',
extractAttributes: []
}
this.getTreeList()
this.$nextTick(() => {
const _this = this
6 months ago
const formData = data ? JSON.parse(JSON.stringify(data)) : { indexSource: '2' }
10 months ago
_this.isView = data && !isEdit
6 months ago
_this.ruleForm = data ? formData : (isEdit ? formData : { indexSource: '2' })
_this.drawerOption.hiddenFooter = _this.isView
6 months ago
this.selectInfo.extractAttributes = data.properties ? data.properties.split(',') : []
this.selectInfo.promptName = data.promptName
this.selectInfo.promptId = data.promptId
})
10 months ago
},
// 重置
handleReset() {
this.selectInfo = {
promptName: '',
promptId: '',
extractAttributes: []
}
this.$set(this.ruleForm, 'promptId', '')
if (this.isEdit) {
this.$set(this.ruleForm, 'name', '')
this.$set(this.ruleForm, 'remark', '')
} else {
6 months ago
this.ruleForm = { indexSource: '2' }
}
// this.$refs.form.clearValidate()
10 months ago
},
6 months ago
// 图谱调试
handleDebug() {
this.$refs.form.validate(async valid => {
if (valid) {
this.$refs.GraphDebugRef.show(this.ruleForm)
}
})
},
7 months ago
selectSql() {
this.$refs.SelectSqlRef.show(this.ruleForm.indexSource, this.selectInfo)
},
selectOk(data, list) {
this.selectInfo = data
this.$set(this.ruleForm, 'promptId', data.promptId)
// this.ruleForm.promptId = data.promptId
this.selectInfo.extractAttributes = list
7 months ago
},
10 months ago
// 确定
handleSubmit() {
this.$refs.form.validate(async valid => {
if (valid) {
if (this.isEdit) {
this.ruleForm.id = this.id
}
if (this.ruleForm.indexSource === '2') {
this.ruleForm.categoryId = this.ruleForm.categoryIdPath[this.ruleForm.categoryIdPath.length - 1 ]
} else if (this.ruleForm.indexSource === '5') {
this.ruleForm.properties = this.selectInfo.extractAttributes.join(',')
}
10 months ago
const { code, msg } = await addOrUpdAtomicIndex(this.ruleForm)
code === 200 ? (this.isEdit ? this.$baseMessage.success(msg || '编辑成功!') : this.$baseMessage.success(msg || '新增成功!')) : (this.isEdit ? this.$baseMessage.error(msg || '新增失败!') : this.$baseMessage.error(msg || '新增失败!'))
this.drawerOption.show = false
this.$emit('reloadData')
}
})
},
// 查询目录
getTreeList() {
getCaseEvidenceTree({ caseType: 1 }).then(res => {
if (res.code === 200) {
this.treeData = res.data
}
})
},
// 切换算法
changeType(val) {
this.ruleForm = { indexSource: val, caseType: this.ruleForm.caseType, name: this.ruleForm.name }
10 months ago
// this.ruleForm['indexSource'] = val
10 months ago
}
}
}
</script>
<style scoped lang="scss">
7 months ago
.add-atomic {
.select-btn {
width: 96px;
height: 36px;
background: #FFFFFF;
border-radius: 6px 6px 6px 6px;
border: 1px solid #3763FF;
line-height: 36px;
text-align: center;font-size: 16px;
color: #3763FF;
cursor: pointer;
margin-bottom: 8px;
7 months ago
}
.sel-name {
font-size: 16px;
7 months ago
color: #3763FF;
}
.sel-desc {
margin-top: 8px;font-size: 16px;
color: #333333
}
6 months ago
.sql_btn {
position: absolute;
right: 16px;
bottom: 16px;width: 112px;
height: 42px;
background: #FFFFFF;
border-radius: 6px 6px 6px 6px;
border: 1px solid #3763FF;
font-size: 16px;
color: #3763FF;
text-align: center;
line-height: 42px;
cursor: pointer;
}
7 months ago
.select-model-list {
display: flex;
margin-top: 16px;
flex-wrap: wrap;
7 months ago
.model-list-item {
padding: 0 12px;
height: 32px;
margin:0 8px 8px 0;
background: #F0F0F0;
border-radius: 6px 6px 6px 6px;font-size: 14px;
color: #333333;
display: flex;
align-items: center;
cursor: pointer;
7 months ago
span {
// margin-right: 16px;
7 months ago
}
}
}
}
10 months ago
</style>