注入
TSXinject
1import {
2 ContainerRegistryManager,
3 SettingService,
4 Inject,
5 Service,
6} from "@quan-erp/shared-backend-core";
7
8@Service()
9export class MyPluginService {
10 @Inject(SettingService, ContainerRegistryManager.BUILTIN_PLUGIN)
11 private settingService: SettingService;
12}写入方法
set / setMany 接受 ServiceProps 与 data。datatype:string | number | boolean | json | date。
- set({ data: { key, value, datatype, userId?, isPublic? } }) — 写入一项设置
- setMany({ data: Record<...> }) — 一次写入多项
TSXset
1import {
2 ContainerRegistryManager,
3 Inject,
4 Service,
5 SettingService,
6} from "@quan-erp/shared-backend-core";
7
8@Service()
9export class ThemeSettingService {
10 @Inject(SettingService, ContainerRegistryManager.BUILTIN_PLUGIN)
11 private settingService: SettingService;
12
13 async saveTheme(userId: number, theme: string) {
14 await this.settingService.set({
15 data: {
16 key: "ui.theme",
17 value: theme,
18 datatype: "string",
19 userId,
20 isPublic: false,
21 },
22 });
23 }
24}读取方法
- get(key, { userId?, isPublic? }) — 读取一项
- getAll(userId) — 该用户可见的全部设置(含全局)
- getPublicSettings() — 标记为公开的设置
TSXget
1import {
2 ContainerRegistryManager,
3 Inject,
4 Service,
5 SettingService,
6} from "@quan-erp/shared-backend-core";
7
8@Service()
9export class ThemeSettingService {
10 @Inject(SettingService, ContainerRegistryManager.BUILTIN_PLUGIN)
11 private settingService: SettingService;
12
13 async loadTheme(userId: number) {
14 return this.settingService.get("ui.theme", { userId });
15 }
16
17 async allForUser(userId: number) {
18 return this.settingService.getAll(userId);
19 }
20}