* fix(home): 🐛 解决多次切换路由后页面卡顿的问题 #96 卸载路由时清除requestAnimationFrame * feat: ✨ 文件存储使用Blob格式 * style: 💄 修改部分类型any为具体类型 * feat: ✨ 界面设置中模块使用瀑布流布局 #96 * fix: 🐛 md文档更换文件夹解决控制台警告 * style: 💄 switch按钮改回使用daisyui组件 * refactor: ♻️ 所有人员列表提取tableColumn * style: 💄 奖项列表中的图片类型修复 * fix(globalConfig): 修复当前音乐项类型缺失问题 * feat: ✨ single person not done * feat: ✨ 可添加单人 #96 * build(.gitignore): 添加 auto-imports.d.ts 到忽略文件 * fix: 🐛 上传、下载excel文件时修复路径错误 打包成应用和网页端的baseUrl不一样,使用环境变量来表示 * fix: 🐛 导入人员列表时处理有值为空的情况 * style: 💄 改变toaster的组件 * fix: 🐛 上传文件、解析数据与存储/读取数据的处理 、 * fix(Config): 更新备案信息链接样式 将备案信息的段落标签替换为可点击的链接标签,使用户能够直接跳转到工信部备案查询页面。同时添加了悬停效果样式,提升用户体验。 * feat: ✨ 首页奖项列表样式修改 not done #96 * chore(deps): ✏️ 更新依赖版本 * chore: ✏️ gsap list demo * build: 🏗️ docker构建优化 * chore: ✏️ gsap scroll demo * style: 💄 gsap demno * feat: ✨ demo smooth scroll gsap scrolltrigger * feat(Demo): 添加更多颜色选项并注释GSAP动画 * refactor(PrizeList): 重构奖品列表组件结构 * feat(PrizeList): 重构奖品列表组件并添加滚动动画 * feat: ✨ 增加定时抽取功能 #96 * feat: ✨ 添加定时抽取功能的说明 * feat: ✨ 优化gsap #96 项数不多时不触发gsap * style: 💄 文本修改 * feat: ✨ 优化 * feat: ✨ 优化奖项列表 * fix(Home): 修复奖品列表滚动检测逻辑 * fix(home): 修复抽奖停止逻辑避免重复执行;调整卡片垂直居中位置计算 * feat: ✨ 播放中奖音频 #96
101 lines
4.6 KiB
TypeScript
101 lines
4.6 KiB
TypeScript
import type { IPersonConfig } from '@/types/storeType'
|
||
import { rgba } from '@/utils/color'
|
||
|
||
export function useElementStyle(element: any, person: IPersonConfig, index: number, patternList: number[], patternColor: string, cardColor: string, cardSize: { width: number, height: number }, textSize: number, mod: 'default' | 'lucky' | 'sphere' = 'default', type: 'add' | 'change' = 'add') {
|
||
if (patternList.includes(index + 1) && mod === 'default') {
|
||
element.style.backgroundColor = rgba(patternColor, Math.random() * 0.2 + 0.8)
|
||
}
|
||
else if (mod === 'sphere' || mod === 'default') {
|
||
element.style.backgroundColor = rgba(cardColor, Math.random() * 0.5 + 0.25)
|
||
}
|
||
else if (mod === 'lucky') {
|
||
element.style.backgroundColor = rgba(cardColor, 0.8)
|
||
}
|
||
element.style.border = `1px solid ${rgba(cardColor, 0.25)}`
|
||
element.style.boxShadow = `0 0 12px ${rgba(cardColor, 0.5)}`
|
||
element.style.width = `${cardSize.width}px`
|
||
element.style.height = `${cardSize.height}px`
|
||
if (mod === 'lucky') {
|
||
element.className = 'lucky-element-card'
|
||
}
|
||
else {
|
||
element.className = 'element-card'
|
||
}
|
||
if (type === 'add') {
|
||
element.addEventListener('mouseenter', (ev: MouseEvent) => {
|
||
const target = ev.target as HTMLElement
|
||
target.style.border = `1px solid ${rgba(cardColor, 0.75)}`
|
||
target.style.boxShadow = `0 0 12px ${rgba(cardColor, 0.75)}`
|
||
})
|
||
element.addEventListener('mouseleave', (ev: MouseEvent) => {
|
||
const target = ev.target as HTMLElement
|
||
target.style.border = `1px solid ${rgba(cardColor, 0.25)}`
|
||
target.style.boxShadow = `0 0 12px ${rgba(cardColor, 0.5)}`
|
||
})
|
||
}
|
||
element.children[0].style.fontSize = `${textSize * 0.5}px`
|
||
if (person.uid) {
|
||
element.children[0].textContent = person.uid
|
||
}
|
||
|
||
element.children[1].style.fontSize = `${textSize}px`
|
||
element.children[1].style.lineHeight = `${textSize * 3}px`
|
||
element.children[1].style.textShadow = `0 0 12px ${rgba(cardColor, 0.95)}`
|
||
if (person.name) {
|
||
element.children[1].textContent = person.name
|
||
}
|
||
// element.children[2].style.fontSize = `${textSize * 0.5}px`
|
||
// if (person.department || person.identity) {
|
||
// element.children[2].innerHTML = `${person.department ? person.department : ''}<br/>${person.identity ? person.identity : ''}`
|
||
// }
|
||
|
||
element.children[2].style.fontSize = `${textSize * 0.5}px`
|
||
// 设置部门和身份的默认值
|
||
element.children[2].innerHTML = ''
|
||
if (person.department || person.identity) {
|
||
element.children[2].innerHTML = `${person.department ? person.department : ''}<br/>${person.identity ? person.identity : ''}`
|
||
}
|
||
element.children[3].src = person.avatar
|
||
return element
|
||
}
|
||
|
||
/**
|
||
* @description 设置抽中卡片的位置
|
||
* 最少一个,最大十个
|
||
*/
|
||
// TODO:不超过5个时:单行排列;超过5个时,6:上3下3;7:上3下4;8:上3下5;9:上4下5;10:上5下5
|
||
export function useElementPosition(element: any, count: number, totalCount: number, cardSize: { width: number, height: number }, windowSize: { width: number, height: number }, cardIndex: number) {
|
||
let xTable = 0
|
||
let yTable = 0
|
||
const centerPosition = {
|
||
x: 0,
|
||
y: windowSize.height / 2 - cardSize.height * 0.9,
|
||
}
|
||
// 有一行为偶数的特殊数量
|
||
const specialPosition = [2, 4, 7, 9]
|
||
// 不包含特殊值的 和 分两行中第一行为奇数值的
|
||
if (!specialPosition.includes(totalCount) || (totalCount > 5 && cardIndex < 5)) {
|
||
const index = cardIndex % 5
|
||
if (index === 0) {
|
||
xTable = centerPosition.x
|
||
yTable = centerPosition.y - Math.floor(cardIndex / 5) * (cardSize.height + 60)
|
||
}
|
||
else {
|
||
xTable = index % 2 === 0 ? Math.ceil(index / 2) * (cardSize.width + 100) : -Math.ceil(index / 2) * (cardSize.width + 100)
|
||
yTable = centerPosition.y - Math.floor(cardIndex / 5) * (cardSize.height + 60)
|
||
}
|
||
}
|
||
else {
|
||
const index = cardIndex % 5
|
||
if (index === 0) {
|
||
xTable = centerPosition.x + (cardSize.width + 100) / 2
|
||
yTable = centerPosition.y - Math.floor(cardIndex / 5) * (cardSize.height + 60)
|
||
}
|
||
else {
|
||
xTable = index % 2 === 0 ? Math.ceil(index / 2) * (cardSize.width + 100) + (cardSize.width + 100) / 2 : -(Math.ceil(index / 2) * (cardSize.width + 100)) + (cardSize.width + 100) / 2
|
||
yTable = centerPosition.y - Math.floor(cardIndex / 5) * (cardSize.height + 60)
|
||
}
|
||
}
|
||
return { xTable, yTable }
|
||
}
|