feat: control related apis support the control id property
This commit is contained in:
@@ -2435,19 +2435,19 @@ export class CommandAdapt {
|
||||
public getControlValue(
|
||||
payload: IGetControlValueOption
|
||||
): IGetControlValueResult | null {
|
||||
return this.draw.getControl().getValueByConceptId(payload)
|
||||
return this.draw.getControl().getValueById(payload)
|
||||
}
|
||||
|
||||
public setControlValue(payload: ISetControlValueOption) {
|
||||
this.draw.getControl().setValueByConceptId(payload)
|
||||
this.draw.getControl().setValueById(payload)
|
||||
}
|
||||
|
||||
public setControlExtension(payload: ISetControlExtensionOption) {
|
||||
this.draw.getControl().setExtensionByConceptId(payload)
|
||||
this.draw.getControl().setExtensionById(payload)
|
||||
}
|
||||
|
||||
public setControlProperties(payload: ISetControlProperties) {
|
||||
this.draw.getControl().setPropertiesByConceptId(payload)
|
||||
this.draw.getControl().setPropertiesById(payload)
|
||||
}
|
||||
|
||||
public setControlHighlight(payload: ISetControlHighlightOption) {
|
||||
|
||||
@@ -207,11 +207,11 @@ export class Control {
|
||||
return prefixCount === postfixCount
|
||||
}
|
||||
|
||||
public getIsDisabledControl(): boolean {
|
||||
public getIsDisabledControl(context: IControlContext = {}): boolean {
|
||||
if (!this.activeControl) return false
|
||||
const { startIndex, endIndex } = this.range.getRange()
|
||||
if (startIndex === endIndex) {
|
||||
const elementList = this.getElementList()
|
||||
const { startIndex, endIndex } = context.range || this.range.getRange()
|
||||
if (startIndex === endIndex && ~startIndex && ~endIndex) {
|
||||
const elementList = context.elementList || this.getElementList()
|
||||
const startElement = elementList[startIndex]
|
||||
if (startElement.controlComponent === ControlComponent.POSTFIX) {
|
||||
return false
|
||||
@@ -569,11 +569,10 @@ export class Control {
|
||||
return this.activeControl.cut()
|
||||
}
|
||||
|
||||
public getValueByConceptId(
|
||||
payload: IGetControlValueOption
|
||||
): IGetControlValueResult {
|
||||
const { conceptId } = payload
|
||||
public getValueById(payload: IGetControlValueOption): IGetControlValueResult {
|
||||
const { id, conceptId } = payload
|
||||
const result: IGetControlValueResult = []
|
||||
if (!id && !conceptId) return result
|
||||
const getValue = (elementList: IElement[], zone: EditorZone) => {
|
||||
let i = 0
|
||||
while (i < elementList.length) {
|
||||
@@ -590,8 +589,14 @@ export class Control {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (element?.control?.conceptId !== conceptId) continue
|
||||
const { type, code, valueSets } = element.control!
|
||||
if (
|
||||
!element.control ||
|
||||
(id && element.controlId !== id) ||
|
||||
(conceptId && element.control.conceptId !== conceptId)
|
||||
) {
|
||||
continue
|
||||
}
|
||||
const { type, code, valueSets } = element.control
|
||||
let j = i
|
||||
let textControlValue = ''
|
||||
while (j < elementList.length) {
|
||||
@@ -655,9 +660,10 @@ export class Control {
|
||||
return result
|
||||
}
|
||||
|
||||
public setValueByConceptId(payload: ISetControlValueOption) {
|
||||
public setValueById(payload: ISetControlValueOption) {
|
||||
let isExistSet = false
|
||||
const { conceptId, value } = payload
|
||||
const { id, conceptId, value } = payload
|
||||
if (!id && !conceptId) return
|
||||
// 设置值
|
||||
const setValue = (elementList: IElement[]) => {
|
||||
let i = 0
|
||||
@@ -675,7 +681,13 @@ export class Control {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (element?.control?.conceptId !== conceptId) continue
|
||||
if (
|
||||
!element.control ||
|
||||
(id && element.controlId !== id) ||
|
||||
(conceptId && element.control.conceptId !== conceptId)
|
||||
) {
|
||||
continue
|
||||
}
|
||||
isExistSet = true
|
||||
const { type } = element.control!
|
||||
// 当前控件结束索引
|
||||
@@ -767,8 +779,9 @@ export class Control {
|
||||
}
|
||||
}
|
||||
|
||||
public setExtensionByConceptId(payload: ISetControlExtensionOption) {
|
||||
const { conceptId, extension } = payload
|
||||
public setExtensionById(payload: ISetControlExtensionOption) {
|
||||
const { id, conceptId, extension } = payload
|
||||
if (!id && !conceptId) return
|
||||
const setExtension = (elementList: IElement[]) => {
|
||||
let i = 0
|
||||
while (i < elementList.length) {
|
||||
@@ -785,7 +798,13 @@ export class Control {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (element?.control?.conceptId !== conceptId) continue
|
||||
if (
|
||||
!element.control ||
|
||||
(id && element.controlId !== id) ||
|
||||
(conceptId && element.control.conceptId !== conceptId)
|
||||
) {
|
||||
continue
|
||||
}
|
||||
element.control.extension = extension
|
||||
// 修改后控件结束索引
|
||||
let newEndIndex = i
|
||||
@@ -807,8 +826,9 @@ export class Control {
|
||||
}
|
||||
}
|
||||
|
||||
public setPropertiesByConceptId(payload: ISetControlProperties) {
|
||||
const { conceptId, properties } = payload
|
||||
public setPropertiesById(payload: ISetControlProperties) {
|
||||
const { id, conceptId, properties } = payload
|
||||
if (!id && !conceptId) return
|
||||
let isExistUpdate = false
|
||||
function setProperties(elementList: IElement[]) {
|
||||
let i = 0
|
||||
@@ -825,7 +845,13 @@ export class Control {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (element?.control?.conceptId !== conceptId) continue
|
||||
if (
|
||||
!element.control ||
|
||||
(id && element.controlId !== id) ||
|
||||
(conceptId && element.control.conceptId !== conceptId)
|
||||
) {
|
||||
continue
|
||||
}
|
||||
isExistUpdate = true
|
||||
element.control = {
|
||||
...element.control,
|
||||
|
||||
@@ -77,7 +77,10 @@ export class CheckboxControl implements IControlInstance {
|
||||
options: IControlRuleOption = {}
|
||||
) {
|
||||
// 校验是否可以设置
|
||||
if (!options.isIgnoreDisabledRule && this.control.getIsDisabledControl()) {
|
||||
if (
|
||||
!options.isIgnoreDisabledRule &&
|
||||
this.control.getIsDisabledControl(context)
|
||||
) {
|
||||
return
|
||||
}
|
||||
const { control } = this.element
|
||||
|
||||
@@ -99,7 +99,10 @@ export class DateControl implements IControlInstance {
|
||||
options: IControlRuleOption = {}
|
||||
): number {
|
||||
// 校验是否可以设置
|
||||
if (!options.isIgnoreDisabledRule && this.control.getIsDisabledControl()) {
|
||||
if (
|
||||
!options.isIgnoreDisabledRule &&
|
||||
this.control.getIsDisabledControl(context)
|
||||
) {
|
||||
return -1
|
||||
}
|
||||
const elementList = context.elementList || this.control.getElementList()
|
||||
@@ -147,7 +150,7 @@ export class DateControl implements IControlInstance {
|
||||
): number {
|
||||
const { isIgnoreDisabledRule = false, isAddPlaceholder = true } = options
|
||||
// 校验是否可以设置
|
||||
if (!isIgnoreDisabledRule && this.control.getIsDisabledControl()) {
|
||||
if (!isIgnoreDisabledRule && this.control.getIsDisabledControl(context)) {
|
||||
return -1
|
||||
}
|
||||
const range = this.getValueRange(context)
|
||||
@@ -171,7 +174,10 @@ export class DateControl implements IControlInstance {
|
||||
options: IControlRuleOption = {}
|
||||
) {
|
||||
// 校验是否可以设置
|
||||
if (!options.isIgnoreDisabledRule && this.control.getIsDisabledControl()) {
|
||||
if (
|
||||
!options.isIgnoreDisabledRule &&
|
||||
this.control.getIsDisabledControl(context)
|
||||
) {
|
||||
return
|
||||
}
|
||||
const elementList = context.elementList || this.control.getElementList()
|
||||
|
||||
@@ -71,10 +71,13 @@ export class ControlSearch {
|
||||
}
|
||||
}
|
||||
}
|
||||
const controlConceptId = element?.control?.conceptId
|
||||
if (!controlConceptId) continue
|
||||
const currentControl = element?.control
|
||||
if (!currentControl) continue
|
||||
const highlightIndex = this.highlightList.findIndex(
|
||||
highlight => highlight.conceptId === controlConceptId
|
||||
highlight =>
|
||||
highlight.id === element.controlId ||
|
||||
(currentControl.conceptId &&
|
||||
currentControl.conceptId === highlight.conceptId)
|
||||
)
|
||||
if (!~highlightIndex) continue
|
||||
// 搜索后控件结束索引
|
||||
|
||||
@@ -12,7 +12,10 @@ export class RadioControl extends CheckboxControl {
|
||||
options: IControlRuleOption = {}
|
||||
) {
|
||||
// 校验是否可以设置
|
||||
if (!options.isIgnoreDisabledRule && this.control.getIsDisabledControl()) {
|
||||
if (
|
||||
!options.isIgnoreDisabledRule &&
|
||||
this.control.getIsDisabledControl(context)
|
||||
) {
|
||||
return
|
||||
}
|
||||
const { control } = this.element
|
||||
|
||||
@@ -163,7 +163,7 @@ export class SelectControl implements IControlInstance {
|
||||
): number {
|
||||
const { isIgnoreDisabledRule = false, isAddPlaceholder = true } = options
|
||||
// 校验是否可以设置
|
||||
if (!isIgnoreDisabledRule && this.control.getIsDisabledControl()) {
|
||||
if (!isIgnoreDisabledRule && this.control.getIsDisabledControl(context)) {
|
||||
return -1
|
||||
}
|
||||
const elementList = context.elementList || this.control.getElementList()
|
||||
@@ -215,7 +215,10 @@ export class SelectControl implements IControlInstance {
|
||||
options: IControlRuleOption = {}
|
||||
) {
|
||||
// 校验是否可以设置
|
||||
if (!options.isIgnoreDisabledRule && this.control.getIsDisabledControl()) {
|
||||
if (
|
||||
!options.isIgnoreDisabledRule &&
|
||||
this.control.getIsDisabledControl(context)
|
||||
) {
|
||||
return
|
||||
}
|
||||
const elementList = context.elementList || this.control.getElementList()
|
||||
|
||||
@@ -75,7 +75,10 @@ export class TextControl implements IControlInstance {
|
||||
options: IControlRuleOption = {}
|
||||
): number {
|
||||
// 校验是否可以设置
|
||||
if (!options.isIgnoreDisabledRule && this.control.getIsDisabledControl()) {
|
||||
if (
|
||||
!options.isIgnoreDisabledRule &&
|
||||
this.control.getIsDisabledControl(context)
|
||||
) {
|
||||
return -1
|
||||
}
|
||||
const elementList = context.elementList || this.control.getElementList()
|
||||
@@ -122,7 +125,10 @@ export class TextControl implements IControlInstance {
|
||||
options: IControlRuleOption = {}
|
||||
): number {
|
||||
// 校验是否可以设置
|
||||
if (!options.isIgnoreDisabledRule && this.control.getIsDisabledControl()) {
|
||||
if (
|
||||
!options.isIgnoreDisabledRule &&
|
||||
this.control.getIsDisabledControl(context)
|
||||
) {
|
||||
return -1
|
||||
}
|
||||
const elementList = context.elementList || this.control.getElementList()
|
||||
|
||||
@@ -40,7 +40,8 @@ export interface IControlHighlightRule {
|
||||
|
||||
export interface IControlHighlight {
|
||||
ruleList: IControlHighlightRule[]
|
||||
conceptId: string
|
||||
id?: string
|
||||
conceptId?: string
|
||||
}
|
||||
|
||||
export interface IControlRule {
|
||||
@@ -124,7 +125,8 @@ export interface IControlRuleOption {
|
||||
}
|
||||
|
||||
export interface IGetControlValueOption {
|
||||
conceptId: string
|
||||
id?: string
|
||||
conceptId?: string
|
||||
}
|
||||
|
||||
export type IGetControlValueResult = (Omit<IControl, 'value'> & {
|
||||
@@ -134,19 +136,22 @@ export type IGetControlValueResult = (Omit<IControl, 'value'> & {
|
||||
})[]
|
||||
|
||||
export interface ISetControlValueOption {
|
||||
conceptId: string
|
||||
id?: string
|
||||
conceptId?: string
|
||||
value: string
|
||||
}
|
||||
|
||||
export interface ISetControlExtensionOption {
|
||||
conceptId: string
|
||||
id?: string
|
||||
conceptId?: string
|
||||
extension: unknown
|
||||
}
|
||||
|
||||
export type ISetControlHighlightOption = IControlHighlight[]
|
||||
|
||||
export type ISetControlProperties = {
|
||||
conceptId: string
|
||||
id?: string
|
||||
conceptId?: string
|
||||
properties: Partial<Omit<IControl, 'value'>>
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user