feat: 模型回退 Avalonia 独立窗口;积分精确到 0.01;人品值/二选一接入后端计费

模型(回退 Flutter 内嵌 → Avalonia):
- 恢复 model/_sdk、5 个模型 src/、GC-DRAW/PlayerWindow、ModelHost/AvaloniaHost(源自 5b62897)
- FlutterShell 主线程承载 Avalonia 事件循环,根治 1.1.1 的 AppKit 崩溃
- /api/models/{id}/launch 由后端开独立 Avalonia 窗口
- 前端删除 Flutter 模型实现与 ModelViewPage 死代码(13 个文件)

积分:
- Points/ThemePaid int → decimal,精确到 0.01;pw.yaml 兼容旧整数格式
- 主题色退款保留 2 位小数;前端新增 formatPoints 显示

人品值/二选一计费(原前端本地免费随机 → 后端计费):
- 新增 POST /api/user/fortune、/api/user/pick,随机数与扣费都在服务端
- 人品值阶梯:当日免费 1 次 → 0.1×5 → 0.2×5 → 0.5×15 → 1.0 起
- 二选一:当日免费 1 次 → 0.5/次;计数按 UTC 日期持久化,跨天清零
- 前端两个功能需登录,扣费后提示本次消耗

附 RELEASE-1.1.2.md 更新日志。
This commit is contained in:
远影科技 committed 2026-11-21 21:51:34 +08:00
1 parent 38781c9807
commit cfd6809714
57 files changed
+8300 -1966

No files matched your search

+2
View File
@@ -89,6 +89,8 @@ class _HomePageViewState extends State<HomePageView> {
Future<void> _launch(ModelInfo model) async {
setState(() => _notice = null);
try {
// 模型窗口由后端用 Avalonia 打开(模型契约返回的是 Avalonia Control),
// 前端只负责发这条指令并显示结果。
final result = await widget.controller.api.launchModel(model.id);
if (!mounted) return;
setState(() => _notice = result.message);
-119
View File
@@ -1,119 +0,0 @@
import 'package:flutter/material.dart';
import '../i18n.dart';
import '../models/base.dart';
import '../models/lookup.dart';
import '../theme.dart';
/// 模型视图:在壳内直接渲染 Flutter 模型。
///
/// 以前「启动模型」是让后端另开一个 Avalonia 窗口;现在模型全部是 Flutter 实现,
/// 直接换掉内容区即可 —— 不会多出一个窗口,也不用跨进程传状态。
class ModelViewPage extends StatelessWidget {
const ModelViewPage({
super.key,
required this.modelId,
required this.onClose,
});
final String modelId;
final VoidCallback onClose;
@override
Widget build(BuildContext context) {
final model = flutterModelFor(modelId);
if (model == null) {
return Center(
child: GcCard(
padding: const EdgeInsets.all(GcSpace.xxl),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
T('model.missing'),
style: TextStyle(
fontSize: 15,
height: 1.35,
fontWeight: FontWeight.w600,
color: GcColors.ink,
),
),
const SizedBox(height: GcSpace.sm),
GcHint(T('model.missingHint')),
const SizedBox(height: GcSpace.lg),
OutlinedButton(
onPressed: onClose,
child: Text(T('model.back')),
),
],
),
),
);
}
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Padding(
padding: const EdgeInsets.fromLTRB(
GcSpace.xxl,
GcSpace.lg,
GcSpace.xxl,
GcSpace.sm,
),
child: Row(
children: <Widget>[
OutlinedButton.icon(
onPressed: onClose,
icon: const Icon(Icons.arrow_back_rounded, size: 16),
label: Text(T('model.back')),
),
const SizedBox(width: GcSpace.lg),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
model.name(),
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 16,
height: 1.3,
fontWeight: FontWeight.w600,
color: GcColors.ink,
),
),
const SizedBox(height: 2),
Text(
model.description(),
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 12,
height: 1.4,
color: GcColors.faint,
),
),
],
),
),
],
),
),
Expanded(child: ClipRect(child: _body(model))),
],
);
}
Widget _body(GcModel model) {
// 模型视图自己管状态(动画、视角),换 id 时必须重建,不能复用 State
return KeyedSubtree(
key: ValueKey<String>(model.id),
child: Builder(builder: (context) => model.buildView(context)),
);
}
}
+40 -14
View File
@@ -1,5 +1,3 @@
import 'dart:math';
import 'package:flutter/material.dart';
import '../controller.dart';
@@ -41,8 +39,6 @@ class _UserPageState extends State<UserPage> {
final _option2Ctrl = TextEditingController();
String? _randomResult;
final _rand = Random();
@override
void initState() {
super.initState();
@@ -197,30 +193,60 @@ class _UserPageState extends State<UserPage> {
// ---------------------------------------------------------------- 人品值
void _rollFortune() {
Future<void> _rollFortune() async {
if (_user == null) {
_toast(T('user.loginFirst'));
return;
}
setState(() => _rolling = true);
// 短延时让数字有个「落定」的观感;每天不限次数
Future<void>.delayed(const Duration(milliseconds: 260), () {
try {
// 服务端算随机数和价格:当天第一次免费,之后按当日次数阶梯计费
final resp = await widget.controller.api.rollFortune();
if (!mounted) return;
final value = _rand.nextInt(101);
final value = (resp['value'] as num?)?.toInt() ?? 0;
final cost = (resp['cost'] as num?)?.toDouble() ?? 0;
setState(() {
_fortune = FortuneResult(value, FortuneResult.commentFor(value));
_fortune = FortuneResult(value, resp['comment'] as String? ?? FortuneResult.commentFor(value));
final payload = resp['user'] as Map<String, dynamic>?;
if (payload != null) _user = UserRecord.fromJson(payload);
_rolling = false;
});
});
_toast(cost > 0 ? '本次消耗 ${formatPoints(cost)} 积分' : '今日首次免费');
} catch (e) {
if (!mounted) return;
setState(() => _rolling = false);
_toast(e.toString());
}
}
// ---------------------------------------------------------------- 二选一
void _pickRandom() {
Future<void> _pickRandom() async {
final a = _option1Ctrl.text.trim();
final b = _option2Ctrl.text.trim();
if (a.isEmpty || b.isEmpty) {
_toast(T('user.fillOptions'));
return;
}
setState(() => _randomResult = _rand.nextBool() ? a : b);
if (_user == null) {
_toast(T('user.loginFirst'));
return;
}
try {
// 服务端随机 + 计费:当天第一次免费,之后每次 0.5 积分
final resp = await widget.controller.api.pickOne(a, b);
if (!mounted) return;
final cost = (resp['cost'] as num?)?.toDouble() ?? 0;
setState(() {
_randomResult = resp['choice'] as String?;
final payload = resp['user'] as Map<String, dynamic>?;
if (payload != null) _user = UserRecord.fromJson(payload);
});
_toast(cost > 0 ? '本次消耗 ${formatPoints(cost)} 积分' : '今日首次免费');
} catch (e) {
if (!mounted) return;
_toast(e.toString());
}
}
// ---------------------------------------------------------------- 主题色
@@ -412,7 +438,7 @@ class _UserPageState extends State<UserPage> {
Text(
user == null
? T('user.loginHint')
: '${T('user.points')} ${user.points} · '
: '${T('user.points')} ${formatPoints(user.points)} · '
'${T('user.days')} ${user.consecutiveDays}',
style: TextStyle(color: GcColors.muted, fontSize: 13),
),