代码迁移

This commit is contained in:
zh
2025-07-03 13:54:01 +08:00
parent b04de8a084
commit 2a4da33e62
985 changed files with 358292 additions and 13 deletions

View File

@ -0,0 +1,124 @@
class EventBinding {
constructor() {
this.element = {}
}
static event = {}
getEvent(name) {
return EventBinding.event[name]
}
getEventAll() {
return EventBinding.event
}
setEvent(name, event) {
EventBinding.event[name] = event
}
on(that, elements) {
this.element = {}
for (let i = 0; i < elements.length; i++) {
if (!elements[i] || !elements[i].attributes) {
continue;
}
let Event = {
'input': [],
'change': [],
'blur': [],
'click': []
}
let isEvent = false
let removeName = []
for (let m of elements[i].attributes) {
switch (m.name) {
case '@model': {
isEvent = true
if (elements[i].type == 'checkbox') {
Event.change.push((e) => { that[m.value] = e.target.checked })
elements[i].checked = that[m.value]
}
else {
if (elements[i].type == 'number') {
Event.input.push((e) => {
if (e.target.value || e.target.value === 0) {
let value = e.target.value
value = Number(value)
if (e.data != '.' && (e.data != '-' || e.target.value)) {
if (((!e.target.max) && (!e.target.min)) || ((value <= Number(e.target.max)) && value >= Number(e.target.min))) {
that[m.value] = value
}
}
}
})
Event.blur.push((e) => {
let value = e.target.value
if (e.target.value || (e.target.dataset.null !== 'undefined' && e.target.dataset.null !== '' && !Boolean(e.target.dataset.null))) {
value = Number(value)
if ((e.target.max) && value > Number(e.target.max)) {
value = Number(e.target.max)
}
if ((e.target.min) && value < Number(e.target.min)) {
value = Number(e.target.min)
}
if((e.target.dataset.min) && value<Number(e.target.dataset.min)) {
value = Number(e.target.dataset.min)
}
}
that[m.value] = value
})
}
else {
Event.input.push((e) => {
that[m.value] = e.target.value
})
}
if (elements[i].nodeName == 'IMG') {
elements[i].src = that[m.value]
}
else {
elements[i].value = that[m.value]
}
}
if (this.element[m.value]) {
this.element[m.value].push(elements[i])
}
else {
this.element[m.value] = [elements[i]]
}
removeName.push(m.name)
break;
}
case '@click': {
isEvent = true
Event.click.push((e) => {
if (typeof (that[m.value]) === 'function') {
that[m.value](e)
}
})
removeName.push(m.name)
break;
}
}
// elements[i].attributes[m] = undefined
}
for (let n = 0; n < removeName.length; n++) {
elements[i].attributes.removeNamedItem(removeName[n])
}
if (isEvent) {
for (let key in Event) {
if (Event[key].length > 0) {
elements[i].addEventListener(key, (e) => {
for (let t = 0; t < Event[key].length; t++) {
Event[key][t](e)
}
});
}
}
}
}
}
}
export default EventBinding;

View File

