Initial commit
This commit is contained in:
@@ -68,7 +68,7 @@
|
||||
:rules="[{ required: true, message: '请输入业务类型!', trigger: ['input', 'change'] }]"
|
||||
:name="['type']"
|
||||
>
|
||||
<a-select allow-clear v-model:value="selectedAlgorithm.type" @change="(v: any)=> selectedAlgorithm.type = v">
|
||||
<a-select placeholder="请选择业务类型" allow-clear v-model:value="selectedAlgorithm.type" @change="(v: any)=> selectedAlgorithm.type = v">
|
||||
<a-select-option v-for="a in algorithmTypes" :value="a.type">{{ a.name }}</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
@@ -81,14 +81,6 @@
|
||||
<a-input v-model:value="selectedAlgorithm.codePath" placeholder="请输入算法文件路径" />
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item
|
||||
label="算法配置"
|
||||
:rules="[{ required: true, message: '请输入算法配置', trigger: ['input', 'change'] }]"
|
||||
:name="['algoConfig']"
|
||||
>
|
||||
<a-textarea v-model:value="selectedAlgorithm.algoConfig" placeholder="请输入算法配置" />
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item
|
||||
label="算法描述"
|
||||
:rules="[{ required: false, message: '请输入算法描述', trigger: ['input', 'change'] }]"
|
||||
@@ -127,6 +119,39 @@
|
||||
</a-form-item-rest>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item
|
||||
label="算法配置"
|
||||
:rules="[{ required: false, message: '请输入算法配置', trigger: ['input', 'change'] }]"
|
||||
:name="['algoConfig']"
|
||||
>
|
||||
<a-form-item-rest>
|
||||
<div class="ks-algorithm-param-list">
|
||||
<div class="ks-algorithm-param-item" v-for="(t,index) in selectedAlgorithm.algoConfigList">
|
||||
<a-row :gutter="15">
|
||||
<a-col :span="7">
|
||||
<a-select placeholder="请选择参数" v-model:value="t.name" @change="(v: any)=> t.name = v">
|
||||
<a-select-option :value="v.paramName" v-for="v in selectedAlgorithm.algorithmParamList">{{v.paramName}}</a-select-option>
|
||||
</a-select>
|
||||
</a-col>
|
||||
<a-col :span="7">
|
||||
<a-select placeholder="请选择操作" v-model:value="t.operation" @change="(v: any)=> t.operation = v">
|
||||
<a-select-option :value="o.type" v-for="o in algorithmConfigOperations">{{o.name}} {{o.type}}</a-select-option>
|
||||
</a-select>
|
||||
</a-col>
|
||||
<a-col :span="3">
|
||||
<a-space class="ks-algorithm-param-actions">
|
||||
<MinusCircleOutlined @click="()=> handleMinusConfig(index)" />
|
||||
<PlusCircleOutlined @click="handleAddConfig" v-if="index === 0" />
|
||||
</a-space>
|
||||
</a-col>
|
||||
</a-row>
|
||||
</div>
|
||||
</div>
|
||||
</a-form-item-rest>
|
||||
|
||||
</a-form-item>
|
||||
|
||||
|
||||
<a-form-item
|
||||
:wrapper-col="{offset: 6}"
|
||||
>
|
||||
@@ -169,7 +194,7 @@ import Layout from '../layout.vue';
|
||||
import { createAlgorithm, deleteAlgorithm, findAlgorithmsByQuery, updateAlgorithm, runAlgorithm } from './api';
|
||||
import type { Algorithm, AlgorithmParam, AlgorithmRequest } from './types';
|
||||
import { substring } from '@/utils/strings';
|
||||
import { algorithmTypes } from './config';
|
||||
import { algorithmTypes,algorithmConfigOperations } from './config';
|
||||
import type { NullableString } from '@/types';
|
||||
|
||||
const query = ref<Partial<AlgorithmRequest>>({
|
||||
@@ -199,14 +224,46 @@ const defaultAlgorithm: Algorithm = {
|
||||
description: null,
|
||||
// 算法配置
|
||||
algoConfig: null,
|
||||
// 算法配置
|
||||
algoConfigList: [],
|
||||
// 算法参数定义信息
|
||||
algorithmParamList: [
|
||||
{ ...defaultAlgorithmParam },
|
||||
],
|
||||
};
|
||||
|
||||
|
||||
const resolveItem = (item: Algorithm) => {
|
||||
let newItem = JSON.parse(JSON.stringify(item))
|
||||
if (!newItem.algorithmParamList) {
|
||||
newItem.algorithmParamList = [];
|
||||
}
|
||||
if (newItem.algorithmParamList.length === 0) {
|
||||
newItem.algorithmParamList.push({ ...defaultAlgorithmParam });
|
||||
}
|
||||
|
||||
try{
|
||||
newItem.algoConfigList = JSON.parse(newItem.algoConfigList)
|
||||
} catch (e: any){
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
if(!newItem.algoConfigList){
|
||||
newItem.algoConfigList = []
|
||||
}
|
||||
|
||||
if(newItem.algoConfigList.length === 0){
|
||||
newItem.algoConfigList.push({
|
||||
name: undefined,
|
||||
operation: undefined,
|
||||
})
|
||||
}
|
||||
return newItem;
|
||||
};
|
||||
|
||||
const algorithms = ref<Algorithm[]>([]);
|
||||
const algorithmsTotal = ref<number>(0);
|
||||
const selectedAlgorithm = ref<Algorithm>(JSON.parse(JSON.stringify(defaultAlgorithm)));
|
||||
const selectedAlgorithm = ref<Algorithm>(resolveItem(defaultAlgorithm));
|
||||
const formRef = ref<FormInstance | null>(null);
|
||||
|
||||
const getAlgorithmTypeName = (type: NullableString): NullableString => {
|
||||
@@ -218,7 +275,7 @@ const load = () => {
|
||||
algorithms.value = [];
|
||||
algorithmsTotal.value = 0;
|
||||
formRef.value?.resetFields();
|
||||
selectedAlgorithm.value = JSON.parse(JSON.stringify(defaultAlgorithm));
|
||||
selectedAlgorithm.value = resolveItem(defaultAlgorithm);
|
||||
|
||||
findAlgorithmsByQuery(query.value).then(r => {
|
||||
algorithms.value = r.rows ?? [];
|
||||
@@ -226,19 +283,13 @@ const load = () => {
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
const handleCreate = () => {
|
||||
selectedAlgorithm.value = JSON.parse(JSON.stringify(defaultAlgorithm));
|
||||
selectedAlgorithm.value = resolveItem(defaultAlgorithm);
|
||||
};
|
||||
|
||||
const handleSelect = (item: Algorithm) => {
|
||||
let newItem = JSON.parse(JSON.stringify(item))
|
||||
if (!newItem.algorithmParamList) {
|
||||
newItem.algorithmParamList = [];
|
||||
}
|
||||
if (newItem.algorithmParamList.length === 0) {
|
||||
newItem.algorithmParamList.push({ ...defaultAlgorithmParam });
|
||||
}
|
||||
selectedAlgorithm.value = newItem;
|
||||
selectedAlgorithm.value = resolveItem(item);
|
||||
};
|
||||
|
||||
const handleAdd = () => {
|
||||
@@ -255,6 +306,20 @@ const handleMinus = (index: number) => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleAddConfig = () => {
|
||||
selectedAlgorithm.value.algoConfigList.push({ name: null, operation: null });
|
||||
};
|
||||
|
||||
const handleMinusConfig = (index: number) => {
|
||||
const paramList = selectedAlgorithm.value.algoConfigList;
|
||||
if (index === 0 && selectedAlgorithm.value.algoConfigList.length === 1) {
|
||||
selectedAlgorithm.value.algoConfigList = [{ name: null, operation: null }];
|
||||
} else if (index >= 0 && index < paramList.length && paramList.length > 1) {
|
||||
paramList.splice(index, 1);
|
||||
selectedAlgorithm.value.algoConfigList = [...paramList];
|
||||
}
|
||||
};
|
||||
|
||||
const handleDelete = () => {
|
||||
if (selectedAlgorithm.value && selectedAlgorithm.value.id > 0) {
|
||||
deleteAlgorithm(selectedAlgorithm.value.id).then(r => {
|
||||
@@ -272,11 +337,26 @@ const handleSave = () => {
|
||||
if (formRef.value) {
|
||||
formRef.value.validate().then(() => {
|
||||
let res = null;
|
||||
if (selectedAlgorithm.value.id > 0) {
|
||||
res = updateAlgorithm(selectedAlgorithm.value);
|
||||
} else {
|
||||
res = createAlgorithm(selectedAlgorithm.value);
|
||||
let savedValue: Algorithm = JSON.parse(JSON.stringify(selectedAlgorithm.value)) as any as Algorithm;
|
||||
let algoConfig = '';
|
||||
if( savedValue.algoConfigList ){
|
||||
savedValue.algoConfigList.forEach(o=> {
|
||||
if(o.name){
|
||||
algoConfig = algoConfig + o.name;
|
||||
}
|
||||
if(o.operation){
|
||||
algoConfig = algoConfig + o.operation;
|
||||
}
|
||||
})
|
||||
}
|
||||
savedValue.algoConfig = algoConfig;
|
||||
|
||||
if (savedValue.id > 0) {
|
||||
res = updateAlgorithm(savedValue);
|
||||
} else {
|
||||
res = createAlgorithm(savedValue);
|
||||
}
|
||||
|
||||
if (res) {
|
||||
res.then(r => {
|
||||
if (r.code === 200) {
|
||||
|
||||
Reference in New Issue
Block a user