Author SHA1 Message Date
gouki d6ce5cd0f3 fix(server): use pure-Go sqlite driver (glebarez/sqlite) for CGO_ENABLED=0 builds
Build and Publish Server / build (push) Successful in 3m22s
2026-08-10 17:47:36 +00:00
gouki 3cc3edeef9 chore(server): add sqlite driver to go.mod/go.sum
Build and Publish Server / build (push) Successful in 59s
2026-08-10 17:43:09 +00:00
gouki 8b5bfe8385 feat(server): support SQLite via DB_TYPE env var
Build and Publish Server / build (push) Failing after 43s
2026-08-10 17:28:45 +00:00
gouki a29328f35b fix(wish-tree): 弹幕一行一条排队播放,不再重叠
Publish Mini Program Dev Version / publish (push) Successful in 1m4s
- 顶部滚动行上移紧贴置顶轮播(16%→12%)
- 树桩3行改为68/73/78%,更紧凑
- 核心修复重叠:弃用CSS无限循环+负delay(同屏多条),
  改为JS定时器按行调度,同一行一条飘完再出下一条,循环播放
- 弹幕动画改为只播一次,key含时间戳保证切换时重新触发动画
- 页面onHide/onUnload停止定时器,onShow恢复
2026-08-10 13:27:19 +00:00
gouki 87f5fa2478 refactor(mini): 个人中心改为登录+二级菜单结构
Publish Mini Program Dev Version / publish (push) Successful in 1m8s
- 个人中心仅保留登录管理、我的数据/功能菜单与关于信息
- 新增偏好设置二级页 preferences(原偏好设置统一收敛至此)
- 新增我的收藏二级页 bookmarks,支持删除与跳转日详情
- 生辰管理拆分为二级页 birth-profiles,未登录时提示引导登录
- 八字页入口改为直达生辰管理页;修复 fortune 非 tabBar 页误用 switchTab
2026-08-10 11:52:15 +00:00
gouki f7d88622e0 tweak(wish-tree): 弹幕改为4行布局
Publish Mini Program Dev Version / publish (push) Successful in 1m10s
- 树桩处3行(64/71/78%),不再遮挡上方树冠便签
- 置顶轮播下方新增1行滚动弹幕(16%)
- 同行统一慢速(树桩32s/顶部26s飘完全屏),按条数均匀错开起始位置,互相不盖
2026-08-10 08:45:38 +00:00
gouki ac2c99c3bc fix(ci): Alpine容器补装libstdc++/libgcc——musl版node的运行时依赖
Publish Mini Program Dev Version / publish (push) Successful in 50s
sha256校验已通过(下载完整),但HKRunner的Alpine精简容器缺
libstdc++.so.6/libgcc_s.so.1——node musl构建是动态链接这两个库的。
缺失时用apk补装,装不上给warning
2026-08-10 00:12:38 +00:00
gouki 4efdd20ff7 fix(ci): 真正根因——Node下载截断,改用sha256硬校验+镜像源优先
Publish Mini Program Dev Version / publish (push) Failing after 39s
根因:unofficial-builds.nodejs.org 在亚洲带宽极低,wget --timeout
只限单次读取,慢速断流仍返回成功,CI拿到截断的gzip(15MB/55MB),
解压出损坏二进制报 symbol not found(并非glibc/musl混用)。

