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' |
import http from '../common/request' |
||||
|
|
||||
export default { |
export default defineStore('configStore', { |
||||
state: { |
state: () => { |
||||
|
return { |
||||
webrtc: {} |
webrtc: {} |
||||
|
} |
||||
}, |
}, |
||||
mutations: { |
actions: { |
||||
setConfig(state, config) { |
setConfig(config) { |
||||
state.webrtc = config.webrtc; |
this.webrtc = config.webrtc; |
||||
}, |
}, |
||||
clear(state){ |
clear() { |
||||
state.webrtc = {}; |
this.webrtc = {}; |
||||
} |
|
||||
}, |
}, |
||||
actions:{ |
loadConfig() { |
||||
loadConfig(context){ |
|
||||
return new Promise((resolve, reject) => { |
return new Promise((resolve, reject) => { |
||||
http({ |
http({ |
||||
url: '/system/config', |
url: '/system/config', |
||||
method: 'GET' |
method: 'GET' |
||||
}).then((config) => { |
}).then((config) => { |
||||
console.log("系统配置",config) |
console.log("系统配置", config) |
||||
context.commit("setConfig",config); |
this.setConfig(config); |
||||
resolve(); |
resolve(); |
||||
}).catch((res)=>{ |
}).catch((res) => { |
||||
reject(res); |
reject(res); |
||||
}); |
}); |
||||
}) |
}) |
||||
} |
} |
||||
} |
} |
||||
|
}) |
||||
} |
|
||||
@ -1,57 +1,58 @@ |
|||||
|
import { defineStore } from 'pinia'; |
||||
import http from '@/common/request'; |
import http from '@/common/request'; |
||||
|
|
||||
export default { |
export default defineStore('groupStore', { |
||||
state: { |
state: () => { |
||||
|
return { |
||||
groups: [], |
groups: [], |
||||
activeIndex: -1, |
activeIndex: -1 |
||||
|
} |
||||
}, |
}, |
||||
mutations: { |
actions: { |
||||
setGroups(state, groups) { |
setGroups(groups) { |
||||
state.groups = groups; |
this.groups = groups; |
||||
}, |
}, |
||||
activeGroup(state, index) { |
activeGroup(index) { |
||||
state.activeIndex = index; |
this.activeIndex = index; |
||||
}, |
}, |
||||
addGroup(state, group) { |
addGroup(group) { |
||||
state.groups.unshift(group); |
this.groups.unshift(group); |
||||
}, |
}, |
||||
removeGroup(state, groupId) { |
removeGroup(groupId) { |
||||
state.groups.forEach((g, index) => { |
this.groups.forEach((g, index) => { |
||||
if (g.id == groupId) { |
if (g.id == groupId) { |
||||
state.groups.splice(index, 1); |
this.groups.splice(index, 1); |
||||
if (state.activeIndex >= state.groups.length) { |
if (this.activeIndex >= this.groups.length) { |
||||
state.activeIndex = state.groups.length - 1; |
this.activeIndex = this.groups.length - 1; |
||||
} |
} |
||||
} |
} |
||||
}) |
}) |
||||
|
|
||||
}, |
}, |
||||
updateGroup(state, group) { |
updateGroup(group) { |
||||
state.groups.forEach((g, idx) => { |
let g = this.findGroup(group.id); |
||||
if (g.id == group.id) { |
Object.assign(g, group); |
||||
// 拷贝属性
|
|
||||
Object.assign(state.groups[idx], group); |
|
||||
} |
|
||||
}) |
|
||||
}, |
}, |
||||
clear(state){ |
clear() { |
||||
state.groups = []; |
this.groups = []; |
||||
state.activeGroup = -1; |
this.activeGroup = -1; |
||||
} |
|
||||
}, |
}, |
||||
actions: { |
loadGroup() { |
||||
loadGroup(context) { |
|
||||
return new Promise((resolve, reject) => { |
return new Promise((resolve, reject) => { |
||||
http({ |
http({ |
||||
url: '/group/list', |
url: '/group/list', |
||||
method: 'GET' |
method: 'GET' |
||||
}).then((groups) => { |
}).then((groups) => { |
||||
context.commit("setGroups", groups); |
this.setGroups(groups); |
||||
resolve(); |
resolve(); |
||||
}).catch((res) => { |
}).catch((res) => { |
||||
reject(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' |
import http from '../common/request' |
||||
|
|
||||
|
export default defineStore('userStore', { |
||||
export default { |
state: () => { |
||||
state: { |
return { |
||||
userInfo: {}, |
userInfo: {} |
||||
config:{ |
} |
||||
webrtc:{} |
|
||||
}, |
|
||||
state: USER_STATE.FREE |
|
||||
}, |
|
||||
|
|
||||
mutations: { |
|
||||
setUserInfo(state, userInfo) { |
|
||||
// 使用深拷贝方式,否则小程序页面不刷新
|
|
||||
Object.assign(state.userInfo, userInfo); |
|
||||
}, |
}, |
||||
setUserState(state, userState) { |
actions: { |
||||
state.state = userState; |
setUserInfo(userInfo) { |
||||
|
this.userInfo = userInfo; |
||||
}, |
}, |
||||
clear(state){ |
clear() { |
||||
state.userInfo = {}; |
this.userInfo = {}; |
||||
state.state = USER_STATE.FREE; |
|
||||
} |
|
||||
}, |
}, |
||||
actions:{ |
loadUser(context) { |
||||
loadUser(context){ |
|
||||
return new Promise((resolve, reject) => { |
return new Promise((resolve, reject) => { |
||||
http({ |
http({ |
||||
url: '/user/self', |
url: '/user/self', |
||||
method: 'GET' |
method: 'GET' |
||||
}).then((userInfo) => { |
}).then((userInfo) => { |
||||
console.log(userInfo) |
console.log(userInfo) |
||||
context.commit("setUserInfo",userInfo); |
this.setUserInfo(userInfo); |
||||
resolve(); |
resolve(); |
||||
}).catch((res)=>{ |
}).catch((res) => { |
||||
reject(res); |
reject(res); |
||||
}); |
}); |
||||
}) |
}) |
||||
} |
} |
||||
} |
} |
||||
|
}) |
||||
} |
|
||||
Loading…
Reference in new issue