1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
| import { isArray } from "/@/cool/utils";
|
| const state = {
| list: []
| };
|
| const getters = {
| messageList: (state: any) => state.list
| };
|
| const actions = {};
|
| const mutations = {
| // 设置列表
| SET_MESSAGE_LIST(state: any, data: any[]) {
| state.list = data;
| },
|
| // 追加数据
| APPEND_MESSAGE_LIST(state: any, data: any) {
| state.list.push(data);
| },
|
| // 追加数据到头部
| PREPEND_MESSAGE_LIST(state: any, data: any) {
| const list = isArray(data) ? data : [data];
| state.list.unshift(...list.reverse());
| },
|
| // 清空列表
| CLEAR_MESSAGE_LIST(state: any) {
| state.list = [];
| },
|
| // 更新消息数据
| UPDATE_MESSAGE(state: any, { file, data, callback }: any) {
| let item = null;
|
| if (file) {
| item = state.list.find((e: any) => e.uid === file.uid);
| }
|
| if (item) {
| if (data) {
| Object.assign(item, data);
| }
|
| if (callback) callback(item);
| }
| }
| };
|
| export default {
| state,
| getters,
| actions,
| mutations
| };
|
|