This commit is contained in:
2025-11-12 20:20:12 +08:00
parent a5add3dd73
commit e6a1a1037e
3 changed files with 21 additions and 15 deletions
+14 -10
View File
@@ -1,5 +1,9 @@
import axios from "axios";
import { myfuncs } from "./myfunc";
import { useUserStore } from "@/stores/user";
const userStore = useUserStore();
var head_path = "/api";
export const my_network_func = {
@@ -23,9 +27,9 @@ export const my_network_func = {
//把cookie插入json
var data = {};
data["data"] = json;
var cookie = myfuncs.loadJson("cookie");
if (cookie) {
data["cookie"] = cookie.Value;
if (userStore.cookieValue!="") {
data["cookie"] = userStore.cookieValue;
}
var re_data = {};
@@ -42,13 +46,13 @@ export const my_network_func = {
if (response.data) {
re_data["data"] = response.data;
//自动保存服务器发送的cookie
if (response.data.cookie) {
if (response.data.cookie.Value == "") {
myfuncs.dele("cookie");
} else {
myfuncs.saveJson("cookie", response.data.cookie);
}
}
// if (response.data.cookie) {
// if (response.data.cookie.Value == "") {
// myfuncs.dele("cookie");
// } else {
// myfuncs.saveJson("cookie", response.data.cookie);
// }
// }
}
callback(re_data);
+5 -4
View File
@@ -6,7 +6,7 @@ import { ref, computed } from "vue";
export const useUserStore = defineStore("user", () => {
// 状态 (State)
const userInfo = ref(null);
const token = ref("");
const cookieValue = ref("");
const isLoggedIn = ref(false);
const logout = () => {
@@ -15,13 +15,14 @@ export const useUserStore = defineStore("user", () => {
const login = () => {
isLoggedIn.value = true;
};
const loginUpdata = () => {
isLoggedIn.value = true;
const loginUpdata = (cookie) => {
console.log(cookie)
cookieValue.value=cookie.value
};
return {
userInfo,
token,
cookieValue,
isLoggedIn,
logout,
login,
+2 -1
View File
@@ -90,8 +90,9 @@ function login() {
myfuncs.saveJson("userCookie",r.data.return.cookie)
}
//userStore.isLoggedIn=true
//更新用户信息
userStore.loginUpdata(r.data.return.cookie)
mos.value?.showAlert(
"success",