feat(CRUD):表格公共搜索->对开关组件状态的搜索优化

This commit is contained in:
妙码生花 2022-06-30 20:54:34 +08:00
parent 6f90fb0035
commit 24112e2d78
2 changed files with 37 additions and 9 deletions

View File

@ -37,11 +37,13 @@ class Crud extends Command
'relationmodel' => ['name' => 'relationmodel', 'shortcut' => 'e', 'mode' => Option::VALUE_OPTIONAL | Option::VALUE_IS_ARRAY, 'description' => 'relation model name', 'default' => null, 'solveArray' => false, 'setInputRule' => false],
'relationforeignkey' => ['name' => 'relationforeignkey', 'shortcut' => 'k', 'mode' => Option::VALUE_OPTIONAL | Option::VALUE_IS_ARRAY, 'description' => 'relation foreign key', 'default' => null, 'solveArray' => false, 'setInputRule' => false],
'relationprimarykey' => ['name' => 'relationprimarykey', 'shortcut' => 'p', 'mode' => Option::VALUE_OPTIONAL | Option::VALUE_IS_ARRAY, 'description' => 'relation primary key', 'default' => null, 'solveArray' => false, 'setInputRule' => false],
'remoteselectfield' => ['name' => 'remoteselectfield', 'shortcut' => 's', 'mode' => Option::VALUE_OPTIONAL | Option::VALUE_IS_ARRAY, 'description' => 'Remote select table field', 'default' => null, 'solveArray' => false, 'setInputRule' => false],
'relationfields' => ['name' => 'relationfields', 'shortcut' => 'l', 'mode' => Option::VALUE_OPTIONAL | Option::VALUE_IS_ARRAY, 'description' => 'relation table fields', 'default' => null, 'solveArray' => false, 'setInputRule' => false],
'relationmode' => ['name' => 'relationmode', 'shortcut' => 'a', 'mode' => Option::VALUE_OPTIONAL | Option::VALUE_IS_ARRAY, 'description' => 'relation table mode,hasone or belongsto', 'default' => null, 'solveArray' => false, 'setInputRule' => false],
// 关联远程下拉select显示字段
'remoteselectfield' => ['name' => 'remoteselectfield', 'shortcut' => 's', 'mode' => Option::VALUE_OPTIONAL | Option::VALUE_IS_ARRAY, 'description' => 'relation table Remote select table field', 'default' => null, 'solveArray' => false, 'setInputRule' => false],
// 是否删除模式
'delete' => ['name' => 'delete', 'shortcut' => 'd', 'mode' => Option::VALUE_OPTIONAL, 'description' => 'delete all files generated by CRUD', 'default' => null, 'solveArray' => false, 'setInputRule' => false],
// 指定数据库
'db' => ['name' => 'db', 'shortcut' => null, 'mode' => Option::VALUE_OPTIONAL, 'description' => 'database config name', 'default' => 'mysql', 'solveArray' => false, 'setInputRule' => false],
// 快速搜索字段设置
'quicksearchfield' => ['name' => 'quicksearchfield', 'shortcut' => null, 'mode' => Option::VALUE_OPTIONAL | Option::VALUE_IS_ARRAY, 'description' => 'quick search field', 'default' => null, 'solveArray' => true, 'setInputRule' => false],
@ -505,7 +507,7 @@ class Crud extends Command
// 关联表主键
'relationPrimaryKey' => $relationPrimaryKey[$index] ?? 'id',
// 远程下拉字段
'remoteSelectField' => $remoteSelectField[$index] ?? '',
'remoteSelectField' => $remoteSelectField[$index] ?? '',
];
}
}
@ -1310,7 +1312,12 @@ class Crud extends Command
];
$column = array_merge($column, $extendAttr);
if (isset($column['render']) && ($column['render'] == 'tag' || $column['render'] == 'tags')) {
$columnReplaceValue = [
'tag',
'tags',
'switch',
];
if (isset($column['render']) && in_array($column['render'], $columnReplaceValue)) {
$column['replaceValue'] = $columnData;
}
return $column;
@ -1394,11 +1401,11 @@ class Crud extends Command
return false;
}
protected function getRemoteSelectField($fieldName, $relations=[])
protected function getRemoteSelectField($fieldName, $relations = [])
{
$field = explode('_', $fieldName);
foreach($relations as $relation){
if($relation['remoteSelectField'] && $relation['relationTableTypeName'] == $field[0]){
foreach ($relations as $relation) {
if ($relation['remoteSelectField'] && $relation['relationTableTypeName'] == $field[0]) {
return $relation['remoteSelectField'];
}
}

View File

@ -5,6 +5,7 @@
<el-row>
<template v-for="(item, idx) in baTable.table.column">
<template v-if="item.operator !== false">
<!-- 时间范围 -->
<el-col v-if="item.render == 'datetime' && (item.operator == 'RANGE' || item.operator == 'NOT RANGE')" :span="12">
<div class="com-search-col">
<div class="com-search-col-label w16">{{ item.label }}</div>
@ -25,6 +26,7 @@
<el-col v-else :span="6">
<div class="com-search-col">
<div class="com-search-col-label">{{ item.label }}</div>
<!-- 数字范围 -->
<div v-if="item.operator == 'RANGE' || item.operator == 'NOT RANGE'" class="com-search-col-input-range">
<el-input
:placeholder="item.operatorPlaceholder"
@ -38,10 +40,12 @@
v-model="baTable.comSearch.form[item.prop! + '-end']"
></el-input>
</div>
<!-- 是否 [NOT] NULL -->
<div v-else-if="item.operator == 'NULL' || item.operator == 'NOT NULL'" class="com-search-col-input">
<el-checkbox v-model="baTable.comSearch.form[item.prop!]" :label="item.operator" size="large"></el-checkbox>
</div>
<div v-else-if="item.operator" class="com-search-col-input">
<!-- 时间筛选 -->
<el-date-picker
class="datetime-picker"
v-if="item.render == 'datetime'"
@ -51,6 +55,8 @@
:placeholder="item.operatorPlaceholder"
:default-value="baTable.comSearch.form[item.prop! + '-default'] ? baTable.comSearch.form[item.prop! + '-default']:new Date()"
></el-date-picker>
<!-- tag -->
<el-select
:placeholder="item.operatorPlaceholder"
v-else-if="item.render == 'tag' && item.replaceValue"
@ -59,15 +65,29 @@
>
<el-option v-for="(opt, okey) in item.replaceValue" :key="item.prop! + okey" :label="opt" :value="okey" />
</el-select>
<!-- 开关 -->
<el-select
:placeholder="item.operatorPlaceholder"
v-else-if="item.render == 'switch'"
v-model="baTable.comSearch.form[item.prop!]"
:clearable="true"
>
<el-option :label="$t('utils.open')" value="1" />
<el-option :label="$t('utils.close')" value="0" />
<template v-if="!isEmpty(item.replaceValue)">
<el-option
v-for="(opt, okey) in item.replaceValue"
:key="item.prop! + okey"
:label="opt"
:value="okey"
/>
</template>
<template v-else>
<el-option :label="$t('utils.open')" value="1" />
<el-option :label="$t('utils.close')" value="0" />
</template>
</el-select>
<!-- 字符串 -->
<el-input
:placeholder="item.operatorPlaceholder"
v-else
@ -95,6 +115,7 @@
import { inject } from 'vue'
import useCurrentInstance from '/@/utils/useCurrentInstance'
import type baTableClass from '/@/utils/baTable'
import { isEmpty } from 'lodash'
const { proxy } = useCurrentInstance()