|
|
|
import { defineStore } from "pinia";
|
|
|
|
const settingStore = defineStore("settingStore", {
|
|
|
|
state: (): any => {
|
|
|
|
return {
|
|
|
|
title: "虚拟仿真实验项目",
|
|
|
|
qw: 0, // 气温
|
|
|
|
zl: 0, // 质量
|
|
|
|
srmj: 0, // 散热面积
|
|
|
|
jrgl: 0, // 加热功率
|
|
|
|
wdsz: 0, // 温度数值
|
|
|
|
ip: "", // ip
|
|
|
|
port: "", // 端口
|
|
|
|
cssd: 0, // 初始湿度
|
|
|
|
jsgl: 0, // 加湿功率
|
|
|
|
jsmj: 0, // 加湿面积
|
|
|
|
sdsz: 0, // 湿度数值
|
|
|
|
falg: false,
|
|
|
|
timer: null,
|
|
|
|
experimentPreservation: false, // 是否设计好实验
|
|
|
|
saveRoute: false, // 是否保存路由
|
|
|
|
stepIds: null,
|
|
|
|
wenduCode: null,
|
|
|
|
shiduCode:null
|
|
|
|
};
|
|
|
|
},
|
|
|
|
actions: {
|
|
|
|
setTitle(name: any) {
|
|
|
|
this.title = name;
|
|
|
|
},
|
|
|
|
setQw(value: number) {
|
|
|
|
console.log(value);
|
|
|
|
|
|
|
|
this.qw = value;
|
|
|
|
},
|
|
|
|
setValue(value: number | boolean, name: string) {
|
|
|
|
this[name] = value;
|
|
|
|
},
|
|
|
|
openHeating() {
|
|
|
|
this.flag = !this.flag; // 切换状态
|
|
|
|
if (this.flag) {
|
|
|
|
// 开启加热
|
|
|
|
this.timer = setInterval(() => {
|
|
|
|
this.qw++;
|
|
|
|
if (this.qw >= 100) {
|
|
|
|
clearInterval(this.timer);
|
|
|
|
}
|
|
|
|
}, 500);
|
|
|
|
} else {
|
|
|
|
// 关闭加热
|
|
|
|
clearInterval(this.timer);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
calculateTemperature() {
|
|
|
|
this.qw <= 0 ? (this.qw = 1) : this.qw;
|
|
|
|
const a = (100000 * this.zl * this.srmj) / this.jrgl;
|
|
|
|
let time = 0;
|
|
|
|
let currentTemp = this.qw;
|
|
|
|
|
|
|
|
const interval = setInterval(() => {
|
|
|
|
currentTemp = (1 - Math.exp(-time / a)) * 100 + this.qw;
|
|
|
|
|
|
|
|
console.log(`时间: ${time}s, 温度: ${currentTemp.toFixed(2)}°C`);
|
|
|
|
this.qw = currentTemp >= 100 ? 100 : currentTemp;
|
|
|
|
if (currentTemp >= 100) {
|
|
|
|
console.log("温度达到 100°C, 停止加热!");
|
|
|
|
clearInterval(interval);
|
|
|
|
}
|
|
|
|
|
|
|
|
time += 1; // 每秒增加 1s
|
|
|
|
}, 1000);
|
|
|
|
},
|
|
|
|
simulateHeatingAndHumidifying() {
|
|
|
|
// 计算时间常数
|
|
|
|
const a = (100000 * this.zl * this.srmj) / this.jrgl;
|
|
|
|
const b = (10000 * this.jsmj) / this.jsgl;
|
|
|
|
|
|
|
|
let time = 0;
|
|
|
|
let currentTemp = this.qw;
|
|
|
|
let currentHumidity = this.cssd;
|
|
|
|
|
|
|
|
const interval = setInterval(() => {
|
|
|
|
// 计算温度
|
|
|
|
currentTemp = (1 - Math.exp(-time / a)) * 100 + this.qw;
|
|
|
|
if (currentTemp > 100) currentTemp = 100;
|
|
|
|
|
|
|
|
// 计算湿度
|
|
|
|
currentHumidity = (1 - Math.exp(-time / b)) * 100 + this.cssd;
|
|
|
|
if (currentHumidity > 100) currentHumidity = 100;
|
|
|
|
|
|
|
|
console.log(
|
|
|
|
`时间: ${time}s, 温度: ${currentTemp.toFixed(
|
|
|
|
2
|
|
|
|
)}°C, 湿度: ${currentHumidity}%RH`
|
|
|
|
);
|
|
|
|
this.qw = currentTemp >= 100 ? 100 : currentTemp;
|
|
|
|
this.cssd = currentHumidity >= 100 ? 100 : Number(currentHumidity.toFixed(2));
|
|
|
|
// 停止加热 & 加湿
|
|
|
|
if (currentTemp >= 100 && currentHumidity >= 100) {
|
|
|
|
console.log("温度和湿度均达到上限,停止模拟!");
|
|
|
|
clearInterval(interval);
|
|
|
|
}
|
|
|
|
|
|
|
|
time += 1; // 每秒增加 1s
|
|
|
|
}, 1000);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
export default settingStore;
|