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 axios from "axios";
import { myfuncs } from "./myfunc"; import { myfuncs } from "./myfunc";
import { useUserStore } from "@/stores/user";
const userStore = useUserStore();
var head_path = "/api"; var head_path = "/api";
export const my_network_func = { export const my_network_func = {
@@ -23,9 +27,9 @@ export const my_network_func = {
//把cookie插入json //把cookie插入json
var data = {}; var data = {};
data["data"] = json; data["data"] = json;
var cookie = myfuncs.loadJson("cookie");
if (cookie) { if (userStore.cookieValue!="") {
data["cookie"] = cookie.Value; data["cookie"] = userStore.cookieValue;
} }
var re_data = {}; var re_data = {};
@@ -42,13 +46,13 @@ export const my_network_func = {
if (response.data) { if (response.data) {
re_data["data"] = response.data; re_data["data"] = response.data;
//自动保存服务器发送的cookie //自动保存服务器发送的cookie
if (response.data.cookie) { // if (response.data.cookie) {
if (response.data.cookie.Value == "") { // if (response.data.cookie.Value == "") {
myfuncs.dele("cookie"); // myfuncs.dele("cookie");
} else { // } else {
myfuncs.saveJson("cookie", response.data.cookie); // myfuncs.saveJson("cookie", response.data.cookie);
} // }
} // }
} }
callback(re_data); callback(re_data);
+5 -4
View File
@@ -6,7 +6,7 @@ import { ref, computed } from "vue";
export const useUserStore = defineStore("user", () => { export const useUserStore = defineStore("user", () => {
// 状态 (State) // 状态 (State)
const userInfo = ref(null); const userInfo = ref(null);
const token = ref(""); const cookieValue = ref("");
const isLoggedIn = ref(false); const isLoggedIn = ref(false);
const logout = () => { const logout = () => {
@@ -15,13 +15,14 @@ export const useUserStore = defineStore("user", () => {
const login = () => { const login = () => {
isLoggedIn.value = true; isLoggedIn.value = true;
}; };
const loginUpdata = () => { const loginUpdata = (cookie) => {
isLoggedIn.value = true; console.log(cookie)
cookieValue.value=cookie.value
}; };
return { return {
userInfo, userInfo,
token, cookieValue,
isLoggedIn, isLoggedIn,
logout, logout,
login, login,
+2 -1
View File
@@ -90,8 +90,9 @@ function login() {
myfuncs.saveJson("userCookie",r.data.return.cookie) myfuncs.saveJson("userCookie",r.data.return.cookie)
} }
//userStore.isLoggedIn=true
//更新用户信息 //更新用户信息
userStore.loginUpdata(r.data.return.cookie)
mos.value?.showAlert( mos.value?.showAlert(
"success", "success",