@slice_cy/mint 1.2.0

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.
Files changed (98) hide show
  1. package/README.md +697 -0
  2. package/app/common/base-response.js +10 -0
  3. package/app/common/business-error.js +10 -0
  4. package/app/common/error-code.js +22 -0
  5. package/app/common/return-utils.js +40 -0
  6. package/app/common/router-schema-validator.js +25 -0
  7. package/app/controller/base.js +24 -0
  8. package/app/controller/project.js +90 -0
  9. package/app/controller/view.js +13 -0
  10. package/app/docs/dsl-doc.js +148 -0
  11. package/app/extend/logger.js +30 -0
  12. package/app/extend/params-valid.js +6 -0
  13. package/app/extend/return-utils.js +9 -0
  14. package/app/middleware/api-sign-verify.js +25 -0
  15. package/app/middleware/err-handler.js +18 -0
  16. package/app/middleware/project-handler.js +25 -0
  17. package/app/pages/boot.js +34 -0
  18. package/app/pages/dashboard/complex-view/header-view/index.vue +108 -0
  19. package/app/pages/dashboard/complex-view/iframe-view/index.vue +37 -0
  20. package/app/pages/dashboard/complex-view/schema-view/complex-view/search-panel/index.vue +36 -0
  21. package/app/pages/dashboard/complex-view/schema-view/complex-view/table-panel/index.vue +123 -0
  22. package/app/pages/dashboard/complex-view/schema-view/components/component-config.js +14 -0
  23. package/app/pages/dashboard/complex-view/schema-view/components/createForm/index.vue +72 -0
  24. package/app/pages/dashboard/complex-view/schema-view/components/detailPanel/index.vue +52 -0
  25. package/app/pages/dashboard/complex-view/schema-view/components/editForm/index.vue +87 -0
  26. package/app/pages/dashboard/complex-view/schema-view/hook/use-schema.js +113 -0
  27. package/app/pages/dashboard/complex-view/schema-view/index.vue +114 -0
  28. package/app/pages/dashboard/complex-view/sider-view/index.vue +116 -0
  29. package/app/pages/dashboard/entry.dashboard.js +44 -0
  30. package/app/pages/dashboard/index.vue +60 -0
  31. package/app/pages/service/index.js +70 -0
  32. package/app/pages/store/index.js +4 -0
  33. package/app/pages/store/menu.js +86 -0
  34. package/app/pages/store/project.js +9 -0
  35. package/app/pages/utils/index.js +26 -0
  36. package/app/pages/widgets/header-container/assets/avatar.png +0 -0
  37. package/app/pages/widgets/header-container/assets/icon.png +0 -0
  38. package/app/pages/widgets/header-container/index.vue +108 -0
  39. package/app/pages/widgets/schema-form/components/input/index.vue +155 -0
  40. package/app/pages/widgets/schema-form/components/input-number/index.vue +148 -0
  41. package/app/pages/widgets/schema-form/components/select/index.vue +132 -0
  42. package/app/pages/widgets/schema-form/form-item-cofnig.js +18 -0
  43. package/app/pages/widgets/schema-form/index.vue +137 -0
  44. package/app/pages/widgets/schema-search-bar/component/date-range-picker/index.vue +55 -0
  45. package/app/pages/widgets/schema-search-bar/component/dynamic-select/index.vue +70 -0
  46. package/app/pages/widgets/schema-search-bar/component/input/index.vue +54 -0
  47. package/app/pages/widgets/schema-search-bar/component/select/index.vue +65 -0
  48. package/app/pages/widgets/schema-search-bar/index.vue +143 -0
  49. package/app/pages/widgets/schema-search-bar/search-item-config.js +20 -0
  50. package/app/pages/widgets/schema-table/index.vue +198 -0
  51. package/app/pages/widgets/sider-container/index.vue +30 -0
  52. package/app/post-router.js +9 -0
  53. package/app/pre-middleware.js +37 -0
  54. package/app/public/dist/entry.dashboard.tpl +2 -0
  55. package/app/public/dist/entry.project-list.tpl +2 -0
  56. package/app/public/dist/prod/css/async.609.bcbe5779.css +1 -0
  57. package/app/public/dist/prod/css/async.952.9bc7c180.css +1 -0
  58. package/app/public/dist/prod/css/common.1a98227b.css +1 -0
  59. package/app/public/dist/prod/css/entry.project-list.14f64dd9.css +1 -0
  60. package/app/public/dist/prod/js/142.56646c73.bundle.js +1 -0
  61. package/app/public/dist/prod/js/609.8270b20d.bundle.js +1 -0
  62. package/app/public/dist/prod/js/68.2813fafe.bundle.js +1 -0
  63. package/app/public/dist/prod/js/952.c76c04fb.bundle.js +1 -0
  64. package/app/public/dist/prod/js/common.9985f827.bundle.js +1 -0
  65. package/app/public/dist/prod/js/entry.dashboard.cd7591e4.bundle.js +1 -0
  66. package/app/public/dist/prod/js/entry.project-list.beb0fa9d.bundle.js +1 -0
  67. package/app/public/dist/prod/js/runtime.5602b906.bundle.js +1 -0
  68. package/app/public/dist/prod/js/vendor.709fbf32.bundle.js +53 -0
  69. package/app/public/dist/prod/static/images/avatar.78e68eaa.png +0 -0
  70. package/app/public/dist/static/logo.png +0 -0
  71. package/app/public/dist/static/normalize.css +1 -0
  72. package/app/public/static/logo.png +0 -0
  73. package/app/public/static/normalize.css +267 -0
  74. package/app/router/project.js +6 -0
  75. package/app/router/view.js +5 -0
  76. package/app/router-schema/project.js +14 -0
  77. package/app/service/base.js +22 -0
  78. package/app/service/project.js +49 -0
  79. package/app/view/entry.tpl +18 -0
  80. package/app/webpack/config/webpack.base.js +288 -0
  81. package/app/webpack/config/webpack.dev.js +53 -0
  82. package/app/webpack/config/webpack.prod.js +106 -0
  83. package/app/webpack/dev.js +34 -0
  84. package/app/webpack/libs/block.js +1 -0
  85. package/app/webpack/prod.js +21 -0
  86. package/config/config.default.js +5 -0
  87. package/index.js +37 -0
  88. package/mint-core/env.js +23 -0
  89. package/mint-core/index.js +101 -0
  90. package/mint-core/loader/config.js +59 -0
  91. package/mint-core/loader/controller.js +59 -0
  92. package/mint-core/loader/extend.js +42 -0
  93. package/mint-core/loader/middleware.js +54 -0
  94. package/mint-core/loader/router-schema.js +39 -0
  95. package/mint-core/loader/router.js +36 -0
  96. package/mint-core/loader/service.js +57 -0
  97. package/model/index.js +94 -0
  98. package/package.json +93 -0
