shopInfo.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { defineStore } from 'pinia'
  2. import { Profile } from '/@/components/shopSelector/types'
  3. import { request } from '../utils/service'
  4. import { ref, Ref } from 'vue'
  5. import { Session } from '/@/utils/storage';
  6. export const useShopInfo = defineStore('shopInfo', () => {
  7. const profile: Ref<Profile> = ref({
  8. id: 0,
  9. profile_id: "",
  10. account_name: "",
  11. time_zone: "",
  12. advertiser_id: "",
  13. country_code: "",
  14. currency_code: "",
  15. currency_symbol: "",
  16. marketplace_str_id: ""
  17. })
  18. function updateShopInfo(obj: Profile) {
  19. profile.value.id = obj.id
  20. profile.value.profile_id = obj.profile_id
  21. profile.value.account_name = obj.account_name
  22. profile.value.time_zone = obj.time_zone
  23. profile.value.advertiser_id = obj.advertiser_id
  24. profile.value.country_code = obj.country_code
  25. profile.value.currency_code = obj.currency_code
  26. profile.value.currency_symbol = obj.currency_symbol
  27. profile.value.marketplace_str_id = obj.marketplace_str_id
  28. Session.set('shopInfo', profile.value);
  29. }
  30. async function reqShopInfo() {
  31. return request({
  32. url: '/api/ad_manage/profiles/',
  33. method: 'GET',
  34. params: { limit: 1 }
  35. })
  36. }
  37. async function initShopInfo() {
  38. const data = Session.get('shopInfo')
  39. if (data?.profile_id) {
  40. profile.value = data
  41. } else {
  42. const resp: any = await reqShopInfo();
  43. updateShopInfo(resp.data[0])
  44. }
  45. }
  46. return { profile, updateShopInfo, initShopInfo }
  47. })