Skip to content

Commit

Permalink
feat(schema): support isDirect in filter
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Aug 28, 2023
1 parent ca16982 commit 86e2f42
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
2 changes: 0 additions & 2 deletions packages/client/client/components/layout/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import Empty from './empty.vue'
import TabGroup from './tab-group.vue'
import TabItem from './tab-item.vue'

export * from './utils'

export default function (app: App) {
app.component('k-numeric', CardNumeric)
app.component('k-card', Card)
Expand Down
Empty file.
25 changes: 19 additions & 6 deletions packages/components/client/form/k-filter-expr.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@
<el-option v-if="isValid(key)" :label="name" :value="key"></el-option>
</template>
</el-select>
<el-select class="operator" :disabled="disabled" v-model="operator">
<el-option v-for="key in availableOps" :key="key" :label="operators[key]" :value="key"></el-option>
</el-select>
<el-input :disabled="disabled" :key="type" :type="type" class="value" v-model="value"></el-input>
<template v-if="entity === 'isDirect'">
<el-switch v-model="boolean"></el-switch>
</template>
<template v-else-if="entity">
<el-select class="operator" :disabled="disabled" v-model="operator">
<el-option v-for="key in availableOps" :key="key" :label="operators[key]" :value="key"></el-option>
</el-select>
<el-input :disabled="disabled" :key="type" :type="type" class="value" v-model="value"></el-input>
</template>
</div>
</template>

Expand All @@ -30,6 +35,7 @@ const emit = defineEmits(['update:modelValue'])
const entity = ref<string>()
const operator = ref<string>()
const value = ref<any>()
const boolean = ref<boolean>(false)
function isValid(key: string) {
if (key.startsWith('user.')) {
Expand All @@ -40,6 +46,7 @@ function isValid(key: string) {
}
const entities = {
'isDirect': '是否私聊',
'userId': '用户 ID',
'guildId': '群组 ID',
'channelId': '频道 ID',
Expand Down Expand Up @@ -87,8 +94,14 @@ watch(entity, () => {
}
})
watch([entity, operator, value], ([entity, operator, value]) => {
if (!entities[entity] || !operators[operator] || !value) return
watch([entity, operator, value, boolean], ([entity, operator, value, boolean]) => {
if (!entities[entity]) return
if (entity === 'isDirect') {
return emit('update:modelValue', {
$eq: [{ $: entity }, boolean],
})
}
if (!operators[operator] || !value) return
let result: any = value
if (['$in', '$nin'].includes(operator)) {
result = value.split(/\s*,\s*/g).filter(Boolean)
Expand Down

0 comments on commit 86e2f42

Please sign in to comment.