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