@liujitcn/kratos-taro-app-system 0.0.83 → 0.0.84

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -13,6 +13,34 @@
13
13
 
14
14
  页面配置统一登记在 `src/pages.ts`,运行时映射位于 `src/index.ts`,构建期描述位于 `src/build.ts`。页面私有组件放在页面目录的 `components` 中,不会被 runner 扫描为路由。
15
15
 
16
+ ## 个人中心扩展
17
+
18
+ 公共组件 `KratosMyPage` 保留顶部标题与设置、个人信息和 AI 助手入口;AI 卡片继续由应用的 `aiEnabled` 配置控制显隐。React `children` 作为业务扩展区,位于这些固定内容之后,与它们共用滚动区域、主题和卡片间距。未传入内容时不增加容器或留白,业务卡片、数据请求和权限由项目模块维护。
19
+
20
+ 公共组件与样式位于 `src/components/KratosMyPage.tsx` 和 `KratosMyPage.scss`。内置 [我的页面](src/views/pages/my/my.tsx) 已使用该组件,并挂载 [MyExtensions 空实现](src/views/pages/my/components/MyExtensions.tsx)。空实现返回 `null`,不显示占位卡片;项目可以按这个结构组织自己的业务内容。
21
+
22
+ 在项目业务模块的 `src/views/pages/my/my.tsx` 复用公开组件入口:
23
+
24
+ ```tsx
25
+ import KratosMyPage from '@liujitcn/kratos-taro-app-system/components/KratosMyPage'
26
+ import OrderSection from './components/OrderSection'
27
+ import ServiceSection from './components/ServiceSection'
28
+
29
+ /** MyPage 组合公共个人中心与项目业务卡片。 */
30
+ export default function MyPage() {
31
+ return (
32
+ <KratosMyPage>
33
+ <OrderSection />
34
+ <ServiceSection />
35
+ </KratosMyPage>
36
+ )
37
+ }
38
+ ```
39
+
40
+ 项目模块的 `pages` 声明 `'pages/my/my': { style: { navigationStyle: 'custom', navigationBarTitleText: '' } }`,`views` 声明 `PROFILE_HOME: 'pages/my/my'`,并在宿主 `module-manifest.ts` 中排在 system 模块之后。构建期 `buildModule.pages` 复用相同页面配置。使用相同的物理路由可以保留微信原生 tab 切换;页面 wrapper 和底部 tabBar 继续由 runner 生成,不在业务页面重复挂载。
41
+
42
+ 扩展区可以直接放多个业务卡片,不需要复制公共页面或给顶部入口提供替换内容。需要登录态、用户资料或导航时,通过 core 的公开 store 与导航 API 获取。
43
+
16
44
  ## AI 助手
17
45
 
18
46
  AI 页面支持会话创建与切换、历史会话搜索、消息加载、附件上传、复制、删除、再生成、工具提示和快捷入口。Provider 与模型通过 `AiModelService` 加载,知识库通过 `AiKnowledgeService` 加载并可多选,发送消息时携带所选知识库编号。H5 使用 Fetch SSE,微信小程序使用 chunked 请求,两端共用增量 SSE 解析器和相同事件契约。
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "type": "git",
8
8
  "url": "git@github.com:liujitcn/kratos-admin.git"
9
9
  },
10
- "version": "0.0.83",
10
+ "version": "0.0.84",
11
11
  "type": "module",
12
12
  "files": [
13
13
  "dist",
@@ -28,6 +28,7 @@
28
28
  },
29
29
  "./api/*": "./src/api/*",
30
30
  "./rpc/*": "./src/rpc/*",
31
+ "./components/*": "./src/components/*.tsx",
31
32
  "./views/*": "./src/views/*",
32
33
  "./package.json": "./package.json"
33
34
  },
@@ -38,8 +39,8 @@
38
39
  "@tarojs/components": "4.2.1",
39
40
  "@tarojs/taro": "4.2.1",
40
41
  "react": "18.3.1",
41
- "@liujitcn/kratos-taro-app-core": "^0.0.83",
42
- "@liujitcn/kratos-taro-app-ui": "^0.0.83"
42
+ "@liujitcn/kratos-taro-app-core": "^0.0.84",
43
+ "@liujitcn/kratos-taro-app-ui": "^0.0.84"
43
44
  },
