committed by
Gitee
38 changed files with 688 additions and 665 deletions
@ -1,32 +1,32 @@ |
|||
import { defineStore } from 'pinia'; |
|||
import http from '../common/request' |
|||
|
|||
export default { |
|||
state: { |
|||
webrtc: {} |
|||
}, |
|||
mutations: { |
|||
setConfig(state, config) { |
|||
state.webrtc = config.webrtc; |
|||
}, |
|||
clear(state){ |
|||
state.webrtc = {}; |
|||
export default defineStore('configStore', { |
|||
state: () => { |
|||
return { |
|||
webrtc: {} |
|||
} |
|||
}, |
|||
actions:{ |
|||
loadConfig(context){ |
|||
actions: { |
|||
setConfig(config) { |
|||
this.webrtc = config.webrtc; |
|||
}, |
|||
clear() { |
|||
this.webrtc = {}; |
|||
}, |
|||
loadConfig() { |
|||
return new Promise((resolve, reject) => { |
|||
http({ |
|||
url: '/system/config', |
|||
method: 'GET' |
|||
}).then((config) => { |
|||
console.log("系统配置",config) |
|||
context.commit("setConfig",config); |
|||
console.log("系统配置", config) |
|||
this.setConfig(config); |
|||
resolve(); |
|||
}).catch((res)=>{ |
|||
}).catch((res) => { |
|||
reject(res); |
|||
}); |
|||
}) |
|||
} |
|||
} |
|||
|
|||
} |
|||
}) |
|||
@ -1,57 +1,58 @@ |
|||
import { defineStore } from 'pinia'; |
|||
import http from '@/common/request'; |
|||
|
|||
export default { |
|||
state: { |
|||
groups: [], |
|||
activeIndex: -1, |
|||
export default defineStore('groupStore', { |
|||
state: () => { |
|||
return { |
|||
groups: [], |
|||
activeIndex: -1 |
|||
} |
|||
}, |
|||
mutations: { |
|||
setGroups(state, groups) { |
|||
state.groups = groups; |
|||
actions: { |
|||
setGroups(groups) { |
|||
this.groups = groups; |
|||
}, |
|||
activeGroup(state, index) { |
|||
state.activeIndex = index; |
|||
activeGroup(index) { |
|||
this.activeIndex = index; |
|||
}, |
|||
addGroup(state, group) { |
|||
state.groups.unshift(group); |
|||
addGroup(group) { |
|||
this.groups.unshift(group); |
|||
}, |
|||
removeGroup(state, groupId) { |
|||
state.groups.forEach((g, index) => { |
|||
removeGroup(groupId) { |
|||
this.groups.forEach((g, index) => { |
|||
if (g.id == groupId) { |
|||
state.groups.splice(index, 1); |
|||
if (state.activeIndex >= state.groups.length) { |
|||
state.activeIndex = state.groups.length - 1; |
|||
this.groups.splice(index, 1); |
|||
if (this.activeIndex >= this.groups.length) { |
|||
this.activeIndex = this.groups.length - 1; |
|||
} |
|||
} |
|||
}) |
|||
|
|||
}, |
|||
updateGroup(state, group) { |
|||
state.groups.forEach((g, idx) => { |
|||
if (g.id == group.id) { |
|||
// 拷贝属性
|
|||
Object.assign(state.groups[idx], group); |
|||
} |
|||
}) |
|||
updateGroup(group) { |
|||
let g = this.findGroup(group.id); |
|||
Object.assign(g, group); |
|||
}, |
|||
clear(state){ |
|||
state.groups = []; |
|||
state.activeGroup = -1; |
|||
} |
|||
}, |
|||
actions: { |
|||
loadGroup(context) { |
|||
clear() { |
|||
this.groups = []; |
|||
this.activeGroup = -1; |
|||
}, |
|||
loadGroup() { |
|||
return new Promise((resolve, reject) => { |
|||
http({ |
|||
url: '/group/list', |
|||
method: 'GET' |
|||
}).then((groups) => { |
|||
context.commit("setGroups", groups); |
|||
this.setGroups(groups); |
|||
resolve(); |
|||
}).catch((res) => { |
|||
reject(res); |
|||
}) |
|||
}); |
|||
} |
|||
}, |
|||
getters: { |
|||
findGroup: (state) => (id) => { |
|||
return state.groups.find((g) => g.id == id); |
|||
} |
|||
} |
|||
} |
|||
}) |
|||
@ -1,35 +0,0 @@ |
|||
import chatStore from './chatStore.js'; |
|||
import friendStore from './friendStore.js'; |
|||
import userStore from './userStore.js'; |
|||
import groupStore from './groupStore.js'; |
|||
import configStore from './configStore.js'; |
|||
import { createStore } from 'vuex'; |
|||
|
|||
const store = createStore({ |
|||
modules: { |
|||
chatStore, |
|||
friendStore, |
|||
userStore, |
|||
groupStore, |
|||
configStore |
|||
}, |
|||
state: {}, |
|||
actions: { |
|||
load(context) { |
|||
return this.dispatch("loadUser").then(() => { |
|||
const promises = []; |
|||
promises.push(this.dispatch("loadFriend")); |
|||
promises.push(this.dispatch("loadGroup")); |
|||
promises.push(this.dispatch("loadChat")); |
|||
promises.push(this.dispatch("loadConfig")); |
|||
return Promise.all(promises); |
|||
}) |
|||
}, |
|||
unload(context){ |
|||
context.commit("clear"); |
|||
} |
|||
}, |
|||
strict: true |
|||
}) |
|||
|
|||
export default store; |
|||
@ -1,44 +1,32 @@ |
|||
import {USER_STATE} from "../common/enums" |
|||
import { defineStore } from 'pinia'; |
|||
import http from '../common/request' |
|||
|
|||
|
|||
export default { |
|||
state: { |
|||
userInfo: {}, |
|||
config:{ |
|||
webrtc:{} |
|||
}, |
|||
state: USER_STATE.FREE |
|||
export default defineStore('userStore', { |
|||
state: () => { |
|||
return { |
|||
userInfo: {} |
|||
} |
|||
}, |
|||
|
|||
mutations: { |
|||
setUserInfo(state, userInfo) { |
|||
// 使用深拷贝方式,否则小程序页面不刷新
|
|||
Object.assign(state.userInfo, userInfo); |
|||
actions: { |
|||
setUserInfo(userInfo) { |
|||
this.userInfo = userInfo; |
|||
}, |
|||
setUserState(state, userState) { |
|||
state.state = userState; |
|||
clear() { |
|||
this.userInfo = {}; |
|||
}, |
|||
clear(state){ |
|||
state.userInfo = {}; |
|||
state.state = USER_STATE.FREE; |
|||
} |
|||
}, |
|||
actions:{ |
|||
loadUser(context){ |
|||
loadUser(context) { |
|||
return new Promise((resolve, reject) => { |
|||
http({ |
|||
url: '/user/self', |
|||
method: 'GET' |
|||
}).then((userInfo) => { |
|||
console.log(userInfo) |
|||
context.commit("setUserInfo",userInfo); |
|||
this.setUserInfo(userInfo); |
|||
resolve(); |
|||
}).catch((res)=>{ |
|||
}).catch((res) => { |
|||
reject(res); |
|||
}); |
|||
}) |
|||
} |
|||
} |
|||
|
|||
} |
|||
}) |
|||
Loading…
Reference in new issue