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

fix:提示信息

上级 57ee2f06
...@@ -11,7 +11,7 @@ module.exports = { ...@@ -11,7 +11,7 @@ module.exports = {
extends: [ extends: [
// https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention // 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. // 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 // https://github.com/standard/standard/blob/master/docs/RULES-en.md
'standard' 'standard'
], ],
...@@ -21,6 +21,10 @@ module.exports = { ...@@ -21,6 +21,10 @@ module.exports = {
], ],
// add your custom rules here // add your custom rules here
rules: { rules: {
'indent': [2, 4], // 强制使用一致的缩进
'eqeqeq': [2, 'always'], // 要求使用 === 和 !==
'semi': [2, 'never'], // 要求或禁止使用分号代替 ASI
'quotes': [2, 'single'] ,
// allow async-await // allow async-await
'generator-star-spacing': 'off', 'generator-star-spacing': 'off',
// allow debugger during development // allow debugger during development
......
<template> <template>
<div class="login" style="text-align: center"> <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 <el-form
:model="ruleForm" :model="ruleForm"
status-icon status-icon
...@@ -43,110 +43,94 @@ ...@@ -43,110 +43,94 @@
</template> </template>
<script> <script>
import store from "@/store"; import store from '@/store'
export default { export default {
name: "Login", name: 'Login',
data() { data () {
const checkName = (rule, value, callback) => { const checkName = (rule, value, callback) => {
if (!value) { if (!value) {
return callback(new Error("账号不能为空")); return callback(new Error('账号不能为空'))
} }
setTimeout(() => { setTimeout(() => {
// if (!Number.isInteger(value)) { if (value.length < 2) {
// callback(new Error('请输入密码')); callback(new Error('名字至少两位'))
// } if { } else {
if (value.length < 2) { callback()
callback(new Error("名字至少两位")); }
} else { }, 1000)
callback();
} }
}, 1000); const validatePass = (rule, value, callback) => {
}; if (value === '') {
const validatePass = (rule, value, callback) => { callback(new Error('请输入密码'))
if (value === "") { } else {
callback(new Error("请输入密码")); callback()
} else { }
// if (this.ruleForm.checkPass !== '') { }
// this.$refs.ruleForm.validateField('checkPass'); return {
// } loading: false,
callback(); // baseurl:"http://127.0.0.1/user/login/",
} baseurl: '/api/',
}; // baseurl: 'http://yongma16.xyz/user/login/',
// var validatePass2 = (rule, value, callback) => { ruleForm: {
// if (value === '') { pass: '',
// callback(new Error('请再次输入密码')); // checkPass: '',
// } else if (value !== this.ruleForm.pass) { name: ''
// callback(new Error('两次输入密码不一致!')); },
// } else { rules: {
// callback(); pass: [{ validator: validatePass, trigger: 'blur' }],
// } checkPass: [{ validator: validatePass, trigger: 'blur' }],
// }; name: [{ validator: checkName, trigger: 'blur' }]
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;
} }
});
},
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> </script>
<style scoped> <style scoped>
......
...@@ -176,10 +176,6 @@ export default { ...@@ -176,10 +176,6 @@ export default {
}); });
}); });
} else { } else {
that.$message({
message: "注册失败" + that.ruleForm.name + "!",
type: "error",
});
return false; return false;
} }
}); });
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册