h5版本移植
This commit is contained in:
Vendored
+67
-3
@@ -1,6 +1,70 @@
|
|||||||
|
|
||||||
//判断字符串是否为邮箱
|
//判断字符串是否为邮箱
|
||||||
function isValidEmail(email) {
|
function isValidEmail(email) {
|
||||||
const regex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
|
const regex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
|
||||||
return regex.test(email);
|
return regex.test(email);
|
||||||
|
}
|
||||||
|
|
||||||
|
function save(key, data) {
|
||||||
|
localStorage.setItem(key, data);
|
||||||
|
}
|
||||||
|
function load(key) {
|
||||||
|
return localStorage.getItem(key);
|
||||||
|
}
|
||||||
|
function dele(key) {
|
||||||
|
localStorage.removeItem(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
function save_json(key, data) {
|
||||||
|
save(key, JSON.stringify(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
function load_json(key) {
|
||||||
|
var js_data = load(key);
|
||||||
|
if (js_data) {
|
||||||
|
return JSON.parse(js_data);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function post_json(path, json, callback) {
|
||||||
|
var host = "";
|
||||||
|
var port = 0;
|
||||||
|
var head_path = "/api/v1";
|
||||||
|
//把cookie插入json
|
||||||
|
var data = {};
|
||||||
|
data["data"] = json;
|
||||||
|
var cookie = load_json("cookie");
|
||||||
|
if (cookie) {
|
||||||
|
data["cookie"] = cookie;
|
||||||
|
}
|
||||||
|
var re_data = {};
|
||||||
|
|
||||||
|
axios
|
||||||
|
.post(head_path + path, data, {
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
console.log(response)
|
||||||
|
re_data["statusCode"] = response.status;
|
||||||
|
//载入服务器返回的数据
|
||||||
|
if (response.data) {
|
||||||
|
re_data["data"] = response.data;
|
||||||
|
}
|
||||||
|
//自动保存服务器发送的cookie
|
||||||
|
if (response.cookie) {
|
||||||
|
if (response.cookie.Value == "") {
|
||||||
|
dele("cookie");
|
||||||
|
} else {
|
||||||
|
save_json("cookie", response.cookie);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
callback(re_data);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
re_data["statusCode"] = -1;
|
||||||
|
callback(re_data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -100,31 +100,15 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
function logout() {
|
function logout() {
|
||||||
console.log("logout");
|
post_json("/user/logout", null, (c) => {
|
||||||
const url = '/api/v1/user/logout';
|
if (c.statusCode == 200) {
|
||||||
const sumt_data = {
|
console.log(c)
|
||||||
cookie: "",
|
dele("user_info")
|
||||||
};
|
dele("cookie")
|
||||||
|
setTimeout(() => {
|
||||||
try {
|
|
||||||
const response = axios.post(url, sumt_data, {
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
}
|
|
||||||
}).then(response => {
|
|
||||||
//console.log('提交成功:', response.data); // 正确打印服务器数据
|
|
||||||
//跳转到主页
|
|
||||||
if (response.data.err_code == 0) {
|
|
||||||
location.href = '/'
|
location.href = '/'
|
||||||
}
|
}, 500);
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
if (error.response) {
|
|
||||||
// 服务器返回了错误状态码(如 4xx, 5xx)
|
|
||||||
console.error('服务器错误:', error.response.data);
|
|
||||||
} else {
|
|
||||||
console.error('请求未完成:', error.message);
|
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@@ -157,43 +157,28 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (from_data_check) {
|
if (from_data_check) {
|
||||||
const url = '/api/v1/user/login';
|
post_json("/user/login", {
|
||||||
const sumt_data = {
|
|
||||||
data: {
|
|
||||||
username: username_dom.value,
|
username: username_dom.value,
|
||||||
password: password_dom.value,
|
password: password_dom.value,
|
||||||
is_keep_login: keep_login_dom.checked
|
is_keep_login: keep_login_dom.checked
|
||||||
},
|
}, (c) => {
|
||||||
|
if (c.statusCode == 200) {
|
||||||
};
|
if (c.data.err_code == 0) {
|
||||||
|
save_json("cookie", c.data.return.cookie)
|
||||||
try {
|
save_json("user_info", c.data.return.user_info)
|
||||||
const response = axios.post(url, sumt_data, {
|
setTimeout(() => {
|
||||||
headers: {
|
location.href = '/'
|
||||||
'Content-Type': 'application/json'
|
}, 500);
|
||||||
}
|
} else {
|
||||||
}).then(response => {
|
//this.$refs.footer.alert('warning', "账号或密码不正确")
|
||||||
console.log('提交成功:', response.data); // 正确打印服务器数据
|
}
|
||||||
//跳转到主页
|
} else {
|
||||||
if (response.data.err_code == 0) {
|
//this.$refs.footer.alert('danger', "网络连接错误:" + c.statusCode)
|
||||||
location.href = '/'
|
}
|
||||||
} else {
|
})
|
||||||
password_dom.classList.add("is-invalid");
|
|
||||||
document.getElementById("pass_err").innerHTML = "账号或密码错误";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
if (error.response) {
|
|
||||||
// 服务器返回了错误状态码(如 4xx, 5xx)
|
|
||||||
console.error('服务器错误:', error.response.data);
|
|
||||||
} else {
|
|
||||||
console.error('请求未完成:', error.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
Reference in New Issue
Block a user