算法平台中的计算模块实现

x33g5p2x  于2022-08-17 转载在 其他  
字(2.9k)|赞(0)|评价(0)|浏览(380)

一 需求说明

1 本需求采用了微同科技开源脚手架。

2 在该脚手架的基础上,实现算法平台。

3 计算模块主要是对题目的输入进行运算,然后输出结果

二 原型设计

三 代码实现

1 前端

<template>
  <el-dialog
    :title="'计算'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="thisDataForm" :rules="dataRule" ref="dataForm"
             label-width="80px">
      <el-form-item label="数据输入" prop="input">
        <el-input type="textarea"
                  :autosize="{ minRows: 5, maxRows: 8}"
                  v-model="thisDataForm.input" :disabled="disabled" placeholder="数据输入"></el-input>
      </el-form-item>
      <el-form-item label="数据输出" prop="output">
        <el-input type="textarea"
                  :autosize="{ minRows: 5, maxRows: 8}"
                  v-model="thisDataForm.output" :disabled="!disabled" placeholder="数据输出"></el-input>
      </el-form-item>
      <el-form-item label="算法耗时" prop="cost">
        <el-input v-model="thisDataForm.cost" :disabled="!disabled" placeholder="算法耗时"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button v-if="!disabled" type="primary" @click="dataFormSubmit()">计算</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        disabled: false,
        visible: false,
        dataForm: {
          id: 0,
          title: '',
          code: '',
          introduce: '',
          inputExplain: '',
          outputExplain: '',
          applicationScenario: '',
          titleLink: '',
          remark: ''
        },
        thisDataForm: {
          id: 0,
          input: '',
          output: '',
          cost: ''
        },
        dataRule: {
          name: [
            {required: true, message: '名称不能为空', trigger: 'blur'}
          ]
        }
      }
    },
    methods: {
      init (id, disabled) {
        this.disabled = disabled
        this.dataForm.id = id || ''
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: `/alg/subject/info/${this.dataForm.id}`,
              method: 'get'
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm = data.subject
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm']
          .validate((valid) => {
            if (valid) {
              this.$http({
                url: `/alg/subject/cal`,
                method: 'post',
                data: this.dataForm
              }).then(({data}) => {
                if (data && data.code === 0) {
                  this.$message({
                    message: '操作成功',
                    type: 'success',
                    duration: 1500
                  })
                  this.visible = true
                  this.thisDataForm.cost = data.cost
                  this.thisDataForm.output = data.output
                  debugger
                  this.$emit('refreshDataList')
                }
              })
            }
          })
      }
    }
  }
</script>

2 后台

/**
* 算法计算
*
* @param algSubject algSubject
* @return RestResponse
*/
@SysLog("计算")
@RequestMapping("/cal")
@RequiresPermissions("alg:subject:save")
public RestResponse cal(@RequestBody AlgSubjectEntity algSubject) {
    logger.info("start");

    return RestResponse.success().put("output","reulst").put("cost","cost");
}

四 测试

1 点击题目的计算功能

2 弹出计算框

3 在数据输入中输入对应的值,然后点击计算,得出结果

五 说明

这里只是把框架搭建起来了,具体算法是要写的。后面再慢慢把算法加进来。

相关文章