@ -0,0 +1,178 @@
import BaseDialog from '../../../BaseDialog';
class Dialog extends BaseDialog {
constructor(sdk, info, options, only) {
super(sdk.viewer._container, options);
this.sdk = sdk
this.viewer = sdk.viewer
this.info = info
if (only) {
this.closeAll()
}
this._init()
}
async _init() {
await this.init()
await this._attribute()
if (this.options.confirmCallBack) {
let confirmBtn = document.createElement('button');
confirmBtn.className = 'confirm';
confirmBtn.innerHTML = '确认'
this.footAppChild(confirmBtn)
confirmBtn.addEventListener('click', () => {
// console.log('确认')
if (this.options.confirmCallBack) {
this.options.confirmCallBack(this.info)
}
});
}
if (this.options.removeCallBack) {
let deleteBtn = document.createElement('button');
deleteBtn.className = 'delete';
deleteBtn.innerHTML = '删除'
this.footAppChild(deleteBtn)
deleteBtn.addEventListener('click', () => {
// console.log('删除')
this.close()
if (this.options.removeCallBack) {
this.options.removeCallBack()
}
});
}
// if (this.options.resetCallBack) {
// let resetBtn = document.createElement('button');
// resetBtn.className = 'reset';
// resetBtn.innerHTML = '重置'
// this.footAppChild(resetBtn)
// resetBtn.addEventListener('click', () => {
// // console.log('重置')
// if (this.options.resetCallBack) {
// this.options.resetCallBack()
// }
// });
// }
if (this.options.rotateCallBack) {
let rotateBtn = document.createElement('button');
rotateBtn.className = 'rotate';
rotateBtn.innerHTML = '旋转'
this.footAppChild(rotateBtn)
rotateBtn.addEventListener('click', () => {
// console.log('旋转')
if (this.options.rotateCallBack) {
this.options.rotateCallBack()
}
});
}
if (this.options.translationalCallBack || this.options.updateHeightCallBack || this.options.secondaryEditCallBack) {
let div = document.createElement('div');
div.style.position ='absolute'
div.style.left ='24px'
div.style.flet = '0'
div.style.display = 'flex'
this.footAppChild(div)
if (this.options.updateHeightCallBack) {
let heightBtn = document.createElement('button');
heightBtn.innerHTML = '<svg class="icon-updateheigh"><use xlink:href="#yj-icon-updateheight"></use></svg>更新高程'
heightBtn.style.width = 'auto'
heightBtn.addEventListener('click', () => {
this.options.updateHeightCallBack()
})
div.appendChild(heightBtn)
}
if (this.options.secondaryEditCallBack) {
let secondaryEditBtn = document.createElement('button');
secondaryEditBtn.className = 'secondaryEdit';
secondaryEditBtn.innerHTML = '<svg class="icon-edit"><use xlink:href="#yj-icon-edit"></use></svg>二次编辑'
if (this.options.updateHeightCallBack) {
secondaryEditBtn.style.marginLeft = '10px'
}
div.appendChild(secondaryEditBtn)
secondaryEditBtn.addEventListener('click', () => {
// console.log('二次编辑')
if (this.options.secondaryEditCallBack) {
this.options.secondaryEditCallBack()
}
});
}
if (this.options.translationalCallBack) {
let translationalBtn = document.createElement('button');
translationalBtn.className = 'translational';
translationalBtn.innerHTML = `<svg class="icon-py"><use xlink:href="#yj-icon-py"></use></svg>平移`
if (this.options.updateHeightCallBack || this.options.secondaryEditCallBack) {
translationalBtn.style.marginLeft = '10px'
}
div.appendChild(translationalBtn)
translationalBtn.addEventListener('click', () => {
// console.log('平移')
if (this.options.translationalCallBack) {
this.options.translationalCallBack()
}
});
}
}
if (this.options.addFootElm) {
for (let i = 0; i < this.options.addFootElm.length; i++) {
let elm = document.createElement(this.options.addFootElm[i].tagName);
elm.className = this.options.addFootElm[i].className
elm.innerHTML = this.options.addFootElm[i].innerHTML
if(this.options.addFootElm[i].event && this.options.addFootElm[i].event.length==2) {
elm.addEventListener(this.options.addFootElm[i].event[0], this.options.addFootElm[i].event[1])
}
this.footAppChild(elm)
}
}
// if (this.options.showCallBack) {
// let showBox = document.createElement('div');
// showBox.className = 'show';
// showBox.style = 'display: flex;align-items: center;'
// showBox.innerHTML = `<span class="label">隐藏</span><input class="btn-switch" type="checkbox" checked name="show"><span class="label">显示</span>`
// this.footAppChild(showBox)
// let showBtn = showBox.querySelector("input[name='show']")
// this.showBtn = showBtn
// showBtn.checked = this.info.show
// showBtn.addEventListener('input', (e) => {
// this.info.show = e.target.checked
// if (this.options.showCallBack) {
// this.options.showCallBack(this.info.show)
// }
// });
// }
}
_attribute() {
let attribute = this._element.content.getElementsByClassName('attribute')[0]
if (!attribute || attribute.length === 0) {
return
}
let attributeSelectOption = attribute.getElementsByClassName('attribute-select')[0].getElementsByTagName('option')
for (let i = attributeSelectOption.length - 1; i >= 0; i--) {
for (let key in this.info.attribute) {
if (attributeSelectOption[i].value === key) {
if (this.info.attribute[key].disabled) {
attributeSelectOption[i].disabled = true
}
break
}
}
}
}
}
export default Dialog