You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.8 KiB
70 lines
1.8 KiB
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, |
|
}; |
|
}, |
|
actions: { |
|
setTitle(name: any) { |
|
this.title = name; |
|
}, |
|
setQw(value: number) { |
|
console.log(value); |
|
|
|
this.qw = value; |
|
}, |
|
setValue(value: number, 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); |
|
}, |
|
}, |
|
}); |
|
|
|
export default settingStore;
|
|
|