From c7918ad0e42e0616bb178263e7bdc0ae553eda2e Mon Sep 17 00:00:00 2001 From: liwq <122639653@qq.com> Date: Wed, 4 Feb 2026 11:38:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=89=8D=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/components/index.vue | 50 ++++---- .../com/tem/bocai/entity/LoginInfoResult.java | 2 + .../bocai/service/impl/LoginServiceImpl.java | 109 +++++++++++++++++- 3 files changed, 133 insertions(+), 28 deletions(-) diff --git a/frontend/src/components/index.vue b/frontend/src/components/index.vue index bd205c2..9932708 100644 --- a/frontend/src/components/index.vue +++ b/frontend/src/components/index.vue @@ -4,13 +4,13 @@ import axios from 'axios'; import * as echarts from 'echarts'; // 输入框数据 -const input1 = ref(''); -const input2 = ref(''); +const betAmount = ref(''); // 登录模态框数据 const loginDialogVisible = ref(false); const isLoggedIn = ref(false); const username = ref('未记录'); +const balance = ref('0'); // 余额 const loginForm = ref({ username: '', password: '', @@ -237,20 +237,20 @@ async function fetchUserSettings() { username.value = response.data.username; isLoggedIn.value = true; } - // 更新止盈点 - if (response.data.winNum) { - input1.value = response.data.winNum; + // 更新投注金额 + if (response.data.betAmount) { + betAmount.value = response.data.betAmount; } - // 更新止亏点 - if (response.data.loseNum) { - input2.value = response.data.loseNum; + // 更新余额 + if (response.data.balance) { + balance.value = response.data.balance; } } console.log('用户设置数据获取完成'); console.log('username.value:', username.value); - console.log('input1.value:', input1.value); - console.log('input2.value:', input2.value); + console.log('betAmount.value:', betAmount.value); + console.log('balance.value:', balance.value); } catch (err) { console.error('获取用户设置数据失败:', err); // 失败时不显示错误,使用默认值 @@ -343,19 +343,18 @@ function handleLogout() { // 处理确认按钮点击 async function handleConfirm() { - console.log('确认按钮点击,止盈点:', input1.value, '止亏点:', input2.value); + console.log('确认按钮点击,投注金额:', betAmount.value); // 验证输入 - if (!input1.value || !input2.value) { - alert('请填写完整的止盈止亏点'); + if (!betAmount.value) { + alert('请填写投注金额'); return; } try { // 构建提交数据 const submitData = { - winNum: input1.value, - loseNum: input2.value + betAmount: betAmount.value }; console.log('提交数据:', submitData); @@ -446,6 +445,7 @@ onUnmounted(() => {
👤
{{ username }}
+
余额: {{ balance }}
@@ -493,15 +493,9 @@ onUnmounted(() => {
- +
- -
-
-
- -
- +
@@ -612,6 +606,11 @@ onUnmounted(() => { margin-bottom: 4px; } +.account-balance { + font-size: 0.85rem; + color: #666; +} + .account-role { font-size: 0.85rem; color: #666; @@ -683,14 +682,15 @@ onUnmounted(() => { .input-group { flex: 1; display: flex; - flex-direction: column; + align-items: center; gap: 8px; } .input-with-button { display: flex; gap: 8px; - align-items: flex-start; + align-items: center; + flex: 1; } .input-with-button input { diff --git a/src/main/java/com/tem/bocai/entity/LoginInfoResult.java b/src/main/java/com/tem/bocai/entity/LoginInfoResult.java index b8a4f4a..cf775b9 100644 --- a/src/main/java/com/tem/bocai/entity/LoginInfoResult.java +++ b/src/main/java/com/tem/bocai/entity/LoginInfoResult.java @@ -56,6 +56,8 @@ public class LoginInfoResult { @Column(name = "balance") private String balance; + private Integer betAmount; + @Column(name = "create_time", nullable = false, updatable = false) @CreationTimestamp @Convert(converter = SQLiteDateConverter.class) diff --git a/src/main/java/com/tem/bocai/service/impl/LoginServiceImpl.java b/src/main/java/com/tem/bocai/service/impl/LoginServiceImpl.java index ab47f02..ad02bd7 100644 --- a/src/main/java/com/tem/bocai/service/impl/LoginServiceImpl.java +++ b/src/main/java/com/tem/bocai/service/impl/LoginServiceImpl.java @@ -188,6 +188,10 @@ public class LoginServiceImpl implements LoginService { if (loginInfoResult.getAmount() != null) { dbUser.setAmount(loginInfoResult.getAmount()); } + // 如果传入了 betAmount,写入到配置文件 + if (loginInfoResult.getBetAmount() != null) { + writeBaseBetUnitToConfig(loginInfoResult.getBetAmount()); + } if (loginInfoResult.getOnOff() != null) { dbUser.setOnOff(loginInfoResult.getOnOff()); if (loginInfoResult.getOnOff().equals(1)) { @@ -258,16 +262,115 @@ public class LoginServiceImpl implements LoginService { return SQLiteUtil.addOrUpdateLoginInfo(loginInfo); } + /** + * 将 BASE_BET_UNIT 值写入到配置文件,保留原有结构 + */ + private void writeBaseBetUnitToConfig(Integer betAmount) { + String configPath = pypath+"/conf.ini"; + java.io.File configFile = new java.io.File(configPath); + if (configFile.exists()) { + try { + // 读取所有行 + java.util.List lines = new java.util.ArrayList<>(); + try (java.io.BufferedReader br = new java.io.BufferedReader(new java.io.FileReader(configFile))) { + String line; + while ((line = br.readLine()) != null) { + lines.add(line); + } + } + + // 查找并更新 BASE_BET_UNIT 行 + boolean updated = false; + for (int i = 0; i < lines.size(); i++) { + String line = lines.get(i); + if (line.startsWith("BASE_BET_UNIT =")) { + lines.set(i, "BASE_BET_UNIT = " + betAmount); + updated = true; + break; + } + } + + // 如果没有找到,在 [init] 节末尾添加 + if (!updated) { + for (int i = 0; i < lines.size(); i++) { + String line = lines.get(i); + if (line.startsWith("[init]")) { + // 找到 [init] 节,在其后添加 + for (int j = i + 1; j < lines.size(); j++) { + String nextLine = lines.get(j); + if (nextLine.startsWith("[")) { + // 遇到下一个节,在此之前添加 + lines.add(j, "BASE_BET_UNIT = " + betAmount); + updated = true; + break; + } + } + if (!updated) { + // 如果是最后一个节,在文件末尾添加 + lines.add("BASE_BET_UNIT = " + betAmount); + updated = true; + } + break; + } + } + } + + // 写回文件 + if (updated) { + try (java.io.BufferedWriter bw = new java.io.BufferedWriter(new java.io.FileWriter(configFile))) { + for (String line : lines) { + bw.write(line); + bw.newLine(); + } + } + System.out.println("BASE_BET_UNIT 已更新为: " + betAmount); + } else { + System.err.println("未找到 [init] 节,无法更新 BASE_BET_UNIT"); + } + } catch (java.io.IOException e) { + System.err.println("读写配置文件失败: " + e.getMessage()); + } + } else { + System.err.println("配置文件不存在: " + configPath); + } + } + @Override public LoginInfoResult getUserSettings() { try { // 获取最新的用户设置信息 Optional existingUser = loginInfoRepository.findFirstByOrderByCreateTimeDesc(); + LoginInfoResult loginInfoResult; if (existingUser.isPresent()) { - return existingUser.get(); + loginInfoResult = existingUser.get(); + } else { + // 如果没有找到,返回一个空的对象 + loginInfoResult = new LoginInfoResult(); } - // 如果没有找到,返回一个空的对象 - return new LoginInfoResult(); + + // 读取 PyModel/conf.ini 文件中的 BASE_BET_UNIT 值 + String configPath = pypath+"/conf.ini"; + java.io.File configFile = new java.io.File(configPath); + if (configFile.exists()) { + java.util.Properties properties = new java.util.Properties(); + try (java.io.FileInputStream fis = new java.io.FileInputStream(configFile)) { + properties.load(fis); + String baseBetUnit = properties.getProperty("BASE_BET_UNIT"); + if (baseBetUnit != null) { + try { + loginInfoResult.setBetAmount(Integer.parseInt(baseBetUnit)); + } catch (NumberFormatException e) { + System.err.println("BASE_BET_UNIT 格式错误: " + e.getMessage()); + } + } + } catch (java.io.IOException e) { + System.err.println("读取配置文件失败: " + e.getMessage()); + } + } else { + System.err.println("配置文件不存在: " + configPath); + } + + return loginInfoResult; } catch (Exception e) { System.err.println("获取用户设置信息失败: " + e.getMessage()); return new LoginInfoResult();