【fix】优化代码

This commit is contained in:
黄少君
2024-02-22 18:37:23 +08:00
parent 17c043348a
commit f8fac0a5bc
246 changed files with 973 additions and 406 deletions

View File

@ -0,0 +1,32 @@
/**
* @name: globalRequestStore
* @author: kahu4
* @date: 2024-02-21 17:32
* @description公共方法
* @update: 2024-02-21 17:32
* */
import { defineStore } from "pinia";
import store from "@/store";
import { shareToAddIntegral } from "@/api/account/integral";
export const useGlobalRequestStore = defineStore('globalRequestStore', {
state: () => ({}),
getters: {},
actions: {
/**
* 分享商品获取积分
* @return {Promise<boolean>}
*/
async doShareToAddIntegral() {
try {
await shareToAddIntegral()
return true
} catch (e) {
return false
}
}
},
});
export const useGlobalRequestStoreWithOut = () => useGlobalRequestStore(store);

View File

@ -0,0 +1,80 @@
import { defineStore } from 'pinia'
import cookie from '@/utils/cookie'
import { getUserInfo } from '@/api/user'
import { getAddressCityList, getAddressList } from '@/api/address'
import { useRouter } from "@/hooks/useRouter";
import { getIntegralName } from "@/api/member";
import store from "@/store";
const {push} = useRouter()
export const useMainStore = defineStore('main', {
state: () => ({
user: null,
address: [],
areaList: [],
selectAddress: null,
moreLoading: true,
cartId: null,
integralName: '积分'
}),
getters: {
defaultAddress(state) {
return state.address?.filter(item => item.isDefault)?.[0]
},
},
actions: {
setAccessToken(user) {
cookie.set('accessToken', user)
return getUserInfo()
},
setSelectAddress(id) {
this.selectAddress = this.address.filter(item => item.id == id)[0]
},
async getUserInfo() {
let res = await getUserInfo()
this.user = res
return res
},
restAddress() {
this.address = []
this.moreLoading = true
},
clearSelectAddress() {
this.selectAddress = null
},
async getAddressList(page) {
let res = await getAddressList({page: page})
if (res.length) {
this.address = this.address.concat(res)
} else {
this.moreLoading = false
}
// console.log('--> % getUserInfo % res:\n', res)
},
async getAddressCityList() {
this.areaList = await getAddressCityList()
},
init() {
let accessToken = cookie.get('accessToken')
if (accessToken) {
return getUserInfo()
}
return null
},
logout() {
this.user = null
this.address = []
this.areaList = []
this.selectAddress = null
cookie.remove('accessToken')
push({url: '/pages/login/guid'}, {type: "redirectTo"})
},
async doGetIntegralName() {
this.integralName = await getIntegralName()
}
},
})
export const useMainStoreWithOut = () => useMainStore(store)