¶Ô±ÈÐÂÎļþ |
| | |
| | | <template> |
| | | <div class="s-canvas" @click="$emit('refresh')"> |
| | | <canvas id="s-canvas" :width="contentWidth" :height="contentHeight"></canvas> |
| | | </div> |
| | | </template> |
| | | <script> |
| | | export default { |
| | | name: 'LoginCode', |
| | | props: { |
| | | identifyCode: { |
| | | // é»è®¤æ³¨åç |
| | | type: String, |
| | | default: '1234', |
| | | }, |
| | | fontSizeMin: { |
| | | // å使å°å¼ |
| | | type: Number, |
| | | default: 25, |
| | | }, |
| | | fontSizeMax: { |
| | | // åä½æå¤§å¼ |
| | | type: Number, |
| | | default: 35, |
| | | }, |
| | | backgroundColorMin: { |
| | | // éªè¯ç å¾çèæ¯è²æå°å¼ |
| | | type: Number, |
| | | default: 200, |
| | | }, |
| | | backgroundColorMax: { |
| | | // éªè¯ç å¾çèæ¯è²æå¤§å¼ |
| | | type: Number, |
| | | default: 220, |
| | | }, |
| | | dotColorMin: { |
| | | // èæ¯å¹²æ°ç¹æå°å¼ |
| | | type: Number, |
| | | default: 60, |
| | | }, |
| | | dotColorMax: { |
| | | // èæ¯å¹²æ°ç¹æå¤§å¼ |
| | | type: Number, |
| | | default: 120, |
| | | }, |
| | | contentWidth: { |
| | | // 容å¨å®½åº¦ |
| | | type: Number, |
| | | default: 90, |
| | | }, |
| | | contentHeight: { |
| | | // 容å¨é«åº¦ |
| | | type: Number, |
| | | default: 38, |
| | | }, |
| | | }, |
| | | methods: { |
| | | // çæä¸ä¸ªéæºæ° |
| | | randomNum(min, max) { |
| | | return Math.floor(Math.random() * (max - min) + min) |
| | | }, |
| | | |
| | | // çæä¸ä¸ªéæºçé¢è² |
| | | randomColor(min, max) { |
| | | const r = this.randomNum(min, max) |
| | | const g = this.randomNum(min, max) |
| | | const b = this.randomNum(min, max) |
| | | return 'rgb(' + r + ',' + g + ',' + b + ')' |
| | | }, |
| | | // ç»å¾ |
| | | drawPic() { |
| | | const canvas = document.getElementById('s-canvas') |
| | | // å建ä¸ä¸ª2D对象ä½ä¸ºä¸ä¸æã |
| | | const ctx = canvas.getContext('2d') |
| | | ctx.textBaseline = 'bottom' |
| | | // ç»å¶èæ¯ |
| | | ctx.fillStyle = '#e6ecfd' |
| | | ctx.fillRect(0, 0, this.contentWidth, this.contentHeight) |
| | | // ç»å¶æå |
| | | for (let i = 0; i < this.identifyCode.length; i++) { |
| | | this.drawText(ctx, this.identifyCode[i], i) |
| | | } |
| | | this.drawLine(ctx) |
| | | this.drawDot(ctx) |
| | | }, |
| | | // å¨ç»å¸ä¸æ¾ç¤ºæ°æ® |
| | | drawText(ctx, txt, i) { |
| | | ctx.fillStyle = this.randomColor(50, 160) // éæºçæåä½é¢è² |
| | | ctx.font = this.randomNum(this.fontSizeMin, this.fontSizeMax) + 'px SimHei' // éæºçæåä½å¤§å° |
| | | const x = (i + 1) * (this.contentWidth / (this.identifyCode.length + 1)) |
| | | const y = this.randomNum(this.fontSizeMax, this.contentHeight - 5) |
| | | var deg = this.randomNum(-30, 30) |
| | | // ä¿®æ¹åæ åç¹åæè½¬è§åº¦ |
| | | ctx.translate(x, y) |
| | | ctx.rotate((deg * Math.PI) / 180) |
| | | ctx.fillText(txt, 0, 0) |
| | | // æ¢å¤åæ åç¹åæè½¬è§åº¦ |
| | | ctx.rotate((-deg * Math.PI) / 180) |
| | | ctx.translate(-x, -y) |
| | | }, |
| | | |
| | | // ç»å¶å¹²æ°çº¿ |
| | | drawLine(ctx) { |
| | | for (let i = 0; i < 4; i++) { |
| | | ctx.strokeStyle = this.randomColor(100, 200) |
| | | ctx.beginPath() |
| | | ctx.moveTo(this.randomNum(0, this.contentWidth), this.randomNum(0, this.contentHeight)) |
| | | ctx.lineTo(this.randomNum(0, this.contentWidth), this.randomNum(0, this.contentHeight)) |
| | | ctx.stroke() |
| | | } |
| | | }, |
| | | |
| | | // ç»å¶å¹²æ°ç¹ |
| | | drawDot(ctx) { |
| | | for (let i = 0; i < 30; i++) { |
| | | ctx.fillStyle = this.randomColor(0, 255) |
| | | ctx.beginPath() |
| | | ctx.arc(this.randomNum(0, this.contentWidth), this.randomNum(0, this.contentHeight), 1, 0, 2 * Math.PI) |
| | | ctx.fill() |
| | | } |
| | | }, |
| | | }, |
| | | watch: { |
| | | identifyCode() { |
| | | this.drawPic() |
| | | }, |
| | | }, |
| | | mounted() { |
| | | this.drawPic() |
| | | }, |
| | | } |
| | | </script> |
| | |
| | | <i slot="prefix" class="iconfont icon-mima"></i> |
| | | </el-input> |
| | | </el-form-item> |
| | | <el-form-item prop="loginCode"> |
| | | <el-col :span="16"> |
| | | <el-input |
| | | v-model="loginCode" |
| | | size="small" |
| | | auto-complete="off" |
| | | placeholder="请è¾å
¥éªè¯ç " |
| | | @keyup.enter.native="handleLogin" |
| | | > |
| | | </el-input> |
| | | </el-col> |
| | | <el-col :span="6" :offset="2"> |
| | | <login-code |
| | | :key="refreshKey" |
| | | :identifyCode="loginCodeValue" |
| | | @refresh="refreshLoginValueCode" |
| | | /> |
| | | </el-col> |
| | | </el-form-item> |
| | | <el-form-item> |
| | | <el-button |
| | | type="primary" |
| | |
| | | </template> |
| | | |
| | | <script> |
| | | import { randomLenNum } from '@/util/util' |
| | | import { mapGetters } from 'vuex' |
| | | import { getCode } from '@/api/code' |
| | | import Verify from '@/components/verifition/Verify' |
| | | import { getSsoAuthUrl } from '@/api/login' |
| | | import LoginCode from '@/page/login/LoginCode.vue' |
| | | |
| | | export default { |
| | | name: 'Userlogin', |
| | | components: { |
| | | Verify |
| | | LoginCode |
| | | }, |
| | | data() { |
| | | return { |
| | |
| | | ] |
| | | }, |
| | | passwordType: 'password', |
| | | SSO: window.location.hash |
| | | SSO: window.location.hash, |
| | | loginCode: null, |
| | | loginCodeValue: Math.random() |
| | | .toString(36) |
| | | .substr(2, 4), |
| | | refreshKey: 0 |
| | | } |
| | | }, |
| | | created() { |
| | |
| | | : (this.passwordType = '') |
| | | }, |
| | | handleLogin() { |
| | | if (!this.loginCode) { |
| | | this.$message.error('请è¾å
¥éªè¯ç ') |
| | | return |
| | | } |
| | | if (this.loginCode.toLowerCase() !== this.loginCodeValue) { |
| | | this.$message.error('éªè¯ç 䏿£ç¡®') |
| | | return |
| | | } |
| | | this.$refs.loginForm.validate((valid) => { |
| | | if (valid) { |
| | | this.$store.dispatch('LoginByUsername', this.loginForm).then(() => { |
| | | this.$router.push({ path: this.tagWel.value }) |
| | | }) |
| | | } else { |
| | | this.refreshLoginValueCode() |
| | | } |
| | | }) |
| | | }, |
| | |
| | | this.$router.push({ path: this.tagWel.value }) |
| | | }) |
| | | } |
| | | }, |
| | | // å·æ°éªè¯ç |
| | | refreshLoginValueCode() { |
| | | this.loginCodeValue = Math.random() |
| | | .toString(36) |
| | | .substr(2, 4) |
| | | this.refreshKey++ |
| | | } |
| | | } |
| | | } |