diff --git a/common/createCanvas.js b/common/createCanvas.js new file mode 100644 index 0000000..781ac87 --- /dev/null +++ b/common/createCanvas.js @@ -0,0 +1,113 @@ +import { deepCopy } from '../common/utils.js' +/** 重要事件分享图绘制 + * @param {Object} option 参数 + * @param {Object} this 上下文 + * @param {Object} el canvasid + * @param {Object} createCodeImg 随机四位数 + */ +let getOptions; +export function createCanvas(options) { + return new Promise(function(resolve, reject) { + let fontSize = options.height * 3 / 6; + let ctx = uni.createCanvasContext(options.el, this); + ctx.setTextBaseline("middle"); + ctx.setFillStyle(randomColor(180, 240)); + //生成随机数 + var code = ''; + var txtArr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q','r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O','P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',0,1,2,3,4,5,6,7,8,9] + for(var i=0;i<4;i++){ + code += txtArr[randomNum(0, txtArr.length)]; + } + options.createCodeImg = code; + let arr = (code + '').split(''); + if (arr.length === 0) { + arr = ['e', 'r', 'r','o','r']; + }; + let offsetLeft = options.width * 0.6 / (arr.length - 1); + let marginLeft = options.width * 0.2; + arr.forEach((item, index) => { + ctx.setFillStyle(randomColor(0, 180)); + let size = randomNum(32, fontSize); + ctx.setFontSize(size); + let dis = offsetLeft * index + marginLeft - size * 0.3; + let deg = randomNum(-30, 30); + ctx.translate(dis, options.height*0.5); + ctx.rotate(deg * Math.PI / 180); + ctx.fillText(item, 0, 0); + ctx.rotate(-deg * Math.PI / 180); + ctx.translate(-dis, -options.height * 0.5); + }) + for (var i = 0; i < 4; i++) { + ctx.strokeStyle = randomColor(40, 180); + ctx.beginPath(); + ctx.moveTo(randomNum(0, options.width), randomNum(0,options.height)); + ctx.lineTo(randomNum(0, options.width), randomNum(0, options.height)); + ctx.stroke(); + } + for (var i = 0; i < options.width / 4; i++) { + ctx.fillStyle = randomColor(0, 255); + ctx.beginPath(); + ctx.arc(randomNum(0, options.width), randomNum(0, options.height), 1, 0, 2 * Math.PI); + ctx.fill(); + } + + ctx.save(); + + // 获取系统信息 + const result = uni.getSystemInfoSync(); + const platform = result.platform; + let time = 0; + if (platform === 'android') { + // 在安卓平台,如果海报过于复杂在转换时需要做延时,否则样式会错乱 + time = 300; + } + // this.ctx.draw(); + getOptions = deepCopy(options); + ctx.draw(false, function() { + setTimeout(function() { + //将canvas转换成临时图片文件 + wx.canvasToTempFilePath({ + width: '140', + height: '70', + canvasId: options.el, + fileType: 'png', + success(res) { + console.log('生成成功'); + console.log(res.tempFilePath, '111'); + resolve(res.tempFilePath); + }, + fail(err) { + console.log('生成失败'); + console.log('canvasToTempFilePath err', err); + reject(err); + }, + complete() { + console.log('成功、失败都走的回调'); + } + }, this); + }, time); + }); + }) +} + +export function validateCode(code) { + var code = code.toLowerCase(); + var v_code = getOptions.createCodeImg.toLowerCase(); + if (code == v_code.substring(v_code.length - 4)) { + return true; + } else { + return false; + } +} + +function randomNum(min, max) { + return Math.floor(Math.random() * (max - min) + min); +} + +function randomColor(min, max) { + let r = randomNum(min, max); + let g = randomNum(min, max); + let b = randomNum(min, max); + return "rgb(" + r + "," + g + "," + b + ")"; +} + diff --git a/common/createCanvas.js b/common/createCanvas.js new file mode 100644 index 0000000..781ac87 --- /dev/null +++ b/common/createCanvas.js @@ -0,0 +1,113 @@ +import { deepCopy } from '../common/utils.js' +/** 重要事件分享图绘制 + * @param {Object} option 参数 + * @param {Object} this 上下文 + * @param {Object} el canvasid + * @param {Object} createCodeImg 随机四位数 + */ +let getOptions; +export function createCanvas(options) { + return new Promise(function(resolve, reject) { + let fontSize = options.height * 3 / 6; + let ctx = uni.createCanvasContext(options.el, this); + ctx.setTextBaseline("middle"); + ctx.setFillStyle(randomColor(180, 240)); + //生成随机数 + var code = ''; + var txtArr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q','r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O','P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',0,1,2,3,4,5,6,7,8,9] + for(var i=0;i<4;i++){ + code += txtArr[randomNum(0, txtArr.length)]; + } + options.createCodeImg = code; + let arr = (code + '').split(''); + if (arr.length === 0) { + arr = ['e', 'r', 'r','o','r']; + }; + let offsetLeft = options.width * 0.6 / (arr.length - 1); + let marginLeft = options.width * 0.2; + arr.forEach((item, index) => { + ctx.setFillStyle(randomColor(0, 180)); + let size = randomNum(32, fontSize); + ctx.setFontSize(size); + let dis = offsetLeft * index + marginLeft - size * 0.3; + let deg = randomNum(-30, 30); + ctx.translate(dis, options.height*0.5); + ctx.rotate(deg * Math.PI / 180); + ctx.fillText(item, 0, 0); + ctx.rotate(-deg * Math.PI / 180); + ctx.translate(-dis, -options.height * 0.5); + }) + for (var i = 0; i < 4; i++) { + ctx.strokeStyle = randomColor(40, 180); + ctx.beginPath(); + ctx.moveTo(randomNum(0, options.width), randomNum(0,options.height)); + ctx.lineTo(randomNum(0, options.width), randomNum(0, options.height)); + ctx.stroke(); + } + for (var i = 0; i < options.width / 4; i++) { + ctx.fillStyle = randomColor(0, 255); + ctx.beginPath(); + ctx.arc(randomNum(0, options.width), randomNum(0, options.height), 1, 0, 2 * Math.PI); + ctx.fill(); + } + + ctx.save(); + + // 获取系统信息 + const result = uni.getSystemInfoSync(); + const platform = result.platform; + let time = 0; + if (platform === 'android') { + // 在安卓平台,如果海报过于复杂在转换时需要做延时,否则样式会错乱 + time = 300; + } + // this.ctx.draw(); + getOptions = deepCopy(options); + ctx.draw(false, function() { + setTimeout(function() { + //将canvas转换成临时图片文件 + wx.canvasToTempFilePath({ + width: '140', + height: '70', + canvasId: options.el, + fileType: 'png', + success(res) { + console.log('生成成功'); + console.log(res.tempFilePath, '111'); + resolve(res.tempFilePath); + }, + fail(err) { + console.log('生成失败'); + console.log('canvasToTempFilePath err', err); + reject(err); + }, + complete() { + console.log('成功、失败都走的回调'); + } + }, this); + }, time); + }); + }) +} + +export function validateCode(code) { + var code = code.toLowerCase(); + var v_code = getOptions.createCodeImg.toLowerCase(); + if (code == v_code.substring(v_code.length - 4)) { + return true; + } else { + return false; + } +} + +function randomNum(min, max) { + return Math.floor(Math.random() * (max - min) + min); +} + +function randomColor(min, max) { + let r = randomNum(min, max); + let g = randomNum(min, max); + let b = randomNum(min, max); + return "rgb(" + r + "," + g + "," + b + ")"; +} + diff --git a/common/mcaptcha.js b/common/mcaptcha.js new file mode 100644 index 0000000..c0eb1d2 --- /dev/null +++ b/common/mcaptcha.js @@ -0,0 +1,76 @@ +/** + * 绘制图形验证码 + */ +export class Mcaptcha { + constructor(options) { + this.options = options; + this.fontSize = options.height * 3 / 6; + this.init(); + this.refresh(); + } + init() { + this.ctx = uni.createCanvasContext(this.options.el); + this.ctx.setTextBaseline("middle"); + this.ctx.setFillStyle(this.randomColor(180, 240)); + } + refresh() { + var code = ''; + var txtArr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q','r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O','P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',0,1,2,3,4,5,6,7,8,9] + for(var i=0;i<4;i++){ + code += txtArr[this.randomNum(0, txtArr.length)]; + } + this.options.createCodeImg = code; + let arr = (code + '').split(''); + if (arr.length === 0) { + arr = ['e', 'r', 'r','o','r']; + }; + let offsetLeft = this.options.width * 0.6 / (arr.length - 1); + let marginLeft = this.options.width * 0.2; + arr.forEach((item, index) => { + this.ctx.setFillStyle(this.randomColor(0, 180)); + let size = this.randomNum(32, this.fontSize); + this.ctx.setFontSize(size); + let dis = offsetLeft * index + marginLeft - size * 0.3; + let deg = this.randomNum(-30, 30); + this.ctx.translate(dis, this.options.height*0.5); + this.ctx.rotate(deg * Math.PI / 180); + this.ctx.fillText(item, 0, 0); + this.ctx.rotate(-deg * Math.PI / 180); + this.ctx.translate(-dis, -this.options.height * 0.5); + }) + for (var i = 0; i < 4; i++) { + this.ctx.strokeStyle = this.randomColor(40, 180); + this.ctx.beginPath(); + this.ctx.moveTo(this.randomNum(0, this.options.width), this.randomNum(0, this.options.height)); + this.ctx.lineTo(this.randomNum(0, this.options.width), this.randomNum(0, this.options.height)); + this.ctx.stroke(); + } + for (var i = 0; i < this.options.width / 4; i++) { + this.ctx.fillStyle = this.randomColor(0, 255); + this.ctx.beginPath(); + this.ctx.arc(this.randomNum(0, this.options.width), this.randomNum(0, this.options.height), 1, 0, 2 * Math.PI); + this.ctx.fill(); + } + this.ctx.draw(); + } + validate(code){ + var code = code.toLowerCase(); + var v_code = this.options.createCodeImg.toLowerCase(); + console.log(code) + console.log(v_code.substring(v_code.length - 4)) + if (code == v_code.substring(v_code.length - 4)) { + return true; + } else { + return false; + } + } + randomNum(min, max) { + return Math.floor(Math.random() * (max - min) + min); + } + randomColor(min, max) { + let r = this.randomNum(min, max); + let g = this.randomNum(min, max); + let b = this.randomNum(min, max); + return "rgb(" + r + "," + g + "," + b + ")"; + } +} \ No newline at end of file diff --git a/common/createCanvas.js b/common/createCanvas.js new file mode 100644 index 0000000..781ac87 --- /dev/null +++ b/common/createCanvas.js @@ -0,0 +1,113 @@ +import { deepCopy } from '../common/utils.js' +/** 重要事件分享图绘制 + * @param {Object} option 参数 + * @param {Object} this 上下文 + * @param {Object} el canvasid + * @param {Object} createCodeImg 随机四位数 + */ +let getOptions; +export function createCanvas(options) { + return new Promise(function(resolve, reject) { + let fontSize = options.height * 3 / 6; + let ctx = uni.createCanvasContext(options.el, this); + ctx.setTextBaseline("middle"); + ctx.setFillStyle(randomColor(180, 240)); + //生成随机数 + var code = ''; + var txtArr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q','r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O','P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',0,1,2,3,4,5,6,7,8,9] + for(var i=0;i<4;i++){ + code += txtArr[randomNum(0, txtArr.length)]; + } + options.createCodeImg = code; + let arr = (code + '').split(''); + if (arr.length === 0) { + arr = ['e', 'r', 'r','o','r']; + }; + let offsetLeft = options.width * 0.6 / (arr.length - 1); + let marginLeft = options.width * 0.2; + arr.forEach((item, index) => { + ctx.setFillStyle(randomColor(0, 180)); + let size = randomNum(32, fontSize); + ctx.setFontSize(size); + let dis = offsetLeft * index + marginLeft - size * 0.3; + let deg = randomNum(-30, 30); + ctx.translate(dis, options.height*0.5); + ctx.rotate(deg * Math.PI / 180); + ctx.fillText(item, 0, 0); + ctx.rotate(-deg * Math.PI / 180); + ctx.translate(-dis, -options.height * 0.5); + }) + for (var i = 0; i < 4; i++) { + ctx.strokeStyle = randomColor(40, 180); + ctx.beginPath(); + ctx.moveTo(randomNum(0, options.width), randomNum(0,options.height)); + ctx.lineTo(randomNum(0, options.width), randomNum(0, options.height)); + ctx.stroke(); + } + for (var i = 0; i < options.width / 4; i++) { + ctx.fillStyle = randomColor(0, 255); + ctx.beginPath(); + ctx.arc(randomNum(0, options.width), randomNum(0, options.height), 1, 0, 2 * Math.PI); + ctx.fill(); + } + + ctx.save(); + + // 获取系统信息 + const result = uni.getSystemInfoSync(); + const platform = result.platform; + let time = 0; + if (platform === 'android') { + // 在安卓平台,如果海报过于复杂在转换时需要做延时,否则样式会错乱 + time = 300; + } + // this.ctx.draw(); + getOptions = deepCopy(options); + ctx.draw(false, function() { + setTimeout(function() { + //将canvas转换成临时图片文件 + wx.canvasToTempFilePath({ + width: '140', + height: '70', + canvasId: options.el, + fileType: 'png', + success(res) { + console.log('生成成功'); + console.log(res.tempFilePath, '111'); + resolve(res.tempFilePath); + }, + fail(err) { + console.log('生成失败'); + console.log('canvasToTempFilePath err', err); + reject(err); + }, + complete() { + console.log('成功、失败都走的回调'); + } + }, this); + }, time); + }); + }) +} + +export function validateCode(code) { + var code = code.toLowerCase(); + var v_code = getOptions.createCodeImg.toLowerCase(); + if (code == v_code.substring(v_code.length - 4)) { + return true; + } else { + return false; + } +} + +function randomNum(min, max) { + return Math.floor(Math.random() * (max - min) + min); +} + +function randomColor(min, max) { + let r = randomNum(min, max); + let g = randomNum(min, max); + let b = randomNum(min, max); + return "rgb(" + r + "," + g + "," + b + ")"; +} + diff --git a/common/mcaptcha.js b/common/mcaptcha.js new file mode 100644 index 0000000..c0eb1d2 --- /dev/null +++ b/common/mcaptcha.js @@ -0,0 +1,76 @@ +/** + * 绘制图形验证码 + */ +export class Mcaptcha { + constructor(options) { + this.options = options; + this.fontSize = options.height * 3 / 6; + this.init(); + this.refresh(); + } + init() { + this.ctx = uni.createCanvasContext(this.options.el); + this.ctx.setTextBaseline("middle"); + this.ctx.setFillStyle(this.randomColor(180, 240)); + } + refresh() { + var code = ''; + var txtArr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q','r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O','P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',0,1,2,3,4,5,6,7,8,9] + for(var i=0;i<4;i++){ + code += txtArr[this.randomNum(0, txtArr.length)]; + } + this.options.createCodeImg = code; + let arr = (code + '').split(''); + if (arr.length === 0) { + arr = ['e', 'r', 'r','o','r']; + }; + let offsetLeft = this.options.width * 0.6 / (arr.length - 1); + let marginLeft = this.options.width * 0.2; + arr.forEach((item, index) => { + this.ctx.setFillStyle(this.randomColor(0, 180)); + let size = this.randomNum(32, this.fontSize); + this.ctx.setFontSize(size); + let dis = offsetLeft * index + marginLeft - size * 0.3; + let deg = this.randomNum(-30, 30); + this.ctx.translate(dis, this.options.height*0.5); + this.ctx.rotate(deg * Math.PI / 180); + this.ctx.fillText(item, 0, 0); + this.ctx.rotate(-deg * Math.PI / 180); + this.ctx.translate(-dis, -this.options.height * 0.5); + }) + for (var i = 0; i < 4; i++) { + this.ctx.strokeStyle = this.randomColor(40, 180); + this.ctx.beginPath(); + this.ctx.moveTo(this.randomNum(0, this.options.width), this.randomNum(0, this.options.height)); + this.ctx.lineTo(this.randomNum(0, this.options.width), this.randomNum(0, this.options.height)); + this.ctx.stroke(); + } + for (var i = 0; i < this.options.width / 4; i++) { + this.ctx.fillStyle = this.randomColor(0, 255); + this.ctx.beginPath(); + this.ctx.arc(this.randomNum(0, this.options.width), this.randomNum(0, this.options.height), 1, 0, 2 * Math.PI); + this.ctx.fill(); + } + this.ctx.draw(); + } + validate(code){ + var code = code.toLowerCase(); + var v_code = this.options.createCodeImg.toLowerCase(); + console.log(code) + console.log(v_code.substring(v_code.length - 4)) + if (code == v_code.substring(v_code.length - 4)) { + return true; + } else { + return false; + } + } + randomNum(min, max) { + return Math.floor(Math.random() * (max - min) + min); + } + randomColor(min, max) { + let r = this.randomNum(min, max); + let g = this.randomNum(min, max); + let b = this.randomNum(min, max); + return "rgb(" + r + "," + g + "," + b + ")"; + } +} \ No newline at end of file diff --git a/components/base/message.vue b/components/base/message.vue new file mode 100644 index 0000000..c1c2c52 --- /dev/null +++ b/components/base/message.vue @@ -0,0 +1,61 @@ + + + + + \ No newline at end of file diff --git a/common/createCanvas.js b/common/createCanvas.js new file mode 100644 index 0000000..781ac87 --- /dev/null +++ b/common/createCanvas.js @@ -0,0 +1,113 @@ +import { deepCopy } from '../common/utils.js' +/** 重要事件分享图绘制 + * @param {Object} option 参数 + * @param {Object} this 上下文 + * @param {Object} el canvasid + * @param {Object} createCodeImg 随机四位数 + */ +let getOptions; +export function createCanvas(options) { + return new Promise(function(resolve, reject) { + let fontSize = options.height * 3 / 6; + let ctx = uni.createCanvasContext(options.el, this); + ctx.setTextBaseline("middle"); + ctx.setFillStyle(randomColor(180, 240)); + //生成随机数 + var code = ''; + var txtArr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q','r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O','P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',0,1,2,3,4,5,6,7,8,9] + for(var i=0;i<4;i++){ + code += txtArr[randomNum(0, txtArr.length)]; + } + options.createCodeImg = code; + let arr = (code + '').split(''); + if (arr.length === 0) { + arr = ['e', 'r', 'r','o','r']; + }; + let offsetLeft = options.width * 0.6 / (arr.length - 1); + let marginLeft = options.width * 0.2; + arr.forEach((item, index) => { + ctx.setFillStyle(randomColor(0, 180)); + let size = randomNum(32, fontSize); + ctx.setFontSize(size); + let dis = offsetLeft * index + marginLeft - size * 0.3; + let deg = randomNum(-30, 30); + ctx.translate(dis, options.height*0.5); + ctx.rotate(deg * Math.PI / 180); + ctx.fillText(item, 0, 0); + ctx.rotate(-deg * Math.PI / 180); + ctx.translate(-dis, -options.height * 0.5); + }) + for (var i = 0; i < 4; i++) { + ctx.strokeStyle = randomColor(40, 180); + ctx.beginPath(); + ctx.moveTo(randomNum(0, options.width), randomNum(0,options.height)); + ctx.lineTo(randomNum(0, options.width), randomNum(0, options.height)); + ctx.stroke(); + } + for (var i = 0; i < options.width / 4; i++) { + ctx.fillStyle = randomColor(0, 255); + ctx.beginPath(); + ctx.arc(randomNum(0, options.width), randomNum(0, options.height), 1, 0, 2 * Math.PI); + ctx.fill(); + } + + ctx.save(); + + // 获取系统信息 + const result = uni.getSystemInfoSync(); + const platform = result.platform; + let time = 0; + if (platform === 'android') { + // 在安卓平台,如果海报过于复杂在转换时需要做延时,否则样式会错乱 + time = 300; + } + // this.ctx.draw(); + getOptions = deepCopy(options); + ctx.draw(false, function() { + setTimeout(function() { + //将canvas转换成临时图片文件 + wx.canvasToTempFilePath({ + width: '140', + height: '70', + canvasId: options.el, + fileType: 'png', + success(res) { + console.log('生成成功'); + console.log(res.tempFilePath, '111'); + resolve(res.tempFilePath); + }, + fail(err) { + console.log('生成失败'); + console.log('canvasToTempFilePath err', err); + reject(err); + }, + complete() { + console.log('成功、失败都走的回调'); + } + }, this); + }, time); + }); + }) +} + +export function validateCode(code) { + var code = code.toLowerCase(); + var v_code = getOptions.createCodeImg.toLowerCase(); + if (code == v_code.substring(v_code.length - 4)) { + return true; + } else { + return false; + } +} + +function randomNum(min, max) { + return Math.floor(Math.random() * (max - min) + min); +} + +function randomColor(min, max) { + let r = randomNum(min, max); + let g = randomNum(min, max); + let b = randomNum(min, max); + return "rgb(" + r + "," + g + "," + b + ")"; +} + diff --git a/common/mcaptcha.js b/common/mcaptcha.js new file mode 100644 index 0000000..c0eb1d2 --- /dev/null +++ b/common/mcaptcha.js @@ -0,0 +1,76 @@ +/** + * 绘制图形验证码 + */ +export class Mcaptcha { + constructor(options) { + this.options = options; + this.fontSize = options.height * 3 / 6; + this.init(); + this.refresh(); + } + init() { + this.ctx = uni.createCanvasContext(this.options.el); + this.ctx.setTextBaseline("middle"); + this.ctx.setFillStyle(this.randomColor(180, 240)); + } + refresh() { + var code = ''; + var txtArr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q','r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O','P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',0,1,2,3,4,5,6,7,8,9] + for(var i=0;i<4;i++){ + code += txtArr[this.randomNum(0, txtArr.length)]; + } + this.options.createCodeImg = code; + let arr = (code + '').split(''); + if (arr.length === 0) { + arr = ['e', 'r', 'r','o','r']; + }; + let offsetLeft = this.options.width * 0.6 / (arr.length - 1); + let marginLeft = this.options.width * 0.2; + arr.forEach((item, index) => { + this.ctx.setFillStyle(this.randomColor(0, 180)); + let size = this.randomNum(32, this.fontSize); + this.ctx.setFontSize(size); + let dis = offsetLeft * index + marginLeft - size * 0.3; + let deg = this.randomNum(-30, 30); + this.ctx.translate(dis, this.options.height*0.5); + this.ctx.rotate(deg * Math.PI / 180); + this.ctx.fillText(item, 0, 0); + this.ctx.rotate(-deg * Math.PI / 180); + this.ctx.translate(-dis, -this.options.height * 0.5); + }) + for (var i = 0; i < 4; i++) { + this.ctx.strokeStyle = this.randomColor(40, 180); + this.ctx.beginPath(); + this.ctx.moveTo(this.randomNum(0, this.options.width), this.randomNum(0, this.options.height)); + this.ctx.lineTo(this.randomNum(0, this.options.width), this.randomNum(0, this.options.height)); + this.ctx.stroke(); + } + for (var i = 0; i < this.options.width / 4; i++) { + this.ctx.fillStyle = this.randomColor(0, 255); + this.ctx.beginPath(); + this.ctx.arc(this.randomNum(0, this.options.width), this.randomNum(0, this.options.height), 1, 0, 2 * Math.PI); + this.ctx.fill(); + } + this.ctx.draw(); + } + validate(code){ + var code = code.toLowerCase(); + var v_code = this.options.createCodeImg.toLowerCase(); + console.log(code) + console.log(v_code.substring(v_code.length - 4)) + if (code == v_code.substring(v_code.length - 4)) { + return true; + } else { + return false; + } + } + randomNum(min, max) { + return Math.floor(Math.random() * (max - min) + min); + } + randomColor(min, max) { + let r = this.randomNum(min, max); + let g = this.randomNum(min, max); + let b = this.randomNum(min, max); + return "rgb(" + r + "," + g + "," + b + ")"; + } +} \ No newline at end of file diff --git a/components/base/message.vue b/components/base/message.vue new file mode 100644 index 0000000..c1c2c52 --- /dev/null +++ b/components/base/message.vue @@ -0,0 +1,61 @@ + + + + + \ No newline at end of file diff --git a/pages/accountBound/accountBound.vue b/pages/accountBound/accountBound.vue index b18a56a..f811511 100644 --- a/pages/accountBound/accountBound.vue +++ b/pages/accountBound/accountBound.vue @@ -1,3 +1,4 @@ + @@ -138,6 +164,9 @@ \ No newline at end of file diff --git a/pages/accountBound/accountBound.vue b/pages/accountBound/accountBound.vue index b18a56a..f811511 100644 --- a/pages/accountBound/accountBound.vue +++ b/pages/accountBound/accountBound.vue @@ -1,3 +1,4 @@ + @@ -138,6 +164,9 @@ \ No newline at end of file diff --git a/pages/accountBound/accountBound.vue b/pages/accountBound/accountBound.vue index b18a56a..f811511 100644 --- a/pages/accountBound/accountBound.vue +++ b/pages/accountBound/accountBound.vue @@ -1,3 +1,4 @@ + @@ -138,6 +164,9 @@ \ No newline at end of file diff --git a/pages/accountBound/accountBound.vue b/pages/accountBound/accountBound.vue index b18a56a..f811511 100644 --- a/pages/accountBound/accountBound.vue +++ b/pages/accountBound/accountBound.vue @@ -1,3 +1,4 @@ + @@ -138,6 +164,9 @@ \ No newline at end of file diff --git a/pages/accountBound/accountBound.vue b/pages/accountBound/accountBound.vue index b18a56a..f811511 100644 --- a/pages/accountBound/accountBound.vue +++ b/pages/accountBound/accountBound.vue @@ -1,3 +1,4 @@ + @@ -138,6 +164,9 @@ \ No newline at end of file diff --git a/pages/accountBound/accountBound.vue b/pages/accountBound/accountBound.vue index b18a56a..f811511 100644 --- a/pages/accountBound/accountBound.vue +++ b/pages/accountBound/accountBound.vue @@ -1,3 +1,4 @@ + @@ -138,6 +164,9 @@ \ No newline at end of file diff --git a/pages/accountBound/accountBound.vue b/pages/accountBound/accountBound.vue index b18a56a..f811511 100644 --- a/pages/accountBound/accountBound.vue +++ b/pages/accountBound/accountBound.vue @@ -1,3 +1,4 @@ + @@ -138,6 +164,9 @@ + + diff --git a/common/createCanvas.js b/common/createCanvas.js new file mode 100644 index 0000000..781ac87 --- /dev/null +++ b/common/createCanvas.js @@ -0,0 +1,113 @@ +import { deepCopy } from '../common/utils.js' +/** 重要事件分享图绘制 + * @param {Object} option 参数 + * @param {Object} this 上下文 + * @param {Object} el canvasid + * @param {Object} createCodeImg 随机四位数 + */ +let getOptions; +export function createCanvas(options) { + return new Promise(function(resolve, reject) { + let fontSize = options.height * 3 / 6; + let ctx = uni.createCanvasContext(options.el, this); + ctx.setTextBaseline("middle"); + ctx.setFillStyle(randomColor(180, 240)); + //生成随机数 + var code = ''; + var txtArr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q','r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O','P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',0,1,2,3,4,5,6,7,8,9] + for(var i=0;i<4;i++){ + code += txtArr[randomNum(0, txtArr.length)]; + } + options.createCodeImg = code; + let arr = (code + '').split(''); + if (arr.length === 0) { + arr = ['e', 'r', 'r','o','r']; + }; + let offsetLeft = options.width * 0.6 / (arr.length - 1); + let marginLeft = options.width * 0.2; + arr.forEach((item, index) => { + ctx.setFillStyle(randomColor(0, 180)); + let size = randomNum(32, fontSize); + ctx.setFontSize(size); + let dis = offsetLeft * index + marginLeft - size * 0.3; + let deg = randomNum(-30, 30); + ctx.translate(dis, options.height*0.5); + ctx.rotate(deg * Math.PI / 180); + ctx.fillText(item, 0, 0); + ctx.rotate(-deg * Math.PI / 180); + ctx.translate(-dis, -options.height * 0.5); + }) + for (var i = 0; i < 4; i++) { + ctx.strokeStyle = randomColor(40, 180); + ctx.beginPath(); + ctx.moveTo(randomNum(0, options.width), randomNum(0,options.height)); + ctx.lineTo(randomNum(0, options.width), randomNum(0, options.height)); + ctx.stroke(); + } + for (var i = 0; i < options.width / 4; i++) { + ctx.fillStyle = randomColor(0, 255); + ctx.beginPath(); + ctx.arc(randomNum(0, options.width), randomNum(0, options.height), 1, 0, 2 * Math.PI); + ctx.fill(); + } + + ctx.save(); + + // 获取系统信息 + const result = uni.getSystemInfoSync(); + const platform = result.platform; + let time = 0; + if (platform === 'android') { + // 在安卓平台,如果海报过于复杂在转换时需要做延时,否则样式会错乱 + time = 300; + } + // this.ctx.draw(); + getOptions = deepCopy(options); + ctx.draw(false, function() { + setTimeout(function() { + //将canvas转换成临时图片文件 + wx.canvasToTempFilePath({ + width: '140', + height: '70', + canvasId: options.el, + fileType: 'png', + success(res) { + console.log('生成成功'); + console.log(res.tempFilePath, '111'); + resolve(res.tempFilePath); + }, + fail(err) { + console.log('生成失败'); + console.log('canvasToTempFilePath err', err); + reject(err); + }, + complete() { + console.log('成功、失败都走的回调'); + } + }, this); + }, time); + }); + }) +} + +export function validateCode(code) { + var code = code.toLowerCase(); + var v_code = getOptions.createCodeImg.toLowerCase(); + if (code == v_code.substring(v_code.length - 4)) { + return true; + } else { + return false; + } +} + +function randomNum(min, max) { + return Math.floor(Math.random() * (max - min) + min); +} + +function randomColor(min, max) { + let r = randomNum(min, max); + let g = randomNum(min, max); + let b = randomNum(min, max); + return "rgb(" + r + "," + g + "," + b + ")"; +} + diff --git a/common/mcaptcha.js b/common/mcaptcha.js new file mode 100644 index 0000000..c0eb1d2 --- /dev/null +++ b/common/mcaptcha.js @@ -0,0 +1,76 @@ +/** + * 绘制图形验证码 + */ +export class Mcaptcha { + constructor(options) { + this.options = options; + this.fontSize = options.height * 3 / 6; + this.init(); + this.refresh(); + } + init() { + this.ctx = uni.createCanvasContext(this.options.el); + this.ctx.setTextBaseline("middle"); + this.ctx.setFillStyle(this.randomColor(180, 240)); + } + refresh() { + var code = ''; + var txtArr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q','r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O','P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',0,1,2,3,4,5,6,7,8,9] + for(var i=0;i<4;i++){ + code += txtArr[this.randomNum(0, txtArr.length)]; + } + this.options.createCodeImg = code; + let arr = (code + '').split(''); + if (arr.length === 0) { + arr = ['e', 'r', 'r','o','r']; + }; + let offsetLeft = this.options.width * 0.6 / (arr.length - 1); + let marginLeft = this.options.width * 0.2; + arr.forEach((item, index) => { + this.ctx.setFillStyle(this.randomColor(0, 180)); + let size = this.randomNum(32, this.fontSize); + this.ctx.setFontSize(size); + let dis = offsetLeft * index + marginLeft - size * 0.3; + let deg = this.randomNum(-30, 30); + this.ctx.translate(dis, this.options.height*0.5); + this.ctx.rotate(deg * Math.PI / 180); + this.ctx.fillText(item, 0, 0); + this.ctx.rotate(-deg * Math.PI / 180); + this.ctx.translate(-dis, -this.options.height * 0.5); + }) + for (var i = 0; i < 4; i++) { + this.ctx.strokeStyle = this.randomColor(40, 180); + this.ctx.beginPath(); + this.ctx.moveTo(this.randomNum(0, this.options.width), this.randomNum(0, this.options.height)); + this.ctx.lineTo(this.randomNum(0, this.options.width), this.randomNum(0, this.options.height)); + this.ctx.stroke(); + } + for (var i = 0; i < this.options.width / 4; i++) { + this.ctx.fillStyle = this.randomColor(0, 255); + this.ctx.beginPath(); + this.ctx.arc(this.randomNum(0, this.options.width), this.randomNum(0, this.options.height), 1, 0, 2 * Math.PI); + this.ctx.fill(); + } + this.ctx.draw(); + } + validate(code){ + var code = code.toLowerCase(); + var v_code = this.options.createCodeImg.toLowerCase(); + console.log(code) + console.log(v_code.substring(v_code.length - 4)) + if (code == v_code.substring(v_code.length - 4)) { + return true; + } else { + return false; + } + } + randomNum(min, max) { + return Math.floor(Math.random() * (max - min) + min); + } + randomColor(min, max) { + let r = this.randomNum(min, max); + let g = this.randomNum(min, max); + let b = this.randomNum(min, max); + return "rgb(" + r + "," + g + "," + b + ")"; + } +} \ No newline at end of file diff --git a/components/base/message.vue b/components/base/message.vue new file mode 100644 index 0000000..c1c2c52 --- /dev/null +++ b/components/base/message.vue @@ -0,0 +1,61 @@ + + + + + \ No newline at end of file diff --git a/pages/accountBound/accountBound.vue b/pages/accountBound/accountBound.vue index b18a56a..f811511 100644 --- a/pages/accountBound/accountBound.vue +++ b/pages/accountBound/accountBound.vue @@ -1,3 +1,4 @@ + @@ -138,6 +164,9 @@ + + diff --git a/pages/search/search.vue b/pages/search/search.vue index 6f7158f..ff3126d 100644 --- a/pages/search/search.vue +++ b/pages/search/search.vue @@ -1,3 +1,4 @@ + @@ -42,10 +53,24 @@ }, data() { return { + isEmpty: false, //是否为空 eventList: [], //事件数据 keyword: '新疆', //搜索关键字 scrollTop: 0, - status: 'nomore', //上滑加载状态 loading加载中,nomore没有更多了 + status: 'loadmore', //上滑加载状态 loading加载中,nomore没有更多了 + } + }, + watch: { + eventList: { + handler(val){ + if(val.length) { + this.isEmpty = false; + } else { + this.isEmpty = true; + } + }, + deep: true, + // immediate: true, } }, mounted() {