初始化
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* pinia
|
||||
*/
|
||||
import { createPinia } from 'pinia';
|
||||
|
||||
export default createPinia();
|
||||
@@ -0,0 +1,103 @@
|
||||
/**
|
||||
* 购物车 store
|
||||
*/
|
||||
import { defineStore } from 'pinia';
|
||||
import type { Order } from '@/api/shop/order/model';
|
||||
import type { OrderInfo } from '@/api/shop/orderInfo/model';
|
||||
import type { UserAddress } from '@/api/shop/userAddress/model';
|
||||
import type { Goods } from '@/api/shop/goods/model';
|
||||
import type { Merchant } from '@/api/shop/merchant/model';
|
||||
import type { Period } from '@/api/booking/period/model'
|
||||
|
||||
export interface CarState {
|
||||
merchantId: Number | null;
|
||||
merchantName: String | null;
|
||||
merchantCode: Number | null;
|
||||
merchant: Merchant | null;
|
||||
order: Order | null;
|
||||
orderInfo: OrderInfo[] | null;
|
||||
goodsList: Goods[] | null;
|
||||
totalPrice: Number | null;
|
||||
childrenPrice: Number | null;
|
||||
payPrice: Number | null;
|
||||
period: Period | null;
|
||||
carNum: Number | null;
|
||||
carNum2: Number | null;
|
||||
type: Number | null;
|
||||
dateTime: String | null;
|
||||
address: UserAddress | null;
|
||||
}
|
||||
|
||||
export const useCarStore = defineStore({
|
||||
id: 'car',
|
||||
state: (): CarState => ({
|
||||
// 场馆ID
|
||||
merchantId: null,
|
||||
// 场馆名称
|
||||
merchantName: null,
|
||||
// 场馆编号
|
||||
merchantCode: null,
|
||||
// 场馆信息
|
||||
merchant: null,
|
||||
// 订单信息
|
||||
order: null,
|
||||
// 场地信息
|
||||
orderInfo: [],
|
||||
// 预定时段
|
||||
period: null,
|
||||
// 订单总金额
|
||||
totalPrice: null,
|
||||
// 实付金额
|
||||
payPrice: null,
|
||||
// 儿童票价
|
||||
childrenPrice: null,
|
||||
// 购物车数量
|
||||
carNum: null,
|
||||
// 儿童票数量
|
||||
carNum2: null,
|
||||
// 1全场 2半场
|
||||
type: null,
|
||||
// 下单日期
|
||||
dateTime: null,
|
||||
// 商品信息
|
||||
goodsList: [],
|
||||
// 用户收货地址
|
||||
address: null
|
||||
}),
|
||||
getters: {},
|
||||
actions: {
|
||||
/**
|
||||
* 添加购物车
|
||||
*/
|
||||
AddCar(value: OrderInfo) {
|
||||
this.orderInfo?.push(value);
|
||||
},
|
||||
/**
|
||||
* 移除购物车
|
||||
*/
|
||||
DelCard(value: OrderInfo) {
|
||||
const index = this.orderInfo?.findIndex((d) => d.fid == value.fid);
|
||||
if(index){
|
||||
this.orderInfo?.splice(index, 1);
|
||||
}
|
||||
},
|
||||
setOrder(value: Order){
|
||||
this.order = value
|
||||
},
|
||||
setMerchant(value: Merchant){
|
||||
this.merchant = value
|
||||
},
|
||||
setGoodsList(value: Goods[]) {
|
||||
this.goodsList = value;
|
||||
},
|
||||
setOrderInfo(value: OrderInfo[]) {
|
||||
this.orderInfo = value;
|
||||
},
|
||||
setAddress(value: UserAddress) {
|
||||
this.address = value;
|
||||
},
|
||||
setPeriod(value: Period){
|
||||
this.period = value
|
||||
},
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,132 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { io, Socket } from 'socket.io-client';
|
||||
import { getToken } from '@/utils/token-util';
|
||||
import { ChatConversation, ChatMessage } from '@/api/system/chat/model';
|
||||
import {
|
||||
pageChatConversation,
|
||||
updateChatConversation
|
||||
} from '@/uni_modules/ws-common/api/system/chat';
|
||||
// import { emitter } from '@/uni_modules/ws-common/utils/common';
|
||||
|
||||
const SOCKET_URL: string = 'wss://server.jimeigroup.cn';
|
||||
|
||||
interface ConnectionOptions {
|
||||
token: string;
|
||||
userId: number;
|
||||
isAdmin: boolean;
|
||||
}
|
||||
|
||||
export interface ChatState {
|
||||
socket: Socket | undefined;
|
||||
conversations: ChatConversation[];
|
||||
}
|
||||
|
||||
export const useChatStore = defineStore({
|
||||
id: 'chat',
|
||||
state: (): ChatState => ({
|
||||
socket: undefined,
|
||||
conversations: []
|
||||
}),
|
||||
getters: {
|
||||
unReadLetter(): number {
|
||||
return this.conversations.reduce((count, item) => count + item.unRead, 0);
|
||||
},
|
||||
unReadConversations(): ChatConversation[] {
|
||||
return this.conversations
|
||||
.filter((item) => item.unRead > 0)
|
||||
.sort((a, b) => {
|
||||
return (
|
||||
new Date(b.updateTime).getTime() - new Date(a.updateTime).getTime()
|
||||
);
|
||||
});
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
readConversation(id) {
|
||||
const index = this.conversations.findIndex((item) => item.id === id);
|
||||
if (index >= 0) {
|
||||
updateChatConversation({
|
||||
id: this.conversations[index].id,
|
||||
unRead: 0
|
||||
});
|
||||
this.conversations.splice(index, 1);
|
||||
}
|
||||
},
|
||||
async connectSocketIO(userId: number) {
|
||||
console.log(
|
||||
'---------------------------------connectSocketIO----------------------------------'
|
||||
);
|
||||
const options: ConnectionOptions = {
|
||||
token: getToken() || '',
|
||||
userId: userId,
|
||||
isAdmin: true
|
||||
};
|
||||
|
||||
const socket: Socket = io(SOCKET_URL, {
|
||||
query: options,
|
||||
transports: ['websocket', 'polling'],
|
||||
timeout: 5000
|
||||
});
|
||||
|
||||
socket.on('connect', () => {
|
||||
this.socket = socket;
|
||||
console.log(
|
||||
'---------------------------------socket connect----------------------------------'
|
||||
);
|
||||
// 获取聊天列表
|
||||
pageChatConversation({
|
||||
keywords: '',
|
||||
status: 1,
|
||||
page: 1,
|
||||
limit: 100,
|
||||
onlyFake: true
|
||||
}).then((res) => {
|
||||
if (res?.list) {
|
||||
this.conversations = res.list;
|
||||
}
|
||||
});
|
||||
});
|
||||
console.log(
|
||||
'---------------------------------socket----------------------------------',
|
||||
socket
|
||||
);
|
||||
// 收到新消息
|
||||
socket.on('message', (data: ChatMessage) => {
|
||||
const index = this.conversations.findIndex(
|
||||
(item) =>
|
||||
item.friendId === data.formUserId && item.userId === data.toUserId
|
||||
);
|
||||
let content = '';
|
||||
if (data.type == 'image') {
|
||||
content = '图片';
|
||||
} else if (data.type === 'card') {
|
||||
content = '卡片';
|
||||
} else {
|
||||
content = data.content;
|
||||
}
|
||||
if (index >= 0) {
|
||||
this.conversations[index].unRead++;
|
||||
this.conversations[index].content = content;
|
||||
this.conversations[index].updateTime = Date.now();
|
||||
} else {
|
||||
this.conversations.push({
|
||||
content: content,
|
||||
friendInfo: data.formUserInfo,
|
||||
userInfo: data.toUserInfo,
|
||||
messages: [],
|
||||
unRead: 1,
|
||||
updateTime: Date.now(),
|
||||
userId: data.toUserId,
|
||||
friendId: data.formUserId
|
||||
});
|
||||
}
|
||||
|
||||
// emitter.emit('message', data);
|
||||
});
|
||||
|
||||
socket.on('connect_error', () => {
|
||||
console.log('connect_error');
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* 接收传参 store
|
||||
*/
|
||||
import { defineStore } from 'pinia';
|
||||
|
||||
export interface ParamsState {
|
||||
title: string | null;
|
||||
comments: string | null;
|
||||
back: string | null;
|
||||
redirect: string | null | undefined;
|
||||
}
|
||||
|
||||
export const useParamsStore = defineStore({
|
||||
id: 'params',
|
||||
state: (): ParamsState => ({
|
||||
// 标题
|
||||
title: '操作成功',
|
||||
// 描述
|
||||
comments: '您的申请已提交',
|
||||
// 当前页面路径
|
||||
back: null,
|
||||
// 跳转的页面
|
||||
redirect: null
|
||||
}),
|
||||
getters: {},
|
||||
actions: {
|
||||
setTitle(value: string) {
|
||||
this.title = value;
|
||||
},
|
||||
setComments(value: string) {
|
||||
this.comments = value;
|
||||
},
|
||||
setBack(value: string) {
|
||||
this.back = value;
|
||||
},
|
||||
setRedirect(value: string) {
|
||||
this.redirect = value;
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* 租户信息 store
|
||||
*/
|
||||
import { defineStore } from 'pinia';
|
||||
import { getSiteInfo } from '@/api/layout';
|
||||
import type { Tenant } from '@/api/system/tennat/model';
|
||||
import type { Company } from '@/api/system/company/model';
|
||||
import type { WebsiteParam } from '@/api/cms/website/field/model';
|
||||
// const EXTRA_MENUS: any = [];
|
||||
|
||||
export interface UserState {
|
||||
tenant : Tenant | null;
|
||||
company : Company | null;
|
||||
params : WebsiteParam | null;
|
||||
}
|
||||
|
||||
export const useTenantStore = defineStore({
|
||||
id: 'tenant',
|
||||
state: () : UserState => ({
|
||||
// 租户信息
|
||||
tenant: null,
|
||||
// 企业信息
|
||||
company: null,
|
||||
// 参数配置
|
||||
params: {},
|
||||
}),
|
||||
getters: {},
|
||||
actions: {
|
||||
/**
|
||||
* 请求用户信息、权限、角色、菜单
|
||||
*/
|
||||
async fetchTenantInfo() {
|
||||
const company = await getSiteInfo().catch(() => void 0);
|
||||
if (!company) {
|
||||
return {};
|
||||
}
|
||||
// 租户信息
|
||||
this.company = company;
|
||||
// 企业信息
|
||||
if (company) {
|
||||
this.company = company;
|
||||
// 获取配置参数
|
||||
// if (company.fields) {
|
||||
// const obj = {}
|
||||
// company.fields.map(d => {
|
||||
// const key = d.name;
|
||||
// obj[key] = d.value
|
||||
// })
|
||||
// this.setParams(obj);
|
||||
// }
|
||||
|
||||
// localStorage.setItem('TenantId', String(company.tenantId));
|
||||
// localStorage.setItem('TenantName', String(company.companyName));
|
||||
// localStorage.setItem('CompanyId', String(company.companyId));
|
||||
}
|
||||
return company;
|
||||
},
|
||||
/**
|
||||
* 更新租户信息
|
||||
*/
|
||||
setInfo(value : Tenant) {
|
||||
this.tenant = value;
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* 登录用户 store
|
||||
*/
|
||||
import { defineStore } from 'pinia';
|
||||
import type { User } from '@/uni_modules/ws-common/api/system/user/model';
|
||||
import { getUserInfo } from '@/uni_modules/ws-common/api/layout';
|
||||
|
||||
export interface UserState {
|
||||
info: User | null;
|
||||
menus: any[] | null | undefined;
|
||||
authorities: (string | undefined)[];
|
||||
roles: (string | undefined)[];
|
||||
}
|
||||
|
||||
export const useUserStore = defineStore({
|
||||
id: 'user',
|
||||
state: (): UserState => ({
|
||||
// 当前登录用户的信息
|
||||
info: null,
|
||||
// 当前登录用户的菜单
|
||||
menus: null,
|
||||
// 当前登录用户的权限
|
||||
authorities: [],
|
||||
// 当前登录用户的角色
|
||||
roles: []
|
||||
}),
|
||||
getters: {},
|
||||
actions: {
|
||||
/**
|
||||
* 请求用户信息、权限、角色、菜单
|
||||
*/
|
||||
async fetchUserInfo() {
|
||||
const result = await getUserInfo().catch(() => {});
|
||||
if (!result) {
|
||||
return {};
|
||||
}
|
||||
// 用户信息
|
||||
this.info = result;
|
||||
// 用户权限
|
||||
this.authorities =
|
||||
result.authorities
|
||||
?.filter((d) => !!d.authority)
|
||||
?.map((d) => d.authority) ?? [];
|
||||
// 用户角色
|
||||
this.roles = result.roles?.map((d) => d.roleCode) ?? [];
|
||||
// 用户菜单, 过滤掉按钮类型并转为 children 形式
|
||||
this.menus = [];
|
||||
|
||||
return result;
|
||||
},
|
||||
/**
|
||||
* 更新用户信息
|
||||
*/
|
||||
setInfo(value: User) {
|
||||
this.info = value;
|
||||
},
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user