From ffa47c37fad36d274c2bc264f15f27c36960681d Mon Sep 17 00:00:00 2001 From: xlsea Date: Tue, 17 Jun 2025 14:01:41 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix(projects):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E6=9F=A5=E8=AF=A2=E5=8F=82=E6=95=B0=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/business/download.ts | 15 ++++------ src/utils/common.ts | 28 +++++++++++++++++++ src/views/demo/demo/modules/demo-search.vue | 1 - src/views/demo/tree/modules/tree-search.vue | 1 - .../logininfor/modules/login-infor-search.vue | 12 +++++--- .../operlog/modules/oper-log-search.vue | 12 +++++--- .../system/config/modules/config-search.vue | 12 +++++--- src/views/system/oss/modules/oss-search.vue | 12 +++++--- src/views/system/role/modules/role-search.vue | 12 +++++--- .../modules/tenant-package-search.vue | 1 - src/views/system/user/modules/user-search.vue | 12 +++++--- .../tool/gen/modules/gen-table-search.vue | 12 +++++--- 12 files changed, 89 insertions(+), 41 deletions(-) diff --git a/src/hooks/business/download.ts b/src/hooks/business/download.ts index 5550cca7..cc20ff46 100644 --- a/src/hooks/business/download.ts +++ b/src/hooks/business/download.ts @@ -1,6 +1,7 @@ import { errorCodeRecord } from '@/constants/common'; import { localStg } from '@/utils/storage'; import { getServiceBaseURL } from '@/utils/service'; +import { transformToURLSearchParams } from '@/utils/common'; export function useDownload() { const isHttpProxy = import.meta.env.DEV && import.meta.env.VITE_HTTP_PROXY === 'Y'; @@ -24,26 +25,20 @@ export function useDownload() { window.URL.revokeObjectURL(blobURL); } - function download(url: string, params: any, fileName: string) { + function download(url: string, params: Record, fileName: string) { window.$loading?.startLoading('正在下载数据,请稍候...'); const token = localStg.get('token'); const clientId = import.meta.env.VITE_APP_CLIENT_ID; const now = Date.now(); - const searchParams = new FormData(); - if (params) { - Object.keys(params).forEach(key => { - if (params[key] !== null && params[key] !== undefined) { - searchParams.append(key, params[key]); - } - }); - } + const searchParams = transformToURLSearchParams(params); + fetch(`${baseURL}${url}?t=${now}`, { method: 'post', body: searchParams, headers: { Authorization: `Bearer ${token}`, Clientid: clientId!, - 'Content-Type': 'application/octet-stream' + 'Content-Type': 'application/x-www-form-urlencoded' } }) .then(async response => { diff --git a/src/utils/common.ts b/src/utils/common.ts index b5489f37..497a9b9a 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -163,3 +163,31 @@ export const handleTree = >(data: T[], config: Com return tree; }; + +/** + * 将对象转换为 URLSearchParams + * + * @param obj + */ +export function transformToURLSearchParams(obj: Record, excludeKeys: string[] = []) { + const searchParams = new URLSearchParams(); + if (!isNotNull(obj)) { + return searchParams; + } + Object.entries(obj).forEach(([key, value]) => { + if (excludeKeys.includes(key)) { + return; + } + if (typeof value === 'object') { + transformToURLSearchParams(value).forEach((v, k) => { + searchParams.append(`${key}[${k}]`, v); + }); + return; + } + if (!isNotNull(value)) { + return; + } + searchParams.append(key, value); + }); + return searchParams; +} diff --git a/src/views/demo/demo/modules/demo-search.vue b/src/views/demo/demo/modules/demo-search.vue index 9ba55bc4..93c6aa30 100644 --- a/src/views/demo/demo/modules/demo-search.vue +++ b/src/views/demo/demo/modules/demo-search.vue @@ -18,7 +18,6 @@ const { formRef, validate, restoreValidation } = useNaiveForm(); const model = defineModel('model', { required: true }); async function reset() { - Object.assign(model.value.params!, {}); await restoreValidation(); emit('reset'); } diff --git a/src/views/demo/tree/modules/tree-search.vue b/src/views/demo/tree/modules/tree-search.vue index 6c00e484..019988be 100644 --- a/src/views/demo/tree/modules/tree-search.vue +++ b/src/views/demo/tree/modules/tree-search.vue @@ -25,7 +25,6 @@ const { formRef, validate, restoreValidation } = useNaiveForm(); const model = defineModel('model', { required: true }); async function reset() { - Object.assign(model.value.params!, {}); await restoreValidation(); emit('reset'); } diff --git a/src/views/monitor/logininfor/modules/login-infor-search.vue b/src/views/monitor/logininfor/modules/login-infor-search.vue index 0192899b..6b4a3e04 100644 --- a/src/views/monitor/logininfor/modules/login-infor-search.vue +++ b/src/views/monitor/logininfor/modules/login-infor-search.vue @@ -20,6 +20,13 @@ const dateRangeLoginTime = ref<[string, string] | null>(null); const model = defineModel('model', { required: true }); +function onDateRangeLoginTimeUpdate(value: [string, string] | null) { + if (value?.length) { + model.value.params!.beginTime = value[0]; + model.value.params!.endTime = value[1]; + } +} + async function reset() { dateRangeLoginTime.value = null; await restoreValidation(); @@ -28,10 +35,6 @@ async function reset() { async function search() { await validate(); - if (dateRangeLoginTime.value?.length) { - model.value.params!.beginTime = dateRangeLoginTime.value[0]; - model.value.params!.endTime = dateRangeLoginTime.value[1]; - } emit('search'); } @@ -62,6 +65,7 @@ async function search() { type="datetimerange" value-format="yyyy-MM-dd HH:mm:ss" clearable + @update:formatted-value="onDateRangeLoginTimeUpdate" /> diff --git a/src/views/monitor/operlog/modules/oper-log-search.vue b/src/views/monitor/operlog/modules/oper-log-search.vue index 69b4077a..6c9cf8a2 100644 --- a/src/views/monitor/operlog/modules/oper-log-search.vue +++ b/src/views/monitor/operlog/modules/oper-log-search.vue @@ -20,6 +20,13 @@ const dateRangeOperTime = ref<[string, string] | null>(null); const model = defineModel('model', { required: true }); +function onDateRangeOperTimeUpdate(value: [string, string] | null) { + if (value?.length) { + model.value.params!.beginTime = value[0]; + model.value.params!.endTime = value[1]; + } +} + async function reset() { dateRangeOperTime.value = null; await restoreValidation(); @@ -28,10 +35,6 @@ async function reset() { async function search() { await validate(); - if (dateRangeOperTime.value?.length) { - model.value.params!.beginTime = dateRangeOperTime.value[0]; - model.value.params!.endTime = dateRangeOperTime.value[1]; - } emit('search'); } @@ -73,6 +76,7 @@ async function search() { type="datetimerange" value-format="yyyy-MM-dd HH:mm:ss" clearable + @update:formatted-value="onDateRangeOperTimeUpdate" /> diff --git a/src/views/system/config/modules/config-search.vue b/src/views/system/config/modules/config-search.vue index fa04b1a1..e75b10e3 100644 --- a/src/views/system/config/modules/config-search.vue +++ b/src/views/system/config/modules/config-search.vue @@ -20,6 +20,13 @@ const dateRangeCreateTime = ref<[string, string] | null>(null); const model = defineModel('model', { required: true }); +function onDateRangeCreateTimeUpdate(value: [string, string] | null) { + if (value?.length) { + model.value.params!.beginTime = value[0]; + model.value.params!.endTime = value[1]; + } +} + async function reset() { dateRangeCreateTime.value = null; await restoreValidation(); @@ -28,10 +35,6 @@ async function reset() { async function search() { await validate(); - if (dateRangeCreateTime.value?.length) { - model.value.params!.beginTime = dateRangeCreateTime.value[0]; - model.value.params!.endTime = dateRangeCreateTime.value[1]; - } emit('search'); } @@ -80,6 +83,7 @@ async function search() { type="datetimerange" value-format="yyyy-MM-dd HH:mm:ss" clearable + @update:formatted-value="onDateRangeCreateTimeUpdate" /> diff --git a/src/views/system/oss/modules/oss-search.vue b/src/views/system/oss/modules/oss-search.vue index a26a6036..f13f5f8a 100644 --- a/src/views/system/oss/modules/oss-search.vue +++ b/src/views/system/oss/modules/oss-search.vue @@ -20,6 +20,13 @@ const dateRangeCreateTime = ref<[string, string] | null>(null); const model = defineModel('model', { required: true }); +function onDateRangeCreateTimeUpdate(value: [string, string] | null) { + if (value?.length) { + model.value.params!.beginCreateTime = value[0]; + model.value.params!.endCreateTime = value[1]; + } +} + async function reset() { dateRangeCreateTime.value = null; await restoreValidation(); @@ -28,10 +35,6 @@ async function reset() { async function search() { await validate(); - if (dateRangeCreateTime.value?.length) { - model.value.params!.beginCreateTime = dateRangeCreateTime.value[0]; - model.value.params!.endCreateTime = dateRangeCreateTime.value[1]; - } emit('search'); } @@ -60,6 +63,7 @@ async function search() { type="datetimerange" value-format="yyyy-MM-dd HH:mm:ss" clearable + @update:formatted-value="onDateRangeCreateTimeUpdate" /> diff --git a/src/views/system/role/modules/role-search.vue b/src/views/system/role/modules/role-search.vue index 04283a87..7b3db1be 100644 --- a/src/views/system/role/modules/role-search.vue +++ b/src/views/system/role/modules/role-search.vue @@ -23,6 +23,13 @@ const model = defineModel('model', { required: true const { options: sysNormalDisableOptions } = useDict('sys_normal_disable'); +function onDateRangeCreateTimeUpdate(value: [string, string] | null) { + if (value?.length) { + model.value.params!.beginTime = `${value[0]} 00:00:00`; + model.value.params!.endTime = `${value[1]} 23:59:59`; + } +} + async function reset() { dateRangeCreateTime.value = null; await restoreValidation(); @@ -31,10 +38,6 @@ async function reset() { async function search() { await validate(); - if (dateRangeCreateTime.value?.length) { - model.value.params!.beginTime = `${dateRangeCreateTime.value[0]} 00:00:00`; - model.value.params!.endTime = `${dateRangeCreateTime.value[1]} 23:59:59`; - } emit('search'); } @@ -67,6 +70,7 @@ async function search() { type="daterange" value-format="yyyy-MM-dd" clearable + @update:formatted-value="onDateRangeCreateTimeUpdate" /> diff --git a/src/views/system/tenant-package/modules/tenant-package-search.vue b/src/views/system/tenant-package/modules/tenant-package-search.vue index 1036673a..4b22df82 100644 --- a/src/views/system/tenant-package/modules/tenant-package-search.vue +++ b/src/views/system/tenant-package/modules/tenant-package-search.vue @@ -21,7 +21,6 @@ const model = defineModel('model', { requi const { options: sysNormalDisableOptions } = useDict('sys_normal_disable'); async function reset() { - Object.assign(model.value.params!, {}); await restoreValidation(); emit('reset'); } diff --git a/src/views/system/user/modules/user-search.vue b/src/views/system/user/modules/user-search.vue index 1bf4ad3b..f9476ade 100644 --- a/src/views/system/user/modules/user-search.vue +++ b/src/views/system/user/modules/user-search.vue @@ -23,6 +23,13 @@ const datePickerRef = ref>(); const model = defineModel('model', { required: true }); +function onDateRangeCreateTimeUpdate(value: [string, string] | null) { + if (value?.length) { + model.value.params!.beginTime = value[0]; + model.value.params!.endTime = value[1]; + } +} + async function reset() { dateRangeCreateTime.value = null; await restoreValidation(); @@ -31,10 +38,6 @@ async function reset() { async function search() { await validate(); - if (dateRangeCreateTime.value?.length) { - model.value.params!.beginTime = dateRangeCreateTime.value[0]; - model.value.params!.endTime = dateRangeCreateTime.value[1]; - } emit('search'); } @@ -82,6 +85,7 @@ async function search() { type="datetimerange" value-format="yyyy-MM-dd HH:mm:ss" clearable + @update:formatted-value="onDateRangeCreateTimeUpdate" /> diff --git a/src/views/tool/gen/modules/gen-table-search.vue b/src/views/tool/gen/modules/gen-table-search.vue index 73842eda..89bef0a4 100644 --- a/src/views/tool/gen/modules/gen-table-search.vue +++ b/src/views/tool/gen/modules/gen-table-search.vue @@ -26,6 +26,13 @@ const model = defineModel('model', { required: tr const dateRange = ref<[string, string]>(); +function onDateRangeUpdate(value: [string, string] | null) { + if (value?.length) { + model.value.params!.beginTime = value[0]; + model.value.params!.endTime = value[1]; + } +} + async function reset() { await restoreValidation(); emit('reset'); @@ -33,10 +40,6 @@ async function reset() { async function search() { await validate(); - if (dateRange.value?.length) { - model.value.params!.beginTime = dateRange.value[0]; - model.value.params!.endTime = dateRange.value[0]; - } emit('search'); } @@ -62,6 +65,7 @@ async function search() { value-format="yyyy-MM-dd HH:mm:ss" type="daterange" clearable + @update:formatted-value="onDateRangeUpdate" /> From 94d1863ef3b47b76e08f3b9e71fcc21e12463452 Mon Sep 17 00:00:00 2001 From: xlsea Date: Tue, 17 Jun 2025 14:03:47 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix(other):=20=E4=BF=AE=E5=A4=8D=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E7=94=9F=E6=88=90=E5=AD=97=E5=85=B8=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/java/VelocityUtils.java | 20 ++------------------ docs/template/modules/operate-drawer.vue.vm | 8 ++++---- docs/template/modules/search.vue.vm | 8 ++++---- 3 files changed, 10 insertions(+), 26 deletions(-) diff --git a/docs/java/VelocityUtils.java b/docs/java/VelocityUtils.java index 062481cb..92c555ed 100644 --- a/docs/java/VelocityUtils.java +++ b/docs/java/VelocityUtils.java @@ -73,8 +73,9 @@ public class VelocityUtils { velocityContext.put("permissionPrefix", getPermissionPrefix(moduleName, businessName)); velocityContext.put("dicts", getDicts(genTable)); velocityContext.put("dictList", getDictList(genTable)); - velocityContext.put("columns", getColumns(genTable)); + velocityContext.put("columns", genTable.getColumns()); velocityContext.put("table", genTable); + velocityContext.put("StrUtil", new StrUtil()); setMenuVelocityContext(velocityContext, genTable); if (GenConstants.TPL_TREE.equals(tplCategory)) { setTreeVelocityContext(velocityContext, genTable); @@ -296,23 +297,6 @@ public class VelocityUtils { } } - /** - * 根据列类型获取字典组 - * - * @param genTable 业务表对象 - * @return 返回字典组 - */ - public static List getColumns(GenTable genTable) { - List columns = genTable.getColumns(); - for (GenTableColumn column : columns) { - if (StringUtils.isNotBlank(column.getDictType())) { - column.setDictType(StringUtils.toCamelCase(column.getDictType())); - } - } - return columns; - } - - /** * 获取权限前缀 * diff --git a/docs/template/modules/operate-drawer.vue.vm b/docs/template/modules/operate-drawer.vue.vm index b5478c01..a7032da4 100644 --- a/docs/template/modules/operate-drawer.vue.vm +++ b/docs/template/modules/operate-drawer.vue.vm @@ -136,7 +136,7 @@ watch(visible, () => { #else #set($comment=$column.columnComment) #end -#set($dictType=$column.dictType) +#set($dictType=$!StrUtil.toCamelCase($column.dictType)) #if($column.htmlType == "textarea" || $column.htmlType == "editor") { #elseif($column.htmlType == "select" && $dictType) @@ -163,7 +163,7 @@ watch(visible, () => { { #foreach($column in $columns) #if($column.query) -#set($dictType=$column.dictType) +#set($dictType=$!StrUtil.toCamelCase($column.dictType)) #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) #set($parentheseIndex=$column.columnComment.indexOf("(")) #if($parentheseIndex != -1) @@ -75,14 +75,14 @@ async function search() { #set($comment=$column.columnComment) #end - #if(($tool.in($column.htmlType, "select", "radio", "checkbox")) && $dictType && "" != $dictType) + #if($!StrUtil.contains("select, radio, checkbox", $column.htmlType) && $dictType && "" != $dictType) - #elseif($tool.in($column.htmlType, "select", "radio", "checkbox")) + #elseif($!StrUtil.contains("select, radio, checkbox", $column.htmlType))