123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- import API from '@/api'
- const state = {
- sessionList: [],
- isLogin: true,
- toApp: false,
- friendList: []
- }
- const mutations = {
- setSessionList (state, data) {
-
- state.sessionList = data.sort((a, b) => {
- return b.is_pin - a.is_pin
- })
- },
- addSession (state, data) {
- state.sessionList.push(data)
- },
- chatAppLogin (state, flag) {
- state.isLogin = flag
- },
- toApp (state, flag) {
- state.toApp = flag
- },
- addSessionItem (state, data) {
- state.sessionList.unshift(data)
- },
- setFriendList (state, data) {
- state.friendList = data
- },
- setSessionItem (state, data) {
- state.sessionList.forEach(item => {
- if (item.session_id == data.session_id) {
- item = data
- }
- })
- },
-
- updateSessionListByPin (state, sessionId) {
- state.sessionList.forEach((item, index) => {
- if (item.session_id == sessionId) {
- state.sessionList.unshift(state.sessionList.splice(index, 1)[0])
- }
- })
- },
-
- cancelSessionListByPin (state, sessionId) {
- state.sessionList.forEach((item, index) => {
- if (item.session_id == sessionId) {
- state.sessionList.push(state.sessionList.splice(index, 1)[0])
- }
- })
- }
- }
- const actions = {
- async getSessionList ({ commit, state }, params) {
- try {
- let { data } = await API.session.sessionList()
- commit('setSessionList', data.data)
- } catch (error) {}
- },
- async getUserInfo ({ commit, state }) {
- try {
- let { data } = await API.user.getInfo()
- commit('setUserInfo', data.data)
- commit('setGroupUserInfo', data.data)
- } catch (error) {}
- },
-
- updateSessionItem ({ commit, state }, params) {
- let targetObj = state.sessionList.find(n => {
- return n.session_id == params.sessionId
- })
- targetObj = Object.assign(targetObj, params.data)
- commit('setSessionItem', targetObj)
- },
-
- async doRepealPersonMsg ({ dispatch, commit, state, rootState }, params = {}) {
- try {
- await API.person.repealPersonMsg({
- session_id: rootState.curSession,
- hash: params.hash
- })
- } catch (error) {}
- },
- async getFriendList ({ commit, state }) {
- try {
- let { data } = await API.group.getFriends()
- commit('setFriendList', data.data)
- } catch (error) {}
- }
- }
- export default {
- state,
- mutations,
- actions
- }
|