根据股票代码快速填充股票名字

This commit is contained in:
wjsjwr 2025-04-13 17:17:24 +08:00
parent 083dda7118
commit 9696657ecc
5 changed files with 63 additions and 8 deletions

View File

@ -10,8 +10,7 @@
<cargoProject FILE="$PROJECT_DIR$/bookkeeper/Cargo.toml" />
</component>
<component name="ChangeListManager">
<list default="true" id="76b3b902-7a5c-4bcd-9c1b-8241d748fb44" name="更改" comment="bug fix: zero division error">
<change afterPath="$PROJECT_DIR$/bookkeeper/templates/ftx.html.j2" afterDir="false" />
<list default="true" id="76b3b902-7a5c-4bcd-9c1b-8241d748fb44" name="更改" comment="增加快速记录功能">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/bookkeeper/src/main.rs" beforeDir="false" afterPath="$PROJECT_DIR$/bookkeeper/src/main.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/bookkeeper/templates/index.html.j2" beforeDir="false" afterPath="$PROJECT_DIR$/bookkeeper/templates/index.html.j2" afterDir="false" />
@ -53,6 +52,7 @@
&quot;ASKED_SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;,
&quot;Cargo.Run bookkeeper.executor&quot;: &quot;Run&quot;,
&quot;DefaultHtmlFileTemplate&quot;: &quot;HTML File&quot;,
&quot;PowerShell.deploy.ps1.executor&quot;: &quot;Run&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.git.unshallow&quot;: &quot;true&quot;,
&quot;RunOnceActivity.rust.reset.selective.auto.import&quot;: &quot;true&quot;,
@ -133,6 +133,15 @@
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
</method>
</configuration>
<configuration name="deploy.ps1" type="PowerShellRunType" factoryName="PowerShell" temporary="true" scriptUrl="$PROJECT_DIR$/bookkeeper/deploy.ps1" executablePath="C:/Program Files/PowerShell/7/pwsh.exe">
<envs />
<method v="2" />
</configuration>
<recent_temporary>
<list>
<item itemvalue="PowerShell.deploy.ps1" />
</list>
</recent_temporary>
</component>
<component name="RustProjectSettings">
<option name="toolchainHomeDirectory" value="$USER_HOME$/.cargo/bin" />
@ -158,7 +167,9 @@
<workItem from="1739197188908" duration="1873000" />
<workItem from="1740209396270" duration="6333000" />
<workItem from="1741527809947" duration="5732000" />
<workItem from="1741617416981" duration="867000" />
<workItem from="1741617416981" duration="2272000" />
<workItem from="1744534517424" duration="144000" />
<workItem from="1744534680689" duration="862000" />
</task>
<task id="LOCAL-00001" summary="Add bookkeeper">
<option name="closed" value="true" />
@ -288,7 +299,15 @@
<option name="project" value="LOCAL" />
<updated>1740216327515</updated>
</task>
<option name="localTasksCounter" value="17" />
<task id="LOCAL-00017" summary="增加快速记录功能">
<option name="closed" value="true" />
<created>1741618500678</created>
<option name="number" value="00017" />
<option name="presentableId" value="LOCAL-00017" />
<option name="project" value="LOCAL" />
<updated>1741618500678</updated>
</task>
<option name="localTasksCounter" value="18" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
@ -322,7 +341,8 @@
<MESSAGE value="添加总计" />
<MESSAGE value="添加登录页面" />
<MESSAGE value="bug fix: zero division error" />
<option name="LAST_COMMIT_MESSAGE" value="bug fix: zero division error" />
<MESSAGE value="增加快速记录功能" />
<option name="LAST_COMMIT_MESSAGE" value="增加快速记录功能" />
</component>
<component name="XSLT-Support.FileAssociations.UIState">
<expand />

2
bookkeeper/Cargo.lock generated
View File

@ -481,7 +481,7 @@ dependencies = [
[[package]]
name = "bookkeeper"
version = "0.3.0"
version = "0.4.0"
dependencies = [
"bcrypt",
"chrono",

View File

@ -1,6 +1,6 @@
[package]
name = "bookkeeper"
version = "0.3.0"
version = "0.4.0"
edition = "2021"
[dependencies]

View File

@ -538,6 +538,25 @@ fn translate(trans: Form<TransModel>) -> transaction::ActiveModel {
record
}
#[get("/stock/<id>")]
async fn get_stock(
conn: Connection<'_, Db>,
id: i32,
cookies: &CookieJar<'_>,
) -> Result<String, Status> {
if !verify(cookies) {
return Err(Status::Forbidden);
}
let row = TE::find()
.filter(transaction::Column::Code.eq(id))
.one(conn.into_inner()).await.unwrap();
match row {
None => Ok(String::from("")),
Some(row) => Ok(row.name),
}
}
async fn run_migrations(rocket: Rocket<Build>) -> fairing::Result {
let conn = &Db::fetch(&rocket).unwrap().conn;
let _ = migration::Migrator::up(conn, None).await;
@ -565,7 +584,7 @@ async fn rocket() -> _ {
"/",
routes![
index, add, get_add, get_tx, post_tx, delete_tx, login_page, login_post, post_ftx,
get_ftx
get_ftx, get_stock
],
)
.mount("/static", FileServer::from("static"))

View File

@ -130,6 +130,7 @@
}
document.getElementById('modal-content').innerHTML = await response.text();
openModal($target);
injectCodeEvent();
});
document.getElementById('ftx').addEventListener('click', async () => {
@ -140,6 +141,7 @@
}
document.getElementById('modal-content').innerHTML = await response.text();
openModal($target);
injectCodeEvent();
});
(document.querySelectorAll('.modify-row') || []).forEach(($cl) => {
@ -209,6 +211,20 @@
}
}
function injectCodeEvent() {
const $target = document.getElementById('code');
$target.addEventListener('blur', (event) => {
fetch(`/stock/${$target.value}`).then((resp) => {
return resp.text();
}).then((text) => {
if (text.trim().length > 0) {
const $update = document.getElementById('name');
$update.value = text;
}
})
});
}
</script>