日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

uniapp实现动态生成随机图形验证码

發(fā)布時間:2023/12/18 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 uniapp实现动态生成随机图形验证码 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

<template><gui-page><view slot="gBody"><view class="content"><!-- 驗證碼 --><view class="firsts_s" style="margin-top: 25rpx;"><view class="firsts_s_l"><view class="first-input"><input type="text" value="" placeholder="驗證碼"placeholder-style="font-size:29rpx;color:#999" v-model="verCode" /></view></view><view class="firsts_s_r" @click="click"><canvas :style="{width:width+'px',height:height+'px'}" canvas-id="canvasW"@error="canvasT"></canvas></view></view></view></view></gui-page></template><script>export default {data() {return {verCode: "",width: 400,height: 45}},onLoad() {},onShow() {var that = this;setTimeout(function() {that.init();}, 100)},methods: { click(){this.init()},init: function() {var context = uni.createCanvasContext('canvasW', this),w = this.width,h = this.height;context.setFillStyle("white");context.setLineWidth(5);context.fillRect(0, 0, w, h);var pool = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"],str = '';for (var i = 0; i < 4; i++) {var c = pool[this.rn(0, pool.length - 1)];var deg = this.rn(-30, 30);context.setFontSize(18);context.setTextBaseline("top");context.setFillStyle(this.rc(80, 150));context.save();context.translate(30 * i + 15, parseInt(h / 1.5));context.rotate(deg * Math.PI / 180);context.fillText(c, -15 + 5, -15);context.restore();str += c;}uni.setStorage({key: 'imgcode',data: str,});for (var i = 0; i < 40; i++) {context.beginPath();context.arc(this.rn(0, w), this.rn(0, h), 1, 0, 2 * Math.PI);context.closePath();context.setFillStyle(this.rc(150, 200));context.fill();}context.draw();},rc: function(min, max) {var r = this.rn(min, max);var g = this.rn(min, max);var b = this.rn(min, max);return "rgb(" + r + "," + g + "," + b + ")";},rn: function(max, min) {return parseInt(Math.random() * (max - min)) + min;},canvasT: function(e) {console.error(e.detail.errMsg)}}} </script>

總結(jié)

以上是生活随笔為你收集整理的uniapp实现动态生成随机图形验证码的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。