@liujitcn/kratos-taro-app-core 0.0.55 → 0.0.56

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/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.55",
10
+ "version": "0.0.56",
11
11
  "type": "module",
12
12
  "files": [
13
13
  "dist",
@@ -1,5 +1,11 @@
1
1
  import { http } from '../../../utils/http'
2
- import type { ConfigService, GetConfigRequest, GetConfigResponse } from '../../../rpc/base/v1/config'
2
+ import type {
3
+ ConfigService,
4
+ GetConfigRequest,
5
+ GetConfigResponse,
6
+ GetI18nCustomRequest,
7
+ GetI18nCustomResponse,
8
+ } from '../../../rpc/base/v1/config'
3
9
 
4
10
  const CONFIG_URL = '/v1/base/config'
5
11
 
@@ -15,6 +21,15 @@ export class ConfigServiceImpl implements ConfigService {
15
21
  header: { Authorization: 'no-auth' },
16
22
  })
17
23
  }
24
+
25
+ /** 获取当前租户的自定义国际化覆盖项。 */
26
+ GetI18nCustom(request: GetI18nCustomRequest): Promise<GetI18nCustomResponse> {
27
+ return http<GetI18nCustomResponse>({
28
+ url: `${CONFIG_URL}/i18n-custom`,
29
+ method: 'GET',
30
+ data: request,
31
+ })
32
+ }
18
33
  }
19
34
 
20
35
  export const defConfigService = new ConfigServiceImpl()
