xg-project-library/js/base.js

64 lines
2.0 KiB
JavaScript
Raw Normal View History

2024-10-31 11:03:26 +00:00
const base = {
template: `
<div class="red-dot" v-if="hideIcon" :style="{top: top + 'px',left: left + 'px'}"></div>
<div class="base flexcenter">
<div class="left flexacenter">
<div class="text flex1">搜索项目</div>
2024-11-04 11:01:08 +00:00
<img class="img" src="/img/search-black-icon.svg" />
2024-10-31 11:03:26 +00:00
</div>
<div class="rigth flexacenter">
2024-11-04 11:01:08 +00:00
<img class="img" src="/img/contrast-icon.png" />
2024-10-31 11:03:26 +00:00
<div class="text">项目对比</div>
2024-11-04 11:01:08 +00:00
<div class="number">{{ count }}</div>
2024-10-31 11:03:26 +00:00
</div>
</div>`,
data() {
return {
hideIcon: false,
top: 0,
left: 0,
2024-11-04 11:01:08 +00:00
count:0,
2024-10-31 11:03:26 +00:00
}
},
methods: {
customMethod() {
console.log("Custom method called")
},
// 计算按钮位置
2024-11-04 11:01:08 +00:00
calculate(random, count) {
this.count = count
2024-10-31 11:03:26 +00:00
const dom = document.querySelector(".add" + random)
const rect = dom.getBoundingClientRect()
const top = rect.top + rect.height / 2 - 5
const left = rect.left + rect.width / 2 - 5
this.top = top
this.left = left
this.hideIcon = true
setTimeout(() => {
const dom = document.querySelector(".base .number")
const rect = dom.getBoundingClientRect()
const top = rect.top + rect.height / 2 - 5
const left = rect.left + rect.width / 2 - 5
this.top = top
this.left = left
}, 10)
setTimeout(() => {
this.top = null
this.left = null
this.hideIcon = false
}, 330)
return
const button = document.querySelector(".button")
const container = document.querySelector(".container")
const containerWidth = container.offsetWidth
const buttonWidth = button.offsetWidth
const buttonLeft = (containerWidth - buttonWidth) / 2
button.style.left = buttonLeft + "px"
},
},
}