function Modal () {
let modal = document.getElementById('modal') || null
if (!modal) {
modal = document.createElement('div')
modal.innerHTML = '您还未登录哦~'
modal.id = 'modal'
modal.style.display = 'none'
document.body.appendChild(modal)
}
return modal
}
class OpenButton {
onClick () {
const modal = Modal()
modal.style.display = 'block'
}
}
class Decorator {
constructor(open_button) {
this.open_button = open_button
}
onClick () {
this.open_button.onClick()
this.changeButtonStatus()
}
changeModal () {
const modal = document.getElementById('modal')
modal.style.display = 'none'
}
closeClick () {
this.changeModal()
this.openButton()
}
changeButtonStatus () {
this.changeButtonText()
this.disableButton()
}
disableButton () {
const btn = document.getElementById('open')
btn.setAttribute("disabled", true)
}
openButton () {
const btn = document.getElementById('open')
btn.removeAttribute("disabled")
}
changeButtonText () {
const btn = document.getElementById('open')
btn.innerText = '快去登录'
}
}
const openButton = new OpenButton()
const decorator = new Decorator(openButton)
document.getElementById('open').addEventListener('click', function () {
decorator.onClick()
})
document.getElementById('close').addEventListener('click', function () {
decorator.closeClick()
})