feat: refine profile and home UI with dynamic fortune rules
No files matched your search
@@ -1,5 +1,5 @@
|
||||
node_modules/
|
||||
dist/
|
||||
dist-h5/
|
||||
.swc/
|
||||
.DS_Store
|
||||
|
||||
@@ -10,7 +10,7 @@ export default defineConfig(async () => ({
|
||||
828: 1.81 / 2
|
||||
},
|
||||
sourceRoot: 'src',
|
||||
outputRoot: 'dist',
|
||||
outputRoot: process.env.TARO_ENV === 'h5' ? 'dist-h5' : 'dist',
|
||||
plugins: ['@tarojs/plugin-framework-react'],
|
||||
defineConstants: {},
|
||||
copy: {
|
||||
@@ -19,6 +19,14 @@ export default defineConfig(async () => ({
|
||||
},
|
||||
framework: 'react',
|
||||
compiler: 'webpack5',
|
||||
h5: {
|
||||
postcss: {
|
||||
pxtransform: {
|
||||
enable: true,
|
||||
config: { baseFontSize: 20, minRootSize: 16, maxRootSize: 40 }
|
||||
}
|
||||
}
|
||||
},
|
||||
mini: {
|
||||
postcss: {
|
||||
pxtransform: {
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
# 前端五行报告:普通扶抑简化参考算法 v1
|
||||
|
||||
用户确认采用可解释的普通扶抑综合评分。本规则为本产品的确定性参考算法,不是统一命理标准或专业断命依据;只作传统文化娱乐参考。
|
||||
|
||||
## 输入与排盘
|
||||
|
||||
- 只使用保存后的公历生日、出生时辰,不使用接口返回的 `elementReport`。
|
||||
- 使用锁定版本的 `lunar-typescript` 生成四柱和地支藏干;年/月柱沿用库的节气划分。
|
||||
- 输入按北京时间处理,不转换浏览器时区,不作真太阳时校正。
|
||||
- 只有时辰时,使用该时辰起始小时(子时23点,丑时1点等);库 `setSect(2)` 约定日柱零点换日。由于缺少具体分钟,节气交界的时辰无法精确划分;不声称处理了分钟级边界。
|
||||
- 日期支持1900至2100年;非法日期、缺失/非法时辰返回空状态,不伪造默认五行或日主。
|
||||
|
||||
## 组成比例
|
||||
|
||||
四个天干各10份,年/日/时支各10份,月支18份。地支分到其藏干:一藏干100%,两藏干70%/30%,三藏干60%/30%/10%,顺序使用历法库藏干顺序。这些份数为产品约定。用最大余数法转换为整数百分比,保证五项之和为100%。
|
||||
|
||||
## 三项评分
|
||||
|
||||
1. 得令(40%):以月支主五行作为季节,辰戌丑未简化为土。日主与季节同类为旺100分,季节生日主为相80分,日主生季节为休50分,日主克季节为囚30分,季节克日主为死15分。旺、相标为月令支持。
|
||||
2. 得地(30%):四支藏干中与日主同五行的份额相加,达到两个完整根计100分,其余按比例计分并封顶100分。有任何同类藏干即标为有根;“有根”不等于“根气充分”。
|
||||
3. 得势(30%):排除日干本身,计算其他天干和所有地支藏干中印星(生日主)与比劫(同日主)的加权份额占比。月支仍取18份,其他支10份,其他天干10份,占比即评分。达到50%标为生扶力量占优。
|
||||
|
||||
总分 = 得令×0.4 + 得地×0.3 + 得势×0.3,四舍五入到整数。该启发式中月令也参与藏干和得势,是刻意强调季节的产品约定,并非三份独立统计样本。
|
||||
|
||||
## 扶抑喜忌
|
||||
|
||||
- 小于45分:偏弱。喜生扶,列印星、比劫;忌项为食伤、财、官杀。
|
||||
- 大于55分:偏强。喜泄耗制衡,列食伤、财、官杀;忌项为印星、比劫。
|
||||
- 45到55分(含边界):相对平衡,不强行指定喜用/忌用;页面提示保持协调。
|
||||
|
||||
此处“喜用”是扶抑方向集合,不进一步判断唯一用神或精确优先级。不包含从格、专旺、化气、合冲刑害、调候、藏干司令天数等;不能把本算法表述为完整八字喜用神体系。
|
||||
|
||||
## 更新与验收
|
||||
|
||||
`useDidShow` 重新读取 `GET /api/user/profile` 的个人资料;生日或时辰改变后,`useMemo` 重新计算整份报告。昵称、头像、性别、地点不参与本版计算。加载失败显示重试入口,不退回假资料。保存使用原来的 `PUT /api/user/profile`,无需新增报告接口。
|
||||
|
||||
执行 `npm run test:elements`,覆盖强弱反转、藏干根气、无效日期、百分比守恒、时辰变化、节气月份切换和子时换日。构建验证仍需 `tsc --noEmit`、H5与小程序构建。
|
||||
|
||||
开发者工具验收:我的→我的元素,检查五项比例、强弱、得令/得地/得势说明;返回修改生日或时辰并保存,再次进入元素页检查四柱和报告。测试平衡命例时,喜忌应显示“暂无明显偏向/偏忌”。
|
||||
@@ -0,0 +1,51 @@
|
||||
# 首页动态生成与验收(开发维护说明)
|
||||
|
||||
用户确认:纯前端简化参考规则;页面不公开公式、权重、计算依据;维度卡片仅展示列表,不做详情交互。因此下面内容仅为维护文档,不渲染进首页。
|
||||
|
||||
## 数据与更新
|
||||
|
||||
只请求 `GET /api/user/profile` 获取生日、时辰、头像,不读取旧 `/api/home/overview` 的报告,也不使用异常时的固定42分示例。沿用 `calculateFiveElements` 的扶抑规则,以及按春节换年的生肖和合冲关系。需要有效生日、时辰,缺失时显示完善资料入口;网络失败显示重试。H5显式 `?preview=1` 由现有预览适配器提供示例个人资料,不请求后端。
|
||||
|
||||
北京时间日期作为基准,昨日/今日/明日分别偏移−1/0/+1。每份报告独立生成整套公历、星期、农历、摘要、指数、吉色吉数、吉向吉时和八个维度。页面显示时重读个人资料;北京时间零点刷新相对日期。生日、时辰、日期任一输入变化后重新计算,相同输入结果稳定,不调用随机数。
|
||||
|
||||
## 评分约定
|
||||
|
||||
本产品的简化娱乐规则,不代表统一命理标准。分值仅用于界面参考,不解释为健康、财富或事件发生的概率。
|
||||
|
||||
- 日主喜忌由已经确认的普通扶抑算法产生。
|
||||
- 某元素在喜用集合:基础权重 + round(max(0,20−个人该元素百分比)/5)。在忌用集合:−基础权重 − round(max(0,个人该元素百分比−20)/5)。相对平衡时不加减。即先判断扶抑方向,再小幅调节份额,不把“缺少”直接等同于“喜用”。
|
||||
- 当日公共基分=50 + 日干五行喜忌项(基础权重10) + 出生生肖年支对当日日支的关系分×5。关系分沿用六合+2、三合同组+1、六冲−2、相害−1、其余0。
|
||||
- 各维度再加该维度五行的喜忌项(基础权重8),以及日干五行对维度五行的同类/生助+6、相克−6、其余0。
|
||||
- 黄历宜忌读取所选日期的历法库数据,匹配该维度活动关键词。命中忌为−10,否则命中宜为+10,否则0;同项冲突优先忌。不把黄历活动误写成事件必然发生。
|
||||
- 维度分限制15到90;≥50显示宜,<50显示忌。展示文案按宜/忌选择对应普通生活建议,再用日干奇偶选择文案变体;不是固定的一套八维文案,也不以随机数伪装计算。
|
||||
- 八个维度等权平均并四舍五入为综合指数。≥80大吉、≥65小吉、≥50平日、≥35小逆、其余谨慎。
|
||||
- 维度关联:情感/社交=火,健康/事业=木,生活=土,财富=金,学业/出行=水。活动词见 `definitions`,属于产品简化映射。
|
||||
|
||||
普通建议仅涉及日常沟通、整理、作息、预算核对、任务安排和路线准备,不生成诊疗、投资或事故预测。摘要由当日状态和最高/最低分维度形成;同分时使用均衡描述。
|
||||
|
||||
## 吉色、吉数、吉向、吉时
|
||||
|
||||
- 有利五行取扶抑报告喜用集合;相对平衡时只在颜色/数字展示中取两个较低占比元素作装饰参考,不重新定义喜用。结合所选日干的生助关系排序,取两项。
|
||||
- 色盘映射:木为绿、火为粉橘、土为杏麦、金为白金、水为蓝;按日干奇偶选色调。
|
||||
- 数字映射采用产品约定的河图数:木3/8、火2/7、土5/0、金4/9、水1/6,按日支奇偶选对应数字。
|
||||
- 吉向读取所选当日 `getDayPositionXiDesc()`,作为传统喜神方位参考;指南针图标跟随方向旋转。
|
||||
- 吉时只在当日 `getTimes()` 的“吉”片段中选择,以时干喜忌项(基础权重2)和出生年支对时支关系排序,取两个不重复时支。用历法库具体起止片段显示:早子时00–01,夜子时23–24,不把跨日片段混作同一天。若无时段,显示暂无参考时段。
|
||||
|
||||
## 图标、列表、排序和导航
|
||||
|
||||
八维图标、水滴和灵境头像为原创矢量源转换的256像素透明PNG,源码在 `scripts/render-home-icons.cjs`。统一由共享 `AppTabBar` 提供首页与我的导航;H5关闭Taro重复系统tabBar,微信端保留原tab配置并使用 `switchTab`。
|
||||
|
||||
`src/index.html` 交给Taro的HTML插件生成预览入口与正确的脚本文件名,不再手写分块编号。模板注入rem响应式脚本,H5使用baseFontSize20、minRootSize16、maxRootSize40;修复以前缺少脚本导致宽屏/窄屏缩放不一致的问题。
|
||||
|
||||
维度按本机顺序展示,不默认按宜忌重排。排序页用上下按钮调整,完成后写入 `home.dimension-order.v1`;损坏或旧存储通过去重/过滤/补齐修复为八维。页面没有不可点击的伪详情箭头,也没有评分依据展开入口。
|
||||
|
||||
## 验收
|
||||
|
||||
1. 开发者工具打开首页;检查水滴头像、三个日期、真实农历、紫色指数卡、四块参考信息、八维图标与卡片、底部灵境头像。
|
||||
2. 依次切换昨日/今日/明日,日期与状态、整份报告同步变化;不同字段允许在某些日期相同,不人为强制每项变化。
|
||||
3. 修改生日或时辰保存后回首页,报告按新资料重新计算;昵称/头像不参与评分。
|
||||
4. 点击排序,用上下按钮调整后完成,退出重进仍保留八维顺序;首尾按钮不可越界。
|
||||
5. 列表无详情点击交互;页面不显示评分公式、干支依据、权重或测试工具,只保留简短娱乐参考标注。
|
||||
6. 切换窄屏、常规屏、长屏检查文本、卡片和安全区;从首页切我的,导航样式一致,H5不重复渲染原生tabBar。
|
||||
|
||||
自动验证:`npm run test:home`。验证真实日期/农历、三日切换、评分一致性、同输入稳定、生日时辰变化、吉时来源和边界、排序修复及图标资产。
|
||||
@@ -0,0 +1,51 @@
|
||||
# 我的生肖
|
||||
|
||||
按用户确认,以春节(农历正月初一)换生肖,使用公历生日经 `lunar-typescript` 转为农历,读取 `getYearShengXiao()`。不使用公历年份模12,也不使用以立春为界的八字年柱。
|
||||
|
||||
`src/utils/zodiac.ts` 只接收生日,返回十二生肖名称或空值。缺失或无效生日不默认展示兔子。支持1900至2100年,和当前元素报告的生日范围一致。
|
||||
|
||||
“我的生肖”入口与弹窗共用同一个 `zodiac` 结果及 `ZodiacMascot` 组件。十二张图标为本地256×256透明PNG,矢量源保存在 `scripts/render-zodiac-icons.cjs`。通过 `sharp` 可重新生成,运行时无需依赖 `sharp`。
|
||||
|
||||
页面返回时通过现有 `GET /api/user/profile` 获取最新生日,生日变化后重新计算生肖。保存生日沿用 `PUT /api/user/profile`,不新增生肖接口。图标、弹窗标题和“属X”名称随结果一起变化;隐藏生日开关不影响计算。
|
||||
|
||||
## 验收
|
||||
|
||||
1. 在开发者工具使用测试账号,进入“我的”,点击“我的生肖”,入口及弹窗应显示同一种动物,弹窗有对应“属X”名称。
|
||||
2. 修改测试账号生日为2024-02-09并保存,返回应显示兔;改为2024-02-10并保存,返回应显示龙。
|
||||
3. 2024-02-05在立春之后但春节之前,仍应为兔;避免把“我的元素”的节气年柱与日常生肖混用。
|
||||
4. 对缺失或非法生日,入口显示“待完善”,弹窗提示完善生日并提供编辑入口。
|
||||
5. 点击遮罩或“知道了”关闭弹窗,进入资料编辑与生肖按钮保持独立。
|
||||
|
||||
自动验证:`npm run test:zodiac`,覆盖春节前后、十二生肖周期、非法生日、资料改变和图标资产完整性。H5和微信小程序均需构建通过。
|
||||
|
||||
## 动态生肖周运:合冲简化规则 v1
|
||||
|
||||
用户已确认采用纯前端合冲关系计算,并要求公开权重与判断依据。输入为保存后的生日和北京时间当前日期。生日先按春节换年得到生肖,再对应子丑寅卯辰巳午未申酉戌亥的出生年支。按北京时间本周一至周日,用历法库计算七天日支;不是按公历日期模12伪造日支。
|
||||
|
||||
每天按以下互斥关系计一次分:
|
||||
|
||||
| 关系 | 分数 | 对应关系 |
|
||||
| --- | --- | --- |
|
||||
| 六合 | +2 | 子丑、寅亥、卯戌、辰酉、巳申、午未 |
|
||||
| 三合同组 | +1 | 申子辰、亥卯未、寅午戌、巳酉丑,同组且不同支 |
|
||||
| 六冲 | −2 | 子午、丑未、寅申、卯酉、辰戌、巳亥 |
|
||||
| 相害 | −1 | 子未、丑午、寅巳、卯辰、申亥、酉戌 |
|
||||
| 平常 | 0 | 其余关系,包括相同地支 |
|
||||
|
||||
六合与六冲表复用历法库 `LunarUtil.HE_ZHI_6` / `LunarUtil.CHONG`。三合同组只是出生年支与日支两支间的助力关系,不声称完整三合成局。不纳入刑、破或八字整体。权重与以下阈值是本产品的简化娱乐参考规则,不是统一命理标准。
|
||||
|
||||
七天分数求和:≥2为“顺势”,≤−2为“谨慎”,−1至1为“平稳”。正分日列为助力日,负分日列为留意日。摘要由本周实际天数、周状态及其对应建议组成;同一生肖同周稳定,不随机。不同生肖/周次可能同为“平稳”,不保证每次切换都换一个状态。
|
||||
|
||||
弹窗展示周一/周日的完整公历日期、状态、摘要、助力/留意日期,可展开权重、周总分与七天日支/关系/分数。明确标注“仅作传统文化娱乐参考”。普通建议限于沟通、协调、确认安排,不生成健康或投资预测。
|
||||
|
||||
页面显示、弹窗打开时检查北京时间日期;弹窗保持打开时在北京时间零点刷新,跨周后重新计算。没有后端报告接口,没有持久化周运结果。无效生日不给出周运;无效设备日期显示日期检查提示。
|
||||
|
||||
### 周运验收
|
||||
|
||||
1. “我的”→“我的生肖”,确认显示本周周一至周日区间、生肖、动态摘要和日期。
|
||||
2. 展开“判断依据”,逐日分数合计应等于周总分;总分对应状态应与上述阈值一致。
|
||||
3. 修改生日跨生肖,检查图标、名称、七天关系和摘要一起更新;同生肖的不同生日在同周允许结果相同。
|
||||
4. 按北京时间周日/周一检查周区间,跨年周应保留完整年份。不要用UTC日期替代北京时间日期。
|
||||
5. 小屏下滚动查看详细依据,“知道了”按钮始终可用;遮罩仍可关闭弹窗。
|
||||
|
||||
测试:`npm run test:zodiac-weekly`,覆盖所有地支关系及对称性、北京时间零点、同周稳定、跨年/跨周、十二生肖结果差异、分数复算、非法输入。
|
||||
@@ -3,6 +3,10 @@
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"test:elements": "node --test scripts/fiveElements.test.cjs",
|
||||
"test:zodiac": "node --test scripts/zodiac.test.cjs",
|
||||
"test:zodiac-weekly": "node --test scripts/zodiacWeekly.test.cjs",
|
||||
"test:home": "node --test scripts/homeOverview.test.cjs",
|
||||
"dev:weapp": "taro build --type weapp --watch",
|
||||
"build:weapp": "taro build --type weapp"
|
||||
},
|
||||
@@ -16,6 +20,7 @@
|
||||
"@tarojs/runtime": "3.6.35",
|
||||
"@tarojs/shared": "3.6.35",
|
||||
"@tarojs/taro": "3.6.35",
|
||||
"china-area-data": "^5.0.1",
|
||||
"lunar-typescript": "^1.8.6",
|
||||
"react": "18.2.0",
|
||||
"react-dom": "18.2.0"
|
||||
|
||||
@@ -35,6 +35,9 @@ importers:
|
||||
'@tarojs/taro':
|
||||
specifier: 3.6.35
|
||||
version: 3.6.35(@tarojs/helper@3.6.35(supports-color@8.1.1))(@tarojs/runtime@3.6.35(@tarojs/shared@3.6.35))(@types/react@18.3.31)(postcss@8.5.26)
|
||||
china-area-data:
|
||||
specifier: ^5.0.1
|
||||
version: 5.0.1
|
||||
lunar-typescript:
|
||||
specifier: ^1.8.6
|
||||
version: 1.8.6
|
||||
@@ -2083,6 +2086,9 @@ packages:
|
||||
charenc@0.0.2:
|
||||
resolution: {integrity: sha512-yrLQ/yVUFXkzg7EDQsPieE/53+0RlaWTs+wBrvW36cyilJ2SaDWfl4Yj7MtLTXleV9uEKefbAGUPv2/iWSooRA==}
|
||||
|
||||
china-area-data@5.0.1:
|
||||
resolution: {integrity: sha512-BQDPpiv5Nn+018ekcJK2oSD9PAD+E1bvXB0wgabc//dFVS/KvRqCgg0QOEUt3vBkx9XzB5a9BmkJCEZDBxVjVw==}
|
||||
|
||||
chokidar@3.6.0:
|
||||
resolution: {integrity: sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==}
|
||||
engines: {node: '>= 8.10.0'}
|
||||
@@ -8818,6 +8824,8 @@ snapshots:
|
||||
|
||||
charenc@0.0.2: {}
|
||||
|
||||
china-area-data@5.0.1: {}
|
||||
|
||||
chokidar@3.6.0:
|
||||
dependencies:
|
||||
anymatch: 3.1.3
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
const test = require('node:test')
|
||||
const assert = require('node:assert/strict')
|
||||
const fs = require('node:fs')
|
||||
const path = require('node:path')
|
||||
const Module = require('node:module')
|
||||
const ts = require('typescript')
|
||||
const filename = path.resolve(__dirname, '../src/utils/fiveElements.ts')
|
||||
const compiled = ts.transpileModule(fs.readFileSync(filename, 'utf8'), {
|
||||
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2017 }
|
||||
}).outputText
|
||||
const loaded = new Module(filename, module)
|
||||
loaded.filename = filename
|
||||
loaded.paths = Module._nodeModulePaths(path.dirname(filename))
|
||||
loaded._compile(compiled, filename)
|
||||
const { analyzePillars, calculateFiveElements } = loaded.exports
|
||||
|
||||
test('同一日主在强弱不同的四柱下,扶抑方向应反转', () => {
|
||||
const strong = analyzePillars(['甲寅', '乙卯', '甲寅', '乙卯'])
|
||||
const weak = analyzePillars(['丙午', '丁巳', '甲申', '戊戌'])
|
||||
assert.equal(strong.dayMaster, weak.dayMaster)
|
||||
assert.equal(strong.strength, '偏强')
|
||||
assert.equal(weak.strength, '偏弱')
|
||||
assert.equal(strong.favorable, '火土金')
|
||||
assert.equal(weak.favorable, '水木')
|
||||
assert.equal(strong.analysis.season.supported, true)
|
||||
assert.equal(weak.analysis.roots.supported, false)
|
||||
})
|
||||
|
||||
test('地支藏干中的同类根必须计入,得势不包含日干自身', () => {
|
||||
const report = analyzePillars(['丙午', '丁巳', '甲辰', '戊戌'])
|
||||
assert.equal(report.analysis.roots.supported, true) // 辰藏乙,不能只看辰土。
|
||||
assert.ok(report.analysis.roots.score > 0)
|
||||
const noSupport = analyzePillars(['丙午', '丁巳', '甲申', '戊戌'])
|
||||
assert.ok(noSupport.analysis.support.score < 20)
|
||||
})
|
||||
|
||||
test('有效日期和时辰改变后重新排盘,不受昵称或后端报告影响', () => {
|
||||
const first = calculateFiveElements('1998-06-18', '辰时')
|
||||
assert.deepEqual(first.pillars, ['戊寅', '戊午', '丙申', '壬辰'])
|
||||
const changedDate = calculateFiveElements('1998-12-18', '辰时')
|
||||
const changedHour = calculateFiveElements('1998-06-18', '戌时')
|
||||
assert.notDeepEqual(first.scores, changedDate.scores)
|
||||
assert.notDeepEqual(first.pillars, changedHour.pillars)
|
||||
assert.notDeepEqual(first.scores, changedHour.scores)
|
||||
assert.deepEqual(first, calculateFiveElements('1998-06-18', '7'))
|
||||
})
|
||||
|
||||
test('百分比总和为100,强弱有界,喜忌互斥,平衡不强行指定喜忌', () => {
|
||||
let balanced = false
|
||||
for (let month = 1; month <= 12; month++) {
|
||||
for (const hour of ['子时', '辰时', '午时', '酉时']) {
|
||||
const report = calculateFiveElements(`2000-${String(month).padStart(2, '0')}-15`, hour)
|
||||
assert.equal(report.scores.reduce((sum, score) => sum + score.value, 0), 100)
|
||||
assert.ok(report.scores.every((score) => Number.isInteger(score.value) && score.value >= 0 && score.value <= 100))
|
||||
assert.ok(report.strengthScore >= 0 && report.strengthScore <= 100)
|
||||
assert.ok(![...report.favorable].some((element) => report.unfavorable.includes(element)))
|
||||
if (report.strength === '相对平衡') {
|
||||
balanced = true
|
||||
assert.equal(report.favorable, '')
|
||||
assert.equal(report.unfavorable, '')
|
||||
}
|
||||
}
|
||||
}
|
||||
assert.equal(balanced, true)
|
||||
})
|
||||
|
||||
test('不把无效生日、缺失时辰或越界时辰转换成虚构报告', () => {
|
||||
for (const [date, hour] of [
|
||||
['', '辰时'], ['2025-02-29', '辰时'], ['2024-02-30', '辰时'],
|
||||
['2024-13-01', '辰时'], ['2000-01-01', ''], ['2000-01-01', '24'],
|
||||
['2000-01-01', '-1'], ['2000-01-01', '辰时xxx']
|
||||
]) assert.equal(calculateFiveElements(date, hour), null)
|
||||
assert.ok(calculateFiveElements('2024-02-29', '子时'))
|
||||
assert.throws(() => analyzePillars(['甲子', '无效', '甲子', '甲子']))
|
||||
})
|
||||
|
||||
test('节气前后切换月柱;子时换日采用历法库第二流派', () => {
|
||||
const before = calculateFiveElements('2024-02-03', '午时')
|
||||
const after = calculateFiveElements('2024-02-05', '午时')
|
||||
assert.notEqual(before.pillars[1], after.pillars[1])
|
||||
const early = calculateFiveElements('2024-06-18', '0')
|
||||
const late = calculateFiveElements('2024-06-18', '23')
|
||||
assert.equal(early.dayMaster, late.dayMaster)
|
||||
})
|
||||
@@ -0,0 +1,51 @@
|
||||
const test = require('node:test')
|
||||
const assert = require('node:assert/strict')
|
||||
const fs = require('node:fs')
|
||||
const path = require('node:path')
|
||||
const vm = require('node:vm')
|
||||
const ts = require('typescript')
|
||||
|
||||
function loadApi(env, search) {
|
||||
let requests = 0
|
||||
let uploads = 0
|
||||
const taro = { default: {
|
||||
getStorageSync: () => '',
|
||||
request: async () => { requests++; return { data: { code: 0, data: { id: 9 } } } },
|
||||
uploadFile: async () => { uploads++; return { data: JSON.stringify({ code: 0, data: { id: 9 } }) } }
|
||||
} }
|
||||
const cache = {}
|
||||
function load(name) {
|
||||
if (cache[name]) return cache[name]
|
||||
const source = fs.readFileSync(path.resolve(__dirname, `../src/services/${name}.ts`), 'utf8')
|
||||
const code = ts.transpileModule(source, { compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2017 } }).outputText
|
||||
const exports = {}
|
||||
cache[name] = exports
|
||||
vm.runInNewContext(code, {
|
||||
exports, process: { env: { TARO_ENV: env } }, window: { location: { search } }, URLSearchParams,
|
||||
require: (id) => id === '@tarojs/taro' ? taro : load('frontendPreview')
|
||||
})
|
||||
return exports
|
||||
}
|
||||
return { api: load('request').api, counts: () => ({ requests, uploads }) }
|
||||
}
|
||||
|
||||
test('显式H5预览使用示例资料,阻止后端读取、保存和上传', async () => {
|
||||
const { api, counts } = loadApi('h5', '?preview=1')
|
||||
const profile = await api.profile()
|
||||
assert.equal(profile.id, 0)
|
||||
assert.equal(profile.birthday, '1998-06-18')
|
||||
await assert.rejects(api.updateProfile({ nickname: 'Changed' }), /纯前端预览/)
|
||||
await assert.rejects(api.uploadAvatar('local.png'), /纯前端预览/)
|
||||
await assert.rejects(api.agreement('privacy'), /纯前端预览/)
|
||||
assert.deepEqual(counts(), { requests: 0, uploads: 0 })
|
||||
profile.nickname = 'Mutated'
|
||||
assert.equal((await api.profile()).nickname, 'You')
|
||||
})
|
||||
|
||||
test('普通H5和微信端不使用预览资料', async () => {
|
||||
for (const [env, search] of [['h5', ''], ['h5', '?preview=0'], ['weapp', '?preview=1']]) {
|
||||
const { api, counts } = loadApi(env, search)
|
||||
assert.equal((await api.profile()).id, 9)
|
||||
assert.deepEqual(counts(), { requests: 1, uploads: 0 })
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,110 @@
|
||||
const test = require('node:test')
|
||||
const assert = require('node:assert/strict')
|
||||
const fs = require('node:fs')
|
||||
const path = require('node:path')
|
||||
const Module = require('node:module')
|
||||
const ts = require('typescript')
|
||||
const { Solar } = require('lunar-typescript')
|
||||
const cache = {}
|
||||
function load(name) {
|
||||
if (cache[name]) return cache[name].exports
|
||||
const filename = path.resolve(__dirname, `../src/utils/${name}.ts`)
|
||||
const loaded = new Module(filename, module)
|
||||
cache[name] = loaded
|
||||
loaded.filename = filename
|
||||
loaded.paths = Module._nodeModulePaths(path.dirname(filename))
|
||||
const original = loaded.require.bind(loaded)
|
||||
loaded.require = (id) => id.startsWith('./') ? load(id.slice(2)) : original(id)
|
||||
loaded._compile(ts.transpileModule(fs.readFileSync(filename, 'utf8'), { compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2017 } }).outputText, filename)
|
||||
return loaded.exports
|
||||
}
|
||||
const { generateHomeOverview: generate, normalizeDimensionOrder, HOME_DIMENSION_IDS } = load('homeOverview')
|
||||
const profile = { birthday: '1998-06-18', birthHour: '辰时' }
|
||||
|
||||
test('昨日今日明日整体切换,公历星期农历均来自实际所选日期', () => {
|
||||
const reports = [-1, 0, 1].map((offset) => generate(profile, '2026-10-15', offset))
|
||||
assert.deepEqual(reports.map((item) => item.activeDay), ['昨日', '今日', '明日'])
|
||||
assert.deepEqual(reports.map((item) => item.date), ['2026-10-14', '2026-10-15', '2026-10-16'])
|
||||
reports.forEach((report) => {
|
||||
const [y, m, d] = report.date.split('-').map(Number)
|
||||
const solar = Solar.fromYmd(y, m, d)
|
||||
const lunar = solar.getLunar()
|
||||
assert.equal(report.weekName, `星期${'日一二三四五六'[solar.getWeek()]}`)
|
||||
assert.equal(report.lunarDate, `农历${lunar.getYearInGanZhi()}年 ${lunar.getMonthInChinese()}月${lunar.getDayInChinese()}`)
|
||||
assert.equal(report.luckyDirection, lunar.getDayPositionXiDesc())
|
||||
assert.equal(report.days.find((day) => day.label === report.activeDay).status, report.status)
|
||||
})
|
||||
assert.notDeepEqual(reports[0].dimensions, reports[1].dimensions)
|
||||
assert.notDeepEqual(reports[1].dimensions, reports[2].dimensions)
|
||||
})
|
||||
|
||||
test('八维评分有界,宜忌与评分一致,综合指数可复算', () => {
|
||||
for (let day = 1; day <= 31; day++) {
|
||||
const report = generate(profile, `2026-10-${String(day).padStart(2, '0')}`)
|
||||
assert.equal(report.dimensions.length, 8)
|
||||
assert.equal(new Set(report.dimensions.map((item) => item.id)).size, 8)
|
||||
report.dimensions.forEach((item) => {
|
||||
assert.ok(item.score >= 15 && item.score <= 90)
|
||||
assert.equal(item.suitable, item.score >= 50)
|
||||
assert.ok(item.headline && item.detail)
|
||||
})
|
||||
assert.equal(report.overallIndex, Math.round(report.dimensions.reduce((sum, item) => sum + item.score, 0) / 8))
|
||||
assert.equal(report.status, report.overallIndex >= 80 ? '大吉' : report.overallIndex >= 65 ? '小吉' : report.overallIndex >= 50 ? '平日' : report.overallIndex >= 35 ? '小逆' : '谨慎')
|
||||
assert.equal(report.luckyColors.length, 2)
|
||||
assert.equal(new Set(report.luckyNumbers).size, 2)
|
||||
}
|
||||
})
|
||||
|
||||
test('吉时仅取所选当日的吉时片段,不越过日期边界且时支不重复', () => {
|
||||
for (let day = 1; day <= 31; day++) {
|
||||
const report = generate(profile, `2026-10-${String(day).padStart(2, '0')}`)
|
||||
const times = Solar.fromYmd(2026, 10, day).getLunar().getTimes()
|
||||
assert.ok(report.luckyHours.length > 0 && report.luckyHours.length <= 2)
|
||||
assert.equal(new Set(report.luckyHours.map((hour) => hour.branch)).size, report.luckyHours.length)
|
||||
report.luckyHours.forEach(({ branch, time }) => {
|
||||
const [start, end] = time.split('–')
|
||||
const match = times.find((hour) => hour.getZhi() === branch && hour.getMinHm() === start)
|
||||
assert.ok(match)
|
||||
assert.equal(match.getTianShenLuck(), '吉')
|
||||
assert.ok(end <= '24:00')
|
||||
assert.ok(start < end)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
test('日期、生日、时辰影响报告;相同输入稳定且不读取后端报告', () => {
|
||||
const first = generate(profile, '2026-10-15')
|
||||
assert.deepEqual(first, generate({ ...profile, elementReport: { invalid: true } }, '2026-10-15'))
|
||||
assert.notDeepEqual(first, generate({ birthday: '1999-11-06', birthHour: '辰时' }, '2026-10-15'))
|
||||
let changedHour = false
|
||||
for (const hour of ['子时', '卯时', '午时', '戌时']) {
|
||||
if (JSON.stringify(generate({ ...profile, birthHour: hour }, '2026-10-15')) !== JSON.stringify(first)) changedHour = true
|
||||
}
|
||||
assert.equal(changedHour, true)
|
||||
})
|
||||
|
||||
test('跨月、跨年与非法日期安全处理,不回退为固定42分报告', () => {
|
||||
assert.equal(generate(profile, '2026-01-01', -1).date, '2025-12-31')
|
||||
assert.equal(generate(profile, '2026-12-31', 1).date, '2027-01-01')
|
||||
assert.equal(generate(profile, '2024-03-01', -1).date, '2024-02-29')
|
||||
for (const date of ['', '2026-02-30', '2026-13-01']) assert.equal(generate(profile, date), null)
|
||||
assert.equal(generate({ birthday: '', birthHour: '' }, '2026-10-15'), null)
|
||||
assert.equal(generate(profile, '2026-10-15', 2), null)
|
||||
})
|
||||
|
||||
test('排序兼容缺失、重复、旧字段和损坏存储,保留八个维度', () => {
|
||||
assert.deepEqual(normalizeDimensionOrder(null), HOME_DIMENSION_IDS)
|
||||
assert.deepEqual(normalizeDimensionOrder('bad'), HOME_DIMENSION_IDS)
|
||||
const order = normalizeDimensionOrder(['travel', 'travel', 'removed', 'wealth', null])
|
||||
assert.deepEqual(order.slice(0, 2), ['travel', 'wealth'])
|
||||
assert.equal(order.length, 8)
|
||||
assert.equal(new Set(order).size, 8)
|
||||
})
|
||||
|
||||
test('首页八个维度、头像与天宫图标资产存在', () => {
|
||||
for (const icon of ['heart', 'gourd', 'vase', 'coin', 'fan', 'scroll', 'bamboo', 'horse', 'water', 'spirit']) {
|
||||
const data = fs.readFileSync(path.resolve(__dirname, `../src/assets/home/${icon}.png`))
|
||||
assert.equal(data.subarray(1, 4).toString(), 'PNG')
|
||||
assert.equal(data.readUInt32BE(16), 256)
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,27 @@
|
||||
// Original vector sources; generate portable PNG assets with sharp.
|
||||
const sharp = require(process.argv[2] || 'sharp')
|
||||
const fs = require('node:fs')
|
||||
const path = require('node:path')
|
||||
const output = path.resolve(__dirname, '../src/assets/home')
|
||||
const art = {
|
||||
heart: `<path d="M64 107C52 99 15 76 15 48 15 21 50 13 64 37 78 13 113 21 113 48c0 28-37 51-49 59Z" fill="url(#pink)"/><path d="M30 46q0-14 17-13" fill="none" stroke="#fff" stroke-width="6" opacity=".7"/>`,
|
||||
gourd: `<path d="M64 26q-13-13 1-21" fill="none" stroke="#b6884a" stroke-width="5"/><path d="M62 17Q91 3 97 23 76 31 62 17Z" fill="#d5bc75"/><path d="M64 24c-26 0-28 28-10 37-43 16-37 60 10 60s53-44 10-60c18-9 16-37-10-37Z" fill="url(#gold)"/><path d="M49 39q-8 8 0 14m-7 30q-13 20 5 24" fill="none" stroke="#fff8da" stroke-width="6" stroke-linecap="round" opacity=".8"/><path d="M51 64q13 5 26 0" fill="none" stroke="#d19138" stroke-width="3"/>`,
|
||||
vase: `<path d="m62 38-5-26m6 16L82 9m-21 23L36 13" fill="none" stroke="#8bc2a5" stroke-width="4"/><ellipse cx="45" cy="17" rx="10" ry="5" transform="rotate(30 45 17)" fill="#b8ddbf"/><ellipse cx="77" cy="17" rx="12" ry="5" transform="rotate(-35 77 17)" fill="#c6e4c6"/><path d="M46 35h36l-5 19c-1 10 29 19 24 43-3 16-21 21-37 21s-34-5-37-21c-5-24 25-33 24-43Z" fill="url(#green)"/><ellipse cx="64" cy="36" rx="20" ry="6" fill="#c8eedc"/><path d="M49 68q-20 23-9 31" fill="none" stroke="#d2f8e7" stroke-width="5" stroke-linecap="round"/>`,
|
||||
coin: `<circle cx="64" cy="65" r="51" fill="url(#gold)" stroke="#dfb25c" stroke-width="3"/><circle cx="64" cy="65" r="43" fill="none" stroke="#fff0b1" stroke-width="4"/><circle cx="64" cy="65" r="35" fill="none" stroke="#e3b15b" stroke-width="2"/><path d="M49 50h30v30H49Z" fill="#ba9251"/><path d="M53 54h22v22H53Z" fill="#fff6d4"/><path d="M32 38q7-9 18-13" fill="none" stroke="#fff8d5" stroke-width="4" stroke-linecap="round"/>`,
|
||||
fan: `<path d="M64 107 8 61Q19 10 64 14q45-4 56 47Z" fill="url(#purple)"/><path d="m64 104-44-49m44 49L37 30m27 74V20m0 84L91 30m-27 74 44-49" stroke="#c3a3f2" stroke-width="3"/><path d="M9 61q14-17 26-4 12-19 29-3 17-16 29 3 12-13 26 4" fill="none" stroke="#f1e1ff" stroke-width="5"/><circle cx="64" cy="105" r="8" fill="#d79be8"/>`,
|
||||
scroll: `<path d="M27 25h74v76H27Z" fill="url(#gold)"/><path d="M34 25v76m12-76v76m12-76v76m12-76v76m12-76v76m12-76v76" stroke="#e0b46a" stroke-width="2"/><path d="M21 17c16 0 16 96 0 96S5 17 21 17Z" fill="#f8d38b" stroke="#d9ad5b" stroke-width="3"/><ellipse cx="21" cy="25" rx="10" ry="6" fill="#fff1bf"/><ellipse cx="21" cy="105" rx="10" ry="6" fill="#f9dda2"/><path d="M103 18v94" stroke="#d9ad5b" stroke-width="9" stroke-linecap="round"/><path d="M40 42h43m-43 12h36m-36 12h43" stroke="#f7ecc4" stroke-width="3"/>`,
|
||||
bamboo: `<g transform="rotate(-16 64 64)"><rect x="42" y="10" width="19" height="107" rx="8" fill="url(#green)"/><rect x="71" y="21" width="15" height="96" rx="7" fill="url(#green)"/><path d="M42 40h19m-19 34h19m10-25h15M71 84h15" stroke="#c2f7df" stroke-width="4"/><path d="M45 70Q10 54 15 32q28 9 30 38m35-4q14-40 34-30-11 26-34 30m0 26q28-21 35-7-17 14-35 7" fill="#76d5b6"/></g>`,
|
||||
horse: `<path d="M29 67q-22-17-20 6 9-9 20 3m60-27 3-24 10-9 10 10-8 11 5 20-18 13-5 18H36L20 69l16-18 33 1 13-15" fill="url(#blue)" stroke="#83b1e1" stroke-width="2"/><path d="m31 83-8 30h12l10-27m17 0 4 27h11l-2-29m15-3 12 19 10-3-16-26" fill="#9dc7f0"/><path d="m81 42 1-16 12-15 8 5-13 15-1 14" fill="#829ed7"/><circle cx="103" cy="28" r="2.5" fill="#6381b1"/>`,
|
||||
water: `<path d="M64 9C55 9 20 57 20 79c0 25 19 40 44 40s44-15 44-40C108 57 73 9 64 9Z" fill="url(#aqua)"/><path d="M48 37Q33 62 32 76" fill="none" stroke="#d1faff" stroke-width="7" opacity=".6" stroke-linecap="round"/><ellipse cx="53" cy="82" rx="3.5" ry="5" fill="#467bd2"/><ellipse cx="78" cy="82" rx="3.5" ry="5" fill="#467bd2"/><path d="M58 94q8 10 16 0" fill="none" stroke="#467bd2" stroke-width="4" stroke-linecap="round"/>`,
|
||||
spirit: `<circle cx="64" cy="64" r="62" fill="#fff9fd"/><path d="M23 63 19 9q25 3 37 36m16 0q12-33 37-36l-4 54" fill="#fff7fb" stroke="#f5d9e8" stroke-width="2"/><path d="m29 45-3-24q17 10 19 25m38 0q2-15 19-25l-3 24" fill="#efa6c6"/><path d="M22 58q10-21 42-21t42 21l8 19-17 26q-33 23-66 0L14 77Z" fill="url(#fox)"/><path d="m64 45-5 12 5 6 5-6Z" fill="#e394bb"/><path d="M35 77q11 12 20 0m18 0q9 12 20 0" fill="none" stroke="#b77ca7" stroke-width="3" stroke-linecap="round"/><path d="m60 88 4 4 4-4q-4-5-8 0" fill="#e596b4"/><ellipse cx="32" cy="88" rx="9" ry="5" fill="#f5b2cb" opacity=".6"/><ellipse cx="96" cy="88" rx="9" ry="5" fill="#f5b2cb" opacity=".6"/>`
|
||||
}
|
||||
const gradients = `<defs><linearGradient id="pink" x2=".4" y2="1"><stop stop-color="#ffd8e2"/><stop offset=".55" stop-color="#f78eac"/><stop offset="1" stop-color="#ffd3b2"/></linearGradient><linearGradient id="gold" x2=".8" y2="1"><stop stop-color="#fff0b3"/><stop offset=".55" stop-color="#f4c467"/><stop offset="1" stop-color="#e9ae47"/></linearGradient><linearGradient id="green" x2="1" y2="1"><stop stop-color="#c4f2dd"/><stop offset=".5" stop-color="#77ceae"/><stop offset="1" stop-color="#43ae99"/></linearGradient><linearGradient id="purple" x2=".6" y2="1"><stop stop-color="#e2d3ff"/><stop offset=".5" stop-color="#ac8ce6"/><stop offset="1" stop-color="#dcb6ee"/></linearGradient><linearGradient id="blue" x2="1" y2="1"><stop stop-color="#d1e8fa"/><stop offset="1" stop-color="#89b0e7"/></linearGradient><linearGradient id="aqua" x2=".5" y2="1"><stop stop-color="#b5f6fc"/><stop offset=".5" stop-color="#63d4ed"/><stop offset="1" stop-color="#37b9e5"/></linearGradient><linearGradient id="fox" x2=".5" y2="1"><stop stop-color="#fff"/><stop offset="1" stop-color="#f9e5f3"/></linearGradient></defs>`
|
||||
async function main() {
|
||||
fs.mkdirSync(output, { recursive: true })
|
||||
for (const [name, content] of Object.entries(art)) {
|
||||
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="256" height="256" viewBox="0 0 128 128">${gradients}${content}</svg>`
|
||||
await sharp(Buffer.from(svg)).png().toFile(path.join(output, `${name}.png`))
|
||||
}
|
||||
console.log(`Rendered ${Object.keys(art).length} home icons`)
|
||||
}
|
||||
main().catch((error) => { console.error(error); process.exitCode = 1 })
|
||||
@@ -0,0 +1,33 @@
|
||||
// Vector source for the twelve original zodiac mascots. PNG output works in both H5 and WeChat.
|
||||
// Run with a locally installed sharp, or pass its module path as the first argument.
|
||||
const path = require('node:path')
|
||||
const fs = require('node:fs')
|
||||
const sharp = require(process.argv[2] || 'sharp')
|
||||
const output = path.resolve(__dirname, '../src/assets/zodiac')
|
||||
const face = (fill, extra = '') => `<path d="M29 61C29 37 43 29 64 29s35 8 35 32v20c0 22-15 31-35 31S29 103 29 81Z" fill="${fill}"/>${extra}`
|
||||
const eyes = `<ellipse cx="49" cy="74" rx="3" ry="4" fill="#62463f" stroke="none"/><ellipse cx="79" cy="74" rx="3" ry="4" fill="#62463f" stroke="none"/>`
|
||||
const smile = `<path d="M58 88q6 7 12 0" fill="none" stroke="#62463f" stroke-width="2.8"/><ellipse cx="40" cy="85" rx="7" ry="4" fill="#ee9f9d" opacity=".45" stroke="none"/><ellipse cx="88" cy="85" rx="7" ry="4" fill="#ee9f9d" opacity=".45" stroke="none"/>`
|
||||
const art = {
|
||||
rat: `<circle cx="31" cy="38" r="18" fill="#d7d0ef"/><circle cx="97" cy="38" r="18" fill="#d7d0ef"/><circle cx="31" cy="38" r="10" fill="#f4c5d5" stroke="none"/><circle cx="97" cy="38" r="10" fill="#f4c5d5" stroke="none"/>${face('#e8e1f4')}${eyes}<ellipse cx="64" cy="85" rx="6" ry="4" fill="#d98ca6"/>${smile}<path d="m29 82-12-3m13 10-13 3m82-10 12-3m-13 10 13 3" fill="none" stroke-width="2"/>`,
|
||||
ox: `<path d="M39 39C18 39 17 22 24 15c0 12 8 10 19 10m42 14c21 0 22-17 15-24 0 12-8 10-19 10" fill="#f7ddb1"/><ellipse cx="26" cy="58" rx="13" ry="9" fill="#c49469"/><ellipse cx="102" cy="58" rx="13" ry="9" fill="#c49469"/>${face('#efd6b0')}${eyes}<rect x="39" y="82" width="50" height="24" rx="12" fill="#f5b6af"/><circle cx="53" cy="93" r="2.5" fill="#946457"/><circle cx="75" cy="93" r="2.5" fill="#946457"/>`,
|
||||
tiger: `<circle cx="34" cy="37" r="14" fill="#f4bc62"/><circle cx="94" cy="37" r="14" fill="#f4bc62"/>${face('#ffd17d')}<path d="M40 80c0-11 15-15 24-8 9-7 24-3 24 8 0 17-10 25-24 25S40 97 40 80Z" fill="#fff3d6" stroke="none"/><path d="M64 31v19m-9-13h18m-16 9h14M30 59l13 5-13 4m68-9-13 5 13 4" fill="none" stroke-width="4"/>${eyes}<path d="m59 85 5 4 5-4Z" fill="#835946" stroke="none"/>${smile}`,
|
||||
rabbit: `<path d="M38 52C25 5 47 1 51 16l6 38m14 0 6-38c4-15 26-11 13 36" fill="#fff4d8"/><path d="m40 42-3-22q4-12 8 0l4 23m30 0 4-23q4-12 8 0l-3 22" fill="#f5bac8" stroke="none"/>${face('#fff4d8')}${eyes}<path d="m60 83 4 4 4-4" fill="#e693aa" stroke="#e693aa"/>${smile}`,
|
||||
dragon: `<path d="m40 39-9-21 12 6 4-14 8 27m18 0 8-27 4 14 12-6-9 21" fill="#f4d58f"/><path d="M28 54 13 45l7 22m80-13 15-9-7 22" fill="#8ad6b4"/>${face('#a1e2c3')}<path d="m53 36 11-13 11 13" fill="#6abea5" stroke="none"/>${eyes}<rect x="38" y="82" width="52" height="24" rx="12" fill="#d2f1d4"/><circle cx="51" cy="91" r="2" fill="#648b6e"/><circle cx="77" cy="91" r="2" fill="#648b6e"/><path d="M40 94q-27 11-22-8m70 8q27 11 22-8" fill="none" stroke="#7ca986" stroke-width="2.5"/>`,
|
||||
snake: `<path d="M93 85c24 31-63 38-63 15 0-16 34-12 34-30" fill="none" stroke="#729f83" stroke-width="19"/><path d="M92 94c12 11-44 18-50 6" fill="none" stroke="#b1deab" stroke-width="10"/><path d="M35 46c0-21 58-26 58 2 0 25-12 39-29 39S35 68 35 46Z" fill="#b8e2a7"/><ellipse cx="49" cy="55" rx="3" ry="4" fill="#62463f" stroke="none"/><ellipse cx="79" cy="55" rx="3" ry="4" fill="#62463f" stroke="none"/><path d="M56 69q8 8 16 0" fill="none"/><path d="M64 75v13m0-2-5 4m5-4 5 4" fill="none" stroke="#e18f9e" stroke-width="2.5"/>`,
|
||||
horse: `<path d="M42 48C21 25 27 4 40 17l15 26m18 0 15-26c13-13 19 8-2 31" fill="#cc9c7b"/><path d="M46 35q18-31 35-5L68 54Z" fill="#795546"/>${face('#dfb18b')}<path d="M61 37h8v33h-8Z" fill="#fff1db" stroke="none"/>${eyes}<ellipse cx="64" cy="94" rx="26" ry="17" fill="#f1d4af"/><circle cx="54" cy="93" r="2" fill="#946457"/><circle cx="74" cy="93" r="2" fill="#946457"/>`,
|
||||
goat: `<path d="M39 43C9 38 14 10 32 19q17 10-2 17m59 7c30-5 25-33 7-24Q79 29 98 36" fill="#e7c6a1"/><ellipse cx="26" cy="63" rx="14" ry="8" fill="#edcfb9"/><ellipse cx="102" cy="63" rx="14" ry="8" fill="#edcfb9"/>${face('#f7e6d0')}<path d="M30 56q-12-20 8-25-1-16 18-13 8-16 21 0 20-3 18 13 20 5 6 25-9-13-18-7-10-13-20-3-12-7-20 10Z" fill="#fffdf1"/>${eyes}<path d="m60 87 4 4 4-4m-7 19 3 10 3-10" fill="none"/>${smile}`,
|
||||
monkey: `<circle cx="25" cy="68" r="16" fill="#ba8d6d"/><circle cx="103" cy="68" r="16" fill="#ba8d6d"/><circle cx="25" cy="68" r="8" fill="#f4d5b0" stroke="none"/><circle cx="103" cy="68" r="8" fill="#f4d5b0" stroke="none"/>${face('#bd9373')}<path d="M34 70c0-23 23-29 30-14 7-15 30-9 30 14v15c0 18-16 24-30 24S34 103 34 85Z" fill="#ffe6ba" stroke="none"/><path d="M56 30q-2-15 14-14-8 5-4 14" fill="#bd9373"/>${eyes}<ellipse cx="64" cy="85" rx="4" ry="3" fill="#c38c78" stroke="none"/>${smile}`,
|
||||
rooster: `<path d="M49 43c-24-19-4-33 4-17 0-25 25-25 22 1 15-16 30 2 8 17" fill="#ed8690"/><path d="M54 101q-2 23 10 15 12 8 10-15" fill="#ed8690"/>${face('#fff1ce')}${eyes}<path d="m64 81-11 8 11 12 11-12Z" fill="#f7bc63"/>`,
|
||||
dog: `<path d="M42 34C11 27 11 57 15 81q11 12 23-10m48-37c31-7 31 23 27 47-11 12-23-10" fill="#a87d64"/>${face('#eed1a9')}<ellipse cx="81" cy="68" rx="14" ry="18" fill="#bd987d" stroke="none"/>${eyes}<ellipse cx="64" cy="88" rx="21" ry="15" fill="#fff0d4" stroke="none"/><path d="m58 84 6 6 6-6q-6-5-12 0" fill="#795b51" stroke="none"/>${smile}`,
|
||||
pig: `<path d="M35 51Q17 22 33 20l23 18m16 0 23-18q16 2-2 31" fill="#f5bbc5"/>${face('#ffd3dc')}${eyes}<rect x="41" y="80" width="46" height="28" rx="14" fill="#eea2b4"/><ellipse cx="55" cy="94" rx="3" ry="5" fill="#b56f86" stroke="none"/><ellipse cx="73" cy="94" rx="3" ry="5" fill="#b56f86" stroke="none"/>`
|
||||
}
|
||||
|
||||
async function main() {
|
||||
fs.mkdirSync(output, { recursive: true })
|
||||
for (const [name, content] of Object.entries(art)) {
|
||||
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="256" height="256" viewBox="0 0 128 128"><g stroke="#78594f" stroke-width="3.2" stroke-linecap="round" stroke-linejoin="round">${content}</g></svg>`
|
||||
await sharp(Buffer.from(svg)).png().toFile(path.join(output, `${name}.png`))
|
||||
}
|
||||
console.log(`Rendered ${Object.keys(art).length} zodiac icons`)
|
||||
}
|
||||
main().catch((error) => { console.error(error); process.exitCode = 1 })
|
||||
@@ -0,0 +1,64 @@
|
||||
const test = require('node:test')
|
||||
const assert = require('node:assert/strict')
|
||||
const fs = require('node:fs')
|
||||
const path = require('node:path')
|
||||
const Module = require('node:module')
|
||||
const crypto = require('node:crypto')
|
||||
const ts = require('typescript')
|
||||
const filename = path.resolve(__dirname, '../src/utils/zodiac.ts')
|
||||
const loaded = new Module(filename, module)
|
||||
loaded.filename = filename
|
||||
loaded.paths = Module._nodeModulePaths(path.dirname(filename))
|
||||
loaded._compile(ts.transpileModule(fs.readFileSync(filename, 'utf8'), {
|
||||
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2017 }
|
||||
}).outputText, filename)
|
||||
const { calculateZodiac, zodiacNames } = loaded.exports
|
||||
|
||||
test('春节前一天与正月初一换生肖,不按1月1日或立春换年', () => {
|
||||
for (const [before, after, previous, next] of [
|
||||
['2023-01-21', '2023-01-22', '虎', '兔'],
|
||||
['2024-02-09', '2024-02-10', '兔', '龙'],
|
||||
['2025-01-28', '2025-01-29', '龙', '蛇'],
|
||||
['2026-02-16', '2026-02-17', '蛇', '马']
|
||||
]) {
|
||||
assert.equal(calculateZodiac(before), previous)
|
||||
assert.equal(calculateZodiac(after), next)
|
||||
}
|
||||
assert.equal(calculateZodiac('2024-01-01'), '兔')
|
||||
assert.equal(calculateZodiac('2024-02-05'), '兔') // 立春后,春节前仍属兔。
|
||||
})
|
||||
|
||||
test('十二生肖全部覆盖,年份跨越周期仍正确', () => {
|
||||
zodiacNames.forEach((name, index) => {
|
||||
assert.equal(calculateZodiac(`${2008 + index}-06-15`), name)
|
||||
assert.equal(calculateZodiac(`${2020 + index}-06-15`), name)
|
||||
})
|
||||
})
|
||||
|
||||
test('无效或缺失生日不默认显示某种生肖,闰年有效日期可计算', () => {
|
||||
for (const birthday of ['', '2025-02-29', '2024-02-30', '2024-00-10', '2024-13-01', '2024-01-00', '2024-1-1', '1899-12-31', '2101-01-01']) {
|
||||
assert.equal(calculateZodiac(birthday), null)
|
||||
}
|
||||
assert.equal(calculateZodiac('2024-02-29'), '龙')
|
||||
})
|
||||
|
||||
test('修改生日跨春节后返回不同生肖,重复计算稳定', () => {
|
||||
const first = calculateZodiac('1999-02-15')
|
||||
const changed = calculateZodiac('1999-02-16')
|
||||
assert.equal(first, '虎')
|
||||
assert.equal(changed, '兔')
|
||||
assert.equal(calculateZodiac('1999-02-15'), first)
|
||||
})
|
||||
|
||||
test('十二个图标均为独立的256像素透明PNG,非重复占位图', () => {
|
||||
const files = ['rat', 'ox', 'tiger', 'rabbit', 'dragon', 'snake', 'horse', 'goat', 'monkey', 'rooster', 'dog', 'pig']
|
||||
const hashes = files.map((name) => {
|
||||
const data = fs.readFileSync(path.resolve(__dirname, `../src/assets/zodiac/${name}.png`))
|
||||
assert.equal(data.subarray(1, 4).toString(), 'PNG')
|
||||
assert.equal(data.readUInt32BE(16), 256)
|
||||
assert.equal(data.readUInt32BE(20), 256)
|
||||
assert.equal(data[25], 6) // RGBA,保留透明背景。
|
||||
return crypto.createHash('sha256').update(data).digest('hex')
|
||||
})
|
||||
assert.equal(new Set(hashes).size, 12)
|
||||
})
|
||||
@@ -0,0 +1,98 @@
|
||||
const test = require('node:test')
|
||||
const assert = require('node:assert/strict')
|
||||
const fs = require('node:fs')
|
||||
const path = require('node:path')
|
||||
const Module = require('node:module')
|
||||
const ts = require('typescript')
|
||||
const { Solar } = require('lunar-typescript')
|
||||
const cache = {}
|
||||
function load(name) {
|
||||
if (cache[name]) return cache[name].exports
|
||||
const filename = path.resolve(__dirname, `../src/utils/${name}.ts`)
|
||||
const loaded = new Module(filename, module)
|
||||
cache[name] = loaded
|
||||
loaded.filename = filename
|
||||
loaded.paths = Module._nodeModulePaths(path.dirname(filename))
|
||||
const originalRequire = loaded.require.bind(loaded)
|
||||
loaded.require = (id) => id === './zodiac' ? load('zodiac') : originalRequire(id)
|
||||
loaded._compile(ts.transpileModule(fs.readFileSync(filename, 'utf8'), {
|
||||
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2017 }
|
||||
}).outputText, filename)
|
||||
return loaded.exports
|
||||
}
|
||||
const { getBeijingDate, getZodiacRelation, calculateWeeklyZodiacFortune: weekly } = load('zodiacWeekly')
|
||||
|
||||
test('合冲表对称,12生肖均覆盖1六合、2三合、1六冲、1相害', () => {
|
||||
const branches = [...'子丑寅卯辰巳午未申酉戌亥']
|
||||
for (const first of branches) {
|
||||
const counts = {}
|
||||
for (const second of branches) {
|
||||
const relation = getZodiacRelation(first, second)
|
||||
assert.equal(relation, getZodiacRelation(second, first))
|
||||
counts[relation] = (counts[relation] || 0) + 1
|
||||
}
|
||||
assert.deepEqual(counts, { 平常: 7, 六合: 1, 三合: 2, 六冲: 1, 相害: 1 })
|
||||
assert.equal(getZodiacRelation(first, first), '平常')
|
||||
}
|
||||
assert.equal(getZodiacRelation('子', '丑'), '六合')
|
||||
assert.equal(getZodiacRelation('寅', '午'), '三合')
|
||||
assert.equal(getZodiacRelation('子', '午'), '六冲')
|
||||
assert.equal(getZodiacRelation('子', '未'), '相害')
|
||||
assert.throws(() => getZodiacRelation('鼠', '子'))
|
||||
})
|
||||
|
||||
test('北京时间零点边界、周一到周日及跨年周正确', () => {
|
||||
assert.equal(getBeijingDate(new Date('2026-10-18T15:59:59Z')), '2026-10-18')
|
||||
assert.equal(getBeijingDate(new Date('2026-10-18T16:00:00Z')), '2026-10-19')
|
||||
assert.equal(getBeijingDate(new Date('invalid')), '')
|
||||
const monday = weekly('1998-06-18', '2026-10-12')
|
||||
const sunday = weekly('1998-06-18', '2026-10-18')
|
||||
assert.deepEqual(monday, sunday)
|
||||
assert.equal(monday.weekStart, '2026-10-12')
|
||||
assert.equal(monday.weekEnd, '2026-10-18')
|
||||
assert.equal(weekly('1998-06-18', '2026-10-19').weekStart, '2026-10-19')
|
||||
const newYear = weekly('1998-06-18', '2027-01-01')
|
||||
assert.equal(newYear.weekStart, '2026-12-28')
|
||||
assert.equal(newYear.weekEnd, '2027-01-03')
|
||||
})
|
||||
|
||||
test('逐日分值与周状态可复算,日期不遗漏、不重复,状态有差异', () => {
|
||||
const statuses = new Set()
|
||||
const date = '2026-10-15'
|
||||
for (let year = 2008; year < 2020; year++) {
|
||||
const report = weekly(`${year}-06-15`, date)
|
||||
assert.equal(report.days.length, 7)
|
||||
assert.equal(new Set(report.days.map((day) => day.date)).size, 7)
|
||||
const weights = { 六合: 2, 三合: 1, 六冲: -2, 相害: -1, 平常: 0 }
|
||||
report.days.forEach((day) => {
|
||||
const [y, m, d] = day.date.split('-').map(Number)
|
||||
assert.equal(day.branch, Solar.fromYmd(y, m, d).getLunar().getDayZhi())
|
||||
assert.equal(day.relation, getZodiacRelation(report.branch, day.branch))
|
||||
assert.equal(day.score, weights[day.relation])
|
||||
})
|
||||
assert.equal(report.score, report.days.reduce((sum, day) => sum + day.score, 0))
|
||||
assert.equal(report.status, report.score >= 2 ? '顺势' : report.score <= -2 ? '谨慎' : '平稳')
|
||||
assert.ok(report.supportiveDays.every((day) => day.score > 0))
|
||||
assert.ok(report.cautiousDays.every((day) => day.score < 0))
|
||||
statuses.add(report.status)
|
||||
}
|
||||
assert.deepEqual([...statuses].sort(), ['平稳', '谨慎', '顺势'].sort())
|
||||
})
|
||||
|
||||
test('生日、周次驱动结果,同生肖同周稳定,跨周明细改变', () => {
|
||||
const first = weekly('1998-06-18', '2026-10-15')
|
||||
assert.deepEqual(first, weekly('1998-06-18', '2026-10-15'))
|
||||
assert.deepEqual(first, weekly('2010-06-18', '2026-10-15'))
|
||||
assert.notDeepEqual(first.days, weekly('1999-06-18', '2026-10-15').days)
|
||||
assert.notDeepEqual(first.days, weekly('1998-06-18', '2026-10-22').days)
|
||||
assert.equal(weekly('2024-02-09', '2026-10-15').zodiac, '兔')
|
||||
assert.equal(weekly('2024-02-10', '2026-10-15').zodiac, '龙')
|
||||
})
|
||||
|
||||
test('非法生日与非法参考日期不给出虚构周运', () => {
|
||||
assert.equal(weekly('', '2026-10-15'), null)
|
||||
assert.equal(weekly('2025-02-29', '2026-10-15'), null)
|
||||
for (const date of ['', 'invalid', '2026-02-30', '2026-13-01', '2026-00-01', '2026-10-00']) {
|
||||
assert.equal(weekly('1998-06-18', date), null)
|
||||
}
|
||||
})
|
||||
@@ -15,7 +15,7 @@ export default defineAppConfig({
|
||||
navigationStyle: 'custom',
|
||||
backgroundColor: '#fffdf7'
|
||||
},
|
||||
tabBar: {
|
||||
tabBar: process.env.TARO_ENV === 'h5' ? undefined : {
|
||||
custom: true,
|
||||
color: '#cfcfcf',
|
||||
selectedColor: '#9a6d0f',
|
||||
|
||||
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 8.8 KiB |
|
After Width: | Height: | Size: 6.8 KiB |
|
After Width: | Height: | Size: 8.5 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 9.2 KiB |
|
After Width: | Height: | Size: 9.0 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 9.6 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 9.9 KiB |
|
After Width: | Height: | Size: 8.7 KiB |
|
After Width: | Height: | Size: 8.9 KiB |
|
After Width: | Height: | Size: 9.1 KiB |
|
After Width: | Height: | Size: 8.8 KiB |
|
After Width: | Height: | Size: 8.6 KiB |
|
After Width: | Height: | Size: 9.2 KiB |
@@ -0,0 +1,40 @@
|
||||
.app-tabbar {
|
||||
position: fixed;
|
||||
z-index: 12;
|
||||
left: 50%;
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
max-width: 750px;
|
||||
height: calc(158px + env(safe-area-inset-bottom));
|
||||
padding-bottom: env(safe-area-inset-bottom);
|
||||
border: 2px solid rgba(255,255,255,.8);
|
||||
border-bottom: 0;
|
||||
border-radius: 30px 30px 0 0;
|
||||
box-sizing: border-box;
|
||||
background: rgba(255,255,255,.97);
|
||||
box-shadow: 0 -10px 32px rgba(96,77,125,.08);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-around;
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
.app-tabbar .app-tabbar-item, .app-tabbar .app-tabbar-realm {
|
||||
width: 150px; height: 132px; margin: 0; padding: 0; flex: none;
|
||||
display: flex; flex-direction: column; align-items: center; justify-content: center;
|
||||
gap: 12px; color: #30283e; background: transparent; border: 0;
|
||||
font-size: 27px; font-weight: 700; line-height: 1.2;
|
||||
overflow: visible;
|
||||
}
|
||||
.app-tabbar-label { display: block; flex: none; line-height: 34px; white-space: nowrap; }
|
||||
.app-tabbar .app-tabbar-item.active { color: #fb9b2d; }
|
||||
.app-home-symbol { width: 48px; height: 48px; position: relative; flex: none; }
|
||||
.app-home-roof { position: absolute; left: 8px; top: 2px; width: 30px; height: 30px; border: 7px solid currentColor; border-right: 0; border-bottom: 0; border-radius: 5px; box-sizing: border-box; transform: rotate(45deg); }
|
||||
.app-home-body { position: absolute; left: 8px; bottom: 1px; width: 32px; height: 27px; border-radius: 3px 3px 7px 7px; background: currentColor; }
|
||||
.app-home-body > view { position: absolute; left: 12px; bottom: 0; width: 9px; height: 14px; border-radius: 5px 5px 0 0; background: #fff; }
|
||||
.app-person-symbol { width: 52px; height: 48px; position: relative; flex: none; }
|
||||
.app-person-head { position: absolute; left: 50%; top: 1px; width: 19px; height: 19px; border-radius: 50%; background: currentColor; transform: translateX(-50%); }
|
||||
.app-person-body { position: absolute; left: 4px; bottom: 0; width: 44px; height: 24px; border-radius: 23px 23px 7px 7px; background: currentColor; }
|
||||
// 共用48px图标占位,放大图标只向上延伸,不挤压或裁切下方文字。
|
||||
.app-realm-symbol { position: relative; width: 116px; height: 48px; flex: none; }
|
||||
.app-spirit-frame { position: absolute; left: 0; bottom: 0; width: 116px; height: 116px; padding: 9px; border: 2px solid #fff; box-sizing: border-box; border-radius: 50%; background: linear-gradient(145deg,#fff,#edf3ff); box-shadow: 0 7px 20px rgba(137,110,160,.12); }
|
||||
.app-spirit-image { display: block; width: 100%; height: 100%; border-radius: 50%; }
|
||||
@@ -0,0 +1,27 @@
|
||||
import Taro from '@tarojs/taro'
|
||||
import { Button, Image, Text, View } from '@tarojs/components'
|
||||
import spirit from '../assets/home/spirit.png'
|
||||
import './AppTabBar.scss'
|
||||
|
||||
export function AppTabBar({ active }: { active: 'home' | 'my' }) {
|
||||
const navigate = (page: 'home' | 'my') => {
|
||||
if (page === active) return
|
||||
const url = `/pages/${page}/index`
|
||||
if (process.env.TARO_ENV === 'weapp') Taro.switchTab({ url })
|
||||
else Taro.redirectTo({ url })
|
||||
}
|
||||
return <View className='app-tabbar'>
|
||||
<Button className={`app-tabbar-item ${active === 'home' ? 'active' : ''}`} onClick={() => navigate('home')}>
|
||||
<View className='app-home-symbol'><View className='app-home-roof' /><View className='app-home-body'><View /></View></View>
|
||||
<Text className='app-tabbar-label'>首页</Text>
|
||||
</Button>
|
||||
<Button className='app-tabbar-realm' onClick={() => Taro.navigateTo({ url: '/pages/fortune/index' })}>
|
||||
<View className='app-realm-symbol'><View className='app-spirit-frame'><Image className='app-spirit-image' src={spirit} mode='aspectFit' /></View></View>
|
||||
<Text className='app-tabbar-label'>天宫</Text>
|
||||
</Button>
|
||||
<Button className={`app-tabbar-item ${active === 'my' ? 'active' : ''}`} onClick={() => navigate('my')}>
|
||||
<View className='app-person-symbol'><View className='app-person-head' /><View className='app-person-body' /></View>
|
||||
<Text className='app-tabbar-label'>我的</Text>
|
||||
</Button>
|
||||
</View>
|
||||
}
|
||||
@@ -1,81 +1,31 @@
|
||||
.radar {
|
||||
position: relative;
|
||||
width: 520px;
|
||||
height: 470px;
|
||||
margin: 22px auto 42px;
|
||||
}
|
||||
|
||||
.radar-web,
|
||||
.radar-fill {
|
||||
.radar { position: relative; width: 100%; height: 490px; margin: 0 auto; }
|
||||
.radar-plot { position: absolute; width: 66%; height: 360px; left: 17%; top: 75px; }
|
||||
.radar-ring, .radar-ring-inner, .radar-fill {
|
||||
position: absolute;
|
||||
left: 110px;
|
||||
top: 58px;
|
||||
width: 300px;
|
||||
height: 300px;
|
||||
clip-path: polygon(50% 0, 98% 36%, 80% 98%, 20% 98%, 2% 36%);
|
||||
}
|
||||
|
||||
.radar-web {
|
||||
border: 2px solid rgba(255, 219, 117, 0.5);
|
||||
background: rgba(255, 237, 184, 0.18);
|
||||
}
|
||||
|
||||
.web-1 {
|
||||
transform: scale(1);
|
||||
}
|
||||
|
||||
.web-2 {
|
||||
transform: scale(0.68);
|
||||
}
|
||||
|
||||
.web-3 {
|
||||
transform: scale(0.36);
|
||||
}
|
||||
|
||||
.radar-fill {
|
||||
background: #13cce9;
|
||||
opacity: 0.95;
|
||||
}
|
||||
|
||||
.radar-label {
|
||||
position: absolute;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.radar-name {
|
||||
font-size: 34px;
|
||||
}
|
||||
|
||||
.radar-value {
|
||||
margin-top: 8px;
|
||||
font-size: 22px;
|
||||
}
|
||||
|
||||
.radar-label-0 {
|
||||
left: 50%;
|
||||
top: 0;
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
|
||||
.radar-label-1 {
|
||||
right: 0;
|
||||
top: 150px;
|
||||
}
|
||||
|
||||
.radar-label-2 {
|
||||
right: 50px;
|
||||
bottom: 12px;
|
||||
}
|
||||
|
||||
.radar-label-3 {
|
||||
left: 48px;
|
||||
bottom: 12px;
|
||||
}
|
||||
|
||||
.radar-label-4 {
|
||||
left: 0;
|
||||
top: 150px;
|
||||
inset: 0;
|
||||
clip-path: polygon(50% 4%, 93.75% 35.79%, 77.04% 87.21%, 22.96% 87.21%, 6.25% 35.79%);
|
||||
}
|
||||
.radar-ring { background: #decac6; }
|
||||
.radar-ring-inner { inset: 2px; background: #fff2e9; }
|
||||
.radar-ring:nth-child(even) .radar-ring-inner { background: #fff9f1; }
|
||||
.radar-axis { position: absolute; left: 50%; top: 50%; width: 46%; border-top: 2px dashed rgba(171,151,151,.35); transform-origin: left center; }
|
||||
.radar-fill { background: rgba(255,143,201,.72); }
|
||||
.radar-dot { position: absolute; width: 9px; height: 9px; border: 2px solid rgba(255,255,255,.5); border-radius: 50%; transform: translate(-50%,-50%); }
|
||||
.radar-label { position: absolute; display: flex; flex-direction: column; align-items: center; gap: 6px; font-weight: 700; }
|
||||
.radar-name-row { display: flex; align-items: center; gap: 6px; }
|
||||
.radar-name { font-size: 32px; line-height: 40px; }
|
||||
.radar-value { min-width: 64px; height: 28px; padding: 0 8px; box-sizing: border-box; border-radius: 20px; color: #fff; font-size: 21px; font-weight: 500; line-height: 28px; text-align: center; }
|
||||
.radar-label-0 { left: 50%; top: 0; transform: translateX(-50%); }
|
||||
.radar-label-1 { right: 2%; top: 177px; }
|
||||
.radar-label-2 { right: 20%; bottom: 0; }
|
||||
.radar-label-3 { left: 20%; bottom: 0; }
|
||||
.radar-label-4 { left: 2%; top: 177px; }
|
||||
.element-mark { position: relative; width: 28px; height: 30px; border-radius: 11px 13px 10px 12px; background: currentColor; box-shadow: inset 5px 5px 8px rgba(255,255,255,.35); }
|
||||
.mark-1 { border-radius: 8px 8px 16px 16px; height: 23px; }
|
||||
.mark-2 { border-radius: 70% 35% 65% 40%; transform: rotate(25deg); }
|
||||
.mark-3 { border-radius: 90% 12% 75% 30%; }
|
||||
.mark-4 { border-radius: 70% 15% 60% 45%; transform: rotate(-12deg); }
|
||||
.mark-eye { position: absolute; top: 12px; width: 3px; height: 4px; border-radius: 50%; background: rgba(49,44,65,.65); }
|
||||
.mark-eye.left { left: 8px; }
|
||||
.mark-eye.right { right: 8px; }
|
||||
.mark-smile { position: absolute; left: 11px; top: 17px; width: 6px; height: 3px; border-bottom: 2px solid rgba(49,44,65,.55); border-radius: 50%; }
|
||||
@@ -2,45 +2,52 @@ import { View, Text } from '@tarojs/components'
|
||||
import { ElementScore } from '../services/request'
|
||||
import './RadarChart.scss'
|
||||
|
||||
type Props = {
|
||||
scores: ElementScore[]
|
||||
}
|
||||
|
||||
const positions = [
|
||||
{ left: 50, top: 3 },
|
||||
{ left: 86, top: 35 },
|
||||
{ left: 72, top: 84 },
|
||||
{ left: 28, top: 84 },
|
||||
{ left: 14, top: 35 }
|
||||
]
|
||||
|
||||
const elementMarks: Record<string, string> = {
|
||||
土: '●', 金: '✦', 水: '●', 木: '●', 火: '●'
|
||||
}
|
||||
type Props = { scores: ElementScore[] }
|
||||
const order = ['土', '金', '水', '木', '火']
|
||||
const colors = ['#b87338', '#dca823', '#42b7e4', '#55b56a', '#ef6777']
|
||||
const points = order.map((_, index) => {
|
||||
const angle = (-90 + index * 72) * Math.PI / 180
|
||||
return { x: 50 + Math.cos(angle) * 46, y: 50 + Math.sin(angle) * 46 }
|
||||
})
|
||||
|
||||
export function RadarChart({ scores }: Props) {
|
||||
const polygon = scores.map((score, index) => {
|
||||
const point = positions[index]
|
||||
const scale = Math.max(score.value, 4) / 100
|
||||
const x = 50 + (point.left - 50) * scale
|
||||
const y = 50 + (point.top - 50) * scale
|
||||
return `${x}% ${y}%`
|
||||
}).join(', ')
|
||||
const values = order.map((name, index) => ({
|
||||
name,
|
||||
value: Math.max(0, Math.min(100, scores.find((score) => score.name === name)?.value || 0)),
|
||||
color: colors[index]
|
||||
}))
|
||||
const maximum = Math.max(50, ...values.map((score) => score.value))
|
||||
const dataPoints = values.map((score, index) => ({
|
||||
x: 50 + (points[index].x - 50) * score.value / maximum,
|
||||
y: 50 + (points[index].y - 50) * score.value / maximum
|
||||
}))
|
||||
const polygon = dataPoints.map(({ x, y }) => `${x}% ${y}%`).join(', ')
|
||||
|
||||
return (
|
||||
<View className='radar'>
|
||||
<View className='radar-web web-1' />
|
||||
<View className='radar-web web-2' />
|
||||
<View className='radar-web web-3' />
|
||||
<View className='radar-fill' style={{ clipPath: `polygon(${polygon})` }} />
|
||||
{scores.map((score, index) => (
|
||||
<View
|
||||
key={score.name}
|
||||
className={`radar-label radar-label-${index}`}
|
||||
style={{ color: score.color }}
|
||||
>
|
||||
<Text className='radar-name'>{elementMarks[score.name]} {score.name}</Text>
|
||||
<Text className='radar-value'>{score.value}%</Text>
|
||||
<View className='radar-plot'>
|
||||
{[1, 0.8, 0.6, 0.4, 0.2].map((scale) => (
|
||||
<View key={scale} className='radar-ring' style={{ transform: `scale(${scale})` }}>
|
||||
<View className='radar-ring-inner' />
|
||||
</View>
|
||||
))}
|
||||
{points.map((_, index) => (
|
||||
<View key={index} className='radar-axis' style={{ transform: `rotate(${-90 + index * 72}deg)` }} />
|
||||
))}
|
||||
<View className='radar-fill' style={{ clipPath: `polygon(${polygon})` }} />
|
||||
{dataPoints.map((point, index) => (
|
||||
<View key={order[index]} className='radar-dot' style={{ left: `${point.x}%`, top: `${point.y}%`, backgroundColor: colors[index] }} />
|
||||
))}
|
||||
</View>
|
||||
{values.map((score, index) => (
|
||||
<View key={score.name} className={`radar-label radar-label-${index}`} style={{ color: score.color }}>
|
||||
<View className='radar-name-row'>
|
||||
<View className={`element-mark mark-${index}`}>
|
||||
<View className='mark-eye left' /><View className='mark-eye right' /><View className='mark-smile' />
|
||||
</View>
|
||||
<Text className='radar-name'>{score.name}</Text>
|
||||
</View>
|
||||
<Text className='radar-value' style={{ backgroundColor: score.color }}>{score.value}%</Text>
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
.zodiac-mascot { display: block; width: 86px; height: 86px; flex: none; }
|
||||
.zodiac-mascot-empty { color: #8d7d9c; font-size: 22px; line-height: 1.4; }
|
||||
.zodiac-large .zodiac-mascot { width: 148px; height: 148px; }
|
||||
@@ -0,0 +1,26 @@
|
||||
import { Image, Text } from '@tarojs/components'
|
||||
import type { ZodiacName } from '../utils/zodiac'
|
||||
import rat from '../assets/zodiac/rat.png'
|
||||
import ox from '../assets/zodiac/ox.png'
|
||||
import tiger from '../assets/zodiac/tiger.png'
|
||||
import rabbit from '../assets/zodiac/rabbit.png'
|
||||
import dragon from '../assets/zodiac/dragon.png'
|
||||
import snake from '../assets/zodiac/snake.png'
|
||||
import horse from '../assets/zodiac/horse.png'
|
||||
import goat from '../assets/zodiac/goat.png'
|
||||
import monkey from '../assets/zodiac/monkey.png'
|
||||
import rooster from '../assets/zodiac/rooster.png'
|
||||
import dog from '../assets/zodiac/dog.png'
|
||||
import pig from '../assets/zodiac/pig.png'
|
||||
import './ZodiacMascot.scss'
|
||||
|
||||
const icons: Record<ZodiacName, string> = {
|
||||
鼠: rat, 牛: ox, 虎: tiger, 兔: rabbit, 龙: dragon, 蛇: snake,
|
||||
马: horse, 羊: goat, 猴: monkey, 鸡: rooster, 狗: dog, 猪: pig
|
||||
}
|
||||
|
||||
export function ZodiacMascot({ zodiac }: { zodiac: ZodiacName | null }) {
|
||||
return zodiac
|
||||
? <Image className='zodiac-mascot' src={icons[zodiac]} mode='aspectFit' ariaLabel={`${zodiac}生肖图标`} />
|
||||
: <Text className='zodiac-mascot-empty'>待完善</Text>
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover" />
|
||||
<meta name="theme-color" content="#a184fa" />
|
||||
<title>Hera 前端预览</title>
|
||||
<script><%= htmlWebpackPlugin.options.script %></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,51 +1,154 @@
|
||||
.agreement-page {
|
||||
color: #222;
|
||||
padding-left: 30px;
|
||||
padding-right: 30px;
|
||||
width: 100%;
|
||||
max-width: 750px;
|
||||
min-height: 100vh;
|
||||
margin: 0 auto;
|
||||
padding: calc(132px + env(safe-area-inset-top)) 32px calc(36px + env(safe-area-inset-bottom));
|
||||
box-sizing: border-box;
|
||||
color: #28243a;
|
||||
background:
|
||||
radial-gradient(circle at 16% 5%, rgba(180, 155, 255, 0.62), transparent 31%),
|
||||
linear-gradient(180deg, #c8b7ff 0%, #e8e2ff 34%, #f0f5ff 70%, #edf5ff 100%);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.tabs {
|
||||
margin-top: 210px;
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
.agreement-page .nav {
|
||||
left: 50%;
|
||||
right: auto;
|
||||
width: 100%;
|
||||
max-width: 750px;
|
||||
height: calc(106px + env(safe-area-inset-top));
|
||||
padding-bottom: 20px;
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
|
||||
.tab {
|
||||
.agreement-page .nav-title {
|
||||
color: #27213f;
|
||||
font-size: 38px;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.agreement-page .back {
|
||||
color: #30294b;
|
||||
}
|
||||
|
||||
.agreement-tabs {
|
||||
position: relative;
|
||||
color: #8f640d;
|
||||
font-size: 34px;
|
||||
font-weight: 700;
|
||||
padding-bottom: 18px;
|
||||
z-index: 1;
|
||||
width: 100%;
|
||||
height: 84px;
|
||||
padding: 6px;
|
||||
border: 2px solid rgba(255, 255, 255, 0.68);
|
||||
border-radius: 46px;
|
||||
background: rgba(255, 255, 255, 0.48);
|
||||
box-shadow: 0 10px 28px rgba(95, 76, 139, 0.08);
|
||||
display: flex;
|
||||
box-sizing: border-box;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.current::after {
|
||||
content: '';
|
||||
.tab-indicator {
|
||||
position: absolute;
|
||||
left: 32px;
|
||||
right: 32px;
|
||||
bottom: 0;
|
||||
height: 8px;
|
||||
border-radius: 4px;
|
||||
background: #8f640d;
|
||||
left: 6px;
|
||||
top: 6px;
|
||||
width: calc(50% - 6px);
|
||||
height: 68px;
|
||||
border-radius: 38px;
|
||||
background: linear-gradient(135deg, #7862dc 0%, #9279ed 100%);
|
||||
box-shadow: 0 8px 18px rgba(102, 78, 193, 0.24);
|
||||
transition: transform 220ms cubic-bezier(0.22, 0.72, 0.22, 1);
|
||||
}
|
||||
|
||||
.article {
|
||||
height: calc(100vh - 350px);
|
||||
margin-top: 42px;
|
||||
.agreement-tabs.privacy-active .tab-indicator {
|
||||
transform: translateX(100%);
|
||||
}
|
||||
|
||||
.agreement-tab {
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
width: 50%;
|
||||
height: 68px;
|
||||
flex: none;
|
||||
color: #59516f;
|
||||
font-size: 30px;
|
||||
font-weight: 700;
|
||||
line-height: 68px;
|
||||
text-align: center;
|
||||
transition: color 180ms ease;
|
||||
}
|
||||
|
||||
.agreement-tab + .agreement-tab {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.agreement-tab.current {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.agreement-article {
|
||||
height: calc(100vh - 252px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
|
||||
margin-top: 28px;
|
||||
border: 2px solid rgba(255, 255, 255, 0.72);
|
||||
border-radius: 28px;
|
||||
background: rgba(255, 255, 255, 0.82);
|
||||
box-shadow: 0 16px 38px rgba(85, 72, 119, 0.08);
|
||||
box-sizing: border-box;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.article-inner {
|
||||
min-height: 100%;
|
||||
padding: 38px 34px 56px;
|
||||
box-sizing: border-box;
|
||||
animation: article-enter 230ms cubic-bezier(0.22, 0.72, 0.22, 1);
|
||||
}
|
||||
|
||||
.article-title {
|
||||
display: block;
|
||||
color: #252525;
|
||||
margin-bottom: 30px;
|
||||
color: #28213f;
|
||||
font-size: 40px;
|
||||
font-weight: 800;
|
||||
margin-bottom: 26px;
|
||||
line-height: 1.35;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.paragraph {
|
||||
display: block;
|
||||
color: #2f2f2f;
|
||||
font-size: 30px;
|
||||
line-height: 1.95;
|
||||
margin-bottom: 28px;
|
||||
margin-bottom: 26px;
|
||||
color: #4c465c;
|
||||
font-size: 28px;
|
||||
line-height: 1.9;
|
||||
text-align: justify;
|
||||
}
|
||||
|
||||
.paragraph:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
@keyframes article-enter {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(10px);
|
||||
}
|
||||
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (max-height: 700px) {
|
||||
.agreement-page {
|
||||
padding-top: calc(112px + env(safe-area-inset-top));
|
||||
}
|
||||
|
||||
.agreement-article {
|
||||
height: calc(100vh - 222px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
|
||||
margin-top: 22px;
|
||||
}
|
||||
|
||||
.article-inner {
|
||||
padding-top: 30px;
|
||||
}
|
||||
}
|
||||
@@ -4,30 +4,46 @@ import { NavBar } from '../../components/NavBar'
|
||||
import { api } from '../../services/request'
|
||||
import './index.scss'
|
||||
|
||||
type AgreementType = 'user' | 'privacy'
|
||||
|
||||
const sampleUser = '为使用小程序软件服务(以下简称“本服务”),您应当阅读并遵守《小程序软件注册协议》以及专项规则等。请您务必审慎阅读、充分理解各条款内容,特别是免除或限制责任的相应条款。'
|
||||
const samplePrivacy = '欢迎使用那吉。本隐私政策旨在向您说明我们收集、使用、存储、披露个人信息的方式、范围及您享有的相关权利,确保您在充分知情的前提下自愿使用本应用。'
|
||||
|
||||
export default function AgreementPage() {
|
||||
const [active, setActive] = useState<'user' | 'privacy'>('user')
|
||||
const [body, setBody] = useState(sampleUser)
|
||||
const [active, setActive] = useState<AgreementType>('user')
|
||||
const [content, setContent] = useState<Record<AgreementType, string>>({
|
||||
user: sampleUser,
|
||||
privacy: samplePrivacy
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
api.agreement(active).then((res) => setBody(res.body)).catch(() => setBody(active === 'user' ? sampleUser : samplePrivacy))
|
||||
let cancelled = false
|
||||
api.agreement(active)
|
||||
.then((res) => {
|
||||
if (!cancelled) setContent((current) => ({ ...current, [active]: res.body }))
|
||||
})
|
||||
.catch(() => undefined)
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}, [active])
|
||||
|
||||
return (
|
||||
<View className='page agreement-page'>
|
||||
<View className='agreement-page'>
|
||||
<NavBar back title='协议' />
|
||||
<View className='tabs'>
|
||||
<Button className={active === 'user' ? 'tab current' : 'tab'} onClick={() => setActive('user')}>用户协议</Button>
|
||||
<Button className={active === 'privacy' ? 'tab current' : 'tab'} onClick={() => setActive('privacy')}>隐私政策</Button>
|
||||
<View className={`agreement-tabs ${active === 'privacy' ? 'privacy-active' : ''}`}>
|
||||
<View className='tab-indicator' />
|
||||
<Button className={active === 'user' ? 'agreement-tab current' : 'agreement-tab'} hoverClass='none' onClick={() => setActive('user')}>用户协议</Button>
|
||||
<Button className={active === 'privacy' ? 'agreement-tab current' : 'agreement-tab'} hoverClass='none' onClick={() => setActive('privacy')}>隐私政策</Button>
|
||||
</View>
|
||||
<ScrollView className='article' scrollY>
|
||||
<Text className='article-title'>{active === 'user' ? '用户协议' : '一、引言'}</Text>
|
||||
<Text className='paragraph'>{body}</Text>
|
||||
<Text className='paragraph'>一、协议的范围{'\n'}1.1 本协议是您与那吉之间关于使用那吉软件服务所订立的协议。所有规则均为本协议不可分割的一部分,与协议正文具有同等法律效力。</Text>
|
||||
<Text className='paragraph'>二、适用范围{'\n'}本政策适用于您通过本应用进行的所有操作及我们因此收集的个人信息,涵盖注册、登录、使用功能、参与互动等场景。</Text>
|
||||
<Text className='paragraph'>三、个人信息的收集与使用{'\n'}我们遵循合法、正当、必要原则,仅收集为实现服务功能所必需的信息。</Text>
|
||||
<ScrollView key={active} className='agreement-article' scrollY enhanced showScrollbar={false}>
|
||||
<View className='article-inner'>
|
||||
<Text className='article-title'>{active === 'user' ? '用户协议' : '隐私政策'}</Text>
|
||||
<Text className='paragraph'>{content[active]}</Text>
|
||||
<Text className='paragraph'>一、协议的范围{'\n'}1.1 本协议是您与那吉之间关于使用那吉软件服务所订立的协议。所有规则均为本协议不可分割的一部分,与协议正文具有同等法律效力。</Text>
|
||||
<Text className='paragraph'>二、适用范围{'\n'}本政策适用于您通过本应用进行的所有操作及我们因此收集的个人信息,涵盖注册、登录、使用功能、参与互动等场景。</Text>
|
||||
<Text className='paragraph'>三、个人信息的收集与使用{'\n'}我们遵循合法、正当、必要原则,仅收集为实现服务功能所必需的信息。</Text>
|
||||
</View>
|
||||
</ScrollView>
|
||||
</View>
|
||||
)
|
||||
|
||||
@@ -1,602 +1,99 @@
|
||||
.home-page {
|
||||
min-height: 100vh;
|
||||
padding: calc(216px + env(safe-area-inset-top)) 30px calc(178px + env(safe-area-inset-bottom));
|
||||
box-sizing: border-box;
|
||||
color: #29243a;
|
||||
background:
|
||||
linear-gradient(180deg, rgba(154, 124, 255, 0.92) 0%, rgba(220, 201, 255, 0.76) 27%, rgba(253, 241, 255, 0.9) 52%, #eef6ff 100%);
|
||||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
.day-switch {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 52px;
|
||||
}
|
||||
|
||||
.avatar-orb {
|
||||
width: 132px;
|
||||
height: 132px;
|
||||
flex: none;
|
||||
border-radius: 70px;
|
||||
background: #fffef0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
box-shadow: 0 12px 26px rgba(119, 102, 154, 0.12);
|
||||
}
|
||||
|
||||
.water-face {
|
||||
width: 82px;
|
||||
height: 96px;
|
||||
border-radius: 50% 50% 52% 52%;
|
||||
background: linear-gradient(180deg, #9ff5ff 0%, #39c6ea 100%);
|
||||
color: #3274c8;
|
||||
font-size: 42px;
|
||||
line-height: 78px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.day-tabs {
|
||||
flex: 1;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.day-tab {
|
||||
min-width: 0;
|
||||
text-align: center;
|
||||
color: rgba(42, 34, 62, 0.58);
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.day-tab + .day-tab::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
left: -2px;
|
||||
top: 20px;
|
||||
width: 2px;
|
||||
height: 12px;
|
||||
background: rgba(42, 34, 62, 0.4);
|
||||
}
|
||||
|
||||
.day-label,
|
||||
.day-status {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.day-label {
|
||||
font-size: 36px;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.day-status {
|
||||
width: 112px;
|
||||
height: 48px;
|
||||
margin: 12px auto 0;
|
||||
border-radius: 26px;
|
||||
font-size: 28px;
|
||||
line-height: 48px;
|
||||
}
|
||||
|
||||
.day-tab.active {
|
||||
color: #29243a;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.day-tab.active .day-label {
|
||||
font-size: 46px;
|
||||
}
|
||||
|
||||
.day-tab.active .day-status {
|
||||
background: #7956f4;
|
||||
color: #fff;
|
||||
box-shadow: 0 8px 18px rgba(105, 71, 220, 0.26);
|
||||
}
|
||||
|
||||
.date-row {
|
||||
margin-top: 52px;
|
||||
color: #4f485f;
|
||||
font-size: 28px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.month-day {
|
||||
font-size: 34px;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.summary-card {
|
||||
min-height: 202px;
|
||||
margin-top: 38px;
|
||||
border-radius: 18px;
|
||||
background: linear-gradient(105deg, #7139f3 0%, #8344ff 54%, #d35af3 100%);
|
||||
color: #fff;
|
||||
padding: 42px 34px;
|
||||
box-sizing: border-box;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.summary-card::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
right: -22px;
|
||||
top: -36px;
|
||||
width: 236px;
|
||||
height: 236px;
|
||||
border-radius: 50%;
|
||||
background: radial-gradient(circle, rgba(131, 226, 255, 0.95) 0%, rgba(61, 121, 250, 0.72) 50%, rgba(255, 255, 255, 0) 70%);
|
||||
filter: blur(1px);
|
||||
}
|
||||
|
||||
.summary-copy {
|
||||
width: 420px;
|
||||
font-size: 34px;
|
||||
line-height: 1.75;
|
||||
font-weight: 800;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.index-orb {
|
||||
width: 178px;
|
||||
height: 178px;
|
||||
border-radius: 96px;
|
||||
background: radial-gradient(circle at 45% 36%, #e8ffff 0%, #86dfff 42%, #5a71ff 100%);
|
||||
color: #fff;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
box-shadow: 0 0 0 12px rgba(255, 255, 255, 0.22);
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.index-number {
|
||||
font-size: 72px;
|
||||
line-height: 0.95;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.index-orb text:last-child {
|
||||
margin-top: 10px;
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.lucky-grid-home {
|
||||
margin-top: 24px;
|
||||
display: grid;
|
||||
grid-template-columns: 1.35fr 0.75fr;
|
||||
gap: 22px;
|
||||
}
|
||||
|
||||
.lucky-box {
|
||||
min-height: 90px;
|
||||
border-radius: 18px;
|
||||
padding: 0 28px;
|
||||
background: rgba(255, 255, 255, 0.52);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
box-sizing: border-box;
|
||||
gap: 18px;
|
||||
}
|
||||
|
||||
.colors-box {
|
||||
background: rgba(246, 233, 255, 0.72);
|
||||
}
|
||||
|
||||
.number-box {
|
||||
background: rgba(234, 225, 255, 0.72);
|
||||
}
|
||||
|
||||
.direction-box {
|
||||
background: rgba(255, 241, 198, 0.82);
|
||||
}
|
||||
|
||||
.hour-box {
|
||||
background: rgba(196, 235, 255, 0.82);
|
||||
}
|
||||
|
||||
.lucky-label {
|
||||
flex: none;
|
||||
color: #29243a;
|
||||
font-size: 30px;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.color-chip,
|
||||
.hour-chip {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
color: #423a52;
|
||||
font-size: 28px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.swatch {
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
.number-slots {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.number-slots text {
|
||||
width: 48px;
|
||||
height: 58px;
|
||||
border-radius: 10px;
|
||||
background: linear-gradient(180deg, #8f75ff, #7454ef);
|
||||
color: #fff;
|
||||
font-size: 48px;
|
||||
line-height: 58px;
|
||||
text-align: center;
|
||||
font-weight: 900;
|
||||
box-shadow: inset 0 -12px 0 rgba(255, 255, 255, 0.18);
|
||||
}
|
||||
|
||||
.compass-icon {
|
||||
width: 42px;
|
||||
height: 42px;
|
||||
border-radius: 50%;
|
||||
background: #fff;
|
||||
color: #ff9f27;
|
||||
font-size: 30px;
|
||||
line-height: 42px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.hour-chip text:first-child {
|
||||
width: 42px;
|
||||
height: 42px;
|
||||
border-radius: 22px;
|
||||
background: #5bb8df;
|
||||
color: #fff;
|
||||
text-align: center;
|
||||
line-height: 42px;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.dimension-head {
|
||||
margin-top: 46px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.dimension-head > text {
|
||||
color: #29243a;
|
||||
font-size: 42px;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.dimension-head button {
|
||||
color: #6d6578;
|
||||
font-size: 28px;
|
||||
}
|
||||
|
||||
.dimension-list {
|
||||
margin-top: 28px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 22px;
|
||||
}
|
||||
|
||||
.dimension-card {
|
||||
min-height: 204px;
|
||||
border-radius: 18px;
|
||||
background: rgba(255, 255, 255, 0.84);
|
||||
padding: 26px 60px 28px 34px;
|
||||
box-sizing: border-box;
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
position: relative;
|
||||
box-shadow: 0 8px 22px rgba(90, 79, 116, 0.06);
|
||||
}
|
||||
|
||||
.dimension-card.suitable {
|
||||
background: rgba(255, 255, 255, 0.86);
|
||||
}
|
||||
|
||||
.dimension-card.avoid {
|
||||
background: linear-gradient(180deg, rgba(255, 249, 236, 0.9) 0%, rgba(255, 255, 255, 0.86) 48%);
|
||||
}
|
||||
|
||||
.dimension-icon {
|
||||
width: 62px;
|
||||
height: 62px;
|
||||
flex: none;
|
||||
margin-right: 20px;
|
||||
border-radius: 18px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.icon-heart {
|
||||
background: radial-gradient(circle at 32% 32%, #ffd2df, #ff79a3 68%, #fff 70%);
|
||||
transform: rotate(-10deg);
|
||||
}
|
||||
|
||||
.icon-gourd {
|
||||
background: radial-gradient(circle at 50% 28%, #ffc65c 0 28%, transparent 29%), radial-gradient(circle at 50% 65%, #f0a222 0 48%, transparent 49%);
|
||||
}
|
||||
|
||||
.icon-vase {
|
||||
background: radial-gradient(circle at 50% 18%, #d5fff0 0 24%, transparent 25%), linear-gradient(180deg, #7df0c9, #2ccda0);
|
||||
border-radius: 30px 30px 16px 16px;
|
||||
}
|
||||
|
||||
.icon-coin {
|
||||
border-radius: 50%;
|
||||
background: radial-gradient(circle, #fff8bb 0 33%, #f1b82d 34% 100%);
|
||||
}
|
||||
|
||||
.icon-fan {
|
||||
border-radius: 50% 50% 12px 12px;
|
||||
background: conic-gradient(from 235deg, #c29cff, #fff, #8e63ef, #c29cff);
|
||||
}
|
||||
|
||||
.icon-scroll {
|
||||
border-radius: 12px;
|
||||
background: repeating-linear-gradient(90deg, #ffe8aa 0 10px, #f5c868 11px 16px);
|
||||
}
|
||||
|
||||
.icon-bamboo {
|
||||
background: linear-gradient(135deg, transparent 20%, #30d3b9 21% 38%, transparent 39% 50%, #25bfa8 51% 68%, transparent 69%);
|
||||
}
|
||||
|
||||
.icon-horse {
|
||||
border-radius: 50% 28px 50% 30px;
|
||||
background: linear-gradient(135deg, #dbe9ff, #6b94f8);
|
||||
}
|
||||
|
||||
.dimension-copy {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.dimension-title-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.dimension-title {
|
||||
color: #29243a;
|
||||
font-size: 34px;
|
||||
font-weight: 900;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.dimension-headline {
|
||||
min-width: 0;
|
||||
color: #5d5667;
|
||||
font-size: 28px;
|
||||
line-height: 1.3;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.dimension-detail {
|
||||
display: block;
|
||||
margin-top: 30px;
|
||||
color: #666071;
|
||||
font-size: 28px;
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.dimension-tag {
|
||||
position: absolute;
|
||||
right: 34px;
|
||||
top: 30px;
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border-radius: 50%;
|
||||
color: #fff;
|
||||
font-size: 28px;
|
||||
line-height: 48px;
|
||||
text-align: center;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.dimension-tag.suitable {
|
||||
background: #4bc660;
|
||||
}
|
||||
|
||||
.dimension-tag.avoid {
|
||||
background: #f45b72;
|
||||
}
|
||||
|
||||
.dimension-arrow {
|
||||
position: absolute;
|
||||
right: 34px;
|
||||
bottom: 30px;
|
||||
color: #3f394a;
|
||||
font-size: 52px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.home-tabbar {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
z-index: 12;
|
||||
height: calc(158px + env(safe-area-inset-bottom));
|
||||
padding-bottom: env(safe-area-inset-bottom);
|
||||
border-radius: 26px 26px 0 0;
|
||||
background: rgba(255, 255, 255, 0.96);
|
||||
box-shadow: 0 -10px 32px rgba(85, 79, 110, 0.1);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-around;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.home-tabbar-item,
|
||||
.home-realm-tab {
|
||||
width: 150px;
|
||||
height: 132px;
|
||||
color: #29243a;
|
||||
font-size: 28px;
|
||||
font-weight: 900;
|
||||
line-height: 1.1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.home-tabbar-item.active {
|
||||
color: #ff9b2a;
|
||||
}
|
||||
|
||||
.home-tab-icon {
|
||||
width: 42px;
|
||||
height: 36px;
|
||||
border-radius: 0 0 18px 18px;
|
||||
background: currentColor;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.home-tab-icon::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
left: 5px;
|
||||
top: -22px;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border-radius: 18px 18px 10px 10px;
|
||||
background: currentColor;
|
||||
}
|
||||
|
||||
.home-mine-icon {
|
||||
width: 48px;
|
||||
height: 32px;
|
||||
border-radius: 24px 24px 14px 14px;
|
||||
background: currentColor;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.home-mine-icon::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
left: 13px;
|
||||
top: -26px;
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
border-radius: 50%;
|
||||
background: currentColor;
|
||||
}
|
||||
|
||||
.home-realm-tab {
|
||||
margin-top: -78px;
|
||||
}
|
||||
|
||||
.home-realm-avatar {
|
||||
width: 112px;
|
||||
height: 112px;
|
||||
border-radius: 60px;
|
||||
border: 12px solid #f0f7ff;
|
||||
box-shadow: 0 10px 24px rgba(121, 129, 164, 0.16);
|
||||
}
|
||||
|
||||
.sort-page {
|
||||
padding-top: calc(188px + env(safe-area-inset-top));
|
||||
}
|
||||
|
||||
.sort-back {
|
||||
position: fixed;
|
||||
left: 30px;
|
||||
top: calc(48px + env(safe-area-inset-top));
|
||||
z-index: 3;
|
||||
width: 58px;
|
||||
height: 58px;
|
||||
color: #2d2549;
|
||||
font-size: 72px;
|
||||
line-height: 44px;
|
||||
}
|
||||
|
||||
.sort-title {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
right: 0;
|
||||
top: calc(116px + env(safe-area-inset-top));
|
||||
z-index: 2;
|
||||
color: #29243a;
|
||||
font-size: 42px;
|
||||
line-height: 1;
|
||||
font-weight: 900;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.sort-hint-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
color: #6e6678;
|
||||
font-size: 28px;
|
||||
}
|
||||
|
||||
.sort-handle-symbol {
|
||||
margin: 0 16px;
|
||||
color: #6e6678;
|
||||
font-size: 42px;
|
||||
}
|
||||
|
||||
.sort-done {
|
||||
margin-left: auto;
|
||||
color: #29243a;
|
||||
font-size: 30px;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.sort-list {
|
||||
margin-top: 62px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.sort-item {
|
||||
height: 112px;
|
||||
border-radius: 18px;
|
||||
background: rgba(255, 255, 255, 0.7);
|
||||
padding: 0 34px 0 38px;
|
||||
box-sizing: border-box;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
color: #29243a;
|
||||
font-size: 32px;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.sort-controls {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
color: #77717f;
|
||||
font-size: 38px;
|
||||
}
|
||||
|
||||
.sort-controls button {
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
border-radius: 22px;
|
||||
background: rgba(121, 86, 244, 0.1);
|
||||
color: #6d57da;
|
||||
font-size: 28px;
|
||||
line-height: 44px;
|
||||
}
|
||||
position: relative; width: 100%; max-width: 750px; min-height: 100vh; margin: 0 auto;
|
||||
padding: calc(182px + env(safe-area-inset-top)) 30px calc(210px + env(safe-area-inset-bottom));
|
||||
box-sizing: border-box; color: #2c263a; overflow-x: hidden;
|
||||
background: linear-gradient(180deg,#9d81fb 0,#c6acfb 300px,#eddaff 660px,#f7edff 1120px,#f6f2ff 100%);
|
||||
}
|
||||
.home-preview-note { position: absolute; top: calc(110px + env(safe-area-inset-top)); left: 0; right: 0; color: rgba(60,41,104,.65); font-size: 22px; line-height: 1.5; text-align: center; }
|
||||
.home-day-switch { display: flex; align-items: center; gap: 38px; padding: 0 16px; }
|
||||
.home-avatar-orb { flex: none; width: 108px; height: 108px; border: 3px solid rgba(255,255,255,.75); border-radius: 50%; box-sizing: border-box; background: #fffef0; display: flex; align-items: center; justify-content: center; box-shadow: 0 10px 20px rgba(115,78,168,.1); overflow: hidden; }
|
||||
.home-water-image { width: 86px; height: 86px; }
|
||||
.home-avatar-image { width: 100%; height: 100%; border-radius: 50%; }
|
||||
.home-day-tabs { display: flex; flex: 1; min-width: 0; align-items: center; }
|
||||
.home-page .home-day-tab { flex: 1; min-width: 0; height: 108px; margin: 0; padding: 0; position: relative; display: flex; flex-direction: column; align-items: center; color: #6f568f; background: transparent; border: 0; font-weight: 500; }
|
||||
.home-page .home-day-tab + .home-day-tab { margin-top: 0; }
|
||||
.home-day-tab + .home-day-tab::before { content: ''; position: absolute; left: 0; top: 23px; width: 2px; height: 9px; border-radius: 2px; background: rgba(79,52,112,.3); }
|
||||
.home-day-label { display: block; height: 58px; font-size: 35px; line-height: 58px; white-space: nowrap; }
|
||||
.home-day-status { min-width: 96px; height: 40px; padding: 0 8px; box-sizing: border-box; margin-top: 6px; border-radius: 24px; font-size: 25px; line-height: 40px; color: #a17bb8; white-space: nowrap; }
|
||||
.home-day-tab.active .home-day-label { color: #2e2340; font-size: 43px; font-weight: 800; }
|
||||
.home-day-tab.active .home-day-status { color: #fff; background: linear-gradient(135deg,#9864fa,#8150ee); box-shadow: 0 5px 12px rgba(124,71,216,.13); font-weight: 700; }
|
||||
.home-date-row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 8px 20px; margin: 38px 10px 28px; color: #5e486f; font-size: 25px; line-height: 1.5; }
|
||||
.home-solar-date { display: flex; align-items: baseline; white-space: nowrap; }
|
||||
.home-date-number { font-size: 38px; font-weight: 800; line-height: 1.1; }
|
||||
.home-lunar-date { font-size: 24px; }
|
||||
.home-summary-card { position: relative; min-height: 200px; padding: 28px; border-radius: 24px; display: flex; align-items: center; justify-content: space-between; gap: 18px; box-sizing: border-box; color: #fff; background: linear-gradient(115deg,#7841f6 0,#8749fc 50%,#c773ef 100%); box-shadow: 0 12px 24px rgba(139,81,211,.1); overflow: hidden; }
|
||||
.home-summary-card::after { content: ''; position: absolute; right: -40px; top: -90px; width: 330px; height: 330px; border: 2px solid rgba(255,255,255,.15); border-radius: 50%; }
|
||||
.home-summary-copy { position: relative; z-index: 1; flex: 1; min-width: 0; font-size: 28px; font-weight: 600; line-height: 1.8; letter-spacing: 1px; }
|
||||
.home-index-halo { position: relative; z-index: 1; width: 174px; height: 174px; padding: 9px; border: 2px solid rgba(240,208,255,.4); border-radius: 50%; box-sizing: border-box; background: rgba(230,195,255,.16); box-shadow: 0 0 16px rgba(255,218,251,.3); flex: none; }
|
||||
.home-index-orb { width: 100%; height: 100%; border-radius: 50%; display: flex; flex-direction: column; align-items: center; justify-content: center; background: radial-gradient(circle at 36% 25%,#b8f3ff 0,#77b7ec 28%,#547be3 61%,#96b6fc 87%,#d9d7ff 100%); box-shadow: inset 0 3px 9px rgba(255,255,255,.8),inset 0 -8px 16px rgba(64,81,187,.2); }
|
||||
.home-index-number { font-size: 76px; font-weight: 800; line-height: 1; letter-spacing: -3px; }
|
||||
.home-index-label { margin-top: 8px; font-size: 22px; line-height: 1.3; }
|
||||
.home-summary-stars { position: absolute; inset: 0; pointer-events: none; }
|
||||
.home-summary-stars > view { position: absolute; width: 6px; height: 6px; border-radius: 50%; background: rgba(255,240,255,.7); }
|
||||
.home-summary-stars > view:nth-child(1) { top: 25px; left: 42px; }
|
||||
.home-summary-stars > view:nth-child(2) { top: 35px; right: 15px; width: 4px; height: 4px; }
|
||||
.home-summary-stars > view:nth-child(3) { bottom: 27px; right: 29px; width: 3px; height: 3px; }
|
||||
.home-lucky-row { display: flex; gap: 20px; margin-top: 20px; }
|
||||
.home-lucky-box { min-width: 0; min-height: 90px; padding: 18px 20px; box-sizing: border-box; border: 1px solid rgba(255,255,255,.3); border-radius: 22px; display: flex; align-items: center; gap: 16px; }
|
||||
.home-colors-box { flex: 1.8; background: rgba(231,211,250,.68); }
|
||||
.home-numbers-box { flex: 1; background: rgba(220,208,252,.72); }
|
||||
.home-direction-box { flex: 1; background: linear-gradient(110deg,#ffe6bd,#fff0df); }
|
||||
.home-hours-box { flex: 1.8; background: linear-gradient(110deg,#c2e7fa,#dfedff); }
|
||||
.home-lucky-label { flex: none; font-size: 27px; font-weight: 800; white-space: nowrap; }
|
||||
.home-color-list { display: flex; gap: 16px; min-width: 0; flex: 1; flex-wrap: wrap; }
|
||||
.home-color-chip { display: flex; align-items: center; gap: 8px; white-space: nowrap; font-size: 25px; }
|
||||
.home-swatch { width: 42px; height: 42px; flex: none; border-radius: 12px; border: 1px solid rgba(120,100,150,.06); box-sizing: border-box; }
|
||||
.home-number-slots { display: flex; gap: 10px; }
|
||||
.home-number-slot { position: relative; width: 43px; height: 52px; border-radius: 8px; color: #fff; background: linear-gradient(180deg,#9279ee 49%,#a18af1 50%); text-align: center; }
|
||||
.home-number-slot > text { position: relative; z-index: 1; font-size: 43px; font-weight: 700; line-height: 52px; }
|
||||
.home-number-slot::after { content: ''; position: absolute; top: 50%; left: 0; right: 0; height: 1px; background: rgba(92,65,152,.26); }
|
||||
.home-compass { flex: none; width: 42px; height: 42px; border: 5px solid #f8d787; border-radius: 50%; background: #fff9eb; box-sizing: border-box; position: relative; }
|
||||
.home-compass-needle { position: absolute; inset: 0; }
|
||||
.home-compass-needle::before { content: ''; position: absolute; left: 10px; top: 3px; border-left: 5px solid transparent; border-right: 5px solid transparent; border-bottom: 14px solid #ee9b82; }
|
||||
.home-compass-needle::after { content: ''; position: absolute; left: 10px; bottom: 3px; border-left: 5px solid transparent; border-right: 5px solid transparent; border-top: 14px solid #7eafdd; }
|
||||
.home-direction-value { font-size: 25px; white-space: nowrap; }
|
||||
.home-hours-list { display: flex; gap: 12px; flex-wrap: wrap; min-width: 0; }
|
||||
.home-hour-chip { display: flex; align-items: center; gap: 5px; color: #39495c; font-size: 23px; white-space: nowrap; }
|
||||
.home-hour-branch { width: 34px; height: 34px; border-radius: 50%; color: #fff; background: #72b8df; line-height: 34px; text-align: center; font-weight: 700; }
|
||||
.home-no-hour { font-size: 22px; color: #7385a1; }
|
||||
.home-dimension-head { display: flex; align-items: center; justify-content: space-between; margin-top: 42px; }
|
||||
.home-dimension-head > text { flex: none; white-space: nowrap; font-size: 37px; font-weight: 800; letter-spacing: -1px; }
|
||||
.home-dimension-head > button { width: auto; flex: none; margin: 0; display: flex; align-items: center; gap: 9px; color: #85738f; font-size: 25px; padding: 14px 0 14px 20px; }
|
||||
.home-sort-symbol { width: 21px; height: 23px; position: relative; }
|
||||
.home-sort-symbol > view { position: absolute; top: 3px; width: 3px; height: 16px; border-radius: 2px; background: currentColor; }
|
||||
.home-sort-symbol > view:first-child { left: 5px; }
|
||||
.home-sort-symbol > view:last-child { right: 5px; }
|
||||
.home-sort-symbol > view:first-child::after { content: ''; position: absolute; top: 0; left: -3px; width: 6px; height: 6px; border-left: 2px solid currentColor; border-top: 2px solid currentColor; transform: rotate(45deg); }
|
||||
.home-sort-symbol > view:last-child::after { content: ''; position: absolute; bottom: 0; left: -3px; width: 6px; height: 6px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); }
|
||||
.home-dimension-list { display: flex; flex-direction: column; gap: 18px; margin-top: 26px; }
|
||||
.home-dimension-card { min-height: 206px; padding: 20px 26px 28px; border: 2px solid rgba(255,255,255,.9); border-radius: 26px; box-sizing: border-box; background: linear-gradient(180deg,#fff8ec,#fff 65%); box-shadow: 0 7px 18px rgba(115,83,149,.025); }
|
||||
.home-dimension-card.dimension-emotion { background: linear-gradient(180deg,#fff0f7,#fff 65%); }
|
||||
.home-dimension-card.dimension-life { background: linear-gradient(180deg,#f3fff0,#fff 65%); }
|
||||
.home-dimension-card.dimension-social { background: linear-gradient(180deg,#f6efff,#fff 65%); }
|
||||
.home-dimension-card.dimension-career { background: linear-gradient(180deg,#effff9,#fff 65%); }
|
||||
.home-dimension-card.dimension-travel { background: linear-gradient(180deg,#f0f7ff,#fff 65%); }
|
||||
.home-dimension-title-row { display: flex; align-items: center; gap: 11px; min-width: 0; }
|
||||
.home-dimension-icon { display: block; width: 56px; height: 56px; flex: none; }
|
||||
.home-dimension-title { font-size: 33px; font-weight: 800; white-space: nowrap; }
|
||||
.home-dimension-headline { min-width: 0; flex: 1; margin-left: 4px; font-size: 26px; line-height: 1.45; color: #665b6c; }
|
||||
.home-dimension-tag { flex: none; width: 43px; height: 43px; border-radius: 50%; color: #fff; font-size: 25px; font-weight: 700; line-height: 43px; text-align: center; }
|
||||
.home-dimension-tag.suitable { background: #6ac87d; }
|
||||
.home-dimension-tag.avoid { background: #f17d8f; }
|
||||
.home-dimension-detail { display: block; margin: 24px 1px 0; color: #77707d; font-size: 27px; line-height: 1.85; }
|
||||
.home-entertainment-note { display: block; margin: 28px 12px 0; color: #b0a1bd; font-size: 21px; line-height: 1.7; text-align: center; }
|
||||
.home-empty { display: flex; flex-direction: column; align-items: center; gap: 28px; padding: 90px 20px; color: #7d6593; font-size: 28px; line-height: 1.8; text-align: center; }
|
||||
.home-empty-image { width: 120px; height: 120px; }
|
||||
.home-empty button { padding: 22px 40px; border-radius: 40px; color: #fff; background: #9977e9; font-size: 28px; }
|
||||
.home-sort-page { padding-top: calc(130px + env(safe-area-inset-top)); }
|
||||
.home-sort-nav { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
|
||||
.home-sort-nav > text { flex: 1; text-align: center; white-space: nowrap; font-size: 36px; font-weight: 800; }
|
||||
.home-sort-nav > button { width: auto; flex: none; min-width: 70px; margin: 0; font-size: 29px; color: #6e4e9c; line-height: 60px; }
|
||||
.home-sort-nav > button:first-child { font-size: 64px; text-align: left; }
|
||||
.home-sort-hint { display: block; margin: 24px 0; color: #8e7c9e; font-size: 25px; line-height: 1.8; }
|
||||
.home-sort-list { display: flex; flex-direction: column; gap: 12px; }
|
||||
.home-sort-item { min-height: 96px; display: flex; align-items: center; gap: 20px; padding: 18px 24px; border-radius: 22px; box-sizing: border-box; background: rgba(255,255,255,.75); font-size: 28px; color: #5c466d; }
|
||||
.home-sort-icon { width: 48px; height: 48px; }
|
||||
.home-sort-controls { display: flex; gap: 16px; margin-left: auto; }
|
||||
.home-sort-controls > button { width: 46px; height: 46px; border-radius: 50%; font-size: 27px; color: #9174cc; background: rgba(175,144,223,.12); line-height: 46px; }
|
||||
.home-sort-controls > button[disabled] { opacity: .3; }
|
||||
@media screen and (max-height: 700px) { .home-page { padding-top: calc(148px + env(safe-area-inset-top)); } .home-preview-note { top: calc(98px + env(safe-area-inset-top)); } .home-sort-page { padding-top: calc(110px + env(safe-area-inset-top)); } }
|
||||
@@ -1,306 +1,147 @@
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import Taro from '@tarojs/taro'
|
||||
import { useEffect, useMemo, useRef, useState } from 'react'
|
||||
import Taro, { useDidShow } from '@tarojs/taro'
|
||||
import { Button, Image, Text, View } from '@tarojs/components'
|
||||
import avatarAsset from '../../assets/fortune/avatar.jpg'
|
||||
import { api, DimensionItem, HomeOverview } from '../../services/request'
|
||||
import { AppTabBar } from '../../components/AppTabBar'
|
||||
import { api, resolveAssetUrl, UserProfile } from '../../services/request'
|
||||
import { isFrontendPreview } from '../../services/frontendPreview'
|
||||
import { generateHomeOverview, HOME_DIMENSION_IDS, normalizeDimensionOrder } from '../../utils/homeOverview'
|
||||
import { getBeijingDate } from '../../utils/zodiacWeekly'
|
||||
import water from '../../assets/home/water.png'
|
||||
import heart from '../../assets/home/heart.png'
|
||||
import gourd from '../../assets/home/gourd.png'
|
||||
import vase from '../../assets/home/vase.png'
|
||||
import coin from '../../assets/home/coin.png'
|
||||
import fan from '../../assets/home/fan.png'
|
||||
import scroll from '../../assets/home/scroll.png'
|
||||
import bamboo from '../../assets/home/bamboo.png'
|
||||
import horse from '../../assets/home/horse.png'
|
||||
import './index.scss'
|
||||
|
||||
type PageMode = 'home' | 'sort'
|
||||
|
||||
const weekNames = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
|
||||
|
||||
const pad = (value: number) => `${value}`.padStart(2, '0')
|
||||
|
||||
const formatDate = (date: Date) => `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`
|
||||
|
||||
const createDate = (offset: number) => {
|
||||
const date = new Date()
|
||||
date.setDate(date.getDate() + offset)
|
||||
return date
|
||||
}
|
||||
|
||||
const createMockHome = (): HomeOverview => {
|
||||
const yesterday = createDate(-1)
|
||||
const today = createDate(0)
|
||||
const tomorrow = createDate(1)
|
||||
|
||||
return {
|
||||
activeDay: '今日',
|
||||
days: [
|
||||
{
|
||||
label: '昨日',
|
||||
date: formatDate(yesterday),
|
||||
weekName: weekNames[yesterday.getDay()],
|
||||
lunarDate: '农历丙午年 九月初二',
|
||||
status: '小逆'
|
||||
},
|
||||
{
|
||||
label: '今日',
|
||||
date: formatDate(today),
|
||||
weekName: weekNames[today.getDay()],
|
||||
lunarDate: '农历丙午年 九月初三',
|
||||
status: '小逆'
|
||||
},
|
||||
{
|
||||
label: '明日',
|
||||
date: formatDate(tomorrow),
|
||||
weekName: weekNames[tomorrow.getDay()],
|
||||
lunarDate: '农历丙午年 九月初四',
|
||||
status: '平日'
|
||||
}
|
||||
],
|
||||
summary: '小逆之日,少言多思,养精蓄锐为上。',
|
||||
overallIndex: 42,
|
||||
luckyColors: [
|
||||
{ name: '绿茶色', value: '#a7ad2a' },
|
||||
{ name: '瀑布蓝', value: '#50c3cf' }
|
||||
],
|
||||
luckyNumbers: ['6', '8'],
|
||||
luckyDirection: '东北',
|
||||
luckyHours: [
|
||||
{ branch: '子', time: '23-01点' },
|
||||
{ branch: '申', time: '15-17点' }
|
||||
],
|
||||
dimensions: [
|
||||
{
|
||||
id: 'emotion',
|
||||
title: '情感',
|
||||
icon: 'heart',
|
||||
headline: '默契收集,心流时刻',
|
||||
detail: '适合捕捉和TA的默契瞬间,让这些小细节成为关系里的锚点。',
|
||||
suitable: true
|
||||
},
|
||||
{
|
||||
id: 'health',
|
||||
title: '健康',
|
||||
icon: 'gourd',
|
||||
headline: '润肺养身,舒缓秋燥',
|
||||
detail: '秋日干燥适合润肺养身,舒缓身体的秋燥不适感。',
|
||||
suitable: true
|
||||
},
|
||||
{
|
||||
id: 'life',
|
||||
title: '生活',
|
||||
icon: 'vase',
|
||||
headline: '收纳旧物,沉淀回忆',
|
||||
detail: '秋日里适合收纳旧物,在整理中沉淀那些温暖的小回忆。',
|
||||
suitable: true
|
||||
},
|
||||
{
|
||||
id: 'wealth',
|
||||
title: '财富',
|
||||
icon: 'coin',
|
||||
headline: '勿乱囤货,按需消费',
|
||||
detail: '财富能量忌盲目囤积,适合避开非必要的批量采购,保持理性消费。',
|
||||
suitable: false
|
||||
},
|
||||
{
|
||||
id: 'social',
|
||||
title: '社交',
|
||||
icon: 'fan',
|
||||
headline: '勿涉纷争,保持中立',
|
||||
detail: '易卷入人际是非,适合远离矛盾,保持中立姿态。',
|
||||
suitable: false
|
||||
},
|
||||
{
|
||||
id: 'study',
|
||||
title: '学业',
|
||||
icon: 'scroll',
|
||||
headline: '基础松散,学业忌跳级',
|
||||
detail: '底层知识不牢,别急于学习进阶内容。',
|
||||
suitable: false
|
||||
},
|
||||
{
|
||||
id: 'career',
|
||||
title: '事业',
|
||||
icon: 'bamboo',
|
||||
headline: '敷衍了事,别凑活',
|
||||
detail: '今日易因松散出错,适合认真对待每一项小任务,别敷衍。',
|
||||
suitable: false
|
||||
},
|
||||
{
|
||||
id: 'travel',
|
||||
title: '出行',
|
||||
icon: 'horse',
|
||||
headline: '勿负重行,轻装简从',
|
||||
detail: '今日出行负重易生疲惫,建议轻装出门,避免带过多不必要的物品。',
|
||||
suitable: false
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
const iconClass = (icon: string) => `dimension-icon icon-${icon}`
|
||||
const icons: Record<string, string> = { heart, gourd, vase, coin, fan, scroll, bamboo, horse }
|
||||
const ORDER_KEY = 'home.dimension-order.v1'
|
||||
const directionAngles: Record<string, number> = { 正北: 0, 东北: 45, 正东: 90, 东南: 135, 正南: 180, 西南: 225, 正西: 270, 西北: 315 }
|
||||
|
||||
export default function HomePage() {
|
||||
const [overview, setOverview] = useState<HomeOverview>(createMockHome)
|
||||
const [mode, setMode] = useState<PageMode>('home')
|
||||
const [orderedIds, setOrderedIds] = useState<string[]>([])
|
||||
const [profile, setProfile] = useState<UserProfile | null>(null)
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [loadFailed, setLoadFailed] = useState(false)
|
||||
const [mode, setMode] = useState<'home' | 'sort'>('home')
|
||||
const [today, setToday] = useState(() => getBeijingDate())
|
||||
const [dayOffset, setDayOffset] = useState<-1 | 0 | 1>(0)
|
||||
const [orderedIds, setOrderedIds] = useState<string[]>(HOME_DIMENSION_IDS)
|
||||
const [avatarFailed, setAvatarFailed] = useState(false)
|
||||
const requestSequence = useRef(0)
|
||||
|
||||
const refreshProfile = () => {
|
||||
setToday(getBeijingDate())
|
||||
setLoading(true)
|
||||
setLoadFailed(false)
|
||||
const sequence = ++requestSequence.current
|
||||
api.profile().then((data) => {
|
||||
if (sequence !== requestSequence.current) return
|
||||
setProfile(data)
|
||||
setAvatarFailed(false)
|
||||
}).catch(() => {
|
||||
if (sequence !== requestSequence.current) return
|
||||
setProfile(null)
|
||||
setLoadFailed(true)
|
||||
}).finally(() => {
|
||||
if (sequence === requestSequence.current) setLoading(false)
|
||||
})
|
||||
try { setOrderedIds(normalizeDimensionOrder(Taro.getStorageSync(ORDER_KEY))) } catch { setOrderedIds([...HOME_DIMENSION_IDS]) }
|
||||
}
|
||||
useDidShow(refreshProfile)
|
||||
|
||||
useEffect(() => {
|
||||
api.homeOverview()
|
||||
.then((data) => {
|
||||
setOverview(data)
|
||||
setOrderedIds(data.dimensions.map((item) => item.id))
|
||||
})
|
||||
.catch(() => {
|
||||
const mock = createMockHome()
|
||||
setOverview(mock)
|
||||
setOrderedIds(mock.dimensions.map((item) => item.id))
|
||||
})
|
||||
let timer: ReturnType<typeof setTimeout>
|
||||
const refreshDate = () => {
|
||||
const now = new Date()
|
||||
setToday(getBeijingDate(now))
|
||||
timer = setTimeout(refreshDate, 86400000 - ((now.getTime() + 28800000) % 86400000) + 100)
|
||||
}
|
||||
refreshDate()
|
||||
return () => { clearTimeout(timer); requestSequence.current++ }
|
||||
}, [])
|
||||
|
||||
const activeDay = overview.days.find((day) => day.label === overview.activeDay) || overview.days[1]
|
||||
const overview = useMemo(() => profile ? generateHomeOverview(profile, today, dayOffset) : null, [profile?.birthday, profile?.birthHour, today, dayOffset])
|
||||
const orderedDimensions = useMemo(() => {
|
||||
const byId = overview.dimensions.reduce<Record<string, DimensionItem>>((result, item) => {
|
||||
result[item.id] = item
|
||||
return result
|
||||
}, {})
|
||||
return orderedIds.map((id) => byId[id]).filter(Boolean)
|
||||
}, [orderedIds, overview.dimensions])
|
||||
if (!overview) return []
|
||||
return orderedIds.map((id) => overview.dimensions.find((item) => item.id === id)).filter(Boolean)
|
||||
}, [overview, orderedIds])
|
||||
|
||||
const moveDimension = (index: number, direction: -1 | 1) => {
|
||||
const target = index + direction
|
||||
if (target < 0 || target >= orderedIds.length) return
|
||||
const next = [...orderedIds]
|
||||
const current = next[index]
|
||||
next[index] = next[target]
|
||||
next[target] = current
|
||||
;[next[index], next[target]] = [next[target], next[index]]
|
||||
setOrderedIds(next)
|
||||
}
|
||||
|
||||
const go = (url: string) => Taro.redirectTo({ url })
|
||||
|
||||
const renderTabbar = () => (
|
||||
<View className='home-tabbar'>
|
||||
<View className='home-tabbar-item active'>
|
||||
<View className='home-tab-icon' />
|
||||
<Text>首页</Text>
|
||||
</View>
|
||||
<Button className='home-realm-tab' onClick={() => go('/pages/fortune/index')}>
|
||||
<Image className='home-realm-avatar' src={avatarAsset} mode='aspectFill' />
|
||||
<Text>天宫</Text>
|
||||
</Button>
|
||||
<Button className='home-tabbar-item' onClick={() => go('/pages/my/index')}>
|
||||
<View className='home-mine-icon' />
|
||||
<Text>我的</Text>
|
||||
</Button>
|
||||
</View>
|
||||
)
|
||||
|
||||
if (mode === 'sort') {
|
||||
return (
|
||||
<View className='home-page sort-page'>
|
||||
<Button className='sort-back' onClick={() => setMode('home')}>‹</Button>
|
||||
<Text className='sort-title'>排序</Text>
|
||||
<View className='sort-hint-row'>
|
||||
<Text>按住右侧</Text>
|
||||
<Text className='sort-handle-symbol'>☰</Text>
|
||||
<Text>上下拖动排序</Text>
|
||||
<Button className='sort-done' onClick={() => setMode('home')}>完成</Button>
|
||||
</View>
|
||||
<View className='sort-list'>
|
||||
{orderedDimensions.map((item, index) => (
|
||||
<View className='sort-item' key={item.id}>
|
||||
<Text>{item.title}</Text>
|
||||
<View className='sort-controls'>
|
||||
<Button onClick={() => moveDimension(index, -1)}>↑</Button>
|
||||
<Button onClick={() => moveDimension(index, 1)}>↓</Button>
|
||||
<Text>☰</Text>
|
||||
</View>
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
{renderTabbar()}
|
||||
</View>
|
||||
)
|
||||
const finishSorting = () => {
|
||||
try { Taro.setStorageSync(ORDER_KEY, orderedIds); setMode('home') }
|
||||
catch { Taro.showToast({ title: '排序保存失败,请重试', icon: 'none' }) }
|
||||
}
|
||||
|
||||
return (
|
||||
<View className='home-page'>
|
||||
<View className='day-switch'>
|
||||
<View className='avatar-orb'>
|
||||
<View className='water-face'>⌣</View>
|
||||
</View>
|
||||
<View className='day-tabs'>
|
||||
{overview.days.map((day) => (
|
||||
<View className={day.label === overview.activeDay ? 'day-tab active' : 'day-tab'} key={day.label}>
|
||||
<Text className='day-label'>{day.label}</Text>
|
||||
<Text className='day-status'>{day.status}</Text>
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
if (loading || !overview) {
|
||||
return <View className='home-page'>
|
||||
<View className='home-empty'>
|
||||
<Image src={water} mode='aspectFit' className='home-empty-image' />
|
||||
<Text>{loading ? '正在准备你的每日参考…' : loadFailed ? '个人资料加载失败,请重试' : '请先完善有效的出生日期和时辰'}</Text>
|
||||
{!loading && <Button onClick={loadFailed ? refreshProfile : () => Taro.navigateTo({ url: '/pages/profile-edit/index' })}>{loadFailed ? '重新加载' : '完善出生信息'}</Button>}
|
||||
</View>
|
||||
|
||||
<View className='date-row'>
|
||||
<Text><Text className='month-day'>{Number(activeDay.date.slice(5, 7))}月{Number(activeDay.date.slice(8, 10))}日</Text> {activeDay.weekName}</Text>
|
||||
<Text>{activeDay.lunarDate}</Text>
|
||||
</View>
|
||||
|
||||
<View className='summary-card'>
|
||||
<Text className='summary-copy'>{overview.summary}</Text>
|
||||
<View className='index-orb'>
|
||||
<Text className='index-number'>{overview.overallIndex}</Text>
|
||||
<Text>综合指数</Text>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
<View className='lucky-grid-home'>
|
||||
<View className='lucky-box colors-box'>
|
||||
<Text className='lucky-label'>吉色</Text>
|
||||
{overview.luckyColors.map((color) => (
|
||||
<View className='color-chip' key={color.name}>
|
||||
<View className='swatch' style={{ background: color.value }} />
|
||||
<Text>{color.name}</Text>
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
<View className='lucky-box number-box'>
|
||||
<Text className='lucky-label'>吉数</Text>
|
||||
<View className='number-slots'>
|
||||
{overview.luckyNumbers.map((number) => <Text key={number}>{number}</Text>)}
|
||||
</View>
|
||||
</View>
|
||||
<View className='lucky-box direction-box'>
|
||||
<Text className='lucky-label'>吉向</Text>
|
||||
<View className='compass-icon'>⌖</View>
|
||||
<Text>{overview.luckyDirection}</Text>
|
||||
</View>
|
||||
<View className='lucky-box hour-box'>
|
||||
<Text className='lucky-label'>吉时</Text>
|
||||
{overview.luckyHours.map((hour) => (
|
||||
<View className='hour-chip' key={`${hour.branch}-${hour.time}`}>
|
||||
<Text>{hour.branch}</Text>
|
||||
<Text>{hour.time}</Text>
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
</View>
|
||||
|
||||
<View className='dimension-head'>
|
||||
<Text>维度解析</Text>
|
||||
<Button onClick={() => setMode('sort')}>排序 ⇅</Button>
|
||||
</View>
|
||||
|
||||
<View className='dimension-list'>
|
||||
{orderedDimensions.map((item) => (
|
||||
<View className={item.suitable ? 'dimension-card suitable' : 'dimension-card avoid'} key={item.id}>
|
||||
<View className={iconClass(item.icon)} />
|
||||
<View className='dimension-copy'>
|
||||
<View className='dimension-title-row'>
|
||||
<Text className='dimension-title'>{item.title}</Text>
|
||||
<Text className='dimension-headline'>{item.headline}</Text>
|
||||
</View>
|
||||
<Text className='dimension-detail'>{item.detail}</Text>
|
||||
</View>
|
||||
<Text className={item.suitable ? 'dimension-tag suitable' : 'dimension-tag avoid'}>
|
||||
{item.suitable ? '宜' : '忌'}
|
||||
</Text>
|
||||
<Text className='dimension-arrow'>›</Text>
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
{renderTabbar()}
|
||||
<AppTabBar active='home' />
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
if (mode === 'sort') {
|
||||
return <View className='home-page home-sort-page'>
|
||||
<View className='home-sort-nav'>
|
||||
<Button onClick={() => setMode('home')}>‹</Button><Text>维度排序</Text><Button onClick={finishSorting}>完成</Button>
|
||||
</View>
|
||||
<Text className='home-sort-hint'>点击上下箭头调整显示顺序,完成后保存在本机。</Text>
|
||||
<View className='home-sort-list'>{orderedDimensions.map((item, index) => <View key={item.id} className='home-sort-item'>
|
||||
<Image className='home-sort-icon' src={icons[item.icon]} mode='aspectFit' /><Text>{item.title}</Text>
|
||||
<View className='home-sort-controls'>
|
||||
<Button disabled={index === 0} onClick={() => moveDimension(index, -1)} ariaLabel={`上移${item.title}`}>↑</Button>
|
||||
<Button disabled={index === orderedDimensions.length - 1} onClick={() => moveDimension(index, 1)} ariaLabel={`下移${item.title}`}>↓</Button>
|
||||
</View>
|
||||
</View>)}</View>
|
||||
<AppTabBar active='home' />
|
||||
</View>
|
||||
}
|
||||
|
||||
const activeDay = overview.days[dayOffset + 1]
|
||||
return <View className='home-page'>
|
||||
{isFrontendPreview() && <Text className='home-preview-note'>前端预览 · 示例资料 · 不保存个人资料</Text>}
|
||||
<View className='home-day-switch'>
|
||||
<View className='home-avatar-orb'><Image src={profile.avatarUrl && !avatarFailed ? resolveAssetUrl(profile.avatarUrl) : water} mode={profile.avatarUrl && !avatarFailed ? 'aspectFill' : 'aspectFit'} className={profile.avatarUrl && !avatarFailed ? 'home-avatar-image' : 'home-water-image'} onError={() => setAvatarFailed(true)} /></View>
|
||||
<View className='home-day-tabs'>{overview.days.map((day, index) => <Button key={day.label} hoverClass='none' className={`home-day-tab ${index === dayOffset + 1 ? 'active' : ''}`} onClick={() => setDayOffset((index - 1) as -1 | 0 | 1)}>
|
||||
<Text className='home-day-label'>{day.label}</Text><Text className='home-day-status'>{day.status}</Text>
|
||||
</Button>)}</View>
|
||||
</View>
|
||||
|
||||
<View className='home-date-row'><View className='home-solar-date'><Text>{Number(activeDay.date.slice(5, 7))}月</Text><Text className='home-date-number'>{Number(activeDay.date.slice(8, 10))}</Text><Text>日 {activeDay.weekName}</Text></View><Text className='home-lunar-date'>{activeDay.lunarDate}</Text></View>
|
||||
|
||||
<View className='home-summary-card'>
|
||||
<View className='home-summary-stars'><View /><View /><View /></View>
|
||||
<Text className='home-summary-copy'>{overview.summary}</Text>
|
||||
<View className='home-index-halo'><View className='home-index-orb'><Text className='home-index-number'>{overview.overallIndex}</Text><Text className='home-index-label'>综合指数</Text></View></View>
|
||||
</View>
|
||||
|
||||
<View className='home-lucky-row'>
|
||||
<View className='home-lucky-box home-colors-box'><Text className='home-lucky-label'>吉色</Text><View className='home-color-list'>{overview.luckyColors.map((color) => <View className='home-color-chip' key={color.name}><View className='home-swatch' style={{ backgroundColor: color.value }} /><Text>{color.name}</Text></View>)}</View></View>
|
||||
<View className='home-lucky-box home-numbers-box'><Text className='home-lucky-label'>吉数</Text><View className='home-number-slots'>{overview.luckyNumbers.map((number) => <View className='home-number-slot' key={number}><Text>{number}</Text></View>)}</View></View>
|
||||
</View>
|
||||
<View className='home-lucky-row'>
|
||||
<View className='home-lucky-box home-direction-box'><Text className='home-lucky-label'>吉向</Text><View className='home-compass'><View className='home-compass-needle' style={{ transform: `rotate(${directionAngles[overview.luckyDirection] || 0}deg)` }} /></View><Text className='home-direction-value'>{overview.luckyDirection}</Text></View>
|
||||
<View className='home-lucky-box home-hours-box'><Text className='home-lucky-label'>吉时</Text><View className='home-hours-list'>{overview.luckyHours.length ? overview.luckyHours.map((hour) => <View className='home-hour-chip' key={`${hour.branch}-${hour.time}`}><Text className='home-hour-branch'>{hour.branch}</Text><Text>{hour.time.replace(/:00/g, '')}</Text></View>) : <Text className='home-no-hour'>暂无参考时段</Text>}</View></View>
|
||||
</View>
|
||||
|
||||
<View className='home-dimension-head'><Text>维度解析</Text><Button onClick={() => setMode('sort')}>排序 <View className='home-sort-symbol'><View /><View /></View></Button></View>
|
||||
<View className='home-dimension-list'>{orderedDimensions.map((item) => <View className={`home-dimension-card dimension-${item.id}`} key={item.id}>
|
||||
<View className='home-dimension-title-row'><Image className='home-dimension-icon' src={icons[item.icon]} mode='aspectFit' /><Text className='home-dimension-title'>{item.title}</Text><Text className='home-dimension-headline'>{item.headline}</Text><Text className={`home-dimension-tag ${item.suitable ? 'suitable' : 'avoid'}`}>{item.suitable ? '宜' : '忌'}</Text></View>
|
||||
<Text className='home-dimension-detail'>{item.detail}</Text>
|
||||
</View>)}</View>
|
||||
<Text className='home-entertainment-note'>每日简化参考 · 仅作传统文化娱乐参考,不作为现实决策依据</Text>
|
||||
<AppTabBar active='home' />
|
||||
</View>
|
||||
}
|
||||
@@ -1,50 +1,23 @@
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import Taro from '@tarojs/taro'
|
||||
import { Button, Image, Text, View } from '@tarojs/components'
|
||||
import Taro, { useDidShow } from '@tarojs/taro'
|
||||
import { Button, Image, ScrollView, Text, View } from '@tarojs/components'
|
||||
import { RadarChart } from '../../components/RadarChart'
|
||||
import { api, UserProfile } from '../../services/request'
|
||||
import avatarAsset from '../../assets/fortune/avatar.jpg'
|
||||
import { AppTabBar } from '../../components/AppTabBar'
|
||||
import { ZodiacMascot } from '../../components/ZodiacMascot'
|
||||
import { api, resolveAssetUrl, UserProfile } from '../../services/request'
|
||||
import coinAsset from '../../assets/fortune/coin.jpg'
|
||||
import { calculateFiveElements } from '../../utils/fiveElements'
|
||||
import { calculateZodiac } from '../../utils/zodiac'
|
||||
import { calculateWeeklyZodiacFortune, getBeijingDate, ZODIAC_WEEKLY_RULES } from '../../utils/zodiacWeekly'
|
||||
import { isFrontendPreview } from '../../services/frontendPreview'
|
||||
import './index.scss'
|
||||
|
||||
type PageMode = 'home' | 'element'
|
||||
|
||||
const mockProfile: UserProfile = {
|
||||
id: 1,
|
||||
nickname: 'You',
|
||||
gender: '男',
|
||||
birthday: '1998-06-18',
|
||||
birthHour: '辰时',
|
||||
province: '河南省',
|
||||
city: '洛阳市',
|
||||
district: '老城区',
|
||||
points: 120,
|
||||
remainingEdits: 5,
|
||||
elementReport: {
|
||||
scores: [
|
||||
{ name: '土', color: '#b46a18', value: 42 },
|
||||
{ name: '金', color: '#d59a05', value: 22 },
|
||||
{ name: '水', color: '#35bfe8', value: 8 },
|
||||
{ name: '木', color: '#36b85b', value: 22 },
|
||||
{ name: '火', color: '#ed3c43', value: 7 }
|
||||
],
|
||||
favorable: '金水',
|
||||
unfavorable: '木火土',
|
||||
dayMaster: '壬'
|
||||
}
|
||||
}
|
||||
|
||||
const formatMaskedBirthday = (birthday: string) => {
|
||||
const formatBirthday = (birthday: string, visible: boolean) => {
|
||||
const [year, month, day] = birthday.split('-')
|
||||
if (!year || !month || !day) return '****_**_**'
|
||||
return '****_**_**'
|
||||
}
|
||||
|
||||
const formatBirthday = (birthday: string) => {
|
||||
const [year, month, day] = birthday.split('-')
|
||||
if (!year || !month || !day) return '****_**_**'
|
||||
return `${year}_${month}_${day}`
|
||||
return visible ? `${year}_${month}_${day}` : '****_**_**'
|
||||
}
|
||||
|
||||
const genderSymbol = (gender: string) => (gender === '女' ? '♀' : '♂')
|
||||
@@ -63,22 +36,68 @@ const traitText = (elements: string) => elements
|
||||
.filter(Boolean)
|
||||
.join('、')
|
||||
|
||||
const WaterMascot = ({ compact = false }: { compact?: boolean }) => (
|
||||
<View className={`water-mascot ${compact ? 'compact' : ''}`}>
|
||||
<View className='water-highlight' />
|
||||
<View className='water-eye left' />
|
||||
<View className='water-eye right' />
|
||||
<View className='water-smile' />
|
||||
</View>
|
||||
)
|
||||
|
||||
export default function MyPage() {
|
||||
const [profile, setProfile] = useState<UserProfile>(mockProfile)
|
||||
const [profile, setProfile] = useState<UserProfile | null>(null)
|
||||
const [profileError, setProfileError] = useState(false)
|
||||
const [mode, setMode] = useState<PageMode>('home')
|
||||
const [zodiacOpen, setZodiacOpen] = useState(false)
|
||||
const [zodiacRulesOpen, setZodiacRulesOpen] = useState(false)
|
||||
const [beijingDate, setBeijingDate] = useState(() => getBeijingDate())
|
||||
const [birthdayVisible, setBirthdayVisible] = useState(false)
|
||||
const previewNote = isFrontendPreview()
|
||||
? <Text className='frontend-preview-note'>前端预览 · 示例资料 · 不保存修改</Text>
|
||||
: null
|
||||
|
||||
const elementReport = useMemo(
|
||||
() => calculateFiveElements(profile.birthday, profile.birthHour),
|
||||
[profile.birthday, profile.birthHour]
|
||||
const zodiac = useMemo(() => calculateZodiac(profile?.birthday || ''), [profile?.birthday])
|
||||
const weeklyFortune = useMemo(
|
||||
() => calculateWeeklyZodiacFortune(profile?.birthday || '', beijingDate),
|
||||
[profile?.birthday, beijingDate]
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
if (!zodiacOpen) return
|
||||
let timer: ReturnType<typeof setTimeout>
|
||||
const refreshDate = () => {
|
||||
const now = new Date()
|
||||
setBeijingDate(getBeijingDate(now))
|
||||
const untilMidnight = 86400000 - ((now.getTime() + 28800000) % 86400000)
|
||||
timer = setTimeout(refreshDate, untilMidnight + 100)
|
||||
}
|
||||
refreshDate()
|
||||
return () => clearTimeout(timer)
|
||||
}, [zodiacOpen])
|
||||
|
||||
const openZodiac = () => {
|
||||
setBeijingDate(getBeijingDate())
|
||||
setZodiacRulesOpen(false)
|
||||
setZodiacOpen(true)
|
||||
}
|
||||
|
||||
const elementReport = useMemo(
|
||||
() => profile ? calculateFiveElements(profile.birthday, profile.birthHour) : null,
|
||||
[profile?.birthday, profile?.birthHour]
|
||||
)
|
||||
|
||||
const refreshProfile = () => {
|
||||
setBeijingDate(getBeijingDate())
|
||||
setProfileError(false)
|
||||
api.profile()
|
||||
.then(setProfile)
|
||||
.catch(() => setProfile(mockProfile))
|
||||
}, [])
|
||||
.catch(() => {
|
||||
setProfileError(true)
|
||||
setProfile(null)
|
||||
})
|
||||
}
|
||||
useDidShow(refreshProfile)
|
||||
|
||||
const go = (url: string) => Taro.navigateTo({ url })
|
||||
|
||||
@@ -87,25 +106,21 @@ export default function MyPage() {
|
||||
Taro.showToast({ title: '企业微信入口待配置', icon: 'none' })
|
||||
}
|
||||
|
||||
const renderTabs = () => (
|
||||
<View className='my-tabbar'>
|
||||
<Button className='my-tabbar-item' onClick={() => Taro.redirectTo({ url: '/pages/home/index' })}>
|
||||
<View className='home-tab-icon' />
|
||||
<Text>首页</Text>
|
||||
</Button>
|
||||
<Button className='realm-tab' onClick={() => go('/pages/fortune/index')}>
|
||||
<Image className='realm-avatar' src={avatarAsset} mode='aspectFill' />
|
||||
<Text>天宫</Text>
|
||||
</Button>
|
||||
<View className='my-tabbar-item active'>
|
||||
<View className='mine-tab-icon' />
|
||||
<Text>我的</Text>
|
||||
</View>
|
||||
</View>
|
||||
)
|
||||
const renderTabs = () => <AppTabBar active='my' />
|
||||
|
||||
const renderElement = () => (
|
||||
const renderElement = () => !elementReport ? (
|
||||
<View className='my-page element-detail'>
|
||||
{previewNote}
|
||||
<Button className='element-back' onClick={() => setMode('home')}>‹</Button>
|
||||
<View className='element-empty'>
|
||||
<Text>请先完善有效的出生日期和时辰,再查看元素报告。</Text>
|
||||
<Button onClick={() => go('/pages/profile-edit/index')}>完善出生信息</Button>
|
||||
</View>
|
||||
{renderTabs()}
|
||||
</View>
|
||||
) : (
|
||||
<View className='my-page element-detail'>
|
||||
{previewNote}
|
||||
<Button className='element-back' onClick={() => setMode('home')}>‹</Button>
|
||||
<View className='element-radar'>
|
||||
<RadarChart scores={elementReport.scores} />
|
||||
@@ -118,63 +133,111 @@ export default function MyPage() {
|
||||
<Text className='element-copy'>
|
||||
<Text className='orange-text'>日主</Text>,即出生日期中的天干,其五行属性直接代表自身能量基础。
|
||||
</Text>
|
||||
<Text className='element-strong'>你适应力强,擅长在变化中寻找机会与路径。</Text>
|
||||
<Text className='element-strong'>你的日主为{elementReport.dayMaster}{elementReport.masterElement},对应的五行特质是{traitText(elementReport.masterElement)}。</Text>
|
||||
<View className='strength-summary'>
|
||||
<Text>日主{elementReport.strength} · 综合评分 {elementReport.strengthScore}/100</Text>
|
||||
<Text className='pillars-summary'>四柱:{elementReport.pillars.join(' · ')}</Text>
|
||||
</View>
|
||||
<View className='strength-factors'>
|
||||
<Text>得令:{elementReport.analysis.season.description}</Text>
|
||||
<Text>得地:{elementReport.analysis.roots.description}</Text>
|
||||
<Text>得势:{elementReport.analysis.support.description}</Text>
|
||||
</View>
|
||||
</View>
|
||||
<View className='element-card favorable-card'>
|
||||
<View className='element-title-row'>
|
||||
<Text className='element-badge green'>喜用</Text>
|
||||
<Text className='element-name'>{elementReport.favorable}</Text>
|
||||
<Text className='element-name'>{elementReport.favorable || '暂无明显偏向'}</Text>
|
||||
</View>
|
||||
<Text className='element-copy'>
|
||||
<Text className='green-text'>喜用</Text>,即更容易让事情进展顺、做得稳、发挥得好的行为方式。
|
||||
{'\n'}根据得令、得地、得势综合判断,作为平衡日主强弱的五行参考。
|
||||
</Text>
|
||||
<Text className='element-strong'>你更容易发挥{traitText(elementReport.favorable)}的优势,遇事能找到适合自己的节奏。</Text>
|
||||
<Text className='element-strong'>{elementReport.strength === '相对平衡'
|
||||
? '当前日主相对平衡,不预设需要补充的五行,宜保持协调。'
|
||||
: `日主${elementReport.strength},以${elementReport.strength === '偏弱' ? '生扶' : '泄耗制衡'}为参考方向。可关注${traitText(elementReport.favorable)}。`}</Text>
|
||||
</View>
|
||||
<View className='element-card avoid-card'>
|
||||
<View className='element-title-row'>
|
||||
<Text className='element-badge pink'>忌用</Text>
|
||||
<Text className='element-name'>{elementReport.unfavorable}</Text>
|
||||
<Text className='element-name'>{elementReport.unfavorable || '暂无明显偏忌'}</Text>
|
||||
</View>
|
||||
<Text className='element-copy'>
|
||||
<Text className='pink-text'>忌用</Text>,即容易让你更累、更乱,或做了很多却效果不好的行为方式。
|
||||
</Text>
|
||||
<Text className='element-strong'>当{traitText(elementReport.unfavorable)}的能量偏旺时,适合放慢节奏,避免陷入无谓消耗。</Text>
|
||||
<Text className='element-strong'>{elementReport.unfavorable
|
||||
? `日主${elementReport.strength}时,${elementReport.unfavorable}不宜继续偏增。可留意${traitText(elementReport.unfavorable)}失衡带来的消耗。`
|
||||
: '当前不划分固定偏忌,避免单一五行过度偏增。'}</Text>
|
||||
</View>
|
||||
<Text className='element-method-note'>普通扶抑简化参考算法 v1,仅作传统文化娱乐参考;不含从格、化气、合冲刑害及调候等特殊判断。按北京时间公历、节气月柱与零点换日计算;时辰以起始小时代表,不作真太阳时校正。</Text>
|
||||
{renderTabs()}
|
||||
</View>
|
||||
)
|
||||
|
||||
if (!profile) {
|
||||
return <View className='my-page my-home'><View className='element-empty'>
|
||||
<Text>{profileError ? '个人资料加载失败,请重试' : '个人资料加载中…'}</Text>
|
||||
{profileError && <Button onClick={refreshProfile}>重新加载</Button>}
|
||||
</View>{renderTabs()}</View>
|
||||
}
|
||||
|
||||
if (mode === 'element') {
|
||||
return renderElement()
|
||||
}
|
||||
|
||||
return (
|
||||
<View className='my-page my-home'>
|
||||
<View className='profile-area'>
|
||||
<Button className='profile-avatar-button' onClick={() => go('/pages/profile-edit/index')}>
|
||||
<View className='water-avatar'>⌣</View>
|
||||
</Button>
|
||||
{previewNote}
|
||||
<View className='profile-area' onClick={() => go('/pages/profile-edit/index')}>
|
||||
<View className='profile-avatar-button'>
|
||||
{profile.avatarUrl
|
||||
? <Image className='profile-avatar-image' src={resolveAssetUrl(profile.avatarUrl)} mode='aspectFill' />
|
||||
: <WaterMascot />}
|
||||
</View>
|
||||
<View className='profile-info'>
|
||||
<View className='name-row'>
|
||||
<Text className='profile-name'>{profile.nickname}</Text>
|
||||
<Text className='gender-chip'>{genderSymbol(profile.gender)}</Text>
|
||||
</View>
|
||||
<Button className='birthday-row' onClick={() => setBirthdayVisible((visible) => !visible)}>
|
||||
<Text className='birthday-icon'>▦</Text>
|
||||
<Text>{birthdayVisible ? formatBirthday(profile.birthday) : formatMaskedBirthday(profile.birthday)}</Text>
|
||||
<Text className={birthdayVisible ? 'eye-line open' : 'eye-line'} />
|
||||
</Button>
|
||||
<View className='birthday-row'>
|
||||
<View className='birthday-icon'>
|
||||
<View className='cake-candle left' />
|
||||
<View className='cake-candle middle' />
|
||||
<View className='cake-candle right' />
|
||||
<View className='cake-body'><View className='cake-icing' /></View>
|
||||
<View className='cake-plate' />
|
||||
</View>
|
||||
<Text className='birthday-value'>{formatBirthday(profile.birthday, birthdayVisible)}</Text>
|
||||
<View
|
||||
className={`birthday-visibility ${birthdayVisible ? 'open' : ''}`}
|
||||
onClick={(event) => {
|
||||
event.stopPropagation()
|
||||
setBirthdayVisible((visible) => !visible)
|
||||
}}
|
||||
>
|
||||
<View className='eye-line'>
|
||||
{birthdayVisible
|
||||
? <View className='eye-pupil' />
|
||||
: (
|
||||
<>
|
||||
<View className='eye-lash left' />
|
||||
<View className='eye-lash right' />
|
||||
</>
|
||||
)}
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
<Button className='profile-arrow' onClick={() => go('/pages/profile-edit/index')}>›</Button>
|
||||
<View className='profile-arrow'>›</View>
|
||||
</View>
|
||||
|
||||
<View className='quick-card'>
|
||||
<Button className='quick-entry' onClick={() => setZodiacOpen(true)}>
|
||||
<View className='zodiac-icon'>⌇</View>
|
||||
<Button className='quick-entry' onClick={openZodiac}>
|
||||
<View className='quick-icon zodiac-icon'><ZodiacMascot zodiac={zodiac} /></View>
|
||||
<Text>我的生肖</Text>
|
||||
</Button>
|
||||
<Button className='quick-entry' onClick={() => setMode('element')}>
|
||||
<View className='element-icon'>⌣</View>
|
||||
<View className='quick-icon element-icon'><WaterMascot compact /></View>
|
||||
<Text>我的元素</Text>
|
||||
</Button>
|
||||
</View>
|
||||
@@ -193,17 +256,30 @@ export default function MyPage() {
|
||||
|
||||
<View className='settings-card'>
|
||||
<Button className='settings-row' onClick={openEnterpriseWechat}>
|
||||
<View className='menu-icon headset-icon' />
|
||||
<View className='menu-icon headset-icon'>
|
||||
<View className='headset-band' />
|
||||
<View className='headset-ear left' />
|
||||
<View className='headset-ear right' />
|
||||
<View className='headset-mic' />
|
||||
</View>
|
||||
<Text>联系我们</Text>
|
||||
<Text className='row-arrow'>›</Text>
|
||||
</Button>
|
||||
<Button className='settings-row' onClick={() => go('/pages/follow/index')}>
|
||||
<View className='menu-icon star-icon'>✦</View>
|
||||
<View className='menu-icon star-icon'>
|
||||
<View className='star-core' />
|
||||
<View className='star-plus horizontal' />
|
||||
<View className='star-plus vertical' />
|
||||
</View>
|
||||
<Text>关注我们</Text>
|
||||
<Text className='row-arrow'>›</Text>
|
||||
</Button>
|
||||
<Button className='settings-row' onClick={() => go('/pages/agreement/index')}>
|
||||
<View className='menu-icon agreement-icon' />
|
||||
<View className='menu-icon agreement-icon'>
|
||||
<View className='agreement-line first' />
|
||||
<View className='agreement-line second' />
|
||||
<View className='agreement-check' />
|
||||
</View>
|
||||
<Text>用户协议</Text>
|
||||
<Text className='row-arrow'>›</Text>
|
||||
</Button>
|
||||
@@ -215,10 +291,42 @@ export default function MyPage() {
|
||||
<View className='zodiac-mask' onClick={() => setZodiacOpen(false)}>
|
||||
<View className='zodiac-modal' onClick={(event) => event.stopPropagation()}>
|
||||
<View className='lucky-flower'>运</View>
|
||||
<Text className='zodiac-title'>生肖周运</Text>
|
||||
<View className='zodiac-large'>⌇</View>
|
||||
<Text className='zodiac-status'>平稳</Text>
|
||||
<Text className='zodiac-summary'>本周运势平稳,生活节奏舒缓,安心度日,享受静谧时光。</Text>
|
||||
<Text className='zodiac-title'>{zodiac ? `${zodiac} · 生肖周运` : '我的生肖'}</Text>
|
||||
<ScrollView className='zodiac-scroll' scrollY showScrollbar={false}>
|
||||
<View className='zodiac-body'>
|
||||
<View className='zodiac-large'><ZodiacMascot zodiac={zodiac} /></View>
|
||||
{weeklyFortune ? (
|
||||
<>
|
||||
<Text className='zodiac-animal-name'>属{zodiac}</Text>
|
||||
<Text className='zodiac-calendar-note'>按农历出生年 · 春节换年</Text>
|
||||
<Text className='zodiac-week-range'>{weeklyFortune.weekStart} — {weeklyFortune.weekEnd}</Text>
|
||||
<Text className={`zodiac-status ${weeklyFortune.tone}`}>{weeklyFortune.status}</Text>
|
||||
<Text className='zodiac-summary'>{weeklyFortune.summary}</Text>
|
||||
<View className='zodiac-date-guide'>
|
||||
<View><Text className='guide-label supportive'>助力日</Text><Text>{weeklyFortune.supportiveDays.map((item) => `${item.label} ${item.weekday}`).join('、') || '本周无明显合助日'}</Text></View>
|
||||
<View><Text className='guide-label cautious'>留意日</Text><Text>{weeklyFortune.cautiousDays.map((item) => `${item.label} ${item.weekday}`).join('、') || '本周无六冲、相害日'}</Text></View>
|
||||
</View>
|
||||
<Button className='zodiac-rules-toggle' onClick={() => setZodiacRulesOpen((open) => !open)}>{zodiacRulesOpen ? '收起判断依据' : '查看判断依据'}</Button>
|
||||
{zodiacRulesOpen && <View className='zodiac-rules'>
|
||||
<Text className='zodiac-rule-copy'>{ZODIAC_WEEKLY_RULES}</Text>
|
||||
<Text className='zodiac-rule-copy'>本周合计:{weeklyFortune.score > 0 ? '+' : ''}{weeklyFortune.score}。逐日与出生年支“{weeklyFortune.branch}”比较:</Text>
|
||||
{weeklyFortune.days.map((item) => <View key={item.date} className={`zodiac-day ${item.score > 0 ? 'supportive' : item.score < 0 ? 'cautious' : ''}`}>
|
||||
<Text>{item.label} {item.weekday}</Text>
|
||||
<Text>{item.branch}日 · {item.relation === '三合' ? '三合同组' : item.relation}</Text>
|
||||
<Text>{item.score > 0 ? '+' : ''}{item.score}</Text>
|
||||
</View>)}
|
||||
<Text className='zodiac-rule-copy'>三合仅取同组两支的助力关系,不代表三合成局;不纳入刑、破或完整八字。</Text>
|
||||
</View>}
|
||||
<Text className='zodiac-week-note'>按北京时间周一至周日计算 · 合冲简化规则 v1{ '\n' }仅作传统文化娱乐参考,不作为现实决策依据</Text>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Text className='zodiac-summary'>{zodiac ? '周运日期无法计算,请检查设备日期后重新打开。' : '请先完善有效的出生日期,再查看你的生肖。'}</Text>
|
||||
{!zodiac && <Button className='zodiac-edit' onClick={() => { setZodiacOpen(false); go('/pages/profile-edit/index') }}>完善生日</Button>}
|
||||
</>
|
||||
)}
|
||||
</View>
|
||||
</ScrollView>
|
||||
<Button className='zodiac-confirm' onClick={() => setZodiacOpen(false)}>知道了</Button>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
@@ -1,113 +1,364 @@
|
||||
.edit-page {
|
||||
min-height: 100vh;
|
||||
box-sizing: border-box;
|
||||
color: #211c3a;
|
||||
background:
|
||||
radial-gradient(circle at 14% 12%, rgba(179, 154, 255, 0.72), transparent 34%),
|
||||
linear-gradient(180deg, #c2afff 0%, #e4d8ff 36%, #edf4ff 70%, #edf5ff 100%);
|
||||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
.edit-page .nav {
|
||||
height: calc(112px + env(safe-area-inset-top));
|
||||
padding: 0 32px 24px;
|
||||
align-items: flex-end;
|
||||
}
|
||||
|
||||
.edit-page .nav-title {
|
||||
color: #211c3a;
|
||||
font-size: 40px;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.edit-page .back {
|
||||
left: 34px;
|
||||
bottom: 18px;
|
||||
color: #292244;
|
||||
font-size: 60px;
|
||||
}
|
||||
|
||||
.profile-loading {
|
||||
padding-top: calc(280px + env(safe-area-inset-top));
|
||||
text-align: center;
|
||||
color: rgba(33, 28, 58, 0.58);
|
||||
font-size: 28px;
|
||||
}
|
||||
|
||||
.edit-content {
|
||||
width: 100%;
|
||||
max-width: 750px;
|
||||
min-height: 100vh;
|
||||
margin: 0 auto;
|
||||
padding: calc(164px + env(safe-area-inset-top)) 64px calc(78px + env(safe-area-inset-bottom));
|
||||
box-sizing: border-box;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
padding-top: 210px;
|
||||
}
|
||||
|
||||
.edit-avatar {
|
||||
width: 150px;
|
||||
height: 150px;
|
||||
border-radius: 88px;
|
||||
background: #fbffd7;
|
||||
color: #17c9ea;
|
||||
font-size: 60px;
|
||||
.avatar-button {
|
||||
width: 280px;
|
||||
height: 280px;
|
||||
flex: none;
|
||||
border-radius: 50%;
|
||||
background: rgba(255, 255, 237, 0.94);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
position: relative;
|
||||
overflow: visible;
|
||||
box-shadow: 0 4px 12px rgba(102, 83, 151, 0.08);
|
||||
}
|
||||
|
||||
.avatar-image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.water-mascot {
|
||||
width: 142px;
|
||||
height: 178px;
|
||||
position: relative;
|
||||
border-radius: 70% 70% 56% 56% / 82% 82% 42% 42%;
|
||||
background: linear-gradient(180deg, #a0f6ff 0%, #47d2ef 54%, #1fb7e4 100%);
|
||||
box-shadow: inset 16px 10px 30px rgba(255, 255, 255, 0.28);
|
||||
}
|
||||
|
||||
.mascot-eye {
|
||||
position: absolute;
|
||||
top: 100px;
|
||||
width: 10px;
|
||||
height: 14px;
|
||||
border-radius: 50%;
|
||||
background: #3275ef;
|
||||
}
|
||||
|
||||
.mascot-eye.left { left: 48px; }
|
||||
.mascot-eye.right { right: 48px; }
|
||||
|
||||
.mascot-smile {
|
||||
position: absolute;
|
||||
left: 56px;
|
||||
top: 116px;
|
||||
width: 34px;
|
||||
height: 22px;
|
||||
border: 7px solid #3275ef;
|
||||
border-top: 0;
|
||||
border-radius: 0 0 28px 28px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.avatar-add {
|
||||
position: absolute;
|
||||
right: 4px;
|
||||
bottom: 4px;
|
||||
width: 66px;
|
||||
height: 66px;
|
||||
border-radius: 50%;
|
||||
background: linear-gradient(145deg, #ffb13b 0%, #ff8c1f 100%);
|
||||
border: 5px solid rgba(255, 255, 255, 0.9);
|
||||
box-sizing: border-box;
|
||||
box-shadow: 0 7px 16px rgba(188, 100, 19, 0.24);
|
||||
}
|
||||
|
||||
.plus-line {
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
width: 30px;
|
||||
height: 6px;
|
||||
border-radius: 6px;
|
||||
background: #fff;
|
||||
transform: translate(-50%, -50%);
|
||||
}
|
||||
|
||||
.plus-line.vertical {
|
||||
transform: translate(-50%, -50%) rotate(90deg);
|
||||
}
|
||||
|
||||
.form-card {
|
||||
width: 100%;
|
||||
min-height: 94px;
|
||||
border: 3px solid rgba(255, 255, 255, 0.72);
|
||||
border-radius: 50px;
|
||||
background: rgba(255, 255, 255, 0.68);
|
||||
box-sizing: border-box;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
color: #28204e;
|
||||
}
|
||||
|
||||
.nickname-card {
|
||||
margin-top: 58px;
|
||||
padding: 0 30px;
|
||||
}
|
||||
|
||||
.field-label {
|
||||
flex: none;
|
||||
font-size: 30px;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.nickname-input {
|
||||
height: 90px;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
margin-left: 36px;
|
||||
color: #28204e;
|
||||
font-size: 31px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.nickname-input input {
|
||||
height: 100%;
|
||||
padding: 0;
|
||||
line-height: 90px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.nickname-count {
|
||||
flex: none;
|
||||
color: #746c9c;
|
||||
font-size: 28px;
|
||||
}
|
||||
|
||||
.gender-row {
|
||||
width: 100%;
|
||||
margin: 34px 0;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 76px;
|
||||
}
|
||||
|
||||
.gender-option {
|
||||
height: 94px;
|
||||
flex: 1;
|
||||
border: 3px solid rgba(255, 255, 255, 0.7);
|
||||
border-radius: 50px;
|
||||
background: rgba(255, 255, 255, 0.66);
|
||||
color: #332463;
|
||||
font-size: 31px;
|
||||
font-weight: 700;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 22px;
|
||||
}
|
||||
|
||||
.gender-option.active {
|
||||
color: #fff;
|
||||
background: linear-gradient(90deg, #65c8f9 0%, #51b8ef 100%);
|
||||
}
|
||||
|
||||
.gender-option + .gender-option {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.gender-symbol {
|
||||
font-size: 52px;
|
||||
font-weight: 500;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.picker-card {
|
||||
margin-bottom: 34px;
|
||||
padding: 0 28px 0 31px;
|
||||
}
|
||||
|
||||
.form-picker {
|
||||
width: 100%;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.field-value {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
margin-left: 36px;
|
||||
font-size: 29px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.field-value.location {
|
||||
font-size: 27px;
|
||||
}
|
||||
|
||||
.field-value.placeholder {
|
||||
color: #8e88aa;
|
||||
}
|
||||
|
||||
.chevron {
|
||||
flex: none;
|
||||
margin-left: 14px;
|
||||
font-size: 56px;
|
||||
font-weight: 300;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.save-button {
|
||||
width: 456px;
|
||||
height: 96px;
|
||||
margin-top: 36px;
|
||||
border-radius: 52px;
|
||||
color: #fff;
|
||||
background: #ff9828;
|
||||
font-size: 34px;
|
||||
font-weight: 800;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
box-shadow: 0 10px 20px rgba(222, 128, 32, 0.14);
|
||||
}
|
||||
|
||||
.save-button[disabled] {
|
||||
opacity: 0.68;
|
||||
}
|
||||
|
||||
.edit-note {
|
||||
margin-top: 28px;
|
||||
color: #666275;
|
||||
font-size: 27px;
|
||||
}
|
||||
|
||||
.edit-note text {
|
||||
color: #f13d57;
|
||||
}
|
||||
|
||||
.avatar-mask {
|
||||
position: fixed;
|
||||
z-index: 30;
|
||||
inset: 0;
|
||||
background: rgba(21, 17, 39, 0.62);
|
||||
}
|
||||
|
||||
.avatar-sheet {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
padding-bottom: env(safe-area-inset-bottom);
|
||||
border-radius: 28px 28px 0 0;
|
||||
overflow: hidden;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.avatar-action {
|
||||
width: 100%;
|
||||
height: 118px;
|
||||
border-bottom: 1px solid #eeeef2;
|
||||
border-radius: 0;
|
||||
color: #202020;
|
||||
background: #fff;
|
||||
font-size: 33px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.edit-avatar text {
|
||||
position: absolute;
|
||||
right: -34px;
|
||||
bottom: 34px;
|
||||
font-size: 28px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.name-pill {
|
||||
width: 420px;
|
||||
height: 76px;
|
||||
margin-top: 56px;
|
||||
border-radius: 40px;
|
||||
background: #fff7de;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 0 30px;
|
||||
gap: 20px;
|
||||
box-sizing: border-box;
|
||||
color: #8f640d;
|
||||
font-size: 38px;
|
||||
}
|
||||
|
||||
.name-pill input {
|
||||
flex: 1;
|
||||
text-align: center;
|
||||
color: #8f640d;
|
||||
}
|
||||
|
||||
.gender-row {
|
||||
margin-top: 58px;
|
||||
display: flex;
|
||||
gap: 86px;
|
||||
}
|
||||
|
||||
.gender {
|
||||
color: #8f640d;
|
||||
font-size: 34px;
|
||||
display: flex;
|
||||
.wechat-avatar-action {
|
||||
height: 154px;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
margin-top: 58px;
|
||||
font-size: 34px;
|
||||
font-weight: 700;
|
||||
color: #8f640d;
|
||||
.wechat-avatar-preview {
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.date-row,
|
||||
.region-row {
|
||||
margin-top: 34px;
|
||||
display: flex;
|
||||
gap: 18px;
|
||||
.sheet-gap {
|
||||
height: 16px;
|
||||
background: #f5f5f7;
|
||||
}
|
||||
|
||||
.date-part {
|
||||
width: 150px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 32px;
|
||||
.cancel-action {
|
||||
height: 126px;
|
||||
border-bottom: 0;
|
||||
}
|
||||
|
||||
.hour {
|
||||
width: 360px;
|
||||
margin-top: 30px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 32px;
|
||||
}
|
||||
@media screen and (max-height: 700px) {
|
||||
.edit-content {
|
||||
padding-top: calc(140px + env(safe-area-inset-top));
|
||||
}
|
||||
|
||||
.region-row .input-pill {
|
||||
width: 176px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 26px;
|
||||
padding: 0 12px;
|
||||
}
|
||||
.avatar-button {
|
||||
width: 220px;
|
||||
height: 220px;
|
||||
}
|
||||
|
||||
.start-button {
|
||||
width: 500px;
|
||||
margin-top: 110px;
|
||||
}
|
||||
.water-mascot {
|
||||
transform: scale(0.82);
|
||||
}
|
||||
|
||||
.edit-note {
|
||||
margin-top: 28px;
|
||||
color: #4b2d1a;
|
||||
font-size: 28px;
|
||||
.nickname-card {
|
||||
margin-top: 38px;
|
||||
}
|
||||
|
||||
.gender-row,
|
||||
.picker-card {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.gender-row {
|
||||
margin-top: 24px;
|
||||
}
|
||||
|
||||
.save-button {
|
||||
margin-top: 18px;
|
||||
}
|
||||
}
|
||||
@@ -1,74 +1,332 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import Taro from '@tarojs/taro'
|
||||
import { Button, Input, Picker, Text, View } from '@tarojs/components'
|
||||
import { Button, Image, Input, Picker, Text, View } from '@tarojs/components'
|
||||
import areaData from 'china-area-data'
|
||||
import { NavBar } from '../../components/NavBar'
|
||||
import { api, UserProfile } from '../../services/request'
|
||||
import { api, resolveAssetUrl, UserProfile } from '../../services/request'
|
||||
import './index.scss'
|
||||
|
||||
const hours = ['子时', '丑时', '寅时', '卯时', '辰时', '巳时', '午时', '未时', '申时', '酉时', '戌时', '亥时']
|
||||
const regions = [['河南省', '北京市', '上海市'], ['洛阳市', '郑州市', '北京市'], ['老城区', '涧西区', '西工区']]
|
||||
const hours = [
|
||||
{ name: '子时', range: '23:00-01:00' },
|
||||
{ name: '丑时', range: '01:00-03:00' },
|
||||
{ name: '寅时', range: '03:00-05:00' },
|
||||
{ name: '卯时', range: '05:00-07:00' },
|
||||
{ name: '辰时', range: '07:00-09:00' },
|
||||
{ name: '巳时', range: '09:00-11:00' },
|
||||
{ name: '午时', range: '11:00-13:00' },
|
||||
{ name: '未时', range: '13:00-15:00' },
|
||||
{ name: '申时', range: '15:00-17:00' },
|
||||
{ name: '酉时', range: '17:00-19:00' },
|
||||
{ name: '戌时', range: '19:00-21:00' },
|
||||
{ name: '亥时', range: '21:00-23:00' }
|
||||
]
|
||||
|
||||
type EditableProfile = Pick<UserProfile, 'nickname' | 'gender' | 'birthday' | 'birthHour' | 'province' | 'city' | 'district'>
|
||||
type RegionEntry = [string, string]
|
||||
|
||||
const emptyForm: EditableProfile = {
|
||||
nickname: '',
|
||||
gender: '',
|
||||
birthday: '',
|
||||
birthHour: '',
|
||||
province: '',
|
||||
city: '',
|
||||
district: ''
|
||||
}
|
||||
|
||||
const previewProfile: UserProfile = {
|
||||
id: 0,
|
||||
nickname: 'You',
|
||||
gender: '男',
|
||||
birthday: '1999-11-06',
|
||||
birthHour: '戌时',
|
||||
province: '河南省',
|
||||
city: '洛阳市',
|
||||
district: '洛龙区',
|
||||
points: 0,
|
||||
remainingEdits: 5,
|
||||
elementReport: { scores: [], favorable: '', unfavorable: '', dayMaster: '' }
|
||||
}
|
||||
|
||||
const toEditableProfile = (data: UserProfile): EditableProfile => ({
|
||||
nickname: data.nickname,
|
||||
gender: data.gender,
|
||||
birthday: data.birthday,
|
||||
birthHour: data.birthHour,
|
||||
province: data.province,
|
||||
city: data.city,
|
||||
district: data.district
|
||||
})
|
||||
|
||||
const regionEntries = (parentCode: string): RegionEntry[] => Object.entries(areaData[parentCode] || {})
|
||||
|
||||
const findCodeByName = (entries: RegionEntry[], name: string) => entries.find(([, label]) => label === name)?.[0]
|
||||
|
||||
const findRegionCodes = (profile: Pick<EditableProfile, 'province' | 'city' | 'district'>): string[] => {
|
||||
const provinces = regionEntries('86')
|
||||
const provinceCode = findCodeByName(provinces, profile.province) || provinces[0]?.[0] || ''
|
||||
const cities = regionEntries(provinceCode)
|
||||
const cityCode = findCodeByName(cities, profile.city)
|
||||
|| (profile.city === profile.province && cities.length === 1 ? cities[0]?.[0] : '')
|
||||
|| cities[0]?.[0]
|
||||
|| ''
|
||||
const districts = regionEntries(cityCode)
|
||||
const districtCode = findCodeByName(districts, profile.district) || districts[0]?.[0] || ''
|
||||
return [provinceCode, cityCode, districtCode]
|
||||
}
|
||||
|
||||
const errorMessage = (error: unknown, fallback: string) => error instanceof Error ? error.message : fallback
|
||||
|
||||
export default function ProfileEditPage() {
|
||||
const [form, setForm] = useState<Partial<UserProfile>>({})
|
||||
const [profile, setProfile] = useState<UserProfile | null>(null)
|
||||
const [form, setForm] = useState<EditableProfile>(emptyForm)
|
||||
const [avatarPreview, setAvatarPreview] = useState('')
|
||||
const [pendingAvatar, setPendingAvatar] = useState('')
|
||||
const [regionCodes, setRegionCodes] = useState<string[]>(findRegionCodes(previewProfile))
|
||||
const [avatarSheetOpen, setAvatarSheetOpen] = useState(false)
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [saving, setSaving] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
api.profile().then(setForm)
|
||||
api.profile()
|
||||
.then((data) => {
|
||||
setProfile(data)
|
||||
setForm(toEditableProfile(data))
|
||||
setRegionCodes(findRegionCodes(data))
|
||||
setAvatarPreview(resolveAssetUrl(data.avatarUrl))
|
||||
})
|
||||
.catch((error) => {
|
||||
if (process.env.TARO_ENV === 'h5') {
|
||||
setProfile(previewProfile)
|
||||
setForm(toEditableProfile(previewProfile))
|
||||
setRegionCodes(findRegionCodes(previewProfile))
|
||||
return
|
||||
}
|
||||
Taro.showToast({ title: errorMessage(error, '个人信息加载失败'), icon: 'none' })
|
||||
})
|
||||
.finally(() => setLoading(false))
|
||||
}, [])
|
||||
|
||||
const useAvatar = (filePath: string) => {
|
||||
if (!filePath) return
|
||||
setAvatarPreview(filePath)
|
||||
setPendingAvatar(filePath)
|
||||
setAvatarSheetOpen(false)
|
||||
}
|
||||
|
||||
const chooseFrom = async (sourceType: 'album' | 'camera') => {
|
||||
try {
|
||||
const result = await Taro.chooseMedia({
|
||||
count: 1,
|
||||
mediaType: ['image'],
|
||||
sourceType: [sourceType],
|
||||
sizeType: ['compressed']
|
||||
})
|
||||
useAvatar(result.tempFiles[0]?.tempFilePath || '')
|
||||
} catch (error) {
|
||||
const message = errorMessage(error, '')
|
||||
if (message && !message.toLowerCase().includes('cancel')) {
|
||||
Taro.showToast({ title: '头像选择失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const handleWechatAvatar = (event: { detail: { avatarUrl: string } }) => {
|
||||
useAvatar(event.detail.avatarUrl)
|
||||
}
|
||||
|
||||
const save = async () => {
|
||||
await api.updateProfile(form)
|
||||
Taro.showToast({ title: '已开启吉运', icon: 'none' })
|
||||
Taro.navigateBack()
|
||||
const nickname = form.nickname.trim()
|
||||
if (!nickname) {
|
||||
Taro.showToast({ title: '请输入昵称', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!form.gender || !form.birthday || !form.birthHour || !form.province || !form.city || !form.district) {
|
||||
Taro.showToast({ title: '请完整填写个人信息', icon: 'none' })
|
||||
return
|
||||
}
|
||||
setSaving(true)
|
||||
try {
|
||||
await api.updateProfile({ ...form, nickname })
|
||||
if (pendingAvatar) {
|
||||
await api.uploadAvatar(pendingAvatar)
|
||||
}
|
||||
Taro.showToast({ title: '修改成功', icon: 'success' })
|
||||
setTimeout(() => Taro.navigateBack(), 500)
|
||||
} catch (error) {
|
||||
Taro.showToast({ title: errorMessage(error, '保存失败,请重试'), icon: 'none' })
|
||||
} finally {
|
||||
setSaving(false)
|
||||
}
|
||||
}
|
||||
|
||||
const birthHour = hours.find((item) => item.name === form.birthHour) || hours[0]
|
||||
const dateParts = form.birthday ? form.birthday.split('-') : ['', '', '']
|
||||
const today = new Date().toISOString().slice(0, 10)
|
||||
const provinceEntries = regionEntries('86')
|
||||
const provinceCode = regionCodes[0] || provinceEntries[0]?.[0] || ''
|
||||
const cityEntries = regionEntries(provinceCode)
|
||||
const cityCode = regionCodes[1] || cityEntries[0]?.[0] || ''
|
||||
const districtEntries = regionEntries(cityCode)
|
||||
const districtCode = regionCodes[2] || districtEntries[0]?.[0] || ''
|
||||
const regionPickerValue = [
|
||||
Math.max(0, provinceEntries.findIndex(([code]) => code === provinceCode)),
|
||||
Math.max(0, cityEntries.findIndex(([code]) => code === cityCode)),
|
||||
Math.max(0, districtEntries.findIndex(([code]) => code === districtCode))
|
||||
]
|
||||
|
||||
const changeRegionColumn = (column: number, value: number) => {
|
||||
if (column === 0) {
|
||||
const nextProvinceCode = provinceEntries[value]?.[0] || provinceEntries[0]?.[0] || ''
|
||||
const nextCities = regionEntries(nextProvinceCode)
|
||||
const nextCityCode = nextCities[0]?.[0] || ''
|
||||
const nextDistrictCode = regionEntries(nextCityCode)[0]?.[0] || ''
|
||||
setRegionCodes([nextProvinceCode, nextCityCode, nextDistrictCode])
|
||||
return
|
||||
}
|
||||
if (column === 1) {
|
||||
const nextCityCode = cityEntries[value]?.[0] || cityEntries[0]?.[0] || ''
|
||||
setRegionCodes([provinceCode, nextCityCode, regionEntries(nextCityCode)[0]?.[0] || ''])
|
||||
return
|
||||
}
|
||||
setRegionCodes([provinceCode, cityCode, districtEntries[value]?.[0] || districtEntries[0]?.[0] || ''])
|
||||
}
|
||||
|
||||
const confirmRegion = (values: number[]) => {
|
||||
const selectedProvince = provinceEntries[values[0]] || provinceEntries[0]
|
||||
const selectedCities = regionEntries(selectedProvince?.[0] || '')
|
||||
const selectedCity = selectedCities[values[1]] || selectedCities[0]
|
||||
const selectedDistricts = regionEntries(selectedCity?.[0] || '')
|
||||
const selectedDistrict = selectedDistricts[values[2]] || selectedDistricts[0]
|
||||
if (!selectedProvince || !selectedCity || !selectedDistrict) return
|
||||
const cityName = selectedCity[1] === '市辖区' ? selectedProvince[1] : selectedCity[1]
|
||||
setRegionCodes([selectedProvince[0], selectedCity[0], selectedDistrict[0]])
|
||||
setForm({
|
||||
...form,
|
||||
province: selectedProvince[1],
|
||||
city: cityName,
|
||||
district: selectedDistrict[1]
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<View className='page edit-page'>
|
||||
<NavBar back />
|
||||
<View className='edit-avatar'>💧<Text>水</Text></View>
|
||||
<View className='name-pill'>
|
||||
<Input value={form.nickname || ''} onInput={(e) => setForm({ ...form, nickname: String(e.detail.value) })} />
|
||||
<Text>✎</Text>
|
||||
</View>
|
||||
<View className='gender-row'>
|
||||
{['男', '女'].map((gender) => (
|
||||
<Button key={gender} className='gender' onClick={() => setForm({ ...form, gender })}>
|
||||
<Text>{form.gender === gender ? '◉' : '○'}</Text>{gender}
|
||||
<View className='edit-page'>
|
||||
<NavBar title='编辑个人信息' back />
|
||||
{loading ? (
|
||||
<View className='profile-loading'>加载中...</View>
|
||||
) : (
|
||||
<View className='edit-content'>
|
||||
<Button className='avatar-button' onClick={() => setAvatarSheetOpen(true)}>
|
||||
{avatarPreview ? (
|
||||
<Image className='avatar-image' src={avatarPreview} mode='aspectFill' />
|
||||
) : (
|
||||
<View className='water-mascot'>
|
||||
<View className='mascot-eye left' />
|
||||
<View className='mascot-eye right' />
|
||||
<View className='mascot-smile' />
|
||||
</View>
|
||||
)}
|
||||
<View className='avatar-add'>
|
||||
<View className='plus-line horizontal' />
|
||||
<View className='plus-line vertical' />
|
||||
</View>
|
||||
</Button>
|
||||
))}
|
||||
</View>
|
||||
<Text className='section-title'>选择你的出生日期(公历)</Text>
|
||||
<Picker mode='date' value={form.birthday} onChange={(e) => setForm({ ...form, birthday: String(e.detail.value) })}>
|
||||
<View className='date-row'>
|
||||
{(form.birthday || '2008-12-28').split('-').map((part, idx) => (
|
||||
<View className='input-pill date-part' key={idx}>{part}</View>
|
||||
))}
|
||||
|
||||
<View className='form-card nickname-card'>
|
||||
<Text className='field-label'>昵称</Text>
|
||||
<Input
|
||||
className='nickname-input'
|
||||
value={form.nickname}
|
||||
maxlength={20}
|
||||
placeholder='请输入昵称'
|
||||
onInput={(event) => setForm({ ...form, nickname: String(event.detail.value) })}
|
||||
/>
|
||||
<Text className='nickname-count'>{form.nickname.length}/20</Text>
|
||||
</View>
|
||||
|
||||
<View className='gender-row'>
|
||||
{[
|
||||
{ value: '男', symbol: '♂' },
|
||||
{ value: '女', symbol: '♀' }
|
||||
].map((item) => (
|
||||
<Button
|
||||
key={item.value}
|
||||
className={`gender-option ${form.gender === item.value ? 'active' : ''}`}
|
||||
onClick={() => setForm({ ...form, gender: item.value })}
|
||||
>
|
||||
<Text className='gender-symbol'>{item.symbol}</Text>
|
||||
<Text>{item.value}生</Text>
|
||||
</Button>
|
||||
))}
|
||||
</View>
|
||||
|
||||
<Picker className='form-picker' mode='date' value={form.birthday} end={today} onChange={(event) => setForm({ ...form, birthday: String(event.detail.value) })}>
|
||||
<View className='form-card picker-card'>
|
||||
<Text className='field-label'>出生日期</Text>
|
||||
<Text className={`field-value ${form.birthday ? '' : 'placeholder'}`}>
|
||||
{form.birthday ? `${dateParts[0]} 年 ${dateParts[1]} 月 ${dateParts[2]} 日` : '请选择'}
|
||||
</Text>
|
||||
<Text className='chevron'>›</Text>
|
||||
</View>
|
||||
</Picker>
|
||||
|
||||
<Picker
|
||||
className='form-picker'
|
||||
mode='selector'
|
||||
range={hours.map((item) => `${item.name}(${item.range})`)}
|
||||
value={Math.max(0, hours.findIndex((item) => item.name === form.birthHour))}
|
||||
onChange={(event) => setForm({ ...form, birthHour: hours[Number(event.detail.value)].name })}
|
||||
>
|
||||
<View className='form-card picker-card'>
|
||||
<Text className='field-label'>出生时辰</Text>
|
||||
<Text className={`field-value ${form.birthHour ? '' : 'placeholder'}`}>
|
||||
{form.birthHour ? `${birthHour.name}(${birthHour.range})` : '请选择'}
|
||||
</Text>
|
||||
<Text className='chevron'>›</Text>
|
||||
</View>
|
||||
</Picker>
|
||||
|
||||
<Picker
|
||||
className='form-picker'
|
||||
mode='multiSelector'
|
||||
range={[
|
||||
provinceEntries.map(([, name]) => name),
|
||||
cityEntries.map(([, name]) => name === '市辖区' ? form.province || '市辖区' : name),
|
||||
districtEntries.map(([, name]) => name)
|
||||
]}
|
||||
value={regionPickerValue}
|
||||
onColumnChange={(event) => changeRegionColumn(Number(event.detail.column), Number(event.detail.value))}
|
||||
onCancel={() => setRegionCodes(findRegionCodes(form))}
|
||||
onChange={(event) => confirmRegion(event.detail.value as number[])}
|
||||
>
|
||||
<View className='form-card picker-card'>
|
||||
<Text className='field-label'>出生地点</Text>
|
||||
<Text className={`field-value location ${form.province ? '' : 'placeholder'}`}>
|
||||
{form.province ? `${form.province} - ${form.city} - ${form.district}` : '请选择'}
|
||||
</Text>
|
||||
<Text className='chevron'>›</Text>
|
||||
</View>
|
||||
</Picker>
|
||||
|
||||
<Button className='save-button' loading={saving} disabled={saving || !profile} onClick={save}>保存修改</Button>
|
||||
<Text className='edit-note'>半年内只能修改<Text>{profile?.remainingEdits ?? 0}</Text>次哦</Text>
|
||||
</View>
|
||||
</Picker>
|
||||
<Picker mode='selector' range={hours} value={Math.max(0, hours.indexOf(form.birthHour || '寅时'))} onChange={(e) => setForm({ ...form, birthHour: hours[Number(e.detail.value)] })}>
|
||||
<View className='input-pill hour'>{form.birthHour || '寅时'}<Text> 时</Text></View>
|
||||
</Picker>
|
||||
<Text className='section-title'>选择你的出生地</Text>
|
||||
<Picker
|
||||
mode='multiSelector'
|
||||
range={regions}
|
||||
value={[
|
||||
Math.max(0, regions[0].indexOf(form.province || '河南省')),
|
||||
Math.max(0, regions[1].indexOf(form.city || '洛阳市')),
|
||||
Math.max(0, regions[2].indexOf(form.district || '老城区'))
|
||||
]}
|
||||
onChange={(e) => {
|
||||
const values = e.detail.value as number[]
|
||||
setForm({ ...form, province: regions[0][values[0]], city: regions[1][values[1]], district: regions[2][values[2]] })
|
||||
}}
|
||||
>
|
||||
<View className='region-row'>
|
||||
<View className='input-pill'>{form.province || '河南省'} ▼</View>
|
||||
<View className='input-pill'>{form.city || '洛阳市'} ▼</View>
|
||||
<View className='input-pill'>{form.district || '老城区'} ▼</View>
|
||||
)}
|
||||
|
||||
{avatarSheetOpen && (
|
||||
<View className='avatar-mask' onClick={() => setAvatarSheetOpen(false)}>
|
||||
<View className='avatar-sheet' onClick={(event) => event.stopPropagation()}>
|
||||
<Button className='avatar-action wechat-avatar-action' openType='chooseAvatar' onChooseAvatar={handleWechatAvatar}>
|
||||
<Text>用微信头像</Text>
|
||||
{avatarPreview && <Image className='wechat-avatar-preview' src={avatarPreview} mode='aspectFill' />}
|
||||
</Button>
|
||||
<Button className='avatar-action' onClick={() => chooseFrom('album')}>从相册选择</Button>
|
||||
<Button className='avatar-action' onClick={() => chooseFrom('camera')}>拍照</Button>
|
||||
<View className='sheet-gap' />
|
||||
<Button className='avatar-action cancel-action' onClick={() => setAvatarSheetOpen(false)}>取消</Button>
|
||||
</View>
|
||||
</View>
|
||||
</Picker>
|
||||
<Button className='gold-button start-button' onClick={save}>开启吉运</Button>
|
||||
<Text className='edit-note'>半年内只能修改五次哦</Text>
|
||||
)}
|
||||
</View>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import type { UserProfile } from './request'
|
||||
|
||||
export function isFrontendPreview(): boolean {
|
||||
return process.env.TARO_ENV === 'h5'
|
||||
&& typeof window !== 'undefined'
|
||||
&& new URLSearchParams(window.location.search).get('preview') === '1'
|
||||
}
|
||||
|
||||
export const frontendPreviewProfile: UserProfile = {
|
||||
id: 0,
|
||||
nickname: 'You',
|
||||
gender: '男',
|
||||
birthday: '1998-06-18',
|
||||
birthHour: '辰时',
|
||||
province: '河南省',
|
||||
city: '洛阳市',
|
||||
district: '洛龙区',
|
||||
points: 0,
|
||||
remainingEdits: 5,
|
||||
elementReport: { scores: [], favorable: '', unfavorable: '', dayMaster: '' }
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import Taro from '@tarojs/taro'
|
||||
import { frontendPreviewProfile, isFrontendPreview } from './frontendPreview'
|
||||
|
||||
const BASE_URL = 'http://localhost:8080'
|
||||
|
||||
@@ -11,6 +12,12 @@ type ApiResult<T> = {
|
||||
type RequestOptions = Omit<Taro.request.Option, 'url'>
|
||||
|
||||
export async function request<T>(url: string, options: RequestOptions = {}): Promise<T> {
|
||||
if (isFrontendPreview()) {
|
||||
if (url === '/api/user/profile' && (!options.method || options.method === 'GET')) {
|
||||
return { ...frontendPreviewProfile, elementReport: { ...frontendPreviewProfile.elementReport, scores: [] } } as T
|
||||
}
|
||||
throw new Error('纯前端预览暂不请求后端或保存修改')
|
||||
}
|
||||
const token = Taro.getStorageSync('token')
|
||||
const headers = {
|
||||
'content-type': 'application/json',
|
||||
@@ -28,6 +35,34 @@ export async function request<T>(url: string, options: RequestOptions = {}): Pro
|
||||
return res.data.data
|
||||
}
|
||||
|
||||
export function resolveAssetUrl(url?: string) {
|
||||
if (!url) return ''
|
||||
return /^https?:\/\//.test(url) || url.startsWith('wxfile://') || url.startsWith('http://tmp/')
|
||||
? url
|
||||
: `${BASE_URL}${url.startsWith('/') ? url : `/${url}`}`
|
||||
}
|
||||
|
||||
async function uploadAvatar(filePath: string): Promise<UserProfile> {
|
||||
if (isFrontendPreview()) throw new Error('纯前端预览暂不上传头像或保存修改')
|
||||
const token = Taro.getStorageSync('token')
|
||||
const response = await Taro.uploadFile({
|
||||
url: `${BASE_URL}/api/user/avatar`,
|
||||
filePath,
|
||||
name: 'file',
|
||||
header: token ? { Authorization: `Bearer ${token}` } : {}
|
||||
})
|
||||
let result: ApiResult<UserProfile>
|
||||
try {
|
||||
result = JSON.parse(response.data) as ApiResult<UserProfile>
|
||||
} catch (error) {
|
||||
throw new Error('头像上传失败')
|
||||
}
|
||||
if (result.code !== 0) {
|
||||
throw new Error(result.message || '头像上传失败')
|
||||
}
|
||||
return result.data
|
||||
}
|
||||
|
||||
export const api = {
|
||||
wxLogin: (code: string) => request<{ sessionKey: string; phoneBound: boolean }>('/api/auth/wx-login', {
|
||||
method: 'POST',
|
||||
@@ -46,6 +81,7 @@ export const api = {
|
||||
method: 'PUT',
|
||||
data
|
||||
}),
|
||||
uploadAvatar,
|
||||
exchangeStatus: () => request<{ points: number; available: boolean; message: string }>('/api/points/exchange-status'),
|
||||
agreement: (type: string) => request<{ title: string; body: string }>(`/api/content/agreement/${type}`),
|
||||
follow: () => request<Record<string, string>>('/api/content/follow'),
|
||||
@@ -66,6 +102,7 @@ export type ElementScore = {
|
||||
|
||||
export type UserProfile = {
|
||||
id: number
|
||||
avatarUrl?: string
|
||||
nickname: string
|
||||
phone?: string
|
||||
gender: string
|
||||
|
||||
@@ -7,3 +7,8 @@ declare module '*.png' {
|
||||
const src: string
|
||||
export default src
|
||||
}
|
||||
|
||||
declare module 'china-area-data' {
|
||||
const data: Record<string, Record<string, string>>
|
||||
export default data
|
||||
}
|
||||
@@ -1,90 +1,158 @@
|
||||
import { Solar } from 'lunar-typescript'
|
||||
import { ElementScore } from '../services/request'
|
||||
|
||||
type ElementName = '木' | '火' | '土' | '金' | '水'
|
||||
import { LunarUtil, Solar } from 'lunar-typescript'
|
||||
import type { ElementScore } from '../services/request'
|
||||
|
||||
export type ElementName = '木' | '火' | '土' | '金' | '水'
|
||||
export type Pillars = [string, string, string, string]
|
||||
export type FiveElementReport = {
|
||||
scores: ElementScore[]
|
||||
favorable: string
|
||||
unfavorable: string
|
||||
dayMaster: string
|
||||
masterElement: ElementName
|
||||
pillars: Pillars
|
||||
strength: '偏弱' | '相对平衡' | '偏强'
|
||||
strengthScore: number
|
||||
analysis: {
|
||||
season: { supported: boolean; score: number; description: string }
|
||||
roots: { supported: boolean; score: number; description: string }
|
||||
support: { supported: boolean; score: number; description: string }
|
||||
}
|
||||
}
|
||||
|
||||
const stemElements: Record<string, ElementName> = {
|
||||
const stems: Record<string, ElementName> = {
|
||||
甲: '木', 乙: '木', 丙: '火', 丁: '火', 戊: '土', 己: '土', 庚: '金', 辛: '金', 壬: '水', 癸: '水'
|
||||
}
|
||||
|
||||
const branchElements: Record<string, ElementName> = {
|
||||
子: '水', 丑: '土', 寅: '木', 卯: '木', 辰: '土', 巳: '火', 午: '火', 未: '土', 申: '金', 酉: '金', 戌: '土', 亥: '水'
|
||||
}
|
||||
|
||||
const elementMeta: Record<ElementName, { color: string }> = {
|
||||
木: { color: '#36b85b' },
|
||||
火: { color: '#ef5a58' },
|
||||
土: { color: '#b46a18' },
|
||||
金: { color: '#d59a05' },
|
||||
水: { color: '#35bfe8' }
|
||||
const colors: Record<ElementName, string> = {
|
||||
木: '#36b85b', 火: '#ef5a58', 土: '#b46a18', 金: '#d59a05', 水: '#35bfe8'
|
||||
}
|
||||
|
||||
const scoreOrder: ElementName[] = ['土', '金', '水', '木', '火']
|
||||
const generationOrder: ElementName[] = ['木', '火', '土', '金', '水']
|
||||
const cycle: ElementName[] = ['木', '火', '土', '金', '水']
|
||||
const emptyWeights = (): Record<ElementName, number> => ({ 木: 0, 火: 0, 土: 0, 金: 0, 水: 0 })
|
||||
|
||||
const hourFromBirthHour = (birthHour: string) => {
|
||||
const numericHour = Number.parseInt(birthHour, 10)
|
||||
if (Number.isFinite(numericHour)) return Math.max(0, Math.min(23, numericHour))
|
||||
|
||||
const branchHours: Record<string, number> = {
|
||||
子: 23, 丑: 1, 寅: 3, 卯: 5, 辰: 7, 巳: 9,
|
||||
午: 11, 未: 13, 申: 15, 酉: 17, 戌: 19, 亥: 21
|
||||
}
|
||||
return branchHours[birthHour.slice(0, 1)] ?? 12
|
||||
// 本项目普通扶抑规则 v1,权重为产品约定,不代表各命理流派的统一标准。
|
||||
// 月令:旺/相/休/囚/死分别取 100/80/50/30/15 分,辰戌丑未按土月简化。
|
||||
const seasonScore = (element: ElementName, season: ElementName) => {
|
||||
const relation = (cycle.indexOf(element) - cycle.indexOf(season) + 5) % 5
|
||||
return [100, 80, 15, 30, 50][relation]
|
||||
}
|
||||
|
||||
export function calculateFiveElements(birthday: string, birthHour: string): FiveElementReport {
|
||||
const date = new Date(`${birthday}T00:00:00`)
|
||||
if (Number.isNaN(date.getTime())) {
|
||||
return {
|
||||
scores: scoreOrder.map((name) => ({ name, color: elementMeta[name].color, value: 20 })),
|
||||
favorable: '金水',
|
||||
unfavorable: '木火土',
|
||||
dayMaster: '壬'
|
||||
}
|
||||
const hiddenStems = (branch: string): Array<{ stem: string; share: number }> => {
|
||||
const hidden = LunarUtil.ZHI_HIDE_GAN[branch] || []
|
||||
const shares = hidden.length === 1 ? [1] : hidden.length === 2 ? [0.7, 0.3] : [0.6, 0.3, 0.1]
|
||||
return hidden.map((stem, index) => ({ stem, share: shares[index] }))
|
||||
}
|
||||
|
||||
// 最大余数法保证展示百分比之和为 100,零值仍保持为零。
|
||||
const toScores = (weights: Record<ElementName, number>): ElementScore[] => {
|
||||
const total = Object.values(weights).reduce((sum, value) => sum + value, 0)
|
||||
const entries = scoreOrder.map((name) => {
|
||||
const exact = weights[name] / total * 100
|
||||
return { name, value: Math.floor(exact), remainder: exact - Math.floor(exact) }
|
||||
})
|
||||
const remaining = 100 - entries.reduce((sum, item) => sum + item.value, 0)
|
||||
const ranked = [...entries].sort((a, b) => b.remainder - a.remainder)
|
||||
for (let index = 0; index < remaining; index++) ranked[index].value++
|
||||
return entries.map(({ name, value }) => ({ name, value, color: colors[name] }))
|
||||
}
|
||||
|
||||
export function analyzePillars(pillars: Pillars): FiveElementReport {
|
||||
if (pillars.some((pillar) => pillar.length !== 2 || !stems[pillar[0]] || !branchElements[pillar[1]])) {
|
||||
throw new Error('四柱数据不完整')
|
||||
}
|
||||
const dayMaster = pillars[2][0]
|
||||
const masterElement = stems[dayMaster]
|
||||
const masterIndex = cycle.indexOf(masterElement)
|
||||
const resource = cycle[(masterIndex + 4) % 5]
|
||||
const season = branchElements[pillars[1][1]]
|
||||
const weights = emptyWeights()
|
||||
const surrounding = emptyWeights()
|
||||
let rootPower = 0
|
||||
const rootBranches: string[] = []
|
||||
|
||||
const solar = Solar.fromYmdHms(
|
||||
date.getFullYear(),
|
||||
date.getMonth() + 1,
|
||||
date.getDate(),
|
||||
hourFromBirthHour(birthHour),
|
||||
0,
|
||||
0
|
||||
)
|
||||
const eightChar = solar.getLunar().getEightChar()
|
||||
const pillars = [eightChar.getYear(), eightChar.getMonth(), eightChar.getDay(), eightChar.getTime()]
|
||||
const weights: Record<ElementName, number> = { 木: 0, 火: 0, 土: 0, 金: 0, 水: 0 }
|
||||
|
||||
pillars.forEach((pillar) => {
|
||||
const [stem, branch] = pillar
|
||||
if (stemElements[stem]) weights[stemElements[stem]] += 2
|
||||
if (branchElements[branch]) weights[branchElements[branch]] += 1
|
||||
pillars.forEach((pillar, index) => {
|
||||
const stemElement = stems[pillar[0]]
|
||||
weights[stemElement] += 10
|
||||
// 得势不把日干自身计入生扶比例,避免自己支持自己的循环判断。
|
||||
if (index !== 2) surrounding[stemElement] += 10
|
||||
const branchWeight = index === 1 ? 18 : 10
|
||||
const hidden = hiddenStems(pillar[1])
|
||||
const roots = hidden.filter(({ stem }) => stems[stem] === masterElement)
|
||||
if (roots.length) rootBranches.push(pillar[1])
|
||||
rootPower += roots.reduce((sum, { share }) => sum + share, 0)
|
||||
hidden.forEach(({ stem, share }) => {
|
||||
weights[stems[stem]] += branchWeight * share
|
||||
surrounding[stems[stem]] += branchWeight * share
|
||||
})
|
||||
})
|
||||
|
||||
const total = Object.values(weights).reduce((sum, value) => sum + value, 0)
|
||||
const scores = scoreOrder.map((name) => ({
|
||||
name,
|
||||
color: elementMeta[name].color,
|
||||
value: Math.round((weights[name] / total) * 100)
|
||||
}))
|
||||
const dayMaster = eightChar.getDay().slice(0, 1)
|
||||
const masterElement = stemElements[dayMaster] || '水'
|
||||
const masterIndex = generationOrder.indexOf(masterElement)
|
||||
const resourceElement = generationOrder[(masterIndex + generationOrder.length - 1) % generationOrder.length]
|
||||
const unfavorable = generationOrder.filter((element) => element !== resourceElement && element !== masterElement).join('')
|
||||
const seasonValue = seasonScore(masterElement, season)
|
||||
// 两个完整同类根视为根气充分;藏干按 1、7:3 或 6:3:1 分配根气。
|
||||
const rootValue = Math.min(100, rootPower / 2 * 100)
|
||||
const surroundingTotal = Object.values(surrounding).reduce((sum, value) => sum + value, 0)
|
||||
const supportValue = (surrounding[masterElement] + surrounding[resource]) / surroundingTotal * 100
|
||||
const strengthScore = Math.round(seasonValue * 0.4 + rootValue * 0.3 + supportValue * 0.3)
|
||||
const strength = strengthScore < 45 ? '偏弱' : strengthScore > 55 ? '偏强' : '相对平衡'
|
||||
const favorable = strength === '偏弱'
|
||||
? `${resource}${masterElement}`
|
||||
: strength === '偏强'
|
||||
? [cycle[(masterIndex + 1) % 5], cycle[(masterIndex + 2) % 5], cycle[(masterIndex + 3) % 5]].join('')
|
||||
: ''
|
||||
const unfavorable = strength === '相对平衡' ? '' : cycle.filter((element) => !favorable.includes(element)).join('')
|
||||
|
||||
return {
|
||||
scores,
|
||||
favorable: `${resourceElement}${masterElement}`,
|
||||
unfavorable,
|
||||
dayMaster
|
||||
scores: toScores(weights), favorable, unfavorable, dayMaster, masterElement, pillars,
|
||||
strength, strengthScore,
|
||||
analysis: {
|
||||
season: {
|
||||
supported: seasonValue >= 80,
|
||||
score: seasonValue,
|
||||
description: `${pillars[1][1]}月按${season}气判断,${masterElement}${seasonValue >= 80 ? '得到月令支持' : '月令支持较少'}。`
|
||||
},
|
||||
roots: {
|
||||
supported: rootPower > 0,
|
||||
score: Math.round(rootValue),
|
||||
description: rootBranches.length
|
||||
? `四支中${rootBranches.join('、')}的藏干有${masterElement}根,根气评分${Math.round(rootValue)}。`
|
||||
: `四支藏干未见${masterElement}同类根。`
|
||||
},
|
||||
support: {
|
||||
supported: supportValue >= 50,
|
||||
score: Math.round(supportValue),
|
||||
description: `除日干外,${resource}与${masterElement}的生扶力量占${Math.round(supportValue)}%。`
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const hourFromBirthHour = (birthHour: string): number | null => {
|
||||
const branchHours: Record<string, number> = {
|
||||
子: 23, 丑: 1, 寅: 3, 卯: 5, 辰: 7, 巳: 9, 午: 11, 未: 13, 申: 15, 酉: 17, 戌: 19, 亥: 21
|
||||
}
|
||||
if (Object.prototype.hasOwnProperty.call(branchHours, birthHour)) return branchHours[birthHour]
|
||||
if (/^[子丑寅卯辰巳午未申酉戌亥]时$/.test(birthHour)) return branchHours[birthHour[0]]
|
||||
if (/^\d{1,2}$/.test(birthHour)) {
|
||||
const hour = Number(birthHour)
|
||||
return hour <= 23 ? hour : null
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
export function calculateFiveElements(birthday: string, birthHour: string): FiveElementReport | null {
|
||||
if (!/^\d{4}-\d{2}-\d{2}$/.test(birthday || '')) return null
|
||||
const [year, month, day] = birthday.split('-').map(Number)
|
||||
const hour = hourFromBirthHour(birthHour || '')
|
||||
if (hour === null || year < 1900 || year > 2100 || month < 1 || month > 12 || day < 1) return null
|
||||
const daysInMonth = new Date(Date.UTC(year, month, 0)).getUTCDate()
|
||||
if (day > daysInMonth) return null
|
||||
try {
|
||||
// 直接使用公历字段,避免浏览器时区/日期字符串解析影响结果。
|
||||
const eightChar = Solar.fromYmdHms(year, month, day, hour, 0, 0).getLunar().getEightChar()
|
||||
eightChar.setSect(2) // 沿用历法库默认:子初不换日,日柱按零点换日。
|
||||
return analyzePillars([eightChar.getYear(), eightChar.getMonth(), eightChar.getDay(), eightChar.getTime()])
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
import { Solar } from 'lunar-typescript'
|
||||
import type { DimensionItem, HomeOverview, UserProfile } from '../services/request'
|
||||
import { calculateFiveElements, ElementName, FiveElementReport } from './fiveElements'
|
||||
import { calculateZodiac, zodiacNames } from './zodiac'
|
||||
import { getZodiacRelation } from './zodiacWeekly'
|
||||
|
||||
type DimensionId = 'emotion' | 'health' | 'life' | 'wealth' | 'social' | 'study' | 'career' | 'travel'
|
||||
type DimensionDefinition = { id: DimensionId; title: string; icon: string; element: ElementName; activities: string[]; positive: [string, string][]; cautious: [string, string][] }
|
||||
export type GeneratedDimension = DimensionItem & { score: number }
|
||||
export type GeneratedHomeOverview = Omit<HomeOverview, 'dimensions'> & { dimensions: GeneratedDimension[] }
|
||||
const cycle: ElementName[] = ['木', '火', '土', '金', '水']
|
||||
const stems: Record<string, ElementName> = { 甲: '木', 乙: '木', 丙: '火', 丁: '火', 戊: '土', 己: '土', 庚: '金', 辛: '金', 壬: '水', 癸: '水' }
|
||||
const branches = [...'子丑寅卯辰巳午未申酉戌亥']
|
||||
const relationPoints = { 六合: 2, 三合: 1, 六冲: -2, 相害: -1, 平常: 0 }
|
||||
const definitions: DimensionDefinition[] = [
|
||||
{ id: 'emotion', title: '情感', icon: 'heart', element: '火', activities: ['嫁娶', '订盟', '纳采'],
|
||||
positive: [['默契收集,认真倾听', '留一点时间给在意的人,认真听完对方的话,也表达自己的感受。'], ['温柔表达,分享日常', '从一件小事聊起,让轻松的分享成为彼此理解的机会。']],
|
||||
cautious: [['放慢表达,少些猜测', '遇到分歧先确认对方的意思,避免用猜测代替沟通。'], ['留出空间,不急回应', '不必急着为关系下结论,先整理感受,再选择合适的表达方式。']] },
|
||||
{ id: 'health', title: '健康', icon: 'gourd', element: '木', activities: ['沐浴', '解除'],
|
||||
positive: [['留白休息,照顾节奏', '给日程留出休息空隙,选择让自己感到舒适的活动。'], ['规律作息,轻松生活', '合理安排工作与休息,用平常心照顾自己的日常节奏。']],
|
||||
cautious: [['减少透支,适度休息', '行程尽量安排宽松一些,避免为了赶进度不断压缩休息。'], ['放下紧绷,量力而行', '适当减少不必要的忙碌,不用勉强自己完成所有安排。']] },
|
||||
{ id: 'life', title: '生活', icon: 'vase', element: '土', activities: ['入宅', '移徙', '安床', '扫舍', '修造'],
|
||||
positive: [['整理日常,留住从容', '从一处小空间开始整理,为生活腾出一点轻松与秩序。'], ['收纳旧物,珍惜日常', '梳理身边物品,留下真正需要和喜欢的部分,不必一次完成。']],
|
||||
cautious: [['少些堆叠,做好取舍', '先处理手头的小事,避免同时开启太多整理或采购计划。'], ['简化安排,稳住节奏', '把复杂的家务拆成小步骤,逐项完成比匆忙赶工更从容。']] },
|
||||
{ id: 'wealth', title: '财富', icon: 'coin', element: '金', activities: ['交易', '纳财', '开市', '立券'],
|
||||
positive: [['梳理预算,按需安排', '核对日常收支和购物清单,让消费围绕实际需求展开。'], ['清点账目,有序消费', '整理订阅与账单,关注自己真正会使用的物品和服务。']],
|
||||
cautious: [['勿乱囤货,按需消费', '面对促销先看清需求与总价,给非必要购买留一点考虑时间。'], ['核对清单,避免冲动', '先确认已有物品和预算,再决定是否添置,不急于跟随热度。']] },
|
||||
{ id: 'social', title: '社交', icon: 'fan', element: '火', activities: ['会亲友', '宴会', '订盟'],
|
||||
positive: [['友好交流,真诚回应', '把注意力放在真诚的交流上,适时表达感谢与关心。'], ['主动问候,轻松相聚', '选择让双方都舒适的话题和时间,为相处保留自然的空间。']],
|
||||
cautious: [['勿涉纷争,尊重边界', '不必急着评判他人的是非,先确认事实,保持清楚的边界。'], ['少些争辩,多些理解', '意见不同时可以暂缓讨论,不让一时的情绪替自己作答。']] },
|
||||
{ id: 'study', title: '学业', icon: 'scroll', element: '水', activities: ['入学', '习艺'],
|
||||
positive: [['专注积累,温故知新', '挑选一个清晰的小目标,结合复习和练习检验理解。'], ['循序探索,整理笔记', '把新知识与已有内容连起来,留下自己的问题与总结。']],
|
||||
cautious: [['回到基础,不急跳级', '遇到难点先检查基础概念,不用靠加快进度掩盖疑问。'], ['减少分心,逐项练习', '收起暂时无关的信息,把注意力留给眼前的一项学习任务。']] },
|
||||
{ id: 'career', title: '事业', icon: 'bamboo', element: '木', activities: ['赴任', '开市', '立券'],
|
||||
positive: [['清晰协作,稳步推进', '先对齐目标和分工,再推进关键任务,为沟通留足时间。'], ['认真落实,积累进展', '聚焦一项可以交付的小成果,让行动形成清晰的进度。']],
|
||||
cautious: [['认真核对,避免敷衍', '提交前检查要求和细节,遇到不明确的地方及时确认。'], ['收拢任务,先稳后快', '把任务按轻重缓急排好,避免为了同时推进而忽略细节。']] },
|
||||
{ id: 'travel', title: '出行', icon: 'horse', element: '水', activities: ['出行', '移徙'],
|
||||
positive: [['轻装安排,从容出发', '提前整理路线和随身物品,为换乘与休息留出余地。'], ['规划路线,享受沿途', '出发前确认时间与目的地,选择适合自己节奏的行程。']],
|
||||
cautious: [['勿负重行,检查安排', '精简随身物品,出发前再次确认路线、时间和必要证件。'], ['留足余量,不必赶路', '为临时调整留出时间,行程有变化时先重新确认安排。']] }
|
||||
]
|
||||
export const HOME_DIMENSION_IDS = definitions.map((item) => item.id)
|
||||
|
||||
export function normalizeDimensionOrder(value: unknown): string[] {
|
||||
const saved = Array.isArray(value) ? value.filter((id): id is DimensionId => HOME_DIMENSION_IDS.includes(id)) : []
|
||||
return [...new Set([...saved, ...HOME_DIMENSION_IDS])]
|
||||
}
|
||||
|
||||
const palette: Record<ElementName, { colors: { name: string; value: string }[]; numbers: string[] }> = {
|
||||
木: { colors: [{ name: '青竹绿', value: '#9fbb81' }, { name: '绿茶色', value: '#a7ad42' }], numbers: ['3', '8'] },
|
||||
火: { colors: [{ name: '珊瑚粉', value: '#ef9ca1' }, { name: '暖橘色', value: '#edaf73' }], numbers: ['2', '7'] },
|
||||
土: { colors: [{ name: '暖杏色', value: '#eac58e' }, { name: '麦芽色', value: '#d6b887' }], numbers: ['5', '0'] },
|
||||
金: { colors: [{ name: '月白色', value: '#f4eede' }, { name: '浅金色', value: '#e8d5a7' }], numbers: ['4', '9'] },
|
||||
水: { colors: [{ name: '瀑布蓝', value: '#58bfce' }, { name: '雾霭蓝', value: '#8eb4d6' }], numbers: ['1', '6'] }
|
||||
}
|
||||
|
||||
function elementSupport(source: ElementName, target: ElementName): number {
|
||||
const delta = (cycle.indexOf(target) - cycle.indexOf(source) + 5) % 5
|
||||
return delta === 0 || delta === 1 ? 6 : delta === 2 ? -6 : 0
|
||||
}
|
||||
const preference = (report: FiveElementReport, element: ElementName, weight: number) => {
|
||||
const share = report.scores.find((score) => score.name === element)?.value || 0
|
||||
// 先由扶抑确定方向,再在该方向内按个人五行份额小幅调整;不是缺什么就补什么。
|
||||
if (report.favorable.includes(element)) return weight + Math.round(Math.max(0, 20 - share) / 5)
|
||||
if (report.unfavorable.includes(element)) return -weight - Math.round(Math.max(0, share - 20) / 5)
|
||||
return 0
|
||||
}
|
||||
const clamp = (value: number) => Math.min(90, Math.max(15, value))
|
||||
const statusFor = (score: number) => score >= 80 ? '大吉' : score >= 65 ? '小吉' : score >= 50 ? '平日' : score >= 35 ? '小逆' : '谨慎'
|
||||
const formatHourEnd = (end: string) => {
|
||||
const [hour, minute] = end.split(':').map(Number)
|
||||
const total = hour * 60 + minute + 1
|
||||
return `${String(Math.floor(total / 60)).padStart(2, '0')}:${String(total % 60).padStart(2, '0')}`
|
||||
}
|
||||
|
||||
function calculateDay(solar: Solar, report: FiveElementReport, birthBranch: string) {
|
||||
const lunar = solar.getLunar()
|
||||
const dayElement = stems[lunar.getDayGan()]
|
||||
const relation = getZodiacRelation(birthBranch, lunar.getDayZhi())
|
||||
const commonScore = 50 + preference(report, dayElement, 10) + relationPoints[relation] * 5
|
||||
const yi = lunar.getDayYi()
|
||||
const ji = lunar.getDayJi()
|
||||
const dimensions: GeneratedDimension[] = definitions.map((definition) => {
|
||||
const discouraged = definition.activities.some((activity) => ji.includes(activity))
|
||||
const encouraged = definition.activities.some((activity) => yi.includes(activity))
|
||||
const calendarPoints = discouraged ? -10 : encouraged ? 10 : 0
|
||||
const score = clamp(commonScore + preference(report, definition.element, 8) + elementSupport(dayElement, definition.element) + calendarPoints)
|
||||
const suitable = score >= 50
|
||||
const variants = suitable ? definition.positive : definition.cautious
|
||||
const [headline, detail] = variants[lunar.getDayGanIndex() % variants.length]
|
||||
return { id: definition.id, title: definition.title, icon: definition.icon, headline, detail, suitable, score }
|
||||
})
|
||||
const overallIndex = Math.round(dimensions.reduce((sum, item) => sum + item.score, 0) / dimensions.length)
|
||||
const ranked = [...dimensions].sort((a, b) => b.score - a.score)
|
||||
const status = statusFor(overallIndex)
|
||||
const summary = ranked[0].score === ranked[ranked.length - 1].score
|
||||
? `${status}之日,节奏相对均衡,按计划推进,也给自己留出余地。`
|
||||
: `${status}之日,可关注${ranked[0].title}安排,${ranked[ranked.length - 1].title}方面多留意细节。`
|
||||
|
||||
const preferred = report.favorable
|
||||
? [...report.favorable] as ElementName[]
|
||||
: [...report.scores].sort((a, b) => a.value - b.value).slice(0, 2).map((score) => score.name as ElementName)
|
||||
const luckyElements = [...preferred].sort((a, b) => elementSupport(dayElement, b) - elementSupport(dayElement, a)).slice(0, 2)
|
||||
const alternate = lunar.getDayGanIndex() % 2
|
||||
const luckyColors = luckyElements.map((element) => palette[element].colors[alternate])
|
||||
const luckyNumbers = luckyElements.map((element) => palette[element].numbers[lunar.getDayZhiIndex() % 2])
|
||||
const hours = lunar.getTimes()
|
||||
.map((hour, index) => ({ hour, index, score: preference(report, stems[hour.getGan()], 2) + relationPoints[getZodiacRelation(birthBranch, hour.getZhi())] }))
|
||||
.filter(({ hour }) => hour.getTianShenLuck() === '吉')
|
||||
.sort((a, b) => b.score - a.score || a.index - b.index)
|
||||
const seen = new Set<string>()
|
||||
const luckyHours = hours.filter(({ hour }) => {
|
||||
if (seen.has(hour.getZhi())) return false
|
||||
seen.add(hour.getZhi())
|
||||
return true
|
||||
}).slice(0, 2).map(({ hour }) => ({ branch: hour.getZhi(), time: `${hour.getMinHm()}–${formatHourEnd(hour.getMaxHm())}` }))
|
||||
return {
|
||||
date: solar.toYmd(), weekName: `星期${'日一二三四五六'[solar.getWeek()]}`,
|
||||
lunarDate: `农历${lunar.getYearInGanZhi()}年 ${lunar.getMonthInChinese()}月${lunar.getDayInChinese()}`,
|
||||
status, summary, overallIndex, luckyColors, luckyNumbers, luckyDirection: lunar.getDayPositionXiDesc(), luckyHours, dimensions
|
||||
}
|
||||
}
|
||||
|
||||
export function generateHomeOverview(profile: Pick<UserProfile, 'birthday' | 'birthHour'>, today: string, offset: -1 | 0 | 1 = 0): GeneratedHomeOverview | null {
|
||||
const report = calculateFiveElements(profile.birthday, profile.birthHour)
|
||||
const zodiac = calculateZodiac(profile.birthday)
|
||||
if (!report || !zodiac || !/^\d{4}-\d{2}-\d{2}$/.test(today)) return null
|
||||
const [year, month, day] = today.split('-').map(Number)
|
||||
if (year < 1900 || year > 2100 || month < 1 || month > 12 || day < 1 || day > new Date(Date.UTC(year, month, 0)).getUTCDate()) return null
|
||||
if (![-1, 0, 1].includes(offset)) return null
|
||||
try {
|
||||
const base = Solar.fromYmd(year, month, day)
|
||||
const birthBranch = branches[zodiacNames.indexOf(zodiac)]
|
||||
const reports = [-1, 0, 1].map((index) => calculateDay(base.next(index), report, birthBranch))
|
||||
const labels = ['昨日', '今日', '明日'] as const
|
||||
const selected = reports[offset + 1]
|
||||
return { ...selected, activeDay: labels[offset + 1], days: reports.map((item, index) => ({ label: labels[index], date: item.date, weekName: item.weekName, lunarDate: item.lunarDate, status: item.status })) }
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Solar } from 'lunar-typescript'
|
||||
|
||||
export const zodiacNames = ['鼠', '牛', '虎', '兔', '龙', '蛇', '马', '羊', '猴', '鸡', '狗', '猪'] as const
|
||||
export type ZodiacName = typeof zodiacNames[number]
|
||||
|
||||
// 日常生肖按农历正月初一换年,不能使用公历年份或立春年柱代替。
|
||||
export function calculateZodiac(birthday: string): ZodiacName | null {
|
||||
if (!/^\d{4}-\d{2}-\d{2}$/.test(birthday || '')) return null
|
||||
const [year, month, day] = birthday.split('-').map(Number)
|
||||
if (year < 1900 || year > 2100 || month < 1 || month > 12 || day < 1) return null
|
||||
if (day > new Date(Date.UTC(year, month, 0)).getUTCDate()) return null
|
||||
try {
|
||||
const zodiac = Solar.fromYmd(year, month, day).getLunar().getYearShengXiao()
|
||||
return zodiacNames.includes(zodiac as ZodiacName) ? zodiac as ZodiacName : null
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
import { LunarUtil, Solar } from 'lunar-typescript'
|
||||
import { calculateZodiac, zodiacNames, ZodiacName } from './zodiac'
|
||||
|
||||
export type ZodiacRelation = '六合' | '三合' | '六冲' | '相害' | '平常'
|
||||
export type ZodiacWeeklyDay = {
|
||||
date: string
|
||||
label: string
|
||||
weekday: string
|
||||
branch: string
|
||||
relation: ZodiacRelation
|
||||
score: number
|
||||
}
|
||||
export type ZodiacWeeklyReport = {
|
||||
zodiac: ZodiacName
|
||||
branch: string
|
||||
weekStart: string
|
||||
weekEnd: string
|
||||
score: number
|
||||
status: '顺势' | '平稳' | '谨慎'
|
||||
tone: 'positive' | 'neutral' | 'cautious'
|
||||
summary: string
|
||||
days: ZodiacWeeklyDay[]
|
||||
supportiveDays: ZodiacWeeklyDay[]
|
||||
cautiousDays: ZodiacWeeklyDay[]
|
||||
}
|
||||
|
||||
export const ZODIAC_WEEKLY_RULES = '六合 +2,三合同组 +1,六冲 −2,相害 −1,其余 0;七日合计 ≥2 为顺势,≤−2 为谨慎,其余为平稳。'
|
||||
const BEIJING_OFFSET = 8 * 60 * 60 * 1000
|
||||
const branches = LunarUtil.ZHI.slice(1)
|
||||
const threeHarmonyGroups = ['申子辰', '亥卯未', '寅午戌', '巳酉丑']
|
||||
const harmPairs = ['子未', '丑午', '寅巳', '卯辰', '申亥', '酉戌']
|
||||
const relationScores: Record<ZodiacRelation, number> = { 六合: 2, 三合: 1, 六冲: -2, 相害: -1, 平常: 0 }
|
||||
const weekdays = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
|
||||
|
||||
// 用UTC字段读取UTC+8日期,不依赖设备时区,也不依赖浏览器Intl能力。
|
||||
export function getBeijingDate(now = new Date()): string {
|
||||
if (!Number.isFinite(now.getTime())) return ''
|
||||
return new Date(now.getTime() + BEIJING_OFFSET).toISOString().slice(0, 10)
|
||||
}
|
||||
|
||||
export function getZodiacRelation(birthBranch: string, dayBranch: string): ZodiacRelation {
|
||||
const index = branches.indexOf(birthBranch)
|
||||
if (index < 0 || !branches.includes(dayBranch)) throw new Error('无效的地支')
|
||||
if (LunarUtil.HE_ZHI_6[index] === dayBranch) return '六合'
|
||||
if (LunarUtil.CHONG[index] === dayBranch) return '六冲'
|
||||
if (harmPairs.some((pair) => pair.includes(birthBranch) && pair.includes(dayBranch)) && birthBranch !== dayBranch) return '相害'
|
||||
// 只表示同组三合的助力关系,两个地支不等于完整三合成局。
|
||||
if (birthBranch !== dayBranch && threeHarmonyGroups.some((group) => group.includes(birthBranch) && group.includes(dayBranch))) return '三合'
|
||||
return '平常'
|
||||
}
|
||||
|
||||
export function calculateWeeklyZodiacFortune(birthday: string, beijingDate = getBeijingDate()): ZodiacWeeklyReport | null {
|
||||
const zodiac = calculateZodiac(birthday)
|
||||
if (!zodiac || !/^\d{4}-\d{2}-\d{2}$/.test(beijingDate)) return null
|
||||
const [year, month, day] = beijingDate.split('-').map(Number)
|
||||
if (year < 1900 || year > 2100 || month < 1 || month > 12 || day < 1 || day > new Date(Date.UTC(year, month, 0)).getUTCDate()) return null
|
||||
try {
|
||||
const current = Solar.fromYmd(year, month, day)
|
||||
const monday = current.next(-((current.getWeek() + 6) % 7))
|
||||
const branch = branches[zodiacNames.indexOf(zodiac)]
|
||||
const days = weekdays.map((weekday, index): ZodiacWeeklyDay => {
|
||||
const solar = monday.next(index)
|
||||
const dayBranch = solar.getLunar().getDayZhi()
|
||||
const relation = getZodiacRelation(branch, dayBranch)
|
||||
return {
|
||||
date: solar.toYmd(),
|
||||
label: `${solar.getMonth()}/${solar.getDay()}`,
|
||||
weekday, branch: dayBranch, relation, score: relationScores[relation]
|
||||
}
|
||||
})
|
||||
const score = days.reduce((sum, item) => sum + item.score, 0)
|
||||
const supportiveDays = days.filter((item) => item.score > 0)
|
||||
const cautiousDays = days.filter((item) => item.score < 0)
|
||||
const status = score >= 2 ? '顺势' : score <= -2 ? '谨慎' : '平稳'
|
||||
const recommendation = score >= 2
|
||||
? '助力关系相对较多,可优先在助力日安排沟通与协作;遇到留意日仍宜放慢节奏。'
|
||||
: score <= -2
|
||||
? '需要留意的关系相对较多,宜提前确认安排、耐心沟通;助力日可用于协调与收尾。'
|
||||
: '合冲影响整体接近平衡,宜按计划推进,在助力日多做协调,在留意日注意细节。'
|
||||
return {
|
||||
zodiac, branch, weekStart: days[0].date, weekEnd: days[6].date, score, status,
|
||||
tone: score >= 2 ? 'positive' : score <= -2 ? 'cautious' : 'neutral',
|
||||
summary: `本周有${supportiveDays.length}个助力日、${cautiousDays.length}个留意日。${recommendation}`,
|
||||
days, supportiveDays, cautiousDays
|
||||
}
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||