| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366 |
- <template>
- <view class="container">
- <!-- 顶部导航栏 -->
- <view class="header">
- <view class="back-btn" @click="goBack">
- <text class="back-icon">←</text>
- </view>
- <text class="header-title">设置</text>
- <view class="header-right"></view>
- </view>
-
- <scroll-view class="scroll-content" scroll-y>
- <!-- 开关设置项 -->
- <view class="settings-section">
- <view class="setting-item" v-for="(setting, index) in toggleSettings" :key="index">
- <text class="setting-label">{{ setting.label }}</text>
- <switch
- class="setting-switch"
- :checked="setting.value"
- @change="handleToggleChange(index, $event)"
- color="#4FC3F7"
- />
- </view>
- </view>
-
- <!-- 分隔线 -->
- <view class="divider"></view>
-
- <!-- 信息项 -->
- <view class="info-section">
- <view class="info-item" @click="handleInfoClick('clearCache')">
- <text class="info-label">清理缓存</text>
- <view class="info-right">
- <text class="info-value">{{ cacheSize }}</text>
- <text class="info-arrow">></text>
- </view>
- </view>
- <view class="info-item" @click="handleInfoClick('about')">
- <text class="info-label">关于我们</text>
- <text class="info-arrow">></text>
- </view>
- <view class="info-item" @click="handleInfoClick('contact')">
- <text class="info-label">联系我们</text>
- <text class="info-arrow">></text>
- </view>
- </view>
-
- <!-- 分隔线 -->
- <view class="divider"></view>
-
- <!-- 退出登录按钮 -->
- <view class="logout-section">
- <button class="logout-btn" @click="handleLogout">退出登录</button>
- </view>
- </scroll-view>
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- toggleSettings: [
- {
- label: '阅读时不自动锁屏',
- value: false,
- key: 'noAutoLock'
- },
- {
- label: '阅读时隐藏别人的笔记',
- value: false,
- key: 'hideOthersNotes'
- },
- {
- label: '阅读时显示时间和电量',
- value: true,
- key: 'showTimeBattery'
- },
- {
- label: '阅读时允许横屏',
- value: false,
- key: 'allowLandscape'
- },
- {
- label: '点赞提醒',
- value: true,
- key: 'likeReminder'
- }
- ],
- cacheSize: '20M'
- }
- },
- onLoad() {
- // 加载保存的设置
- this.loadSettings()
- // 加载缓存大小
- this.loadCacheSize()
- },
- methods: {
- goBack() {
- uni.navigateBack()
- },
- handleToggleChange(index, event) {
- this.toggleSettings[index].value = event.detail.value
- // 保存设置到本地存储
- this.saveSettings()
- },
- handleInfoClick(type) {
- switch(type) {
- case 'clearCache':
- this.clearCache()
- break
- case 'about':
- this.showAbout()
- break
- case 'contact':
- this.showContact()
- break
- }
- },
- clearCache() {
- uni.showModal({
- title: '提示',
- content: `确定要清理 ${this.cacheSize} 缓存吗?`,
- success: (res) => {
- if (res.confirm) {
- // 清理缓存
- uni.clearStorageSync()
- this.cacheSize = '0M'
- uni.showToast({
- title: '缓存已清理',
- icon: 'success'
- })
- }
- }
- })
- },
- showAbout() {
- uni.navigateTo({
- url: '/pages/about/about'
- })
- },
- showContact() {
- uni.showModal({
- title: '联系我们',
- content: '邮箱: support@yunread.com\n电话: 400-123-4567',
- showCancel: false
- })
- },
- handleLogout() {
- uni.showModal({
- title: '提示',
- content: '确定要退出登录吗?',
- success: (res) => {
- if (res.confirm) {
- // 清除登录信息
- uni.removeStorageSync('token')
- uni.removeStorageSync('userInfo')
-
- uni.showToast({
- title: '已退出登录',
- icon: 'success'
- })
-
- // 跳转到登录页
- setTimeout(() => {
- uni.reLaunch({
- url: '/pages/login/login'
- })
- }, 1500)
- }
- }
- })
- },
- loadSettings() {
- // 从本地存储加载设置
- const savedSettings = uni.getStorageSync('appSettings')
- if (savedSettings) {
- this.toggleSettings.forEach((setting, index) => {
- if (savedSettings[setting.key] !== undefined) {
- this.toggleSettings[index].value = savedSettings[setting.key]
- }
- })
- }
- },
- saveSettings() {
- // 保存设置到本地存储
- const settings = {}
- this.toggleSettings.forEach(setting => {
- settings[setting.key] = setting.value
- })
- uni.setStorageSync('appSettings', settings)
- },
- loadCacheSize() {
- // 计算缓存大小
- try {
- const info = uni.getStorageInfoSync()
- const size = (info.keys.length * 2).toFixed(0) // 简单估算
- this.cacheSize = size + 'M'
- } catch (e) {
- this.cacheSize = '20M'
- }
- }
- }
- }
- </script>
- <style scoped>
- .container {
- width: 100%;
- height: 100vh;
- min-height: 100vh;
- background-color: #FFFFFF;
- display: flex;
- padding-top: 30px;
- box-sizing: border-box;
- flex-direction: column;
- box-sizing: border-box;
- overflow: hidden;
- }
-
- .header {
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 20rpx 30rpx;
- padding-top: calc(20rpx + env(safe-area-inset-top));
- background-color: #FFFFFF;
- border-bottom: 1rpx solid #F0F0F0;
- position: relative;
- flex-shrink: 0;
- box-sizing: border-box;
- }
-
- .back-btn {
- width: 60rpx;
- height: 60rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- z-index: 10;
- }
-
- .back-icon {
- font-size: 40rpx;
- color: #333333;
- font-weight: bold;
- }
-
- .header-title {
- position: absolute;
- left: 50%;
- transform: translateX(-50%);
- font-size: 36rpx;
- font-weight: bold;
- color: #333333;
- }
-
- .header-right {
- width: 60rpx;
- }
-
- .scroll-content {
- flex: 1;
- width: 100%;
- height: 0;
- overflow: hidden;
- padding-bottom: calc(env(safe-area-inset-bottom));
- background-color: #FFFFFF;
- box-sizing: border-box;
- }
-
- .settings-section {
- background-color: #FFFFFF;
- padding: 0 30rpx;
- }
-
- .setting-item {
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 30rpx 0;
- border-bottom: 1rpx solid #F0F0F0;
- }
-
- .setting-item:last-child {
- border-bottom: none;
- }
-
- .setting-label {
- font-size: 30rpx;
- color: #333333;
- flex: 1;
- }
-
- .setting-switch {
- transform: scale(0.9);
- }
-
- .divider {
- height: 20rpx;
- background-color: #F5F5F5;
- }
-
- .info-section {
- background-color: #FFFFFF;
- padding: 0 30rpx;
- }
-
- .info-item {
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 30rpx 0;
- border-bottom: 1rpx solid #F0F0F0;
- }
-
- .info-item:last-child {
- border-bottom: none;
- }
-
- .info-label {
- font-size: 30rpx;
- color: #333333;
- flex: 1;
- }
-
- .info-right {
- display: flex;
- align-items: center;
- gap: 20rpx;
- }
-
- .info-value {
- font-size: 28rpx;
- color: #999999;
- }
-
- .info-arrow {
- font-size: 32rpx;
- color: #CCCCCC;
- }
-
- .logout-section {
- padding: 40rpx 30rpx;
- background-color: #FFFFFF;
- }
-
- .logout-btn {
- width: 100%;
- height: 88rpx;
- background-color: transparent;
- color: #FF1744;
- font-size: 32rpx;
- border: none;
- border-radius: 44rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- }
-
- .logout-btn::after {
- border: none;
- }
- </style>
|