|
@@ -52,66 +52,25 @@ export default class ComboBox extends Base {
|
|
|
this.eventBus._on('comboBoxPropertyPanelChanged', this.handlePropertyPanel.bind(this))
|
|
|
this.eventBus._on('setProperty', this.setProperty.bind(this))
|
|
|
this.eventBus._on('changeSelectAvailable', this.changeSelectAvailable.bind(this))
|
|
|
-
|
|
|
- for (let key in this.annotation) {
|
|
|
- if (key === 'background-color') {
|
|
|
- let newName = 'backgroundColor'
|
|
|
- this.annotation[newName] = this.annotation[key]
|
|
|
- delete this.annotation[key]
|
|
|
- }
|
|
|
- if (key === 'fieldname') {
|
|
|
- let newKey = 'fieldName'
|
|
|
- this.annotation[newKey] = this.annotation[key]
|
|
|
- delete this.annotation[key]
|
|
|
- }
|
|
|
- if (key === 'opt') {
|
|
|
- let newKey = 'options'
|
|
|
- let options = []
|
|
|
- if (Array.isArray(this.annotation[key])) {
|
|
|
- for (const item of this.annotation[key]) {
|
|
|
- options.push(item.value ?? item.key)
|
|
|
- }
|
|
|
- } else {
|
|
|
- options.push(this.annotation[key].value)
|
|
|
- }
|
|
|
- this.annotation[newKey] = options
|
|
|
- delete this.annotation[key]
|
|
|
- }
|
|
|
- if (!this.annotation['opt'] && !this.annotation['options']) {
|
|
|
- this.annotation.options = []
|
|
|
- }
|
|
|
- if (key === 'options' && typeof this.annotation.options === 'string') {
|
|
|
- this.annotation.options = this.annotation.options.split(',')
|
|
|
- }
|
|
|
- if (key === 'flags') {
|
|
|
- let newKey = 'isHidden'
|
|
|
- this.annotation[newKey] = this.annotation[key].indexOf('noview') > -1 || this.annotation[key].indexOf('hidden') > -1 ? '1' : '0'
|
|
|
- delete this.annotation[key]
|
|
|
- }
|
|
|
- if (key === 'select' && !this.layer.annotationStore.notFirstRender) {
|
|
|
- this.annotation[key] = (parseInt(this.annotation[key]) + 1).toString()
|
|
|
- }
|
|
|
- if (key === 'textStyle') {
|
|
|
- const textStyle = this.annotation[key]
|
|
|
- if (textStyle.fontColor) this.annotation.textColor = textStyle.fontColor
|
|
|
- if (textStyle.fontSize) this.annotation.fontSize = parseInt(textStyle.fontSize).toString()
|
|
|
- if (textStyle.fontName && textStyle.fontName.length > 0) {
|
|
|
- const fontArr = [ 'Courier', 'Courier-Bold', 'Courier-BoldOblique', 'Courier-Oblique', 'Helvetica', 'Helvetica-Bold', 'Helvetica-BoldOblique', 'Helvetica-Oblique', 'Times-Roman', 'Times-Bold', 'Times-BoldItalic', 'Times-Italic' ]
|
|
|
- this.annotation.fontName = 'Helvetica'
|
|
|
- for (const item of fontArr) {
|
|
|
- if (item.toLowerCase() === textStyle.fontName.toLowerCase()) {
|
|
|
- this.annotation.fontName = item
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- this.annotation.fontName = 'Helvetica'
|
|
|
- }
|
|
|
- }
|
|
|
+ const annotation = this.annotation
|
|
|
+ if (!annotation.items) {
|
|
|
+ annotation.items = []
|
|
|
}
|
|
|
- if (!this.annotation['select']) {
|
|
|
- this.annotation.select = '1'
|
|
|
+ if (!annotation.fontName) {
|
|
|
+ annotation.fontName = 'Helvetica'
|
|
|
+ }
|
|
|
+ if (!annotation.select) {
|
|
|
+ annotation.select = 0
|
|
|
+ }
|
|
|
+ if (annotation.isBold && annotation.isItalic) {
|
|
|
+ annotation.fontStyle = 'boldItalic'
|
|
|
+ } else if (annotation.isBold) {
|
|
|
+ annotation.fontStyle = 'bold'
|
|
|
+ } else if (annotation.isItalic) {
|
|
|
+ annotation.fontStyle = 'italic'
|
|
|
+ } else {
|
|
|
+ annotation.fontStyle = 'normal'
|
|
|
}
|
|
|
- const annotation = this.annotation
|
|
|
|
|
|
const { start, end } = this.getActualRect(
|
|
|
this.viewport,
|
|
@@ -121,7 +80,6 @@ export default class ComboBox extends Base {
|
|
|
this.end = end
|
|
|
|
|
|
const rect = this.calculate(start, end)
|
|
|
- const actualbdwidth = (this.annotation.lineWidth || this.annotation.width || 2) * this.scale
|
|
|
|
|
|
const annotationContainer = document.createElement('div')
|
|
|
annotationContainer.id = annotation.name
|
|
@@ -140,7 +98,6 @@ export default class ComboBox extends Base {
|
|
|
top: 0,
|
|
|
width: `${Math.abs(rect.width)}px`,
|
|
|
height: `${Math.abs(rect.height)}px`,
|
|
|
- backgroundColor: annotation.backgroundColor,
|
|
|
position: 'relative',
|
|
|
overflow: 'hidden'
|
|
|
}
|
|
@@ -154,17 +111,18 @@ export default class ComboBox extends Base {
|
|
|
paddingLeft: '4px',
|
|
|
width: `${Math.abs(rect.width)}px`,
|
|
|
height: `${Math.abs(rect.height)}px`,
|
|
|
- borderColor: '#43474D',
|
|
|
- borderWidth: '1px',
|
|
|
- borderStyle: 'solid',
|
|
|
- borderRadius: '0',
|
|
|
+ borderColor: annotation.borderColor,
|
|
|
+ borderWidth: (annotation.borderWidth || 1) + 'px',
|
|
|
+ borderStyle: annotation.borderStyle || 'solid',
|
|
|
cursor: 'pointer',
|
|
|
webkitAppearance: 'none',
|
|
|
appearance: 'none',
|
|
|
- background: 'transparent',
|
|
|
+ backgroundColor: annotation.backgroundColor,
|
|
|
fontSize: annotation.fontSize + 'px',
|
|
|
fontFamily: annotation.fontName,
|
|
|
- color: annotation.textColor,
|
|
|
+ color: annotation.color,
|
|
|
+ fontWeight: annotation.isBold ? 'bold' : 'normal',
|
|
|
+ fontStyle: annotation.isItalic ? 'italic' : 'normal',
|
|
|
textOverflow: 'ellipsis',
|
|
|
whiteSpace: 'nowrap'
|
|
|
}
|
|
@@ -212,12 +170,12 @@ export default class ComboBox extends Base {
|
|
|
this.container.append(this.annotationContainer)
|
|
|
|
|
|
// 添加选项
|
|
|
- if (annotation.options && annotation.options.length > 0) {
|
|
|
- for (var i = 0; i < annotation.options.length; i++) {
|
|
|
+ if (annotation.items && annotation.items.length > 0) {
|
|
|
+ for (var i = 0; i < annotation.items.length; i++) {
|
|
|
const optionElement = createElement('option')
|
|
|
- optionElement.value = annotation.options[i]
|
|
|
- optionElement.innerHTML = annotation.options[i]
|
|
|
- if (this.annotation.select - 1 === i) {
|
|
|
+ optionElement.value = annotation.items[i].Value
|
|
|
+ optionElement.innerHTML = annotation.items[i].Value
|
|
|
+ if (annotation.selected === i) {
|
|
|
optionElement.selected = true
|
|
|
}
|
|
|
this.selectElement.appendChild(optionElement)
|
|
@@ -411,10 +369,10 @@ export default class ComboBox extends Base {
|
|
|
this.initial = true
|
|
|
|
|
|
if (this.layer.toolMode !== 'form') {
|
|
|
- if (this.annotation['isHidden'] === '1') {
|
|
|
+ if (this.annotation.isHidden === 1) {
|
|
|
this.annotationContainer.style.display = 'none'
|
|
|
this.annotationContainer.style.pointerEvents = 'none'
|
|
|
- } else if (this.annotation['isHidden'] === '0') {
|
|
|
+ } else if (this.annotation.isHidden === 0) {
|
|
|
this.annotationContainer.style.display = 'block'
|
|
|
this.annotationContainer.style.pointerEvents = 'auto'
|
|
|
}
|
|
@@ -461,13 +419,13 @@ export default class ComboBox extends Base {
|
|
|
|
|
|
calculate (start, end) {
|
|
|
const initRect = this.rectCalc({ start, end });
|
|
|
- const actualbdwidth = (this.annotation.width || this.annotation.lineWidth || 2) * this.scale
|
|
|
+ const actualBdWidth = (this.annotation.borderWidth || 1) * this.scale
|
|
|
|
|
|
return {
|
|
|
- top: initRect.top - actualbdwidth,
|
|
|
- left: initRect.left - actualbdwidth,
|
|
|
- width: initRect.width + actualbdwidth * 2,
|
|
|
- height: initRect.height + actualbdwidth * 2,
|
|
|
+ top: initRect.top - actualBdWidth,
|
|
|
+ left: initRect.left - actualBdWidth,
|
|
|
+ width: initRect.width + actualBdWidth * 2,
|
|
|
+ height: initRect.height + actualBdWidth * 2,
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -779,8 +737,6 @@ export default class ComboBox extends Base {
|
|
|
this.newStart = start
|
|
|
this.newEnd = end
|
|
|
|
|
|
- const actualbdwidth = (this.annotation.lineWidth || this.annotation.width || 2) * this.scale
|
|
|
-
|
|
|
this.annotationContainer.style.top = rect.top + 'px'
|
|
|
this.annotationContainer.style.left = rect.left + 'px'
|
|
|
this.annotationContainer.style.width = rect.width + 'px'
|
|
@@ -833,73 +789,170 @@ export default class ComboBox extends Base {
|
|
|
}
|
|
|
|
|
|
handlePropertyPanel (props) {
|
|
|
- if (this.layer.annotationStore.selectedElementName !== this.annotation.name) return
|
|
|
+ const annotation = this.annotation
|
|
|
+ if (this.layer.annotationStore.selectedElementName !== annotation.name) return
|
|
|
|
|
|
let updatePropsNum = 0
|
|
|
for (const key in props) {
|
|
|
- for (const item in this.annotation) {
|
|
|
- if (item === key && key === 'options' && JSON.stringify(this.annotation[item]) !== JSON.stringify(props[key])) {
|
|
|
- if (typeof props[key] === 'string') {
|
|
|
- props[key] = props[key].split(',')
|
|
|
- } else {
|
|
|
- props[key] = Array.from(props[key])
|
|
|
- }
|
|
|
- this.annotation[item] = props[key]
|
|
|
+ for (const item in annotation) {
|
|
|
+ if (item === key && annotation[item] !== props[key]) {
|
|
|
updatePropsNum ++
|
|
|
|
|
|
- this.selectElement.innerHTML = ''
|
|
|
- for (var i = 0; i < this.annotation.options.length; i++) {
|
|
|
- const optionElement = createElement('option')
|
|
|
- optionElement.value = this.annotation.options[i]
|
|
|
- optionElement.innerHTML = this.annotation.options[i]
|
|
|
- if (this.annotation.select - 1 === i) {
|
|
|
- optionElement.selected = true
|
|
|
- }
|
|
|
- this.selectElement.appendChild(optionElement)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (item === key && this.annotation[item] !== props[key] && key !== 'options') {
|
|
|
- this.annotation[item] = props[key]
|
|
|
- updatePropsNum ++
|
|
|
+ annotation[item] = props[key]
|
|
|
|
|
|
if (key === 'backgroundColor') {
|
|
|
- this.borderElement.style[key] = props[key]
|
|
|
if (props[key] === '') {
|
|
|
props.clearBackgroundColor = true
|
|
|
}
|
|
|
+ this.selectElement.style[key] = props[key]
|
|
|
}
|
|
|
if (key === 'fontSize') {
|
|
|
this.selectElement.style.fontSize = props[key] + 'px'
|
|
|
}
|
|
|
- if (key === 'textColor') {
|
|
|
+ if (key === 'color') {
|
|
|
this.selectElement.style.color = props[key]
|
|
|
}
|
|
|
if (key === 'fontName') {
|
|
|
this.selectElement.style.fontFamily = props[key]
|
|
|
}
|
|
|
+ if (key === 'fontStyle') {
|
|
|
+ const fontStyle = props[key]
|
|
|
+ if (fontStyle === 'boldItalic') {
|
|
|
+ this.selectElement.style.fontStyle = 'italic'
|
|
|
+ this.selectElement.style.fontWeight = 'bold'
|
|
|
+ annotation.isBold = true
|
|
|
+ annotation.isItalic = true
|
|
|
+ } else if (fontStyle === 'bold') {
|
|
|
+ this.selectElement.style.fontWeight = 'bold'
|
|
|
+ annotation.isBold = true
|
|
|
+ annotation.isItalic = false
|
|
|
+ } else if (fontStyle === 'italic') {
|
|
|
+ this.selectElement.style.fontStyle = 'italic'
|
|
|
+ annotation.isBold = false
|
|
|
+ annotation.isItalic = true
|
|
|
+ } else {
|
|
|
+ annotation.isItalic = false
|
|
|
+ annotation.isBold = false
|
|
|
+ this.selectElement.style.fontStyle = 'normal'
|
|
|
+ this.selectElement.style.fontWeight = 'normal'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (key === 'addItem') {
|
|
|
+ if (annotation.items.includes(props.addItem)) {
|
|
|
+ delete props.addItem
|
|
|
+ continue
|
|
|
+ } else {
|
|
|
+ updatePropsNum ++
|
|
|
+
|
|
|
+ annotation.items.push({
|
|
|
+ Value: props.addItem,
|
|
|
+ String: props.addItem
|
|
|
+ })
|
|
|
+ const optionElement = createElement('option')
|
|
|
+ optionElement.value = props.addItem
|
|
|
+ optionElement.innerHTML = props.addItem
|
|
|
+ this.selectElement.appendChild(optionElement)
|
|
|
+
|
|
|
+ props.addItem = {
|
|
|
+ item: props.addItem,
|
|
|
+ index: annotation.items.length - 1
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ if (key === 'deleteItemIndex') {
|
|
|
+ updatePropsNum ++
|
|
|
+
|
|
|
+ const deleteItemIndex = props.deleteItemIndex
|
|
|
+ if (annotation.selected === props.deleteItemIndex) {
|
|
|
+ annotation.selected = null
|
|
|
+ }
|
|
|
+ annotation.items.splice(deleteItemIndex, 1)
|
|
|
+ this.selectElement.options[deleteItemIndex].remove()
|
|
|
+ // this.selectElement.options[props.selected].selected = true
|
|
|
+ // if (deleteIndex === annotation.selected) {
|
|
|
+ // this.selectElement.options[deleteIndex] && (this.selectElement.options[deleteIndex].selected = true)
|
|
|
+ // }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (key === 'moveOption') {
|
|
|
+ updatePropsNum ++
|
|
|
+
|
|
|
+ const fromIndex = props.moveOption.fromIndex
|
|
|
+ const toIndex = props.moveOption.toIndex
|
|
|
+
|
|
|
+ const items = annotation.items
|
|
|
+ if (fromIndex > toIndex) {
|
|
|
+ items.splice(fromIndex - 1, 2, items[fromIndex], items[fromIndex - 1])
|
|
|
+ } else {
|
|
|
+ items.splice(fromIndex, 2, items[fromIndex + 1], items[fromIndex])
|
|
|
+ }
|
|
|
+ props.moveOption.item = {
|
|
|
+ Value: items[toIndex].Value,
|
|
|
+ String: items[toIndex].String
|
|
|
+ }
|
|
|
+
|
|
|
+ const optionElement = this.selectElement.options[fromIndex]
|
|
|
+ optionElement.remove()
|
|
|
+
|
|
|
+ this.selectElement.insertBefore(optionElement, this.selectElement.options[toIndex])
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if (updatePropsNum > 0) {
|
|
|
- const annotation = {
|
|
|
+ const annotationData = {
|
|
|
operate: "mod-form",
|
|
|
- name: this.annotation.name,
|
|
|
+ name: annotation.name,
|
|
|
pageIndex: this.page,
|
|
|
- pagePtr: this.annotation.pagePtr,
|
|
|
- annotPtr: this.annotation.annotPtr,
|
|
|
+ index: annotation.items.length - 1,
|
|
|
+ pagePtr: annotation.pagePtr,
|
|
|
+ annotPtr: annotation.annotPtr,
|
|
|
}
|
|
|
- if (props.options) {
|
|
|
- props.options = props.options.join(',')
|
|
|
- if (props.options === '') {
|
|
|
- props.clearOption = true
|
|
|
- }
|
|
|
+ if (!annotation.items.length) {
|
|
|
+ props.clearOption = true
|
|
|
}
|
|
|
- if (props.select && typeof props.select === 'number') {
|
|
|
- props.select += ''
|
|
|
+
|
|
|
+ const isFont = ['fontSize', 'fontName', 'color', 'fontStyle'].some(item => props[item])
|
|
|
+ if (isFont) {
|
|
|
+ annotationData.fontSize = annotation.fontSize
|
|
|
+ annotationData.color = annotation.color
|
|
|
+ const fontArr = {
|
|
|
+ Courier: {
|
|
|
+ normal: 'Courier',
|
|
|
+ bold: 'Courier-Bold',
|
|
|
+ italic: 'Courier-Oblique',
|
|
|
+ boldItalic: 'Courier-BoldOblique'
|
|
|
+ },
|
|
|
+ Helvetica: {
|
|
|
+ normal: 'Helvetica',
|
|
|
+ bold: 'Helvetica-Bold',
|
|
|
+ italic: 'Helvetica-Oblique',
|
|
|
+ boldItalic: 'Helvetica-BoldOblique'
|
|
|
+ },
|
|
|
+ Times: {
|
|
|
+ normal: 'Times',
|
|
|
+ bold: 'Times-Bold',
|
|
|
+ italic: 'Times-Italic',
|
|
|
+ boldItalic: 'Times-BoldItalic'
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ const fontName = annotation.fontName
|
|
|
+ if (annotation.isBold && annotation.isItalic) {
|
|
|
+ annotationData.fontName = fontArr[fontName].boldItalic
|
|
|
+ } else if (annotation.isBold) {
|
|
|
+ annotationData.fontName = fontArr[fontName].bold
|
|
|
+ } else if (annotation.isItalic) {
|
|
|
+ annotationData.fontName = fontArr[fontName].italic
|
|
|
+ } else {
|
|
|
+ annotationData.fontName = fontArr[fontName].normal
|
|
|
+ }
|
|
|
}
|
|
|
- const updateAnnot = Object.assign({}, annotation, props)
|
|
|
+
|
|
|
+ const updateAnnot = Object.assign({}, annotationData, props)
|
|
|
this.eventBus.dispatch('annotationChange', {
|
|
|
type: 'modify',
|
|
|
annotation: updateAnnot
|
|
@@ -908,27 +961,66 @@ export default class ComboBox extends Base {
|
|
|
}
|
|
|
|
|
|
setProperty (props) {
|
|
|
- if (props.name !== this.annotation.name) return
|
|
|
+ const annotation = this.annotation
|
|
|
+ if (props.name !== annotation.name) return
|
|
|
|
|
|
for (const key in props) {
|
|
|
- for (const item in this.annotation) {
|
|
|
- if (item === key && this.annotation[item] !== props[key]) {
|
|
|
- this.annotation[item] = props[key]
|
|
|
+ for (const item in annotation) {
|
|
|
+ if (item === key && annotation[item] !== props[key]) {
|
|
|
+ annotation[item] = props[key]
|
|
|
|
|
|
if (key === 'backgroundColor') {
|
|
|
- this.borderElement.style[key] = props[key]
|
|
|
+ this.selectElement.style[key] = props[key]
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- const annotation = {
|
|
|
+ const annotationData = {
|
|
|
operate: "mod-form",
|
|
|
pageIndex: this.page,
|
|
|
- pagePtr: this.annotation.pagePtr,
|
|
|
- annotPtr: this.annotation.annotPtr,
|
|
|
+ pagePtr: annotation.pagePtr,
|
|
|
+ annotPtr: annotation.annotPtr,
|
|
|
}
|
|
|
- const updateAnnot = Object.assign({}, annotation, props)
|
|
|
+
|
|
|
+ const isFont = ['fontSize', 'fontName', 'color', 'fontStyle'].some(item => props[item])
|
|
|
+ if (isFont) {
|
|
|
+ annotationData.fontSize = annotation.fontSize
|
|
|
+ annotationData.color = annotation.color
|
|
|
+ const fontArr = {
|
|
|
+ Courier: {
|
|
|
+ normal: 'Courier',
|
|
|
+ bold: 'Courier-Bold',
|
|
|
+ italic: 'Courier-Oblique',
|
|
|
+ boldItalic: 'Courier-BoldOblique'
|
|
|
+ },
|
|
|
+ Helvetica: {
|
|
|
+ normal: 'Helvetica',
|
|
|
+ bold: 'Helvetica-Bold',
|
|
|
+ italic: 'Helvetica-Oblique',
|
|
|
+ boldItalic: 'Helvetica-BoldOblique'
|
|
|
+ },
|
|
|
+ Times: {
|
|
|
+ normal: 'Times',
|
|
|
+ bold: 'Times-Bold',
|
|
|
+ italic: 'Times-Italic',
|
|
|
+ boldItalic: 'Times-BoldItalic'
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ const fontName = annotation.fontName
|
|
|
+ if (annotation.isBold && annotation.isItalic) {
|
|
|
+ annotationData.fontName = fontArr[fontName].boldItalic
|
|
|
+ } else if (annotation.isBold) {
|
|
|
+ annotationData.fontName = fontArr[fontName].bold
|
|
|
+ } else if (annotation.isItalic) {
|
|
|
+ annotationData.fontName = fontArr[fontName].italic
|
|
|
+ } else {
|
|
|
+ annotationData.fontName = fontArr[fontName].normal
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ const updateAnnot = Object.assign({}, annotationData, props)
|
|
|
this.eventBus.dispatch('annotationChange', {
|
|
|
type: 'modify',
|
|
|
annotation: updateAnnot
|
|
@@ -944,14 +1036,10 @@ export default class ComboBox extends Base {
|
|
|
}
|
|
|
|
|
|
handleSelect () {
|
|
|
- this.annotation.select = this.selectElement.selectedIndex + 1
|
|
|
- for (var i = 0; i < this.annotation.options.length; i++) {
|
|
|
- if (this.selectElement.selectedIndex === i) {
|
|
|
- this.selectElement.options[i].selected = true
|
|
|
- }
|
|
|
- }
|
|
|
+ this.annotation.selected = this.selectElement.selectedIndex
|
|
|
+
|
|
|
this.setProperty({
|
|
|
- select: this.annotation.select + '',
|
|
|
+ selected: this.annotation.selected,
|
|
|
name: this.annotation.name
|
|
|
})
|
|
|
}
|