越秀定制型网站建设,网页制作软件绿色版,别人的域名解析到了我的网站上,新网和中企动力什么关系欢迎大家加入开源鸿蒙跨平台开发者社区#xff0c;一起共建开源鸿蒙跨平台生态。 修剪管理系统概述
修剪是植物养护的重要环节#xff0c;它促进植物的生长和塑形。在Cordova框架与OpenHarmony系统的结合下#xff0c;我们需要实现一个完整的修剪记录系统#xff0c;包括修…欢迎大家加入开源鸿蒙跨平台开发者社区一起共建开源鸿蒙跨平台生态。修剪管理系统概述修剪是植物养护的重要环节它促进植物的生长和塑形。在Cordova框架与OpenHarmony系统的结合下我们需要实现一个完整的修剪记录系统包括修剪记录的创建、查询、统计和提醒功能。这个系统需要记录修剪的类型、位置和效果。修剪记录数据模型classPruningType{constructor(id,name,description,purpose){this.idid;this.namename;this.descriptiondescription;this.purposepurpose;// 修剪目的}}classPruningRecord{constructor(plantId,pruningType,location,notes){this.idprune_Date.now();this.plantIdplantId;this.pruningTypepruningType;this.locationlocation;// 修剪位置this.datenewDate();this.notesnotes;this.branchesRemoved0;// 移除的枝条数}}classPruningManager{constructor(){this.records[];this.pruningTypes[];this.initDefaultPruningTypes();this.loadFromStorage();}initDefaultPruningTypes(){this.pruningTypes[newPruningType(prune_1,轻修剪,移除枯死或病弱枝条,清理),newPruningType(prune_2,中度修剪,塑形和促进分枝,塑形),newPruningType(prune_3,重度修剪,大幅度修剪以促进新生长,更新),newPruningType(prune_4,摘心,移除顶端生长点,促进分枝)];}addPruningRecord(plantId,pruningType,location,notes){constrecordnewPruningRecord(plantId,pruningType,location,notes);this.records.push(record);this.saveToStorage();returnrecord;}}这个修剪记录数据模型定义了PruningType、PruningRecord和PruningManager类。PruningType类定义了修剪类型及其目的PruningRecord类记录每次修剪的详细信息PruningManager类管理所有修剪记录。与OpenHarmony数据库的集成functionsavePruningRecordToDatabase(record){cordova.exec(function(result){console.log(修剪记录已保存到数据库);},function(error){console.error(保存失败:,error);},DatabasePlugin,savePruningRecord,[{id:record.id,plantId:record.plantId,pruningType:record.pruningType,location:record.location,date:record.date.toISOString(),notes:record.notes,branchesRemoved:record.branchesRemoved}]);}functionloadPruningRecordsFromDatabase(){cordova.exec(function(result){console.log(修剪记录已从数据库加载);pruningManager.recordsresult.map(rec{constrecordnewPruningRecord(rec.plantId,rec.pruningType,rec.location,rec.notes);record.idrec.id;record.datenewDate(rec.date);record.branchesRemovedrec.branchesRemoved;returnrecord;});renderPruningRecords();},function(error){console.error(加载失败:,error);},DatabasePlugin,loadPruningRecords,[]);}这段代码展示了如何与OpenHarmony的数据库进行交互。savePruningRecordToDatabase函数将修剪记录保存到数据库loadPruningRecordsFromDatabase函数从数据库加载所有修剪记录。通过这种方式我们确保了修剪数据的持久化存储。修剪记录列表展示functionrenderPruningRecords(plantId){constplantplants.find(pp.idplantId);if(!plant)return;constrecordspruningManager.records.filter(rr.plantIdplantId).sort((a,b)newDate(b.date)-newDate(a.date));constcontainerdocument.getElementById(page-container);container.innerHTMLdiv classpruning-records-container h2${plant.name}的修剪记录/h2 button classadd-record-btn onclickshowAddPruningRecordDialog(${plantId}) ✂️ 添加修剪记录 /button /div;if(records.length0){container.innerHTMLp classempty-message还没有修剪记录/p;return;}constrecordsListdocument.createElement(div);recordsList.classNamerecords-list;records.forEach(record{constpruningTypepruningManager.pruningTypes.find(pp.idrecord.pruningType);constrecordItemdocument.createElement(div);recordItem.classNamerecord-item;recordItem.innerHTMLdiv classrecord-info p classrecord-date${record.date.toLocaleString(zh-CN)}/p p classpruning-type✂️ 修剪类型:${pruningType?.name||未知}/p p classpruning-purpose目的:${pruningType?.purpose||N/A}/p p classpruning-location位置:${record.location}/p p classbranches-removed移除枝条:${record.branchesRemoved}条/p${record.notes?p classrecord-notes备注:${record.notes}/p:}/div div classrecord-actions button onclickeditPruningRecord(${record.id})编辑/button button onclickdeletePruningRecord(${record.id})删除/button /div;recordsList.appendChild(recordItem);});container.appendChild(recordsList);}这个函数负责渲染修剪记录列表。它显示了特定植物的所有修剪记录包括日期、修剪类型、目的、位置和移除的枝条数。用户可以通过编辑和删除按钮管理记录。这种设计提供了清晰的记录展示。添加修剪记录对话框functionshowAddPruningRecordDialog(plantId){constdialogdocument.createElement(div);dialog.classNamemodal-dialog;letpruningTypeOptions;pruningManager.pruningTypes.forEach(type{pruningTypeOptionsoption value${type.id}${type.name}-${type.purpose}/option;});dialog.innerHTMLdiv classmodal-content h3添加修剪记录/h3 form idadd-pruning-form div classform-group label修剪类型/label select idpruning-type required option value请选择修剪类型/option${pruningTypeOptions}/select /div div classform-group label修剪位置/label input typetext idpruning-location placeholder例如: 顶端、左侧枝条 required /div div classform-group label移除枝条数/label input typenumber idbranches-removed min0 value0 /div div classform-group label修剪日期/label input typedatetime-local idpruning-date required /div div classform-group label备注/label textarea idpruning-notes/textarea /div div classform-actions button typesubmit保存/button button typebutton onclickcloseDialog()取消/button /div /form /div;document.getElementById(modal-container).appendChild(dialog);constnownewDate();document.getElementById(pruning-date).valuenow.toISOString().slice(0,16);document.getElementById(add-pruning-form).addEventListener(submit,function(e){e.preventDefault();constpruningTypedocument.getElementById(pruning-type).value;constlocationdocument.getElementById(pruning-location).value;constbranchesRemovedparseInt(document.getElementById(branches-removed).value);constdatenewDate(document.getElementById(pruning-date).value);constnotesdocument.getElementById(pruning-notes).value;constrecordnewPruningRecord(plantId,pruningType,location,notes);record.datedate;record.branchesRemovedbranchesRemoved;pruningManager.records.push(record);pruningManager.saveToStorage();savePruningRecordToDatabase(record);closeDialog();renderPruningRecords(plantId);showToast(修剪记录已添加);});}这个函数创建并显示添加修剪记录的对话框。用户可以选择修剪类型、输入位置、枝条数、日期和备注。提交后新记录会被添加到pruningManager中并保存到数据库。修剪统计功能classPruningStatistics{constructor(pruningManager){this.pruningManagerpruningManager;}getTotalPruningCount(plantId){returnthis.pruningManager.records.filter(rr.plantIdplantId).length;}getTotalBranchesRemoved(plantId){constrecordsthis.pruningManager.records.filter(rr.plantIdplantId);returnrecords.reduce((sum,r)sumr.branchesRemoved,0);}getMostCommonPruningType(plantId){constrecordsthis.pruningManager.records.filter(rr.plantIdplantId);consttypeCounts{};records.forEach(record{typeCounts[record.pruningType](typeCounts[record.pruningType]||0)1;});constmostCommonObject.keys(typeCounts).reduce((a,b)typeCounts[a]typeCounts[b]?a:b);returnthis.pruningManager.pruningTypes.find(pp.idmostCommon);}getPruningFrequency(plantId,days30){constrecordsthis.pruningManager.records.filter(rr.plantIdplantId);constcutoffDatenewDate();cutoffDate.setDate(cutoffDate.getDate()-days);constrecentRecordsrecords.filter(rnewDate(r.date)cutoffDate);return(recentRecords.length/days*7).toFixed(2);// 每周修剪次数}}这个PruningStatistics类提供了修剪的统计功能。getTotalPruningCount返回修剪总次数getTotalBranchesRemoved计算移除的总枝条数getMostCommonPruningType返回最常用的修剪类型getPruningFrequency计算修剪频率。这些统计信息可以帮助用户了解修剪规律。修剪提醒功能functioncheckPruningReminders(){plants.forEach(plant{constlastPruningDategetLastPruningDate(plant.id);constpruningIntervalplant.pruningInterval||30;// 默认30天if(!lastPruningDate){sendPruningReminder(plant.id,plant.name,从未修剪过);return;}constdaysSincePruningMath.floor((newDate()-newDate(lastPruningDate))/(24*60*60*1000));if(daysSincePruningpruningInterval){sendPruningReminder(plant.id,plant.name,已${daysSincePruning}天未修剪);}});}functionsendPruningReminder(plantId,plantName,message){cordova.exec(function(result){console.log(修剪提醒已发送);},function(error){console.error(提醒发送失败:,error);},NotificationPlugin,sendReminder,[{title:${plantName}需要修剪,message:message,plantId:plantId,type:pruning}]);}functiongetLastPruningDate(plantId){constrecordspruningManager.records.filter(rr.plantIdplantId).sort((a,b)newDate(b.date)-newDate(a.date));returnrecords.length0?records[0].date:null;}setInterval(checkPruningReminders,60*60*1000);// 每小时检查一次这段代码实现了修剪提醒功能。checkPruningReminders函数检查所有植物如果某个植物超过设定的修剪间隔就发送提醒。通过NotificationPlugin我们可以向用户发送系统通知。修剪效果追踪classPruningEffectTracking{constructor(){this.effectRecordsnewMap();// 修剪ID - 效果数据}recordPruningEffect(pruningRecordId,newGrowthDays,growthRate){this.effectRecords.set(pruningRecordId,{recordedDate:newDate(),newGrowthDays:newGrowthDays,// 新生长出现的天数growthRate:growthRate// 生长速率});}getPruningEffect(pruningRecordId){returnthis.effectRecords.get(pruningRecordId);}}这个PruningEffectTracking类用于追踪修剪的效果。通过记录修剪后新生长出现的时间和生长速率用户可以评估修剪的效果。总结修剪记录系统是植物养护应用的重要功能。通过合理的数据模型设计、与OpenHarmony系统的集成和各种统计分析功能我们可以创建一个功能完整的修剪管理系统帮助用户科学地管理植物的修剪。