提交 d49fa0dc 编写于 作者: yma16's avatar yma16

fix:提示信息

上级 57ee2f06
......@@ -11,7 +11,7 @@ module.exports = {
extends: [
// https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention
// consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules.
'plugin:vue/essential',
'plugin:vue/essential',
// https://github.com/standard/standard/blob/master/docs/RULES-en.md
'standard'
],
......@@ -21,6 +21,10 @@ module.exports = {
],
// add your custom rules here
rules: {
'indent': [2, 4], // 强制使用一致的缩进
'eqeqeq': [2, 'always'], // 要求使用 === 和 !==
'semi': [2, 'never'], // 要求或禁止使用分号代替 ASI
'quotes': [2, 'single'] ,
// allow async-await
'generator-star-spacing': 'off',
// allow debugger during development
......
<template>
<div class="login" style="text-align: center">
<el-card class="box-card" style="text-align: center" v-loading="loading">
<el-card class="box-card" style="text-align: center" v-loading="loading">
<el-form
:model="ruleForm"
status-icon
......@@ -43,110 +43,94 @@
</template>
<script>
import store from "@/store";
import store from '@/store'
export default {
name: "Login",
data() {
const checkName = (rule, value, callback) => {
if (!value) {
return callback(new Error("账号不能为空"));
}
setTimeout(() => {
// if (!Number.isInteger(value)) {
// callback(new Error('请输入密码'));
// } if {
if (value.length < 2) {
callback(new Error("名字至少两位"));
} else {
callback();
name: 'Login',
data () {
const checkName = (rule, value, callback) => {
if (!value) {
return callback(new Error('账号不能为空'))
}
setTimeout(() => {
if (value.length < 2) {
callback(new Error('名字至少两位'))
} else {
callback()
}
}, 1000)
}
}, 1000);
};
const validatePass = (rule, value, callback) => {
if (value === "") {
callback(new Error("请输入密码"));
} else {
// if (this.ruleForm.checkPass !== '') {
// this.$refs.ruleForm.validateField('checkPass');
// }
callback();
}
};
// var validatePass2 = (rule, value, callback) => {
// if (value === '') {
// callback(new Error('请再次输入密码'));
// } else if (value !== this.ruleForm.pass) {
// callback(new Error('两次输入密码不一致!'));
// } else {
// callback();
// }
// };
return {
loading: false,
// baseurl:"http://127.0.0.1/user/login/",
baseurl: "/api/",
// baseurl: 'http://yongma16.xyz/user/login/',
ruleForm: {
pass: "",
// checkPass: '',
name: "",
},
rules: {
pass: [{ validator: validatePass, trigger: "blur" }],
checkPass: [{ validator: validatePass, trigger: "blur" }],
name: [{ validator: checkName, trigger: "blur" }],
},
};
},
methods: {
submitForm(formName) {
const that = this; // this指向
this.$refs[formName].validate((valid) => {
if (valid) {
that.loading = true;
// 提交数据
const loginUrl = that.baseurl + "user/login/";
const userInfo = {
name: that.ruleForm.name,
password: that.ruleForm.pass,
};
that.$axios
.post(loginUrl, userInfo)
.then((res) => {
// alter('提交中');
if (res.data.code == 1) {
localStorage.setItem(
"yma16siteUserInfo",
JSON.stringify({
username: userInfo.name,
password: userInfo.password,
})
);
store.commit("setUserInfo", userInfo); // store信息
document.cookie = `user=${that.ruleForm.name}`;
that.$router.push({ path: "/" });
// 添加cookie
} else if (res.data.code == 0) {
// alter("失败!" res.data.msg)
that.$message.error("用户名或密码错误");
}
that.loading = false;
})
.catch((error) => {
that.loading = false;
that.$message.error(error);
});
} else {
that.$message.error("请输入账号密码");
return false;
const validatePass = (rule, value, callback) => {
if (value === '') {
callback(new Error('请输入密码'))
} else {
callback()
}
}
return {
loading: false,
// baseurl:"http://127.0.0.1/user/login/",
baseurl: '/api/',
// baseurl: 'http://yongma16.xyz/user/login/',
ruleForm: {
pass: '',
// checkPass: '',
name: ''
},
rules: {
pass: [{ validator: validatePass, trigger: 'blur' }],
checkPass: [{ validator: validatePass, trigger: 'blur' }],
name: [{ validator: checkName, trigger: 'blur' }]
}
}
});
},
resetForm(formName) {
this.$refs[formName].resetFields();
},
},
};
methods: {
submitForm (formName) {
const that = this // this指向
this.$refs[formName].validate((valid) => {
if (valid) {
that.loading = true
// 提交数据
const loginUrl = that.baseurl + 'user/login/'
const userInfo = {
name: that.ruleForm.name,
password: that.ruleForm.pass
}
that.$axios
.post(loginUrl, userInfo)
.then((res) => {
// alter('提交中');
if (res.data.code === 1) {
localStorage.setItem(
'yma16siteUserInfo',
JSON.stringify({
username: userInfo.name,
password: userInfo.password
})
)
store.commit('setUserInfo', userInfo) // store信息
document.cookie = `user=${that.ruleForm.name}`
that.$router.push({ path: '/' })
// 添加cookie
} else if (res.data.code === 0) {
// alter("失败!" res.data.msg)
that.$message.error('用户名或密码错误')
}
that.loading = false
})
.catch((error) => {
that.loading = false
that.$message.error(error)
})
} else {
return false
}
})
},
resetForm (formName) {
this.$refs[formName].resetFields()
}
}
}
</script>
<style scoped>
......
......@@ -176,10 +176,6 @@ export default {
});
});
} else {
that.$message({
message: "注册失败" + that.ruleForm.name + "!",
type: "error",
});
return false;
}
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册