const memoryCards = require('../../data/memoryCards') const { getProgress } = require('../../utils/storage') const { getCollectedMemories } = require('../../utils/memoryCollection') const { chapterRoute } = require('../../utils/chapterRoute') const { getHomeLayoutMetrics, getHomeLayoutStyle, hasReadingProgress, } = require('./homeLayout') Page({ data: { coverOpened: false, completedCount: 0, lastChapter: 1, hasReadingProgress: false, memoryCount: 0, homeLayoutStyle: [ 'height:390px', '--home-top-inset:8px', '--home-right-inset:10px', '--home-bottom-inset:7px', '--home-left-inset:10px', ].join(';'), }, onLoad() { this.applyHomeLayout() }, onShow() { const progress = getProgress() this.setData({ completedCount: progress.completedChapters.length, lastChapter: progress.lastChapter || 1, hasReadingProgress: hasReadingProgress(progress), memoryCount: getCollectedMemories(progress, memoryCards).length, }) this.applyHomeLayout() }, onResize(resizeInfo) { this.applyHomeLayout(resizeInfo) }, applyHomeLayout(resizeInfo = null) { let windowInfo = {} try { windowInfo = wx.getWindowInfo ? wx.getWindowInfo() : wx.getSystemInfoSync() } catch (error) { windowInfo = {} } const resizeSize = resizeInfo && resizeInfo.size ? resizeInfo.size : resizeInfo if (resizeSize) { windowInfo = { ...windowInfo, windowWidth: resizeSize.windowWidth || windowInfo.windowWidth, windowHeight: resizeSize.windowHeight || windowInfo.windowHeight, } } let menuRect = {} try { menuRect = wx.getMenuButtonBoundingClientRect ? wx.getMenuButtonBoundingClientRect() : {} } catch (error) { menuRect = {} } const metrics = getHomeLayoutMetrics(windowInfo, menuRect) this.setData({ homeLayoutStyle: getHomeLayoutStyle(metrics), }) }, startGame() { const chapter = this.data.lastChapter || 1 wx.navigateTo({ url: chapterRoute(chapter), }) }, revealCover() { if (this.data.coverOpened) return this.setData({ coverOpened: true }) }, keepCoverOpen() {}, openCatalog() { wx.navigateTo({ url: '/pages/catalog/catalog' }) }, openCast() { wx.navigateTo({ url: '/pages/cast/cast' }) }, openMemories() { wx.navigateTo({ url: '/pages/memories/memories' }) }, onShareAppMessage() { return { title: '唐侦探:在一桌饭里,看见被忽略的人', path: '/pages/home/home', } }, onShareTimeline() { return { title: '唐侦探:在一桌饭里,看见被忽略的人', query: '', } }, })