This commit is contained in:
2026-04-22 18:54:52 +08:00
commit bc8986e3b2
49 changed files with 20987 additions and 0 deletions

93
pages/home/index.js Normal file
View File

@@ -0,0 +1,93 @@
const { getRuntimeConfig } = require('../../config/env')
const { sessionStore } = require('../../stores')
const { maskToken } = require('../../utils/util')
const QUICK_ENTRIES = [
{
title: '登录主包',
description: '演示主包内的认证入口、全局会话同步和基础 UI 组件封装。',
badge: '主包',
actionText: '打开登录页',
actionPath: '/pages/login/index'
},
{
title: '业务工作台',
description: '演示分包页面,只在需要时加载,保持主包轻量和首页启动稳定。',
badge: '分包',
actionText: '进入工作台',
actionPath: '/packages/demo/pages/workbench/index'
}
]
function buildSessionView(state) {
const userName = state.userInfo?.nickname || state.userInfo?.name || '访客'
return {
statusLabel: state.isLoggedIn ? '已登录' : '未登录',
userName,
tokenLabel: maskToken(state.token),
permissionsLabel: state.permissions.length ? state.permissions.join(' / ') : '暂无权限'
}
}
Page({
data: {
quickEntries: QUICK_ENTRIES,
envName: '',
apiBaseUrl: '',
isLoggedIn: false,
sessionView: buildSessionView(sessionStore.getState())
},
onLoad() {
const runtimeConfig = getRuntimeConfig()
this.unsubscribe = sessionStore.subscribe(nextState => {
this.syncSession(nextState)
})
this.setData({
envName: runtimeConfig.name.toUpperCase(),
apiBaseUrl: runtimeConfig.baseURL
})
this.syncSession(sessionStore.getState())
},
onUnload() {
this.unsubscribe?.()
},
syncSession(state) {
this.setData({
isLoggedIn: state.isLoggedIn,
sessionView: buildSessionView(state)
})
},
handlePrimaryAction() {
if (this.data.isLoggedIn) {
wx.navigateTo({
url: '/packages/demo/pages/workbench/index'
})
return
}
wx.navigateTo({
url: '/pages/login/index'
})
},
handleLogout() {
sessionStore.clearSession()
wx.showToast({
title: '已清理登录态',
icon: 'success'
})
},
handleEntryAction(event) {
const { path } = event.detail
if (!path) {
return
}
wx.navigateTo({
url: path
})
}
})

7
pages/home/index.json Normal file
View File

@@ -0,0 +1,7 @@
{
"navigationBarTitleText": "首页",
"usingComponents": {
"app-button": "../../components/base/app-button/index",
"entry-card": "../../components/biz/entry-card/index"
}
}

65
pages/home/index.wxml Normal file
View File

@@ -0,0 +1,65 @@
<view class="page-shell">
<view class="panel hero">
<text class="hero__eyebrow">Stable Native Architecture</text>
<text class="hero__title">玄志小程序基础骨架</text>
<text class="hero__summary">
原生小程序 + JS + npm + TDesign + 分包 + service/store 分层,保留微信原生性能和长期维护边界。
</text>
<app-button
block
text="{{isLoggedIn ? '进入业务工作台' : '前往登录页'}}"
bind:tap="handlePrimaryAction"
></app-button>
<app-button
wx:if="{{isLoggedIn}}"
block
text="清理登录态"
theme="default"
variant="outline"
bind:tap="handleLogout"
></app-button>
</view>
<view class="panel session-card">
<text class="section-title">当前会话</text>
<view class="session-card__rows">
<view class="meta-row">
<text class="session-card__label">运行环境</text>
<text class="session-card__value">{{envName}}</text>
</view>
<view class="meta-row">
<text class="session-card__label">API 地址</text>
<text class="session-card__value session-card__value--mono">{{apiBaseUrl}}</text>
</view>
<view class="meta-row">
<text class="session-card__label">登录状态</text>
<text class="session-card__value">{{sessionView.statusLabel}}</text>
</view>
<view class="meta-row">
<text class="session-card__label">当前用户</text>
<text class="session-card__value">{{sessionView.userName}}</text>
</view>
<view class="meta-row">
<text class="session-card__label">Token</text>
<text class="session-card__value session-card__value--mono">{{sessionView.tokenLabel}}</text>
</view>
<view class="meta-row meta-row--top">
<text class="session-card__label">权限</text>
<text class="session-card__value session-card__value--mono">{{sessionView.permissionsLabel}}</text>
</view>
</view>
</view>
<view class="entry-list">
<entry-card
wx:for="{{quickEntries}}"
wx:key="actionPath"
title="{{item.title}}"
description="{{item.description}}"
badge="{{item.badge}}"
actionText="{{item.actionText}}"
actionPath="{{item.actionPath}}"
bind:action="handleEntryAction"
></entry-card>
</view>
</view>

68
pages/home/index.wxss Normal file
View File

@@ -0,0 +1,68 @@
.hero {
display: flex;
flex-direction: column;
gap: 24rpx;
padding: 36rpx 32rpx;
background: linear-gradient(160deg, #0f172a 0%, #1e293b 100%);
color: #f8fafc;
}
.hero__eyebrow {
font-size: 22rpx;
letter-spacing: 4rpx;
text-transform: uppercase;
color: #93c5fd;
}
.hero__title {
font-size: 48rpx;
font-weight: 700;
line-height: 1.2;
}
.hero__summary {
font-size: 26rpx;
line-height: 1.8;
color: rgba(248, 250, 252, 0.8);
}
.session-card {
display: flex;
flex-direction: column;
gap: 24rpx;
padding: 32rpx;
}
.session-card__rows {
display: flex;
flex-direction: column;
gap: 20rpx;
}
.session-card__label {
flex-shrink: 0;
font-size: 24rpx;
color: #64748b;
}
.session-card__value {
flex: 1;
text-align: right;
font-size: 24rpx;
color: #0f172a;
}
.session-card__value--mono {
font-family: 'Cascadia Code', 'Courier New', monospace;
word-break: break-all;
}
.entry-list {
display: flex;
flex-direction: column;
gap: 24rpx;
}
.meta-row--top {
align-items: flex-start;
}