Files
boursecu_user/src/store/walletStore.ts
T
2026-01-18 13:01:46 +03:30

59 lines
1.7 KiB
TypeScript

import { type ComputedRef, ref } from 'vue'
import {defineStore} from "pinia";
import {getMe} from "@/api/me";
import type {User} from "@/models/login";
import type {Wallet} from "@/models/wallet";
import {getWallet} from "@/api/wallet";
import type {Const} from "@/models/const";
import {getConstByKey} from "@/api/const";
export const useWalletStore = defineStore('wallet', () => {
const walletInfo = ref<Wallet | undefined>(undefined)
const limitedPrice = ref<Const[]>()
const limitedBuyGold = ref<Const[]>()
async function getMyWallet() {
try {
walletInfo.value = await getWallet()
return walletInfo.value
} catch (e) {
console.log(e)
}
}
async function getLimitedPrice(){
try {
limitedPrice.value = await getConstByKey('limited_price')
return limitedPrice.value
}catch (e) {
console.log(e)
}
}
async function getLimitedBuyGold(){
try {
limitedBuyGold.value = await getConstByKey('first_customer_wallet_value')
return limitedBuyGold.value
}catch (e) {
console.log(e)
}
}
/* const permissions: ComputedRef<string[]> = computed(() => {
const permissions: string[] = get(userInfo.value, 'permission', [])
const excludes: string[] = get(userInfo.value, 'exclude', [])
return permissions.filter((item) => !excludes.includes(item))
})*/
/*
function canAccess(permissionKey: string) {
if (isAdmin.value) return true
return permissions.value.includes(permissionKey)
}
*/
/*
const isAdmin = computed(() => {
return userInfo.value?.is_admin
})*/
return { walletInfo, getMyWallet, getLimitedPrice, getLimitedBuyGold, limitedPrice, limitedBuyGold/* permissions, canAccess, isAdmin*/ }
})