package/src/index.ts CHANGED
@@ -22,6 +22,8 @@ export const coreModule = defineKratosTaroModule({
22
22
  icons: {
23
23
  HOME_DEFAULT: 'static/tabs/home_default.png',
24
24
  HOME_SELECTED: 'static/tabs/home_selected.png',
25
+ MESSAGE_DEFAULT: 'static/tabs/message_default.png',
26
+ MESSAGE_SELECTED: 'static/tabs/message_selected.png',
25
27
  USER_DEFAULT: 'static/tabs/user_default.png',
26
28
  USER_SELECTED: 'static/tabs/user_selected.png',
27
29
  },
@@ -9,4 +9,4 @@
9
9
  | `en-US.json` | 英文 Core 语言包。 | Taro 切换为英文时使用。 |
10
10
  | `ja-JP.json` | 日文 Core 语言包。 | Taro 切换为日文时使用。 |
11
11
 
12
- 语言包是标准 JSON,不能在文件内直接写注释;公共键使用 `common.` 或 `core.` 命名空间。新增语言后执行仓库根目录的 `make i18n-sync`。语言切换选项固定显示后端 `base_language.native_name`,接口不可用时使用代码内置的原生名称;`common.language.*` 仅用于普通文案和语言迁移初始数据。新增语言的完整文件清单见[国际化语言扩展指南](../../../../../../docs/国际化语言扩展指南.md)。
12
+ 语言包是标准 JSON,不能在文件内直接写注释;公共键使用 `common.` 或 `core.` 命名空间。新增语言后执行仓库根目录的 `make i18n`。语言切换选项固定显示后端 `base_language.native_name`,接口不可用时使用代码内置的原生名称;`common.language.*` 仅用于普通文案和语言迁移初始数据。新增语言的完整文件清单见[国际化语言扩展指南](../../../../../../docs/国际化语言扩展指南.md)。
@@ -40,8 +40,18 @@ export interface GetConfigResponse {
40
40
  configs: ConfigItem[];
41
41
  /** AI 助手是否可用 */
42
42
  ai_enabled: boolean;
43
+ }
44
+
45
+ /** 当前租户自定义国际化覆盖项查询条件。 */
46
+ export interface GetI18nCustomRequest {
47
+ /** 位置:枚举【BaseConfigSite】 */
48
+ site: BaseConfigSite;
49
+ }
50
+
51
+ /** 当前租户自定义国际化覆盖项查询结果。 */
52
+ export interface GetI18nCustomResponse {
43
53
  /** 全部语言的自定义国际化覆盖项 */
44
- i18n_customs: I18nCustomItem[];
54
+ items: I18nCustomItem[];
45
55
  }
46
56
 
47
57
  /** 全部语言的自定义国际化覆盖项。 */
@@ -58,4 +68,6 @@ export interface I18nCustomItem {
58
68
  export interface ConfigService {
59
69
  /** 获取系统配置 */
60
70
  GetConfig(request: GetConfigRequest): Promise<GetConfigResponse>;
71
+ /** 获取当前租户的自定义国际化覆盖项 */
72
+ GetI18nCustom(request: GetI18nCustomRequest): Promise<GetI18nCustomResponse>;
61
73
  }
@@ -1,6 +1,6 @@
1
1
  // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
2
2
  // versions:
3
- // protoc-gen-ts_proto v2.12.1
3
+ // protoc-gen-ts_proto v2.11.8
4
4
  // protoc unknown
5
5
  // source: base/v1/file.proto
6
6
 
@@ -15,6 +15,8 @@ export interface SettingStoreState {
15
15
  aiEnabled: boolean
16
16
  getData: (key: string) => string | undefined
17
17
  loadData: () => Promise<void>
18
+ loadI18nCustom: () => Promise<void>
19
+ resetI18nCustom: () => void
18
20
  }
19
21
 
20
22
  let loading: Promise<void> | undefined
@@ -36,7 +38,6 @@ export const useSettingStore = create<SettingStoreState>((set, get) => ({
36
38
  set({ aiEnabled: false })
37
39
  return
38
40
  }
39
- applyCustomLocaleMessages(response.i18n_customs ?? [])
40
41
  const nextData = new Map(response.configs.map((item) => [item.key, item.value]))
41
42
  const missing = REQUIRED_APP_CONFIGS.filter(({ key }) => !nextData.get(key))
42
43
  if (missing.length) {
@@ -54,4 +55,11 @@ export const useSettingStore = create<SettingStoreState>((set, get) => ({
54
55
  loading = undefined
55
56
  }
56
57
  },
58
+ async loadI18nCustom() {
59
+ const response = await defConfigService.GetI18nCustom({ site: BaseConfigSite.BASE_CONFIG_SITE_APP })
60
+ applyCustomLocaleMessages(response.items ?? [])
61
+ },
62
+ resetI18nCustom() {
63
+ applyCustomLocaleMessages([])
64
+ },
57
65
  }))
@@ -21,6 +21,7 @@ import {
21
21
  setTokenExpiresIn,
22
22
  } from '../utils/auth'
23
23
  import { AUTH_SILENT_LOGOUT_EVENT } from '../utils/http'
24
+ import { useSettingStore } from './setting'
24
25
 
25
26
  const USER_STORAGE_KEY = 'user'
26
27
 
@@ -94,6 +95,12 @@ export const useUserStore = create<UserStoreState>((set, get) => ({
94
95
  setToken(`${data.token_type} ${data.access_token}`)
95
96
  setRefreshToken(data.refresh_token)
96
97
  setTokenExpiresIn(data.expires_in)
98
+ const settingStore = useSettingStore.getState()
99
+ try {
100
+ await settingStore.loadI18nCustom()
101
+ } catch {
102
+ settingStore.resetI18nCustom()
103
+ }
97
104
  await runUserStoreExtensions('onLogin')
98
105
  },
99
106
  async login(request) {
@@ -137,12 +144,14 @@ export const useUserStore = create<UserStoreState>((set, get) => ({
137
144
  clearToken()
138
145
  persistUserInfo()
139
146
  set({ userInfo: undefined })
147
+ useSettingStore.getState().resetI18nCustom()
140
148
  await runUserStoreExtensions('onLogout')
141
149
  },
142
150
  silentLogout() {
143
151
  clearToken()
144
152
  persistUserInfo()
145
153
  set({ userInfo: undefined })
154
+ useSettingStore.getState().resetI18nCustom()
146
155
  void runUserStoreExtensions('onSilentLogout')
147
156
  },
148
157
  ensureAuthenticated() {
@@ -159,6 +168,7 @@ export function startUserStoreEventBridge(): void {
159
168
  Taro.eventCenter.on(AUTH_SILENT_LOGOUT_EVENT, () => {
160
169
  persistUserInfo()
161
170
  useUserStore.setState({ userInfo: undefined })
171
+ useSettingStore.getState().resetI18nCustom()
162
172
  void runUserStoreExtensions('onSilentLogout')
163
173
  })
164
174
  }