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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
| import { getStorage, setStorage, changeTheme } from "@/utils/utis";
| import {
| SET_COIN_LIST,
| SET_CURRENCY,
| SET_COIN_SYMBOL_ARR,
| SET_KEFU,
| SET_THEME,
| } from "@/store/const.store";
| import { _getCoins, _getExchangeRate, itemlist } from "@/API/home.api";
| import { customer } from "@/API/user.api";
|
| export default {
| namespaced: true,
| state: {
| currency: {}, // 当前汇率
| coinArr: [], // 解构出来的币种数组
| hotArr: [], // 热门币种
| newcoinArr: [], // 热门币种
| coinList: [], // 品种
| kefu_url: "",
| theme: "light",
| },
| getters: {
| coinList: (state) => state.coinList,
| coinArr: (state) => state.coinArr,
| hotArr: (state) => state.hotArr,
| newcoinArr: (state) => state.newcoinArr,
| currency: (state) => state.currency,
| kefu_url: (state) => state.kefu_url,
| theme: (state) => state.theme,
| },
| mutations: {
| [SET_THEME]: (state, theme) => {
| state.theme = theme;
| window.document.documentElement.setAttribute("data-theme", theme);
| changeTheme(theme);
| setStorage("theme", theme);
| },
| [SET_COIN_LIST](state, list) {
| state.coinList = list;
| },
| [SET_CURRENCY](state, currency) {
| state.currency = currency;
| },
| SET_NEW_CION_LIST(state, currency) {
| const arr = [];
| currency?.map((item) => {
| arr.push(item.tokenCode);
| });
|
| state.newcoinArr = arr;
| },
|
| [SET_COIN_SYMBOL_ARR](state, list) {
| const arr = [];
| const hots = [];
| list.map((item) => {
| arr.push(item.symbol);
| if (item.isTop === "1") {
| // 热门
| hots.push(item.symbol);
| }
| });
| console.log(arr, "===");
| state.coinArr = arr;
| state.hotArr = hots;
| },
| [SET_KEFU](state, url) {
| state.kefu_url = url;
| },
| },
| actions: {
| async [SET_COIN_LIST]({ commit, state }) {
| // 获取配置的币种
|
| const list = await _getCoins().catch((err) => {
| Promise.reject(err);
| });
| commit(SET_COIN_SYMBOL_ARR, list); // 原数据
| commit(SET_COIN_LIST, list); // 拆分的单个数据
| Promise.resolve(list);
| },
| async NEW_CION_LIST({ commit, state }) {
| // 获取配置的币种
|
| const list = await itemlist().catch((err) => {
| Promise.reject(err);
| });
|
| commit("SET_NEW_CION_LIST", list); // 拆分的单个数据
| Promise.resolve(list);
| },
| async [SET_CURRENCY]({ commit, state, rootState }) {
| // 设置汇率
| console.log("rootState", rootState);
| const currency = await _getExchangeRate({
| token: rootState.user.userInfo.token,
| }).catch((err) => Promise.reject(err));
| commit(SET_CURRENCY, currency);
| },
| actionsToken({ commit }, data) {
| commit("SET_TOKEN", data);
| },
| actionsStatus({ commit }, data) {
| commit("SET_STATUS", data);
| },
| async [SET_KEFU]({ commit, state, rootState }) {
| // 设置汇率
|
| const data = await customer().catch((err) => Promise.reject(err));
| let url = data.customer_service_url;
| commit(SET_KEFU, url);
| },
| },
| };
|
|