潘志宝
2024-09-14 36730eac964e814a4fc9a0879c499e326fc00ac8
src/views/model/mcs/sche/scheme/ScheduleSchemeForm.vue
@@ -9,216 +9,75 @@
    >
      <el-row>
        <el-col :span="12">
          <el-form-item label="模型编号" prop="modelCode">
            <el-input v-model="formData.modelCode" placeholder="请输入模型编号" />
          <el-form-item label="方案编号" prop="code">
            <el-input v-model="formData.code" placeholder="请输入方案编号" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="模型名称" prop="modelName">
            <el-input v-model="formData.modelName" placeholder="请输入模型名称" />
          <el-form-item label="方案名称" prop="name">
            <el-input v-model="formData.name" placeholder="请输入方案名称" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="模型类型" prop="modelType">
            <el-input v-model="formData.modelType" placeholder="请输入模型类型" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="调用方式" prop="invocation">
            <el-input v-model="formData.invocation" placeholder="调用方式" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="类名" prop="className">
            <el-input v-model="formData.className" placeholder="请输入类名 " />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="方法名" prop="methodName">
            <el-input v-model="formData.methodName" placeholder="请输入方法名 " />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="参数数量" prop="portLength">
            <el-input v-model="formData.portLength" placeholder="请输入参数数量 " />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="参数构造" prop="paramStructure">
            <el-input v-model="formData.paramStructure" placeholder="请输入参数构造 " />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="模型路径" prop="modelPath">
            <el-input v-model="formData.modelPath" placeholder="模型路径 " />
          </el-form-item>
        </el-col>
      </el-row>
      <el-divider content-position="left">输入参数</el-divider>
      <el-table
        :data="formData.paramList"
        border
        style="width: 100%; margin-top: 5px;">
        <el-table-column
          prop=""
          label="端口"
          width="100"
          align="center">
          <template slot-scope="scope">
            <el-input size="mini" v-model="scope.row.modelparamportorder" maxlength="5" clearable
                      style="width:100%;hight:100%"></el-input>
          </template>
        </el-table-column>
        <el-table-column
          prop=""
          label="序号"
          width="100"
          align="center">
          <template slot-scope="scope">
            <el-input size="mini" v-model="scope.row.modelparamorder" maxlength="5" clearable
                      style="width:100%;hight:100%"></el-input>
          </template>
        </el-table-column>
        <el-table-column
          prop=""
          label="类型"
          width="150"
          align="center">
          <template slot-scope="scope">
            <el-select v-model="scope.row.modelparamtype" placeholder="请选择">
          <el-form-item label="触发方式" prop="triggerMethod">
            <el-select v-model="formData.triggerMethod" placeholder="请选择">
              <el-option
                v-for="dict in getIntDictOptions(DICT_TYPE.MODEL_PARAM_TYPE)"
                v-for="dict in getIntDictOptions(DICT_TYPE.SCHE_TRIGGER_METHOD)"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </template>
        </el-table-column>
        <el-table-column
          prop=""
          label="参数名称"
          align="center">
          <template slot-scope="scope">
            <el-select
              size="mini"
              v-model="scope.row.modelparamid"
              filterable
              placeholder="请选择">
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="触发条件" prop="triggerCondition">
            <el-input v-model="formData.triggerCondition" placeholder="请输入触发条件" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="调整对象" prop="scheduleObj">
            <el-input v-model="formData.scheduleObj" placeholder="请输入调整对象" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="调整类型" prop="scheduleType">
            <el-input v-model="formData.scheduleType" placeholder="请输入调整类型" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="调整策略" prop="scheduleStrategy">
            <el-input v-model="formData.scheduleStrategy" placeholder="请输入调整策略 " />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="调度模型" prop="modelId">
            <el-select v-model="formData.modelId" clearable placeholder="请选择调度模型">
              <el-option
                v-for="(item, index) in modelparamListMap[scope.row.modelparamtype]"
                :key="index"
                :label="item.name"
                v-for="item in scheduleModelList"
                :key="item.id"
                :label="item.modelName"
                :value="item.id"
                :disabled="!(item.type === scope.row.modelparamtype)">
              </el-option>
              />
            </el-select>
          </template>
        </el-table-column>
        <el-table-column
          prop=""
          label="参数长度"
          width="120"
          align="center">
          <template slot-scope="scope">
            <el-input size="mini" v-model="scope.row.datalength" maxlength="50" clearable
                      style="width:100%;hight:100%"></el-input>
          </template>
        </el-table-column>
        <el-table-column
          prop=""
          label="操作"
          width="100"
          align="center">
          <template slot-scope="scope">
            <el-button
              @click.native.prevent="addRow(scope.$index, formData.paramList)"
              type="text"
              size="small">
              添加
            </el-button>
            <el-button
              @click.native.prevent="deleteRow(scope.$index, formData.paramList)"
              type="text"
              size="small">
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-divider content-position="left">设置参数</el-divider>
      <el-table
        :data="formData.paramList"
        border
        style="width: 100%; margin-top: 5px;">
        <el-table-column
          prop=""
          label="键"
          align="center">
          <template slot-scope="scope">
            <el-input size="mini" v-model="scope.row.key" maxlength="256" clearable
                      style="width:100%;hight:100%"></el-input>
          </template>
        </el-table-column>
        <el-table-column
          prop=""
          label="名称"
          align="center">
          <template slot-scope="scope">
            <el-input size="mini" v-model="scope.row.name" maxlength="256" clearable
                      style="width:100%;hight:100%"></el-input>
          </template>
        </el-table-column>
        <el-table-column
          prop=""
          label="类型"
          align="center">
          <template slot-scope="scope">
            <el-input size="mini" v-model="scope.row.valuetype" maxlength="256" clearable
                      style="width:100%;hight:100%"></el-input>
          </template>
        </el-table-column>
        <el-table-column
          prop=""
          label="值"
          align="center">
          <template slot-scope="scope">
            <el-input size="mini" v-model="scope.row.value" maxlength="256" clearable
                      style="width:100%;hight:100%"></el-input>
          </template>
        </el-table-column>
        <el-table-column
          prop=""
          label="操作"
          width="100"
          align="center">
          <template slot-scope="scope">
            <el-button
              @click.native.prevent="addRow(scope.$index, formData.settingList)"
              type="text"
              size="small">
              添加
            </el-button>
            <el-button
              @click.native.prevent="deleteRow(scope.$index, formData.settingList)"
              type="text"
              size="small">
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="备注" prop="remark">
            <el-input v-model="formData.remark" placeholder="请输入备注"  type="textarea" maxlength="100"
                      show-word-limit/>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <template #footer>
      <el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button>
