| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 |
- <template>
- <view class="test-container">
- <text class="title">调试工具</text>
-
- <!-- 缓存信息展示 -->
- <view class="section">
- <text class="section-title">当前缓存状态</text>
- <view class="info-card">
- <view class="info-row">
- <text class="label">是否登录:</text>
- <text class="value" :class="{ success: isLogined, error: !isLogined }">
- {{ isLogined ? '已登录' : '未登录' }}
- </text>
- </view>
- <view class="info-row">
- <text class="label">Token:</text>
- <text class="value token">{{ tokenDisplay }}</text>
- </view>
- <view class="info-row">
- <text class="label">用户信息:</text>
- <text class="value">{{ userInfoDisplay }}</text>
- </view>
- </view>
- </view>
-
- <!-- 操作按钮 -->
- <view class="section">
- <text class="section-title">操作</text>
-
- <button class="action-btn" @click="simulateLogin">模拟登录</button>
- <button class="action-btn warn" @click="clearCache">清除缓存</button>
- <button class="action-btn" @click="refreshStatus">刷新状态</button>
- <button class="action-btn" @click="gotoSplash">跳转到启动页</button>
- <button class="action-btn" @click="gotoLogin">跳转到登录页</button>
- <button class="action-btn" @click="gotoHome">跳转到首页</button>
- </view>
-
- <!-- 日志区域 -->
- <view class="section">
- <text class="section-title">操作日志</text>
- <scroll-view scroll-y class="log-box">
- <view v-for="(log, index) in logs" :key="index" class="log-item">
- <text class="log-time">{{ log.time }}</text>
- <text class="log-text">{{ log.text }}</text>
- </view>
- </scroll-view>
- </view>
- </view>
- </template>
- <script setup>
- import { ref, computed, onMounted } from 'vue'
- import { getUserInfo, getToken, isLogin, saveUserInfo, clearUserInfo } from '@/utils/userCache.js'
- const logs = ref([])
- const isLogined = ref(false)
- const tokenDisplay = ref('无')
- const userInfoDisplay = ref('无')
- // 刷新状态
- const refreshStatus = () => {
- isLogined.value = isLogin()
- const token = getToken()
- tokenDisplay.value = token ? token.substring(0, 20) + '...' : '无'
-
- const userInfo = getUserInfo()
- if (userInfo) {
- userInfoDisplay.value = JSON.stringify(userInfo)
- } else {
- userInfoDisplay.value = '无'
- }
-
- addLog('状态已刷新')
- }
- // 添加日志
- const addLog = (text) => {
- const now = new Date()
- const time = `${now.getHours().toString().padStart(2, '0')}:${now.getMinutes().toString().padStart(2, '0')}:${now.getSeconds().toString().padStart(2, '0')}`
- logs.value.unshift({ time, text })
-
- // 只保留最近 20 条
- if (logs.value.length > 20) {
- logs.value.pop()
- }
- }
- // 模拟登录
- const simulateLogin = () => {
- const mockUserInfo = {
- id: 'test_user_001',
- nickname: '测试用户',
- phone: '13800138000',
- avatar: ''
- }
- const mockToken = 'mock_token_' + Date.now()
-
- const success = saveUserInfo(mockUserInfo, mockToken)
- if (success) {
- addLog('模拟登录成功')
- refreshStatus()
-
- uni.showToast({
- title: '模拟登录成功',
- icon: 'success'
- })
- } else {
- addLog('模拟登录失败')
- }
- }
- // 清除缓存
- const clearCache = () => {
- uni.showModal({
- title: '提示',
- content: '确定要清除缓存吗?',
- success: (res) => {
- if (res.confirm) {
- clearUserInfo()
- addLog('缓存已清除')
- refreshStatus()
-
- uni.showToast({
- title: '已清除',
- icon: 'success'
- })
- }
- }
- })
- }
- // 跳转
- const gotoSplash = () => {
- addLog('跳转到启动页')
- uni.reLaunch({
- url: '/pages/splash/splash'
- })
- }
- const gotoLogin = () => {
- addLog('跳转到登录页')
- uni.navigateTo({
- url: '/pages/login/login'
- })
- }
- const gotoHome = () => {
- addLog('跳转到首页')
- uni.navigateTo({
- url: '/pages/index/index'
- })
- }
- onMounted(() => {
- addLog('调试工具已加载')
- refreshStatus()
- })
- </script>
- <style lang="scss" scoped>
- .test-container {
- min-height: 100vh;
- background-color: #f5f5f5;
- padding: 40rpx;
- }
- .title {
- font-size: 40rpx;
- font-weight: 600;
- color: #333;
- display: block;
- text-align: center;
- margin-bottom: 40rpx;
- }
- .section {
- background-color: #ffffff;
- border-radius: 16rpx;
- padding: 32rpx;
- margin-bottom: 32rpx;
-
- .section-title {
- font-size: 30rpx;
- font-weight: 600;
- color: #333;
- display: block;
- margin-bottom: 24rpx;
- }
- }
- .info-card {
- background-color: #f9f9f9;
- border-radius: 12rpx;
- padding: 24rpx;
-
- .info-row {
- display: flex;
- margin-bottom: 16rpx;
-
- &:last-child {
- margin-bottom: 0;
- }
-
- .label {
- font-size: 26rpx;
- color: #666;
- width: 160rpx;
- flex-shrink: 0;
- }
-
- .value {
- font-size: 26rpx;
- color: #333;
- flex: 1;
- word-break: break-all;
-
- &.success {
- color: #52c41a;
- }
-
- &.error {
- color: #ff4d4f;
- }
-
- &.token {
- font-family: monospace;
- background-color: #f0f0f0;
- padding: 4rpx 12rpx;
- border-radius: 8rpx;
- }
- }
- }
- }
- .action-btn {
- width: 100%;
- height: 80rpx;
- background-color: #1890ff;
- color: #ffffff;
- font-size: 28rpx;
- border-radius: 12rpx;
- margin-bottom: 16rpx;
- border: none;
-
- &::after {
- border: none;
- }
-
- &.warn {
- background-color: #ff4d4f;
- }
- }
- .log-box {
- height: 400rpx;
- background-color: #1e1e1e;
- border-radius: 12rpx;
- padding: 20rpx;
-
- .log-item {
- display: flex;
- margin-bottom: 12rpx;
-
- &:last-child {
- margin-bottom: 0;
- }
-
- .log-time {
- font-size: 22rpx;
- color: #888;
- font-family: monospace;
- margin-right: 16rpx;
- }
-
- .log-text {
- font-size: 24rpx;
- color: #fff;
- flex: 1;
- }
- }
- }
- </style>
|