Files
ccdi/ruoyi-ui/src/views/ccdiProject/components/AddProjectDialog.vue

178 lines
3.9 KiB
Vue
Raw Normal View History

2026-01-30 11:01:13 +08:00
<template>
<el-dialog
:visible.sync="dialogVisible"
:title="title"
width="600px"
:close-on-click-modal="false"
:close-on-press-escape="false"
@close="handleClose"
>
<el-form
ref="projectForm"
:model="formData"
:rules="rules"
label-width="100px"
label-position="right"
>
<!-- 项目名称 -->
<el-form-item label="项目名称" prop="projectName">
<el-input
v-model="formData.projectName"
placeholder="请输入项目名称"
maxlength="100"
2026-01-30 11:01:13 +08:00
show-word-limit
/>
</el-form-item>
<!-- 项目描述 -->
<el-form-item label="项目描述" prop="description">
2026-01-30 11:01:13 +08:00
<el-input
v-model="formData.description"
2026-01-30 11:01:13 +08:00
type="textarea"
:rows="4"
2026-01-30 11:01:13 +08:00
placeholder="请输入项目描述"
maxlength="500"
2026-01-30 11:01:13 +08:00
show-word-limit
/>
</el-form-item>
<!-- 配置方式 -->
<el-form-item label="配置方式" prop="configType">
<el-radio-group v-model="formData.configType">
<el-radio label="default">全局默认模型参数配置</el-radio>
<el-radio label="custom">自定义项目规则参数配置</el-radio>
</el-radio-group>
2026-01-30 11:01:13 +08:00
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="handleClose"> </el-button>
<el-button type="primary" :loading="submitting" @click="handleSubmit">
创建项目
2026-01-30 11:01:13 +08:00
</el-button>
</div>
</el-dialog>
</template>
<script>
import { createProject } from '@/api/ccdiProject'
2026-01-30 11:01:13 +08:00
export default {
name: 'AddProjectDialog',
props: {
visible: {
type: Boolean,
default: false
},
title: {
type: String,
default: '新建项目'
},
form: {
type: Object,
default: () => ({})
}
},
data() {
return {
submitting: false,
formData: {
projectName: '',
description: '',
configType: 'default'
2026-01-30 11:01:13 +08:00
},
rules: {
projectName: [
{ required: true, message: '请输入项目名称', trigger: 'blur' },
{ min: 2, max: 100, message: '长度在 2 到 100 个字符', trigger: 'blur' }
2026-01-30 11:01:13 +08:00
],
configType: [
{ required: true, message: '请选择配置方式', trigger: 'change' }
2026-01-30 11:01:13 +08:00
]
}
}
},
computed: {
dialogVisible: {
get() {
return this.visible
},
set(val) {
if (!val) {
this.handleClose()
}
}
}
},
watch: {
form: {
handler(newVal) {
if (newVal && Object.keys(newVal).length > 0) {
this.formData = { ...this.formData, ...newVal }
}
},
immediate: true,
deep: true
},
visible(val) {
if (val) {
this.$nextTick(() => {
if (this.$refs.projectForm) {
this.$refs.projectForm.clearValidate()
}
})
}
}
},
methods: {
/** 提交表单 */
handleSubmit() {
this.$refs.projectForm.validate(valid => {
if (valid) {
this.submitting = true
createProject(this.formData).then(response => {
this.$message.success('项目创建成功')
this.submitting = false
this.$emit('submit', response.data)
this.handleClose()
}).catch(() => {
2026-01-30 11:01:13 +08:00
this.submitting = false
})
2026-01-30 11:01:13 +08:00
}
})
},
2026-01-30 11:01:13 +08:00
/** 关闭对话框 */
handleClose() {
this.$emit('close')
this.$refs.projectForm.resetFields()
this.formData = {
projectName: '',
description: '',
configType: 'default'
2026-01-30 11:01:13 +08:00
}
}
}
}
</script>
<style lang="scss" scoped>
.dialog-footer {
text-align: right;
.el-button + .el-button {
margin-left: 8px;
}
}
:deep(.el-radio-group) {
display: flex;
flex-direction: column;
gap: 12px;
.el-radio {
line-height: 32px;
}
}
2026-01-30 11:01:13 +08:00
</style>