1/* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 * 15*/ 16 17// src/main/ets/model/TaskListModel.ets 18 19import { common } from '@kit.AbilityKit'; 20import util from '@ohos.util'; 21import TaskModel from'./TaskModel'; 22 23export default class TaskListModel { 24 public tasks: TaskModel[] = []; 25 26 constructor(tasks: TaskModel[]) { 27 this.tasks = tasks; 28 } 29 30 async loadTasks(context: common.UIAbilityContext){ 31 let getJson = await context.resourceManager.getRawFileContent('defaultTasks.json'); 32 let textDecoderOptions: util.TextDecoderOptions = { ignoreBOM : true }; 33 let textDecoder = util.TextDecoder.create('utf-8',textDecoderOptions); 34 let result = textDecoder.decodeToString(getJson); 35 this.tasks =JSON.parse(result).map((task: TaskModel)=>{ 36 let newTask = new TaskModel(); 37 newTask.taskName = task.taskName; 38 newTask.isFinish = task.isFinish; 39 return newTask; 40 }); 41 } 42}