Initial commit

This commit is contained in:
ChuXun
2025-12-07 22:53:46 +08:00
commit 5a2d39293d
27 changed files with 3188 additions and 0 deletions

419
pages/strategy/strategy.js Normal file
View File

@@ -0,0 +1,419 @@
// strategy.js
const app = getApp()
Page({
data: {
event: null,
strategies: {
economic: [
{
id: 'economic_1',
title: '调整边币兑换率',
description: '通过合理调整边币与法币的兑换率,稳定币值',
applicable: ['exchange', 'fakeCurrency'],
historyCase: {
title: '1943年陕甘宁边区调整币值案例',
description: '1943年初陕甘宁边区政府通过调整边币与法币兑换率有效应对了币值波动'
}
},
{
id: 'economic_2',
title: '紧缩货币发行',
description: '减少边币发行量,提高现有边币价值',
applicable: ['exchange', 'fakeCurrency', 'shortage'],
historyCase: {
title: '1944年某根据地紧缩货币政策',
description: '1944年某根据地实施紧缩货币政策有效控制了通货膨胀'
}
},
{
id: 'economic_3',
title: '建立物资储备',
description: '组织经济战备,储备重要物资以稳定物价',
applicable: ['shortage', 'exchange'],
historyCase: {
title: '1942年晋察冀边区物资储备计划',
description: '1942年晋察冀边区政府建立战略物资储备有效应对了国民党经济封锁'
}
}
],
administrative: [
{
id: 'admin_1',
title: '查抄伪币窝点',
description: '派出工作组和武装力量,打击伪造边币的犯罪活动',
applicable: ['fakeCurrency'],
historyCase: {
title: '1941年晋冀鲁豫边区打击伪币行动',
description: '1941年晋冀鲁豫边区政府开展了大规模打击伪币活动摧毁多个伪币制造点'
}
},
{
id: 'admin_2',
title: '实施物资配给',
description: '对关键物资实行统一配给制度,确保公平分配',
applicable: ['shortage'],
historyCase: {
title: '1945年山东解放区物资配给制度',
description: '1945年山东解放区实施关键物资配给制度保障了军民基本生活需求'
}
},
{
id: 'admin_3',
title: '设立边币管理委员会',
description: '成立专门机构,统一协调货币政策和币值稳定措施',
applicable: ['fakeCurrency', 'exchange', 'shortage'],
historyCase: {
title: '1940年陕甘宁边区货币管理委员会',
description: '1940年陕甘宁边区成立货币管理委员会统一协调金融政策保障了经济发展'
}
}
],
mobilization: [
{
id: 'mob_1',
title: '开展拒用伪币宣传',
description: '通过各种渠道向民众普及伪币识别知识,动员群众拒绝使用伪币',
applicable: ['fakeCurrency'],
historyCase: {
title: '1943年冀中群众性反伪币运动',
description: '1943年冀中地区开展了声势浩大的反伪币宣传运动有效减少了伪币流通'
}
},
{
id: 'mob_2',
title: '组织互助合作',
description: '发动群众组建互助组和合作社,共同应对物资短缺',
applicable: ['shortage'],
historyCase: {
title: '1942年抗日民主根据地互助合作运动',
description: '1942年多个抗日根据地开展互助合作运动有效缓解了物资短缺问题'
}
},
{
id: 'mob_3',
title: '开展爱用边币运动',
description: '动员群众积极使用边币,增强对根据地货币的信心',
applicable: ['exchange', 'fakeCurrency'],
historyCase: {
title: '1944年晋冀鲁豫边区爱用边币运动',
description: '1944年晋冀鲁豫边区开展爱用边币运动提高了边币的公信力和使用范围'
}
}
]
},
showModal: false,
currentHistoryCase: null,
currentRound: 0,
maxRounds: 3,
selectedStrategies: [],
strategiesUsed: {},
roundTitle: "第1轮 - 初期应对",
isProcessing: false, // 处理状态防止重复点击
isLoading: true, // 加载状态
selectableCount: 0, // 当前可选择的策略数
roundDescriptions: [
"初期应对 - 选择最紧急的措施",
"中期调整 - 加强应对效果",
"后期加强 - 巩固已有成果"
]
},
onLoad: function() {
wx.showLoading({
title: '加载中...',
mask: true
});
try {
// 从全局数据获取选中的事件
const selectedEvent = app.globalData.selectedEvent;
if (selectedEvent) {
// 重置全局状态
app.globalData.selectedStrategies = [];
app.globalData.currentRound = 0;
this.initData(selectedEvent);
} else {
// 如果没有选中事件,创建一个测试事件(用于调试)
const testEvent = {
id: 'fake_currency_1',
type: 'fakeCurrency',
title: '伪币冲击:初级',
description: '敌方在根据地周边地区投放少量伪造边币,市场上开始出现伪币流通现象',
level: 1,
impact: '市场信心轻微下降,边币贬值风险较小'
};
this.initData(testEvent);
wx.showToast({
title: '使用测试数据',
icon: 'none',
duration: 2000
});
}
} catch (error) {
console.error('初始化数据出错:', error);
wx.hideLoading();
wx.showToast({
title: '加载失败,请重试',
icon: 'none',
duration: 2000
});
}
},
// 初始化数据和计算可选择的策略数量
initData: function(eventData) {
try {
// 设置基本数据
this.setData({
event: eventData,
currentRound: 0,
selectedStrategies: [],
strategiesUsed: {},
roundTitle: "第1轮 - 初期应对",
isProcessing: false
});
// 计算可选择的策略数量
let count = 0;
const eventType = eventData.type;
// 遍历所有策略类别
for (const category in this.data.strategies) {
this.data.strategies[category].forEach(strategy => {
if (strategy.applicable && strategy.applicable.indexOf(eventType) > -1) {
count++;
}
});
}
this.setData({
selectableCount: count,
isLoading: false
});
wx.hideLoading();
} catch (error) {
console.error('初始化数据出错:', error);
wx.hideLoading();
wx.showToast({
title: '数据初始化失败',
icon: 'none',
duration: 2000
});
}
},
handleStrategySelect: function(e) {
// 防止重复处理
if (this.data.isProcessing || this.data.showModal) {
return;
}
try {
const strategyType = e.currentTarget.dataset.type;
const strategyId = e.currentTarget.dataset.id;
const isApplicable = e.currentTarget.dataset.applicable;
const isUsed = e.currentTarget.dataset.used;
// 如果不适用或已使用,不处理
if (isApplicable === 'false' || isUsed === 'true') {
wx.vibrateShort(); // 轻微震动提示无法选择
return;
}
// 找到选中的策略
const selectedStrategy = this.data.strategies[strategyType].find(item => item.id === strategyId);
if (selectedStrategy) {
// 设置处理中状态
this.setData({
isProcessing: true
});
// 轻微振动反馈
wx.vibrateShort({
type: 'light'
});
// 标记该策略已使用
let newStrategiesUsed = {...this.data.strategiesUsed};
newStrategiesUsed[selectedStrategy.id] = true;
// 添加到已选策略列表
let newSelectedStrategies = [...this.data.selectedStrategies];
newSelectedStrategies.push({
round: this.data.currentRound + 1,
strategy: selectedStrategy
});
// 更新到全局数据
app.globalData.selectedStrategies = newSelectedStrategies;
// 显示历史案例模态框
this.setData({
showModal: true,
currentHistoryCase: selectedStrategy.historyCase,
strategiesUsed: newStrategiesUsed,
selectedStrategies: newSelectedStrategies
});
}
} catch (error) {
console.error('选择策略出错:', error);
this.setData({
isProcessing: false
});
wx.showToast({
title: '操作失败,请重试',
icon: 'none',
duration: 2000
});
}
},
closeModal: function() {
// 如果还在处理中,防止重复点击
if (!this.data.showModal) {
return;
}
try {
// 先关闭模态框
this.setData({
showModal: false,
currentHistoryCase: null
});
// 增加轮次
const newRound = this.data.currentRound + 1;
app.globalData.currentRound = newRound;
// 如果达到最大轮次,跳转到结果页面
if (newRound >= this.data.maxRounds) {
wx.showToast({
title: '策略选择完成',
icon: 'success',
duration: 1000,
mask: true
});
setTimeout(() => {
this.navigateToResults();
}, 1000);
} else {
// 否则继续下一轮
let roundTitle = "";
if (newRound === 1) {
roundTitle = "第2轮 - 中期调整";
} else if (newRound === 2) {
roundTitle = "第3轮 - 后期加强";
}
// 更新当前轮次状态
this.setData({
currentRound: newRound,
roundTitle: roundTitle,
isProcessing: false // 重置处理状态
});
wx.showToast({
title: `进入${roundTitle}`,
icon: 'none',
duration: 1500
});
}
} catch (error) {
console.error('关闭模态框出错:', error);
this.setData({
isProcessing: false
});
wx.showToast({
title: '操作失败,请重试',
icon: 'none',
duration: 2000
});
}
},
// 添加返回首页的函数
navigateBack: function() {
wx.showModal({
title: '确认返回',
content: '返回将丢失当前已选择的策略,确定返回吗?',
success: (res) => {
if (res.confirm) {
wx.navigateBack();
}
}
});
},
preventBubble: function(e) {
// 阻止冒泡,防止点击内容区域关闭模态框
return;
},
// 提前结束,直接查看结果
finishEarly: function() {
if (this.data.selectedStrategies.length > 0) {
wx.showModal({
title: '确认完成',
content: '确定结束当前决策过程,直接查看结果吗?',
success: (res) => {
if (res.confirm) {
this.navigateToResults();
}
}
});
} else {
wx.showToast({
title: '请至少选择一个策略',
icon: 'none'
});
}
},
// 跳转到结果页面的统一方法
navigateToResults: function() {
wx.navigateTo({
url: '/pages/result/result',
success: () => {
console.log('跳转到结果页面');
// 跳转成功后重置处理状态
this.setData({
isProcessing: false
});
},
fail: (err) => {
console.error('跳转失败', err);
wx.showToast({
title: '跳转失败,请重试',
icon: 'none'
});
this.setData({
isProcessing: false
});
}
});
},
// 生命周期函数
onShareAppMessage: function() {
return {
title: '边区危机应对策略小游戏',
path: '/pages/index/index',
imageUrl: '/images/share-img.jpg' // 需要提供分享图片
};
},
// 页面卸载时清理
onUnload: function() {
// 取消可能存在的定时器
if (this.navigateTimer) {
clearTimeout(this.navigateTimer);
}
}
})