|
|
@@ -1,6 +1,6 @@
|
|
|
<template>
|
|
|
- <lay-layer :title="modelConfig.title" v-model="modelConfig.visible" :area="['500px', '550px']" :btn="operator">
|
|
|
- <div style="padding: 20px">
|
|
|
+ <lay-layer :title="modelConfig.title" v-model="modelConfig.visible" :area="['500px', '550px']" :btn="modelConfig.step == 1 ? operator1 : operator2">
|
|
|
+ <div v-show="modelConfig.step == 1" style="padding: 20px">
|
|
|
<lay-form :model="modelParams" ref="modelFormRef" required>
|
|
|
<lay-form-item label="版本名称" prop="name">
|
|
|
<lay-input v-model="modelParams.name" />
|
|
|
@@ -8,58 +8,166 @@
|
|
|
<lay-form-item label="版本文件" prop="path">
|
|
|
<DragUpload v-model="modelParams.path" />
|
|
|
</lay-form-item>
|
|
|
- <lay-form-item label="备注" prop="remark">
|
|
|
- <lay-textarea placeholder="请输入备注" v-model="modelParams.remark" />
|
|
|
+ <lay-form-item label="更新说明" prop="updateInstructions">
|
|
|
+ <lay-textarea placeholder="请输入更新说明" v-model="modelParams.updateInstructions" />
|
|
|
</lay-form-item>
|
|
|
</lay-form>
|
|
|
</div>
|
|
|
+ <div v-show="modelConfig.step == 2" style="padding: 20px">
|
|
|
+ <lay-card class="custom-card">
|
|
|
+ <div class="operator-wp">
|
|
|
+ <lay-button class="custom-button-primary" @click="handleUpVersion()">引用上个版本</lay-button>
|
|
|
+ <lay-button class="custom-button-primary" @click="handleUpdate()">添加参数</lay-button>
|
|
|
+ </div>
|
|
|
+ <div class="table-wp">
|
|
|
+ <lay-table :page="tablePage" :columns="columns" resize :data-source="dataSource" :loading="modelConfig.loading" @change="handleCurrentChange">
|
|
|
+ <template v-slot:status="{ row }">
|
|
|
+ {{ row.status ? "启用" : "禁用" }}
|
|
|
+ </template>
|
|
|
+ <template v-slot:operator="{ row }">
|
|
|
+ <lay-space>
|
|
|
+ <TableButton text="编辑" @click="handleUpdate(row)" />
|
|
|
+ <TableButton type="danger" text="删除" @click="handleDelete(row)" />
|
|
|
+ </lay-space>
|
|
|
+ </template>
|
|
|
+ </lay-table>
|
|
|
+ </div>
|
|
|
+ </lay-card>
|
|
|
+ </div>
|
|
|
+ <UpdateParams ref="updateParams" />
|
|
|
</lay-layer>
|
|
|
</template>
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
import { ref, reactive, getCurrentInstance } from "vue";
|
|
|
-import { add_strategy, update_strategy } from "@/api";
|
|
|
+import TableButton from "@/components/TableButton.vue";
|
|
|
import DragUpload from "@/components/DragUpload.vue";
|
|
|
+import UpdateParams from "./UpdateParams.vue";
|
|
|
+import { add_strategy_program, update_strategy_program, get_strategy_program_params_list } from "@/api";
|
|
|
|
|
|
const { proxy }: any = getCurrentInstance();
|
|
|
+const updateParams = ref();
|
|
|
|
|
|
interface ModelConfig {
|
|
|
title: string;
|
|
|
visible: boolean;
|
|
|
isUpdate: boolean;
|
|
|
loading: boolean;
|
|
|
+ step: number;
|
|
|
}
|
|
|
interface ModelParams {
|
|
|
id?: string;
|
|
|
name?: string;
|
|
|
path?: string;
|
|
|
- remark?: string;
|
|
|
+ strategyId?: string;
|
|
|
+ updateInstructions?: string;
|
|
|
}
|
|
|
|
|
|
let modelParams = ref<ModelParams>({});
|
|
|
-let modelConfig: ModelConfig = reactive({ title: "", visible: false, isUpdate: false, loading: false });
|
|
|
+let modelConfig: ModelConfig = reactive({ step: 1, title: "", visible: false, isUpdate: false, loading: false });
|
|
|
|
|
|
let handleResult = reactive<{ resolve?: any; reject?: any }>({});
|
|
|
|
|
|
+interface FormItem {
|
|
|
+ pageNum?: number;
|
|
|
+ pageSize?: number;
|
|
|
+ strategyId?: string;
|
|
|
+}
|
|
|
+const pageParams: FormItem = reactive({ pageNum: 1, pageSize: 10 });
|
|
|
+
|
|
|
+interface TablePage {
|
|
|
+ current: number;
|
|
|
+ limit: number;
|
|
|
+ total: number;
|
|
|
+}
|
|
|
+const tablePage: TablePage = reactive({ current: 1, limit: 10, total: 0 });
|
|
|
+const columns = ref([
|
|
|
+ { title: "名称", key: "name" },
|
|
|
+ { title: "字段", key: "code" },
|
|
|
+ { title: "类型", key: "valType" },
|
|
|
+ { title: "默认值", key: "defaultVal" },
|
|
|
+ { title: "可选值", key: "contentVal" },
|
|
|
+ {
|
|
|
+ title: "操作",
|
|
|
+ customSlot: "operator",
|
|
|
+ key: "operator",
|
|
|
+ ignoreExport: true,
|
|
|
+ },
|
|
|
+]);
|
|
|
+let dataSource = ref<Array<any>>([]);
|
|
|
+
|
|
|
const show = (params: any, version?: any) => {
|
|
|
modelConfig.visible = true;
|
|
|
+ modelConfig.step = 1;
|
|
|
modelConfig.isUpdate = !!version;
|
|
|
modelConfig.title = modelConfig.isUpdate ? "编辑版本" : "添加版本";
|
|
|
- modelParams.value = modelConfig.isUpdate ? { ...params } : { status: 1 };
|
|
|
+ modelParams.value = modelConfig.isUpdate ? { ...version, strategyId: params.id } : { strategyId: params.id, status: 1 };
|
|
|
+ dataSource.value = modelConfig.isUpdate ? version.parameters : [];
|
|
|
return new Promise(async (resolve, reject) => {
|
|
|
handleResult.resolve = resolve;
|
|
|
handleResult.reject = reject;
|
|
|
});
|
|
|
};
|
|
|
-const operator = reactive([
|
|
|
+
|
|
|
+const handleUpVersion = async () => {
|
|
|
+ let result = await proxy.$waitingConfirm("引用参数会覆盖当前参数,确认引用?");
|
|
|
+ if (!result) return;
|
|
|
+ const params = { strategyId: modelParams.value.strategyId };
|
|
|
+ modelConfig.loading = true;
|
|
|
+ get_strategy_program_params_list(params, (data: any) => {
|
|
|
+ modelConfig.loading = false;
|
|
|
+ if (data.code == 200) {
|
|
|
+ dataSource.value = data.data;
|
|
|
+ }
|
|
|
+ });
|
|
|
+};
|
|
|
+
|
|
|
+const handleUpdate = async (value?: any) => {
|
|
|
+ const result = await updateParams.value.show(value);
|
|
|
+ if (result) {
|
|
|
+ const isUpdate = !!value;
|
|
|
+ if (isUpdate) {
|
|
|
+ dataSource.value = dataSource.value.map((item: any) => (result.id == value.id ? result : item));
|
|
|
+ } else {
|
|
|
+ dataSource.value.push({ ...result, id: -new Date() });
|
|
|
+ }
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+const handleDelete = async (value?: any) => {
|
|
|
+ let result = await proxy.$waitingConfirm("是否确认删除该参数?");
|
|
|
+ if (!result) return;
|
|
|
+ dataSource.value = dataSource.value.filter((item: any) => item.id != value.id);
|
|
|
+};
|
|
|
+
|
|
|
+const operator1 = reactive([
|
|
|
+ {
|
|
|
+ text: "下一步",
|
|
|
+ callback: () => {
|
|
|
+ modelConfig.step = 2;
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ text: "取消",
|
|
|
+ callback: () => {
|
|
|
+ modelConfig.visible = false;
|
|
|
+ handleResult.resolve(false);
|
|
|
+ },
|
|
|
+ },
|
|
|
+]);
|
|
|
+const operator2 = reactive([
|
|
|
{
|
|
|
text: "确认",
|
|
|
+ hidden: true,
|
|
|
callback: () => {
|
|
|
modelConfig.loading = true;
|
|
|
- console.log(modelParams.value)
|
|
|
if (modelConfig.isUpdate) {
|
|
|
- const params = { ...modelParams.value };
|
|
|
- update_strategy(params, (data: any) => {
|
|
|
+ const parameters = dataSource.value.map((item: any) => {
|
|
|
+ if (item.id < 0) item.id = undefined;
|
|
|
+ return item;
|
|
|
+ });
|
|
|
+ const params = { ...modelParams.value, parameters };
|
|
|
+ update_strategy_program(params, (data: any) => {
|
|
|
modelConfig.loading = false;
|
|
|
if (data.code == 200) {
|
|
|
proxy.$message("编辑成功!");
|
|
|
@@ -68,8 +176,12 @@ const operator = reactive([
|
|
|
}
|
|
|
});
|
|
|
} else {
|
|
|
- const params = { ...modelParams.value };
|
|
|
- add_strategy(params, (data: any) => {
|
|
|
+ const parameters = dataSource.value.map((item: any) => {
|
|
|
+ if (item.id < 0) item.id = undefined;
|
|
|
+ return item;
|
|
|
+ });
|
|
|
+ const params = { ...modelParams.value, parameters };
|
|
|
+ add_strategy_program(params, (data: any) => {
|
|
|
modelConfig.loading = false;
|
|
|
if (data.code == 200) {
|
|
|
proxy.$message("添加成功!");
|
|
|
@@ -80,6 +192,12 @@ const operator = reactive([
|
|
|
}
|
|
|
},
|
|
|
},
|
|
|
+ {
|
|
|
+ text: "上一步",
|
|
|
+ callback: () => {
|
|
|
+ modelConfig.step = 1;
|
|
|
+ },
|
|
|
+ },
|
|
|
{
|
|
|
text: "取消",
|
|
|
callback: () => {
|
|
|
@@ -88,5 +206,10 @@ const operator = reactive([
|
|
|
},
|
|
|
},
|
|
|
]);
|
|
|
+
|
|
|
+// 分页设置
|
|
|
+const handleCurrentChange = (val: any) => {
|
|
|
+ pageParams.pageNum = val.current;
|
|
|
+};
|
|
|
defineExpose({ show });
|
|
|
</script>
|