初始化
This commit is contained in:
7
src/mixins/index.ts
Normal file
7
src/mixins/index.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { App } from 'vue'
|
||||
import share from './share'
|
||||
import theme from './theme'
|
||||
import setTitle from './setTitle'
|
||||
export function setupMixin(app: App) {
|
||||
app.mixin(share).mixin(theme).mixin(setTitle)
|
||||
}
|
||||
8
src/mixins/setTitle.ts
Normal file
8
src/mixins/setTitle.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { useNavigationBarTitleStore } from '@/stores/navigationBarTitle'
|
||||
|
||||
export default {
|
||||
onShow() {
|
||||
const navigationBarTitleStore = useNavigationBarTitleStore()
|
||||
navigationBarTitleStore.setTitle()
|
||||
}
|
||||
}
|
||||
64
src/mixins/share.ts
Normal file
64
src/mixins/share.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
// #ifdef H5
|
||||
import wechatOa from '@/utils/wechat'
|
||||
// #endif
|
||||
|
||||
import { useRoute } from 'uniapp-router-next'
|
||||
import router from '@/router'
|
||||
import { useShareMessage } from '@/hooks/useShareMessage'
|
||||
|
||||
const onShareAppMessage = async () => {
|
||||
const { resolveOptions } = useShareMessage()
|
||||
const options = await resolveOptions()
|
||||
return options
|
||||
}
|
||||
const share = {
|
||||
onShow() {
|
||||
const route = useRoute()
|
||||
const { useShare } = useShareMessage()
|
||||
const menuList = [
|
||||
'menuItem:share:appMessage',
|
||||
'menuItem:share:timeline',
|
||||
'menuItem:share:qq',
|
||||
'menuItem:share:weiboApp',
|
||||
'menuItem:share:QZone'
|
||||
]
|
||||
if (!route.meta.share) {
|
||||
// 不允许分享的页面隐藏分享按钮
|
||||
// #ifdef MP-WEIXIN
|
||||
uni.hideShareMenu({
|
||||
hideShareItems: []
|
||||
})
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
wechatOa.hideMenuItems(menuList)
|
||||
// #endif
|
||||
} else {
|
||||
// 公众号隐藏分享按钮后切换页面需要调显示按钮api
|
||||
// #ifdef H5
|
||||
wechatOa.showMenuItems(menuList)
|
||||
useShare()
|
||||
// #endif
|
||||
}
|
||||
},
|
||||
// #ifdef MP-WEIXIN
|
||||
async onShareTimeline() {
|
||||
const { resolveOptions } = useShareMessage()
|
||||
const options = await resolveOptions()
|
||||
const route = router.currentRoute.value
|
||||
return {
|
||||
title: options.title,
|
||||
query: route.query,
|
||||
imageUrl: options.imageUrl
|
||||
}
|
||||
},
|
||||
async onShareAppMessage() {
|
||||
const { resolveOptions } = useShareMessage()
|
||||
const options = await resolveOptions()
|
||||
return options
|
||||
},
|
||||
onUnload() {
|
||||
share.onShareAppMessage = onShareAppMessage
|
||||
}
|
||||
// #endif
|
||||
}
|
||||
export default share
|
||||
18
src/mixins/theme.ts
Normal file
18
src/mixins/theme.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { useThemeStore } from '@/stores/theme'
|
||||
import { useAppStore } from '@/stores/app'
|
||||
|
||||
export default {
|
||||
computed: {
|
||||
$theme() {
|
||||
const themeStore = useThemeStore()
|
||||
const appStore = useAppStore()
|
||||
return {
|
||||
primaryColor: themeStore.primaryColor,
|
||||
pageStyle: themeStore.vars,
|
||||
navColor: themeStore.navColor,
|
||||
navBgColor: themeStore.navBgColor,
|
||||
title: appStore.getWebsiteConfig.shop_name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user