From cb83f5ca5f9e232d08d8f1e07fa540d555c3fc22 Mon Sep 17 00:00:00 2001 From: SunShine55 <18772101563@163.com> Date: Mon, 11 Mar 2024 17:02:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=91=8A=E8=AD=A6=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: SunShine55 <18772101563@163.com> --- .../common/encryptionComponents/AddStaff.ets | 124 +++++++++--------- 1 file changed, 64 insertions(+), 60 deletions(-) diff --git a/entry/src/main/ets/common/encryptionComponents/AddStaff.ets b/entry/src/main/ets/common/encryptionComponents/AddStaff.ets index 12754c8..311a95b 100644 --- a/entry/src/main/ets/common/encryptionComponents/AddStaff.ets +++ b/entry/src/main/ets/common/encryptionComponents/AddStaff.ets @@ -85,57 +85,7 @@ struct AddStaff { } try { if (GlobalContext.load('domainAccount')) { - 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) { - 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); - - this.controller.deleteSpans({ start: startOffset, end: endOffset }); - setTimeout(() => { - let index: number = this.controller.getCaretOffset(); - let staffBuilder: CustomBuilder = () => { - this.StaffItemBuilder(result.accountName, result[this.textContent], index); - }; - this.controller.addBuilderSpan(staffBuilder); - }, this.staffArray['length'] > Constants.RICH_EDITOR_FIRST - ? Constants.ENCRYPTION_SET_TIMEOUT_TIME : Constants.TIMEOUT_TIME_MIN) - }).catch((error: BusinessError) => { - 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; - } else { - this.isNetworkInvalid = true; - return; - } - }) - } 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; - } else { - this.isNetworkInvalid = true; - return; - } - } - }) + this.createStaffByDomain(inputId, startOffset, endOffset); } else { this.isAccountCheckSuccess = true; let o2: Staff = { @@ -146,15 +96,7 @@ struct AddStaff { this.succ = GlobalContext.load('hiAccountVerifySucc') + 1; GlobalContext.store('hiAccountVerifySucc', this.succ); - this.controller.deleteSpans({ start: startOffset, end: endOffset }); - setTimeout(() => { - let index: number = this.controller.getCaretOffset(); - let staffBuilder: CustomBuilder = () => { - this.StaffItemBuilder(inputId, inputId, index); - }; - this.controller.addBuilderSpan(staffBuilder); - }, this.staffArray['length'] > Constants.RICH_EDITOR_FIRST - ? Constants.ENCRYPTION_SET_TIMEOUT_TIME : Constants.TIMEOUT_TIME_MIN) + this.addBuildSpan(inputId, inputId, startOffset, endOffset); } } catch (err) { this.isAccountCheckSuccess = true; @@ -164,6 +106,68 @@ struct AddStaff { } } + 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; + } else { + this.isNetworkInvalid = true; + return; + } + } + }) + } + + 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); + + this.addBuildSpan(result.accountName, result[this.textContent], startOffset, endOffset); + }).catch((error: BusinessError) => { + 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; + } 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) + } + private onDataChange() { !this.isInitDataStatus && this.staffArray && this.staffArray.forEach((item: Staff, index: number) => { let staffItemBuilder: CustomBuilder = () => {