@liujitcn/kratos-admin-system 0.0.43 → 0.0.44

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.
@@ -42,6 +42,8 @@ export interface RuntimeConfigField {
42
42
  visible?: ProFormField["visible"];
43
43
  /** 字段校验规则。 */
44
44
  rules?: RuntimeConfigRule[];
45
+ /** 提交前将控件值转换为 JSON 中的目标类型。 */
46
+ valueType?: "string" | "number" | "boolean" | "json";
45
47
  }
46
48
  /** 管理端运行配置定义。 */
47
49
  export interface RuntimeConfigDefinition<T extends RuntimeConfigModel = RuntimeConfigModel> {
@@ -27,6 +27,8 @@ export interface ConfigItem {
27
27
  export interface GetConfigResponse {
28
28
  /** 系统配置列表 */
29
29
  configs: ConfigItem[];
30
+ /** AI 助手是否可用 */
31
+ ai_enabled: boolean;
30
32
  }
31
33
  /** Base系统配置公共服务 */
32
34
  export interface ConfigService {
@@ -18,11 +18,14 @@ import { computed } from "vue";
18
18
  import { useRouter } from "vue-router";
19
19
  import { t } from "@liujitcn/kratos-admin-core";
20
20
  import { useAuthStore } from "@liujitcn/kratos-admin-core/stores/runtime";
21
+ import { useConfigStore } from "@liujitcn/kratos-admin-core/stores/runtime";
21
22
  import { navigateTo } from "@liujitcn/kratos-admin-core/navigation";
22
23
 
23
24
  const router = useRouter();
24
25
  const authStore = useAuthStore();
26
+ const configStore = useConfigStore();
25
27
  const aiRoute = computed(() => {
28
+ if (!configStore.aiEnabled) return undefined;
26
29
  return authStore.flatMenuListGet.find(item => item.name === "AiChat" && item.path);
27
30
  });
28
31
 
@@ -44,6 +44,8 @@ export interface RuntimeConfigField {
44
44
  visible?: ProFormField["visible"];
45
45
  /** 字段校验规则。 */
46
46
  rules?: RuntimeConfigRule[];
47
+ /** 提交前将控件值转换为 JSON 中的目标类型。 */
48
+ valueType?: "string" | "number" | "boolean" | "json";
47
49
  }
48
50
 
49
51
  /** 管理端运行配置定义。 */
@@ -38,6 +38,8 @@ export interface ConfigItem {
38
38
  export interface GetConfigResponse {
39
39
  /** 系统配置列表 */
40
40
  configs: ConfigItem[];
41
+ /** AI 助手是否可用 */
42
+ ai_enabled: boolean;
41
43
  }
42
44
 
43
45
  /** Base系统配置公共服务 */
@@ -32,7 +32,7 @@
32
32
  :rules="rules"
33
33
  :col-span="12"
34
34
  :gutter="24"
35
- label-position="top"
35
+ label-position="right"
36
36
  scroll-to-error
37
37
  >
38
38
  <template #textValue>
@@ -96,7 +96,7 @@
96
96
  :fields="localizedFormFields"
97
97
  :col-span="12"
98
98
  :gutter="24"
99
- label-position="top"
99
+ label-position="right"
100
100
  scroll-to-error
101
101
  />
102
102
  </template>
@@ -178,8 +178,10 @@ const localizedFormFields = computed<ProFormField[]>(() =>
178
178
  rowBreakBefore: field.rowBreakBefore,
179
179
  visible: field.visible,
180
180
  labelTooltip: field.labelTooltipKey ? t(field.labelTooltipKey) : undefined,
181
+ valueType: field.valueType,
181
182
  rules: field.rules?.map(rule => ({
182
183
  ...rule,
184
+ required: Boolean(rule.required),
183
185
  message: t(
184
186
  rule.messageKey,
185
187
  rule.messageArgs
@@ -653,6 +655,33 @@ function loadFormValue(value?: string) {
653
655
  valueFormRef.value?.clearValidate();
654
656
  }
655
657
 
658
+ /** 按字段声明恢复运行配置提交值的 JSON 类型。 */
659
+ function normalizeRuntimeConfigValue() {
660
+ if (!formDefinition.value) return;
661
+ for (const field of formDefinition.value.fields) {
662
+ const value = field.prop.split(".").reduce<any>((current, key) => current?.[key], formValue.value);
663
+ if (field.valueType === "number" && typeof value === "string" && value !== "") {
664
+ setRuntimeConfigFieldValue(field.prop, Number(value));
665
+ } else if (field.valueType === "boolean" && typeof value === "string") {
666
+ setRuntimeConfigFieldValue(field.prop, value === "true");
667
+ } else if (field.valueType === "json" && typeof value === "string" && value !== "") {
668
+ setRuntimeConfigFieldValue(field.prop, JSON.parse(value));
669
+ }
670
+ }
671
+ }
672
+
673
+ /** 按点路径写入运行配置字段值。 */
674
+ function setRuntimeConfigFieldValue(prop: string, value: unknown) {
675
+ const path = prop.split(".");
676
+ const lastKey = path.pop();
677
+ if (!lastKey) return;
678
+ const target = path.reduce<Record<string, any>>((current, key) => {
679
+ if (!current[key] || typeof current[key] !== "object") current[key] = {};
680
+ return current[key];
681
+ }, formValue.value);
682
+ target[lastKey] = value;
683
+ }
684
+
656
685
  /**
657
686
  * 关闭系统配置弹窗并恢复默认表单值。
658
687
  */
@@ -699,6 +728,7 @@ async function handleSubmit() {
699
728
  return;
700
729
  }
701
730
  if ((await valueFormRef.value?.validate()) !== true) return;
731
+ normalizeRuntimeConfigValue();
702
732
  formData.value = JSON.stringify(formValue.value);
703
733
  }
704
734
  saving.value = true;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@liujitcn/kratos-admin-system",
3
3
  "private": false,
4
- "version": "0.0.43",
4
+ "version": "0.0.44",
5
5
  "type": "module",
6
6
  "description": "kratos-admin system management module",
7
7
  "license": "MIT",
@@ -16,7 +16,7 @@
16
16
  "sortablejs": "^1.15.2",
17
17
  "swagger-ui-dist": "^5.32.9",
18
18
  "vue-element-plus-x": "^2.0.3",
19
- "@liujitcn/kratos-admin-core": "0.0.43"
19
+ "@liujitcn/kratos-admin-core": "0.0.44"
20
20
  },
21
21
  "peerDependencies": {
22
22
  "@element-plus/icons-vue": "^2.3.1",