|
|
@@ -41,6 +41,7 @@
|
|
|
</el-input>
|
|
|
</el-form-item>
|
|
|
|
|
|
+ <!-- 修改:将pH改为CEC -->
|
|
|
<el-form-item
|
|
|
label="阳离子交换量(cmol/kg)"
|
|
|
prop="CEC"
|
|
|
@@ -125,39 +126,34 @@
|
|
|
<script setup lang="ts">
|
|
|
import { reactive, ref, nextTick } from "vue";
|
|
|
import { ElMessage } from "element-plus";
|
|
|
-import axios from "axios";
|
|
|
-import { useRouter } from "vue-router";
|
|
|
import request from "../../../utils/request";
|
|
|
|
|
|
// 定义表单数据接口
|
|
|
interface Form {
|
|
|
OM: number | null;
|
|
|
CL: number | null;
|
|
|
- CEC: number | null;
|
|
|
+ CEC: number | null; // 修改:将pH改为CEC
|
|
|
H_plus: number | null;
|
|
|
N: number | null;
|
|
|
Al3_plus: number | null;
|
|
|
- delta_ph: number | null;
|
|
|
}
|
|
|
|
|
|
const form = reactive<Form>({
|
|
|
OM: null,
|
|
|
CL: null,
|
|
|
- CEC: null,
|
|
|
+ CEC: null, // 修改:将pH改为CEC
|
|
|
H_plus: null,
|
|
|
N: null,
|
|
|
Al3_plus: null,
|
|
|
- delta_ph: null,
|
|
|
});
|
|
|
|
|
|
-const router = useRouter();
|
|
|
const result = ref<number | null>(null);
|
|
|
const dialogVisible = ref(false);
|
|
|
const predictForm = ref<any>(null);
|
|
|
const errorMessages = reactive<Record<string, string>>({
|
|
|
OM: "",
|
|
|
CL: "",
|
|
|
- CEC: "",
|
|
|
+ CEC: "", // 修改:将pH改为CEC
|
|
|
H_plus: "",
|
|
|
N: "",
|
|
|
Al3_plus: "",
|
|
|
@@ -197,7 +193,7 @@ const onSubmit = async () => {
|
|
|
const inputConfigs = [
|
|
|
{ field: "OM" as keyof Form, min: 0, max: 30 },
|
|
|
{ field: "CL" as keyof Form, min: 50, max: 400 },
|
|
|
- { field: "CEC" as keyof Form, min: 0, max: 15 },
|
|
|
+ { field: "CEC" as keyof Form, min: 0, max: 15 }, // 修改:将pH改为CEC
|
|
|
{ field: "H_plus" as keyof Form, min: 0, max: 1 },
|
|
|
{ field: "N" as keyof Form, min: 0, max: 0.2 },
|
|
|
{ field: "Al3_plus" as keyof Form, min: 0, max: 6 },
|
|
|
@@ -206,7 +202,7 @@ const onSubmit = async () => {
|
|
|
let isValid = true;
|
|
|
for (const config of inputConfigs) {
|
|
|
const { field, min, max } = config;
|
|
|
- const value = form[field]; // 现在 TypeScript 明白 field 是 keyof Form 类型
|
|
|
+ const value = form[field];
|
|
|
if (value === null || !validateInput(value.toString(), min, max)) {
|
|
|
isValid = false;
|
|
|
errorMessages[field] = `输入值应在 ${min} 到 ${max} 之间且为有效数字`;
|
|
|
@@ -222,19 +218,19 @@ const onSubmit = async () => {
|
|
|
|
|
|
console.log("开始计算...");
|
|
|
const data = {
|
|
|
- model_id: 25,
|
|
|
+ model_id: 24,
|
|
|
parameters: {
|
|
|
- OM: form.OM, // 土壤有机质
|
|
|
- CL: form.CL, // 土壤粘粒
|
|
|
- CEC: form.CEC, // 阳离子交换量
|
|
|
- H: form.H_plus, // 交换性氢
|
|
|
- N: form.N, // 水解氮
|
|
|
- Al: form.Al3_plus, // 交换性铝
|
|
|
+ OM: form.OM,
|
|
|
+ CL: form.CL,
|
|
|
+ CEC: form.CEC, // 修改:将pH改为CEC
|
|
|
+ H_plus: form.H_plus,
|
|
|
+ N: form.N,
|
|
|
+ Al3_plus: form.Al3_plus,
|
|
|
},
|
|
|
};
|
|
|
|
|
|
try {
|
|
|
- const response = await request.post("/predict", data, {
|
|
|
+ const response = await request.post("http://127.0.0.1:5000/predict", data, {
|
|
|
headers: {
|
|
|
"Content-Type": "application/json",
|
|
|
},
|
|
|
@@ -267,7 +263,7 @@ const onSubmit = async () => {
|
|
|
const onDialogClose = () => {
|
|
|
dialogVisible.value = false;
|
|
|
|
|
|
- // 使用类型断言确保 key 是 keyof Form 类型
|
|
|
+ // 重置表单
|
|
|
Object.keys(form).forEach((key) => {
|
|
|
if (key in form) {
|
|
|
const typedKey = key as keyof Form;
|
|
|
@@ -275,7 +271,7 @@ const onDialogClose = () => {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- // 同样地处理 errorMessages
|
|
|
+ // 重置错误消息
|
|
|
Object.keys(errorMessages).forEach((key) => {
|
|
|
if (key in errorMessages) {
|
|
|
const typedKey = key as keyof typeof errorMessages;
|
|
|
@@ -285,7 +281,7 @@ const onDialogClose = () => {
|
|
|
|
|
|
nextTick(() => {
|
|
|
if (predictForm.value) {
|
|
|
- (predictForm.value as any).resetFields(); // 使用类型断言避免类型错误
|
|
|
+ (predictForm.value as any).resetFields();
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
@@ -356,4 +352,4 @@ const onDialogClose = () => {
|
|
|
border-color: #dcdfe6;
|
|
|
color: #606266;
|
|
|
}
|
|
|
-</style>
|
|
|
+</style>
|