From 6d37fb51cf419a2bef84e3c17300ea6f708da141 Mon Sep 17 00:00:00 2001 From: lijiahang Date: Sat, 7 Oct 2023 18:55:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8D=A1=E7=89=87=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ops/launch/generator/template/Table.java | 5 + .../generator/template/VueTemplate.java | 10 + ...server-module-entity-request-query.java.vm | 3 + .../orion-server-module-service-impl.java.vm | 13 +- .../resources/templates/orion-vue-api.ts.vm | 1 + ...vue-views-components-host-card-list.vue.vm | 181 ++++++++++++++++++ .../orion-vue-views-components-table.vue.vm | 10 +- .../templates/orion-vue-views-index.vue.vm | 57 +++++- .../orion-vue-views-types-card.fields.ts.vm | 22 +++ .../entity/request/host/HostQueryRequest.java | 3 + .../asset/service/impl/HostServiceImpl.java | 9 +- .../src/components/card/list/index.vue | 6 +- orion-ops-ui/src/types/card.ts | 6 +- .../asset/host/components/host-card-list.vue | 6 +- orion-ops-ui/src/views/asset/host/index.vue | 4 +- .../src/views/asset/host/types/card.fields.ts | 2 +- 16 files changed, 315 insertions(+), 23 deletions(-) create mode 100644 orion-ops-launch/src/main/resources/templates/orion-vue-views-components-host-card-list.vue.vm create mode 100644 orion-ops-launch/src/main/resources/templates/orion-vue-views-types-card.fields.ts.vm diff --git a/orion-ops-launch/src/main/java/com/orion/ops/launch/generator/template/Table.java b/orion-ops-launch/src/main/java/com/orion/ops/launch/generator/template/Table.java index bee5e18d..0ac46631 100644 --- a/orion-ops-launch/src/main/java/com/orion/ops/launch/generator/template/Table.java +++ b/orion-ops-launch/src/main/java/com/orion/ops/launch/generator/template/Table.java @@ -100,6 +100,11 @@ public class Table { */ protected boolean enableRowSelection; + /** + * 使用卡片视图 + */ + protected boolean enableCardView; + /** * 生成的枚举文件 */ diff --git a/orion-ops-launch/src/main/java/com/orion/ops/launch/generator/template/VueTemplate.java b/orion-ops-launch/src/main/java/com/orion/ops/launch/generator/template/VueTemplate.java index f2a059b0..562a2488 100644 --- a/orion-ops-launch/src/main/java/com/orion/ops/launch/generator/template/VueTemplate.java +++ b/orion-ops-launch/src/main/java/com/orion/ops/launch/generator/template/VueTemplate.java @@ -63,6 +63,16 @@ public class VueTemplate extends Template { return this; } + /** + * 启用卡片列表 + * + * @return this + */ + public VueTemplate enableCardView() { + table.enableCardView = true; + return this; + } + /** * 设置枚举 * diff --git a/orion-ops-launch/src/main/resources/templates/orion-server-module-entity-request-query.java.vm b/orion-ops-launch/src/main/resources/templates/orion-server-module-entity-request-query.java.vm index 26ae9d80..f4a3cbd6 100644 --- a/orion-ops-launch/src/main/resources/templates/orion-server-module-entity-request-query.java.vm +++ b/orion-ops-launch/src/main/resources/templates/orion-server-module-entity-request-query.java.vm @@ -23,6 +23,9 @@ import java.math.*; @EqualsAndHashCode(callSuper = true) @Schema(name = "${type}QueryRequest", description = "$!{table.comment} 查询请求对象") public class ${type}QueryRequest extends PageRequest { + + @Schema(description = "搜索") + private String searchValue; #foreach($field in ${table.fields}) #if("$field.propertyType" == "String" && "$field.metaInfo.jdbcType" != "LONGVARCHAR") diff --git a/orion-ops-launch/src/main/resources/templates/orion-server-module-service-impl.java.vm b/orion-ops-launch/src/main/resources/templates/orion-server-module-service-impl.java.vm index c0862706..f071d48d 100644 --- a/orion-ops-launch/src/main/resources/templates/orion-server-module-service-impl.java.vm +++ b/orion-ops-launch/src/main/resources/templates/orion-server-module-service-impl.java.vm @@ -3,6 +3,7 @@ package ${package.ServiceImpl}; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.orion.lang.define.wrapper.DataGrid; +import com.orion.lang.utils.Strings; #if($cacheMeta.enableCache) import com.orion.ops.framework.common.constant.Const; #end @@ -262,10 +263,16 @@ public class ${table.serviceImplName} implements ${table.serviceName} { * @return wrapper */ private LambdaQueryWrapper<${type}DO> buildQueryWrapper(${type}QueryRequest request) { + String searchValue = request.getSearchValue(); return ${typeLower}DAO.wrapper() - #foreach($field in ${table.fields}) - .eq(${type}DO::get${field.capitalName}, request.get${field.capitalName}())#if(!$foreach.hasNext);#end - #end + #foreach($field in ${table.fields}) + .eq(${type}DO::get${field.capitalName}, request.get${field.capitalName}()) + #end + .and(Strings.isNotEmpty(searchValue), c -> c + #foreach($field in ${table.fields}) + .eq(${type}DO::get${field.capitalName}, searchValue) + #end + ); } } diff --git a/orion-ops-launch/src/main/resources/templates/orion-vue-api.ts.vm b/orion-ops-launch/src/main/resources/templates/orion-vue-api.ts.vm index a385001a..8e4b4240 100644 --- a/orion-ops-launch/src/main/resources/templates/orion-vue-api.ts.vm +++ b/orion-ops-launch/src/main/resources/templates/orion-vue-api.ts.vm @@ -33,6 +33,7 @@ export interface ${vue.featureEntity}UpdateRequest extends ${vue.featureEntity}C * ${table.comment}查询请求 */ export interface ${vue.featureEntity}QueryRequest extends Pagination { + searchValue?: string; #foreach($field in ${table.fields}) #if("$field.propertyType" == "String" || "$field.propertyType" == "Date") ${field.propertyName}?: string; diff --git a/orion-ops-launch/src/main/resources/templates/orion-vue-views-components-host-card-list.vue.vm b/orion-ops-launch/src/main/resources/templates/orion-vue-views-components-host-card-list.vue.vm new file mode 100644 index 00000000..b5fe97a5 --- /dev/null +++ b/orion-ops-launch/src/main/resources/templates/orion-vue-views-components-host-card-list.vue.vm @@ -0,0 +1,181 @@ + + + + + + + diff --git a/orion-ops-launch/src/main/resources/templates/orion-vue-views-components-table.vue.vm b/orion-ops-launch/src/main/resources/templates/orion-vue-views-components-table.vue.vm index 70d655b0..7039b3b0 100644 --- a/orion-ops-launch/src/main/resources/templates/orion-vue-views-components-table.vue.vm +++ b/orion-ops-launch/src/main/resources/templates/orion-vue-views-components-table.vue.vm @@ -133,13 +133,13 @@ diff --git a/orion-ops-launch/src/main/resources/templates/orion-vue-views-types-card.fields.ts.vm b/orion-ops-launch/src/main/resources/templates/orion-vue-views-types-card.fields.ts.vm new file mode 100644 index 00000000..7e3e714d --- /dev/null +++ b/orion-ops-launch/src/main/resources/templates/orion-vue-views-types-card.fields.ts.vm @@ -0,0 +1,22 @@ +import { CardField, CardFieldConfig } from '@/types/card'; +import { dateFormat } from '@/utils'; + +export const fieldConfig = { + rowGap: '10px', + labelSpan: 8, + fields: [ + #foreach($field in ${table.fields}){ + label: '${field.comment}', + dataIndex: '${field.propertyName}', + slotName: '${field.propertyName}', + #if(${field.propertyType} == 'String') + ellipsis: true, + #elseif(${field.propertyType} == 'Date') + render: ({ record }) => { + return record.${field.propertyName} && dateFormat(new Date(record.${field.propertyName})); + }, + #end + }, #end + ] as CardField[] +} as CardFieldConfig; +export default fieldConfig; diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/host/HostQueryRequest.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/host/HostQueryRequest.java index 5426ab5e..0438698c 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/host/HostQueryRequest.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/host/HostQueryRequest.java @@ -22,6 +22,9 @@ import java.util.List; @Schema(name = "HostQueryRequest", description = "主机 查询请求对象") public class HostQueryRequest extends PageRequest { + @Schema(description = "搜索") + private String searchValue; + @Schema(description = "id") private Long id; diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/HostServiceImpl.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/HostServiceImpl.java index c55982e4..0c0788b5 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/HostServiceImpl.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/HostServiceImpl.java @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.orion.lang.define.wrapper.DataGrid; import com.orion.lang.utils.Booleans; +import com.orion.lang.utils.Strings; import com.orion.lang.utils.collect.Lists; import com.orion.ops.framework.common.constant.ErrorMessage; import com.orion.ops.framework.common.utils.Valid; @@ -249,11 +250,17 @@ public class HostServiceImpl implements HostService { } } // 基础条件 + String searchValue = request.getSearchValue(); LambdaQueryWrapper wrapper = hostDAO.wrapper() .eq(HostDO::getId, request.getId()) .like(HostDO::getName, request.getName()) .like(HostDO::getCode, request.getCode()) - .like(HostDO::getAddress, request.getAddress()); + .like(HostDO::getAddress, request.getAddress()) + .and(Strings.isNotEmpty(searchValue), c -> c + .like(HostDO::getName, searchValue) + .like(HostDO::getCode, searchValue) + .like(HostDO::getAddress, searchValue) + ); if (setIdList) { wrapper.in(HostDO::getId, idList); } diff --git a/orion-ops-ui/src/components/card/list/index.vue b/orion-ops-ui/src/components/card/list/index.vue index f00d6278..94f17d89 100644 --- a/orion-ops-ui/src/components/card/list/index.vue +++ b/orion-ops-ui/src/components/card/list/index.vue @@ -163,10 +163,12 @@ ]"> - {{ item[field.dataIndex] }} + + {{ item[field.dataIndex] }} diff --git a/orion-ops-ui/src/types/card.ts b/orion-ops-ui/src/types/card.ts index ac307fd3..3dc8e5bc 100644 --- a/orion-ops-ui/src/types/card.ts +++ b/orion-ops-ui/src/types/card.ts @@ -1,5 +1,5 @@ import { PaginationProps, ResponsiveValue } from '@arco-design/web-vue'; -import { reactive } from 'vue'; +import { reactive, VNodeChild } from 'vue'; /** * 字段对齐方式 @@ -48,6 +48,10 @@ export interface CardField { valueClass?: string; ellipsis?: boolean; tooltip?: boolean; + render?: (data: { + record: CardRecord; + index: number; + }) => VNodeChild; } /** diff --git a/orion-ops-ui/src/views/asset/host/components/host-card-list.vue b/orion-ops-ui/src/views/asset/host/components/host-card-list.vue index 0e4c4a05..02863e40 100644 --- a/orion-ops-ui/src/views/asset/host/components/host-card-list.vue +++ b/orion-ops-ui/src/views/asset/host/components/host-card-list.vue @@ -59,7 +59,9 @@ 配置 - + 删除 @@ -111,7 +113,7 @@ diff --git a/orion-ops-ui/src/views/asset/host/index.vue b/orion-ops-ui/src/views/asset/host/index.vue index 61f2b8ce..3efef31c 100644 --- a/orion-ops-ui/src/views/asset/host/index.vue +++ b/orion-ops-ui/src/views/asset/host/index.vue @@ -44,8 +44,7 @@ const appStore = useAppStore(); const cacheStore = useCacheStore(); - // FIXME 临时 - const renderTable = computed(() => appStore.hostView === 'card'); + const renderTable = computed(() => appStore.hostView === 'table'); // 添加回调 const modalAddCallback = () => { @@ -58,7 +57,6 @@ // 修改回调 const modalUpdateCallback = () => { - console.log(renderTable.value); if (renderTable.value) { table.value.updatedCallback(); } else { diff --git a/orion-ops-ui/src/views/asset/host/types/card.fields.ts b/orion-ops-ui/src/views/asset/host/types/card.fields.ts index 076c81c2..3662dee5 100644 --- a/orion-ops-ui/src/views/asset/host/types/card.fields.ts +++ b/orion-ops-ui/src/views/asset/host/types/card.fields.ts @@ -18,7 +18,7 @@ export const fieldConfig = { label: '主机标签', dataIndex: 'tags', slotName: 'tags', - rowAlign: 'start' + rowAlign: 'start', }, ] as CardField[] } as CardFieldConfig;