class Winning {
constructor(el, option) {
this.el = el
this.option = Object.assign(
{},
{
type: 'qq', // 可选择qq或者phone
min: 10, //最少数据
max: 20 // 最多数据,
},
option
)
this._init()
}
_init() {
this.getData()
}
// TODO: 生成数据(可以采用回调加强灵活性)
getData() {
let html = '',
count = random(this.option.min, this.option.max),
type = this.option.type === 'qq'
for (let i = 0; i < count; i++) {
html += `<li class="list-group-item">恭喜${
type ? 'QQ' : '手机'
}用户: <span class="text-primary">${
type ? getQQ() : getPhone()
}</span> 于 ${new Date().Format(
'yyyy-MM-dd'
)} <span class="text-danger">奖励: ${randomGift()}</span></li>`
}
document.getElementById(this.el).innerHTML = html
}
// 滚动
scroll() {}
}
//***************************** */
const random = (min, max) => Math.floor(Math.random() * (max - min + 1) + min)
// 获取随机6-10位QQ号
function getQQ() {
let qq = random(100000, 9999999999).toString()
return qq.replace(qq.substr(-4), '****')
}
let phoneTest = [
'133',
'149',
'153',
'173',
'177',
'180',
'181',
'189',
'199',
'130',
'131',
'132',
'145',
'155',
'156',
'166',
'171',
'175',
'176',
'185',
'186',
'166',
'134',
'135',
'136',
'137',
'138',
'139',
'147',
'150',
'151',
'152',
'157',
'158',
'159',
'172',
'178',
'182',
'183',
'184',
'187',
'188',
'198'
]
const getPhone = () => {
return (
phoneTest[random(0, phoneTest.length - 1)] + '****' + random(1000, 9999)
)
}
const gifts = [
'<img src="https://ae01.alicdn.com/kf/HTB10965akH0gK0jSZPi761vapXa7.png" width="15">永久豪华绿钻',
'<img src="https://ae01.alicdn.com/kf/HTB10965akH0gK0jSZPi761vapXa7.png" width="15">永久豪华绿钻',
'<img src="https://ae01.alicdn.com/kf/HTB1UsP5ahD1gK0jSZFs762ldVXaf.png" width="15">永久视频会员',
'<img src="https://ae01.alicdn.com/kf/HTB1JJ24aeL2gK0jSZPh761hvXXae.png" width="15">永久豪华黄钻',
'<img src="https://ae01.alicdn.com/kf/HTB1Cmv5abj1gK0jSZFu763rHpXaU.png" width="15">永久超级会员',
'<img src="https://ae01.alicdn.com/kf/HTB12gj5akT2gK0jSZPc763KkpXa5.png" width="15">'
]
// 随机中奖的奖品
function randomGift() {
let num = random(0, gifts.length - 1),
zan = random(100, 10000)
return num === gifts.length - 1 ? gifts[num] + `${zan}名片赞` : gifts[num]
}
// 格式化时间
Date.prototype.Format = function(fmt) {
let o = {
'M+': this.getMonth() + 1, //月份
'd+': this.getDate(), //日
'h+': this.getHours(), //小时
'm+': this.getMinutes(), //分
's+': this.getSeconds(), //秒
'q+': Math.floor((this.getMonth() + 3) / 3), //季度
S: this.getMilliseconds() //毫秒
}
if (/(y+)/.test(fmt))
fmt = fmt.replace(
RegExp.$1,
(this.getFullYear() + '').substr(4 - RegExp.$1.length)
)
for (var k in o)
if (new RegExp('(' + k + ')').test(fmt))
fmt = fmt.replace(
RegExp.$1,
RegExp.$1.length == 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length)
)
return fmt
}
网友评论