JavaProjectRepo/business-css/frontend/src/views/component/scenario/index.vue

509 lines
15 KiB
Vue
Raw Normal View History

2025-12-26 11:33:50 +08:00
<script lang="ts">
export default {
name: "scenario-事故情景",
};
</script>
<script setup lang="ts">
import { onMounted, ref, nextTick } from "vue";
import { ElForm, ElMessage, ElMessageBox } from "element-plus";
2025-12-26 17:27:12 +08:00
import { searchScenariosLsit,addScenarios,updateScenarios,deleteScenarios,deleteBatchScenarios} from "@/api/business/scenario";
2025-12-26 11:33:50 +08:00
import Page from '@/components/Pagination/page.vue'
2025-12-26 17:27:12 +08:00
import { getDictItemById } from '@/api/dict';
2025-12-31 09:11:08 +08:00
import ConditionModel from '@/views/component/scenario/condition.vue'
2025-12-26 17:27:12 +08:00
const algorithmTypeData: any = ref([]); // 算法类型数据
const stepsActive = ref(0); // 步骤导航栏当前激活的步骤索引
const props = defineProps({ // 接收父组件传递的项目信息
projectInfo: {
required: true,
type: Object,
default: {}
}
});
2025-12-26 11:33:50 +08:00
// 搜索框
const queryParams = ref({
current: 1,
size: 10,
querystr: ''
});
//分页 总条数
const total = ref()
//定义表格数据
const tableData: any = ref([]);
const multipleSelection = ref([]);
// 表格加载
const loading = ref(false)
function gettableData() {
let params = {
2025-12-26 17:27:12 +08:00
projectId: props.projectInfo.projectId,
2025-12-26 11:33:50 +08:00
name: input.value,
pageNum: queryParams.value.current,
pageSize: queryParams.value.size,
};
loading.value = true;
2025-12-26 17:27:12 +08:00
searchScenariosLsit(params).then((result:any) => {
2025-12-26 11:33:50 +08:00
tableData.value = result.records;
total.value = result.total;
loading.value = false;
}).catch((err) => {
loading.value = false;
});
}
//表格多选事件
function handleSelectionChange(val: any) {
multipleSelection.value = val;
}
const infoForm = ref();
//搜索内容及点击搜索按钮
const input = ref("");
//新建事故情景
const title = ref("");
const info: any = ref({
name: "",
code: "",
description: "",
});
2025-12-31 09:11:08 +08:00
const scenarioId = ref(""); // 事故情景id
2025-12-26 11:33:50 +08:00
const dialogVisible = ref(false);
function addClick() {
title.value = "新增事故情景";
info.value = {
name: "",
code: "",
description: "",
};
2025-12-26 17:27:12 +08:00
stepsActive.value = 0;
2025-12-26 11:33:50 +08:00
dialogVisible.value = true;
}
2025-12-31 09:11:08 +08:00
const isSwitch = ref(false); // 事故情景id
2025-12-26 11:33:50 +08:00
//新建事故情景-确认按钮/修改按钮
function confirmClick(formEl: any) {
console.log(info.value)
formEl.validate((valid: any) => {
if (valid) {
2025-12-26 17:27:12 +08:00
if (!info.value.scenarioId) {
2025-12-26 11:33:50 +08:00
const params = {
2025-12-26 17:27:12 +08:00
projectId: props.projectInfo.projectId,
2025-12-26 11:33:50 +08:00
name: info.value.name,
2025-12-26 17:27:12 +08:00
algorithmType: info.value.algorithmType,
2025-12-26 11:33:50 +08:00
description: info.value.description,
};
2025-12-31 09:11:08 +08:00
if(isSwitch.value == true){
return ;
}
isSwitch.value = true
2025-12-26 17:27:12 +08:00
addScenarios(params).then((res:any) => {
2025-12-31 09:11:08 +08:00
isSwitch.value = false;
if(res && res.code == 0) {
scenarioId.value = res.scenarioId;
2025-12-26 17:27:12 +08:00
gettableData();
ElMessage({
type: "success",
message: "新增成功",
});
stepsActive.value = 1;
} else {
ElMessage({
type: "error",
message: "新增失败",
});
}
2025-12-31 09:11:08 +08:00
}).catch(() => {
isSwitch.value = false;
})
2025-12-26 17:27:12 +08:00
} else if (info.value.scenarioId) {
2025-12-26 11:33:50 +08:00
const params = {
2025-12-26 17:27:12 +08:00
scenarioId: info.value.scenarioId,
projectId: info.value.projectId,
2025-12-26 11:33:50 +08:00
name: info.value.name,
2025-12-26 17:27:12 +08:00
algorithmType: info.value.algorithmType,
2025-12-26 11:33:50 +08:00
description: info.value.description,
};
2025-12-26 17:27:12 +08:00
updateScenarios(params).then((res) => {
2025-12-26 11:33:50 +08:00
gettableData();
dialogVisible.value = false;
});
} else {
return false;
}
}
});
}
//新建角色-取消按钮
function handleClose() {
dialogVisible.value = false;
if (infoForm.value != null) infoForm.value.resetFields();
}
2025-12-26 17:27:12 +08:00
function handleScenarioClose(){
dialogVisible.value = false;
gettableData();
if (infoForm.value != null) infoForm.value.resetFields();
}
2025-12-26 11:33:50 +08:00
//新建事故情景
const rules = ref({
name: [{ required: true, message: "请输入事故情景名称", trigger: "blur" }],
2025-12-26 17:27:12 +08:00
algorithmType: [{ required: true, message: "请选择算法类型", trigger: "change" }],
2025-12-26 11:33:50 +08:00
});
//修改事故情景
function editClick(row: any) {
title.value = "修改事故情景";
info.value = JSON.parse(JSON.stringify(row));
dialogVisible.value = true;
}
//删除事故情景
function delAloneClick(row: any) {
ElMessageBox.confirm("确定删除此事故情景吗?", "删除提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
})
.then(() => {
let params = {
2025-12-26 17:27:12 +08:00
id: row.scenarioId,
2025-12-26 11:33:50 +08:00
};
2025-12-26 17:27:12 +08:00
deleteScenarios(params).then(() => {
2025-12-26 11:33:50 +08:00
gettableData();
ElMessage({
type: "success",
message: "删除成功",
});
});
})
}
// 多选删除?
function delClick() {
ElMessageBox.confirm("确定删除已选择角色吗?", "删除提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
}).then(() => {
let id = [] as any[];
multipleSelection.value.forEach((item: any) => {
2025-12-26 17:27:12 +08:00
id.push(item.scenarioId)
2025-12-26 11:33:50 +08:00
})
let params = {
ids: id,
};
2025-12-26 17:27:12 +08:00
deleteBatchScenarios(params.ids).then(() => {
2025-12-26 11:33:50 +08:00
gettableData();
ElMessage({
message: "删除成功",
type: "success",
});
});
});
}
function dateFormat(row: any) {
const daterc = row;
if (daterc != null) {
var date = new Date(daterc);
var year = date.getFullYear();
var month =
date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
// 拼接
return year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;
}
}
2025-12-26 17:27:12 +08:00
const getAlgorithmType = async () => {
try {
let params = {
dictId: '595502b91e7741b5033b53622d8731a3',
size:99,
current:1
}
const result:any = await getDictItemById(params);
if (result.code == '0') {
algorithmTypeData.value = result.data.records
}
} catch (error) {
}
}
2025-12-31 09:11:08 +08:00
const conditionModel = ref()
function submitClick(){
conditionModel.value?.submitClick()
}
2025-12-26 11:33:50 +08:00
onMounted(() => {
2025-12-26 17:27:12 +08:00
getAlgorithmType()
2025-12-26 11:33:50 +08:00
gettableData();
});
</script>
<template>
<div class="scenario-box">
<div class="conductscenario-bg-box">
<div class="scenario-search-box"
style="display: flex;display: -webkit-flex; justify-content: space-between; -webkit-justify-content: space-between;margin-bottom: 10px">
<div style="display: flex;display: -webkit-flex;">
<el-input v-model="input" placeholder="请输入事故情景名称" @keyup.enter="gettableData" style="width: 200px" clearable />
<el-button type="primary" style="margin-left: 10px" @click="gettableData">搜索</el-button>
</div>
<div>
<el-button type="primary" @click="addClick">
新增</el-button>
<el-button :type="multipleSelection.length > 0 ? 'primary' : ''"
:disabled="multipleSelection.length <= 0" @click="delClick">删除</el-button>
</div>
</div>
<el-table v-loading="loading" :data="tableData" style="width: 100%; height: calc(100vh - 260px);margin-bottom: 10px;" border
@selection-change="handleSelectionChange"
:header-cell-style="{ background: 'rgb(250 250 250)', color: '#383838', height: '50px' }">
<el-table-column type="selection" width="50" align="center"></el-table-column>
2025-12-26 17:27:12 +08:00
<el-table-column prop="name" label="事故情景名称" min-width="180"></el-table-column>
<el-table-column prop="name" label="算法模型" min-width="180"></el-table-column>
2025-12-26 11:33:50 +08:00
<el-table-column prop="updatedAt" label="模拟时间" width="200">
<template #default="scope">
<span v-if="scope.row.updatedAt != null">{{ dateFormat(scope.row.updatedAt) }}</span>
<span v-else>--</span>
</template>
</el-table-column>
2025-12-26 17:27:12 +08:00
<el-table-column prop="updatedAt" label="状态" width="100">
2025-12-26 11:33:50 +08:00
<template #default="scope">
2025-12-26 17:27:12 +08:00
<span v-if="scope.row.status == 0" style="color: #0099FF;">初始创建</span>
<span v-else-if="scope.row.status == 1" style="color: #FF9900;">进行中</span>
<span v-else style="color: #009933;">已完成</span>
2025-12-26 11:33:50 +08:00
</template>
</el-table-column>
<el-table-column fixed="right" label="操作" width="190">
<template #default="scope">
<span
style="display: flex;display: -webkit-flex; justify-content: space-around;-webkit-justify-content: space-around; ">
<img src="@/assets/table/edit.png" alt="" title="修改"
@click="editClick(scope.row)" style="cursor: pointer; ">
<img src="@/assets/table/design.png" alt="" title="分享设计"
style="cursor: pointer; ">
<img src="@/assets/table/simulation.png" alt="" title="模拟分析"
style="cursor: pointer; ">
<img src="@/assets/table/export.png" alt="" title="导出事故情景工程"
style="cursor: pointer; ">
<img src="@/assets/table/del.png" alt="" title="删除"
@click="delAloneClick(scope.row)" style="cursor: pointer; ">
</span>
</template>
</el-table-column>
</el-table>
<Page :total="total" v-model:size="queryParams.size" v-model:current="queryParams.current" @pagination="gettableData()" ></Page>
</div>
<el-dialog v-model="dialogVisible" :close-on-click-modal="false"
2025-12-31 09:11:08 +08:00
:modal="false" draggable :before-close="handleScenarioClose" title="新增事故情景"
2025-12-26 17:27:12 +08:00
append-to-body width="1000px">
<div class="scenario-setting-box">
<el-steps style="width: 500px;margin:0 auto " :active="stepsActive" align-center>
<el-step title="事故情景设置"/>
<el-step title="初始条件设置" />
<!-- <el-step title="确认模拟" /> -->
</el-steps>
</div>
<div class="scenario-setting-bottombox">
2025-12-31 09:11:08 +08:00
<el-form ref="infoForm" :model="info" :rules="rules" label-width="140px" style="width:600px"
v-if="stepsActive == 1">
2025-12-26 17:27:12 +08:00
<el-form-item label="事故情景名称:" prop="name">
<el-input v-model="info.name" style="width: 100%" placeholder="输入事故情景名称" ></el-input>
</el-form-item>
<el-form-item label="算法类型:" prop="algorithmType">
<el-select v-model="info.algorithmType" placeholder="请选择" style="width:100%;" clearable>
<el-option v-for="item in algorithmTypeData" :key="item.id" :label="item.dictName" :value="item.itemCode" />
</el-select>
</el-form-item>
<el-form-item label="事故情景描述:">
<el-input type="textarea" v-model="info.description" :rows="6" style="width: 100%" placeholder="请输入事故情景描述"></el-input>
</el-form-item>
</el-form>
2025-12-31 09:11:08 +08:00
<ConditionModel v-if="stepsActive == 0" ref="conditionModel" :projectInfo="projectInfo" :scenarioId="scenarioId" />
2025-12-26 17:27:12 +08:00
</div>
<div style="text-align: center;">
2025-12-31 09:11:08 +08:00
<el-button v-if="stepsActive == 1" type="primary" @click="confirmClick(infoForm)">下一步</el-button>
<el-button v-else type="primary" @click="submitClick">下一步2</el-button>
2025-12-26 17:27:12 +08:00
</div>
2025-12-26 11:33:50 +08:00
</el-dialog>
</div>
</template>
<style scoped>
.scenario-box {
padding-right: 10px;
}
:deep(.el-tree-node__content) {
font-size: 15px;
font-weight: 500;
width: 100%;
height: 40px;
}
.dialog-footer {
display: block;
margin-top: 20px;
}
.conductscenario-bg-box {
padding: 0px;
width: 100%;
height: calc(100vh - 130px);
overflow: auto;
background-color: rgba(255, 255, 255, 1);
border: none;
border-radius: 3px;
box-sizing: border-box;
padding-bottom: 10px;
}
.line {
height: 1px;
background: rgba(240, 241, 242, 1);
margin-top: 12px;
}
.menuspan {
display: inline-block;
width: 120px;
font-size: 14px;
font-family: "微软雅黑";
font-weight: 400;
font-style: normal;
color: #787878;
}
</style>
<style>
.el-dialog {
padding: 0 !important;
border-radius: 10px !important;
border: 1px solid #363636 !important;
}
.el-dialog .el-dialog__header{
display: flex;
display: -webkit-flex;
justify-content: flex-start;-webkit-justify-content: flex-start;
align-items: center;-webkit-align-items: center;
padding: 10px 20px;
background-color: #f1f3f8 !important;
font-family: 'Arial Negreta', 'Arial Normal', 'Arial', sans-serif;
font-weight: 700;
font-style: normal;
font-size: 16px;
color: #1B1B1B;
text-align: left;
border-radius: 10px 10px 0 0;
height: 50px;
}
.el-dialog .el-dialog__close{
font-size: 22px;
color: rgb(80, 80, 80);
}
.el-dialog .el-dialog__headerbtn{
display: flex;
align-items: center;
}
.el-dialog .el-dialog__body{
padding: 20px 40px !important;
}
.el-dialog .el-input{
--el-input-inner-height: 38px
}
2025-12-26 17:27:12 +08:00
.el-dialog .el-select__wrapper{
height: 40px
}
2025-12-26 11:33:50 +08:00
.scenario-search-box .el-button{
height: 36px !important;
}
.el-dialog .el-button{
height: 40px;
}
2025-12-26 17:27:12 +08:00
.scenario-setting-box{
width: 900px;
height: 100px;
background: inherit;
background-color: rgba(255, 255, 255, 1);
border: none;
border-radius: 5px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
margin: 0 auto;
display: flex;
justify-content: center;
align-items: center;
}
.scenario-setting-box .el-step__icon.is-text{
width: 30px;
height: 30px;
line-height: 30px;
background-color: #c9c9c9 ;
border-color: #c9c9c9 ;
color: #fff;
}
.scenario-setting-box .is-finish .el-step__icon.is-text{
width: 30px;
height: 30px;
line-height: 30px;
background-color: #266fff ;
border-color: #266fff ;
color: #fff;
}
.scenario-setting-box .is-process .el-step__icon.is-text{
width: 30px;
height: 30px;
line-height: 30px;
background-color: #266fff ;
border-color: #266fff ;
color: #fff;
}
.scenario-setting-box .el-step__title{
font-family: 'Arial Normal', 'Arial', sans-serif;
font-weight: 400;
font-style: normal;
font-size: 16px;
letter-spacing: normal;
}
.scenario-setting-box .el-step__title.is-finish{
color: #266fff ;
}
.scenario-setting-box .el-step__title.is-process{
color: #266fff ;
}
.scenario-setting-box .el-step__line{
height: 1px !important;
background-color: #ebebeb !important;
}
.scenario-setting-bottombox{
width: 900px;
height: calc(100vh - 300px);
background: inherit;
background-color: rgba(255, 255, 255, 1);
border: none;
border-radius: 5px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
margin: 20px auto;
display: flex;
justify-content: center;
align-items: center;
}
2025-12-26 11:33:50 +08:00
</style>