139 lines
3.7 KiB
JavaScript
139 lines
3.7 KiB
JavaScript
|
|
Page({
|
||
|
|
data: {
|
||
|
|
// 系统信息
|
||
|
|
statusBarHeight: 0,
|
||
|
|
navbarHeight: 0,
|
||
|
|
menuButtonInfo: { height: 32, width: 32, top: 0 },
|
||
|
|
// 字体大小相关
|
||
|
|
fontSizeValue: 16, // 默认字体大小
|
||
|
|
previewFontSize: 16, // 预览区域字体大小
|
||
|
|
currentFontSize: 'small', // 当前字体大小
|
||
|
|
activeDotIndex: 1 // 默认字体为第二个位置
|
||
|
|
},
|
||
|
|
|
||
|
|
/* 监听页面加载 */
|
||
|
|
onLoad: function (options) {
|
||
|
|
// 获取系统信息
|
||
|
|
this.getSystemInfo();
|
||
|
|
// 加载字体设置
|
||
|
|
this.loadCurrentFontSize();
|
||
|
|
},
|
||
|
|
|
||
|
|
/* 获取系统信息 */
|
||
|
|
getSystemInfo: function() {
|
||
|
|
const systemInfo = wx.getSystemInfoSync();
|
||
|
|
const menuButtonInfo = wx.getMenuButtonBoundingClientRect();
|
||
|
|
|
||
|
|
this.setData({
|
||
|
|
statusBarHeight: systemInfo.statusBarHeight,
|
||
|
|
navbarHeight: menuButtonInfo.height + (menuButtonInfo.top - systemInfo.statusBarHeight) * 2,
|
||
|
|
menuButtonInfo: menuButtonInfo
|
||
|
|
});
|
||
|
|
},
|
||
|
|
|
||
|
|
/* 加载用字体设置 */
|
||
|
|
loadCurrentFontSize: function() {
|
||
|
|
try {
|
||
|
|
// 获取聊天设置
|
||
|
|
const chatSettings = wx.getStorageSync('chatSettings') || {};
|
||
|
|
const fontSizeValue = chatSettings.fontSizeValue || 16;
|
||
|
|
|
||
|
|
// 字体大小选项
|
||
|
|
let currentFontSize = 'medium';
|
||
|
|
if (fontSizeValue <= 16) {
|
||
|
|
currentFontSize = 'small';
|
||
|
|
} else if (fontSizeValue >= 20) {
|
||
|
|
currentFontSize = 'large';
|
||
|
|
}
|
||
|
|
|
||
|
|
// 当前字体所在的位置
|
||
|
|
const activeDotIndex = Math.min(Math.round((fontSizeValue - 14) / 2), 5);
|
||
|
|
|
||
|
|
// 设置滑块值和预览字体大小
|
||
|
|
this.setData({
|
||
|
|
currentFontSize: currentFontSize,
|
||
|
|
fontSizeValue: fontSizeValue,
|
||
|
|
previewFontSize: fontSizeValue,
|
||
|
|
activeDotIndex: activeDotIndex
|
||
|
|
});
|
||
|
|
} catch (error) {
|
||
|
|
console.error('加载字体设置失败:', error);
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
/* 滑块值变化 */
|
||
|
|
onSliderChange: function(e) {
|
||
|
|
// 不处理滑块之间的点击
|
||
|
|
},
|
||
|
|
|
||
|
|
/* 点击字体大小位置 */
|
||
|
|
onDotClick: function(e) {
|
||
|
|
const value = parseInt(e.currentTarget.dataset.value);
|
||
|
|
|
||
|
|
// 当前字体所在的位置
|
||
|
|
const activeDotIndex = Math.min(Math.round((value - 14) / 2), 5);
|
||
|
|
|
||
|
|
// 更新预览字体大小和字体所在位置
|
||
|
|
this.setData({
|
||
|
|
previewFontSize: value,
|
||
|
|
activeDotIndex: activeDotIndex,
|
||
|
|
fontSizeValue: value
|
||
|
|
});
|
||
|
|
|
||
|
|
// 保存设置
|
||
|
|
this.saveFontSizeSetting(value);
|
||
|
|
},
|
||
|
|
|
||
|
|
/* 阻止滑块之间的点击 */
|
||
|
|
onSliderTap: function(e) {
|
||
|
|
e.stopPropagation();
|
||
|
|
},
|
||
|
|
|
||
|
|
/* 保存字体大小设置 */
|
||
|
|
saveFontSizeSetting: function(value) {
|
||
|
|
try {
|
||
|
|
// 字体大小选项
|
||
|
|
let fontSizeOption = 'medium';
|
||
|
|
if (value <= 16) {
|
||
|
|
fontSizeOption = 'small';
|
||
|
|
} else if (value >= 20) {
|
||
|
|
fontSizeOption = 'large';
|
||
|
|
}
|
||
|
|
|
||
|
|
// 获取聊天设置
|
||
|
|
const chatSettings = wx.getStorageSync('chatSettings') || {};
|
||
|
|
// 更新字体大小设置
|
||
|
|
const updatedSettings = { ...chatSettings, fontSize: fontSizeOption, fontSizeValue: value };
|
||
|
|
// 保存到本地
|
||
|
|
wx.setStorageSync('chatSettings', updatedSettings);
|
||
|
|
|
||
|
|
// 更新数据
|
||
|
|
this.setData({
|
||
|
|
currentFontSize: fontSizeOption,
|
||
|
|
fontSizeValue: value
|
||
|
|
});
|
||
|
|
|
||
|
|
// 更新通知
|
||
|
|
getApp().globalData.fontSize = fontSizeOption;
|
||
|
|
|
||
|
|
} catch (error) {
|
||
|
|
console.error('保存字体设置失败:', error);
|
||
|
|
wx.showToast({
|
||
|
|
title: '设置保存失败',
|
||
|
|
icon: 'none',
|
||
|
|
duration: 1500
|
||
|
|
});
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
/* 返回上一页 */
|
||
|
|
navigateBack: function() {
|
||
|
|
wx.navigateBack();
|
||
|
|
},
|
||
|
|
|
||
|
|
/* 监听页面显示 */
|
||
|
|
onShow: function () {
|
||
|
|
// 重新加载字体设置
|
||
|
|
this.loadCurrentFontSize();
|
||
|
|
}
|
||
|
|
});
|