新增
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { getConfig } from '@/api/app'
|
||||
|
||||
interface AppSate {
|
||||
config: Record<string, any>
|
||||
}
|
||||
export const useAppStore = defineStore({
|
||||
id: 'appStore',
|
||||
state: (): AppSate => ({
|
||||
config: {
|
||||
domain: ''
|
||||
}
|
||||
}),
|
||||
getters: {
|
||||
getWebsiteConfig: (state) => state.config.website || {},
|
||||
getLoginConfig: (state) => state.config.login || {},
|
||||
getTabbarConfig: (state) => state.config.tabbar || [],
|
||||
getStyleConfig: (state) => state.config.style || {},
|
||||
getH5Config: (state) => state.config.webPage || {},
|
||||
getCopyrightConfig: (state) => state.config.copyright || [],
|
||||
},
|
||||
actions: {
|
||||
getImageUrl(url: string) {
|
||||
return url.indexOf('http') ? `${this.config.domain}${url}` : url
|
||||
},
|
||||
async getConfig() {
|
||||
const data = await getConfig()
|
||||
this.config = data
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,54 @@
|
||||
import { getDecorate } from '@/api/shop'
|
||||
import { generateVars } from '@/utils/theme'
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
interface ThemeStore {
|
||||
primaryColor: string
|
||||
minorColor: string
|
||||
btnColor: string
|
||||
navColor: string
|
||||
navBgColor: string
|
||||
vars: string
|
||||
}
|
||||
export const useThemeStore = defineStore({
|
||||
id: 'themeStore',
|
||||
state: (): ThemeStore => ({
|
||||
primaryColor: '',
|
||||
minorColor: '',
|
||||
btnColor: 'white',
|
||||
navColor: '#000000',
|
||||
navBgColor: '#ffffff',
|
||||
vars: ''
|
||||
}),
|
||||
actions: {
|
||||
async getTheme() {
|
||||
const data = await getDecorate({
|
||||
id: 5
|
||||
})
|
||||
const {
|
||||
themeColor1,
|
||||
themeColor2,
|
||||
buttonColor,
|
||||
navigationBarColor,
|
||||
topTextColor
|
||||
} = JSON.parse(data.data)
|
||||
this.primaryColor = themeColor1
|
||||
this.minorColor = themeColor2
|
||||
this.btnColor = buttonColor
|
||||
this.navColor = topTextColor === 'white' ? '#ffffff' : '#000000'
|
||||
this.navBgColor = navigationBarColor || themeColor1
|
||||
this.vars = generateVars(
|
||||
{
|
||||
primary: themeColor1
|
||||
},
|
||||
{
|
||||
'--color-minor': themeColor2,
|
||||
'--color-btn-text': buttonColor
|
||||
}
|
||||
)
|
||||
},
|
||||
setTheme(color: string) {
|
||||
this.primaryColor = color
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,38 @@
|
||||
import { getUserCenter } from '@/api/user'
|
||||
import { TOKEN_KEY } from '@/enums/constantEnums'
|
||||
import cache from '@/utils/cache'
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
interface UserSate {
|
||||
userInfo: Record<string, any>
|
||||
token: string | null
|
||||
temToken: string | null
|
||||
}
|
||||
export const useUserStore = defineStore({
|
||||
id: 'userStore',
|
||||
state: (): UserSate => ({
|
||||
userInfo: {},
|
||||
token: cache.get(TOKEN_KEY) || null,
|
||||
temToken: null
|
||||
}),
|
||||
getters: {
|
||||
isLogin: (state) => !!state.token
|
||||
},
|
||||
actions: {
|
||||
async getUser() {
|
||||
const data = await getUserCenter({
|
||||
token: this.token || this.temToken
|
||||
})
|
||||
this.userInfo = data
|
||||
},
|
||||
login(token: string) {
|
||||
this.token = token
|
||||
cache.set(TOKEN_KEY, token)
|
||||
},
|
||||
logout() {
|
||||
this.token = ''
|
||||
this.userInfo = {}
|
||||
cache.remove(TOKEN_KEY)
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user