From 8991907227d2ff5bfc7488a29b855b14d8fc2198 Mon Sep 17 00:00:00 2001
From: Shigma <1700011071@pku.edu.cn>
Date: Tue, 8 Feb 2022 02:06:09 +0800
Subject: [PATCH] feat(components): support input number schema
---
packages/core/src/app.ts | 10 ++----
.../components/client/common/index.ts | 2 --
.../components/client/form/primitive.vue | 31 ++++++++++---------
.../components/client/form/schema.vue | 4 +--
.../frontend/components/client/form/union.vue | 2 +-
plugins/frontend/components/client/index.ts | 24 ++++++++++++++
plugins/frontend/components/client/style.scss | 5 +++
plugins/frontend/components/tsconfig.json | 1 +
plugins/frontend/console/client/index.scss | 4 ---
plugins/frontend/console/client/main.ts | 8 -----
plugins/frontend/console/client/tsconfig.json | 1 +
11 files changed, 53 insertions(+), 39 deletions(-)
create mode 100644 plugins/frontend/components/client/style.scss
diff --git a/packages/core/src/app.ts b/packages/core/src/app.ts
index fb6ae15cd0..1530005879 100644
--- a/packages/core/src/app.ts
+++ b/packages/core/src/app.ts
@@ -277,14 +277,8 @@ export namespace App {
Schema.array(Schema.string()),
Schema.transform(Schema.string(), (nickname) => [nickname]),
] as const).description('机器人的昵称,可以是字符串或字符串数组。将用于指令前缀的匹配。'),
- autoAssign: Schema.union([
- Schema.boolean(),
- Schema.function(),
- ] as const).default(true).description('当获取不到频道数据时,是否使用接受者作为代理者。'),
- autoAuthorize: Schema.union([
- Schema.natural(),
- Schema.function(),
- ] as const).default(1).description('当获取不到用户数据时默认使用的权限等级。'),
+ autoAssign: Schema.union([Boolean, Function]).default(true).description('当获取不到频道数据时,是否使用接受者作为代理者。'),
+ autoAuthorize: Schema.union([Schema.natural(), Function]).default(1).description('当获取不到用户数据时默认使用的权限等级。'),
minSimilarity: Schema.percent().default(0.4).description('用于模糊匹配的相似系数,应该是一个 0 到 1 之间的数值。数值越高,模糊匹配越严格。设置为 1 可以完全禁用模糊匹配。'),
}).description('基础设置'))
diff --git a/plugins/frontend/components/client/common/index.ts b/plugins/frontend/components/client/common/index.ts
index 0b7ff2ad2f..a3fa851c5b 100644
--- a/plugins/frontend/components/client/common/index.ts
+++ b/plugins/frontend/components/client/common/index.ts
@@ -2,7 +2,6 @@ import { App } from 'vue'
import Button from './button.vue'
import Checkbox from './checkbox.vue'
import Input from './input.vue'
-import Switch from './switch.vue'
import Radio from './radio.vue'
export default function (app: App) {
@@ -10,5 +9,4 @@ export default function (app: App) {
app.component('k-checkbox', Checkbox)
app.component('k-input', Input)
app.component('k-radio', Radio)
- app.component('k-switch', Switch)
}
diff --git a/plugins/frontend/components/client/form/primitive.vue b/plugins/frontend/components/client/form/primitive.vue
index ad82bd4284..d8993c4617 100644
--- a/plugins/frontend/components/client/form/primitive.vue
+++ b/plugins/frontend/components/client/form/primitive.vue
@@ -5,18 +5,21 @@
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
@@ -38,8 +41,8 @@ const props = defineProps({
const showPass = ref(false)
-const config = computed({
- get: () => props.modelValue,
+const value = computed({
+ get: () => props.modelValue ?? props.schema.meta.default,
set: emit.bind(null, 'update:modelValue'),
})
diff --git a/plugins/frontend/components/client/form/schema.vue b/plugins/frontend/components/client/form/schema.vue
index e6e502892e..540feedb13 100644
--- a/plugins/frontend/components/client/form/schema.vue
+++ b/plugins/frontend/components/client/form/schema.vue
@@ -111,7 +111,7 @@ function isPrimitive(schema: Schema) {
.schema-item {
padding: 0.5rem 1rem;
border-bottom: 1px solid var(--border);
- transition: border-color 0.3s ease;
+ transition: border-color 0.3s ease, background-color 0.3s ease;
&:first-child, :not(.schema-item) + & {
border-top: 1px solid var(--border);
@@ -126,7 +126,7 @@ function isPrimitive(schema: Schema) {
}
&:hover {
- background: var(--bg2);
+ background-color: var(--bg1);
}
.schema-header {
diff --git a/plugins/frontend/components/client/form/union.vue b/plugins/frontend/components/client/form/union.vue
index 9967410a73..8e6a222d7f 100644
--- a/plugins/frontend/components/client/form/union.vue
+++ b/plugins/frontend/components/client/form/union.vue
@@ -47,7 +47,7 @@ const props = defineProps({
})
const config = computed({
- get: () => props.modelValue,
+ get: () => props.modelValue ?? props.schema.meta.default,
set: emit.bind(null, 'update:modelValue'),
})
diff --git a/plugins/frontend/components/client/index.ts b/plugins/frontend/components/client/index.ts
index c6a8e2b5e2..c4af15d11f 100644
--- a/plugins/frontend/components/client/index.ts
+++ b/plugins/frontend/components/client/index.ts
@@ -1,10 +1,24 @@
import { App } from 'vue'
+import {
+ ElInput,
+ ElInputNumber,
+ ElEmpty,
+ ElTooltip,
+ ElScrollbar,
+ ElSelect,
+ ElSlider,
+ ElSwitch,
+ ElTree,
+} from 'element-plus'
+
import common from './common'
import form from './form'
import icons from './icons'
import layout from './layout'
import notice from './notice'
+export { ElMessage as message } from 'element-plus'
+
export * from './common'
export * from './form'
export * from './icons'
@@ -12,6 +26,16 @@ export * from './layout'
export * from './notice'
export default function (app: App) {
+ app.use(ElInput)
+ app.use(ElInputNumber)
+ app.use(ElEmpty)
+ app.use(ElTooltip)
+ app.use(ElScrollbar)
+ app.use(ElSelect)
+ app.use(ElSlider)
+ app.use(ElSwitch)
+ app.use(ElTree)
+
app.use(common)
app.use(form)
app.use(icons)
diff --git a/plugins/frontend/components/client/style.scss b/plugins/frontend/components/client/style.scss
new file mode 100644
index 0000000000..6020022abd
--- /dev/null
+++ b/plugins/frontend/components/client/style.scss
@@ -0,0 +1,5 @@
+
+
+.el-scrollbar__bar {
+ z-index: 500;
+}
diff --git a/plugins/frontend/components/tsconfig.json b/plugins/frontend/components/tsconfig.json
index 8b4835b4ac..90bccaf4b6 100644
--- a/plugins/frontend/components/tsconfig.json
+++ b/plugins/frontend/components/tsconfig.json
@@ -8,6 +8,7 @@
"emitDeclarationOnly": false,
"types": [
"vite/client",
+ "element-plus/global",
],
},
"include": [
diff --git a/plugins/frontend/console/client/index.scss b/plugins/frontend/console/client/index.scss
index 2aad6fd480..8d05a7e0c2 100644
--- a/plugins/frontend/console/client/index.scss
+++ b/plugins/frontend/console/client/index.scss
@@ -81,10 +81,6 @@ html.dark {
height: 100%;
}
-.el-scrollbar__bar {
- z-index: 500;
-}
-
.k-menu-item {
display: block;
position: relative;
diff --git a/plugins/frontend/console/client/main.ts b/plugins/frontend/console/client/main.ts
index 8eab825209..022bc1ba9e 100644
--- a/plugins/frontend/console/client/main.ts
+++ b/plugins/frontend/console/client/main.ts
@@ -8,19 +8,11 @@ import App from './layout/index.vue'
import Blank from './layout/blank.vue'
import client from '~/components'
-import { ElCascader, ElEmpty, ElTooltip, ElScrollbar, ElSelect, ElTree } from 'element-plus'
-
import 'element-plus/dist/index.css'
import './index.scss'
const app = createApp(App)
-app.use(ElCascader)
-app.use(ElEmpty)
-app.use(ElTooltip)
-app.use(ElSelect)
-app.use(ElScrollbar)
-app.use(ElTree)
app.use(client)
app.component('k-collapse', Collapse)
diff --git a/plugins/frontend/console/client/tsconfig.json b/plugins/frontend/console/client/tsconfig.json
index db9d9a608d..8876b6f702 100644
--- a/plugins/frontend/console/client/tsconfig.json
+++ b/plugins/frontend/console/client/tsconfig.json
@@ -8,6 +8,7 @@
"emitDeclarationOnly": false,
"types": [
"vite/client",
+ "element-plus/global",
],
},
"include": [