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

fix:提示信息

上级 57ee2f06
...@@ -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
......
...@@ -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)) {
// callback(new Error('请输入密码'));
// } if {
if (value.length < 2) { if (value.length < 2) {
callback(new Error("名字至少两位")); callback(new Error('名字至少两位'))
} else { } else {
callback(); callback()
}
}, 1000)
} }
}, 1000);
};
const validatePass = (rule, value, callback) => { const validatePass = (rule, value, callback) => {
if (value === "") { if (value === '') {
callback(new Error("请输入密码")); callback(new Error('请输入密码'))
} else { } else {
// if (this.ruleForm.checkPass !== '') { callback()
// 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 { return {
loading: false, loading: false,
// baseurl:"http://127.0.0.1/user/login/", // baseurl:"http://127.0.0.1/user/login/",
baseurl: "/api/", baseurl: '/api/',
// baseurl: 'http://yongma16.xyz/user/login/', // baseurl: 'http://yongma16.xyz/user/login/',
ruleForm: { ruleForm: {
pass: "", pass: '',
// checkPass: '', // checkPass: '',
name: "", name: ''
}, },
rules: { rules: {
pass: [{ validator: validatePass, trigger: "blur" }], pass: [{ validator: validatePass, trigger: 'blur' }],
checkPass: [{ validator: validatePass, trigger: "blur" }], checkPass: [{ validator: validatePass, trigger: 'blur' }],
name: [{ validator: checkName, trigger: "blur" }], name: [{ validator: checkName, trigger: 'blur' }]
}, }
}; }
}, },
methods: { methods: {
submitForm(formName) { submitForm (formName) {
const that = this; // this指向 const that = this // this指向
this.$refs[formName].validate((valid) => { this.$refs[formName].validate((valid) => {
if (valid) { if (valid) {
that.loading = true; that.loading = true
// 提交数据 // 提交数据
const loginUrl = that.baseurl + "user/login/"; const loginUrl = that.baseurl + 'user/login/'
const userInfo = { const userInfo = {
name: that.ruleForm.name, name: that.ruleForm.name,
password: that.ruleForm.pass, password: that.ruleForm.pass
}; }
that.$axios that.$axios
.post(loginUrl, userInfo) .post(loginUrl, userInfo)
.then((res) => { .then((res) => {
// alter('提交中'); // alter('提交中');
if (res.data.code == 1) { if (res.data.code === 1) {
localStorage.setItem( localStorage.setItem(
"yma16siteUserInfo", 'yma16siteUserInfo',
JSON.stringify({ JSON.stringify({
username: userInfo.name, username: userInfo.name,
password: userInfo.password, password: userInfo.password
}) })
); )
store.commit("setUserInfo", userInfo); // store信息 store.commit('setUserInfo', userInfo) // store信息
document.cookie = `user=${that.ruleForm.name}`; document.cookie = `user=${that.ruleForm.name}`
that.$router.push({ path: "/" }); that.$router.push({ path: '/' })
// 添加cookie // 添加cookie
} else if (res.data.code == 0) { } else if (res.data.code === 0) {
// alter("失败!" res.data.msg) // alter("失败!" res.data.msg)
that.$message.error("用户名或密码错误"); that.$message.error('用户名或密码错误')
} }
that.loading = false; that.loading = false
}) })
.catch((error) => { .catch((error) => {
that.loading = false; that.loading = false
that.$message.error(error); that.$message.error(error)
}); })
} else { } else {
that.$message.error("请输入账号密码"); return false
return false;
} }
}); })
},
resetForm(formName) {
this.$refs[formName].resetFields();
},
}, },
}; 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.
先完成此消息的编辑!
想要评论请 注册