From 18ea8c73ba373f85c19b0260d96ae11f5c926618 Mon Sep 17 00:00:00 2001 From: li-li-wang Date: Tue, 12 Mar 2024 21:36:37 +0800 Subject: [PATCH] =?UTF-8?q?DLP=E6=94=AF=E6=8C=81=E5=AF=B9=E6=89=B9?= =?UTF-8?q?=E9=87=8F=E7=94=A8=E6=88=B7=E7=9A=84=E5=A4=8D=E5=88=B6=E7=B2=98?= =?UTF-8?q?=E8=B4=B4=E6=8E=88=E6=9D=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-li-wang --- .../common/encryptionComponents/AddStaff.ets | 162 ++++++++++-------- entry/src/main/ets/pages/changeEncryption.ets | 3 +- 2 files changed, 95 insertions(+), 70 deletions(-) diff --git a/entry/src/main/ets/common/encryptionComponents/AddStaff.ets b/entry/src/main/ets/common/encryptionComponents/AddStaff.ets index 7e76c22..6210e10 100644 --- a/entry/src/main/ets/common/encryptionComponents/AddStaff.ets +++ b/entry/src/main/ets/common/encryptionComponents/AddStaff.ets @@ -51,6 +51,9 @@ struct AddStaff { @State focusFlag: boolean = false; @Prop isDisable: boolean = false; @State isInitDataStatus: boolean = false; + @State errInput: string[] = []; + @State inputArray: string[] = []; + @State isInputInvalidFlag: boolean = false; private controller: RichEditorController = new RichEditorController(); private options: RichEditorOptions = { controller: this.controller }; @@ -72,9 +75,10 @@ struct AddStaff { this.staffArrayLength = false; } - private onSubmitMock(inputId: string, startOffset: number, endOffset: number) { + private async onSubmitMock(inputId: string, startOffset: number, endOffset: number) { if (this.staffArray.length >= Constants.ENCRYPTION_ADD_STAFF_LENGTH_MAX) { this.staffArrayLength = true; + this.controller.deleteSpans({ start: startOffset, end: endOffset }); return; } if (!this.isAccountCheckSuccess) { @@ -83,89 +87,108 @@ struct AddStaff { if (!inputId) { return; } - try { + let regex: RegExp = new RegExp('(\r|\n)*', 'g'); + let inputString = inputId.replace(regex, ''); + this.inputArray = inputString.split(';'); + this.errInput = []; + this.controller.deleteSpans({ start: startOffset, end: endOffset }); + for (let i = 0; i < this.inputArray.length; i++) { + if (!this.inputArray[i]) { + continue; + } if (GlobalContext.load('domainAccount')) { - this.createStaffByDomain(inputId, startOffset, endOffset); + await this.createStaffByDomain(i); } else { this.isAccountCheckSuccess = true; let o2: Staff = { - authAccount: inputId, - textContent: inputId + authAccount: this.inputArray[i], + textContent: this.inputArray[i] + } + if (this.staffArray.length < Constants.ENCRYPTION_ADD_STAFF_LENGTH_MAX) { + this.staffArray.push(o2); + this.succ = GlobalContext.load('hiAccountVerifySucc') + 1; + GlobalContext.store('hiAccountVerifySucc', this.succ); + this.addBuildSpan(i, inputId); + } else { + this.errInput = []; } - this.staffArray.push(o2); - this.succ = GlobalContext.load('hiAccountVerifySucc') + 1; - GlobalContext.store('hiAccountVerifySucc', this.succ); - - this.addBuildSpan(inputId, inputId, startOffset, endOffset); } - } catch (err) { - this.isAccountCheckSuccess = true; - this.fail = GlobalContext.load('hiAccountVerifyFail') + 1; - GlobalContext.store('hiAccountVerifyFail', this.fail); - console.error(TAG, (err as BusinessError).code); + } + this.controller.addTextSpan(this.errInput.join(';')); + if (this.errInput.length && this.isInputInvalidFlag) { + this.isInputInvalid = true; } } - private createStaffByDomain(inputId: string, startOffset: number, endOffset: number) { - this.isAccountCheckSuccess = false; - let accountDomain: string = GlobalContext.load('accountDomain'); - let domainAccountInfo: osAccount.DomainAccountInfo = { - domain: accountDomain, - accountName: inputId.toLocaleLowerCase().trim() - }; - account_osAccount.DomainAccountManager.hasAccount(domainAccountInfo, (err: BusinessError, isExist: boolean) => { - this.isAccountCheckSuccess = true; - if (isExist) { - this.createStaffItem(inputId, startOffset, endOffset); - } else { - this.fail = GlobalContext.load('hiAccountVerifyFail') + 1; - GlobalContext.store('hiAccountVerifyFail', this.fail); - if ([Constants.ERR_JS_INVALID_PARAMETER, Constants.ERR_JS_ACCOUNT_NOT_FOUND].includes(err.code)) { - this.isInputInvalid = true; - return; + private createStaffByDomain(i: number) { + return new Promise((resolve, reject) => { + this.isAccountCheckSuccess = false; + let accountDomain: string = GlobalContext.load('accountDomain'); + let domainAccountInfo: osAccount.DomainAccountInfo = { + domain: accountDomain, + accountName: this.inputArray[i].toLocaleLowerCase().trim() + }; + account_osAccount.DomainAccountManager.hasAccount(domainAccountInfo, + async (error: BusinessError, isExist: boolean) => { + this.isAccountCheckSuccess = true; + if (isExist) { + await this.createStaffItem(i); } else { - this.isNetworkInvalid = true; - return; + this.showErrInput(i, error); } - } + resolve(); + }) }) } - private createStaffItem(inputId: string, startOffset: number, endOffset: number) { - AccountTipsConfig.getAccountInfo(inputId) - .then((result: account_osAccount.DomainAccountInfo) => { - let o1: Staff = { - authAccount: result.accountName, - textContent: result[this.textContent] as string - } - this.staffArray.push(o1); - this.succ = GlobalContext.load('hiAccountVerifySucc') + 1; - GlobalContext.store('hiAccountVerifySucc', this.succ); + private createStaffItem(i: number) { + return new Promise((resolve, reject) => { + AccountTipsConfig.getAccountInfo(this.inputArray[i]) + .then((result: account_osAccount.DomainAccountInfo) => { + let o1: Staff = { + authAccount: result.accountName, + textContent: result[this.textContent] as string + } + if (this.staffArray.length < Constants.ENCRYPTION_ADD_STAFF_LENGTH_MAX) { + this.staffArray.push(o1); + this.succ = GlobalContext.load('hiAccountVerifySucc') + 1; + GlobalContext.store('hiAccountVerifySucc', this.succ); + this.addBuildSpan(i, result[this.textContent]); + } else { + this.errInput = []; + } + }).catch((error: BusinessError) => { + this.showErrInput(i, error); + }) + resolve(); + }) + } - this.addBuildSpan(result.accountName, result[this.textContent], startOffset, endOffset); - }).catch((error: BusinessError) => { + private addBuildSpan(i: number, textContent: string) { + let index: number = this.controller.getCaretOffset(); + let staffBuilder: CustomBuilder = () => { + this.StaffItemBuilder(this.inputArray[i], textContent, index); + }; + this.controller.addBuilderSpan(staffBuilder, { offset: index }); + } + + private showErrInput(i: number, error: BusinessError) { + if (this.staffArray.length < Constants.ENCRYPTION_ADD_STAFF_LENGTH_MAX) { + this.errInput.push(this.inputArray[i]); + this.isAccountCheckSuccess = true; this.fail = GlobalContext.load('hiAccountVerifyFail') + 1; GlobalContext.store('hiAccountVerifyFail', this.fail); - if ([Constants.ERR_JS_ACCOUNT_NOT_FOUND].includes(error.code)) { - this.isInputInvalid = true; - return; + if ([ + Constants.ERR_JS_INVALID_PARAMETER, + Constants.ERR_JS_ACCOUNT_NOT_FOUND + ].includes(error.code)) { + this.isInputInvalidFlag = true; } else { this.isNetworkInvalid = true; - return; } - }) - } - - private addBuildSpan(accountName: string, textContent: string, startOffset: number, endOffset: number) { - this.controller.deleteSpans({ start: startOffset, end: endOffset }); - setTimeout(() => { - let index: number = this.controller.getCaretOffset(); - let staffBuilder: CustomBuilder = () => { - this.StaffItemBuilder(accountName, textContent, index); - }; - this.controller.addBuilderSpan(staffBuilder); - }, this.staffArray['length'] > Constants.RICH_EDITOR_FIRST - ? Constants.ENCRYPTION_SET_TIMEOUT_TIME : Constants.TIMEOUT_TIME_MIN) + } else { + this.errInput = []; + } } private onDataChange() { @@ -234,15 +257,18 @@ struct AddStaff { if (value.insertValue === Constants.ENTER_KEY_VALUE) { let richEditorSpans: (RichEditorTextSpanResult | RichEditorImageSpanResult)[] = this.controller.getSpans(); + let inputId: string = ''; + let startOffset: number[] = []; + let endOffset: number[] = []; for (let index: number = 0; index < richEditorSpans.length; index++) { let buildSpan: RichEditorTextSpanResult = richEditorSpans[index] as RichEditorTextSpanResult; if (buildSpan.textStyle) { - let inputId: string = buildSpan.value; - let startOffset: number = buildSpan.spanPosition.spanRange[0]; - let endOffset: number = buildSpan.spanPosition.spanRange[1]; - this.onSubmitMock(inputId, startOffset, endOffset); + inputId += buildSpan.value; + startOffset.push(buildSpan.spanPosition.spanRange[0]); + endOffset.push(buildSpan.spanPosition.spanRange[1]); } } + this.onSubmitMock(inputId, startOffset[0], endOffset.slice(-1)[0]); return false; } return true; diff --git a/entry/src/main/ets/pages/changeEncryption.ets b/entry/src/main/ets/pages/changeEncryption.ets index 15724b4..8a99fd8 100644 --- a/entry/src/main/ets/pages/changeEncryption.ets +++ b/entry/src/main/ets/pages/changeEncryption.ets @@ -237,7 +237,6 @@ struct changeEncryption { } catch { console.log(TAG, 'file decryption fail'); } - }).catch((err: number) => { console.error(TAG, 'DocumentViewPicker save failed', JSON.stringify(err)); }); @@ -246,7 +245,7 @@ struct changeEncryption { } } - async fileDecryption(saveRes: Array) { + async fileDecryption(saveRes: Array): Promise { let plainUri = saveRes[0]; let uriInfo: fileUri.FileUri | undefined = undefined; let file: fs.File | undefined = undefined;