CounterFireGames/src/store/marketplace.js
2024-06-28 19:07:29 +08:00

105 lines
2.4 KiB
JavaScript

import { defineStore } from 'pinia';
import { ref, toRaw, computed } from 'vue';
import { apiMarketplaceState, apiGetCartList, apiAddCartList, apiDelCartList } from "@/utils/marketplace"
export const useMarketplaceStore = defineStore('marketplace', () => {
const overview = ref('')
const sort = ref()
const minPrice = ref()
const maxPrice = ref()
const hero = ref([])
const rank = ref([])
const gold = ref([])
const status = ref([])
const getCartList = ref([])
const currencyPrice = ref([])
//TODO:: 根据实际情况修改该值
const getParamsData = ref({
page_size: 20, // 每页大小
cursor: '', // 游标
search: {
name: '', // 名字查询
},
filter: {
price_min: '', // 最低价
price_max: '', // 最高价
item_ids: [], // 道具ID
hero_ranks: [] // 品阶
},
sort: {
fields: [
{
name: '',
type: 0,
}
]
}
})
const updateOverviewStatus = (_connected) => {
overview.value = _connected;
}
const updateSortStatus = (_connected) => {
sort.value = _connected;
}
const updateMinPriceStatus = (_connected) => {
minPrice.value = _connected;
}
const updateMaxPriceStatus = (_connected) => {
maxPrice.value = _connected;
}
const updateHeroStatus = (_connected) => {
hero.value = _connected;
}
const updateRankStatus = (_connected) => {
rank.value = _connected;
}
const updateGoldStatus = (_connected) => {
gold.value = _connected;
}
const updateStatusStatus = (_connected) => {
status.value = _connected;
}
const priceDatas = computed(() => {
return toRaw(currencyPrice.value)
})
async function getMarketplaceState(_connected) {
return await apiMarketplaceState(_connected)
}
async function getCartListState() {
return await apiGetCartList()
}
async function addCartListState(_connected) {
return await apiAddCartList(_connected)
}
async function delCartListState(_connected) {
return await apiDelCartList(_connected)
}
return {
getParamsData,
overview, updateOverviewStatus,
sort, updateSortStatus,
minPrice, updateMinPriceStatus,
maxPrice, updateMaxPriceStatus,
hero, updateHeroStatus,
rank, updateRankStatus,
gold, updateGoldStatus,
status, updateStatusStatus,
getMarketplaceState,
getCartList, getCartListState,
addCartListState,
delCartListState,
currencyPrice,priceDatas,
}
},
{
persist: true,
}
)