龍魂 · 鸿蒙AI国学创作应用:对联/文言文/藏头诗/历史人物/道德经/河图洛书/五行八卦/二十八星宿生成器(二)
·
龍魂 · 鸿蒙AI国学创作应用:对联/文言文/藏头诗/历史人物/道德经/河图洛书/五行八卦/二十八星宿生成器
龍魂系统 · 鸿蒙原生国学创作层 · 传统文化数字化引擎
DNA: ZHUGEXIN⚡️2025-🇨🇳🐉⚖️♠️🧚🏼♀️❤️♾️ | UID: 9622 | CONFIRM: #CONFIRM🌌9622-ONLY-ONCE🧬LK9X-772Z
一、核心定位
| 维度 | 说明 |
|---|---|
| 平台 | 鸿蒙 HarmonyOS NEXT · API 24+ · 纯血鸿蒙 |
| 语言 | ArkTS · 声明式UI · 传统文化引擎 |
| 场景 | 对联创作 · 文言文生成 · 藏头诗 · 历史人物问答 · 道德经解读 · 河图洛书 · 五行八卦 · 二十八星宿 · 风水学 |
| 架构 | 龍魂国学引擎 → 规则模板 + AI生成 → 鸿蒙交互层 |
| 主权 | 数据本地 · 国密SM2/SM3签名 · 不上传云端 |
| 设计 | 模板优先 · 规则引擎 · 低算力 · 可复用 · 结构清晰 |
二、系统架构
┌─────────────────────────────────────────┐
│ 龍魂系统 · 国学创作层 │
│ DNA: ZHUGEXIN⚡️2025-🇨🇳🐉⚖️♠️🧚🏼♀️❤️♾️ │
│ UID: 9622 │
├─────────────────────────────────────────┤
│ 鸿蒙 ArkTS 国学创作引擎 │
│ │
│ 创作流水线 │
│ ├── 对联生成器(平仄对仗引擎) │
│ ├── 文言文生成器(句式模板库) │
│ ├── 藏头诗生成器(首字约束引擎) │
│ ├── 历史人物问答(知识图谱检索) │
│ ├── 道德经解读(章节索引+释义) │
│ ├── 河图洛书(数字矩阵计算) │
│ ├── 五行八卦(生克推演引擎) │
│ ├── 二十八星宿(天文历法计算) │
│ ├── 风水学(方位吉凶推演) │
│ └── 国密签名验证(CryptoVerifier) │
├─────────────────────────────────────────┤
│ 龍魂国学数据层 │
│ │
│ 对联库 · 文言文模板 · 历史人物库 · 道德经全文 │
│ 河图洛书矩阵 · 五行生克表 · 八卦卦象 · 星宿表 │
│ 风水罗盘数据 · 国密加密存储 │
└─────────────────────────────────────────┘
4.3 历史人物引擎(entry/src/main/ets/engines/HistoricalFigureEngine.ets)
// entry/src/main/ets/engines/HistoricalFigureEngine.ets
// 龍魂 · 历史人物引擎
import { HistoricalFigure } from '../models/GuoxueModel';
export class HistoricalFigureEngine {
// 历史人物数据库
private figures: Map<string, HistoricalFigure> = new Map([
['诸葛亮', new HistoricalFigure({
name: '诸葛亮',
dynasty: '三国·蜀汉',
era: '181-234年',
achievements: ['隆中对定三分天下', '赤壁之战联吴抗曹', '六出祁山北伐中原', '发明木牛流马', '治蜀有方'],
personality: '鞠躬尽瘁,死而后已。智慧超群,忠诚不渝。',
famousQuotes: ['非淡泊无以明志,非宁静无以致远', '鞠躬尽瘁,死而后已', '亲贤臣,远小人'],
relatedEvents: ['三顾茅庐', '草船借箭', '空城计', '白帝城托孤', '五丈原']
})],
['曹操', new HistoricalFigure({
name: '曹操',
dynasty: '三国·魏',
era: '155-220年',
achievements: ['挟天子以令诸侯', '统一北方', '屯田制恢复生产', '唯才是举'],
personality: '奸雄本色,雄才大略。文韬武略,不拘小节。',
famousQuotes: ['宁教我负天下人,休教天下人负我', '老骥伏枥,志在千里', '对酒当歌,人生几何'],
relatedEvents: ['官渡之战', '赤壁之战', '煮酒论英雄', '华容道']
})],
['岳飞', new HistoricalFigure({
name: '岳飞',
dynasty: '南宋',
era: '1103-1142年',
achievements: ['精忠报国抗金兵', '郾城大捷', '收复失地', '治军严明'],
personality: '精忠报国,刚正不阿。文武双全,气节凛然。',
famousQuotes: ['精忠报国', '莫等闲,白了少年头,空悲切', '壮志饥餐胡虏肉,笑谈渴饮匈奴血'],
relatedEvents: ['岳母刺字', '郾城之战', '十二道金牌', '风波亭']
})],
['文天祥', new HistoricalFigure({
name: '文天祥',
dynasty: '南宋',
era: '1236-1283年',
achievements: ['起兵抗元', '被俘不屈', '留下正气歌', '舍生取义'],
personality: '浩然正气,宁死不屈。忠贞不渝,气节高尚。',
famousQuotes: ['人生自古谁无死,留取丹心照汗青', '天地有正气,杂然赋流形', '孔曰成仁,孟曰取义'],
relatedEvents: ['崖山海战', '过零丁洋', '正气歌', '柴市就义']
})],
['孔子', new HistoricalFigure({
name: '孔子',
dynasty: '春秋·鲁',
era: '前551-前479年',
achievements: ['创立儒家学说', '周游列国传播思想', '删述六经', '有教无类'],
personality: '温良恭俭让,博学而笃志。仁德为本,教化天下。',
famousQuotes: ['己所不欲,勿施于人', '学而时习之,不亦说乎', '三人行,必有我师焉'],
relatedEvents: ['周游列国', '杏坛讲学', '韦编三绝', '陈蔡之厄']
})],
['老子', new HistoricalFigure({
name: '老子',
dynasty: '春秋·楚',
era: '约前571-前471年',
achievements: ['著《道德经》', '创立道家学说', '提出无为而治', '道法自然'],
personality: '清静无为,道法自然。大智若愚,超然物外。',
famousQuotes: ['道可道,非常道', '上善若水', '无为而无不为'],
relatedEvents: ['紫气东来', '骑牛出关', '著书五千言']
})],
['秦始皇', new HistoricalFigure({
name: '秦始皇',
dynasty: '秦',
era: '前259-前210年',
achievements: ['统一六国', '建立中央集权', '统一文字货币度量衡', '修长城', '建兵马俑'],
personality: '雄才大略,残暴专横。功过参半,千古一帝。',
famousQuotes: ['朕为始皇帝,后世以计数', '天下共苦战斗不休,以有侯王'],
relatedEvents: ['统一六国', '焚书坑儒', '修筑长城', '巡游天下', '沙丘之变']
})],
['汉武帝', new HistoricalFigure({
name: '汉武帝',
dynasty: '西汉',
era: '前156-前87年',
achievements: ['独尊儒术', '开拓疆域', '派张骞通西域', '抗击匈奴', '盐铁官营'],
personality: '雄才大略,好大喜功。开疆拓土,文治武功。',
famousQuotes: ['犯强汉者,虽远必诛', '盖有非常之功,必待非常之人'],
relatedEvents: ['罢黜百家', '卫青霍去病北伐', '张骞通西域', '巫蛊之祸']
})],
['唐太宗', new HistoricalFigure({
name: '李世民',
dynasty: '唐',
era: '598-649年',
achievements: ['玄武门之变夺位', '贞观之治', '完善科举', '虚心纳谏', '天可汗'],
personality: '英明果断,从谏如流。文武兼备,胸怀天下。',
famousQuotes: ['以铜为镜,可以正衣冠', '水能载舟,亦能覆舟', '疾风知劲草,板荡识诚臣'],
relatedEvents: ['玄武门之变', '贞观之治', '魏征进谏', '凌烟阁二十四功臣']
})],
['武则天', new HistoricalFigure({
name: '武则天',
dynasty: '唐',
era: '624-705年',
achievements: ['中国历史上唯一女皇帝', '开创殿试', '发展科举', '重视农业'],
personality: '心狠手辣,雄才大略。知人善任,政治手腕高超。',
famousQuotes: ['欲安其家,先安其国', '君子虽殒,善名不灭'],
relatedEvents: ['入宫为才人', '废唐建周', '神龙政变', '无字碑']
})],
['朱元璋', new HistoricalFigure({
name: '朱元璋',
dynasty: '明',
era: '1328-1398年',
achievements: ['建立明朝', '推翻元朝', '恢复汉人政权', '严惩贪官', '休养生息'],
personality: '出身贫寒,雄才大略。猜忌多疑,手段狠辣。',
famousQuotes: ['驱逐胡虏,恢复中华', '高筑墙,广积粮,缓称王'],
relatedEvents: ['红巾军起义', '鄱阳湖之战', '建立明朝', '胡惟庸案', '蓝玉案']
})],
['郑和', new HistoricalFigure({
name: '郑和',
dynasty: '明',
era: '1371-1433年',
achievements: ['七下西洋', '开拓海上丝绸之路', '促进中外交流', '展示国威'],
personality: '勇敢坚毅,胸怀天下。和平使者,航海先驱。',
famousQuotes: ['宣德化而柔远人', '及临外邦,番王之不恭者,生擒之'],
relatedEvents: ['七下西洋', '到达非洲', '建立航海图', '马六甲访问']
})],
['林则徐', new HistoricalFigure({
name: '林则徐',
dynasty: '清',
era: '1785-1850年',
achievements: ['虎门销烟', '禁烟运动', '编译《四洲志》', '开眼看世界'],
personality: '刚正不阿,忧国忧民。民族英雄,开眼看世界第一人。',
famousQuotes: ['苟利国家生死以,岂因祸福避趋之', '海纳百川,有容乃大', '壁立千仞,无欲则刚'],
relatedEvents: ['虎门销烟', '鸦片战争', '贬谪伊犁', '治理黄河']
})],
['孙中山', new HistoricalFigure({
name: '孙中山',
dynasty: '民国',
era: '1866-1925年',
achievements: ['创立兴中会', '领导辛亥革命', '建立中华民国', '提出三民主义'],
personality: '革命先驱,百折不挠。天下为公,博爱无私。',
famousQuotes: ['革命尚未成功,同志仍须努力', '天下为公', '吾志所向,一往无前'],
relatedEvents: ['辛亥革命', '建立民国', '护法运动', '国共合作']
})]
]);
// 查询人物
query(name: string): HistoricalFigure | undefined {
return this.figures.get(name);
}
// 模糊搜索
search(keyword: string): HistoricalFigure[] {
const results: HistoricalFigure[] = [];
for (const [name, figure] of this.figures) {
if (name.includes(keyword) ||
figure.dynasty.includes(keyword) ||
figure.achievements.some(a => a.includes(keyword))) {
results.push(figure);
}
}
return results;
}
// 获取所有人物
getAll(): HistoricalFigure[] {
return Array.from(this.figures.values());
}
// 按朝代筛选
filterByDynasty(dynasty: string): HistoricalFigure[] {
return Array.from(this.figures.values()).filter(f => f.dynasty.includes(dynasty));
}
}
export const figureEngine = new HistoricalFigureEngine();
4.4 道德经引擎(entry/src/main/ets/engines/DaoDeJingEngine.ets)
// entry/src/main/ets/engines/DaoDeJingEngine.ets
// 龍魂 · 道德经引擎
import { DaoDeJingChapter } from '../models/GuoxueModel';
export class DaoDeJingEngine {
// 道德经八十一章
private chapters: Map<number, DaoDeJingChapter> = new Map([
[1, new DaoDeJingChapter({
chapter: 1,
title: '道可道',
original: '道可道,非常道;名可名,非常名。无名,天地之始;有名,万物之母。故常无欲,以观其妙;常有欲,以观其徼。此两者,同出而异名,同谓之玄。玄之又玄,众妙之门。',
translation: '可以用言语表达的道,就不是永恒的道;可以用名称界定的名,就不是永恒的名。无,是天地的开端;有,是万物的根源。所以,从常无中,将以观察道的奥妙;从常有中,将以观察道的边界。这两者是同一个来源而名称不同,都可以说是幽微深远的。幽微深远而又幽微深远,是一切奥妙的门径。',
interpretation: '本章是《道德经》的开篇,提出了"道"的核心概念。道是不可言说的终极实在,超越一切概念和语言。有无相生,是理解宇宙万物生成变化的根本方法。',
keywords: ['道', '名', '无', '有', '玄']
})],
[2, new DaoDeJingChapter({
chapter: 2,
title: '天下皆知',
original: '天下皆知美之为美,斯恶已;皆知善之为善,斯不善已。故有无相生,难易相成,长短相形,高下相倾,音声相和,前后相随。是以圣人处无为之事,行不言之教。万物作焉而不辞,生而不有,为而不恃,功成而弗居。夫唯弗居,是以不去。',
translation: '天下人都知道美之所以为美,丑的观念就产生了;都知道善之所以为善,不善的观念就产生了。所以有和无互相生成,难和易互相完成,长和短互相形成,高和下互相依存,音和声互相调和,前和后互相跟随。因此圣人以无为的态度处事,以不言的方式施教。万物兴起而不拒绝,生养万物而不占有,有所作为而不倚靠,功成而不居功。正因为不居功,所以功绩不会失去。',
interpretation: '本章阐述了相对主义的辩证法。一切概念都是相对的,美丑、善恶、有无都是相互依存、相互转化的。圣人顺应自然,不执着于任何一方,以无为达到无不为的境界。',
keywords: ['美丑', '善恶', '有无', '无为', '相对']
})],
[3, new DaoDeJingChapter({
chapter: 3,
title: '不尚贤',
original: '不尚贤,使民不争;不贵难得之货,使民不为盗;不见可欲,使民心不乱。是以圣人之治,虚其心,实其腹,弱其志,强其骨。常使民无知无欲,使夫智者不敢为也。为无为,则无不治。',
translation: '不推崇贤能,使人民不争名;不贵重难得的财货,使人民不做盗贼;不显现可贪的事物,使人民心思不乱。因此圣人的治理,是空虚人民的心思,充实人民的肚腹,削弱人民的意志,强健人民的筋骨。常使人民没有伪诈的心智,没有争盗的欲念,使那些聪明的人不敢妄为。以无为的态度去治理,就没有治理不好的。',
interpretation: '本章提出了"无为而治"的政治理想。通过消除引发争斗和欲望的根源,使人民回归自然淳朴的状态。这不是愚民政策,而是让人心回归本真,减少人为的纷扰。',
keywords: ['无为而治', '不争', '无欲', '虚心', '实腹']
})],
[8, new DaoDeJingChapter({
chapter: 8,
title: '上善若水',
original: '上善若水。水善利万物而不争,处众人之所恶,故几于道。居善地,心善渊,与善仁,言善信,正善治,事善能,动善时。夫唯不争,故无尤。',
translation: '最高的善像水一样。水善于滋润万物而不与万物相争,停留在众人所厌恶的地方,所以最接近于道。居住善于选择地方,心胸善于保持深沉,待人善于真诚仁爱,说话善于遵守信用,为政善于治理,处事善于发挥所长,行动善于把握时机。正因为不与万物相争,所以不会有过失。',
interpretation: '本章以水为喻,阐述了"善"的最高境界。水的特性是柔、下、不争,却能滋养万物。人应该学习水的品德,以柔克刚,以退为进,在不争中成就一切。',
keywords: ['上善若水', '不争', '柔弱', '处下', '无尤']
})],
[16, new DaoDeJingChapter({
chapter: 16,
title: '致虚极',
original: '致虚极,守静笃。万物并作,吾以观复。夫物芸芸,各复归其根。归根曰静,是谓复命。复命曰常,知常曰明。不知常,妄作凶。知常容,容乃公,公乃王,王乃天,天乃道,道乃久,没身不殆。',
translation: '达到虚空的极点,坚守宁静的笃实。万物一起生长,我从中观察它们循环往复的规律。万物纷繁茂盛,各自返回它的本根。返回本根叫做静,静叫做复命。复命叫做常,认识常叫做明。不认识常,轻举妄动就会遭凶。认识常才能包容,包容才能公正,公正才能周全,周全才能符合自然,符合自然才能符合道,符合道才能长久,终身不会遭遇危险。',
interpretation: '本章论述了"虚静"的功夫。通过致虚守静,可以观察到万物循环往复的规律。归根复命是宇宙的根本法则,认识这个法则才能包容、公正、周全,最终与道合一。',
keywords: ['虚静', '归根', '复命', '知常', '包容']
})],
[25, new DaoDeJingChapter({
chapter: 25,
title: '有物混成',
original: '有物混成,先天地生。寂兮寥兮,独立而不改,周行而不殆,可以为天下母。吾不知其名,字之曰道,强为之名曰大。大曰逝,逝曰远,远曰反。故道大,天大,地大,王亦大。域中有四大,而王居其一焉。人法地,地法天,天法道,道法自然。',
translation: '有一个浑然一体的东西,在天地形成以前就已经存在。听不到它的声音也看不见它的形体,它独立长存而永不改变,循环运行而永不停歇,可以作为天下万物的本原。我不知道它的名字,勉强称它为"道",再勉强命名为"大"。大就是流逝,流逝就是辽远,辽远就是返回。所以说道大,天大,地大,王也大。宇宙中有四大,而王是其中之一。人取法地,地取法天,天取法道,道取法自然。',
interpretation: '本章描述了道的本体特征:先天地而生,独立不改,周行不殆。道是宇宙万物的本原和法则。人、地、天、道层层效法,最终归于自然。自然不是自然界,而是自己如此、本来如此的状态。',
keywords: ['道', '大', '自然', '四大', '效法']
})],
[33, new DaoDeJingChapter({
chapter: 33,
title: '知人者智',
original: '知人者智,自知者明。胜人者有力,自胜者强。知足者富,强行者有志。不失其所者久,死而不亡者寿。',
translation: '能了解别人的人是有智慧的,能了解自己的人是高明的。能战胜别人的人是有力量的,能战胜自己的人才是真正的强大。知道满足的人才是富有的,坚持力行的人是有志气的。不迷失根基的人才能长久,身体死亡而精神不消亡的人才是真正的长寿。',
interpretation: '本章强调了自我认知和自我超越的重要性。知人不如自知,胜人不如自胜。真正的强大是内心的强大,真正的富有是精神的富有。超越自我,与道合一,才能达到永恒。',
keywords: ['自知', '自胜', '知足', '强行', '不亡']
})],
[40, new DaoDeJingChapter({
chapter: 40,
title: '反者道之动',
original: '反者道之动,弱者道之用。天下万物生于有,有生于无。',
translation: '循环往复是道的运动,柔弱是道的作用。天下万物产生于有,有产生于无。',
interpretation: '本章是《道德经》的核心纲领。道的运动是循环往复的,物极必反是宇宙的根本规律。道的作用是柔弱的,以柔克刚是道的妙用。有无相生,无是万物的终极根源。',
keywords: ['反', '弱', '有无', '道之动', '道之用']
})],
[42, new DaoDeJingChapter({
chapter: 42,
title: '道生一',
original: '道生一,一生二,二生三,三生万物。万物负阴而抱阳,冲气以为和。人之所恶,唯孤、寡、不穀,而王公以为称。故物或损之而益,或益之而损。人之所教,我亦教之。强梁者不得其死,吾将以为教父。',
translation: '道产生统一体,统一体产生阴阳二气,阴阳二气相交产生第三者,第三者产生万物。万物背阴而向阳,阴阳二气互相激荡而成和谐。人们所厌恶的,就是孤、寡、不穀,而王公却用这些作为自己的称号。所以一切事物,有时减损它反而增益,有时增益它反而减损。别人教导我的,我也用来教导人。强暴的人不得好死,我将把这句话作为教人的根本。',
interpretation: '本章阐述了宇宙生成的过程:道→一→二→三→万物。这是老子的宇宙论。万物都包含阴阳两面,阴阳和谐是万物存在的条件。损有余而补不足,是道的平衡法则。',
keywords: ['道生一', '阴阳', '冲气', '损益', '强梁']
})],
[64, new DaoDeJingChapter({
chapter: 64,
title: '其安易持',
original: '其安易持,其未兆易谋。其脆易泮,其微易散。为之于未有,治之于未乱。合抱之木,生于毫末;九层之台,起于累土;千里之行,始于足下。为者败之,执者失之。是以圣人无为故无败,无执故无失。民之从事,常于几成而败之。慎终如始,则无败事。是以圣人欲不欲,不贵难得之货;学不学,复众人之所过,以辅万物之自然而不敢为。',
translation: '局面安定时容易维持,事情没有迹象时容易谋划。事物脆弱时容易消解,事物细微时容易散失。要在事情没有发生时就处理,要在祸乱没有产生时就治理。合抱的大树,生长于细小的萌芽;九层的高台,筑起于每一堆泥土;千里的远行,开始于脚下的第一步。妄为就会失败,执着就会失去。因此圣人无所作为所以不会失败,无所执着所以不会失去。人们做事,常常在快要成功时失败。像对待开始一样谨慎对待结束,就不会有失败的事情。因此圣人想要的是不想要的,不贵重难得的财货;学习的是不学习的,补救众人所犯的过错,以此辅助万物的自然发展而不敢妄为。',
interpretation: '本章强调了防微杜渐和慎终如始的重要性。大事必作于细,难事必作于易。无为不是不作为,而是顺应自然规律而为。慎终如始是成功的关键,辅助万物自然发展是圣人的境界。',
keywords: ['防微杜渐', '慎终如始', '无为', '自然', '千里之行']
})],
[81, new DaoDeJingChapter({
chapter: 81,
title: '信言不美',
original: '信言不美,美言不信。善者不辩,辩者不善。知者不博,博者不知。圣人不积,既以为人己愈有,既以与人己愈多。天之道,利而不害;圣人之道,为而不争。',
translation: '真实的话不华美,华美的话不真实。善良的人不巧辩,巧辩的人不善良。真正了解的人不广博,广博的人不能深入了解。圣人不私自积藏,尽量帮助别人,自己反而更充足;尽量给予别人,自己反而更丰富。自然的规律,是利物而不害物;圣人的法则,是有所作为而不争夺。',
interpretation: '本章是《道德经》的末章,总结了全书的中心思想。真实、善良、真知都是质朴无华的。圣人的境界是给予而非占有,是利人而非争利。天道利而不害,人道为而不争,这是老子留给世人的最终教诲。',
keywords: ['信言', '善者', '知者', '不积', '不争']
})]
]);
// 查询章节
getChapter(num: number): DaoDeJingChapter | undefined {
return this.chapters.get(num);
}
// 关键词搜索
searchByKeyword(keyword: string): DaoDeJingChapter[] {
const results: DaoDeJingChapter[] = [];
for (const chapter of this.chapters.values()) {
if (chapter.original.includes(keyword) ||
chapter.translation.includes(keyword) ||
chapter.keywords.includes(keyword)) {
results.push(chapter);
}
}
return results;
}
// 获取所有章节
getAllChapters(): DaoDeJingChapter[] {
return Array.from(this.chapters.values()).sort((a, b) => a.chapter - b.chapter);
}
// 随机获取
getRandom(): DaoDeJingChapter {
const chapters = Array.from(this.chapters.values());
return chapters[Math.floor(Math.random() * chapters.length)];
}
}
export const daoDeJingEngine = new DaoDeJingEngine();
4.5 河图洛书引擎(entry/src/main/ets/engines/HeTuLuoShuEngine.ets)
// entry/src/main/ets/engines/HeTuLuoShuEngine.ets
// 龍魂 · 河图洛书引擎
export class HeTuLuoShuEngine {
// 河图矩阵(天一生水...)
private heTuMatrix: number[][] = [
[7, 2, 6],
[8, 5, 4],
[3, 10, 9]
];
// 洛书矩阵(戴九履一...)
private luoShuMatrix: number[][] = [
[4, 9, 2],
[3, 5, 7],
[8, 1, 6]
];
// 河图口诀
private heTuMnemonic: string[] = [
'天一生水,地六成之',
'地二生火,天七成之',
'天三生木,地八成之',
'地四生金,天九成之',
'天五生土,地十成之'
];
// 洛书口诀
private luoShuMnemonic: string[] = [
'戴九履一',
'左三右七',
'二四为肩',
'六八为足',
'五居中央'
];
// 获取河图
getHeTu(): { matrix: number[][], mnemonic: string[], description: string } {
return {
matrix: this.heTuMatrix,
mnemonic: this.heTuMnemonic,
description: '河图,相传伏羲氏时,有龙马从黄河出现,背负"河图"。河图以十数合五方、五行、阴阳、天地之象。图式以白圈为阳,为天,为奇数;黑点为阴,为地,为偶数。'
};
}
// 获取洛书
getLuoShu(): { matrix: number[][], mnemonic: string[], description: string, magicSum: number } {
return {
matrix: this.luoShuMatrix,
mnemonic: this.luoShuMnemonic,
description: '洛书,相传大禹时,有神龟从洛水出现,背负"洛书"。洛书以九数合九宫、八卦、五行之象。其特点是纵、横、斜三条线上的三个数字之和皆等于15。',
magicSum: 15
};
}
// 验证洛书幻方
validateLuoShu(): boolean {
const m = this.luoShuMatrix;
const sum = 15;
// 行
for (let i = 0; i < 3; i++) {
if (m[i][0] + m[i][1] + m[i][2] !== sum) return false;
}
// 列
for (let j = 0; j < 3; j++) {
if (m[0][j] + m[1][j] + m[2][j] !== sum) return false;
}
// 对角线
if (m[0][0] + m[1][1] + m[2][2] !== sum) return false;
if (m[0][2] + m[1][1] + m[2][0] !== sum) return false;
return true;
}
// 数字对应五行
getWuXingByNumber(num: number): string {
const map: Map<number, string> = new Map([
[1, '水'], [6, '水'],
[2, '火'], [7, '火'],
[3, '木'], [8, '木'],
[4, '金'], [9, '金'],
[5, '土'], [10, '土']
]);
return map.get(num) || '未知';
}
// 数字对应方位
getDirectionByNumber(num: number): string {
const map: Map<number, string> = new Map([
[1, '北'], [6, '北'],
[2, '南'], [7, '南'],
[3, '东'], [8, '东'],
[4, '西'], [9, '西'],
[5, '中'], [10, '中']
]);
return map.get(num) || '未知';
}
}
export const heTuLuoShuEngine = new HeTuLuoShuEngine();
4.6 五行八卦引擎(entry/src/main/ets/engines/WuXingBaGuaEngine.ets)
// entry/src/main/ets/engines/WuXingBaGuaEngine.ets
// 龍魂 · 五行八卦引擎
import { WuXingData, BaGuaData } from '../models/GuoxueModel';
export class WuXingBaGuaEngine {
// 五行数据
private wuXingData: Map<string, WuXingData> = new Map([
['金', new WuXingData({
element: '金',
generation: '生水',
restriction: '克木',
color: '白',
direction: '西',
season: '秋',
organ: '肺',
emotion: '悲'
})],
['木', new WuXingData({
element: '木',
generation: '生火',
restriction: '克土',
color: '青',
direction: '东',
season: '春',
organ: '肝',
emotion: '怒'
})],
['水', new WuXingData({
element: '水',
generation: '生木',
restriction: '克火',
color: '黑',
direction: '北',
season: '冬',
organ: '肾',
emotion: '恐'
})],
['火', new WuXingData({
element: '火',
generation: '生土',
restriction: '克金',
color: '赤',
direction: '南',
season: '夏',
organ: '心',
emotion: '喜'
})],
['土', new WuXingData({
element: '土',
generation: '生金',
restriction: '克水',
color: '黄',
direction: '中',
season: '长夏',
organ: '脾',
emotion: '思'
})]
]);
// 八卦数据
private baGuaData: Map<string, BaGuaData> = new Map([
['乾', new BaGuaData({
name: '乾',
symbol: '☰',
nature: '天',
attribute: '健',
family: '父',
direction: '西北',
number: 1
})],
['坤', new BaGuaData({
name: '坤',
symbol: '☷',
nature: '地',
attribute: '顺',
family: '母',
direction: '西南',
number: 2
})],
['震', new BaGuaData({
name: '震',
symbol: '☳',
nature: '雷',
attribute: '动',
family: '长男',
direction: '东',
number: 3
})],
['巽', new BaGuaData({
name: '巽',
symbol: '☴',
nature: '风',
attribute: '入',
family: '长女',
direction: '东南',
number: 4
})],
['坎', new BaGuaData({
name: '坎',
symbol: '☵',
nature: '水',
attribute: '陷',
family: '中男',
direction: '北',
number: 5
})],
['离', new BaGuaData({
name: '离',
symbol: '☲',
nature: '火',
attribute: '丽',
family: '中女',
direction: '南',
number: 6
})],
['艮', new BaGuaData({
name: '艮',
symbol: '☶',
nature: '山',
attribute: '止',
family: '少男',
direction: '东北',
number: 7
})],
['兑', new BaGuaData({
name: '兑',
symbol: '☱',
nature: '泽',
attribute: '悦',
family: '少女',
direction: '西',
number: 8
})]
]);
// 获取五行
getWuXing(element: string): WuXingData | undefined {
return this.wuXingData.get(element);
}
// 获取八卦
getBaGua(name: string): BaGuaData | undefined {
return this.baGuaData.get(name);
}
// 五行生克推演
getRelation(from: string, to: string): string {
const wuXing = ['金', '木', '水', '火', '土'];
const fromIndex = wuXing.indexOf(from);
const toIndex = wuXing.indexOf(to);
if (fromIndex === -1 || toIndex === -1) return '未知';
// 生:(index + 1) % 5
if ((fromIndex + 1) % 5 === toIndex) return `${from}生${to}`;
// 克:(index + 2) % 5
if ((fromIndex + 2) % 5 === toIndex) return `${from}克${to}`;
// 被生
if ((toIndex + 1) % 5 === fromIndex) return `${to}生${from}`;
// 被克
if ((toIndex + 2) % 5 === fromIndex) return `${to}克${from}`;
return '同';
}
// 八卦配五行
getBaGuaWuXing(gua: string): string {
const map: Map<string, string> = new Map([
['乾', '金'], ['兑', '金'],
['震', '木'], ['巽', '木'],
['坎', '水'],
['离', '火'],
['坤', '土'], ['艮', '土']
]);
return map.get(gua) || '未知';
}
// 获取所有五行
getAllWuXing(): WuXingData[] {
return Array.from(this.wuXingData.values());
}
// 获取所有八卦
getAllBaGua(): BaGuaData[] {
return Array.from(this.baGuaData.values());
}
}
export const wuXingBaGuaEngine = new WuXingBaGuaEngine();
4.7 二十八星宿引擎(entry/src/main/ets/engines/XingXiuEngine.ets)
// entry/src/main/ets/engines/XingXiuEngine.ets
// 龍魂 · 二十八星宿引擎
import { XingXiuData } from '../models/GuoxueModel';
export class XingXiuEngine {
// 二十八星宿数据
private xingXiuList: XingXiuData[] = [
// 东方青龙七宿
new XingXiuData({ name: '角', direction: '东方青龙', animal: '苍龙', constellation: '室女座', auspicious: true, meaning: '天门,主造化万物,布君威信' }),
new XingXiuData({ name: '亢', direction: '东方青龙', animal: '苍龙', constellation: '室女座', auspicious: true, meaning: '天府,主天下万物' }),
new XingXiuData({ name: '氐', direction: '东方青龙', animal: '苍龙', constellation: '天秤座', auspicious: false, meaning: '天根,主疫疾' }),
new XingXiuData({ name: '房', direction: '东方青龙', animal: '苍龙', constellation: '天蝎座', auspicious: true, meaning: '天府,主左骖' }),
new XingXiuData({ name: '心', direction: '东方青龙', animal: '苍龙', constellation: '天蝎座', auspicious: false, meaning: '天王,主明堂' }),
new XingXiuData({ name: '尾', direction: '东方青龙', animal: '苍龙', constellation: '天蝎座', auspicious: true, meaning: '天江,主后宫' }),
new XingXiuData({ name: '箕', direction: '东方青龙', animal: '苍龙', constellation: '人马座', auspicious: true, meaning: '天津,主八风' }),
// 北方玄武七宿
new XingXiuData({ name: '斗', direction: '北方玄武', animal: '玄武', constellation: '人马座', auspicious: true, meaning: '天庙,主宰相禄位' }),
new XingXiuData({ name: '牛', direction: '北方玄武', animal: '玄武', constellation: '摩羯座', auspicious: true, meaning: '天关,主牺牲' }),
new XingXiuData({ name: '女', direction: '北方玄武', animal: '玄武', constellation: '宝瓶座', auspicious: true, meaning: '天少府,主布帛' }),
new XingXiuData({ name: '虚', direction: '北方玄武', animal: '玄武', constellation: '宝瓶座', auspicious: false, meaning: '天节,主哭泣' }),
new XingXiuData({ name: '危', direction: '北方玄武', animal: '玄武', constellation: '宝瓶座', auspicious: false, meaning: '天市,主架屋' }),
new XingXiuData({ name: '室', direction: '北方玄武', animal: '玄武', constellation: '飞马座', auspicious: true, meaning: '天营,主军粮' }),
new XingXiuData({ name: '壁', direction: '北方玄武', animal: '玄武', constellation: '飞马座', auspicious: true, meaning: '天厩,主图书' }),
// 西方白虎七宿
new XingXiuData({ name: '奎', direction: '西方白虎', animal: '白虎', constellation: '仙女座/双鱼座', auspicious: true, meaning: '天豕,主武库' }),
new XingXiuData({ name: '娄', direction: '西方白虎', animal: '白虎', constellation: '白羊座', auspicious: true, meaning: '天狱,主苑牧' }),
new XingXiuData({ name: '胃', direction: '西方白虎', animal: '白虎', constellation: '白羊座', auspicious: true, meaning: '天仓,主五谷' }),
new XingXiuData({ name: '昴', direction: '西方白虎', animal: '白虎', constellation: '金牛座', auspicious: false, meaning: '天耳,主狱事' }),
new XingXiuData({ name: '毕', direction: '西方白虎', animal: '白虎', constellation: '金牛座', auspicious: true, meaning: '天耳,主边兵' }),
new XingXiuData({ name: '觜', direction: '西方白虎', animal: '白虎', constellation: '猎户座', auspicious: false, meaning: '天苑,主守御' }),
new XingXiuData({ name: '参', direction: '西方白虎', animal: '白虎', constellation: '猎户座', auspicious: true, meaning: '天市,主诛斩' }),
// 南方朱雀七宿
new XingXiuData({ name: '井', direction: '南方朱雀', animal: '朱雀', constellation: '双子座', auspicious: false, meaning: '天阙,主水衡' }),
new XingXiuData({ name: '鬼', direction: '南方朱雀', animal: '朱雀', constellation: '巨蟹座', auspicious: false, meaning: '天目,主视明' }),
new XingXiuData({ name: '柳', direction: '南方朱雀', animal: '朱雀', constellation: '长蛇座', auspicious: true, meaning: '天库,主厨食' }),
new XingXiuData({ name: '星', direction: '南方朱雀', animal: '朱雀', constellation: '长蛇座', auspicious: true, meaning: '天都,主衣裳' }),
new XingXiuData({ name: '张', direction: '南方朱雀', animal: '朱雀', constellation: '长蛇座', auspicious: true, meaning: '天庙,主珍宝' }),
new XingXiuData({ name: '翼', direction: '南方朱雀', animal: '朱雀', constellation: '巨爵座', auspicious: true, meaning: '天乐,主俳倡' }),
new XingXiuData({ name: '轸', direction: '南方朱雀', animal: '朱雀', constellation: '乌鸦座', auspicious: true, meaning: '天车,主风' })
];
// 按方向分组
getByDirection(direction: string): XingXiuData[] {
return this.xingXiuList.filter(x => x.direction === direction);
}
// 查询星宿
getByName(name: string): XingXiuData | undefined {
return this.xingXiuList.find(x => x.name === name);
}
// 获取所有
getAll(): XingXiuData[] {
return this.xingXiuList;
}
// 获取四象
getFourAnimals(): string[] {
return ['东方青龙', '北方玄武', '西方白虎', '南方朱雀'];
}
// 判断吉凶
isAuspicious(name: string): boolean {
const xing = this.getByName(name);
return xing ? xing.auspicious : false;
}
}
export const xingXiuEngine = new XingXiuEngine();
五、主页面实现
5.1 国学创作主页面(entry/src/main/ets/pages/GuoxueCreation.ets)
// entry/src/main/ets/pages/GuoxueCreation.ets
// 龍魂 · 国学创作鸿蒙主页面
import { guoxueState, GuoxueState, CreationType } from '../models/GuoxueModel';
import { coupletEngine } from '../engines/CoupletEngine';
import { acrosticEngine } from '../engines/AcrosticEngine';
import { figureEngine } from '../engines/HistoricalFigureEngine';
import { daoDeJingEngine } from '../engines/DaoDeJingEngine';
import { heTuLuoShuEngine } from '../engines/HeTuLuoShuEngine';
import { wuXingBaGuaEngine } from '../engines/WuXingBaGuaEngine';
import { xingXiuEngine } from '../engines/XingXiuEngine';
@Entry
@Component
struct GuoxueCreationPage {
@StorageLink('guoxueState') guoxueState: GuoxueState = guoxueState;
@State private selectedTab: number = 0;
@State private inputText: string = '';
@State private resultText: string = '';
@State private detailVisible: boolean = false;
@State private detailContent: string = '';
// 标签配置
private tabs = [
{ label: '对联', icon: '🏮', type: CreationType.COUPLET },
{ label: '藏头诗', icon: '✒️', type: CreationType.ACROSTIC_POEM },
{ label: '历史人物', icon: '👤', type: CreationType.HISTORICAL_FIGURE },
{ label: '道德经', icon: '📜', type: CreationType.DAO_DE_JING },
{ label: '河图洛书', icon: '🔢', type: CreationType.HE_TU },
{ label: '五行八卦', icon: '☯️', type: CreationType.WU_XING },
{ label: '二十八宿', icon: '⭐', type: CreationType.XING_XIU }
];
build() {
Column() {
this.HeaderBuilder()
this.TabBuilder()
this.ContentBuilder()
this.FooterBuilder()
}
.width('100%')
.height('100%')
.backgroundColor('#0a0a0a')
}
@Builder
HeaderBuilder() {
Row() {
Text('🐉').fontSize(28).margin({ right: 8 })
Column() {
Text('龍魂国学创作').fontSize(20).fontWeight(FontWeight.Bold).fontColor('#c41e3a')
Text(`UID:${MASTER_UID} · 传统文化引擎`).fontSize(12).fontColor('#666')
}
.alignItems(HorizontalAlign.Start)
.layoutWeight(1)
}
.width('100%')
.height(56)
.padding({ left: 16, right: 16 })
.backgroundColor('#1a1a1a')
.border({ width: { bottom: 1 }, color: '#333' })
}
@Builder
TabBuilder() {
Scroll() {
Row() {
ForEach(this.tabs, (tab, index) => {
Column() {
Text(tab.icon).fontSize(20)
Text(tab.label)
.fontSize(11)
.fontColor(this.selectedTab === index ? '#c41e3a' : '#888')
.margin({ top: 4 })
if (this.selectedTab === index) {
Divider()
.strokeWidth(2)
.color('#c41e3a')
.width(20)
.margin({ top: 4 })
}
}
.padding({ top: 8, bottom: 8, left: 12, right: 12 })
.onClick(() => {
this.selectedTab = index;
this.resultText = '';
this.inputText = '';
})
})
}
.width('100%')
}
.scrollBar(BarState.Auto)
.backgroundColor('#1a1a1a')
.border({ width: { bottom: 1 }, color: '#333' })
}
@Builder
ContentBuilder() {
Scroll() {
Column() {
// 输入区
this.InputBuilder()
// 操作按钮
this.ActionBuilder()
// 结果区
this.ResultBuilder()
// 详情弹窗
if (this.detailVisible) {
this.DetailBuilder()
}
}
.width('100%')
.padding(16)
}
.width('100%')
.layoutWeight(1)
.scrollBar(BarState.Auto)
}
@Builder
InputBuilder() {
Column() {
Text(this.tabs[this.selectedTab].label + '创作')
.fontSize(16)
.fontWeight(FontWeight.Bold)
.fontColor('#fff')
.margin({ bottom: 12 })
.width('100%')
if (this.selectedTab === 0) {
// 对联输入
Text('输入主题(如:春节、龙年、励志)')
.fontSize(12)
.fontColor('#666')
.margin({ bottom: 8 })
.width('100%')
TextInput({ placeholder: '输入主题...', text: $$this.inputText })
.width('100%')
.height(44)
.fontSize(14)
.fontColor('#fff')
.placeholderColor('#666')
.backgroundColor('#1a1a1a')
.borderRadius(8)
.padding({ left: 12, right: 12 })
} else if (this.selectedTab === 1) {
// 藏头诗输入
Text('输入藏头字(如:龍魂中国)')
.fontSize(12)
.fontColor('#666')
.margin({ bottom: 8 })
.width('100%')
TextInput({ placeholder: '输入藏头字...', text: $$this.inputText })
.width('100%')
.height(44)
.fontSize(14)
.fontColor('#fff')
.placeholderColor('#666')
.backgroundColor('#1a1a1a')
.borderRadius(8)
.padding({ left: 12, right: 12 })
} else if (this.selectedTab === 2) {
// 历史人物输入
Text('输入人物名(如:诸葛亮、岳飞)')
.fontSize(12)
.fontColor('#666')
.margin({ bottom: 8 })
.width('100%')
TextInput({ placeholder: '输入人物名...', text: $$this.inputText })
.width('100%')
.height(44)
.fontSize(14)
.fontColor('#fff')
.placeholderColor('#666')
.backgroundColor('#1a1a1a')
.borderRadius(8)
.padding({ left: 12, right: 12 })
} else if (this.selectedTab === 3) {
// 道德经输入
Text('输入章节号(1-81)或关键词')
.fontSize(12)
.fontColor('#666')
.margin({ bottom: 8 })
.width('100%')
TextInput({ placeholder: '输入章节号或关键词...', text: $$this.inputText })
.width('100%')
.height(44)
.fontSize(14)
.fontColor('#fff')
.placeholderColor('#666')
.backgroundColor('#1a1a1a')
.borderRadius(8)
.padding({ left: 12, right: 12 })
} else if (this.selectedTab === 4) {
// 河图洛书
Text('点击按钮查看河图/洛书')
.fontSize(12)
.fontColor('#666')
.margin({ bottom: 8 })
.width('100%')
} else if (this.selectedTab === 5) {
// 五行八卦
Text('输入五行(金木水火土)或八卦名')
.fontSize(12)
.fontColor('#666')
.margin({ bottom: 8 })
.width('100%')
TextInput({ placeholder: '输入五行或八卦名...', text: $$this.inputText })
.width('100%')
.height(44)
.fontSize(14)
.fontColor('#fff')
.placeholderColor('#666')
.backgroundColor('#1a1a1a')
.borderRadius(8)
.padding({ left: 12, right: 12 })
} else if (this.selectedTab === 6) {
// 二十八星宿
Text('输入星宿名或方向(东方青龙/北方玄武/西方白虎/南方朱雀)')
.fontSize(12)
.fontColor('#666')
.margin({ bottom: 8 })
.width('100%')
TextInput({ placeholder: '输入星宿名或方向...', text: $$this.inputText })
.width('100%')
.height(44)
.fontSize(14)
.fontColor('#fff')
.placeholderColor('#666')
.backgroundColor('#1a1a1a')
.borderRadius(8)
.padding({ left: 12, right: 12 })
}
}
.width('100%')
.margin({ bottom: 16 })
}
@Builder
ActionBuilder() {
Row() {
if (this.selectedTab === 4) {
Button('查看河图')
.fontSize(13)
.fontColor('#fff')
.backgroundColor('#c41e3a')
.borderRadius(8)
.padding({ left: 16, right: 16 })
.onClick(() => {
this.showHeTu();
})
Button('查看洛书')
.fontSize(13)
.fontColor('#fff')
.backgroundColor('#333')
.borderRadius(8)
.padding({ left: 16, right: 16 })
.margin({ left: 8 })
.onClick(() => {
this.showLuoShu();
})
} else {
Button('生成/查询')
.fontSize(13)
.fontColor('#fff')
.backgroundColor('#c41e3a')
.borderRadius(8)
.padding({ left: 16, right: 16 })
.onClick(() => {
this.generate();
})
Button('随机')
.fontSize(13)
.fontColor('#fff')
.backgroundColor('#333')
.borderRadius(8)
.padding({ left: 16, right: 16 })
.margin({ left: 8 })
.onClick(() => {
this.randomGenerate();
})
}
}
.width('100%')
.justifyContent(FlexAlign.Center)
.margin({ bottom: 16 })
}
@Builder
ResultBuilder() {
if (this.resultText) {
Column() {
Text('结果')
.fontSize(14)
.fontWeight(FontWeight.Bold)
.fontColor('#c41e3a')
.margin({ bottom: 8 })
.width('100%')
Text(this.resultText)
.fontSize(14)
.fontColor('#fff')
.width('100%')
.padding(12)
.backgroundColor('#1a1a1a')
.borderRadius(8)
}
.width('100%')
.margin({ bottom: 16 })
}
}
@Builder
DetailBuilder() {
Column() {
Row() {
Text('详情')
.fontSize(14)
.fontWeight(FontWeight.Bold)
.fontColor('#c41e3a')
.layoutWeight(1)
Button('✕')
.fontSize(12)
.fontColor('#fff')
.backgroundColor('transparent')
.onClick(() => {
this.detailVisible = false;
})
}
.width('100%')
.margin({ bottom: 8 })
Text(this.detailContent)
.fontSize(13)
.fontColor('#ccc')
.width('100%')
.padding(12)
.backgroundColor('#1a1a1a')
.borderRadius(8)
}
.width('100%')
.margin({ bottom: 16 })
}
@Builder
FooterBuilder() {
Row() {
Column() {
Text('🐉').fontSize(20)
Text(`UID:${MASTER_UID}`).fontSize(10).fontColor('#666')
}
.alignItems(HorizontalAlign.Start)
.layoutWeight(1)
Row() {
Text(`📚 ${this.guoxueState.statistics.totalCouplets} 对联`).fontSize(11).fontColor('#888')
Text(`✒️ ${this.guoxueState.statistics.totalAcrostics} 藏头`).fontSize(11).fontColor('#888').margin({ left: 8 })
}
}
.width('100%')
.height(40)
.padding({ left: 16, right: 16 })
.backgroundColor('#1a1a1a')
.border({ width: { top: 1 }, color: '#333' })
}
// === 生成逻辑 ===
generate() {
switch (this.selectedTab) {
case 0: this.generateCouplet(); break;
case 1: this.generateAcrostic(); break;
case 2: this.queryFigure(); break;
case 3: this.queryDaoDeJing(); break;
case 5: this.queryWuXingBaGua(); break;
case 6: this.queryXingXiu(); break;
}
}
// 对联生成
generateCouplet() {
const theme = this.inputText || '通用';
const couplet = coupletEngine.generate(theme, 7);
this.resultText = `【主题】${couplet.theme}\n\n` +
`上联:${couplet.upper}\n` +
`下联:${couplet.lower}\n\n` +
`横批:${couplet.horizontal}\n\n` +
`平仄:${couplet.tonePattern}`;
this.guoxueState.couplets.push(couplet);
}
// 藏头诗生成
generateAcrostic() {
const headWord = this.inputText || '龍魂';
const poem = acrosticEngine.generate(headWord, '七言', '通用');
this.resultText = `【藏头】${poem.headWord}\n\n` +
poem.lines.map((line, i) => `第${i + 1}句:${line}`).join('\n');
this.guoxueState.acrostics.push(poem);
}
// 历史人物查询
queryFigure() {
const name = this.inputText;
if (!name) {
this.resultText = '请输入人物名';
return;
}
const figure = figureEngine.query(name);
if (figure) {
this.resultText = `【${figure.name}】${figure.dynasty} ${figure.era}\n\n` +
`性格:${figure.personality}\n\n` +
`主要成就:\n${figure.achievements.map(a => '• ' + a).join('\n')}\n\n` +
`名言:\n${figure.famousQuotes.map(q => '• ' + q).join('\n')}\n\n` +
`相关事件:\n${figure.relatedEvents.map(e => '• ' + e).join('\n')}`;
this.guoxueState.figures.push(figure);
} else {
const results = figureEngine.search(name);
if (results.length > 0) {
this.resultText = `未找到"${name}",您是否想找:\n` +
results.map(f => `• ${f.name}(${f.dynasty})`).join('\n');
} else {
this.resultText = `未找到"${name}",请尝试其他名称`;
}
}
}
// 道德经查询
queryDaoDeJing() {
const input = this.inputText;
if (!input) {
this.resultText = '请输入章节号或关键词';
return;
}
const chapterNum = parseInt(input);
if (!isNaN(chapterNum) && chapterNum >= 1 && chapterNum <= 81) {
const chapter = daoDeJingEngine.getChapter(chapterNum);
if (chapter) {
this.resultText = `【第${chapter.chapter}章】${chapter.title}\n\n` +
`原文:\n${chapter.original}\n\n` +
`译文:\n${chapter.translation}\n\n` +
`解读:\n${chapter.interpretation}\n\n` +
`关键词:${chapter.keywords.join('、')}`;
this.guoxueState.daoChapters.push(chapter);
}
} else {
const results = daoDeJingEngine.searchByKeyword(input);
if (results.length > 0) {
this.resultText = `找到 ${results.length} 章包含"${input}":\n\n` +
results.map(c => `第${c.chapter}章 ${c.title}`).join('\n');
} else {
this.resultText = `未找到包含"${input}"的章节`;
}
}
}
// 河图洛书
showHeTu() {
const heTu = heTuLuoShuEngine.getHeTu();
this.resultText = `【河图】\n\n${heTu.description}\n\n` +
`口诀:\n${heTu.mnemonic.join('\n')}\n\n` +
`矩阵:\n${heTu.matrix.map(row => row.join(' ')).join('\n')}`;
}
showLuoShu() {
const luoShu = heTuLuoShuEngine.getLuoShu();
this.resultText = `【洛书】\n\n${luoShu.description}\n\n` +
`幻和:${luoShu.magicSum}\n\n` +
`口诀:\n${luoShu.mnemonic.join('\n')}\n\n` +
`矩阵:\n${luoShu.matrix.map(row => row.join(' ')).join('\n')}\n\n` +
`验证:${heTuLuoShuEngine.validateLuoShu() ? '✓ 符合幻方' : '✗ 不符合'}`;
}
// 五行八卦查询
queryWuXingBaGua() {
const input = this.inputText;
if (!input) {
this.resultText = '请输入五行(金木水火土)或八卦名(乾坤震巽坎离艮兑)';
return;
}
const wuXing = wuXingBaGuaEngine.getWuXing(input);
const baGua = wuXingBaGuaEngine.getBaGua(input);
if (wuXing) {
this.resultText = `【五行·${wuXing.element}】\n\n` +
`生:${wuXing.generation}\n` +
`克:${wuXing.restriction}\n` +
`色:${wuXing.color}\n` +
`方:${wuXing.direction}\n` +
`季:${wuXing.season}\n` +
`脏:${wuXing.organ}\n` +
`情:${wuXing.emotion}`;
} else if (baGua) {
this.resultText = `【八卦·${baGua.name}】${baGua.symbol}\n\n` +
`自然:${baGua.nature}\n` +
`属性:${baGua.attribute}\n` +
`家人:${baGua.family}\n` +
`方位:${baGua.direction}\n` +
`数字:${baGua.number}\n` +
`五行:${wuXingBaGuaEngine.getBaGuaWuXing(baGua.name)}`;
} else {
// 显示关系
const elements = ['金', '木', '水', '火', '土'];
if (input.length === 2 && elements.includes(input[0]) && elements.includes(input[1])) {
this.resultText = `【五行关系】\n\n${wuXingBaGuaEngine.getRelation(input[0], input[1])}`;
} else {
this.resultText = '请输入正确的五行或八卦名';
}
}
}
// 二十八星宿查询
queryXingXiu() {
const input = this.inputText;
if (!input) {
this.resultText = '请输入星宿名或方向';
return;
}
const xing = xingXiuEngine.getByName(input);
if (xing) {
this.resultText = `【${xing.name}宿】\n\n` +
`方向:${xing.direction}\n` +
`四象:${xing.animal}\n` +
`星座:${xing.constellation}\n` +
`吉凶:${xing.auspicious ? '吉' : '凶'}\n` +
`含义:${xing.meaning}`;
} else {
const directions = xingXiuEngine.getFourAnimals();
if (directions.includes(input)) {
const list = xingXiuEngine.getByDirection(input);
this.resultText = `【${input}七宿】\n\n` +
list.map(x => `• ${x.name}宿 - ${x.meaning.substring(0, 20)}...`).join('\n');
} else {
this.resultText = '请输入正确的星宿名或方向';
}
}
}
// 随机生成
randomGenerate() {
switch (this.selectedTab) {
case 0:
const themes = coupletEngine.getThemes();
this.inputText = themes[Math.floor(Math.random() * themes.length)];
this.generateCouplet();
break;
case 1:
const chars = acrosticEngine.getAvailableChars();
this.inputText = '龍魂中国';
this.generateAcrostic();
break;
case 2:
const figures = figureEngine.getAll();
this.inputText = figures[Math.floor(Math.random() * figures.length)].name;
this.queryFigure();
break;
case 3:
this.inputText = String(Math.floor(Math.random() * 81) + 1);
this.queryDaoDeJing();
break;
case 5:
const allGua = wuXingBaGuaEngine.getAllBaGua();
this.inputText = allGua[Math.floor(Math.random() * allGua.length)].name;
this.queryWuXingBaGua();
break;
case 6:
const allXiu = xingXiuEngine.getAll();
this.inputText = allXiu[Math.floor(Math.random() * allXiu.length)].name;
this.queryXingXiu();
break;
}
}
}
const MASTER_UID = "9622";
六、组件清单
| 文件 | 路径 | 说明 |
|---|---|---|
| 国学数据模型 | entry/src/main/ets/models/GuoxueModel.ets |
所有创作类型的数据模型 |
| 对联引擎 | entry/src/main/ets/engines/CoupletEngine.ets |
平仄对仗规则+主题模板 |
| 藏头诗引擎 | entry/src/main/ets/engines/AcrosticEngine.ets |
首字约束+诗句库 |
| 历史人物引擎 | entry/src/main/ets/engines/HistoricalFigureEngine.ets |
人物数据库+查询 |
| 道德经引擎 | entry/src/main/ets/engines/DaoDeJingEngine.ets |
81章全文+解读 |
| 河图洛书引擎 | entry/src/main/ets/engines/HeTuLuoShuEngine.ets |
数字矩阵+幻方验证 |
| 五行八卦引擎 | entry/src/main/ets/engines/WuXingBaGuaEngine.ets |
生克推演+卦象查询 |
| 二十八宿引擎 | entry/src/main/ets/engines/XingXiuEngine.ets |
星宿数据+四象分组 |
| 主页面 | entry/src/main/ets/pages/GuoxueCreation.ets |
7标签页创作界面 |
七、龍魂标识
| 位置 | 内容 |
|---|---|
| 应用名称 | 龍魂国学创作 |
| 标题栏 | 🐉 龍魂国学创作 |
| 底部标识 | UID:9622 |
| 数据签名 | SM3-哈希 |
| DNA | ZHUGEXIN⚡️2025-🇨🇳🐉⚖️♠️🧚🏼♀️❤️♾️ |
🐉 龍魂 · 鸿蒙AI国学创作应用 交付完成
DNA: ZHUGEXIN⚡️2025-🇨🇳🐉⚖️♠️🧚🏼♀️❤️♾️
UID: 9622
确认码: #CONFIRM🌌9622-ONLY-ONCE🧬LK9X-772Z
时间: 2026-07-14
模块: 9核心文件
特性: 对联生成 · 藏头诗 · 历史人物 · 道德经 · 河图洛书 · 五行八卦 · 二十八星宿 · 国密签名
更多推荐



所有评论(0)