This commit is contained in:
2025-10-24 17:12:18 +08:00
commit 9dead7a890
2004 changed files with 298646 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
import * as Pinia from "pinia";
import piniaPersist from "pinia-plugin-persist-uni";
/* 创建全局状态管理器, 并且使用持久化插件 */
const pinia = Pinia.createPinia().use(piniaPersist);
export default pinia;

View File

@@ -0,0 +1,72 @@
import { defineStore } from "pinia";
import pinia from "../index";
const STORE_ID = "ORDER";
const useOrderStore = defineStore(STORE_ID, {
state: (): any => {
return {
merchantId: "", //服务id
projectId: 0, //项目id
addrId: 0, //地址id
prodCount: 0, //产品数量
isPoints: 0, //是否使用积分
travelMode: 0, //出行方式
default: {
merchantId: "", //服务id
projectId: 0, //项目id
addrId: 0, // 默认地址
prodCount: 1, //产品数量
isPoints: 0, //是否使用积分
travelMode: 1, //滴滴
},
};
},
getters: {
orderInfo() {
return {
merchantId: this.merchantId,
projectId: this.projectId,
addrId: this.addrId,
prodCount: this.prodCount,
isPoints: this.isPoints,
travelMode: this.travelMode,
};
},
},
actions: {
setOrderInfo(data: any) {
this.merchantId = data.merchantId ?? this.default.merchantId;
this.projectId = data.projectId ?? this.default.projectId;
this.addrId = data.addrId ?? this.default.addrId;
this.prodCount = data.prodCount ?? this.default.prodCount;
this.isPoints = data.isPoints ?? this.default.isPoints;
this.travelMode = data.travelMode ?? this.default.travelMode;
},
},
persist: {
/* 开启数据持久化 */
enabled: true,
H5Storage: window?.localStorage,
strategies: [
{
key: STORE_ID,
paths: [
"merchantId",
"projectId",
"addrId",
"prodCount",
"isPoints",
"travelMode",
"default",
],
},
],
},
});
export default useOrderStore;
export function useOrderStoreWithout() {
return useOrderStore(pinia);
}

View File

@@ -0,0 +1,139 @@
import { defineStore } from "pinia";
import pinia from "../index";
import { wxLogin, testLogin, getUserInfo, logOut,updateProdSwitch } from "@/api/user/user";
import { setUserInfo, activation } from "@/api/user/user-info";
import util from "@/utils/util.js";
const STORE_ID = "USER";
const useUserStore = defineStore(STORE_ID, {
state: (): any => {
return {
userInfo: null,
userOverview: null,
token: null,
isNewReg: null,
sessionId: "",
activeTab: 0, // 默认选中的索引
prodSwitch: 1,
};
},
getters: {
isLogin(): boolean {
return !!(this.userInfo && this.token);
},
},
actions: {
//设置active的值
setActive(active) {
this.activeTab = active;
},
// 微信登录
async doWxLogin(loginData) {
const { data } = await wxLogin(loginData);
if (data && data.accessToken) return data;
return false;
},
async doPhoneLogin(loginData) {
const { data } = await testLogin(loginData);
if (data && data.accessToken) return data;
return false;
},
async uploadAvatar(avatarUrl) {
const res = await util.wxUploadAvatar(avatarUrl, this.token);
console.log(res);
this.getUserInfo();
},
async updateProdSwitch(){
const {data} = await updateProdSwitch();
this.prodSwitch=data;
},
// 退出登录
getProdSwitch() {
return this.prodSwitch;
},
async doLogout() {
await logOut();
this.$reset();
uni.setStorage({ key: STORE_ID, data: JSON.stringify(this.$state) });
},
async getUserInfo() {
const { data } = await getUserInfo();
if (!data) return false;
this.userInfo = data;
uni.setStorage({ key: STORE_ID, data: JSON.stringify(this.$state) });
return this.userInfo;
},
async setUserInfo(params) {
const { success } = await setUserInfo(params);
if (!success) {
return false;
}
await this.getUserInfo();
uni.showToast({
title: "激活成功",
icon: "none",
});
return true;
},
async onActivation(params) {
uni.showLoading({
title: "提交中...",
});
const { success } = await activation(params);
if (!success) {
return false;
}
await this.getUserInfo();
let text = "激活成功";
if (params.flagStatus !== 0) {
text = "提交成功,审核中";
}
uni.hideLoading();
uni.showToast({
title: text,
icon: "none",
});
return true;
},
getSessionId() {
if (this.sessionId) {
return this.sessionId;
} else {
const sessionId = util.randomString(16);
this.sessionId = sessionId;
return sessionId;
}
},
},
persist: {
/* 开启数据持久化 */
enabled: true,
H5Storage: window?.localStorage,
strategies: [
{
key: STORE_ID,
paths: [
"userInfo",
"userOverview",
"token",
"isNewReg",
"sessionId",
"activeTab",
"prodSwitch"
],
},
],
},
});
export default useUserStore;
export function useUserStoreWithout() {
return useUserStore(pinia);
}