| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- import { defineStore } from "pinia";
- import { SHOP_CART_LIST, SHOP_ORDER_STATUS, CONTENT_FLOAT, SHOP_ADDRESS_LIST } from "@/api";
- import { setStorage, getStorage } from '@/utils'
- const state = () => ({
- cartList: [],
- cartNum: 0,
- orderStatus: [],
- hotLink: [],
- addressList: [],
- logistics: {},
- tabParams: null
- })
- export const useShopStore = defineStore('shop', {
- state,
- getters: {
- getCartList() {
- return this.cartList
- },
- getCartNum() {
- return this.cartNum
- },
- getOrderStatus() {
- return this.orderStatus
- },
- getHotLink() {
- // if (!this.hotLink.length) {
- // this.setHotLink();
- // }
- return this.hotLink || [];
- },
- getAddressList() {
- return this.addressList || [];
- },
- getLogistics() {
- return this.logistics || {}
- },
- getTabParams() {
- return this.tabParams || null
- }
- },
- actions: {
- async setCartList(is_free) {
- try {
- const { data: { list = [], cartCount = 0 } } = await SHOP_CART_LIST(is_free);
- this.cartList = list || [];
- this.cartNum = cartCount;
- } catch (error) { }
- },
- setCartNum(_num_) {
- this.cartNum = _num_
- },
- async setOrderStatus() {
- try {
- const res = await SHOP_ORDER_STATUS();
- let arr = Object.entries(res.data).map(([key, value]) => ({
- status: key,
- value: value
- }));
- this.orderStatus = arr
- } catch (error) { }
- },
- async setHotLink() {
- try {
- const res = await CONTENT_FLOAT({
- type: 'image-text',
- posititon: 'search'
- })
- this.hotLink = res.data
- } catch (error) { }
- },
- async setAddressList() {
- try {
- const res = await SHOP_ADDRESS_LIST()
- this.addressList = res.data
- } catch (error) { }
- },
- setLogistics(data) {
- this.logistics = data
- },
- setTabParams(params) {
- this.tabParams = params;
- }
- }
- })
|