【modify】使用ESLint格式化代码

This commit is contained in:
zer0Black
2023-03-01 09:33:58 +08:00
parent 694855ae8b
commit 63369b8b87
400 changed files with 42942 additions and 43132 deletions
+220 -221
View File
@@ -178,236 +178,235 @@
</div>
</template>
<script>
import { mapActions } from "vuex"
import { timeFix } from "@/utils/util"
import Vue from 'vue'
import { ACCESS_TOKEN ,ENCRYPTED_STRING} from "@/store/mutation-types"
import { putAction,postAction,getAction } from '@/api/manage'
import { USER_INFO } from "@/store/mutation-types"
import { getRSAPublicKey } from '@/utils/encryption.js'
const Base64 = require('js-base64').Base64
import {JSEncrypt} from 'jsencrypt'
import { mapActions } from 'vuex'
import { timeFix } from '@/utils/util'
import Vue from 'vue'
import { ACCESS_TOKEN, ENCRYPTED_STRING, USER_INFO } from '@/store/mutation-types'
import { putAction, postAction, getAction } from '@/api/manage'
export default {
components: {},
data () {
return {
loginBtn: false,
mobile:isMobile(),
// login type: 0 email, 1 username, 2 telephone
loginType: 0,
stepCaptchaVisible: false,
form: this.$form.createForm(this),
state: {
time: 60,
smsSendBtn: false,
},
validatorRules:{
username:{rules: [{ required: true, message: '请输入用户名!'},{validator: this.handleUsernameOrEmail}]},
password:{rules: [{ required: true, message: '请输入密码!',validator: 'click'}]},
mobile:{rules: [{validator:this.validateMobile}]},
captcha:{rule: [{ required: true, message: '请输入验证码!'}]},
inputCode:{rules: [{ required: true, message: '请输入验证码!'}]}
},
velorifiedCode:"",
inputCodeContent:"",
inputCodeNull:true,
currentUsername:"",
currdatetime:'',
randCodeImage:'',
requestCodeSuccess:false,
rsaPublicKey:'',
passwordType:'password', //passwordType : password , text
import { getRSAPublicKey } from '@/utils/encryption.js'
import { JSEncrypt } from 'jsencrypt'
const Base64 = require('js-base64').Base64
export default {
components: {},
data () {
return {
loginBtn: false,
mobile: isMobile(),
// login type: 0 email, 1 username, 2 telephone
loginType: 0,
stepCaptchaVisible: false,
form: this.$form.createForm(this),
state: {
time: 60,
smsSendBtn: false
},
validatorRules: {
username: { rules: [{ required: true, message: '请输入用户名!' }, { validator: this.handleUsernameOrEmail }] },
password: { rules: [{ required: true, message: '请输入密码!', validator: 'click' }] },
mobile: { rules: [{ validator: this.validateMobile }] },
captcha: { rule: [{ required: true, message: '请输入验证码!' }] },
inputCode: { rules: [{ required: true, message: '请输入验证码!' }] }
},
velorifiedCode: '',
inputCodeContent: '',
inputCodeNull: true,
currentUsername: '',
currdatetime: '',
randCodeImage: '',
requestCodeSuccess: false,
rsaPublicKey: '',
passwordType: 'password' // passwordType : password , text
}
},
created () {
this.currdatetime = new Date().getTime()
Vue.ls.remove(ACCESS_TOKEN)
this.getRouterData()
this.handleChangeCheckCode()
this.getPublicKey() // 获取秘钥
},
methods: {
...mapActions(['Login', 'Logout', 'PhoneLogin']),
handleUsernameOrEmail (rule, value, callback) {
const regex = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/
if (regex.test(value)) {
this.loginType = 0
} else {
this.loginType = 1
}
callback()
},
created () {
this.currdatetime = new Date().getTime();
Vue.ls.remove(ACCESS_TOKEN)
this.getRouterData();
this.handleChangeCheckCode();
this.getPublicKey(); //获取秘钥
},
methods: {
...mapActions(['Login', 'Logout', 'PhoneLogin']),
handleUsernameOrEmail (rule, value, callback) {
const regex = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;
if (regex.test(value)) {
this.loginType = 0
} else {
this.loginType = 1
}
callback()
},
handleSubmit () {
let that = this
let loginParams = {};
that.loginBtn = true;
that.form.validateFields([ 'username', 'password','inputCode', 'rememberMe' ], { force: true }, (err, values) => {
if (!err) {
loginParams.remember_me = values.rememberMe
loginParams.captcha = that.inputCodeContent
loginParams.checkKey = that.currdatetime
loginParams.rsaPublicKey = that.rsaPublicKey;
// 新建JSEncrypt对象
let encrypt = new JSEncrypt();
encrypt.setPublicKey(loginParams.rsaPublicKey);
// 公钥加密
loginParams.username = encrypt.encrypt(values.username)
loginParams.password = encrypt.encrypt(values.password)
//登录
that.Login(loginParams).then((res) => {
this.loginSuccess()
}).catch((err) => {
if (err.code === 500) {
// 刷新验证码
this.handleChangeCheckCode();
}
that.requestFailed(err);
});
}else {
that.loginBtn = false;
}
})
},
getCaptcha (e) {
e.preventDefault();
let that = this;
this.form.validateFields([ 'mobile' ], { force: true },(err,values) => {
if(!values.mobile){
that.cmsFailed("请输入手机号");
}else if (!err) {
this.state.smsSendBtn = true;
let interval = window.setInterval(() => {
if (that.state.time-- <= 0) {
that.state.time = 60;
that.state.smsSendBtn = false;
window.clearInterval(interval);
}
}, 1000);
const hide = this.$message.loading('验证码发送中..', 0);
let smsParams = {};
smsParams.mobile=values.mobile;
smsParams.smsmode="0";
postAction("/sys/sms",smsParams)
.then(res => {
if(!res.success){
setTimeout(hide, 0);
this.cmsFailed(res.message);
}
setTimeout(hide, 500);
})
.catch(err => {
setTimeout(hide, 1);
clearInterval(interval);
that.state.time = 60;
that.state.smsSendBtn = false;
this.requestFailed(err);
});
handleSubmit () {
const that = this
const loginParams = {}
that.loginBtn = true
that.form.validateFields(['username', 'password', 'inputCode', 'rememberMe'], { force: true }, (err, values) => {
if (!err) {
loginParams.remember_me = values.rememberMe
loginParams.captcha = that.inputCodeContent
loginParams.checkKey = that.currdatetime
loginParams.rsaPublicKey = that.rsaPublicKey
// 新建JSEncrypt对象
const encrypt = new JSEncrypt()
encrypt.setPublicKey(loginParams.rsaPublicKey)
// 公钥加密
loginParams.username = encrypt.encrypt(values.username)
loginParams.password = encrypt.encrypt(values.password)
// 登录
that.Login(loginParams).then((res) => {
this.loginSuccess()
}).catch((err) => {
if (err.code === 500) {
// 刷新验证码
this.handleChangeCheckCode()
}
}
);
},
handleChangeCheckCode(){
this.form.setFieldsValue({inputCode: ''});
this.currdatetime = new Date().getTime();
getAction(`/sys/randomImage/${this.currdatetime}`).then(res=>{
if(res.success){
this.randCodeImage = res.result
this.requestCodeSuccess=true
}else{
this.$message.error(res.message)
this.requestCodeSuccess=false
}
}).catch(()=>{
this.requestCodeSuccess=false
})
},
//获取RSA公钥
getPublicKey(){
// 获取公钥
getRSAPublicKey().then(res => {
this.rsaPublicKey = res.result
})
},
loginSuccess () {
this.$router.push({ path: "/" }).catch((res)=>{})
this.$notification.success({
message: '欢迎',
description: `${timeFix()},欢迎回来`,
});
},
cmsFailed(err){
this.$notification[ 'error' ]({
message: "验证码发送失败",
description:err,
duration: 4,
});
},
requestFailed (err) {
this.$notification[ 'error' ]({
message: '登录失败',
description: ((err.response || {}).data || {}).message || err.message || "请求出现错误请稍后再试",
duration: 4,
});
this.loginBtn = false;
},
validateMobile(rule,value,callback){
if (!value || new RegExp(/^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/).test(value)){
callback();
}else{
callback("您的手机号码格式不正确!");
that.requestFailed(err)
})
} else {
that.loginBtn = false
}
},
validateInputCode(rule,value,callback){
if(!value || this.verifiedCode==this.inputCodeContent){
callback();
}else{
callback("您输入的验证码不正确!");
})
},
getCaptcha (e) {
e.preventDefault()
const that = this
this.form.validateFields(['mobile'], { force: true }, (err, values) => {
if (!values.mobile) {
that.cmsFailed('请输入手机号')
} else if (!err) {
this.state.smsSendBtn = true
const interval = window.setInterval(() => {
if (that.state.time-- <= 0) {
that.state.time = 60
that.state.smsSendBtn = false
window.clearInterval(interval)
}
}, 1000)
const hide = this.$message.loading('验证码发送中..', 0)
const smsParams = {}
smsParams.mobile = values.mobile
smsParams.smsmode = '0'
postAction('/sys/sms', smsParams)
.then(res => {
if (!res.success) {
setTimeout(hide, 0)
this.cmsFailed(res.message)
}
setTimeout(hide, 500)
})
.catch(err => {
setTimeout(hide, 1)
clearInterval(interval)
that.state.time = 60
that.state.smsSendBtn = false
this.requestFailed(err)
})
}
},
generateCode(value){
this.verifiedCode = value.toLowerCase()
},
inputCodeChange(e){
this.inputCodeContent = e.target.value
},
getRouterData(){
this.$nextTick(() => {
if (this.$route.params.username) {
this.form.setFieldsValue({
'username': this.$route.params.username
});
}
})
},
}
}
// 判断当前设备
function isMobile() {
var userAgentInfo = navigator.userAgent;
var mobileAgents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"];
var mobile_flag = false;
//根据userAgent判断是否是手机
for (var v = 0; v < mobileAgents.length; v++) {
if (userAgentInfo.indexOf(mobileAgents[v]) > 0) {
mobile_flag = true;
break;
}
)
},
handleChangeCheckCode () {
this.form.setFieldsValue({ inputCode: '' })
this.currdatetime = new Date().getTime()
getAction(`/sys/randomImage/${this.currdatetime}`).then(res => {
if (res.success) {
this.randCodeImage = res.result
this.requestCodeSuccess = true
} else {
this.$message.error(res.message)
this.requestCodeSuccess = false
}
}).catch(() => {
this.requestCodeSuccess = false
})
},
// 获取RSA公钥
getPublicKey () {
// 获取公钥
getRSAPublicKey().then(res => {
this.rsaPublicKey = res.result
})
},
loginSuccess () {
this.$router.push({ path: '/' }).catch((res) => {})
this.$notification.success({
message: '欢迎',
description: `${timeFix()},欢迎回来`
})
},
cmsFailed (err) {
this.$notification.error({
message: '验证码发送失败',
description: err,
duration: 4
})
},
requestFailed (err) {
this.$notification.error({
message: '登录失败',
description: ((err.response || {}).data || {}).message || err.message || '请求出现错误,请稍后再试',
duration: 4
})
this.loginBtn = false
},
validateMobile (rule, value, callback) {
if (!value || new RegExp(/^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/).test(value)) {
callback()
} else {
callback('您的手机号码格式不正确!')
}
},
validateInputCode (rule, value, callback) {
if (!value || this.verifiedCode == this.inputCodeContent) {
callback()
} else {
callback('您输入的验证码不正确!')
}
},
generateCode (value) {
this.verifiedCode = value.toLowerCase()
},
inputCodeChange (e) {
this.inputCodeContent = e.target.value
},
getRouterData () {
this.$nextTick(() => {
if (this.$route.params.username) {
this.form.setFieldsValue({
username: this.$route.params.username
})
}
})
}
var screen_width = window.screen.width;
var screen_height = window.screen.height;
//根据屏幕分辨率判断是否是手机
if (screen_width < 500 && screen_height < 800) {
mobile_flag = true;
}
return mobile_flag;
}
}
// 判断当前设备
function isMobile () {
var userAgentInfo = navigator.userAgent
var mobileAgents = ['Android', 'iPhone', 'SymbianOS', 'Windows Phone', 'iPad', 'iPod']
var mobile_flag = false
// 根据userAgent判断是否是手机
for (var v = 0; v < mobileAgents.length; v++) {
if (userAgentInfo.indexOf(mobileAgents[v]) > 0) {
mobile_flag = true
break
}
}
var screen_width = window.screen.width
var screen_height = window.screen.height
// 根据屏幕分辨率判断是否是手机
if (screen_width < 500 && screen_height < 800) {
mobile_flag = true
}
return mobile_flag
}
</script>
<style lang="less" scoped>