12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- const state = {
- currencies: [],
- loadingCurrencies: true,
- selectedCurrency: null
- }
- const getters = {
- currencies(state) {
- return state.currencies
- },
- loadingCurrencies(state) {
- return state.loadingCurrencies
- },
- currencySymbols(state) {
- if (!state.currencies || !state.selectedCurrency) {
- return []
- }
- return state.currencies.filter(c => state.selectedCurrency.id !== c.id).map(c => c.symbol)
- },
- baseCurrency(state) {
- return state.currencies.find(c => c.base === true)
- },
- selectedCurrency(state) {
- return state.selectedCurrency
- },
- selectedCurrencySymbol(state) {
- return state.selectedCurrency && state.selectedCurrency.symbol
- }
- }
- const mutations = {
- setCurrencies(state, payload) {
- state.currencies = [...payload]
- },
- setLoadingCurrencies(state, payload) {
- state.loadingCurrencies = !!payload
- },
- autoSelectCurrency(state) {
- state.selectedCurrency = state.currencies.find(item => item.base == true)
- }
- }
- const actions = {
- initCurrencies({ commit }, payload) {
- commit('setCurrencies', payload)
- commit('autoSelectCurrency')
- commit('setLoadingCurrencies', false)
- },
- resetCurrency({ commit }, payload) {
- commit('setLoadingCurrencies', true)
- commit('setCurrencies', [])
- }
- }
- export default {
- state,
- getters,
- mutations,
- actions
- }
|