@@ -228,11 +87,11 @@
</template>
<script lang="ts" setup>
  import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  import * as ScheduleModelApi from '@/api/model/sche/model'
  import * as ScheduleSchemeApi from '@/api/model/sche/scheme'
  import { CommonStatusEnum } from '@/utils/constants'
  import * as DataSourceConfigApi from "@/api/infra/dataSourceConfig";
  import * as ScheduleModelApi from "@/api/model/sche/model";
  defineOptions({ name: 'ScheduleModelForm' })
  defineOptions({ name: 'ScheduleSchemeForm' })
  const { t } = useI18n() // 国际化
  const message = useMessage() // 消息弹窗
@@ -259,7 +118,7 @@
    name: [{ required: true, message: '名称不能为空', trigger: 'blur' }]
  })
  const formRef = ref() // 表单 Ref
  const modelparamListMap = ref([] as ScheduleModelApi.ModelParamVO[])
  const scheduleModelList = ref([] as ScheduleModelApi.ScheduleModelVO[])
  const addRow = function (index, rows) {
    let row = JSON.parse(JSON.stringify(rows[index]))
@@ -299,14 +158,13 @@
    if (id) {
      formLoading.value = true
      try {
        formData.value = await ScheduleModelApi.getScheduleModel(id)
        formData.value = await ScheduleSchemeApi.getScheduleScheme(id)
      } finally {
        formLoading.value = false
      }
      // 加载数据源列表
      modelparamListMap.value = await ScheduleModelApi.getModelParamList()
    }
    // 加载调度模型列表
    scheduleModelList.value = await ScheduleModelApi.getScheduleModelList()
  }
  defineExpose({ open }) // 提供 open 方法,用于打开弹窗
@@ -320,12 +178,12 @@
    // 提交请求
    formLoading.value = true
    try {
      const data = formData.value as unknown as ScheduleModelApi.ScheduleModelVO
      const data = formData.value as unknown as ScheduleSchemeApi.ScheduleSchemeVO
      if (formType.value === 'create') {
        await ScheduleModelApi.createScheduleModel(data)
        await ScheduleSchemeApi.createScheduleScheme(data)
        message.success(t('common.createSuccess'))
      } else {
        await ScheduleModelApi.updateScheduleModel(data)
        await ScheduleSchemeApi.updateScheduleScheme(data)
        message.success(t('common.updateSuccess'))
      }
      dialogVisible.value = false
@@ -350,7 +208,7 @@
      modelId: undefined,
      scheduleTime: undefined,
      remark: undefined,
      status: 0
      status: CommonStatusEnum.ENABLE
    }
    formRef.value?.resetFields()
  }