1/* 2 * Copyright (c) 2023-2023 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 */ 15import { Log, PrintJob, PrintJobOptions, StringUtil } from '@ohos/common'; 16 17const TAG: string = 'PrintPageModel'; 18/** 19 * 打印任务界面显示的每一行Item数据 20 */ 21export class PrintJobItem { 22 /** 23 * jobId 24 */ 25 jobId: string = ''; 26 /** 27 * 文件数量 28 */ 29 fileNum: number = 1; 30 /** 31 * 打印任务Title-文件名称 32 */ 33 jobTitleText: string = ''; 34 /** 35 * 打印任务详情-参数项 36 */ 37 jobDescriptionText: string = ''; 38 /** 39 * 任务状态描述 40 */ 41 jobStateStrName: string = ''; 42 /** 43 * 打印任务删除按钮是否隐藏 44 */ 45 isHideCancelBtn: boolean = true; 46 /** 47 * 打印任务是否block 48 */ 49 jobStateColor: Resource; 50 51 constructor(job: PrintJob, isHideCancelBtn: boolean, jobStateColor: Resource, jobStateStrName: string) { 52 this.jobId = job.jobId; 53 this.isHideCancelBtn = isHideCancelBtn; 54 this.jobStateStrName = jobStateStrName; 55 this.jobStateColor = jobStateColor; 56 try { 57 let optObj: PrintJobOptions = JSON.parse(job.options); 58 this.fileNum = optObj?.jobNum ?? 1; 59 this.jobTitleText = optObj?.jobName ?? ''; 60 this.jobDescriptionText = optObj?.jobDescription ?? ''; 61 } catch (err) { 62 Log.error(TAG, `PrintJobItem constructor failed, parse Options err:${JSON.parse(err)}`); 63 } 64 } 65 66 toString(): string { 67 return `[PrintJobItem jobId:${this.jobId} , fileNum:${this.fileNum}, jobTitleText:${StringUtil.encodeCommonString(this.jobTitleText)}, 68jobDescriptionText:${this.jobDescriptionText}, jobStateStrName:${this.jobStateStrName}, isHideCancelBtn:${this.isHideCancelBtn}, 69jobStateColor:${this.jobStateColor} ]`; 70 } 71 72 getKey(): string { 73 return this.jobId + '_' + this.jobStateStrName; 74 } 75} 76 77@Observed 78export class ShowTips { 79 /** 80 * 是否显示横幅提示 81 */ 82 isShowTips: boolean = false; 83 /** 84 * 横幅提示内容 85 */ 86 showTipsText: string = ''; 87 /** 88 * 横幅提示文本字体颜色 89 */ 90 fontColor: Resource = $r('sys.color.ohos_id_color_warning'); 91 /** 92 * 横幅提示图标 93 */ 94 icon: Resource = $r('app.media.ic_printer_tips'); 95 96 toString(): string { 97 return `[ShowTips isShowTips:${this.isShowTips}, showTipsText:${this.showTipsText} ]`; 98 } 99} 100 101/** 102 * 任务列表界面数据 103 */ 104export class PageData { 105 tips: ShowTips; 106 uiJobQueue: Array<PrintJobItem> = []; 107 108 constructor(tips: ShowTips, uiJobQueue: Array<PrintJobItem>) { 109 this.tips = tips; 110 this.uiJobQueue = uiJobQueue; 111 } 112 113 toString(): string { 114 let ret: string = '[PageData tips: ' + this.tips.toString(); 115 for (let i = 0; i < this.uiJobQueue.length; i++) { 116 ret += this.uiJobQueue[i].toString(); 117 } 118 ret += ']'; 119 return ret; 120 } 121}