diff --git a/app.js b/app.js index c40f249..56eef3a 100644 --- a/app.js +++ b/app.js @@ -1,99 +1,21 @@ -//app.js +// zooble@2025-12-14 +const { createRequest } = require('./utils/request.js'); + App({ - async onLaunch () { - this.login(); - // 移除 2022-12-05 之前的本地存储,因为可能有敏感词存在 - const timestamp = new Date('2022-12-05').getTime(); - const audioList = this.globalData.getAudioList().filter(v => v.time > timestamp); - const storageKey = 'audioList'; - wx.setStorageSync(storageKey, audioList); - }, - // 将登录态封装进去 - // todo: 多个请求同时发起,且登录态都失效时,ssid 会相互覆盖 - async request(config){ - let ssid = wx.getStorageSync('ssid'); - if(!ssid){ - ssid = await this.login(); - } - const initialSuccess = config.success; - config.data = { - ...config.data, - ssid - }; - config.success = async resp => { - if(resp.data.code === 5001000){ - wx.setStorageSync('ssid', ''); - delete config.ssid; - this.request(config); - } - else{ - initialSuccess(resp); - } - }; - config = { - header: { - 'content-type': 'application/json' - }, - dataType: 'json', - method: 'POST', - ...config - }; - return wx.request(config); - }, - login(){ - let ssid = wx.getStorageSync('ssid'); - if(ssid){ - return ssid; - } - wx.showLoading({ - title: '登录中...', - mask: true - }); - return new Promise((resolve, reject) => { - wx.login({ - success: res => { - wx.request({ - url: `${this.globalData.domain}/open-api/mp/login`, - data: { - code: res.code, - appid: 'wx330e54aa6000516d' - }, - header: { - 'content-type': 'application/json' - }, - dataType: 'json', - method: 'POST', - success: resp => { - const { - ssid, - openid - } = resp.data?.data?.user; - wx.setStorageSync('ssid', ssid); - wx.setStorageSync('openid', openid); - resolve(ssid); - }, - fail: resp => { - wx.showModal({ - title: '提示', - content: '登录失败,点击确定重试', - showCancel: false, - success: res => { - this.login(); - } - }); - reject(resp.errMsg); - }, - complete: () => { - wx.hideLoading(); - } - }); - } - }); - }); - }, globalData: { // domain: 'http://localhost:3003', domain: 'https://api.xwenliang.cn', + appid: 'wx330e54aa6000516d', + cid: '', + safeAreaTop: 0, + safeAreaBottom: 0, + statusBarHeight: 0, + navBarHeight: 0, + totalNavHeight: 0, // 导航栏总高度(状态栏 + 导航栏) + tabBarHeight: 56, + totalTabBarHeight: 0, // tab总高度(tab + 底部安全区) + contentHeight: 0, // 内容区域高度(全屏高度 - 导航栏总高度 - 底部安全区) + contentWithoutTabbarHeight: 0, // 内容区域高度 - tab 高度 getTypeList(){ const globalData = this; return [ @@ -148,6 +70,29 @@ App({ } ]; }, + onLaunch(option){ + const { query } = option; + // 获取渠道值 + this.globalData.cid = query.cid || ''; + // 挂载 request + const { domain, appid, cid } = this.globalData; + this.request = createRequest({ domain, appid, cid }); + + // 获取系统信息,计算安全区域 + const windowInfo = wx.getWindowInfo ? wx.getWindowInfo() : wx.getSystemInfoSync(); + const { statusBarHeight, safeArea, windowHeight, screenHeight } = windowInfo; + this.globalData.statusBarHeight = statusBarHeight; + this.globalData.safeAreaTop = safeArea.top; + this.globalData.safeAreaBottom = screenHeight - safeArea.bottom; + // 右上角胶囊位置信息 + const menuButtonInfo = wx.getMenuButtonBoundingClientRect(); + // 导航栏高度,是胶囊以及胶囊的上下边距所包含的高度,通常是 32+4+4 + this.globalData.navBarHeight = menuButtonInfo.height + (menuButtonInfo.top - statusBarHeight) * 2; + this.globalData.totalNavHeight = statusBarHeight + this.globalData.navBarHeight; + this.globalData.contentHeight = windowHeight - this.globalData.totalNavHeight; + this.globalData.totalTabBarHeight = this.globalData.tabBarHeight + this.globalData.safeAreaBottom; + this.globalData.contentWithoutTabbarHeight = this.globalData.contentHeight - this.globalData.totalTabBarHeight; + }, // TTS接口请求方法 async requestTTS(text, voice) { return new Promise((resolve, reject) => { @@ -201,8 +146,8 @@ App({ return wx.getStorageSync(storageKey) || []; }, /** - * @param {(add|delete)} action - 增或删 - * @param {object|number} [param] - 增加时是 audio 描述,删除时是唯一特征 path 值 + * @param {(add|delete)} action - 增或删 + * @param {object|number} [param] - 增加时是 audio 描述,删除时是唯一特征 path 值 */ setAudioList(action, param){ const storageKey = 'audioList'; diff --git a/app.json b/app.json index 5dacca9..cf3e0b4 100644 --- a/app.json +++ b/app.json @@ -7,7 +7,8 @@ "backgroundTextStyle": "light", "navigationBarBackgroundColor": "#fff", "navigationBarTitleText": "文字转语音", - "navigationBarTextStyle": "black" + "navigationBarTextStyle": "black", + "navigationStyle": "custom" }, "sitemapLocation": "sitemap.json" } \ No newline at end of file diff --git a/app.wxss b/app.wxss index 2ca0051..9105d95 100644 --- a/app.wxss +++ b/app.wxss @@ -1,4 +1,54 @@ /**app.wxss**/ +page { + height: 100%; + background: #D7E5FA; + background-image: url(https://gallery.xwenliang.cn/miniprogram/2025-11-13-ea3e6a30ac.jpg); + background-position: top center; + background-size: 100% auto; + background-repeat: no-repeat; + overflow: hidden; + width: 100%; + height: 100%; +} + +.container-custom { + width: 100%; + height: 100%; + display: flex; + flex-direction: column; + box-sizing: border-box; + overflow-x: hidden; + background-repeat: no-repeat; +} + +.container-default { + width: 100%; + height: 100%; + display: flex; + flex-direction: column; + overflow-x: hidden; +} + +.container-default-box { + width: 100%; + overflow-x: hidden; + overflow-y: auto; + box-sizing: border-box; + padding: 0 8px; +} + +/* 全局安全区域样式类 */ +.safe-area-top { + padding-top: constant(safe-area-inset-top); + padding-top: env(safe-area-inset-top); +} + +.safe-area-bottom { + padding-bottom: constant(safe-area-inset-bottom); + padding-bottom: env(safe-area-inset-bottom); +} + +/* 保留原有的 container 类以兼容其他页面 */ .container { width: 100%; height: 100%; diff --git a/pages/index/index.wxml b/pages/index/index.wxml index 3c364f9..7c6a0c7 100644 --- a/pages/index/index.wxml +++ b/pages/index/index.wxml @@ -1,5 +1,10 @@ - + + + + + +