@@ -0,0 +1,148 @@
1
+ <template>
2
+ <div class="form-item">
3
+ <div class="item-label">
4
+ <a-flex
5
+ :gap="5"
6
+ align-items="center"
7
+ >
8
+ <span
9
+ v-if="schema?.option?.required"
10
+ class="required"
11
+ >
12
+ *
13
+ </span>
14
+ <span>{{ schema.label }}</span>
15
+ </a-flex>
16
+ </div>
17
+ <a-input-number
18
+ v-model:value="dtoValue"
19
+ :class="[validTip.length ? 'validate-border-error' : '']"
20
+ v-bind="componentAttrs"
21
+ @blur="onBlur"
22
+ @focus="onFocus"
23
+ ></a-input-number>
24
+ <div
25
+ v-if="validTip.length"
26
+ class="validate-tip-error"
27
+ >
28
+ {{ validTip }}
29
+ </div>
30
+ </div>
31
+ </template>
32
+
33
+ <script setup>
34
+ import { watch, onMounted, ref, computed, inject } from "vue";
35
+ const props = defineProps({
36
+ schema: {
37
+ type: Object,
38
+ default: () => ({}),
39
+ },
40
+ schemaKey: {
41
+ type: String,
42
+ default: "",
43
+ },
44
+ model: {
45
+ type: Number,
46
+ default: undefined,
47
+ },
48
+ });
49
+
50
+ const name = "inputNumber";
51
+
52
+ const componentAttrs = computed(() => {
53
+ const { minimum, maximum } = props.schema;
54
+ const { placeholder: pValue } = props.schema.option.uiComponentConfig;
55
+ const ruleList = [];
56
+ if (minimum) {
57
+ ruleList.push(`最小值:${minimum}`);
58
+ }
59
+ if (maximum) {
60
+ ruleList.push(`最大值:${maximum}`);
61
+ }
62
+ ruleList.push(pValue || "请输入");
63
+ return {
64
+ allowClear: true,
65
+ ...(props.schema.option?.uiComponentConfig || {}),
66
+ placeholder: ruleList.join(" | "),
67
+ disabled: props.schema.option?.disabled,
68
+ };
69
+ });
70
+
71
+ watch(
72
+ [() => props.schema, () => props.model, () => props.schemaKey],
73
+ () => {
74
+ initData();
75
+ },
76
+ { deep: true },
77
+ );
78
+
79
+ const dtoValue = ref();
80
+ const getValue = () => {
81
+ return dtoValue.value
82
+ ? {
83
+ [props.schemaKey]: dtoValue.value,
84
+ }
85
+ : {};
86
+ };
87
+
88
+ const getAjv = inject("getAjv");
89
+ const validTip = ref("");
90
+
91
+ const validate = async () => {
92
+ validTip.value = "";
93
+ if (props.schema.option?.required && !dtoValue.value) {
94
+ validTip.value = `${props.schema.label}必填`;
95
+ return false;
96
+ }
97
+ if (dtoValue.value) {
98
+ const ajv = await getAjv();
99
+ const validate = ajv.compile(props.schema);
100
+ const valid = validate(dtoValue.value);
101
+ if (!valid && validate.errors && validate.errors[0]) {
102
+ const { keyword, params } = validate.errors[0];
103
+ switch (keyword) {
104
+ case "type":
105
+ validTip.value = `${props.schema.label}类型错误`;
106
+ break;
107
+ case "minimum":
108
+ validTip.value = `${props.schema.label}最小值不能小于${params.limit}`;
109
+ break;
110
+ case "maximum":
111
+ validTip.value = `${props.schema.label}最大值不能大于${params.limit}`;
112
+ break;
113
+ default:
114
+ validTip.value = `${props.schema.label}不符合要求`;
115
+ break;
116
+ }
117
+ return false;
118
+ }
119
+ }
120
+
121
+ return true;
122
+ };
123
+
124
+ const onFocus = () => {
125
+ validTip.value = "";
126
+ };
127
+
128
+ const onBlur = () => {
129
+ void validate();
130
+ };
131
+
132
+ function initData() {
133
+ dtoValue.value = props.model || props.schema.option?.default || undefined;
134
+ validTip.value = "";
135
+ }
136
+
137
+ onMounted(() => {
138
+ initData();
139
+ });
140
+
141
+ defineExpose({
142
+ getValue,
143
+ validate,
144
+ name,
145
+ });
146
+ </script>
147
+
148
+ <style scoped lang="less"></style>
@@ -0,0 +1,132 @@
1
+ <template>
2
+ <div class="form-item">
3
+ <div class="item-label">
4
+ <a-flex
5
+ :gap="5"
6
+ align-items="center"
7
+ >
8
+ <span
9
+ v-if="schema?.option?.required"
10
+ class="required"
11
+ >
12
+ *
13
+ </span>
14
+ <span>{{ schema.label }}</span>
15
+ </a-flex>
16
+ </div>
17
+
18
+ <a-select
19
+ v-model:value="dtoValue"
20
+ style="width: 100%"
21
+ :class="[validTip.length ? 'validate-border-error' : '']"
22
+ v-bind="componentAttrs"
23
+ @change="onChange"
24
+ ></a-select>
25
+ <div
26
+ v-if="validTip.length"
27
+ class="validate-tip-error"
28
+ >
29
+ {{ validTip }}
30
+ </div>
31
+ </div>
32
+ </template>
33
+
34
+ <script setup>
35
+ import { watch, onMounted, ref, computed, inject } from "vue";
36
+ const props = defineProps({
37
+ schema: {
38
+ type: Object,
39
+ default: () => ({}),
40
+ },
41
+ schemaKey: {
42
+ type: String,
43
+ default: "",
44
+ },
45
+ model: {
46
+ type: Object,
47
+ default: undefined,
48
+ },
49
+ });
50
+
51
+ const name = "select";
52
+
53
+ const componentAttrs = computed(() => {
54
+ return {
55
+ allowClear: true,
56
+ placeholder: "请选择",
57
+ ...(props.schema.option?.uiComponentConfig || {}),
58
+ options: props.schema.option?.enumList || [],
59
+ disabled: props.schema.option?.disabled,
60
+ };
61
+ });
62
+
63
+ watch(
64
+ [() => props.schema, () => props.model],
65
+ () => {
66
+ initData();
67
+ },
68
+ { deep: true },
69
+ );
70
+
71
+ const dtoValue = ref();
72
+ const getValue = () => {
73
+ return dtoValue.value
74
+ ? {
75
+ [props.schemaKey]: dtoValue.value,
76
+ }
77
+ : {};
78
+ };
79
+
80
+ const getAjv = inject("getAjv");
81
+ const validTip = ref("");
82
+
83
+ const validate = async () => {
84
+ validTip.value = "";
85
+ if (props.schema.option?.required && !dtoValue.value) {
86
+ validTip.value = `${props.schema.label}必填`;
87
+ return false;
88
+ }
89
+ if (dtoValue.value) {
90
+ const ajv = await getAjv();
91
+ const validate = ajv.compile(props.schema, {
92
+ enum: (props.schema?.option?.enumList || []).map((i) => i.value),
93
+ });
94
+ const valid = validate(dtoValue.value);
95
+ if (!valid && validate.errors && validate.errors[0]) {
96
+ const { keyword } = validate.errors[0];
97
+ switch (keyword) {
98
+ case "enum":
99
+ validTip.value = `${props.schema.label}取值超出枚举范围`;
100
+ break;
101
+ default:
102
+ validTip.value = `${props.schema.label}不符合要求`;
103
+ break;
104
+ }
105
+ return false;
106
+ }
107
+ }
108
+
109
+ return true;
110
+ };
111
+
112
+ const onChange = () => {
113
+ validTip.value = "";
114
+ };
115
+
116
+ function initData() {
117
+ dtoValue.value = props.model || props.schema.option?.default || undefined;
118
+ validTip.value = "";
119
+ }
120
+
121
+ onMounted(() => {
122
+ initData();
123
+ });
124
+
125
+ defineExpose({
126
+ getValue,
127
+ validate,
128
+ name,
129
+ });
130
+ </script>
131
+
132
+ <style scoped lang="less"></style>
@@ -0,0 +1,18 @@
1
+ import businessFormItemConfig from "$businessFormItemConfig";
2
+ export default {
3
+ input: {
4
+ loader: () =>
5
+ import(/* webpackChunkName: "schema-form-input" */ "./components/input/index.vue"),
6
+ },
7
+ select: {
8
+ loader: () =>
9
+ import(/* webpackChunkName: "schema-form-select" */ "./components/select/index.vue"),
10
+ },
11
+ inputNumber: {
12
+ loader: () =>
13
+ import(
14
+ /* webpackChunkName: "schema-form-input-number" */ "./components/input-number/index.vue"
15
+ ),
16
+ },
17
+ ...businessFormItemConfig,
18
+ };
@@ -0,0 +1,137 @@
1
+ <template>
2
+ <div
3
+ v-if="schema?.properties"
4
+ class="schema-from"
5
+ >
6
+ <template
7
+ v-for="(schemaValue, key) in schema.properties"
8
+ :key="key"
9
+ >
10
+ <component
11
+ :is="loadedComponentMap[schemaValue.option.comType]"
12
+ v-if="loadedComponentMap[schemaValue.option.comType]"
13
+ v-show="schemaValue.option?.visible !== false"
14
+ ref="componentRefList"
15
+ :schema-key="key"
16
+ :schema="schemaValue"
17
+ :model="model[key]"
18
+ ></component>
19
+ </template>
20
+ </div>
21
+ </template>
22
+
23
+ <script setup>
24
+ import { ref, provide, watch } from "vue";
25
+ import formItemConfig from "./form-item-cofnig";
26
+ const props = defineProps({
27
+ // type: object,
28
+ // properties: {
29
+ // [key]: {
30
+ // type: "",
31
+ // label: "",
32
+ // ...schema, //标准配置
33
+ // option: {
34
+ // uiComponentConfig: {}, // 表单控件配置
35
+ // comType: "", // 搜索组件类型枚举:input | select | dynamicSelect | dateRangePicker
36
+ // enumList: [], // 如果comType === select时,需要传enumList
37
+ // visible: true, // 字段是否在表格中渲染显示;仅显式配置false时隐藏(定义该开关的意义是考虑到DSL集成覆盖的问题)
38
+ // default: "", // 默认值
39
+ // disabled: true, // 是否禁用
40
+ // api: "", // comType === dynamicSelect时必填,下拉选项数据请求接口
41
+ // },
42
+ // },
43
+ // },
44
+ schema: {
45
+ type: Object,
46
+ default: () => ({}),
47
+ },
48
+ model: {
49
+ type: Object,
50
+ default: () => ({}),
51
+ },
52
+ });
53
+
54
+ let ajvPromise;
55
+ const getAjv = () => {
56
+ if (!ajvPromise) {
57
+ ajvPromise = import(/* webpackChunkName: "async-ajv" */ "ajv").then(
58
+ ({ default: Ajv }) => new Ajv(),
59
+ );
60
+ }
61
+ return ajvPromise;
62
+ };
63
+
64
+ provide("getAjv", getAjv);
65
+
66
+ const componentRefList = ref([]);
67
+ const loadedComponentMap = ref({});
68
+
69
+ const loadFormComponents = async () => {
70
+ const comTypeList = [
71
+ ...new Set(
72
+ Object.values(props.schema.properties || {})
73
+ .filter((item) => item.option?.visible !== false)
74
+ .map((item) => item.option?.comType)
75
+ .filter(Boolean),
76
+ ),
77
+ ];
78
+ const componentEntries = await Promise.all(
79
+ comTypeList.map(async (comType) => {
80
+ const config = formItemConfig[comType];
81
+ if (!config) return null;
82
+ const loadedModule = config.loader ? await config.loader() : null;
83
+ const component = config.component || loadedModule?.default;
84
+ return component ? [comType, component] : null;
85
+ }),
86
+ );
87
+ loadedComponentMap.value = Object.fromEntries(componentEntries.filter(Boolean));
88
+ };
89
+
90
+ watch(
91
+ () => props.schema,
92
+ async () => {
93
+ componentRefList.value = [];
94
+ loadedComponentMap.value = {};
95
+ await loadFormComponents();
96
+ },
97
+ { deep: true, immediate: true },
98
+ );
99
+
100
+ const validate = async () => {
101
+ const resultList = await Promise.all(componentRefList.value.map((item) => item.validate()));
102
+ return resultList.every(Boolean);
103
+ };
104
+
105
+ const getValue = () => {
106
+ return componentRefList.value.reduce((pre, item) => ({ ...pre, ...item.getValue() }), {});
107
+ };
108
+
109
+ defineExpose({
110
+ validate,
111
+ getValue,
112
+ });
113
+ </script>
114
+
115
+ <style lang="less">
116
+ // 统一管理子组件的样式
117
+ .schema-from {
118
+ .form-item {
119
+ .item-label {
120
+ margin-bottom: 12px;
121
+ }
122
+ .required {
123
+ color: red;
124
+ }
125
+ &:not(:first-child) {
126
+ margin-top: 12px;
127
+ }
128
+ .validate-border-error {
129
+ border: 1px solid red;
130
+ }
131
+ .validate-tip-error {
132
+ color: red;
133
+ margin-top: 10px;
134
+ }
135
+ }
136
+ }
137
+ </style>
@@ -0,0 +1,55 @@
1
+ <template>
2
+ <a-range-picker
3
+ v-model:value="selectValue"
4
+ style="width: 100%"
5
+ v-bind="antdFormItemConfig"
6
+ ></a-range-picker>
7
+ </template>
8
+
9
+ <script setup>
10
+ import { ref, onMounted, computed } from "vue";
11
+ const props = defineProps({
12
+ schemaKey: {
13
+ type: String,
14
+ default: "",
15
+ },
16
+ schema: {
17
+ type: Object,
18
+ default: () => ({}),
19
+ },
20
+ });
21
+
22
+ const emit = defineEmits(["load"]);
23
+
24
+ const antdFormItemConfig = computed(() => ({
25
+ allowClear: true,
26
+ ...(props.schema?.option?.uiComponentConfig || {}),
27
+ }));
28
+
29
+ const selectValue = ref([]);
30
+
31
+ const getValue = () => {
32
+ return selectValue.value !== undefined
33
+ ? {
34
+ [`${props.schemaKey}_start`]: selectValue.value[0] || "",
35
+ [`${props.schemaKey}_end`]: selectValue.value[1] || "",
36
+ }
37
+ : {};
38
+ };
39
+
40
+ const reset = () => {
41
+ selectValue.value = props.schema?.option?.default ?? [];
42
+ };
43
+
44
+ onMounted(() => {
45
+ reset();
46
+ emit("load");
47
+ });
48
+
49
+ defineExpose({
50
+ getValue,
51
+ reset,
52
+ });
53
+ </script>
54
+
55
+ <style scoped lang="less"></style>
@@ -0,0 +1,70 @@
1
+ <template>
2
+ <a-select
3
+ v-model:value="selectValue"
4
+ v-bind="antdFormItemConfig"
5
+ :options="enumList"
6
+ ></a-select>
7
+ </template>
8
+
9
+ <script setup>
10
+ import { ref, onMounted, computed } from "vue";
11
+ import { httpGet } from "$mintService";
12
+ const props = defineProps({
13
+ schemaKey: {
14
+ type: String,
15
+ default: "",
16
+ },
17
+ schema: {
18
+ type: Object,
19
+ default: () => ({}),
20
+ },
21
+ });
22
+
23
+ const emit = defineEmits(["load"]);
24
+
25
+ const antdFormItemConfig = computed(() => ({
26
+ allowClear: true,
27
+ placeholder: `请选择${props.schema?.label}`,
28
+ ...(props.schema?.option?.uiComponentConfig || {}),
29
+ }));
30
+
31
+ const selectValue = ref();
32
+
33
+ const getValue = () => {
34
+ return selectValue.value !== undefined
35
+ ? {
36
+ [props.schemaKey]: selectValue.value,
37
+ }
38
+ : {};
39
+ };
40
+
41
+ const reset = () => {
42
+ if (props.schema?.option?.default) {
43
+ selectValue.value = props.schema?.option?.default;
44
+ return;
45
+ }
46
+ if (antdFormItemConfig.value?.mode && antdFormItemConfig.value.mode === "multiple") {
47
+ selectValue.value = [];
48
+ return;
49
+ }
50
+ selectValue.value = undefined;
51
+ };
52
+
53
+ const enumList = ref([]);
54
+ const fetchEnumList = async () => {
55
+ const res = await httpGet(props.schema.option.api);
56
+ enumList.value = res.data;
57
+ };
58
+ onMounted(async () => {
59
+ reset();
60
+ await fetchEnumList();
61
+ emit("load");
62
+ });
63
+
64
+ defineExpose({
65
+ getValue,
66
+ reset,
67
+ });
68
+ </script>
69
+
70
+ <style scoped lang="less"></style>
@@ -0,0 +1,54 @@
1
+ <template>
2
+ <a-input
3
+ v-model:value="inputValue"
4
+ v-bind="antdFormItemConfig"
5
+ ></a-input>
6
+ </template>
7
+
8
+ <script setup>
9
+ import { ref, onMounted, computed } from "vue";
10
+ const props = defineProps({
11
+ schemaKey: {
12
+ type: String,
13
+ default: "",
14
+ },
15
+ schema: {
16
+ type: Object,
17
+ default: () => ({}),
18
+ },
19
+ });
20
+
21
+ const emit = defineEmits(["load"]);
22
+
23
+ const antdFormItemConfig = computed(() => ({
24
+ allowClear: true,
25
+ placeholder: `请输入${props.schema?.label}`,
26
+ ...(props.schema?.option?.uiComponentConfig || {}),
27
+ }));
28
+
29
+ const inputValue = ref();
30
+
31
+ const getValue = () => {
32
+ return inputValue.value !== undefined
33
+ ? {
34
+ [props.schemaKey]: inputValue.value,
35
+ }
36
+ : {};
37
+ };
38
+
39
+ const reset = () => {
40
+ inputValue.value = props.schema?.option?.default || undefined;
41
+ };
42
+
43
+ onMounted(() => {
44
+ reset();
45
+ emit("load");
46
+ });
47
+
48
+ defineExpose({
49
+ getValue,
50
+ reset,
51
+ });
52
+ </script>
53
+
54
+ <style scoped lang="less"></style>
@@ -0,0 +1,65 @@
1
+ <template>
2
+ <a-select
3
+ v-model:value="selectValue"
4
+ v-bind="antdFormItemConfig"
5
+ ></a-select>
6
+ </template>
7
+
8
+ <script setup>
9
+ import { ref, onMounted, computed } from "vue";
10
+ const props = defineProps({
11
+ schemaKey: {
12
+ type: String,
13
+ default: "",
14
+ },
15
+ schema: {
16
+ type: Object,
17
+ default: () => ({}),
18
+ },
19
+ });
20
+
21
+ const emit = defineEmits(["load"]);
22
+
23
+ const antdFormItemConfig = computed(() => {
24
+ return {
25
+ allowClear: true,
26
+ placeholder: `请选择${props.schema?.label}`,
27
+ ...(props.schema?.option?.uiComponentConfig || {}),
28
+ options: props.schema?.option?.enumList || [],
29
+ };
30
+ });
31
+
32
+ const selectValue = ref();
33
+
34
+ const getValue = () => {
35
+ return selectValue.value !== undefined
36
+ ? {
37
+ [props.schemaKey]: selectValue.value,
38
+ }
39
+ : {};
40
+ };
41
+
42
+ const reset = () => {
43
+ if (props.schema?.option?.default) {
44
+ selectValue.value = props.schema?.option?.default;
45
+ return;
46
+ }
47
+ if (antdFormItemConfig.value?.mode && antdFormItemConfig.value.mode === "multiple") {
48
+ selectValue.value = [];
49
+ return;
50
+ }
51
+ selectValue.value = undefined;
52
+ };
53
+
54
+ onMounted(() => {
55
+ reset();
56
+ emit("load");
57
+ });
58
+
59
+ defineExpose({
60
+ getValue,
61
+ reset,
62
+ });
63
+ </script>
64
+
65
+ <style scoped lang="less"></style>