Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let method = 'post';
let path = Url.registerApi;
let params = {
userName: this.userName,
passWord: this.passWord
};
try {
this.loading = true; // 开启按钮注册状态
let res = await registerUser(path, method, params);
console.log(res)
// 将 token & 用户名存储到 localStorage 中
localStorage.setItem('token', res.token);
localStorage.setItem('userName', res.userName);
// 注册成功提示
Toast.success({
duration: 1000,
message: res.message
});
// 1.5 秒后跳转到首页
let timer = setTimeout(() => {
this.$router.push({ name: 'Home' }); // 注册成功跳转到首页
clearTimeout(timer); // 清除定时器
}, 1500);
} catch (error) {
console.log(error)
this.$toast.fail('注册失败');
} finally {
this.loading = false;
}
}
}
this.$axios.post("/vue/login", this.loginInfo).then(res => {
console.log(res.data);
if (!!res.data.type) {
window.sessionStorage.userInfo = JSON.stringify({
token: res.data.token
});
window.localStorage.setItem('username',res.data.result.username)
Toast.success("登录成功 即将跳转");
this.$router.push({ name: "home" });
}
});
} else {
let cartInfo = localStorage.cartInfo
? JSON.parse(localStorage.cartInfo)
: [];
let isHaveGood = cartInfo.find(cart => cart.goodId === this.goodId);
console.log("ishave", isHaveGood);
if (!isHaveGood) {
let newGoodsInfo = {
goodId: this.goodsInfo.ID,
name: this.goodsInfo.NAME,
price: this.goodsInfo.PRESENT_PRICE,
image: this.goodsInfo.IMAGE1,
count: 1
};
cartInfo.push(newGoodsInfo);
localStorage.cartInfo = JSON.stringify(cartInfo);
Toast.success("添加成功");
} else {
Toast.success("已有此商品");
}
this.$router.push({ name: "Cart" });
}
},
.then(res => {
console.log(res);
if (res.data.code === 200) {
Toast.success(res.data.message);
this.$router.push("/");
} else {
console.log(res.data.message);
this.openLoading = false;
Toast.fail("注册失败");
}
})
.catch(err => {
}).then((res) => {
console.log(res)
if(res.code == 0) {
Toast.fail(res.msg)
} else {
Toast.success(res.msg)
this.$router.replace('/center')
}
})
},
async onAddCart(item) {
let res = await apiAddCart(item.productId);
if (res.data.code === 0) {
Toast.success({
message: this.$t("m.message.addSuccess"),
duration: 500
});
item.num++;
} else {
Toast.fail({
message: res.data.msg,
position: "bottom"
});
}
this.onCalAllCoach();
},
async onCutCart(item) {
created(){
if (localStorage.userInfo) {
Toast.success('你已经登录过了')
this.$router.push('/')
}
},
methods: {
async onAddCart(item) {
let res = await apiAddCart(item.uid);
if (res.data.code === 0) {
Toast.success({
message: this.$t("m.message.addSuccess"),
duration: 500
});
} else {
Toast.fail({
message: res.data.msg,
position: "bottom"
});
}
},
onDetail(id) {
async onBuy() {
if (this.isBuy) {
this.setOrders([this.detailInfo]);
this.$router.push("./orderwait");
if (!this.cartNum) {
let res = await apiActionCart(this.$route.query.uid, "add");
if (res.data.code === 0) {
Toast.success({
message: this.$t("m.message.addSuccess"),
duration: 500
});
} else {
Toast.fail({
message: res.data.msg,
position: "bottom"
});
}
this.addCartModel = false;
}
}
},
...mapMutations({
async onAddCart(item) {
let res = await apiAddCart(item.uid);
if (res.data.code === 0) {
Toast.success({
message: this.$t("m.message.addSuccess"),
duration: 500
});
} else {
Toast.fail({
message: res.data.msg,
position: "bottom"
});
}
},
onCategory(index) {