This commit is contained in:
oneao committed 2026-05-05 21:34:56 +08:00
1 parent 4d60582d4f
commit 2fb19021ae
40 files changed
+2552 -348

No files matched your search

+5 -3
View File
@@ -31,11 +31,12 @@ func buildInsertSQL(table string, data map[string]any) (string, []any) {
}
func (c *Client) Insert(ctx context.Context, table, keyField string, data map[string]any) error {
if _, err := validateData(table, keyField, data); err != nil {
if _, err := validateInsertData(table, keyField, data); err != nil {
return err
}
ensureID(data, keyField)
data = applyMetaFields(ctx, table, data, true)
sql, args := buildInsertSQL(table, data)
@@ -51,7 +52,7 @@ func (c *Client) BatchInsert(ctx context.Context, table, keyField string, list [
}
first := list[0]
if _, err := validateData(table, keyField, first); err != nil {
if _, err := validateInsertData(table, keyField, first); err != nil {
return err
}
@@ -71,6 +72,7 @@ func (c *Client) BatchInsert(ctx context.Context, table, keyField string, list [
)
for _, row := range list {
ensureID(row, keyField)
row = applyMetaFields(ctx, table, row, true)
@@ -1,6 +1,7 @@
package db
import (
"allapp-go/pkg/uniqueid"
"fmt"
"regexp"
"strings"
@@ -58,3 +59,30 @@ func validateData(table string, keyField string, data map[string]any) (any, erro
return val, nil
}
// 校验数据
func validateInsertData(table string, keyField string, data map[string]any) (any, error) {
if table == "" {
return nil, fmt.Errorf("表名不能为空")
}
if len(data) == 0 {
return nil, fmt.Errorf("数据不能为空")
}
if keyField == "" {
return nil, fmt.Errorf("主键字段不能为空")
}
val, _ := data[keyField]
return val, nil
}
func ensureID(data map[string]any, keyField string) {
v, ok := data[keyField]
if !ok || v == nil || v == "" {
data[keyField] = uniqueid.NextId()
}
}
+1 -1
View File
@@ -25,7 +25,7 @@ interface FinanceState {
records: FinanceRecordGroup[]
getTotalIncome: () => string
getTotalExpense: () => string
getTotalBalance: () => string
getTotalBalance: () => string
setRecords: (records: FinanceRecord[]) => void
getRecordById: (id: number) => FinanceRecord | null
+100 -147
View File
@@ -1,165 +1,118 @@
<!DOCTYPE html>
<html lang="zh">
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>个人中心</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>金额输入 Demo</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto;
}
<style>
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI";
background: #f5f6f7;
}
body {
background: #f5f6f8;
}
.container {
max-width: 420px;
margin: 0 auto;
background: #fff;
min-height: 100vh;
padding: 20px;
}
.container {
max-width: 420px;
margin: 0 auto;
}
.amount-wrapper {
text-align: center;
padding: 30px 0;
cursor: pointer;
}
/* ===== Header ===== */
.header {
height: 180px;
padding: 20px;
background: linear-gradient(135deg, #4f8cff, #6ed0ff);
color: #fff;
position: relative;
}
.amount-label {
font-size: 14px;
color: #999;
margin-bottom: 6px;
}
.user {
display: flex;
align-items: center;
margin-top: 40px;
}
.amount {
font-size: 42px;
font-weight: 600;
color: #111;
letter-spacing: -1px;
}
.avatar {
width: 64px;
height: 64px;
border-radius: 50%;
background: rgba(255, 255, 255, 0.3);
}
.info {
margin-left: 14px;
}
.name {
font-size: 18px;
font-weight: 600;
}
.desc {
font-size: 13px;
opacity: 0.9;
margin-top: 4px;
}
/* ===== Card ===== */
.card {
background: #fff;
margin: -40px 16px 16px;
border-radius: 16px;
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.06);
overflow: hidden;
}
.section {
margin: 16px;
background: #fff;
border-radius: 16px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
overflow: hidden;
}
/* ===== Item ===== */
.item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 16px;
font-size: 15px;
border-bottom: 1px solid #f0f0f0;
}
.item:last-child {
border-bottom: none;
}
.item span {
color: #333;
}
.arrow {
color: #bbb;
}
/* Danger */
.danger {
color: #ff4d4f;
}
</style>
/* 点击反馈 */
.amount-wrapper:active {
opacity: 0.6;
}
/* 隐藏输入 */
.hidden-input {
position: absolute;
opacity: 0;
pointer-events: none;
}
</style>
</head>
<body>
<div class="container">
```
<!-- Header -->
<div class="header">
<div class="user">
<div class="avatar"></div>
<div class="info">
<div class="name">张三</div>
<div class="desc">让工具更高效 ⚡</div>
</div>
</div>
</div>
<div class="container">
<!-- 功能区 -->
<div class="card">
<div class="item">
<span>我的工具</span>
<span class="arrow">›</span>
</div>
<div class="item">
<span>数据管理</span>
<span class="arrow">›</span>
</div>
<div class="item">
<span>云同步</span>
<span class="arrow">›</span>
</div>
</div>
<!-- 金额 -->
<div class="amount-wrapper" onclick="focusInput()">
<div class="amount-label">金额</div>
<div class="amount" id="amount">¥ 0.00</div>
</div>
<!-- 设置区 -->
<div class="section">
<div class="item">
<span>深色模式</span>
<span class="arrow">›</span>
</div>
<div class="item">
<span>通知设置</span>
<span class="arrow">›</span>
</div>
<div class="item">
<span>关于应用</span>
<span class="arrow">›</span>
</div>
<div class="item">
<span class="danger">退出登录</span>
</div>
</div>
```
<!-- 隐藏输入 -->
<input
id="input"
class="hidden-input"
type="text"
inputmode="decimal"
oninput="handleInput(this.value)"
/>
</div>
<script>
let value = "0";
function focusInput() {
document.getElementById("input").focus();
}
function handleInput(text) {
// 只保留数字和小数点
let v = text.replace(/[^\d.]/g, "");
// 只允许一个 .
const parts = v.split(".");
if (parts.length > 2) {
v = parts[0] + "." + parts[1];
}
// 限制两位小数
if (v.includes(".")) {
let [int, dec] = v.split(".");
v = int + "." + dec.slice(0, 2);
}
// 去前导0
if (v.startsWith("0") && v[1] !== ".") {
v = v.replace(/^0+/, "");
}
if (v === "") v = "0";
value = v;
updateUI();
}
function updateUI() {
document.getElementById("amount").innerText = "¥ " + value;
document.getElementById("input").value = value;
}
</script>
</div>
</body>
</html>