修复:
1. sha256 硬校验拦截一切假文件(musl:8d96de02... glibc:e05a4d65...)
2. musl 版优先 npmmirror 镜像(实测与官方sha256一致),unofficial 后备
3. 循环换源重试,全部失败才报错
4. wget 改用 busybox 兼容短参数 -t/-T
2026-08-10 00:01:14 +00:00
gouki 297747041a fix(ci): Node下载增加npmmirror镜像源+gzip校验+二进制验证
Publish Mini Program Dev Version / publish (push) Failing after 11s
1826/1827连续失败:hk runner下载musl版node时拿到错误产物
(glibc版node在musl环境报libstdc++.so.6缺失)。
加固:musl下载增加npmmirror镜像fallback;下载后校验gzip魔数;
解压后验证node可执行,失败则清除缓存避免污染后续run
2026-08-09 23:47:23 +00:00
25 changed files with 729 additions and 390 deletions
+40 -8
View File
@@ -35,26 +35,58 @@ jobs:
echo "复用缓存 Node 工具链"
else
# 清理旧缓存:Alpine busybox mv 遇已存在目录会合并而非替换,
# 残留的 glibc 版 node 会污染 musl 环境导致 symbol not found
# 残留的版 node 会污染环境导致 symbol not found
rm -rf "$TOOLDIR"
mkdir -p "$TOOLDIR"
# 探测 libcAlpine(musl) 用 unofficial musl 构建,其余用官方 glibc 构建(tar.gzbusybox tar 不支持 xz
# 关键教训:unofficial-builds 在亚洲带宽极低,wget --timeout 只限单次读取,
# 慢速断流仍返回成功,产生截断的 gzip(解压出损坏二进制报 symbol not found)。
# 必须用 sha256 硬校验,不匹配则换源重试。
if ldd --version 2>&1 | grep -qi musl || [ ! -e /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 ]; then
NODE_DIST="node-v22.12.0-linux-x64-musl"
wget -q --tries=2 --timeout=120 -O "$TOOLDIR/node.tgz" \
"https://unofficial-builds.nodejs.org/download/release/v22.12.0/$NODE_DIST.tar.gz"
NODE_SHA="8d96de0293fc3978d09e2a3fee68c66bca4efcca90f52105e6f7463636e97308"
# 优先 npmmirror(国内/亚洲快),unofficial-builds 作为后备
URLS="https://registry.npmmirror.com/-/binary/node-unofficial-builds/v22.12.0/$NODE_DIST.tar.gz
https://unofficial-builds.nodejs.org/download/release/v22.12.0/$NODE_DIST.tar.gz"
else
NODE_DIST="node-v22.12.0-linux-x64"
wget -q --tries=2 --timeout=120 -O "$TOOLDIR/node.tgz" \
"https://nodejs.org/dist/v22.12.0/$NODE_DIST.tar.gz" \
|| wget -q --tries=2 --timeout=120 -O "$TOOLDIR/node.tgz" \
"https://mirrors.aliyun.com/nodejs-release/v22.12.0/$NODE_DIST.tar.gz"
NODE_SHA="e05a4d65232ae2b27b3d77da2e368522fb46b923335b8e0d5f77624c32484044"
URLS="https://nodejs.org/dist/v22.12.0/$NODE_DIST.tar.gz
https://mirrors.aliyun.com/nodejs-release/v22.12.0/$NODE_DIST.tar.gz"
fi
DL_OK=""
for url in $URLS; do
echo "尝试下载: $url"
if wget -t 2 -T 120 -q -O "$TOOLDIR/node.tgz" "$url"; then
# sha256 硬校验(busybox 有 sha256sum):拦截截断/错误页等假文件
if [ "$(sha256sum "$TOOLDIR/node.tgz" | cut -d' ' -f1)" = "$NODE_SHA" ]; then
echo "下载成功且校验通过"
DL_OK=1
break
fi
echo "sha256 校验失败,文件可能截断,尝试下一源"
else
echo "wget 下载失败,尝试下一源"
fi
rm -f "$TOOLDIR/node.tgz"
done
test -n "$DL_OK" || { echo "::error::所有下载源均失败或校验不通过"; exit 1; }
tar -C "$TOOLDIR" -xzf "$TOOLDIR/node.tgz"
mv "$TOOLDIR/$NODE_DIST" "$TOOLDIR/node"
rm -f "$TOOLDIR/node.tgz"
# musl 版 node 动态链接 libstdc++/libgcc_sAlpine 精简容器缺失时补装
if [ "$NODE_DIST" = "node-v22.12.0-linux-x64-musl" ] && [ ! -e /usr/lib/libstdc++.so.6 ] && [ ! -e /lib/libstdc++.so.6 ]; then
if command -v apk >/dev/null 2>&1; then
apk add --no-cache libstdc++ libgcc || echo "::warning::libstdc++/libgcc 安装失败,node 可能无法启动"
fi
fi
fi
# 验证二进制可执行,失败则清缓存并报错(避免坏缓存被后续 run 复用)
if ! "$TOOLDIR/node/bin/node" --version; then
echo "::error::Node 二进制无法执行,请检查下载源与 libc 匹配"
rm -rf "$TOOLDIR"
exit 1
fi
"$TOOLDIR/node/bin/node" --version
echo "PATH=$TOOLDIR/node/bin:$PATH" >> "$GITEA_ENV"
- name: Verify Node runtime
+3
View File
@@ -8,6 +8,9 @@
"pages/divination/divination",
"pages/solar-terms/solar-terms",
"pages/settings/settings",
"pages/preferences/preferences",
"pages/bookmarks/bookmarks",
"pages/birth-profiles/birth-profiles",
"pages/wish-tree/wish-tree",
"pages/wish-detail/wish-detail",
"pages/wiki/wiki"
+3 -3
View File
@@ -23,7 +23,7 @@ const GLOSSARY = [
{ term: '空亡', desc: '六十甲子分为六旬,每旬十个干支配十二地支,余下两个地支无天干相配,称为该旬"空亡"。这是干支纪法本身的结构性概念,此处仅作历法知识展示。' },
{ term: '大运', desc: '传统上以月柱为基础、按十年一换的节奏推演出的干支序列,用来描述人生不同阶段的节律。属于传统民俗推演方法,供文化了解。' },
{ term: '流年', desc: '即每一年的干支(如 2026 年为丙午年)。传统做法将流年与本命干支对照,观察逐年的变化关系。' },
{ term: '子时流派', desc: '子时(23:00-01:00)横跨两天,晚子时(23:00-24:00)出生者的日柱按当天还是次日起算,历代流派说法不一。可在"我的-偏好设置"中选择。' }
{ term: '子时流派', desc: '子时(23:00-01:00)横跨两天,晚子时(23:00-24:00)出生者的日柱按当天还是次日起算,历代流派说法不一。可在"我的-设置"中选择。' }
];
/** 根据出生信息构建排盘展示数据 */
@@ -144,10 +144,10 @@ Page({
},
goSettings() {
wx.switchTab({ url: '/pages/settings/settings' });
wx.navigateTo({ url: '/pages/birth-profiles/birth-profiles' });
},
goFortune() {
wx.switchTab({ url: '/pages/fortune/fortune' });
wx.navigateTo({ url: '/pages/fortune/fortune' });
}
});
+108
View File
@@ -0,0 +1,108 @@
const birthProfile = require('../../utils/birth-profile.js');
Page({
data: {
loggedIn: false,
profiles: [],
activeProfileId: '',
maxFree: birthProfile.MAX_PROFILES,
canAdd: true,
showAddForm: false,
formName: '',
formGender: 'male',
formDate: '1990-01-01',
formTime: '12:00'
},
onShow() {
this.setData({ loggedIn: birthProfile.isLoggedIn() });
this.loadProfiles();
},
loadProfiles() {
const render = () => {
const profiles = birthProfile.getProfiles();
const active = birthProfile.getActiveProfile();
this.setData({
profiles,
activeProfileId: active ? active.id : '',
canAdd: profiles.length < this.data.maxFree
});
};
// 已登录时先从服务端同步,失败静默回退本地
if (birthProfile.isLoggedIn()) {
birthProfile.syncFromServer().then(render).catch(render);
} else {
render();
}
},
toggleAddForm() {
if (!this.data.showAddForm && !this.data.canAdd) {
wx.showToast({ title: `最多可免费绑定 ${this.data.maxFree} 个生辰`, icon: 'none' });
return;
}
this.setData({ showAddForm: !this.data.showAddForm });
},
onFormName(e) {
this.setData({ formName: e.detail.value });
},
setFormGender(e) {
this.setData({ formGender: e.currentTarget.dataset.g });
},
onFormDate(e) {
this.setData({ formDate: e.detail.value });
},
onFormTime(e) {
this.setData({ formTime: e.detail.value });
},
submitProfile() {
const { formName, formGender, formDate, formTime } = this.data;
if (!formDate || !formTime) {
wx.showToast({ title: '请选择出生日期和时间', icon: 'none' });
return;
}
const result = birthProfile.addProfile({
name: formName.trim() || '未命名',
gender: formGender,
birthday: formDate,
birthTime: formTime
});
if (!result.ok) {
wx.showToast({ title: result.msg, icon: 'none' });
return;
}
// 已登录时推送到服务端(静默失败,不影响本地)
birthProfile.pushProfileToServer(result.profile);
this.setData({ showAddForm: false, formName: '' });
wx.showToast({ title: '绑定成功', icon: 'success' });
this.loadProfiles();
},
removeProfile(e) {
const id = e.currentTarget.dataset.id;
const profile = this.data.profiles.find(p => p.id === id);
if (!profile) return;
wx.showModal({
title: '删除生辰',
content: `确定删除「${profile.name}」的生辰信息吗?`,
success: (res) => {
if (!res.confirm) return;
birthProfile.removeProfile(id);
birthProfile.removeProfileFromServer(profile);
wx.showToast({ title: '已删除', icon: 'success' });
this.loadProfiles();
}
});
},
// 未登录时引导回个人中心登录
goLogin() {
wx.navigateBack();
}
});
@@ -0,0 +1,4 @@
{
"navigationBarTitleText": "生辰管理",
"enablePullDownRefresh": false
}
@@ -0,0 +1,70 @@
<view class="container">
<!-- 未登录提示 -->
<view class="card login-tip" wx:if="{{!loggedIn}}">
<text class="text-sm">当前未登录,生辰仅保存在本机</text>
<text class="text-xs text-muted block mt-1">登录后可云端同步,换设备不丢失</text>
<view class="btn-outline text-center mt-2" bindtap="goLogin">去登录</view>
</view>
<!-- 生辰管理 -->
<view class="card">
<view class="section-title flex justify-between items-center">
<text>生辰管理</text>
<text class="text-xs text-muted">{{profiles.length}}/{{maxFree}}</text>
</view>
<view class="text-xs text-muted mb-2">八字排盘基于生辰信息,每位用户可免费绑定 {{maxFree}} 个出生年月(如本人、家人)。</view>
<view class="profile-list" wx:if="{{profiles.length > 0}}">
<view class="profile-item" wx:for="{{profiles}}" wx:key="id">
<view class="flex justify-between items-center">
<view>
<view class="flex items-center gap-1">
<text class="text-base font-medium">{{item.name}}</text>
<text class="badge badge-lucky" wx:if="{{item.id === activeProfileId}}">使用中</text>
</view>
<text class="text-xs text-muted block">{{item.gender === 'female' ? '女' : '男'}} · {{item.birthday}} {{item.birthTime}}</text>
</view>
<view class="btn-ghost text-unlucky" bindtap="removeProfile" data-id="{{item.id}}">删除</view>
</view>
</view>
</view>
<view class="text-center text-muted p-2" wx:else>
<text>暂未绑定生辰,请到下方添加</text>
</view>
<view class="btn-outline text-center mt-2" bindtap="toggleAddForm" wx:if="{{canAdd}}">
{{showAddForm ? '收起' : '+ 添加生辰'}}
</view>
<view class="text-center text-xs text-muted mt-2" wx:else>
免费名额已用完,可删除旧档案后添加
</view>
<!-- 添加表单 -->
<block wx:if="{{showAddForm}}">
<view class="form-item mt-2">
<text class="form-label">备注名(如:本人、爸爸)</text>
<input class="form-input" placeholder="未命名" value="{{formName}}" bindinput="onFormName"/>
</view>
<view class="form-item">
<text class="form-label">性别</text>
<view class="flex gap-2">
<view class="btn-outline {{formGender === 'male' ? 'active' : ''}}" bindtap="setFormGender" data-g="male">男</view>
<view class="btn-outline {{formGender === 'female' ? 'active' : ''}}" bindtap="setFormGender" data-g="female">女</view>
</view>
</view>
<view class="form-item">
<text class="form-label">出生日期(公历)</text>
<picker mode="date" value="{{formDate}}" start="1900-01-01" end="2100-12-31" bindchange="onFormDate">
<view class="picker-input">{{formDate}}</view>
</picker>
</view>
<view class="form-item">
<text class="form-label">出生时间</text>
<picker mode="time" value="{{formTime}}" bindchange="onFormTime">
<view class="picker-input">{{formTime}}</view>
</picker>
</view>
<view class="btn-primary text-center" bindtap="submitProfile">保存生辰</view>
</block>
</view>
</view>
@@ -0,0 +1,56 @@
.container {
padding: 20rpx;
}
.section-title {
font-size: 28rpx;
font-weight: 600;
margin-bottom: 16rpx;
color: #C41E3A;
}
.login-tip {
border: 1rpx dashed #C41E3A;
}
/* 生辰档案 */
.profile-item {
padding: 16rpx 0;
border-bottom: 1rpx solid #E8D5C4;
}
.profile-item:last-child {
border-bottom: none;
}
/* 添加生辰表单 */
.form-item {
margin-bottom: 24rpx;
}
.form-label {
font-size: 24rpx;
color: #6B5E53;
margin-bottom: 8rpx;
display: block;
}
.form-input {
padding: 20rpx;
background: #FFFBF5;
border-radius: 12rpx;
border: 1rpx solid #E8D5C4;
}
.picker-input {
padding: 20rpx;
background: #FFFBF5;
border-radius: 12rpx;
border: 1rpx solid #E8D5C4;
}
.btn-outline.active {
background: #C41E3A;
color: #FFFFFF;
border-color: #C41E3A;
}
+28
View File
@@ -0,0 +1,28 @@
Page({
data: {
bookmarks: []
},
onShow() {
this.loadBookmarks();
},
loadBookmarks() {
const bookmarks = wx.getStorageSync('lunar-bookmarks') || [];
this.setData({ bookmarks });
},
removeBookmark(e) {
const date = e.currentTarget.dataset.date;
const bookmarks = this.data.bookmarks.filter(b => b.date !== date);
wx.setStorageSync('lunar-bookmarks', bookmarks);
this.setData({ bookmarks });
wx.showToast({ title: '已删除', icon: 'success' });
},
// 点击收藏项跳转到当日详情
openDetail(e) {
const date = e.currentTarget.dataset.date;
wx.navigateTo({ url: `/pages/day-detail/day-detail?date=${date}` });
}
});
+4
View File
@@ -0,0 +1,4 @@
{
"navigationBarTitleText": "我的收藏",
"enablePullDownRefresh": false
}
+20
View File
@@ -0,0 +1,20 @@
<view class="container">
<view class="card">
<view class="section-title">我的收藏</view>
<view class="bookmark-list" wx:if="{{bookmarks.length > 0}}">
<view class="bookmark-item" wx:for="{{bookmarks}}" wx:key="date" bindtap="openDetail" data-date="{{item.date}}">
<view class="flex justify-between items-center">
<view>
<text class="text-base font-medium">{{item.date}}</text>
<text class="text-xs text-muted block">{{item.lunarDate}}</text>
</view>
<view class="btn-ghost text-unlucky" catchtap="removeBookmark" data-date="{{item.date}}">删除</view>
</view>
</view>
</view>
<view class="empty-tip" wx:else>
<text class="text-sm text-muted">暂无收藏</text>
<text class="text-xs text-muted block mt-1">在日期详情页点击「收藏」即可添加</text>
</view>
</view>
</view>
+24
View File
@@ -0,0 +1,24 @@
.container {
padding: 20rpx;
}
.section-title {
font-size: 28rpx;
font-weight: 600;
margin-bottom: 16rpx;
color: #C41E3A;
}
.bookmark-item {
padding: 16rpx 0;
border-bottom: 1rpx solid #E8D5C4;
}
.bookmark-item:last-child {
border-bottom: none;
}
.empty-tip {
text-align: center;
padding: 40rpx 0;
}
+54
View File
@@ -0,0 +1,54 @@
Page({
data: {
weekStartDay: 0,
ziHourSect: 'lateZiNextDay',
solarTime: true,
showBuddhist: false,
highlightLunar: true
},
onShow() {
this.loadSettings();
},
loadSettings() {
const settings = wx.getStorageSync('lunar-settings') || {};
this.setData({
weekStartDay: settings.weekStartDay || 0,
ziHourSect: settings.ziHourSect || 'lateZiNextDay',
solarTime: settings.solarTime !== false,
showBuddhist: settings.showBuddhist === true,
highlightLunar: settings.highlightLunar !== false
});
},
saveSettings() {
const { weekStartDay, ziHourSect, solarTime, showBuddhist, highlightLunar } = this.data;
wx.setStorageSync('lunar-settings', { weekStartDay, ziHourSect, solarTime, showBuddhist, highlightLunar });
},
setWeekStart(e) {
this.setData({ weekStartDay: Number(e.currentTarget.dataset.v) });
this.saveSettings();
},
setZiSect(e) {
this.setData({ ziHourSect: e.currentTarget.dataset.v });
this.saveSettings();
},
onSolarTimeChange(e) {
this.setData({ solarTime: e.detail.value });
this.saveSettings();
},
onBuddhistChange(e) {
this.setData({ showBuddhist: e.detail.value });
this.saveSettings();
},
onHighlightLunarChange(e) {
this.setData({ highlightLunar: e.detail.value });
this.saveSettings();
}
});
+4
View File
@@ -0,0 +1,4 @@
{
"navigationBarTitleText": "偏好设置",
"enablePullDownRefresh": false
}
+38
View File
@@ -0,0 +1,38 @@
<view class="container">
<view class="card">
<view class="section-title">偏好设置</view>
<view class="setting-item">
<text class="setting-label">周起始日</text>
<view class="flex gap-2">
<view class="btn-outline {{weekStartDay === 0 ? 'active' : ''}}" bindtap="setWeekStart" data-v="0">周日</view>
<view class="btn-outline {{weekStartDay === 1 ? 'active' : ''}}" bindtap="setWeekStart" data-v="1">周一</view>
</view>
</view>
<view class="setting-item">
<text class="setting-label">子时流派</text>
<view class="flex gap-2">
<view class="btn-outline {{ziHourSect === 'lateZiNextDay' ? 'active' : ''}}" bindtap="setZiSect" data-v="lateZiNextDay">晚子时算次日</view>
<view class="btn-outline {{ziHourSect === 'lateZiSameDay' ? 'active' : ''}}" bindtap="setZiSect" data-v="lateZiSameDay">晚子时算当日</view>
</view>
</view>
<view class="setting-item">
<text class="setting-label">真太阳时校正</text>
<switch checked="{{solarTime}}" bindchange="onSolarTimeChange" color="#C41E3A"/>
</view>
<view class="setting-item">
<text class="setting-label">显示佛历提醒</text>
<switch checked="{{showBuddhist}}" bindchange="onBuddhistChange" color="#C41E3A"/>
</view>
<view class="setting-item">
<text class="setting-label">初一十五高亮</text>
<switch checked="{{highlightLunar}}" bindchange="onHighlightLunarChange" color="#C41E3A"/>
</view>
</view>
<view class="text-xs text-muted text-center mt-2">设置仅保存在本机,修改后立即生效</view>
</view>
+32
View File
@@ -0,0 +1,32 @@
.container {
padding: 20rpx;
}
.section-title {
font-size: 28rpx;
font-weight: 600;
margin-bottom: 16rpx;
color: #C41E3A;
}
.setting-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 20rpx 0;
border-bottom: 1rpx solid #E8D5C4;
}
.setting-item:last-child {
border-bottom: none;
}
.setting-label {
font-size: 28rpx;
}
.btn-outline.active {
background: #C41E3A;
color: #FFFFFF;
border-color: #C41E3A;
}
+17 -159
View File
@@ -7,140 +7,33 @@ Page({
userInfo: null,
loggedIn: false,
logging: false,
weekStartDay: 0,
ziHourSect: 'lateZiNextDay',
solarTime: true,
showBuddhist: false,
highlightLunar: true,
bookmarks: [],
// 生辰档案
profiles: [],
activeProfileId: '',
// 菜单角标
profileCount: 0,
maxFree: birthProfile.MAX_PROFILES,
canAdd: true,
showAddForm: false,
formName: '',
formGender: 'male',
formDate: '1990-01-01',
formTime: '12:00',
bookmarkCount: 0,
version: versionInfo.version,
buildNumber: versionInfo.buildNumber,
buildTime: versionInfo.buildTime,
commitSha: versionInfo.commitSha
},
onLoad() {
this.loadSettings();
this.loadBookmarks();
},
onShow() {
this.loadBookmarks();
this.loadProfiles();
this.refreshUser();
this.refreshCounts();
},
loadSettings() {
const settings = wx.getStorageSync('lunar-settings') || {};
this.setData({
weekStartDay: settings.weekStartDay || 0,
ziHourSect: settings.ziHourSect || 'lateZiNextDay',
solarTime: settings.solarTime !== false,
showBuddhist: settings.showBuddhist === true,
highlightLunar: settings.highlightLunar !== false
});
refreshUser() {
const token = wx.getStorageSync('token');
const userInfo = wx.getStorageSync('lunar-user-info');
this.setData({ loggedIn: !!token, userInfo: userInfo || null });
},
saveSettings() {
const { weekStartDay, ziHourSect, solarTime, showBuddhist, highlightLunar } = this.data;
wx.setStorageSync('lunar-settings', { weekStartDay, ziHourSect, solarTime, showBuddhist, highlightLunar });
},
loadBookmarks() {
refreshCounts() {
const bookmarks = wx.getStorageSync('lunar-bookmarks') || [];
this.setData({ bookmarks });
},
// ==================== 生辰档案 ====================
loadProfiles() {
const render = () => {
const profiles = birthProfile.getProfiles();
const active = birthProfile.getActiveProfile();
this.setData({
profiles,
activeProfileId: active ? active.id : '',
canAdd: profiles.length < this.data.maxFree
});
};
// 已登录时先从服务端同步,失败静默回退本地
if (birthProfile.isLoggedIn()) {
birthProfile.syncFromServer().then(render).catch(render);
} else {
render();
}
},
toggleAddForm() {
if (!this.data.showAddForm && !this.data.canAdd) {
wx.showToast({ title: `最多可免费绑定 ${this.data.maxFree} 个生辰`, icon: 'none' });
return;
}
this.setData({ showAddForm: !this.data.showAddForm });
},
onFormName(e) {
this.setData({ formName: e.detail.value });
},
setFormGender(e) {
this.setData({ formGender: e.currentTarget.dataset.g });
},
onFormDate(e) {
this.setData({ formDate: e.detail.value });
},
onFormTime(e) {
this.setData({ formTime: e.detail.value });
},
submitProfile() {
const { formName, formGender, formDate, formTime } = this.data;
if (!formDate || !formTime) {
wx.showToast({ title: '请选择出生日期和时间', icon: 'none' });
return;
}
const result = birthProfile.addProfile({
name: formName.trim() || '未命名',
gender: formGender,
birthday: formDate,
birthTime: formTime
});
if (!result.ok) {
wx.showToast({ title: result.msg, icon: 'none' });
return;
}
// 已登录时推送到服务端(静默失败,不影响本地)
birthProfile.pushProfileToServer(result.profile);
this.setData({ showAddForm: false, formName: '' });
wx.showToast({ title: '绑定成功', icon: 'success' });
this.loadProfiles();
},
removeProfile(e) {
const id = e.currentTarget.dataset.id;
const profile = this.data.profiles.find(p => p.id === id);
if (!profile) return;
wx.showModal({
title: '删除生辰',
content: `确定删除「${profile.name}」的生辰信息吗?`,
success: (res) => {
if (!res.confirm) return;
birthProfile.removeProfile(id);
birthProfile.removeProfileFromServer(profile);
wx.showToast({ title: '已删除', icon: 'success' });
this.loadProfiles();
}
const profiles = birthProfile.getProfiles();
this.setData({
bookmarkCount: bookmarks.length,
profileCount: profiles.length
});
},
@@ -166,8 +59,8 @@ Page({
wx.setStorageSync('lunar-user-info', res.data.user);
this.setData({ userInfo: res.data.user, loggedIn: true, logging: false });
wx.showToast({ title: '登录成功', icon: 'success' });
// 登录后同步服务端生辰档案
this.loadProfiles();
// 登录后拉取云端生辰档案,保证菜单计数准确
birthProfile.syncFromServer().then(() => this.refreshCounts()).catch(() => {});
} else {
this.setData({ logging: false });
wx.showToast({ title: (res && res.msg) || '登录失败', icon: 'none' });
@@ -198,45 +91,10 @@ Page({
});
},
// ==================== 偏好设置 ====================
setWeekStart(e) {
this.setData({ weekStartDay: Number(e.currentTarget.dataset.v) });
this.saveSettings();
},
setZiSect(e) {
this.setData({ ziHourSect: e.currentTarget.dataset.v });
this.saveSettings();
},
onSolarTimeChange(e) {
this.setData({ solarTime: e.detail.value });
this.saveSettings();
},
onBuddhistChange(e) {
this.setData({ showBuddhist: e.detail.value });
this.saveSettings();
},
onHighlightLunarChange(e) {
this.setData({ highlightLunar: e.detail.value });
this.saveSettings();
},
removeBookmark(e) {
const date = e.currentTarget.dataset.date;
let bookmarks = this.data.bookmarks.filter(b => b.date !== date);
wx.setStorageSync('lunar-bookmarks', bookmarks);
this.setData({ bookmarks });
wx.showToast({ title: '已删除', icon: 'success' });
},
navTo(e) {
const url = e.currentTarget.dataset.url;
// tabBar 页面必须用 switchTab 打开
const tabPages = ['/pages/home/home', '/pages/wish-tree/wish-tree', '/pages/bazi/bazi', '/pages/wiki/wiki', '/pages/settings/settings', '/pages/fortune/fortune'];
const tabPages = ['/pages/home/home', '/pages/wish-tree/wish-tree', '/pages/bazi/bazi', '/pages/wiki/wiki', '/pages/settings/settings'];
if (tabPages.includes(url)) {
wx.switchTab({ url });
} else {
+29 -115
View File
@@ -1,8 +1,7 @@
<view class="container">
<!-- 用户信息 -->
<!-- 登录与账号 -->
<view class="card">
<view class="section-title">用户信息</view>
<view class="flex items-center gap-2 justify-between" wx:if="{{loggedIn}}">
<view class="flex items-center justify-between" wx:if="{{loggedIn}}">
<view class="flex items-center gap-2">
<image src="{{userInfo.avatar}}" class="avatar" mode="aspectFill" wx:if="{{userInfo.avatar}}"/>
<view class="avatar avatar-placeholder" wx:else>
@@ -10,135 +9,50 @@
</view>
<view>
<text class="text-base font-medium">{{userInfo.nickname || '微信用户'}}</text>
<text class="text-xs text-muted block">已登录,档案云端同步</text>
<text class="text-xs text-muted block">已登录,生辰档案云端同步</text>
</view>
</view>
<view class="btn-ghost text-muted" bindtap="logout">退出</view>
</view>
<block wx:else>
<view class="text-sm text-muted mb-2">登录后可将生辰档案同步到云端,换设备不丢失</view>
<view class="flex items-center gap-2 mb-2">
<view class="avatar avatar-placeholder">
<text>客</text>
</view>
<view>
<text class="text-base font-medium">未登录</text>
<text class="text-xs text-muted block">绑定的生辰仅保存在本机,登录后才生效</text>
</view>
</view>
<view class="btn-primary text-center" bindtap="login">{{logging ? '登录中…' : '微信登录'}}</view>
<view class="text-xs text-muted text-center mt-2">登录后可将生辰档案同步到云端,换设备不丢失</view>
</block>
</view>
<!-- 生辰管理 -->
<!-- 我的数据 -->
<view class="card">
<view class="section-title flex justify-between items-center">
<text>生辰管理</text>
<text class="text-xs text-muted">{{profiles.length}}/{{maxFree}}</text>
</view>
<view class="text-xs text-muted mb-2">八字排盘基于生辰信息,每位用户可免费绑定 {{maxFree}} 个出生年月(如本人、家人)。</view>
<view class="profile-list" wx:if="{{profiles.length > 0}}">
<view class="profile-item" wx:for="{{profiles}}" wx:key="id">
<view class="flex justify-between items-center">
<view>
<view class="flex items-center gap-1">
<text class="text-base font-medium">{{item.name}}</text>
<text class="badge badge-lucky" wx:if="{{item.id === activeProfileId}}">使用中</text>
</view>
<text class="text-xs text-muted block">{{item.gender === 'female' ? '女' : '男'}} · {{item.birthday}} {{item.birthTime}}</text>
</view>
<view class="btn-ghost text-unlucky" bindtap="removeProfile" data-id="{{item.id}}">删除</view>
</view>
<view class="section-title">我的数据</view>
<view class="menu-item" bindtap="navTo" data-url="/pages/birth-profiles/birth-profiles">
<text class="menu-label">生辰管理</text>
<view class="menu-right">
<text class="menu-count">{{profileCount}}/{{maxFree}}</text>
<text class="menu-arrow"></text>
</view>
</view>
<view class="text-center text-muted p-2" wx:else>
<text>暂未绑定生辰,请到下方添加</text>
</view>
<view class="btn-outline text-center mt-2" bindtap="toggleAddForm" wx:if="{{canAdd}}">
{{showAddForm ? '收起' : '+ 添加生辰'}}
</view>
<view class="text-center text-xs text-muted mt-2" wx:else>
免费名额已用完,可删除旧档案后添加
</view>
<!-- 添加表单 -->
<block wx:if="{{showAddForm}}">
<view class="form-item mt-2">
<text class="form-label">备注名(如:本人、爸爸)</text>
<input class="form-input" placeholder="未命名" value="{{formName}}" bindinput="onFormName"/>
</view>
<view class="form-item">
<text class="form-label">性别</text>
<view class="flex gap-2">
<view class="btn-outline {{formGender === 'male' ? 'active' : ''}}" bindtap="setFormGender" data-g="male">男</view>
<view class="btn-outline {{formGender === 'female' ? 'active' : ''}}" bindtap="setFormGender" data-g="female">女</view>
</view>
</view>
<view class="form-item">
<text class="form-label">出生日期(公历)</text>
<picker mode="date" value="{{formDate}}" start="1900-01-01" end="2100-12-31" bindchange="onFormDate">
<view class="picker-input">{{formDate}}</view>
</picker>
</view>
<view class="form-item">
<text class="form-label">出生时间</text>
<picker mode="time" value="{{formTime}}" bindchange="onFormTime">
<view class="picker-input">{{formTime}}</view>
</picker>
</view>
<view class="btn-primary text-center" bindtap="submitProfile">保存生辰</view>
</block>
</view>
<!-- 偏好设置 -->
<view class="card">
<view class="section-title">偏好设置</view>
<view class="setting-item">
<text class="setting-label">周起始日</text>
<view class="flex gap-2">
<view class="btn-outline {{weekStartDay === 0 ? 'active' : ''}}" bindtap="setWeekStart" data-v="0">周日</view>
<view class="btn-outline {{weekStartDay === 1 ? 'active' : ''}}" bindtap="setWeekStart" data-v="1">周一</view>
<view class="menu-item" bindtap="navTo" data-url="/pages/bookmarks/bookmarks">
<text class="menu-label">我的收藏</text>
<view class="menu-right">
<text class="menu-count" wx:if="{{bookmarkCount > 0}}">{{bookmarkCount}}</text>
<text class="menu-arrow"></text>
</view>
</view>
<view class="setting-item">
<text class="setting-label">子时流派</text>
<view class="flex gap-2">
<view class="btn-outline {{ziHourSect === 'lateZiNextDay' ? 'active' : ''}}" bindtap="setZiSect" data-v="lateZiNextDay">晚子时算次日</view>
<view class="btn-outline {{ziHourSect === 'lateZiSameDay' ? 'active' : ''}}" bindtap="setZiSect" data-v="lateZiSameDay">晚子时算当日</view>
</view>
</view>
<view class="setting-item">
<text class="setting-label">真太阳时校正</text>
<switch checked="{{solarTime}}" bindchange="onSolarTimeChange" color="#C41E3A"/>
</view>
<view class="setting-item">
<text class="setting-label">显示佛历提醒</text>
<switch checked="{{showBuddhist}}" bindchange="onBuddhistChange" color="#C41E3A"/>
</view>
<view class="setting-item">
<text class="setting-label">初一十五高亮</text>
<switch checked="{{highlightLunar}}" bindchange="onHighlightLunarChange" color="#C41E3A"/>
<view class="menu-item" bindtap="navTo" data-url="/pages/preferences/preferences">
<text class="menu-label">设置</text>
<text class="menu-arrow"></text>
</view>
</view>
<!-- 收藏管理 -->
<view class="card">
<view class="section-title">我的收藏</view>
<view class="bookmark-list" wx:if="{{bookmarks.length > 0}}">
<view class="bookmark-item" wx:for="{{bookmarks}}" wx:key="date">
<view class="flex justify-between items-center">
<view>
<text class="text-base font-medium">{{item.date}}</text>
<text class="text-xs text-muted block">{{item.lunarDate}}</text>
</view>
<view class="btn-ghost text-unlucky" bindtap="removeBookmark" data-date="{{item.date}}">删除</view>
</view>
</view>
</view>
<view class="text-center text-muted" wx:else>
<text>暂无收藏</text>
</view>
</view>
<!-- 功能入口 -->
<!-- 功能 -->
<view class="card">
<view class="section-title">功能</view>
<view class="menu-item" bindtap="navTo" data-url="/pages/fortune/fortune">
+14 -70
View File
@@ -10,8 +10,8 @@
}
.avatar {
width: 80rpx;
height: 80rpx;
width: 96rpx;
height: 96rpx;
border-radius: 50%;
}
@@ -21,74 +21,7 @@
justify-content: center;
background: #C41E3A;
color: #FFFFFF;
font-size: 36rpx;
}
/* 生辰档案 */
.profile-item {
padding: 16rpx 0;
border-bottom: 1rpx solid #E8D5C4;
}
.profile-item:last-child {
border-bottom: none;
}
/* 添加生辰表单 */
.form-item {
margin-bottom: 24rpx;
}
.form-label {
font-size: 24rpx;
color: #6B5E53;
margin-bottom: 8rpx;
display: block;
}
.form-input {
padding: 20rpx;
background: #FFFBF5;
border-radius: 12rpx;
border: 1rpx solid #E8D5C4;
}
.picker-input {
padding: 20rpx;
background: #FFFBF5;
border-radius: 12rpx;
border: 1rpx solid #E8D5C4;
}
.setting-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 20rpx 0;
border-bottom: 1rpx solid #E8D5C4;
}
.setting-item:last-child {
border-bottom: none;
}
.setting-label {
font-size: 28rpx;
}
.btn-outline.active {
background: #C41E3A;
color: #FFFFFF;
border-color: #C41E3A;
}
.bookmark-item {
padding: 16rpx 0;
border-bottom: 1rpx solid #E8D5C4;
}
.bookmark-item:last-child {
border-bottom: none;
font-size: 40rpx;
}
.menu-item {
@@ -107,6 +40,17 @@
font-size: 28rpx;
}
.menu-right {
display: flex;
align-items: center;
gap: 8rpx;
}
.menu-count {
font-size: 24rpx;
color: #9E8E7E;
}
.menu-arrow {
color: #C9B8A6;
font-size: 36rpx;
+109 -11
View File
@@ -75,6 +75,21 @@ Page({
this.loadProducts();
},
onUnload() {
this.stopDanmakuScheduler();
},
onHide() {
this.stopDanmakuScheduler();
},
onShow() {
// 从后台/下一页返回时,若已有弹幕数据则恢复调度
if (this.danmakuRows && this.danmakuRows.length && !(this.danmakuTimers && this.danmakuTimers.length)) {
this.startDanmakuScheduler(this.danmakuRows);
}
},
onPullDownRefresh() {
const { currentTreeIndex, trees } = this.data;
const tree = trees[currentTreeIndex];
@@ -211,16 +226,8 @@ Page({
};
});
// 其余以弹幕飘过
const danmaku = list.slice(MAX_HANG).map((w, i) => ({
id: w.id,
content: w.content,
author: w.author || '匿名',
type: w.type,
top: 12 + (i % 6) * 7,
duration: 16 + w.content.length * 0.4,
delay: -(i * 2.1),
}));
// 其余以弹幕飘过:树桩处3行 + 置顶轮播下方1行,慢速均匀间隔不重叠
const danmaku = this.buildDanmaku(list.slice(MAX_HANG));
const cache = { hangWishes, danmaku, top };
this.wishCache[tree.id] = cache;
@@ -232,8 +239,93 @@ Page({
this.setData({
[`trees[${index}].hangWishes`]: cache.hangWishes,
topWishes: cache.top,
currentDanmaku: cache.danmaku,
});
// 启动弹幕调度:每行一条完毕后再出下一条
this.startDanmakuScheduler(cache.danmaku);
},
// 启动弹幕调度:每行同一时刻只播一条,前一条飘完再出下一条(循环)
startDanmakuScheduler(rows) {
this.stopDanmakuScheduler();
this.danmakuRows = rows || [];
this.danmakuTimers = [];
if (!this.danmakuRows.length) {
this.setData({ currentDanmaku: [] });
return;
}
const GAP = 1.5; // 同一行前一条飘完后,间隔再出下一条(秒)
// 每行独立调度:row 行的第 idx 条播完后,隔 GAP 秒播第 idx+1 条
const playRow = (row, idx) => {
const rowData = this.danmakuRows[row];
if (!rowData) return;
const item = rowData.list[idx % rowData.list.length];
// 更新该行当前弹幕(用行号作为 key 保证 setData 局部刷新)
this.setData({
[`currentDanmaku[${row}]`]: {
key: `${row}-${idx % rowData.list.length}-${Date.now()}`,
id: item.id,
content: item.content,
author: item.author,
type: item.type,
top: rowData.top,
duration: rowData.duration,
},
});
// 前一条飘完 + 间隔后,播下一条
const timer = setTimeout(() => {
playRow(row, idx + 1);
}, (rowData.duration + GAP) * 1000);
this.danmakuTimers[row] = timer;
};
// 初始化 currentDanmaku 数组长度,并启动每行
this.setData({ currentDanmaku: new Array(this.danmakuRows.length).fill(null) });
this.danmakuRows.forEach((_, row) => {
// 各行错开启动,避免 4 行同时从右侧涌出
const startTimer = setTimeout(() => playRow(row, 0), row * 1200);
this.danmakuTimers.push(startTimer);
});
},
// 停止弹幕调度
stopDanmakuScheduler() {
if (this.danmakuTimers) {
this.danmakuTimers.forEach((t) => clearTimeout(t));
this.danmakuTimers = [];
}
},
// 构建弹幕:共 4 行(行 0-2 树桩处三行,行 3 顶部置顶轮播下方)
// 按行分组返回,由 JS 定时器控制:同一行一条完毕后再出下一条,不重叠
buildDanmaku(list) {
const DURATION_BOTTOM = 30; // 树桩处一条飘完全屏的秒数(慢速)
const DURATION_TOP = 24; // 顶部行稍快一点
// 行位置(屏幕百分比):
// - 行3 顶部行紧贴置顶轮播下方(稍有空隙)
// - 行0-2 树桩处三行,第一条68%,三行紧凑(间隔5%)
const ROW_TOPS = [68, 73, 78, 12];
const ROW_DURATIONS = [DURATION_BOTTOM, DURATION_BOTTOM, DURATION_BOTTOM, DURATION_TOP];
// 轮流分配到 4 行
const rows = [[], [], [], []];
list.forEach((w, i) => {
rows[i % 4].push(w);
});
// 每行存该行的所有弹幕(带位置/时长),供定时器轮流播放
return rows.map((rowList, row) => ({
top: ROW_TOPS[row],
duration: ROW_DURATIONS[row],
list: rowList.map((w) => ({
id: w.id,
content: w.content,
author: w.author || '匿名',
type: w.type,
})),
})).filter((r) => r.list.length > 0);
},
// 格式化许愿
@@ -457,4 +549,10 @@ Page({
path: '/pages/wish-tree/wish-tree',
};
},
onShareTimeline() {
return {
title: '快来许愿树许下你的愿望吧!'
};
}
});
+7 -7
View File
@@ -45,14 +45,14 @@
</swiper-item>
</swiper>
<!-- 弹幕层(超出50条的心愿缓缓飘过) -->
<!-- 弹幕层(超出30条的心愿缓缓飘过,每行一条完毕再出下一条 -->
<view class="danmaku-layer">
<view
wx:for="{{currentDanmaku}}"
wx:key="id"
class="danmaku-item {{item.type === 'paid' ? 'paid' : ''}}"
style="top: {{item.top}}%; animation-duration: {{item.duration}}s; animation-delay: {{item.delay}}s;"
>{{item.content}} · {{item.author}}</view>
<block wx:for="{{currentDanmaku}}" wx:key="key" wx:if="{{item}}">
<view
class="danmaku-item {{item.type === 'paid' ? 'paid' : ''}}"
style="top: {{item.top}}%; animation-duration: {{item.duration}}s;"
>{{item.content}} · {{item.author}}</view>
</block>
</view>
<!-- 边缘暗角 -->
+3 -2
View File
@@ -142,7 +142,8 @@
text-shadow: 0 2rpx 6rpx rgba(0, 0, 0, 0.6);
animation-name: danmaku;
animation-timing-function: linear;
animation-iteration-count: infinite;
animation-iteration-count: 1;
animation-fill-mode: both;
will-change: transform;
}
@@ -608,7 +609,7 @@
}
}
/* 弹幕:从屏幕右侧飘到左侧 */
/* 弹幕:从屏幕右侧飘到左侧。每条只播一次,由 JS 控制一行一条排队出现。 */
@keyframes danmaku {
0% {
transform: translateX(100vw);
+12 -3
View File
@@ -4,7 +4,11 @@ go 1.22
require (
github.com/gin-gonic/gin v1.9.1
github.com/glebarez/sqlite v1.11.0
github.com/golang-jwt/jwt/v5 v5.3.1
github.com/joho/godotenv v1.5.1
gorm.io/driver/mysql v1.6.0
gorm.io/gorm v1.31.2
)
require (
@@ -35,11 +39,16 @@ require (
require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/glebarez/go-sqlite v1.21.2 // indirect
github.com/go-sql-driver/mysql v1.8.1 // indirect
github.com/golang-jwt/jwt/v5 v5.3.1 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
golang.org/x/crypto v0.17.0 // indirect
gorm.io/driver/mysql v1.6.0 // indirect
gorm.io/gorm v1.31.2 // indirect
modernc.org/libc v1.22.5 // indirect
modernc.org/mathutil v1.5.0 // indirect
modernc.org/memory v1.5.0 // indirect
modernc.org/sqlite v1.23.1 // indirect
)
+27 -3
View File
@@ -9,12 +9,18 @@ github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583j
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=
github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg=
github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU=
github.com/glebarez/go-sqlite v1.21.2 h1:3a6LFC4sKahUunAmynQKLZceZCOzUthkRkEAl9gAXWo=
github.com/glebarez/go-sqlite v1.21.2/go.mod h1:sfxdZyhQjTM2Wry3gVYWaW072Ri1WMdWJi0k6+3382k=
github.com/glebarez/sqlite v1.11.0 h1:wSG0irqzP6VurnMEpFGer5Li19RpIRi2qvQz++w0GMw=
github.com/glebarez/sqlite v1.11.0/go.mod h1:h8/o8j5wiAsqSPoWELDUdJXhjAhsVliSn7bWZjOhrgQ=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
@@ -33,6 +39,10 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 h1:Xim43kblpZXfIBQsbuBVKCudVG457BR2GZFIz3uw3hQ=
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26/go.mod h1:dDKJzRmX4S37WGHujM7tX//fmj1uioxKzKxz3lo4HJo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
@@ -48,6 +58,8 @@ github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
@@ -57,6 +69,9 @@ github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZ
github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
@@ -83,12 +98,11 @@ golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
@@ -99,6 +113,16 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/mysql v1.6.0 h1:eNbLmNTpPpTOVZi8MMxCi2aaIm0ZpInbORNXDwyLGvg=
gorm.io/driver/mysql v1.6.0/go.mod h1:D/oCC2GWK3M/dqoLxnOlaNKmXz8WNTfcS9y5ovaSqKo=
gorm.io/driver/sqlite v1.6.0 h1:WHRRrIiulaPiPFmDcod6prc4l2VGVWHz80KspNsxSfQ=
gorm.io/driver/sqlite v1.6.0/go.mod h1:AO9V1qIQddBESngQUKWL9yoH93HIeA1X6V633rBwyT8=
gorm.io/gorm v1.31.2 h1:3o8FXNo9v9S858gil+3LlZA1LkCOzgb4g5BL64FgaCo=
gorm.io/gorm v1.31.2/go.mod h1:XyQVbO2k6YkOis7C2437jSit3SsDK72s7n7rsSHd+Gs=
modernc.org/libc v1.22.5 h1:91BNch/e5B0uPbJFgqbxXuOnxBQjlS//icfQEGmvyjE=
modernc.org/libc v1.22.5/go.mod h1:jj+Z7dTNX8fBScMVNRAYZ/jF91K8fdT2hYMThc3YjBY=
modernc.org/mathutil v1.5.0 h1:rV0Ko/6SfM+8G+yKiyI830l3Wuz1zRutdslNoQ0kfiQ=
modernc.org/mathutil v1.5.0/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
modernc.org/memory v1.5.0 h1:N+/8c5rE6EqugZwHii4IFsaJ7MUhoWX07J5tC/iI5Ds=
modernc.org/memory v1.5.0/go.mod h1:PkUhL0Mugw21sHPeskwZW4D6VscE/GQJOnIpCnW6pSU=
modernc.org/sqlite v1.23.1 h1:nrSBg4aRQQwq59JpvGEQ15tNxoO5pX/kUjcRNwSAGQM=
modernc.org/sqlite v1.23.1/go.mod h1:OrDj17Mggn6MhE+iPbBNf7RGKODDE9NFT0f3EwDzJqk=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
+2
View File
@@ -20,6 +20,7 @@ type ServerConfig struct {
}
type DatabaseConfig struct {
Type string
Host string
Port string
User string
@@ -59,6 +60,7 @@ func Load() *Config {
CORSOrigins: getEnv("CORS_ORIGINS", ""),
},
Database: DatabaseConfig{
Type: getEnv("DB_TYPE", "mysql"),
Host: getEnv("DB_HOST", "localhost"),
Port: getEnv("DB_PORT", "3306"),
User: getEnv("DB_USER", "root"),
+21 -9
View File
@@ -4,6 +4,7 @@ import (
"fmt"
"log"
"github.com/glebarez/sqlite"
"gorm.io/driver/mysql"
"gorm.io/gorm"
"github.com/gouki/lunar-server/internal/model"
@@ -13,16 +14,27 @@ var DB *gorm.DB
// InitDB 初始化数据库连接
func InitDB(cfg *Config) error {
dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=True&loc=Local",
cfg.Database.User,
cfg.Database.Password,
cfg.Database.Host,
cfg.Database.Port,
cfg.Database.Name,
)
var err error
DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
switch cfg.Database.Type {
case "sqlite", "sqlite3":
// DB_NAME 作为 SQLite 文件路径,例如 /app/data/lunar.db
dbPath := cfg.Database.Name
if dbPath == "" {
dbPath = "lunar.db"
}
DB, err = gorm.Open(sqlite.Open(dbPath), &gorm.Config{})
default:
dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=True&loc=Local",
cfg.Database.User,
cfg.Database.Password,
cfg.Database.Host,
cfg.Database.Port,
cfg.Database.Name,
)
DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
}
if err != nil {
return fmt.Errorf("failed to connect database: %w", err)
}