- Changed API base URLs in app.js to point to the production server for deployment. - Updated the my page UI by refining labels and removing unnecessary text for a cleaner look. - Adjusted CSS styles to enhance layout and reduce whitespace, improving overall user experience. This update aims to ensure proper API connectivity and enhance the visual presentation of the user interface.
182 lines
5.1 KiB
JavaScript
182 lines
5.1 KiB
JavaScript
/**
|
|
* Soul创业实验 - 自定义 TabBar
|
|
* 支持:首页 / 目录 / [找伙伴] / [动态,审核模式隐藏] / 我的
|
|
*/
|
|
|
|
const app = getApp()
|
|
|
|
Component({
|
|
data: {
|
|
selected: 0,
|
|
color: '#8e8e93',
|
|
selectedColor: '#00CED1',
|
|
matchEnabled: false,
|
|
tabList: [
|
|
{
|
|
pagePath: '/pages/index/index',
|
|
text: '首页',
|
|
iconPath: '/assets/icons/home.svg',
|
|
isSpecial: false,
|
|
},
|
|
{
|
|
pagePath: '/pages/chapters/chapters',
|
|
text: '目录',
|
|
iconPath: '/assets/icons/list.svg',
|
|
isSpecial: false,
|
|
},
|
|
{
|
|
pagePath: '/pages/super-moments/super-moments',
|
|
text: '动态',
|
|
iconPath: '/assets/icons/sparkles.svg',
|
|
isSpecial: false,
|
|
},
|
|
{
|
|
pagePath: '/pages/my/my',
|
|
text: '我的',
|
|
iconPath: '/assets/icons/user.svg',
|
|
isSpecial: false,
|
|
},
|
|
],
|
|
},
|
|
|
|
lifetimes: {
|
|
attached() {
|
|
this.loadFeatureConfig()
|
|
},
|
|
ready() {
|
|
if (this.data.matchEnabled === undefined || this.data.matchEnabled === null) {
|
|
this.loadFeatureConfig()
|
|
}
|
|
},
|
|
},
|
|
|
|
methods: {
|
|
buildTabList(matchEnabled, tabUi, auditMode) {
|
|
const audit = !!auditMode
|
|
const ui = tabUi || {}
|
|
const h = ui.home ? String(ui.home) : '首页'
|
|
const ch = ui.chapters ? String(ui.chapters) : '目录'
|
|
const ma = ui.match ? String(ui.match) : '找伙伴'
|
|
const mo = ui.moments ? String(ui.moments) : ui.feed ? String(ui.feed) : '动态'
|
|
const my = ui.my ? String(ui.my) : '我的'
|
|
const tabs = [
|
|
{
|
|
pagePath: '/pages/index/index',
|
|
text: h,
|
|
iconPath: '/assets/icons/home.svg',
|
|
isSpecial: false,
|
|
},
|
|
{
|
|
pagePath: '/pages/chapters/chapters',
|
|
text: ch,
|
|
iconPath: '/assets/icons/list.svg',
|
|
isSpecial: false,
|
|
},
|
|
]
|
|
if (matchEnabled) {
|
|
tabs.push({
|
|
pagePath: '/pages/match/match',
|
|
text: ma,
|
|
iconPath: '/assets/icons/partners.svg',
|
|
isSpecial: true,
|
|
})
|
|
}
|
|
if (!audit) {
|
|
tabs.push({
|
|
pagePath: '/pages/super-moments/super-moments',
|
|
text: mo,
|
|
iconPath: '/assets/icons/sparkles.svg',
|
|
isSpecial: false,
|
|
})
|
|
}
|
|
tabs.push({
|
|
pagePath: '/pages/my/my',
|
|
text: my,
|
|
iconPath: '/assets/icons/user.svg',
|
|
isSpecial: false,
|
|
})
|
|
return tabs
|
|
},
|
|
|
|
async loadFeatureConfig() {
|
|
try {
|
|
const res = await app.getConfig()
|
|
|
|
let matchEnabled = false
|
|
if (res && res.success && res.features) {
|
|
matchEnabled = res.features.matchEnabled === true
|
|
} else if (res && res.configs && res.configs.feature_config) {
|
|
matchEnabled = res.configs.feature_config.matchEnabled === true
|
|
}
|
|
|
|
const tabUi = app.globalData.configCache?.mpConfig?.mpUi?.tabBar || {}
|
|
try {
|
|
await app.getAuditMode()
|
|
} catch (_) {}
|
|
const auditMode = !!app.globalData.auditMode
|
|
const tabList = this.buildTabList(matchEnabled, tabUi, auditMode)
|
|
|
|
this.setData({ matchEnabled, tabList }, () => {
|
|
this.updateSelected()
|
|
})
|
|
|
|
if (!matchEnabled) {
|
|
const pages = getCurrentPages()
|
|
const currentPage = pages[pages.length - 1]
|
|
if (currentPage && currentPage.route === 'pages/match/match') {
|
|
wx.switchTab({ url: '/pages/index/index' })
|
|
}
|
|
}
|
|
|
|
if (auditMode) {
|
|
const pages = getCurrentPages()
|
|
const currentPage = pages[pages.length - 1]
|
|
if (currentPage && currentPage.route === 'pages/super-moments/super-moments') {
|
|
wx.switchTab({ url: '/pages/index/index' })
|
|
}
|
|
}
|
|
} catch (_) {
|
|
try {
|
|
await app.getAuditMode()
|
|
} catch (__) {}
|
|
const auditMode = !!app.globalData.auditMode
|
|
const tabList = this.buildTabList(false, {}, auditMode)
|
|
this.setData({ matchEnabled: false, tabList }, () => {
|
|
this.updateSelected()
|
|
})
|
|
if (auditMode) {
|
|
const pages = getCurrentPages()
|
|
const currentPage = pages[pages.length - 1]
|
|
if (currentPage && currentPage.route === 'pages/super-moments/super-moments') {
|
|
wx.switchTab({ url: '/pages/index/index' })
|
|
}
|
|
}
|
|
}
|
|
},
|
|
|
|
updateSelected() {
|
|
const pages = getCurrentPages()
|
|
if (pages.length === 0) return
|
|
const route = pages[pages.length - 1].route
|
|
const tabList = this.data.tabList || []
|
|
let selected = 0
|
|
for (let i = 0; i < tabList.length; i++) {
|
|
const p = tabList[i].pagePath.replace(/^\//, '')
|
|
if (route === p) {
|
|
selected = i
|
|
break
|
|
}
|
|
}
|
|
this.setData({ selected })
|
|
},
|
|
|
|
switchTab(e) {
|
|
const url = e.currentTarget.dataset.path
|
|
const index = Number(e.currentTarget.dataset.index)
|
|
if (Number.isNaN(index)) return
|
|
if (this.data.selected === index) return
|
|
wx.switchTab({ url })
|
|
},
|
|
},
|
|
})
|