在数据库中添加了Version字段,并修改前端,不再使用指定的Version

This commit is contained in:
2026-01-08 14:12:34 +08:00
parent 7d7c0b251f
commit 67c3be3c9e
5 changed files with 29 additions and 20 deletions

2
.env
View File

@@ -6,4 +6,4 @@ JWT_SECRET="your_super_secret_key"
SSL_KEY_PATH=/etc/ssl/private/private.key SSL_KEY_PATH=/etc/ssl/private/private.key
SSL_CERT_PATH=/etc/ssl/certs/full_chain.pem SSL_CERT_PATH=/etc/ssl/certs/full_chain.pem
RUST_LOG=info RUST_LOG=info
APP_VERSION="0.1.9" APP_VERSION="0.2.0"

1
.gitignore vendored
View File

@@ -1 +1,2 @@
/target /target
/.vscode

View File

@@ -32,10 +32,10 @@ pub async fn insert_weather_data(pool: &PgPool, weather_data: &WeatherData) -> R
atmosphericstability, suitabilitydegree, winddirection, averagewinddirection, atmosphericstability, suitabilitydegree, winddirection, averagewinddirection,
winddirectionstandarddeviation, windspeed, averagewindspeed, windspeedsuitability, winddirectionstandarddeviation, windspeed, averagewindspeed, windspeedsuitability,
winddirectionsuitability, overallsuitability, inspectiontype, assignmentnumber, winddirectionsuitability, overallsuitability, inspectiontype, assignmentnumber,
calculatedwindspeed, hasspotcheckwindspeed calculatedwindspeed, hasspotcheckwindspeed, version
) VALUES ( ) VALUES (
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19,
$20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34, $35 $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34, $35, $36
) RETURNING id ) RETURNING id
"#; "#;
@@ -82,6 +82,7 @@ pub async fn insert_weather_data(pool: &PgPool, weather_data: &WeatherData) -> R
.bind(&weather_data.assignment_number) .bind(&weather_data.assignment_number)
.bind(weather_data.calculated_wind_speed) // 这个本来就是 Option无需修改 .bind(weather_data.calculated_wind_speed) // 这个本来就是 Option无需修改
.bind(weather_data.has_spot_check_wind_speed) .bind(weather_data.has_spot_check_wind_speed)
.bind(&weather_data.version)
.fetch_one(pool) .fetch_one(pool)
.await .await
{ {
@@ -116,8 +117,6 @@ pub async fn create_pool() -> Result<PgPool, Box<dyn Error>> {
Ok(pool) Ok(pool)
} }
// 在db.rs中添加以下函数
// 获取天气数据详情 // 获取天气数据详情
pub async fn get_weather_details(pool: &PgPool, weather_id: i32) -> Result<WeatherData, String> { pub async fn get_weather_details(pool: &PgPool, weather_id: i32) -> Result<WeatherData, String> {
let query = r#" let query = r#"
@@ -133,7 +132,7 @@ pub async fn get_weather_details(pool: &PgPool, weather_id: i32) -> Result<Weath
wd.winddirectionstandarddeviation, wd.windspeed, wd.averagewindspeed, wd.winddirectionstandarddeviation, wd.windspeed, wd.averagewindspeed,
wd.windspeedsuitability, wd.winddirectionsuitability, wd.overallsuitability, wd.windspeedsuitability, wd.winddirectionsuitability, wd.overallsuitability,
wd.inspectiontype, wd.assignmentnumber, wd.calculatedwindspeed, wd.hasspotcheckwindspeed, wd.inspectiontype, wd.assignmentnumber, wd.calculatedwindspeed, wd.hasspotcheckwindspeed,
u.openid u.openid, wd.version
FROM weather_data wd FROM weather_data wd
JOIN users u ON wd.user_id = u.id JOIN users u ON wd.user_id = u.id
WHERE wd.id = $1 WHERE wd.id = $1

View File

@@ -247,6 +247,8 @@ pub struct WeatherData {
pub theta: f64, pub theta: f64,
pub title: String, pub title: String,
pub version: String,
#[serde(rename = "windDirection")] #[serde(rename = "windDirection")]
#[sqlx(rename = "winddirection")] #[sqlx(rename = "winddirection")]
#[sqlx(try_from = "serde_json::Value")] #[sqlx(try_from = "serde_json::Value")]

View File

@@ -1,5 +1,3 @@
const version = "0.1.9";
//公式相关 //公式相关
function toggleAccordion(header) { function toggleAccordion(header) {
@@ -36,20 +34,29 @@ document.addEventListener('DOMContentLoaded', function() {
throwOnError: false throwOnError: false
}); });
// 获取页面中的版本号元素 // 确保数据已加载
const versionElement = document.querySelector('.version'); if (window.weatherData) {
// 获取页面中的版本号元素
const versionElement = document.querySelector('.version');
// 更新内容(拼接版本号) // 【修改点】直接使用 window.weatherData.version
if (versionElement) { // 使用 || 'v1.0' 作为默认值,防止数据库版本为空时显示 undefined
versionElement.textContent = `版本号: ${version}`; const dbVersion = window.weatherData.version || 'default';
// 更新页面显示
if (versionElement) {
versionElement.textContent = `版本号: ${dbVersion}`;
}
// 【修改点】调用 downloadpdf只传 data不再传那个空的 version 变量
downloadpdf(window.weatherData);
} else {
console.error("错误window.weatherData 未定义");
} }
//console.log(window.weatherData);
downloadpdf(window.weatherData, version);
}); });
// 下载按钮 // 下载按钮
function downloadpdf(data, version) { function downloadpdf(data) {
const areaTypeMap = { const areaTypeMap = {
urban: "城市", urban: "城市",
@@ -320,17 +327,17 @@ ${data.hasSpotCheckWindSpeed ? `
htmlString += ` htmlString += `
</div> </div>
<br> <br>
<div class="footer">----报表结束 version:${version}----</div> <div class="footer">----报表结束 version:${data.version}----</div>
</body> </body>
</html> </html>
` `
const filename = `${data.id}-${version}.pdf` const filename = `${data.id}-${data.version || 'unknown'}.pdf`
var opt = { var opt = {
margin: 10, margin: 10,
filename: filename, filename: filename,
image: { image: {
type: 'jpeg', type: 'jpeg',
quality: 0.98 quality: 0.99
}, },
html2canvas: { html2canvas: {
scale: 2 scale: 2