44
45
  "scripts": {
45
46
  "build": "pnpm run build:entries && pnpm pack --pack-destination ../../../dist/npm",
@@ -1,3 +1,4 @@
1
+ /* 公共个人中心与业务扩展共用完整页面视口。 */
1
2
  page {
2
3
  height: 100%;
3
4
  overflow: hidden;
@@ -0,0 +1,110 @@
1
+ import type { CSSProperties, ReactNode } from 'react'
2
+ import { Image, ScrollView, View } from '@tarojs/components'
3
+ import defaultAvatar from '@liujitcn/kratos-taro-app-core/static/images/avatar.png'
4
+ import {
5
+ formatSrc,
6
+ getMpCapsuleRightGap,
7
+ navigateAppRoute,
8
+ navigateToLogin,
9
+ useI18n,
10
+ useSettingStore,
11
+ useThemeStore,
12
+ useUserStore,
13
+ } from '@liujitcn/kratos-taro-app-core'
14
+ import './KratosMyPage.scss'
15
+
16
+ /** KratosMyPageProps 个人中心的项目业务扩展属性。 */
17
+ export interface KratosMyPageProps {
18
+ /** 在个人信息和 AI 助手之后渲染的项目业务内容。 */
19
+ children?: ReactNode
20
+ }
21
+
22
+ /** KratosMyPage 保留公共个人中心入口,并在下方渲染项目业务内容。 */
23
+ export default function KratosMyPage({ children }: KratosMyPageProps) {
24
+ const { t } = useI18n()
25
+ const themeStore = useThemeStore()
26
+ const profile = useUserStore((state) => state.userInfo)
27
+ const isLoggedIn = useUserStore((state) => state.isAuthenticated())
28
+ const ensureAuthenticated = useUserStore((state) => state.ensureAuthenticated)
29
+ const aiEnabled = useSettingStore((state) => state.aiEnabled)
30
+ const avatarText = (profile?.nick_name || 'U').slice(0, 1)
31
+ /** MP-WEIXIN 原生胶囊按钮右侧避让宽度,写入 --mp-capsule-gap 供 .k-top 预留空间。 */
32
+ const capsuleGap = getMpCapsuleRightGap()
33
+ const topNavStyle = { '--mp-capsule-gap': `${capsuleGap}px` } as CSSProperties
34
+ /** 设计稿齿轮线稿,随主题取色的 data URI,替代 CSS 手绘图标。 */
35
+ const gearIcon = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(
36
+ `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="${
37
+ themeStore.theme === 'light' ? '#102232' : '#e9f4f6'
38
+ }" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.6 1.6 0 0 0 .3 1.8 2 2 0 1 1-2.8 2.8 1.6 1.6 0 0 0-2.7 1.1 2 2 0 1 1-4 0 1.6 1.6 0 0 0-2.6-1.1 2 2 0 1 1-2.8-2.8A1.6 1.6 0 0 0 3 13.9a2 2 0 1 1 0-4 1.6 1.6 0 0 0 1.5-2.7 2 2 0 1 1 2.8-2.8A1.6 1.6 0 0 0 10 4.6a2 2 0 1 1 4 0 1.6 1.6 0 0 0 2.7.6 2 2 0 1 1 2.8 2.8 1.6 1.6 0 0 0-.1 2.6a2.2 2.2 0 1 1 0 4.4Z"/></svg>`,
39
+ )}`
40
+ /** 个人卡账号行:登录展示账号,未登录提示去登录。 */
41
+ const accountText =
42
+ isLoggedIn && profile ? profile.user_name || profile.nick_name || '' : t('system.profile.login_prompt')
43
+
44
+ /** 打开需要登录的公共页面。 */
45
+ const openAuthenticatedPage = (route: string) => {
46
+ if (!ensureAuthenticated()) {
47
+ navigateToLogin()
48
+ return
49
+ }
50
+ navigateAppRoute(route)
51
+ }
52
+
53
+ return (
54
+ <ScrollView
55
+ enableBackToTop
56
+ scrollY
57
+ className={`my-viewport${process.env.TARO_ENV === 'weapp' ? ' my-viewport--weapp' : ''} ${
58
+ themeStore.theme === 'light' ? 'theme-light' : 'theme-dark'
59
+ }`}
60
+ >
61
+ <View className='my-content'>
62
+ <View className='k-top' style={topNavStyle}>
63
+ <View className='k-top__title'>{t('core.navigation.my')}</View>
64
+ <View className='k-ic' onClick={() => openAuthenticatedPage('app/settings')}>
65
+ <Image className='my-gear' src={gearIcon} mode='aspectFit' />
66
+ </View>
67
+ </View>
68
+
69
+ <View className='my-stack'>
70
+ <View
71
+ className='k-glass k-glass--lit k-pfx my-profile'
72
+ onClick={() => navigateAppRoute('app/profile')}
73
+ >
74
+ <View className='my-pfx-main'>
75
+ {isLoggedIn && profile ? (
76
+ <Image
77
+ className='k-pfx__av'
78
+ src={profile.avatar ? formatSrc(profile.avatar) : defaultAvatar}
79
+ mode='aspectFill'
80
+ />
81
+ ) : (
82
+ <View className='k-pfx__av'>{avatarText}</View>
83
+ )}
84
+ <View className='my-pfx-meta'>
85
+ <View className='k-pfx__nm'>
86
+ {isLoggedIn && profile ? profile.nick_name : t('system.profile.not_logged_in')}
87
+ </View>
88
+ <View className='k-pfx__ac'>{accountText}</View>
89
+ </View>
90
+ </View>
91
+ <View className='k-pfx__ent'>{t('system.profile.title')} ›</View>
92
+ </View>
93
+
94
+ {aiEnabled ? (
95
+ <View className='k-aix' onClick={() => openAuthenticatedPage('app/ai')}>
96
+ <View className='k-aix__ic'>AI</View>
97
+ <View className='my-aix-copy'>
98
+ <View className='k-aix__t'>{t('system.settings.ai_title')}</View>
99
+ <View className='k-aix__d'>{t('system.settings.ai_description')}</View>
100
+ </View>
101
+ <View className='k-aix__b'>{t('system.settings.go_ask')}</View>
102
+ </View>
103
+ ) : null}
104
+
105
+ {children}
106
+ </View>
107
+ </View>
108
+ </ScrollView>
109
+ )
110
+ }
@@ -0,0 +1,4 @@
1
+ /** MyExtensions 项目业务扩展的空实现,可添加订单、收藏或统计卡片。 */
2
+ export default function MyExtensions() {
3
+ return null
4
+ }
@@ -1,101 +1,11 @@
1
- import type { CSSProperties } from 'react'
2
- import { Image, ScrollView, View } from '@tarojs/components'
3
- import defaultAvatar from '@liujitcn/kratos-taro-app-core/static/images/avatar.png'
4
- import {
5
- formatSrc,
6
- getMpCapsuleRightGap,
7
- navigateAppRoute,
8
- navigateToLogin,
9
- useI18n,
10
- useSettingStore,
11
- useThemeStore,
12
- useUserStore,
13
- } from '@liujitcn/kratos-taro-app-core'
14
- import './my.scss'
1
+ import KratosMyPage from '@liujitcn/kratos-taro-app-system/components/KratosMyPage'
2
+ import MyExtensions from './components/MyExtensions'
15
3
 
16
- /** 个人中心首页。 */
4
+ /** MyPage 组合公共个人中心与项目业务扩展。 */
17
5
  export default function MyPage() {
18
- const { t } = useI18n()
19
- const themeStore = useThemeStore()
20
- const profile = useUserStore((state) => state.userInfo)
21
- const isLoggedIn = useUserStore((state) => state.isAuthenticated())
22
- const ensureAuthenticated = useUserStore((state) => state.ensureAuthenticated)
23
- const aiEnabled = useSettingStore((state) => state.aiEnabled)
24
- const avatarText = (profile?.nick_name || 'U').slice(0, 1)
25
- /** MP-WEIXIN 原生胶囊按钮右侧避让宽度,写入 --mp-capsule-gap 供 .k-top 预留空间。 */
26
- const capsuleGap = getMpCapsuleRightGap()
27
- const topNavStyle = { '--mp-capsule-gap': `${capsuleGap}px` } as CSSProperties
28
- /** 设计稿齿轮线稿,随主题取色的 data URI,替代 CSS 手绘图标。 */
29
- const gearIcon = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(
30
- `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="${
31
- themeStore.theme === 'light' ? '#102232' : '#e9f4f6'
32
- }" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.6 1.6 0 0 0 .3 1.8 2 2 0 1 1-2.8 2.8 1.6 1.6 0 0 0-2.7 1.1 2 2 0 1 1-4 0 1.6 1.6 0 0 0-2.6-1.1 2 2 0 1 1-2.8-2.8A1.6 1.6 0 0 0 3 13.9a2 2 0 1 1 0-4 1.6 1.6 0 0 0 1.5-2.7 2 2 0 1 1 2.8-2.8A1.6 1.6 0 0 0 10 4.6a2 2 0 1 1 4 0 1.6 1.6 0 0 0 2.7.6 2 2 0 1 1 2.8 2.8 1.6 1.6 0 0 0-.1 2.6a2.2 2.2 0 1 1 0 4.4Z"/></svg>`,
33
- )}`
34
- /** 个人卡账号行:登录展示账号,未登录提示去登录。 */
35
- const accountText =
36
- isLoggedIn && profile ? profile.user_name || profile.nick_name || '' : t('system.profile.login_prompt')
37
-
38
- const openAuthenticatedPage = (route: string) => {
39
- if (!ensureAuthenticated()) {
40
- navigateToLogin()
41
- return
42
- }
43
- navigateAppRoute(route)
44
- }
45
-
46
6
  return (
47
- <ScrollView
48
- enableBackToTop
49
- scrollY
50
- className={`my-viewport${process.env.TARO_ENV === 'weapp' ? ' my-viewport--weapp' : ''} ${
51
- themeStore.theme === 'light' ? 'theme-light' : 'theme-dark'
52
- }`}
53
- >
54
- <View className='my-content'>
55
- <View className='k-top' style={topNavStyle}>
56
- <View className='k-top__title'>{t('core.navigation.my')}</View>
57
- <View className='k-ic' onClick={() => openAuthenticatedPage('app/settings')}>
58
- <Image className='my-gear' src={gearIcon} mode='aspectFit' />
59
- </View>
60
- </View>
61
-
62
- <View className='my-stack'>
63
- <View
64
- className='k-glass k-glass--lit k-pfx my-profile'
65
- onClick={() => navigateAppRoute('app/profile')}
66
- >
67
- <View className='my-pfx-main'>
68
- {isLoggedIn && profile ? (
69
- <Image
70
- className='k-pfx__av'
71
- src={profile.avatar ? formatSrc(profile.avatar) : defaultAvatar}
72
- mode='aspectFill'
73
- />
74
- ) : (
75
- <View className='k-pfx__av'>{avatarText}</View>
76
- )}
77
- <View className='my-pfx-meta'>
78
- <View className='k-pfx__nm'>
79
- {isLoggedIn && profile ? profile.nick_name : t('system.profile.not_logged_in')}
80
- </View>
81
- <View className='k-pfx__ac'>{accountText}</View>
82
- </View>
83
- </View>
84
- <View className='k-pfx__ent'>{t('system.profile.title')} ›</View>
85
- </View>
86
-
87
- {aiEnabled ? (
88
- <View className='k-aix' onClick={() => openAuthenticatedPage('app/ai')}>
89
- <View className='k-aix__ic'>AI</View>
90
- <View className='my-aix-copy'>
91
- <View className='k-aix__t'>{t('system.settings.ai_title')}</View>
92
- <View className='k-aix__d'>{t('system.settings.ai_description')}</View>
93
- </View>
94
- <View className='k-aix__b'>{t('system.settings.go_ask')}</View>
95
- </View>
96
- ) : null}
97
- </View>
98
- </View>
99
- </ScrollView>
7
+ <KratosMyPage>
8
+ <MyExtensions />
9
+ </KratosMyPage>
100
10
  )
101
11
  }