dev
xiaowen 3 years ago
parent f53efcc92d
commit 585ce7c131

@ -37,7 +37,7 @@ Component({
lifetimes: { lifetimes: {
attached: function () { attached: function () {
// 在组件实例进入页面节点树时执行 // 在组件实例进入页面节点树时执行
const query = this.createSelectorQuery() const query = wx.createSelectorQuery()
query.select('#' + this.data.canvasId) query.select('#' + this.data.canvasId)
.fields({ .fields({
node: true, node: true,

@ -0,0 +1,240 @@
function word_cloud(self, id, config) {
const _self = this;
_self.ownerDocument = wx.createSelectorQuery().select('#' + id).boundingClientRect();
_self.ownerWindow = self;
_self.config = config;
_self.ownerDocument.exec(res => {
_self.canvas = res[0]
})
_self.canvas.width = _self.config.width;
_self.canvas.height = _self.config.height;
_self.ctx = _self.canvas.getContext('2d');
_self.canvas.style.zIndex = 1;
_self.word = [];
_self.canvas.style.backgroundColor = _self.config.bgcolor;
}
word_cloud.prototype.clear = function () {
var _self = this;
_self.ctx.clearRect(0, 0, _self.config.width, _self.config.height);
_self.ctx_temp.clearRect(0, 0, _self.config.width, _self.config.height);
_self.word = [];
clearTimeout(_self._timeout);
}
word_cloud.prototype.show = function (data) {
var _self = this;
_self.clear();
data = data.sort(function (a, b) { //排序
return parseInt(b[0]) - parseInt(a[0]);
});
for (var i = 0; i < data.length; i++) {
if (data[i]) {
var ret = data[i];
var size = parseInt(ret[0]) * _self.config.size_zoom;
var txt = ret[1];
var color = ret[2];
if (size < _self.config.min_size) size = _self.config.min_size;
_self.word.push({
size: size,
text: txt,
color: color
});
}
}
var pixel = [];
var midx = Math.floor(_self.config.width / 2);
var midy = Math.floor(_self.config.height / 2);
var step = 1;
var isgoon = true;
while (isgoon) {
var leftX = midx - step * _self.config.minstep;
var rightX = midx + step * _self.config.minstep;
var topY = midy - step * _self.config.minstep;
var bottomY = midy + step * _self.config.minstep;
isgoon = false;
var buff = [];
if (topY >= 0) //上下
{
for (var i = leftX; i < rightX; i += _self.config.minstep) {
buff.push([i, topY]);
buff.push([i, bottomY]);
}
isgoon = true;
}
if (leftX >= 0) //左右
{
for (var i = topY; i < bottomY; i += _self.config.minstep) {
buff.push([rightX, i]);
buff.push([leftX, i]);
}
isgoon = true;
}
buff = buff.sort(function () {
return Math.floor(Math.random() * 1000) > 500;
});
pixel = pixel.concat(buff);
step++;
}
_self.pixel = pixel; //遍历路径
var curIndex = 0;
var _append = function () {
if (curIndex < _self.word.length) {
_self.appendWord(_self.word[curIndex]);
curIndex++;
_self._timeout = setTimeout(_append, _self.config.speed);
}
};
_self._timeout = setTimeout(_append, _self.config.speed);
};
word_cloud.prototype.appendWord = function (objWord) {
var _self = this;
var r = 0;
if (Math.random() * 100 < _self.config.rotate_chance) {
r = Math.round(Math.random() * 40);
if (Math.random() * 10 > 5)
r = 0 - r;
}
var imgdata = _self.ctx.getImageData(0, 0, _self.config.width, _self.config.height);
var wordData = _self.wordPixel(objWord.text, objWord.size, objWord.color, r);
var width = wordData.width;
var height = wordData.height;
var step = Math.round(width / 2);
for (var i = 0; i < _self.pixel.length; i += step) {
var x = Math.round(_self.pixel[i][0] - width / 2);
var y = Math.round(_self.pixel[i][1] - height / 2);
var curLine = 0;
var curIndex = 0;
var isfaild = false;
if (x < 0 || y < 0 || x + width > _self.config.width || y + height > _self.config.height) {
continue;
}
while (curLine < height + _self.config.spacing) {
var cSite = ((y + curLine) * _self.config.width + x + curIndex) * 4;
var tSite = (curLine * (width) + curIndex) * 4;
if (imgdata.data[cSite] > 0 || imgdata.data[cSite + 1] > 0 || imgdata.data[cSite + 2] > 0 || imgdata.data[cSite + 3] > 0) {
if (wordData.data[tSite] > 0 || wordData.data[tSite + 1] > 0 || wordData.data[tSite + 2] > 0 || wordData.data[tSite + 3] > 0) {
isfaild = true;
break;
}
}
curIndex++;
if (curIndex >= width) {
curLine++;
curIndex = 0;
}
}
if (!isfaild) {
var curData = _self.ctx.createImageData(width, height);
curLine = 0;
curIndex = 0;
while (curLine < height + _self.config.spacing) {
var cSite = ((y + curLine) * _self.config.width + x + curIndex) * 4;
var tSite = (curLine * (width) + curIndex) * 4;
if (imgdata.data[cSite] > 0 || imgdata.data[cSite + 1] > 0 || imgdata.data[cSite + 2] > 0 || imgdata.data[cSite + 3] > 0) {
curData.data[tSite] = imgdata.data[cSite];
curData.data[tSite + 1] = imgdata.data[cSite + 1];
curData.data[tSite + 2] = imgdata.data[cSite + 2];
curData.data[tSite + 3] = imgdata.data[cSite + 3];
} else {
curData.data[tSite] = wordData.data[tSite];
curData.data[tSite + 1] = wordData.data[tSite + 1];
curData.data[tSite + 2] = wordData.data[tSite + 2];
curData.data[tSite + 3] = wordData.data[tSite + 3];
}
curIndex++;
if (curIndex >= width) {
curLine++;
curIndex = 0;
}
}
_self.ctx.putImageData(curData, x, y, 0, 0, width, height);
break;
}
}
_self.ctx_temp.clearRect(0, 0, _self.config.width, _self.config.height);
};
word_cloud.prototype.wordPixel = function (text, size, color, rotate) {
var _self = this;
if (!color) {
if (_self.config.default_color && _self.config.default_color.length > 0) {
var ind = Math.round(Math.random() * _self.config.default_color.length);
color = _self.config.default_color[ind];
} else {
color = "#" + Math.floor((Math.random() * 255)).toString(16) + Math.floor((Math.random() * 255)).toString(16) + Math.floor((Math.random() * 255)).toString(16);
}
}
_self.ctx_temp.textBaseline = "top";
_self.ctx_temp.font = _self.config.default_bold + " " + size + "px " + _self.config.default_family;
_self.ctx_temp.fillStyle = color;
_self.ctx_temp.strokeStyle = color;
var height = size + _self.config.spacing;
var width = _self.ctx_temp.measureText(text).width + _self.config.spacing;
if (isNaN(rotate) || rotate == 0) {
_self.ctx_temp.fillText(text, 0, 0);
} else {
var a = Math.round(Math.abs(Math.sin((Math.PI / 180) * rotate) * height));
var b = Math.round(Math.abs(Math.sin((Math.PI / 180) * rotate) * width));
var centerX = Math.round((width + a) / 2);
var centerY = Math.round((height + b) / 2);
_self.ctx_temp.translate(centerX, centerY);
_self.ctx_temp.rotate((Math.PI / 180) * rotate);
_self.ctx_temp.translate(-centerX, -centerY);
_self.ctx_temp.fillText(text, a / 2, b / 2);
_self.ctx_temp.translate(centerX, centerY);
_self.ctx_temp.rotate((Math.PI / 180) * (-rotate));
_self.ctx_temp.translate(-centerX, -centerY);
width += a;
height += b;
}
return _self.ctx_temp.getImageData(0, 0, width, height);
}

@ -3,275 +3,257 @@ const app = getApp()
import timer from '../../../../utils/timer' import timer from '../../../../utils/timer'
Page({ Page({
/** /**
* 页面的初始数据 * 页面的初始数据
*/ */
data: { data: {
sUserName: '', sUserName: '',
sPwd: '', sPwd: '',
sPhone: '', sPhone: '',
sEmail: '', sEmail: '',
companyName: '', companyName: '',
brandName: '', brandName: '',
sVerifycode: '', sVerifycode: '',
captchaLabel: '获取验证码', captchaLabel: '获取验证码',
seconds: timer.length, captchaDisabled: false
captchaDisabled: false },
}, //用户输入
//用户输入 usernameInput(e) {
usernameInput(e) { this.setData({
this.setData({ sUserName: e.detail.value
sUserName: e.detail.value
})
},
//密码输入
passwordInput(e) {
this.setData({
sPwd: e.detail.value
})
},
//手机号输入
sPhoneInput(e) {
this.setData({
sPhone: e.detail.value
})
},
//邮箱输入
sEmailInput(e) {
this.setData({
sEmail: e.detail.value
})
},
//名称输入
companyInput(e) {
this.setData({
companyName: e.detail.value
})
},
//品牌输入
brandInput(e) {
this.setData({
brandName: e.detail.value
})
},
//验证码输入
codeInput(e) {
this.setData({
sVerifycode: e.detail.value
})
},
//获取验证码
captcha() {
let b = this.validPhone();
if (!b) return;
// 禁用按钮点击
this.setData({
captchaDisabled: true
});
// 立刻显示重发提示,不必等待倒计时启动
this.setData({
captchaLabel: timer.length + '秒后重新发送'
});
// 启动以1s为步长的倒计时
var interval = setInterval(() => {
timer.countdown(this);
}, 1000);
// 停止倒计时
setTimeout(function () {
clearInterval(interval);
}, timer.length * 1000);
let obj = {
action: 'getVERCode',
sPhone: this.data.sPhone,
}
app.globalData.request(obj).then((res) => {
if (res.Code == 1) {
wx.showModal({
title: '提示',
content: data.Msg,
}) })
} },
}).catch(err => { //密码输入
wx.showModal({ passwordInput(e) {
title: '提示', this.setData({
content: err.Msg, sPwd: e.detail.value
}) })
}) },
}, //手机号输入
sPhoneInput(e) {
/** this.setData({
* 生命周期函数--监听页面加载 sPhone: e.detail.value
*/ })
//提交审核 },
Submit() { //邮箱输入
let a = this.validfrom(); sEmailInput(e) {
if (!a) return; this.setData({
let obj = { sEmail: e.detail.value
action: 'regUser', })
sUserName: this.data.sUserName, },
sPwd: this.data.sPwd, //名称输入
sPhone: this.data.sPhone, companyInput(e) {
sEmail: this.data.sEmail, this.setData({
companyName: this.data.companyName, companyName: e.detail.value
brandName: this.data.brandName, })
sVerifycode: this.data.sVerifycode, },
} //品牌输入
app.globalData.request(obj).then((res) => { brandInput(e) {
wx.showModal({ this.setData({
title: '提示', brandName: e.detail.value
content: data.Msg, })
}) },
//验证码输入
}).catch(err => { codeInput(e) {
wx.showModal({ this.setData({
title: '提示', sVerifycode: e.detail.value
content: err.Msg, })
}) },
}) //获取验证码
}, captcha() {
validPhone() { let b = this.validPhone();
let b = true; if (!b) return;
let sPhone = this.data.sPhone; let obj = {
//验证手机号 action: 'getVERCode',
if (!this.data.sPhone) { sPhone: this.data.sPhone,
wx.showModal({ }
title: '提示', // 定时60s
content: "手机号不能为空", timer(this)
}) app.globalData.request(obj).then((res) => {
b = false; if (res.Code == 1) {
return b; wx.showModal({
} title: '提示',
//验证手机格式 content: data.Msg,
if (!(/^1[34578]\d{9}$/.test(sPhone))) { })
wx.showModal({ }
title: '提示', }).catch(err => {
content: "手机格式错误", wx.showModal({
}) title: '提示',
b = false content: err.Msg,
return b; })
} })
return b; },
}, /**
validfrom() { * 生命周期函数--监听页面加载
let a = true; */
//验证用户名 //提交审核
if (!this.data.sUserName) { Submit() {
wx.showModal({ let a = this.validfrom();
title: '提示', if (!a) return;
content: "用户名不能为空", let obj = {
}) action: 'regUser',
a = false; sUserName: this.data.sUserName,
return a; sPwd: this.data.sPwd,
} sPhone: this.data.sPhone,
//验证密码 sEmail: this.data.sEmail,
if (!this.data.sPwd) { companyName: this.data.companyName,
wx.showModal({ brandName: this.data.brandName,
title: '提示', sVerifycode: this.data.sVerifycode,
content: "密码不能为空", }
}) app.globalData.request(obj).then((res) => {
a = false; wx.showModal({
return a; title: '提示',
} content: data.Msg,
//验证手机号 })
if (!this.data.sPhone) { }).catch(err => {
wx.showModal({ wx.showModal({
title: '提示', title: '提示',
content: "手机号不能为空", content: err.Msg,
}) })
a = false; })
return a; },
} validPhone() {
//验证邮箱 let b = true;
if (!this.data.sEmail) { let sPhone = this.data.sPhone;
wx.showModal({ //验证手机号
title: '提示', if (!this.data.sPhone) {
content: "邮箱不能为空", wx.showModal({
}) title: '提示',
a = false; content: "手机号不能为空",
return a; })
} b = false;
//验证公司名称 return b;
if (!this.data.companyName) { }
wx.showModal({ //验证手机格式
title: '提示', if (!(/^1[34578]\d{9}$/.test(sPhone))) {
content: "公司名称不能为空", wx.showModal({
}) title: '提示',
a = false; content: "手机格式错误",
return a; })
} b = false
//验证品牌 return b;
if (!this.data.brandName) { }
wx.showModal({ return b;
title: '提示', },
content: "公司品牌不能为空", validfrom() {
}) let a = true;
a = false; //验证用户名
return a; if (!this.data.sUserName) {
} wx.showModal({
//验证验证码 title: '提示',
if (!this.data.sVerifycode) { content: "用户名不能为空",
wx.showModal({ })
title: '提示', a = false;
content: "公司品牌不能为空", return a;
}) }
a = false; //验证密码
return a; if (!this.data.sPwd) {
} wx.showModal({
title: '提示',
content: "密码不能为空",
})
a = false;
return a;
}
//验证手机号
if (!this.data.sPhone) {
wx.showModal({
title: '提示',
content: "手机号不能为空",
})
a = false;
return a;
}
//验证邮箱
if (!this.data.sEmail) {
wx.showModal({
title: '提示',
content: "邮箱不能为空",
})
a = false;
return a;
}
//验证公司名称
if (!this.data.companyName) {
wx.showModal({
title: '提示',
content: "公司名称不能为空",
})
a = false;
return a;
}
//验证品牌
if (!this.data.brandName) {
wx.showModal({
title: '提示',
content: "公司品牌不能为空",
})
a = false;
return a;
}
//验证验证码
if (!this.data.sVerifycode) {
wx.showModal({
title: '提示',
content: "公司品牌不能为空",
})
a = false;
return a;
}
}, },
onLoad(options) { onLoad(options) {
}, },
/** /**
* 生命周期函数--监听页面初次渲染完成 * 生命周期函数--监听页面初次渲染完成
*/ */
onReady() { onReady() {
}, },
/** /**
* 生命周期函数--监听页面显示 * 生命周期函数--监听页面显示
*/ */
onShow() { onShow() {
}, },
/** /**
* 生命周期函数--监听页面隐藏 * 生命周期函数--监听页面隐藏
*/ */
onHide() { onHide() {
}, },
/** /**
* 生命周期函数--监听页面卸载 * 生命周期函数--监听页面卸载
*/ */
onUnload() { onUnload() {
}, },
/** /**
* 页面相关事件处理函数--监听用户下拉动作 * 页面相关事件处理函数--监听用户下拉动作
*/ */
onPullDownRefresh() { onPullDownRefresh() {
}, },
/** /**
* 页面上拉触底事件的处理函数 * 页面上拉触底事件的处理函数
*/ */
onReachBottom() { onReachBottom() {
}, },
/** /**
* 用户点击右上角分享 * 用户点击右上角分享
*/ */
onShareAppMessage() { onShareAppMessage() {
} }
}) })

@ -1,24 +1,26 @@
var length = 59; var length = 60;
function countdown(that) { function countdown(that) {
    var seconds = that.data.seconds; that.setData({
    var captchaLabel = that.data.captchaLabel; captchaDisabled: true,
    if (seconds <= 1) { captchaLabel: length + '秒后重新发送'
        captchaLabel = '获取验证码'; });
        seconds = length; setTimeout(() => {
        that.setData({ if (length <= 1) {
            captchaDisabled: false length = 60
        }); that.setData({
    } else { captchaDisabled: false,
        captchaLabel = --seconds + '秒后重新发送' captchaLabel: "获取验证码"
    } });
    that.setData({ return false;
        seconds: seconds, } else {
        captchaLabel: captchaLabel length--;
    }); that.setData({
captchaDisabled: true,
captchaLabel: length + '秒后重新发送'
});
}
countdown(that)
}, 1000)
} }
module.exports = countdown
module.exports = {
    countdown: countdown,
    length: length
}
Loading…
Cancel
Save