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 */ 15 16import { MediaTypeCode, MediaTypes, PrintJobOptions } from '@ohos/common'; 17import WifiP2pHelper from '../Common/Adapter/WifiP2pHelper'; 18import FileModel from '../Model/FileModel'; 19import SelectionModel from '../Model/SelectionModel'; 20import { WLANConfirmDialog, PrintingSelectDialog, alarmDialog, connectConfirmDialog } from './component/CusDialogComp'; 21import { 22 PrinterSelection, 23 MediaSizeSelection, 24 DirectionSelection, 25 MediaTypeSelection, 26 QualitySelection, 27 DuplexSelection 28} from './component/SelectComponent'; 29import { MediaSize, MediaSizeUtil } from '@ohos/common'; 30import { StringUtil } from '@ohos/common'; 31import { PreviewComponent } from './component/PreviewComponent'; 32import { ErrorCode, PrintPageSize, PreviewAttribute, PrinterRange, PrintMargin, PrinterCapability, PrinterInfo, PrinterState } from '@ohos/common'; 33import { PrintJob } from '../Model/PrintJob' 34import PrintAdapter from '../Common/Adapter/PrintAdapter'; 35import { GlobalThisHelper, GlobalThisStorageKey} from '@ohos/common'; 36import FileUtil from '../Common/Utils/FileUtil'; 37import CheckEmptyUtils from '@ohos/common'; 38import { CopyUtil } from '@ohos/common'; 39import { 40 Constants, 41 AppCommonEvent, 42 AppStorageKeyName, 43 PrintRangeType, 44 PrintQuality, 45 Duplex, 46 PageDirection, 47 ColorCode, 48 MediaType, 49 MouseState 50} from '@ohos/common'; 51import { Log } from '@ohos/common'; 52import { uuidGenerator } from '@ohos/common'; 53import { BISHENG_PRINTER } from '@ohos/common'; 54import emitter from '@ohos.events.emitter'; 55// @ts-ignore 56import print from '@ohos.print'; 57import promptAction from '@ohos.promptAction'; 58import common from '@ohos.app.ability.common'; 59import {CancelButton} from './component/BaseComponent'; 60import image from '@ohos.multimedia.image'; 61import { AboutPageComponent } from './component/AboutPageComponent'; 62 63const TAG = 'PrintPage'; 64 65 66@Entry 67@Component 68struct Index { 69 @Provide('ImageCount') imageCount: number = Constants.NUMBER_1;//预览显示的页数 70 @Provide('CurrentIndex') currentIndex: number = Constants.NUMBER_1; 71 @Provide('Printer') @Watch('onPrinterChange') printer: PrinterInfo = undefined //打印机 72 @Provide('ShowPageNum') showPageNum: number = Constants.NUMBER_1 73 @Provide('PrinterList') printerList: Array<PrinterInfo> = []; 74 @Provide('PrintJob') printJob: PrintJob = undefined; 75 @Provide('UsedPrinterId') usedPrinterId: string = undefined; 76 @Provide('PrintAdapter') adapter: PrintAdapter = undefined; 77 @Provide('ConnectCountDown') connectCount: number = Constants.CONNECT_COUNT; 78 @Provide('ConnectCountDownTimer') ConnectTimer: number = undefined 79 @Provide('CanPrint') canPrint: boolean = false; 80 @Provide('WLANFlag') wlanFlag: boolean = false; 81 @Provide('IsNeedListenWlan') isNeedListenWlan: boolean = false; 82 @Provide('ConnectingPrinterId') connectingPrinterId: string = Constants.DEFAULT_CONNECTING_PRINTER_ID; 83 @Provide('ConnectingPrinterName') connectingPrinterName: string = undefined; 84 @Provide('PrinterSelectArray') printerSelectArray: Array<SelectionModel> = []; 85 @Provide('CurrentPrinter') currentPrinterSelection: SelectionModel = SelectionModel.NO_Printer; 86 @Provide('MediaSizeSelectArray') mediaSizeSelectArray: Array<SelectionModel> = []; 87 @Provide('CurrentMediaSize') @Watch('updateMediaSize') currentMediaSize: SelectionModel = SelectionModel.MediaSize_ISO_A4; 88 @Provide('DirectionSelectArray') directionSelectArray: Array<SelectionModel> = []; 89 @Provide('CurrentDirection') @Watch('updateDirection') currentDirection: SelectionModel = SelectionModel.Direction_AUTO; 90 @Provide('MediaTypeSelectArray') mediaTypeSelectArray: Array<SelectionModel> = []; 91 @Provide('CurrentMediaType') @Watch('updateMediaType') currentMediaType: SelectionModel = SelectionModel.MediaType_NORMAL; 92 @Provide('QualitySelectArray') qualitySelectArray: Array<SelectionModel> = []; 93 @Provide('CurrentQuality') currentQuality: SelectionModel = SelectionModel.PrintQuality_STANDARD; 94 @Provide('DuplexSelectArray') duplexSelectArray: Array<SelectionModel> = []; 95 @Provide('CurrentDuplex') currentDuplex: SelectionModel = SelectionModel.DuplexMode_SINGLE; 96 @Provide('PrintRange') printRange: Array<number> = []; //打印范围 97 @Provide('NeedDuplex') @Watch('needDuplexChange')needDuplex: boolean = true; 98 @Provide('IsBorderless') isBorderless: boolean = false //是否无边距 99 @Provide('IsPreviewFailed') isPreviewFailed: boolean = false //是否需要显示预览失败图示 100 private abilityContext: common.UIAbilityContext = undefined 101 @State @Watch('updateImageSources')imageSources: Array<FileModel> = undefined; 102 @State startPage: number = Constants.NUMBER_1 //打印范围起始页 103 @State startPageStr: string = Constants.STRING_ONE //打印范围起始页 104 @State endPage: number = Constants.NUMBER_1 //打印范围终止页 105 @State endPageStr: string = Constants.STRING_ONE //打印范围终止页 106 @State printCount: number = Constants.NUMBER_1 //份数 107 @State printCountStr: string = Constants.STRING_ONE //份数 108 @State isColored: boolean = false //是否彩印 109 @State isColorEnabled: boolean = true //是否支持彩印 110 @State isDuplexEnabled: boolean = true //是否支持双面 111 @State isPhotoEnabled: boolean = true //是否支持相片纸 112 @State isPlusPressed: boolean = false //是否按下份数+ 113 @State plusMouseState: number = MouseState.NONE //份数+ 114 @State minusMouseState: number = MouseState.NONE //份数- 115 @State isMinusPressed: boolean = false //是否按下份数- 116 @State mediaSizeList: Array<MediaSize> = undefined; //所有纸张尺寸 117 @State printRangeType: number = PrintRangeType.ALL; //打印范围类型 0:全部页面 1:范围打印 118 @State colorMode: number = ColorCode.MONOCHROME; 119 @State mediaSize: MediaSize = MediaSize.ISO_A4; //纸张尺寸 120 @State pageDirection: number = Constants.NUMBER_0; //纸张方向 121 @State printerRange: PrinterRange = undefined; //打印框架需要的参数,实际不起效 122 @State printerPageSize: PrintPageSize = undefined; //纸张尺寸 123 @State alarmText: string = undefined; 124 @State lastPrinterExist: boolean = false; 125 @State isConnected: boolean = false; 126 @State printerCap: print.PrinterCapability = undefined; 127 @State printButtonFlag: boolean = true; 128 @State cusRangeBorderColor: Resource = $r('app.color.border_line'); 129 @State errorMessage: Resource = undefined; 130 @State isCusRangeError: boolean = false; 131 @State isCusRangeMax: boolean = false; 132 @State cusRangeArr: Array<number> = []; 133 @State cusRangeText: string = undefined; 134 @State isRangeRadioEnable: boolean = false; 135 @State isCustomRadioEnable: boolean = false; 136 @State isAbovePageLimit: boolean = false;//是否超过页数限制 137 @State printParamCompHeight: number = 0;//参数区组件高度 138 @Provide('PreviewCompHeight') previewCompHeight: number = 0;//预览区组件高度 139 @Provide('IsGlobalDisable') isGlobalDisable: boolean = false; 140 @Provide('PrinterSelectFlag') @Watch('openPrinterSelectDialog') printerSelectFlag: boolean = false; 141 @Provide('OpenWLANFlag') @Watch('openWLANDialog') openWlanFlag: boolean = true; 142 @Provide('ConnectFlag') @Watch('connectAlarm') connectFlag: boolean = true; 143 @StorageLink('JobQueue') jobQueue: Array<PrintJob> = new Array(); 144 private usedPrinterFileName: string = 'lastUsedPrinter' 145 private firstFileName: string = undefined 146 private totalPage: number = Constants.NUMBER_1//总页数 147 private allPages: Array<number> = []; 148 private jobName: string = Constants.STRING_NONE 149 private jobNum: number = Constants.NUMBER_1 150 private jobDes: string = Constants.STRING_NONE 151 private jobId: string = Constants.STRING_NONE 152 private jobFileList: Array<string> = [] 153 private supportedMediaTypes: Array<string> = [] 154 private scroller: Scroller = new Scroller() 155 private firstStartPageEdit: boolean = true 156 private firstEndPageEdit: boolean = true 157 private editCusRangeFlag: boolean = true//自定义输入框自动置空时为false,不触发编辑 158 private rangeInputLimit: number = Constants.NUMBER_3 //范围输入框位数限制 159 private firstPrinterDiscoveredFlag: boolean = false; 160 private changeRangeTypeFlag: boolean = true;//范围框radio选中是否让startPage输入框获焦 161 private fileNum: number = Constants.NUMBER_0; 162 163 WLANConfirmDialogCtl: CustomDialogController = new CustomDialogController({ 164 builder: WLANConfirmDialog(), 165 alignment: DialogAlignment.Center, 166 autoCancel: false, 167 customStyle: true, 168 }) 169 PrintingSelectDialogCtl: CustomDialogController = new CustomDialogController({ 170 builder: PrintingSelectDialog(), 171 alignment: DialogAlignment.Center, 172 autoCancel: false, 173 customStyle: true, 174 }) 175 alarmDialogCtl: CustomDialogController = new CustomDialogController({ 176 builder: alarmDialog({ alarmText: this.alarmText }), 177 alignment: DialogAlignment.Center, 178 autoCancel: false, 179 customStyle: true, 180 }) 181 connectConfirmDialogCtl: CustomDialogController = new CustomDialogController({ 182 builder: connectConfirmDialog(), 183 alignment: DialogAlignment.Center, 184 autoCancel: false, 185 customStyle: true, 186 }) 187 188 build() { 189 Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) { 190 // 预览组件 191 PreviewComponent({ 192 pageDirection: $pageDirection, 193 colorMode: $colorMode, 194 mediaSize: $mediaSize, 195 imageSources: $imageSources 196 }) 197 .height('40%') 198 .onAreaChange((oldValue: Area, newValue: Area) => { 199 Log.info(`Ace: on area change, oldValue is ${JSON.stringify(oldValue)} value is ${JSON.stringify(newValue)}`) 200 this.previewCompHeight = <number>newValue.height; 201 this.printParamCompHeight = this.previewCompHeight*1.5 202 }) 203 Column() { 204 Scroll(this.scroller) { 205 Column() { 206 PrinterSelection() 207 Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center }) { 208 Text($r('app.string.index_add_copies')) 209 .fontSize($r('app.float.font_size_body2')) 210 .width($r('app.float.text_label_width')) 211 .textAlign(TextAlign.End) 212 .key('Index_Text_copies') 213 .focusable(true) 214 TextInput({ text: this.printCountStr }) 215 .type(InputType.Number) 216 .maxLength(Constants.NUMBER_2) 217 .fontSize($r('app.float.font_size_body2')) 218 .border({ 219 width: $r('app.float.border_width'), 220 radius: $r('app.float.radius_s'), 221 color: $r('app.color.border_line') 222 }) 223 .backgroundColor(Color.White) 224 .width($r('app.float.print_copies_textInput_width')) 225 .height($r('app.float.params_comp_height')) 226 .margin({ 227 left: $r('app.float.print_copies_textInput_left_margin'), 228 right: $r('app.float.print_copies_textInput_right_margin') 229 }) 230 .key('Index_TextInput_copies') 231 .onChange((value: string) => { 232 Log.info(TAG, 'copies onChange value:' + value) 233 this.printCount = Number.parseInt(value) 234 this.printCountStr = value//规避前置0输入 235 this.printCountStr = this.printCount.toString() 236 Log.info(TAG, 'copies onChange printCount:' + this.printCount) 237 if (Number.isNaN(this.printCount)) { 238 this.printCount = Constants.NUMBER_1 239 this.printCountStr = Constants.STRING_NONE 240 } 241 if (this.printCount < Constants.NUMBER_1) { 242 this.printCount = Constants.NUMBER_1 243 } 244 if (this.printCount > Constants.NUMBER_99||this.printCount >= Number.MAX_VALUE) { 245 this.printCount = Constants.NUMBER_99 246 } 247 }) 248 .onSubmit(() => { 249 this.printCountStr = Constants.STRING_NONE 250 this.printCountStr = this.printCount.toString() 251 }) 252 .onBlur(() => { 253 this.printCountStr = '' 254 this.printCountStr = this.printCount.toString() 255 Log.info(TAG,'copies onBlur printCountStr: ',this.printCountStr) 256 }) 257 .onTouch((e:TouchEvent)=>{ 258 e.stopPropagation() 259 }) 260 .onMouse((e:MouseEvent)=>{ 261 e.stopPropagation() 262 }) 263 Column() { 264 Image(this.getPlusImage(this.plusMouseState,this.printCount < Constants.NUMBER_99)) 265 .width($r('app.float.print_copies_image_width')) 266 .height($r('app.float.print_copies_image_height')) 267 .enabled(this.printCount < Constants.NUMBER_99) 268 .key('Index_Image_plus_copies') 269 .onClick(() => { 270 if (this.printCount < Constants.NUMBER_99) { 271 this.printCount++ 272 this.printCountStr = this.printCount.toString() 273 } 274 }) 275 .onTouch((event: TouchEvent) => { 276 if (event.type === TouchType.Down) { 277 this.plusMouseState = MouseState.PRESS 278 } 279 if (event.type === TouchType.Up) { 280 this.plusMouseState = MouseState.NONE 281 } 282 }) 283 .onHover((isHover: boolean) => { 284 if (isHover) { 285 this.plusMouseState = MouseState.HOVER 286 } else { 287 this.plusMouseState = MouseState.NONE 288 } 289 }) 290 Image(this.getMinusImage(this.minusMouseState,this.printCount > Constants.NUMBER_1)) 291 .width($r('app.float.print_copies_image_width')) 292 .height($r('app.float.print_copies_image_height')) 293 .enabled(this.printCount > Constants.NUMBER_1) 294 .key('Index_Image_minus_copies') 295 .onClick(() => { 296 if (this.printCount > Constants.NUMBER_1) { 297 this.printCount-- 298 this.printCountStr = this.printCount.toString() 299 } 300 }) 301 .onTouch((event: TouchEvent) => { 302 if (event.type === TouchType.Down) { 303 this.minusMouseState = MouseState.PRESS 304 } 305 if (event.type === TouchType.Up) { 306 this.minusMouseState = MouseState.NONE 307 } 308 }) 309 .onHover((isHover: boolean) => { 310 if (isHover) { 311 this.minusMouseState = MouseState.HOVER 312 } else { 313 this.minusMouseState = MouseState.NONE 314 } 315 }) 316 } 317 .width($r('app.float.print_copies_image_width')) 318 .height($r('app.float.params_comp_height')) 319 320 Text($r('app.string.ColorMode')) 321 .key('Index_Text_color') 322 .fontSize($r('app.float.font_size_body2')) 323 .height($r('app.float.params_comp_height')) 324 .margin({ 325 left: $r('app.float.text_colorMode_left_margin'), 326 right: $r('app.float.text_colorMode_right_margin') 327 }) 328 .textAlign(TextAlign.Start) 329 .visibility(this.isColorEnabled ? Visibility.Visible : Visibility.None) 330 Toggle({ type: ToggleType.Switch, isOn: !this.isColored }) 331 .key('Index_Toggle_color') 332 .width($r('app.float.toggle_colorMode_width')) 333 .margin({ right: $r('app.float.toggle_colorMode_right_margin') }) 334 .alignSelf(ItemAlign.Center) 335 .visibility(this.isColorEnabled ? Visibility.Visible : Visibility.None) 336 .onChange((isOn: boolean) => { 337 this.isColored = !isOn 338 Log.info(TAG, 'ColorMode onChange: ' + this.isColored) 339 if (this.isColored) { 340 this.colorMode = ColorCode.COLOR 341 } else { 342 this.colorMode = ColorCode.MONOCHROME 343 } 344 }) 345 } 346 .height($r('app.float.params_row_height')) 347 .width($r('app.float.params_row_width')) 348 349 Column() { 350 Row() { 351 Text($r('app.string.index_page_range')) 352 .fontSize($r('app.float.font_size_body2')) 353 .width($r('app.float.text_label_width')) 354 .textAlign(TextAlign.End) 355 .key('Index_Text_pageRange') 356 Radio({ value: 'Radio1', group: 'radioGroup' }) 357 .checked(this.printRangeType === PrintRangeType.ALL) 358 .key('Index_Radio_allPages_pageRange') 359 .width($r('app.float.image_comp_width')) 360 .margin({ 361 left: $r('app.float.Radio_pageRange_left_margin'), 362 right: $r('app.float.Radio_pageRange_right_margin') 363 }) 364 .onChange((value: boolean) => { 365 Log.info(TAG,'Radio_range_pageRange all') 366 if (value) { 367 this.printRangeType = PrintRangeType.ALL; 368 this.updatePrintRange() 369 } 370 }) 371 Text($r('app.string.index_all_pages')) 372 .fontSize($r('app.float.font_size_body2')) 373 .key('Index_Text_allPages_pageRange') 374 } 375 .height($r('app.float.params_row_height')) 376 .width($r('app.float.params_row_width')) 377 378 Row() { 379 Radio({ value: 'Radio2', group: 'radioGroup' }) 380 .checked(this.printRangeType === PrintRangeType.RANGE) 381 .key('Index_Radio_range_pageRange') 382 .width($r('app.float.image_comp_width')) 383 .margin({ 384 left: $r('app.float.Radio_pageRange2_left_margin'), 385 right: $r('app.float.Radio_pageRange2_right_margin') 386 }) 387 .onChange((value: boolean) => { 388 if (value) { 389 if (this.changeRangeTypeFlag) { 390 focusControl.requestFocus('Index_TextInput_from_pageRange') 391 } 392 Log.info(TAG, 'Radio_range_pageRange onChange: '+ this.endPage) 393 this.printRangeType = PrintRangeType.RANGE; 394 Log.info(TAG,'this.isRangeRadioEnable = true') 395 this.isRangeRadioEnable = true 396 this.updatePrintRange() 397 }else{ 398 Log.info(TAG,'this.isRangeRadioEnable = false') 399 this.isRangeRadioEnable = false 400 this.setStartPageStr() 401 this.setEndPageStr() 402 } 403 }) 404 .onTouch((e:TouchEvent)=>{ 405 e.stopPropagation() 406 }) 407 .onMouse((e:MouseEvent)=>{ 408 e.stopPropagation() 409 }) 410 Text($r('app.string.index_from')) 411 .maxLines(Constants.NUMBER_2) 412 .textOverflow({ overflow: TextOverflow.Ellipsis}) 413 .textAlign(TextAlign.Start) 414 .fontSize($r('app.float.font_size_body2')) 415 .key('Index_Text_from_pageRange') 416 TextInput({ text: this.startPageStr }) 417 .key('Index_TextInput_from_pageRange') 418 .width($r('app.float.textInput_pageRange_width')) 419 .height($r('app.float.params_comp_height')) 420 .type(InputType.Number) 421 .maxLength(this.rangeInputLimit) 422 .fontSize($r('app.float.font_size_body2')) 423 .fontColor(this.isRangeRadioEnable?Color.Black:Color.Gray) 424 .border({ 425 width: $r('app.float.border_width'), 426 radius: $r('app.float.radius_s'), 427 color: $r('app.color.border_line') 428 }) 429 .margin({ 430 left: $r('app.float.textInput_pageRange_left_margin'), 431 right: $r('app.float.textInput_pageRange_right_margin') 432 }) 433 .backgroundColor(Color.White) 434 .onChange((value: string) => { 435 this.startPage = Number.parseInt(value) 436 this.startPageStr = value//规避前置0输入 437 this.startPageStr = this.startPage.toString() 438 Log.info(TAG, 'from change; value = ' + this.startPage + ' endpage = ' + this.endPage) 439 if (this.startPage < Constants.NUMBER_1) { 440 this.startPage = Constants.NUMBER_1 441 } else if (this.startPage > this.endPage) { 442 this.startPage = this.endPage 443 Log.info(TAG, 'from change; startPage = ' + this.startPage) 444 } 445 if (Number.isNaN(this.startPage)) { 446 this.startPage = Constants.NUMBER_1 447 this.startPageStr = Constants.STRING_NONE 448 } 449 if (!this.firstStartPageEdit) { 450 this.printRangeType = PrintRangeType.RANGE; 451 this.firstStartPageEdit = false 452 } 453 this.updatePrintRange(); 454 }) 455 .onSubmit(() => { 456 Log.info(TAG,'startPageStr onSubmit: ',this.startPage.toString()) 457 this.setStartPageStr() 458 }) 459 .onBlur(() => { 460 Log.info(TAG,'startPageStr onBlur: ',this.startPage.toString()) 461 this.setStartPageStr() 462 }) 463 .onFocus(()=>{ 464 this.printRangeType = PrintRangeType.RANGE; 465 }) 466 .onTouch((e:TouchEvent)=>{ 467 e.stopPropagation() 468 }) 469 .onMouse((e:MouseEvent)=>{ 470 e.stopPropagation() 471 }) 472 473 Text($r('app.string.index_to')) 474 .maxLines(Constants.NUMBER_2) 475 .textOverflow({ overflow: TextOverflow.Ellipsis}) 476 .textAlign(TextAlign.Start) 477 .fontSize($r('app.float.font_size_body2')) 478 .key('Index_Text_to_pageRange') 479 TextInput({ text: this.endPageStr }) 480 .width($r('app.float.textInput_pageRange_width')) 481 .height($r('app.float.params_comp_height')) 482 .key('Index_TextInput_to_pageRange') 483 .type(InputType.Number) 484 .maxLength(this.rangeInputLimit) 485 .fontSize($r('app.float.font_size_body2')) 486 .backgroundColor(Color.White) 487 .fontColor(this.isRangeRadioEnable?Color.Black:Color.Gray) 488 .margin({ 489 left: $r('app.float.textInput_pageRange_left_margin'), 490 right: $r('app.float.textInput_pageRange_right_margin') 491 }) 492 .border({ 493 width: $r('app.float.border_width'), 494 radius: $r('app.float.radius_s'), 495 color: $r('app.color.border_line') 496 }) 497 .onChange((value: string) => { 498 this.endPage = Number.parseInt(value) 499 this.endPageStr = value//规避前置0输入 500 this.endPageStr = this.endPage.toString() 501 if (this.endPage > this.totalPage) { 502 this.endPage = this.totalPage 503 } else if (this.endPage < this.startPage) { 504 this.endPage = this.startPage 505 } 506 if (Number.isNaN(this.endPage)) { 507 this.endPage = this.startPage 508 this.endPageStr = Constants.STRING_NONE 509 } 510 if(!this.firstEndPageEdit){ 511 this.printRangeType = PrintRangeType.RANGE; 512 this.firstEndPageEdit = false 513 } 514 this.updatePrintRange(); 515 }) 516 .onSubmit(() => { 517 Log.info(TAG,'endPageStr onSubmit: ',this.endPage.toString()) 518 this.setEndPageStr(); 519 }) 520 .onBlur(() => { 521 this.changeRangeTypeFlag = true; 522 Log.info(TAG,'endPageStr onBlur: ',this.endPage.toString()) 523 this.setEndPageStr(); 524 }) 525 .onFocus(()=>{ 526 this.changeRangeTypeFlag = false; 527 this.printRangeType = PrintRangeType.RANGE; 528 this.updatePrintRange() 529 }) 530 .onTouch((e:TouchEvent)=>{ 531 e.stopPropagation() 532 }) 533 .onMouse((e:MouseEvent)=>{ 534 e.stopPropagation() 535 }) 536 }.height($r('app.float.params_row_height')).width($r('app.float.params_row_width')) 537 Row() { 538 Radio({ value: 'Radio3', group: 'radioGroup' }) 539 .checked(this.printRangeType === PrintRangeType.CUSTOM) 540 .key('Index_Radio_custom_pageRange') 541 .width(24) 542 .margin({ 543 left: 98, 544 right: 8 545 }) 546 .onChange((value: boolean) => { 547 if (value) { 548 focusControl.requestFocus('Index_TextInput_custom_pageRange') 549 this.printRangeType = PrintRangeType.CUSTOM; 550 Log.info(TAG,'isCustomRadioEnable = true') 551 this.isCustomRadioEnable = true 552 this.updatePrintRange() 553 }else{ 554 Log.info(TAG,'isCustomRadioEnable = false') 555 this.isCustomRadioEnable = false 556 if (this.isCusRangeError) { 557 this.editCusRangeFlag = false 558 this.cusRangeText = '' 559 } 560 this.isCusRangeError = false 561 this.isCusRangeMax = false 562 this.cusRangeBorderColor = $r('app.color.border_line') 563 } 564 }) 565 .onTouch((e:TouchEvent)=>{ 566 e.stopPropagation() 567 }) 568 .onMouse((e:MouseEvent)=>{ 569 e.stopPropagation() 570 }) 571 Text($r('app.string.index_page_custom')) 572 .fontSize(14) 573 .key('Index_Text_custom_pageRange') 574 }.height(48).width(432) 575 TextInput({placeholder:$r('app.string.index_page_custom_example'),text: this.cusRangeText }).key('Index_TextInput_custom_pageRange') 576 .width(326).height(32).border({ width: 1, radius: 8, color: this.cusRangeBorderColor }) 577 .margin({ 578 bottom: 8, 579 left: 98, 580 right: 8 581 }) 582 .backgroundColor(Color.White) 583 .placeholderFont({size:14}) 584 .fontColor(this.isCustomRadioEnable?Color.Black:Color.Gray) 585 .fontSize(14) 586 .maxLength(50) 587 .onChange((value:string)=>{ 588 if (this.editCusRangeFlag) { 589 this.printRangeType = PrintRangeType.CUSTOM; 590 this.checkCustomRange(value); 591 this.updatePrintRange(); 592 this.cusRangeText = value; 593 }else{ 594 this.editCusRangeFlag = true 595 } 596 }) 597 .onBlur(() => { 598 Log.info(TAG,'cusRangeTextInput onBlur') 599 if (this.printRangeType === PrintRangeType.CUSTOM) { 600 this.checkCustomRangeTextInput() 601 } 602 }) 603 .onFocus(()=>{ 604 if (this.editCusRangeFlag) { 605 this.printRangeType = PrintRangeType.CUSTOM; 606 this.updatePrintRange() 607 } 608 }) 609 .onTouch((e:TouchEvent)=>{ 610 e.stopPropagation() 611 }) 612 .onMouse((e:MouseEvent)=>{ 613 e.stopPropagation() 614 }) 615 Text(this.errorMessage).key('Index_Text_custom_errorMessage') 616 .fontSize($r('app.float.font_size_body3')).fontColor('#E84026').fontWeight(FontWeight.Medium) 617 .margin({ 618 top: 8, 619 left: 98, 620 right: 20, 621 bottom: 8 622 }) 623 .visibility((this.isCusRangeError || this.isCusRangeMax)?Visibility.Visible:Visibility.None) 624 } 625 .alignItems(HorizontalAlign.Start) 626 627 MediaSizeSelection() 628 DirectionSelection() 629 MediaTypeSelection().visibility(!this.isPhotoEnabled ? Visibility.None : Visibility.Visible) 630 Row() { 631 Blank() 632 Row(){ 633 Checkbox() 634 .select(this.isBorderless) 635 .width($r('app.float.image_comp_width')) 636 .height($r('app.float.image_comp_height')) 637 .enabled(this.currentMediaType.obj === MediaType.PHOTO) 638 .key('Index_Checkbox_borderless') 639 .onChange((value: boolean) => { 640 if (value) { 641 this.showToast($r('app.string.borderless_enable_toast')) 642 } 643 this.isBorderless = value 644 }) 645 } 646 .onClick(() => { 647 if (this.currentMediaType.obj !== MediaType.PHOTO) { 648 this.showToast($r('app.string.borderless_type_toast')) 649 } 650 }) 651 Text($r('app.string.index_borderless')) 652 .fontSize($r('app.float.font_size_body2')) 653 .width($r('app.float.text_borderless_width')) 654 .opacity(this.currentMediaType.obj === MediaType.PHOTO ? Constants.NUMBER_1 : $r('app.float.disable_opacity')) 655 .key('Index_Text_borderless') 656 } 657 .visibility(!this.isPhotoEnabled? Visibility.None : Visibility.Visible) 658 .height($r('app.float.params_row_height')) 659 .width($r('app.float.params_row_width')) 660 661 QualitySelection() 662 DuplexSelection().visibility(this.isDuplexEnabled ? Visibility.Visible : Visibility.None) 663 } 664 .alignItems(HorizontalAlign.Start) 665 .justifyContent(FlexAlign.Start) 666 .margin({ top: $r('app.float.print_setting_padding_top') 667 , bottom: $r('app.float.print_setting_padding_bottom') 668 }) 669 670 } 671 // .height($r('app.float.print_setting_height')) 672 .height(this.printParamCompHeight-73) 673 .width($r('app.float.print_setting_width')) 674 .margin({left:24,right:24}) 675 .scrollable(ScrollDirection.Vertical) // 滚动方向纵向 676 .scrollBar(BarState.Off) 677 .edgeEffect(EdgeEffect.None) 678 .align(Alignment.Top) 679 .enabled(!this.isGlobalDisable) 680 .opacity(this.isGlobalDisable?0.4:1) 681 682 Column().height(12) 683 Divider() 684 .width($r('app.float.print_setting_width')) 685 .strokeWidth(Constants.NUMBER_1) 686 .color($r('app.color.black')) 687 .opacity($r('app.float.divider_opacity')) 688 .key('Index_Divider') 689 Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.End, alignItems: ItemAlign.Center }) { 690 AboutPageComponent().margin({left:24,right:152}) 691 CancelButton({ 692 cancelLabel: $r('app.string.Cancel'), 693 cancelWidth: $r('app.float.button_index_width'), 694 cancelHeight: $r('app.float.button_index_height'), 695 cancelClick: () => { 696 this.abilityContext.terminateSelf().then((data) => { 697 console.info('===>terminateSelfCallBack===>: ' + data); 698 }); 699 } 700 }) 701 .key('Index_Button_cancel') 702 .margin({ right: $r('app.float.button_index_cancel_margin_right') }) 703 704 Button($r('app.string.Index_doPrint')) 705 .key('Index_Button_doPrint') 706 .width($r('app.float.button_index_width')) 707 .height($r('app.float.button_index_height')) 708 .margin({ right: $r('app.float.button_index_doPrint_margin_right') }) 709 .enabled(this.canPrint && this.printButtonFlag && !this.isCusRangeError && !this.isGlobalDisable) 710 .fontColor($r('app.color.white')) 711 .onClick(() => { 712 this.getJobDescription() 713 this.startPrint() 714 }) 715 } 716 .margin({ 717 top: $r('app.float.print_setting_margin_top'), 718 bottom: $r('app.float.print_setting_margin_bottom') 719 }) 720 }.width($r('app.float.print_setting_width')) 721 } 722 .onTouch((event?:TouchEvent)=>{ 723 if (event.type === TouchType.Down) { 724 Log.info(TAG,'requestFocus') 725 focusControl.requestFocus('Index_Text_copies') 726 } 727 }) 728 } 729 730 public getPlusImage(mouseState: number,isEnabled :boolean): Resource { 731 if (!isEnabled){ 732 return $r('app.media.ic_plus_disabled'); 733 } 734 switch (mouseState) { 735 case MouseState.NONE: 736 return $r('app.media.ic_plus'); 737 break 738 case MouseState.PRESS: 739 return $r('app.media.ic_plusPress'); 740 break 741 case MouseState.HOVER: 742 return $r('app.media.ic_plusHover'); 743 break 744 } 745 } 746 747 public getMinusImage(mouseState: number,isEnabled :boolean): Resource { 748 if (!isEnabled){ 749 return $r('app.media.ic_minus_disabled'); 750 } 751 switch (mouseState) { 752 case MouseState.NONE: 753 return $r('app.media.ic_minus'); 754 break 755 case MouseState.PRESS: 756 return $r('app.media.ic_minusPress'); 757 break 758 case MouseState.HOVER: 759 return $r('app.media.ic_minusHover'); 760 break 761 } 762 } 763 764 aboutToAppear() { 765 Log.info(TAG, 'aboutToAppear') 766 this.getWant() 767 this.loadImageSources(); 768 this.setSelect(); 769 this.initParams(); 770 this.bindService(); 771 this.recordLastUsedPrinter(); 772 this.preDiscovery(); 773 this.checkWlan(); 774 this.subscribe(); 775 } 776 777 aboutToDisappear() { 778 this.unsubscribe() 779 this.abilityContext = undefined 780 clearInterval(this.ConnectTimer) 781 this.releaseResource(); 782 } 783 784 releaseResource() { 785 Log.info(TAG, 'start release resource'); 786 if (CheckEmptyUtils.isEmptyArr<FileModel>(this.imageSources)) { 787 return; 788 } 789 for (let imageModel of this.imageSources) { 790 imageModel.imageSource.release(); 791 } 792 } 793 794 showToast(message: Resource) { 795 try { 796 promptAction.showToast({ 797 message: message, 798 duration: Constants.TOAST_INTERVAL, 799 bottom: Constants.TOAST_BOTTOM 800 }); 801 } catch (error) { 802 Log.error(TAG, `showToast args error code is ${error.code}, message is ${error.message}`); 803 } 804 ; 805 } 806 807 private getWant() { 808 this.abilityContext = GlobalThisHelper.getValue<common.UIAbilityContext>(GlobalThisStorageKey.KEY_MAIN_ABILITY_CONTEXT) 809 let data = { 810 wantJobId: Constants.STRING_NONE, 811 wantFileList: [], 812 } 813 this.abilityContext.eventHub.emit(Constants.EVENT_GET_ABILITY_DATA, data); 814 Log.debug(TAG, 'aboutToAppear jobId: ' + JSON.stringify(data.wantJobId) + ', fileList: ' + JSON.stringify(data.wantFileList)); 815 this.jobId = data.wantJobId 816 this.jobFileList = data.wantFileList 817 } 818 819 private subscribe() { 820 821 var innerEventState = { eventId: AppCommonEvent.PRINTER_STATE_CHANGE_EVENT } 822 emitter.on(innerEventState, (eventData) => { 823 let printers = AppStorage.Get<Array<PrinterInfo>>(AppStorageKeyName.PRINTER_QUEUE_NAME) 824 825 if (this.printer === undefined || printers === undefined) { 826 Log.error(TAG, 'emitter callback this printer is null or printers is null, return'); 827 return 828 } 829 Log.info(TAG, 'emitter PRINTER_STATE_CHANGE_EVENT callback this.printer: ' 830 + StringUtil.encodeCommonString(this.printer.printerName)); 831 for (let index = 0; index < printers.length; index++) { 832 if (printers[index].printerId === this.printer.printerId) { 833 this.checkPrinterConnection(printers[index].printerState) 834 } 835 } 836 }) 837 838 var innerEventCap = { eventId: AppCommonEvent.PRINTER_UPDATE_CAPABILITY_EVENT } 839 emitter.on(innerEventCap, (eventData) => { 840 let printers = AppStorage.Get<Array<PrinterInfo>>(AppStorageKeyName.PRINTER_QUEUE_NAME); 841 if (this.printer === undefined || this.printer === null) { 842 Log.error(TAG, 'printer is undefined'); 843 return; 844 } 845 Log.error(TAG, 'emitter PRINTER_UPDATE_CAPABILITY_EVENT callback this.printer: ' + StringUtil.encodeCommonString(this.printer.printerName)); 846 if (printers === undefined) { 847 Log.error(TAG, 'emitter callback printers is null, return'); 848 return 849 } 850 for (let index = 0; index < printers.length; index++) { 851 if (printers[index].printerId === this.printer.printerId) { 852 clearInterval(this.ConnectTimer) 853 this.connectConfirmDialogCtl.close() 854 this.printer.capability = printers[index].capability 855 this.printer.option = printers[index].option 856 this.printer.description = printers[index].description 857 Log.info(TAG, 'this.printer.capability update: ', JSON.stringify(this.printer.capability)) 858 this.updateSupportParam(printers[index]) 859 } 860 } 861 }) 862 863 var innerEventWlan = { eventId: AppCommonEvent.WLAN_INACTIVE_EVENT } 864 emitter.on(innerEventWlan, (eventData) => { 865 Log.info(TAG, 'WLAN_INACTIVE_EVENT') 866 this.isNeedListenWlan = true 867 let isPrinterSelectDialogOpen = GlobalThisHelper.getValue<boolean>(GlobalThisStorageKey.KEY_PRINTER_SELECT_DIALOG_OPEN); 868 Log.info(TAG, 'isPrinterSelectDialogOpen: ' + isPrinterSelectDialogOpen) 869 if (isPrinterSelectDialogOpen) { 870 this.PrintingSelectDialogCtl.close() 871 GlobalThisHelper.createValue<boolean>(false, GlobalThisStorageKey.KEY_PRINTER_SELECT_DIALOG_OPEN, true); 872 this.WLANConfirmDialogCtl.open() 873 } 874 }) 875 876 var innerEventWlan = { eventId: AppCommonEvent.WLAN_ACTIVE_EVENT } 877 emitter.on(innerEventWlan, (eventData) => { 878 Log.info(TAG, 'WLAN_ACTIVE_EVENT') 879 if (this.isNeedListenWlan) { 880 this.isNeedListenWlan = false 881 this.adapter.getPrinterDiscCtl().startDiscovery(Constants.STRING_NONE, []) 882 } 883 884 }) 885 886 var innerEventPrinter = { eventId: AppCommonEvent.ADD_PRINTER_EVENT } 887 emitter.on(innerEventPrinter, (eventData) => { 888 if (!this.firstPrinterDiscoveredFlag){ 889 this.firstPrinterDiscoveredFlag = true; 890 } 891 if(this.isGlobalDisable){ 892 Log.info(TAG, 'last printer no need connecting'); 893 emitter.off(AppCommonEvent.ADD_PRINTER_EVENT); 894 return; 895 } 896 let printerJSON = eventData.data.printer 897 let printer = JSON.parse(printerJSON) 898 Log.info(TAG, 'ADD_PRINTER_EVENT') 899 if (printer.printerId === this.usedPrinterId) { 900 Log.info(TAG, 'last printer is connecting'); 901 this.printer = printer; 902 this.adapter.getPrinterDiscCtl().connectPrinter(printer) 903 emitter.off(AppCommonEvent.ADD_PRINTER_EVENT) 904 } 905 906 }) 907 908 909 print.on('extInfoChange', (extensionId: string, info: string) => { 910 let extInfo = JSON.parse(info) 911 Log.info(TAG, 'extInfoChange: ', info) 912 if (CheckEmptyUtils.isEmpty(this.printer)){ 913 Log.info(TAG, 'invalid printer!') 914 return; 915 } 916 switch (extInfo.code){ 917 case ErrorCode.IPP_CONNECT_ERROR: 918 this.connectionFailed(); 919 break; 920 case ErrorCode.GET_CAPS_ERROR: 921 this.adapter.getPrinterDiscCtl().queryPrinterCapability(this.printer.printerId); 922 break; 923 case ErrorCode.CONNECTION_POP: 924 if (this.printer.printerId !== this.usedPrinterId){ 925 this.connectFlag = !this.connectFlag 926 } 927 default: 928 break; 929 } 930 }) 931 } 932 933 private unsubscribe() { 934 emitter.off(AppCommonEvent.PRINTER_STATE_CHANGE_EVENT) 935 emitter.off(AppCommonEvent.PRINTER_UPDATE_CAPABILITY_EVENT) 936 emitter.off(AppCommonEvent.WLAN_INACTIVE_EVENT) 937 938 print.off('extInfoChange') 939 } 940 941 preDiscovery() { 942 this.adapter.getPrinterDiscCtl().startDiscovery(Constants.STRING_NONE, []) 943 } 944 945 checkWlan(){ 946 if (!WifiP2pHelper.checkWifiActive()) { 947 Log.info(TAG,'checkWlan: inactive') 948 this.isNeedListenWlan = true; 949 } 950 } 951 952 bindService() { 953 this.adapter = PrintAdapter.getInstance(); 954 } 955 956 setSelectDefault(disconnectFlag: boolean) { 957 if (this.printer === undefined || disconnectFlag) { 958 Log.info(TAG, 'setSelectDefault') 959 this.currentPrinterSelection = SelectionModel.NO_Printer 960 this.printerSelectArray = [] 961 this.printerSelectArray.push(SelectionModel.Add_Printer) 962 } 963 } 964 965 initParams() { 966 this.printButtonFlag = true 967 this.printerPageSize = MediaSizeUtil.mediaSizeToPageSize(SelectionModel.MediaSize_ISO_A4.obj) 968 } 969 970 setSelect() { 971 this.setSelectDefault(false); 972 this.setMediaSizesSelect(); 973 this.setDirectionSelect(); 974 this.setMediaTypeSelect(); 975 this.setPrintQualitySelect(); 976 this.setDuplexSelect(); 977 } 978 979 updatePrintRange() { 980 Log.info(TAG, 'updatePrintRange'+ this.startPage+' '+this.endPage) 981 this.printRange = [] 982 switch (this.printRangeType) { 983 case PrintRangeType.ALL: 984 for (var num = 1; num <= this.totalPage; ) { 985 this.printRange.push(num) 986 num++ 987 } 988 break; 989 case PrintRangeType.RANGE: 990 for (var num = this.startPage; num <= this.endPage; ) { 991 this.printRange.push(num) 992 num++ 993 } 994 break; 995 case PrintRangeType.CUSTOM: 996 this.printRange = CopyUtil.deepClone(this.cusRangeArr) 997 Log.info(TAG,'updatePrintRange CUSTOM this.printRange ',JSON.stringify(this.printRange)) 998 break; 999 default: 1000 break; 1001 } 1002 1003 if (this.printRange.length === 0){ 1004 if (this.allPages != undefined) { 1005 this.printRange = CopyUtil.deepClone(this.allPages) 1006 }else{ 1007 for (var num = 1; num <= this.totalPage; ) { 1008 this.printRange.push(num) 1009 num++ 1010 } 1011 } 1012 } 1013 this.imageCount = this.printRange.length 1014 this.needDuplex = this.imageCount>1?true:false 1015 if (this.printerRange === undefined) { 1016 this.printerRange = new PrinterRange() 1017 } 1018 this.printerRange.startPage = this.startPage; 1019 this.printerRange.endPage = this.endPage; 1020 this.printerRange.pages = this.printRange.slice(); 1021 } 1022 1023 updateMediaSize() { 1024 if (CheckEmptyUtils.isEmpty(this.currentMediaSize)) { 1025 return 1026 } 1027 if (!CheckEmptyUtils.isEmpty(this.currentMediaSize.obj)) { 1028 this.mediaSize = this.currentMediaSize.obj 1029 Log.info(TAG, 'updateMediaSize:MediaSize = ' + JSON.stringify(this.mediaSize)) 1030 this.printerPageSize = MediaSizeUtil.mediaSizeToPageSize(this.mediaSize) 1031 } 1032 Log.info(TAG, 'afterUpdateMediaSize: ' + this.printerPageSize.name) 1033 } 1034 1035 updateMediaType() { 1036 if (this.printer !== undefined) { 1037 let isBSH = this.isBiSheng(this.printer.printerName) 1038 if (isBSH) { 1039 this.mediaSizeList = MediaSizeUtil.getDefaultMediaSizeByMediaType(this.currentMediaType.obj) 1040 } 1041 this.setMediaSizesSelect() 1042 } 1043 this.setPrintQualitySelect() 1044 if (this.currentMediaType.name === SelectionModel.MediaType_NORMAL.name) { 1045 Log.info(TAG,'this.isBorderless = false') 1046 this.isBorderless = false 1047 } 1048 } 1049 1050 updateDirection() { 1051 this.pageDirection = this.currentDirection.obj 1052 } 1053 1054 /** 1055 * 更新打印机能力支持的参数 1056 * 1057 * @param cap 1058 */ 1059 updateSupportParam(printer: PrinterInfo) { 1060 Log.info(TAG, 'updateSupportParam printer: ' + StringUtil.encodeCommonString(this.printer.printerName)); 1061 let cap = printer.capability 1062 if (CheckEmptyUtils.isEmpty(cap)) { 1063 return 1064 } 1065 1066 if (cap.colorMode === ColorCode.MONOCHROME) { 1067 this.colorMode = ColorCode.MONOCHROME 1068 this.isColored = false 1069 this.isColorEnabled = false 1070 }else{ 1071 this.isColorEnabled = true 1072 } 1073 1074 if (cap.duplexMode === Duplex.SINGLE) { 1075 this.isDuplexEnabled = false; 1076 this.currentDuplex = SelectionModel.DuplexMode_SINGLE; 1077 } else { 1078 this.isDuplexEnabled = true; 1079 } 1080 let isBSH = this.isBiSheng(printer.printerName) 1081 if (isBSH) { 1082 this.mediaSizeList = MediaSizeUtil.getDefaultMediaSizeByMediaType(this.currentMediaType.obj) 1083 } else { 1084 this.mediaSizeList = new Array<MediaSize>() 1085 for (let index = 0; index < cap.pageSize.length; index++) { 1086 this.mediaSizeList.push(MediaSizeUtil.pageSizeToMediaSize(cap.pageSize[index])) 1087 } 1088 } 1089 Log.debug(TAG,'printer.option:',printer.option) 1090 let option = JSON.parse(printer.option); 1091 if(!CheckEmptyUtils.isEmpty(option.supportedMediaTypes)){ 1092 this.supportedMediaTypes = option.supportedMediaTypes 1093 } 1094 Log.debug(TAG,'supportedMediaTypes:',JSON.stringify(this.supportedMediaTypes)) 1095 this.setMediaTypeSelect() 1096 this.setMediaSizesSelect() 1097 this.canPrint = true 1098 } 1099 1100 updateImageSources(){ 1101 Log.info(TAG,'updateImageSources length = '+this.imageSources.length) 1102 this.allPages = [] 1103 for (var num = 1; num <= this.imageSources.length; ) { 1104 this.allPages.push(num) 1105 num++ 1106 } 1107 } 1108 1109 isBiSheng(printerName: string): boolean { 1110 Log.info(TAG, 'isBiSheng:', StringUtil.encodeCommonString(printerName)); 1111 return printerName.includes(BISHENG_PRINTER); 1112 } 1113 1114 setMediaSizesSelect() { 1115 if (this.mediaSizeList !== undefined) { 1116 Log.info(TAG, 'setMediaSizesSelect mediaSizeList.length:' + this.mediaSizeList.length) 1117 } 1118 if (this.mediaSizeList === undefined) { 1119 this.mediaSizeList = new Array<MediaSize>() 1120 MediaSizeUtil.initMediaSizeArray(this.mediaSizeList) 1121 } 1122 this.mediaSizeSelectArray = new Array<SelectionModel>() 1123 let isNeedResetMediaSize = true 1124 this.mediaSizeList.forEach(mediaSize => { 1125 if (this.currentMediaSize.res === mediaSize.label) { 1126 isNeedResetMediaSize = false 1127 } 1128 let mediaSizeSelection = SelectionModel.getSelectionModelByLabel(mediaSize.label) 1129 if(!CheckEmptyUtils.isEmpty(mediaSizeSelection)){ 1130 this.mediaSizeSelectArray.push(mediaSizeSelection) 1131 } 1132 }); 1133 Log.info(TAG, 'this.mediaSizeSelectArray.length: ' + this.mediaSizeSelectArray.length) 1134 if(isNeedResetMediaSize){ 1135 this.currentMediaSize = SelectionModel.MediaSize_ISO_A4; 1136 } 1137 } 1138 1139 setDirectionSelect() { 1140 this.directionSelectArray = new Array<SelectionModel>() 1141 this.directionSelectArray.push(SelectionModel.Direction_AUTO, SelectionModel.Direction_LANDSCAPE, SelectionModel.Direction_VERTICAL) 1142 } 1143 1144 setMediaTypeSelect() { 1145 this.mediaTypeSelectArray = new Array<SelectionModel>() 1146 if(this.supportedMediaTypes.length === Constants.NUMBER_1){ 1147 this.isPhotoEnabled = false 1148 this.mediaTypeSelectArray.push(SelectionModel.MediaType_NORMAL) 1149 if (this.currentMediaType.name == SelectionModel.MediaType_PHOTO.name) { 1150 this.currentMediaType = SelectionModel.MediaType_NORMAL 1151 } 1152 } else { 1153 this.isPhotoEnabled = true 1154 this.mediaTypeSelectArray.push(SelectionModel.MediaType_NORMAL, SelectionModel.MediaType_PHOTO) 1155 } 1156 } 1157 1158 setPrintQualitySelect() { 1159 this.qualitySelectArray = new Array<SelectionModel>() 1160 if (this.currentMediaType.obj === MediaType.NORMAL) { 1161 this.qualitySelectArray.push(SelectionModel.PrintQuality_BEST, SelectionModel.PrintQuality_STANDARD, SelectionModel.PrintQuality_ECONOMY); 1162 } else { 1163 this.qualitySelectArray.push(SelectionModel.PrintQuality_BEST, SelectionModel.PrintQuality_STANDARD); 1164 if (this.currentQuality = SelectionModel.PrintQuality_ECONOMY) { 1165 this.currentQuality = SelectionModel.PrintQuality_STANDARD 1166 } 1167 } 1168 } 1169 1170 1171 setDuplexSelect() { 1172 this.duplexSelectArray = new Array<SelectionModel>() 1173 this.duplexSelectArray.push(SelectionModel.DuplexMode_SINGLE, SelectionModel.DuplexMode_LONG, SelectionModel.DuplexMode_SHORT) 1174 } 1175 1176 isPrintRangeAll(): boolean { 1177 Log.info(TAG,'startPage,endPage,totalPage'+this.startPage+' '+this.endPage+' '+this.totalPage ) 1178 if (this.startPage === 1 && (this.endPage === this.totalPage || this.totalPage === Constants.NUMBER_0)) { 1179 return true; 1180 } else { 1181 return false; 1182 } 1183 } 1184 1185 /** 1186 * 加载第三方应用传过来的图片信息 1187 * 1188 * @param name 1189 */ 1190 async loadImageSources() { 1191 Log.info(TAG, 'loadImageSources start') 1192 if (this.jobFileList) { 1193 this.fileNum = this.jobFileList.length; 1194 this.imageSources = await FileUtil.initImageData(this.checkMaxPages(this.jobFileList)); 1195 } else { 1196 // @ts-ignore 1197 await print.queryPrintJobById(this.jobId).then(async (printJob) => { 1198 if (!CheckEmptyUtils.isEmpty(printJob) && !CheckEmptyUtils.isEmptyArr(printJob.fdList)) { 1199 this.fileNum = printJob.fdList.length; 1200 Log.debug(TAG, 'queryPrintJobById printJob: ', JSON.stringify(printJob)); 1201 this.imageSources = await FileUtil.initFdImageData(printJob.fdList); 1202 } 1203 }) 1204 } 1205 Log.debug(TAG, "loadImageSources imageSources: ", JSON.stringify(this.imageSources)) 1206 this.totalPage = this.imageSources.length === 0 ? 1 : this.imageSources.length 1207 this.imageCount = this.totalPage 1208 this.rangeInputLimit = this.totalPage.toString().length 1209 let errorCount: number = GlobalThisHelper.getValue<number>(GlobalThisStorageKey.KEY_IMAGE_ERROR_COUNT) 1210 let errorName: string = GlobalThisHelper.getValue<string>(GlobalThisStorageKey.KEY_IMAGE_ERROR_NAME) 1211 if (this.imageSources.length !== 0){ 1212 if (errorCount === 1) { 1213 Log.info(TAG, "loadImageSources this.showToast ") 1214 setTimeout(() => {//延迟弹窗,否则会概率弹窗失败 1215 this.showToast($r('app.string.toast_preview_failed',errorName)) 1216 }, Constants.SHOW_TOAST_TIMEOUT); 1217 } else if (errorCount > 1) { 1218 setTimeout(() => {//延迟弹窗,否则会概率弹窗失败 1219 this.showToast($r('app.string.toast_preview_failed_plurals',errorName,errorCount)) 1220 }, Constants.SHOW_TOAST_TIMEOUT); 1221 } 1222 }else{ 1223 this.isPreviewFailed = true; 1224 } 1225 this.endPage = this.totalPage 1226 if (this.imageSources.length > Constants.MAX_PAGES) {//需要弹预览失败toast时不用弹100张限制的toast 1227 this.isAbovePageLimit = true; 1228 this.endPage = Constants.MAX_PAGES; 1229 } 1230 this.isGlobalDisable = this.imageSources.length === 0 ? true : false 1231 this.endPageStr = this.endPage.toString() 1232 this.updatePrintRange() 1233 1234 1235 } 1236 1237 /** 1238 * 记录上一次使用过的打印机 1239 */ 1240 async recordLastUsedPrinter() { 1241 let printerString = FileUtil.readStringFromFile(this.usedPrinterFileName, this.abilityContext) 1242 if (CheckEmptyUtils.checkStrIsEmpty(printerString)) { 1243 Log.error(TAG, 'lasted used printer is null'); 1244 return; 1245 } 1246 let printer = JSON.parse(printerString); 1247 this.usedPrinterId = printer.printerId 1248 Log.info(TAG, 'load last printer: ' + StringUtil.encodeCommonString(printer.printerName)); 1249 } 1250 1251 /** 1252 * 保存成功连接并执行过打印的打印机 1253 * 1254 * @param printer 打印机信息 1255 */ 1256 saveLastedUsedPrinter(printer: PrinterInfo) { 1257 Log.info(TAG, 'saveLastedUsedPrinter printer: ' + StringUtil.encodeCommonString(printer.printerName)); 1258 if (CheckEmptyUtils.isEmpty(printer)) { 1259 Log.error(TAG, 'printer is null') 1260 return; 1261 } 1262 let printerString = JSON.stringify(printer) 1263 if (CheckEmptyUtils.checkStrIsEmpty(printerString)) { 1264 Log.error(TAG, 'printer string is null') 1265 return; 1266 } 1267 FileUtil.writeStringToFile(printerString, this.usedPrinterFileName, this.abilityContext); 1268 Log.info(TAG, 'printer save success') 1269 } 1270 1271 openPrinterSelectDialog() { 1272 Log.info(TAG,'openPrinterSelectDialog printerSelectFlag : '+this.printerSelectFlag) 1273 if (this.printerSelectFlag) { 1274 this.printerSelectFlag = false 1275 this.PrintingSelectDialogCtl.close(); 1276 this.PrintingSelectDialogCtl.open(); 1277 } 1278 } 1279 1280 openWLANDialog() { 1281 this.WLANConfirmDialogCtl.open() 1282 } 1283 1284 connectAlarm() { 1285 clearInterval(this.ConnectTimer) 1286 this.connectConfirmDialogCtl.open() 1287 this.connectCount = Constants.CONNECT_COUNT 1288 this.ConnectTimer = setInterval(() => { 1289 this.connectCountDown() 1290 }, Constants.COUNTDOWN_INTERVAL); 1291 } 1292 1293 connectCountDown() { 1294 this.connectCount-- 1295 if (this.connectCount === Constants.COUNTDOWN_ALARM_TO_FAIL) { 1296 this.connectConfirmDialogCtl.close() 1297 } else if (this.connectCount === Constants.NUMBER_0 && !this.isConnected) { 1298 this.connectionFailed() 1299 } 1300 } 1301 1302 onPrinterChange() { 1303 if (this.printer !== undefined) { 1304 this.currentPrinterSelection = new SelectionModel(this.printer.printerName, this.printer, this.printer.printerName) 1305 Log.info(TAG, 'onPrinterChange printerName: ' + StringUtil.encodeCommonString(this.currentPrinterSelection.name)) 1306 } 1307 } 1308 1309 1310 /** 1311 * 打印机状态发生变化时进行处理 1312 * 1313 * @param printerState 打印机状态 1314 */ 1315 checkPrinterConnection(printerState: PrinterState) { 1316 Log.error(TAG, 'checkPrinterConnection printerState: ' + JSON.stringify(printerState)); 1317 switch (printerState) { 1318 case PrinterState.PRINTER_CONNECTED: 1319 this.isConnected = true 1320 this.connectingPrinterName = this.printer.printerName; 1321 this.connectingPrinterId = this.printer.printerId; 1322 clearInterval(this.ConnectTimer) 1323 this.connectConfirmDialogCtl.close(); 1324 break; 1325 case PrinterState.PRINTER_DISCONNECTED: 1326 this.connectionFailed() 1327 break; 1328 default: 1329 break; 1330 } 1331 1332 } 1333 /** 1334 * 将渲染的图片保存 1335 */ 1336 async saveImage(jobFiles: string[]) { 1337 Log.info(TAG, 'enter saveImage') 1338 if (this.mediaSize === undefined) { 1339 Log.error(TAG, 'this.mediaSize is undefined') 1340 return null 1341 } 1342 let size = this.mediaSize.get300PixelMediaSize(); 1343 let fileList = new Array<number>(); 1344 let imageSourceIndexList = new Array<number>(); 1345 for (let index = 0; index < this.printRange.length; index++) { 1346 imageSourceIndexList.push(this.printRange[index] - 1); 1347 } 1348 Log.info(TAG, 'imageSourceIndexList: ', JSON.stringify(imageSourceIndexList)) 1349 let len = imageSourceIndexList.length; 1350 for (let index = 0; index < len; index++) { 1351 Log.info(TAG,'imageModel START ,this.imageSources '+JSON.stringify(this.imageSources)) 1352 let imageModel = this.imageSources[imageSourceIndexList[index]]; 1353 Log.info(TAG,'imageModel: '+JSON.stringify(imageModel)) 1354 let offCanvas, scale, offCanvasWidth, offCanvasHeight, orientation 1355 if (this.pageDirection === PageDirection.VERTICAL || (this.pageDirection === PageDirection.AUTO && imageModel.height >= imageModel.width)) { 1356 //竖向 或者 自适应且图片竖向 1357 Log.debug('VERTICAL'); 1358 offCanvasWidth = px2fp(size.width); 1359 offCanvasHeight = px2fp(size.height); 1360 orientation = PageDirection.VERTICAL 1361 } else if (this.pageDirection === PageDirection.LANDSCAPE || (this.pageDirection === PageDirection.AUTO && imageModel.height <= imageModel.width)) { 1362 //横向 自适应且图片横向 1363 Log.debug('LANDSCAPE'); 1364 offCanvasWidth = px2fp(size.height); 1365 offCanvasHeight = px2fp(size.width); 1366 orientation = PageDirection.LANDSCAPE 1367 } else { 1368 offCanvasWidth = px2fp(size.width); 1369 offCanvasHeight = px2fp(size.height); 1370 Log.error('set offCanvas size error'); 1371 } 1372 offCanvas = new OffscreenCanvasRenderingContext2D(offCanvasWidth, offCanvasHeight, new RenderingContextSettings(true)); 1373 if (offCanvas === undefined) { 1374 Log.error(TAG, 'offCanvas is undefined'); 1375 return; 1376 } 1377 offCanvas.imageSmoothingEnabled = false; 1378 offCanvas.fillStyle = '#fff' 1379 offCanvas.fillRect(Constants.NUMBER_0, Constants.NUMBER_0, offCanvasWidth, offCanvasHeight); 1380 scale = this.isBorderless ? Math.max(offCanvasWidth / px2fp(imageModel.width), offCanvasHeight / px2fp(imageModel.height)) : 1381 Math.min(offCanvasWidth / px2fp(imageModel.width), offCanvasHeight / px2fp(imageModel.height)); 1382 let xPosition = (offCanvasWidth - px2fp(imageModel.width * scale)) / Constants.NUMBER_2; 1383 let yPosition = (offCanvasHeight - px2fp(imageModel.height * scale)) / Constants.NUMBER_2; 1384 1385 //将处理好的offCanvas图片写到本地文件 1386 if (CheckEmptyUtils.isEmpty(imageModel.imageSource)) { 1387 Log.error(TAG, 'imageSource is error'); 1388 continue; 1389 } 1390 Log.info(TAG, 'begin createPixelMap'); 1391 let imageSource = undefined; 1392 let pixelMap = undefined; 1393 let canvasPixelMap = undefined; 1394 try { 1395 imageSource = image.createImageSource(imageModel.fd); 1396 if (CheckEmptyUtils.isEmpty(imageSource)) { 1397 Log.error(TAG, 'imageSource is error') 1398 continue; 1399 }; 1400 const editResult: boolean = orientation === Constants.NUMBER_1 ? true : false; 1401 pixelMap = await imageSource.createPixelMap({isEdit: editResult}); 1402 if (CheckEmptyUtils.isEmpty(pixelMap)) { 1403 Log.error(TAG, 'pixelMap is error') 1404 continue; 1405 }; 1406 imageModel.imageSource.release(); 1407 Log.info(TAG, 'end createPixelMap'); 1408 offCanvas.drawImage(pixelMap, xPosition, yPosition, px2fp(imageModel.width * scale), px2fp(imageModel.height * scale)) //5184 3456 //1200 2133 1409 canvasPixelMap = offCanvas.getPixelMap(Constants.NUMBER_0, Constants.NUMBER_0, offCanvasWidth, offCanvasHeight); 1410 1411 //保存图片 1412 Log.info(TAG, 'begin createDataShareUri'); 1413 if (this.firstFileName === undefined) { 1414 this.firstFileName = imageModel.name; 1415 Log.info(TAG, 'init firstFileName:' + this.firstFileName) 1416 } 1417 let fileName = uuidGenerator() + Constants.JPEG_SUFFIX; 1418 FileUtil.createJobsDir(this.abilityContext.filesDir) 1419 let uri = this.abilityContext.filesDir + Constants.FILE_SEPARATOR + Constants.TEMP_JOB_FOLDER + Constants.FILE_SEPARATOR + fileName 1420 await FileUtil.saveImageToJpeg(canvasPixelMap, uri, orientation); 1421 Log.debug(TAG, 'end saveImageToJpeg'); 1422 jobFiles.push(uri); 1423 } catch (error) { 1424 Log.error(TAG, 'error happened: ' + JSON.stringify(error)) 1425 } finally { 1426 //释放资源 1427 if (pixelMap !== undefined) { 1428 pixelMap.release(); 1429 } 1430 if (canvasPixelMap !== undefined) { 1431 canvasPixelMap.release(); 1432 } 1433 if (imageSource !== undefined) { 1434 imageSource.release(); 1435 } 1436 } 1437 } 1438 Log.info(TAG, 'exit saveImage'); 1439 fileList = FileUtil.getFdList(jobFiles); 1440 this.jobNum = fileList.length 1441 this.jobName = this.getJobName(this.jobNum) 1442 1443 return fileList; 1444 } 1445 1446 /** 1447 * 开始打印 1448 * 1449 */ 1450 startPrint() { 1451 Log.info(TAG, 'startPrint') 1452 this.isGlobalDisable = true 1453 this.saveLastedUsedPrinter(this.printer) 1454 this.checkCustomRangeTextInput() 1455 1456 let jobFiles = new Array<string>() 1457 this.saveImage(jobFiles).then((fileList) => { 1458 let state = this.adapter.getPrintJobCtl().createPrintJob(this.jobId); 1459 let ops: PrintJobOptions = { 1460 jobName: this.jobName, 1461 jobNum: this.jobNum, 1462 jobDescription: this.jobDes, 1463 mediaType: this.getMediaType(this.currentMediaType.obj), 1464 documentCategory: this.currentMediaType.obj === MediaType.PHOTO ? Constants.NUMBER_1 : Constants.NUMBER_0, 1465 printQuality: this.currentQuality.obj.toString(), 1466 printerName: this.removeSpaces(this.printer.printerName), 1467 printerUri: this.getPrinterUri(), 1468 documentFormat: 'image/jpeg', 1469 files: jobFiles 1470 } 1471 let option = JSON.stringify(ops); 1472 1473 this.printJob = new PrintJob(jobFiles,fileList,this.jobId,this.printer.printerId,state,Constants.NUMBER_0,this.printCount,this.printerRange,true,this.printerPageSize,true, 1474 this.colorMode,this.currentDuplex.obj,new PrintMargin(),null,option); 1475 let printMargin = new PrintMargin(); 1476 printMargin.top = Constants.NUMBER_0; 1477 printMargin.bottom = Constants.NUMBER_0; 1478 printMargin.left = Constants.NUMBER_0; 1479 printMargin.right = Constants.NUMBER_0; 1480 1481 this.adapter.getPrintJobCtl().startPrint(this.printJob).then((result) => { 1482 if (result) { 1483 this.startJobAbility(); 1484 } else { // 任务下发失败 1485 this.showToast($r('app.string.error_task_send_msg')); 1486 } 1487 }); 1488 }); 1489 } 1490 1491 startJobAbility(){ 1492 let jobAbilityWant = { 1493 bundleName: Constants.BUNDLE_NAME, 1494 abilityName: Constants.JOB_MANAGER_ABILITY_NAME, 1495 parameters: { 1496 jobId: this.jobId 1497 }, 1498 } 1499 // @ts-ignore 1500 this.abilityContext.startAbility(jobAbilityWant).then(() => { 1501 Log.info(TAG,'startJobManagerAbility') 1502 this.canPrint = false; 1503 this.abilityContext.terminateSelf().then((data) => { 1504 console.info('===>terminateSelfCallBack===>: '+data); 1505 }); 1506 }).catch((err) => { 1507 Log.error(TAG, 'fail to startAbility, err =' + JSON.stringify(err)); 1508 }) 1509 } 1510 1511 removeSpaces(name: string) { 1512 if (CheckEmptyUtils.checkStrIsEmpty(name)) { 1513 return ""; 1514 } 1515 return name.replace(/\s+/g, "_"); 1516 } 1517 1518 getMediaType(selectType: number): string { 1519 if (MediaTypes.sCodeToStringMap.has(selectType)) { 1520 return MediaTypes.sCodeToStringMap.get(selectType); 1521 } 1522 return MediaTypes.sCodeToStringMap.get(MediaTypeCode.MEDIA_PLAIN); 1523 } 1524 1525 getPrinterUri(): string { 1526 let option = this.printer.option; 1527 let optionObject = JSON.parse(option); 1528 if (!optionObject.hasOwnProperty('printerUri')) { 1529 return ''; 1530 } 1531 return optionObject.printerUri; 1532 } 1533 1534 connectionFailed() { 1535 clearInterval(this.ConnectTimer) 1536 this.alarmText = StringUtil.getString('alarm_dialog_connect_failed') 1537 this.alarmDialogCtl.open() 1538 this.printer.printerId = Constants.STRING_NEGATIVE_ONE 1539 this.connectingPrinterId = Constants.DEFAULT_CONNECTING_PRINTER_ID 1540 this.connectingPrinterName = undefined; 1541 Log.info(TAG, 'connectCountDown setPrinterId:' + this.printer.printerId) 1542 this.setSelectDefault(true) 1543 } 1544 1545 getJobName(fileCount: number): string { 1546 Log.info(TAG, 'getJobName: COUNT' + fileCount) 1547 let jobName: string = this.firstFileName 1548 if (fileCount > 1) { 1549 let nameExt = StringUtil.getString('print_job_name_plurals',fileCount) 1550 jobName = jobName + nameExt 1551 } 1552 Log.debug(TAG,'jobName: ',jobName) 1553 return jobName 1554 } 1555 1556 getJobDescription() { 1557 1558 let color = Constants.STRING_NONE 1559 switch (this.colorMode) { 1560 case ColorCode.COLOR: 1561 color = StringUtil.getString('ColorMode_COLOR') + StringUtil.getString('pauseMark') 1562 break; 1563 case ColorCode.MONOCHROME: 1564 color = StringUtil.getString('ColorMode_MONOCHROME') + StringUtil.getString('pauseMark') 1565 break; 1566 } 1567 let mediaType = Constants.STRING_NONE 1568 switch (this.currentMediaType.obj) { 1569 case MediaType.NORMAL: 1570 mediaType = StringUtil.getString('MediaType_NORMAL') + StringUtil.getString('pauseMark') 1571 break; 1572 case MediaType.PHOTO: 1573 mediaType = StringUtil.getString('MediaType_PHOTO') + StringUtil.getString('pauseMark') 1574 break; 1575 } 1576 let borderless = Constants.STRING_NONE 1577 if (this.isBorderless) { 1578 borderless = StringUtil.getString('pauseMark') + StringUtil.getString('JobDes_BorderLess') 1579 } 1580 let quality = Constants.STRING_NONE 1581 switch (this.currentQuality.obj) { 1582 case PrintQuality.ECONOMY: 1583 quality = StringUtil.getString('PrintQuality_ECONOMY') + StringUtil.getString('pauseMark') 1584 break; 1585 case PrintQuality.STANDARD: 1586 quality = StringUtil.getString('PrintQuality_STANDARD') + StringUtil.getString('pauseMark') 1587 break; 1588 case PrintQuality.BEST: 1589 quality = StringUtil.getString('PrintQuality_BEST') + StringUtil.getString('pauseMark') 1590 break; 1591 } 1592 let direction = Constants.STRING_NONE 1593 switch (this.currentDirection.obj) { 1594 case PageDirection.AUTO: 1595 direction = StringUtil.getString('PageDirection_AUTO') + StringUtil.getString('pauseMark') 1596 break; 1597 case PageDirection.LANDSCAPE: 1598 direction = StringUtil.getString('PageDirection_LANDSCAPE') + StringUtil.getString('pauseMark') 1599 break; 1600 case PageDirection.VERTICAL: 1601 direction = StringUtil.getString('PageDirection_VERTICAL') + StringUtil.getString('pauseMark') 1602 break; 1603 } 1604 let duplex = Constants.STRING_NONE 1605 1606 let size = this.currentMediaSize.res 1607 let sizeStr =size.toString().split(' ')[0] 1608 this.jobDes = `${color}${quality}${direction}${mediaType}${sizeStr}${borderless}` 1609 } 1610 1611 checkCustomRange(value:string){ 1612 this.cusRangeArr = [] 1613 this.isCusRangeError = false 1614 this.isCusRangeMax = false 1615 this.cusRangeBorderColor = $r('app.color.border_line') 1616 1617 if (value === Constants.STRING_NONE) { 1618 return 1619 } 1620 1621 let prePageArray = [] 1622 let pageArray = [] 1623 prePageArray = value.split(Constants.EU_COMMA) 1624 prePageArray.forEach((prePage:string)=>{ 1625 pageArray.push.apply(pageArray,prePage.split(Constants.CN_COMMA)) 1626 }) 1627 1628 for (let index = 0; index < pageArray.length; index++){ 1629 let range =pageArray[index].split(Constants.HYPHEN) 1630 if (range.length === Constants.NUMBER_2) { 1631 let startNum = this.checkNum(range[0]) 1632 let endNum = this.checkNum(range[1]) 1633 if (!(startNum && endNum)){ 1634 this.cusRangeArr = [] 1635 return 1636 } 1637 if (startNum>endNum) { 1638 this.setInvalidRange() 1639 this.cusRangeArr = [] 1640 return 1641 }else{ 1642 for (let index:number = startNum; index <= endNum; index++) { 1643 this.cusRangeArr.push(index); 1644 } 1645 } 1646 continue; 1647 } 1648 1649 let num = this.checkNum(pageArray[index]) 1650 1651 if (num){ 1652 this.cusRangeArr.push(num); 1653 }else{ 1654 this.cusRangeArr = [] 1655 return 1656 } 1657 1658 } 1659 const set = new Set(this.cusRangeArr) 1660 this.cusRangeArr = Array.from(set) 1661 let length = value.length 1662 if (length >= Constants.MAX_CUSTOM_PRINT_RANGE_LENGTH) { 1663 this.errorMessage = $r('app.string.cus_range_error_words_limit') 1664 this.cusRangeBorderColor = $r('app.color.border_line_error') 1665 this.isCusRangeMax = true 1666 return 1667 } 1668 Log.info(TAG,'checkCustomRange this.cusRangeArr = ',JSON.stringify(this.cusRangeArr)) 1669 } 1670 1671 checkNum(numStr:string):number{ 1672 if (numStr.includes('.')||numStr.startsWith('0')){ 1673 this.setInvalidRange() 1674 return 1675 } 1676 let num = Number(numStr) 1677 if (Number.isNaN(num)||num < 1){ 1678 this.setInvalidRange() 1679 return undefined 1680 }else if (num > this.totalPage) { 1681 this.errorMessage = $r('app.string.cus_range_error_max_image_count',this.totalPage.toString()) 1682 this.cusRangeBorderColor = $r('app.color.border_line_error') 1683 this.isCusRangeError = true 1684 return undefined 1685 } 1686 return num 1687 } 1688 1689 setInvalidRange(){ 1690 this.errorMessage = $r('app.string.cus_range_error_invalid_range') 1691 this.cusRangeBorderColor = $r('app.color.border_line_error') 1692 this.isCusRangeError = true 1693 } 1694 1695 needDuplexChange(){ 1696 Log.info(TAG,'needDuplexChange ') 1697 if(!this.needDuplex && !(this.currentDuplex === SelectionModel.DuplexMode_SINGLE)){ 1698 this.currentDuplex = SelectionModel.DuplexMode_SINGLE 1699 } 1700 } 1701 1702 setStartPageStr(){ 1703 this.startPageStr = '' 1704 this.startPageStr = this.startPage.toString(); 1705 } 1706 setEndPageStr(){ 1707 this.endPageStr = '' 1708 this.endPageStr = this.endPage.toString(); 1709 } 1710 /** 1711 * 检查传入图片数量,大于100时不与加载 1712 * 1713 */ 1714 checkMaxPages(fileList: Array<string>): Array<string>{ 1715 let returnList: Array<string>; 1716 if (fileList.length > Constants.MAX_PAGES) { 1717 returnList = fileList.slice(0,Constants.MAX_PAGES); 1718 setTimeout(() => {//延迟弹窗,否则会概率弹窗失败 1719 this.showToast($r('app.string.toast_max_copies')); 1720 }, Constants.SHOW_TOAST_TIMEOUT); 1721 } else { 1722 returnList = fileList 1723 } 1724 return returnList 1725 } 1726 1727 checkCustomRangeTextInput(){ 1728 if (this.printRangeType !== PrintRangeType.CUSTOM){ 1729 return; 1730 } 1731 if (this.isCusRangeError) { 1732 this.editCusRangeFlag = false 1733 this.cusRangeText = '' 1734 this.isCusRangeError = false 1735 } 1736 this.isCusRangeMax = false 1737 this.cusRangeBorderColor = $r('app.color.border_line') 1738 if (this.cusRangeArr.length === 0 ) { 1739 this.printRangeType = PrintRangeType.ALL; 1740 this.updatePrintRange() 1741 } 1742 } 1743} 1744 1745