mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-04-18 00:03:16 +08:00
update 适配代码生成模板
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
|
import type { ${BusinessName}Form, ${BusinessName}Query, ${BusinessName}VO } from '@/api/${moduleName}/${businessName}/types';
|
||||||
|
import type { PageResult } from '@/api/types';
|
||||||
|
import type { AxiosPromise } from '@/utils/api-types';
|
||||||
import request from '@/utils/request';
|
import request from '@/utils/request';
|
||||||
import { AxiosPromise } from 'axios';
|
|
||||||
import { ${BusinessName}VO, ${BusinessName}Form, ${BusinessName}Query } from '@/api/${moduleName}/${businessName}/types';
|
|
||||||
import { PageResult } from '@/api/types';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询${functionName}列表
|
* 查询${functionName}列表
|
||||||
|
|||||||
@@ -268,22 +268,31 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
#set($needAddDateRange = false)
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
|
||||||
|
#set($needAddDateRange = true)
|
||||||
|
#end
|
||||||
|
#end
|
||||||
<script setup name="${BusinessName}" lang="ts">
|
<script setup name="${BusinessName}" lang="ts">
|
||||||
import { list${BusinessName}, get${BusinessName}, del${BusinessName}, add${BusinessName}, update${BusinessName} } from "@/api/${moduleName}/${businessName}";
|
import { add${BusinessName}, del${BusinessName}, get${BusinessName}, list${BusinessName}, update${BusinessName} } from '@/api/${moduleName}/${businessName}';
|
||||||
import { ${BusinessName}VO, ${BusinessName}Query, ${BusinessName}Form } from '@/api/${moduleName}/${businessName}/types';
|
import { ${BusinessName}Form, ${BusinessName}Query, ${BusinessName}VO } from '@/api/${moduleName}/${businessName}/types';
|
||||||
|
#if(${dicts} != '')
|
||||||
|
import { useDict } from '@/utils/dict';
|
||||||
|
#end
|
||||||
|
import modal from '@/plugins/modal';
|
||||||
|
import { handleTree#if($needAddDateRange), addDateRange#end } from '@/utils/ruoyi';
|
||||||
|
|
||||||
|
#if(${dicts} != '')
|
||||||
|
#set($dictsNoSymbol=$dicts.replace("'", ""))
|
||||||
|
const { ${dictsNoSymbol} } = toRefs<any>(useDict(${dicts}));
|
||||||
|
#end
|
||||||
|
|
||||||
type ${BusinessName}Option = {
|
type ${BusinessName}Option = {
|
||||||
${treeCode}: number;
|
${treeCode}: number;
|
||||||
${treeName}: string;
|
${treeName}: string;
|
||||||
children?: ${BusinessName}Option[];
|
children?: ${BusinessName}Option[];
|
||||||
}
|
};
|
||||||
|
|
||||||
const { proxy } = getCurrentInstance() as ComponentInternalInstance;;
|
|
||||||
|
|
||||||
#if(${dicts} != '')
|
|
||||||
#set($dictsNoSymbol=$dicts.replace("'", ""))
|
|
||||||
const { ${dictsNoSymbol} } = toRefs<any>(proxy?.useDict(${dicts}));
|
|
||||||
#end
|
|
||||||
|
|
||||||
const ${businessName}List = ref<${BusinessName}VO[]>([]);
|
const ${businessName}List = ref<${BusinessName}VO[]>([]);
|
||||||
const ${businessName}Options = ref<${BusinessName}Option[]>([]);
|
const ${businessName}Options = ref<${BusinessName}Option[]>([]);
|
||||||
@@ -294,7 +303,7 @@ const loading = ref(false);
|
|||||||
|
|
||||||
const queryFormRef = ref<ElFormInstance>();
|
const queryFormRef = ref<ElFormInstance>();
|
||||||
const ${businessName}FormRef = ref<ElFormInstance>();
|
const ${businessName}FormRef = ref<ElFormInstance>();
|
||||||
const ${businessName}TableRef = ref<ElTableInstance>()
|
const ${businessName}TableRef = ref<ElTableInstance>();
|
||||||
|
|
||||||
const dialog = reactive<DialogOption>({
|
const dialog = reactive<DialogOption>({
|
||||||
visible: false,
|
visible: false,
|
||||||
@@ -373,42 +382,42 @@ const getList = async () => {
|
|||||||
#foreach ($column in $columns)
|
#foreach ($column in $columns)
|
||||||
#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
|
#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
|
||||||
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
proxy?.addDateRange(queryParams.value, dateRange${AttrName}.value, '${AttrName}');
|
addDateRange(queryParams.value, dateRange${AttrName}.value, '${AttrName}');
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
const res = await list${BusinessName}(queryParams.value);
|
const res = await list${BusinessName}(queryParams.value);
|
||||||
const data = proxy?.handleTree<${BusinessName}VO>(res.data, "${treeCode}", "${treeParentCode}");
|
const data = handleTree<${BusinessName}VO>(res.data, '${treeCode}', '${treeParentCode}');
|
||||||
if (data) {
|
if (data) {
|
||||||
${businessName}List.value = data;
|
${businessName}List.value = data;
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
/** 查询${functionName}下拉树结构 */
|
/** 查询${functionName}下拉树结构 */
|
||||||
const getTreeselect = async () => {
|
const getTreeselect = async () => {
|
||||||
const res = await list${BusinessName}();
|
const res = await list${BusinessName}();
|
||||||
${businessName}Options.value = [];
|
${businessName}Options.value = [];
|
||||||
const data: ${BusinessName}Option = { ${treeCode}: 0, ${treeName}: '顶级节点', children: [] };
|
const data: ${BusinessName}Option = { ${treeCode}: 0, ${treeName}: '顶级节点', children: [] };
|
||||||
data.children = proxy?.handleTree<${BusinessName}Option>(res.data, "${treeCode}", "${treeParentCode}");
|
data.children = handleTree<${BusinessName}Option>(res.data, '${treeCode}', '${treeParentCode}');
|
||||||
${businessName}Options.value.push(data);
|
${businessName}Options.value.push(data);
|
||||||
}
|
};
|
||||||
|
|
||||||
// 取消按钮
|
/** 取消按钮 */
|
||||||
const cancel = () => {
|
const cancel = () => {
|
||||||
reset();
|
reset();
|
||||||
dialog.visible = false;
|
dialog.visible = false;
|
||||||
}
|
};
|
||||||
|
|
||||||
// 表单重置
|
/** 表单重置 */
|
||||||
const reset = () => {
|
const reset = () => {
|
||||||
form.value = {...initFormData}
|
form.value = { ...initFormData };
|
||||||
${businessName}FormRef.value?.resetFields();
|
${businessName}FormRef.value?.resetFields();
|
||||||
}
|
};
|
||||||
|
|
||||||
/** 搜索按钮操作 */
|
/** 搜索按钮操作 */
|
||||||
const handleQuery = () => {
|
const handleQuery = () => {
|
||||||
getList();
|
getList();
|
||||||
}
|
};
|
||||||
|
|
||||||
/** 重置按钮操作 */
|
/** 重置按钮操作 */
|
||||||
const resetQuery = () => {
|
const resetQuery = () => {
|
||||||
@@ -420,7 +429,7 @@ const resetQuery = () => {
|
|||||||
#end
|
#end
|
||||||
queryFormRef.value?.resetFields();
|
queryFormRef.value?.resetFields();
|
||||||
handleQuery();
|
handleQuery();
|
||||||
}
|
};
|
||||||
|
|
||||||
/** 新增按钮操作 */
|
/** 新增按钮操作 */
|
||||||
const handleAdd = (row?: ${BusinessName}VO) => {
|
const handleAdd = (row?: ${BusinessName}VO) => {
|
||||||
@@ -432,22 +441,22 @@ const handleAdd = (row?: ${BusinessName}VO) => {
|
|||||||
form.value.${treeParentCode} = 0;
|
form.value.${treeParentCode} = 0;
|
||||||
}
|
}
|
||||||
dialog.visible = true;
|
dialog.visible = true;
|
||||||
dialog.title = "添加${functionName}";
|
dialog.title = '添加${functionName}';
|
||||||
}
|
};
|
||||||
|
|
||||||
/** 展开/折叠操作 */
|
/** 展开/折叠操作 */
|
||||||
const handleToggleExpandAll = () => {
|
const handleToggleExpandAll = () => {
|
||||||
isExpandAll.value = !isExpandAll.value;
|
isExpandAll.value = !isExpandAll.value;
|
||||||
toggleExpandAll(${businessName}List.value, isExpandAll.value)
|
toggleExpandAll(${businessName}List.value, isExpandAll.value);
|
||||||
}
|
};
|
||||||
|
|
||||||
/** 展开/折叠操作 */
|
/** 展开/折叠操作 */
|
||||||
const toggleExpandAll = (data: ${BusinessName}VO[], status: boolean) => {
|
const toggleExpandAll = (data: ${BusinessName}VO[], status: boolean) => {
|
||||||
data.forEach((item) => {
|
data.forEach(item => {
|
||||||
${businessName}TableRef.value?.toggleRowExpansion(item, status)
|
${businessName}TableRef.value?.toggleRowExpansion(item, status);
|
||||||
if (item.children && item.children.length > 0) toggleExpandAll(item.children, status)
|
if (item.children && item.children.length > 0) toggleExpandAll(item.children, status);
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
/** 修改按钮操作 */
|
/** 修改按钮操作 */
|
||||||
const handleUpdate = async (row: ${BusinessName}VO) => {
|
const handleUpdate = async (row: ${BusinessName}VO) => {
|
||||||
@@ -464,8 +473,8 @@ const handleUpdate = async (row: ${BusinessName}VO) => {
|
|||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
dialog.visible = true;
|
dialog.visible = true;
|
||||||
dialog.title = "修改${functionName}";
|
dialog.title = '修改${functionName}';
|
||||||
}
|
};
|
||||||
|
|
||||||
/** 提交按钮 */
|
/** 提交按钮 */
|
||||||
const submitForm = () => {
|
const submitForm = () => {
|
||||||
@@ -478,25 +487,25 @@ const submitForm = () => {
|
|||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
if (form.value.${pkColumn.javaField}) {
|
if (form.value.${pkColumn.javaField}) {
|
||||||
await update${BusinessName}(form.value).finally(() => buttonLoading.value = false);
|
await update${BusinessName}(form.value).finally(() => (buttonLoading.value = false));
|
||||||
} else {
|
} else {
|
||||||
await add${BusinessName}(form.value).finally(() => buttonLoading.value = false);
|
await add${BusinessName}(form.value).finally(() => (buttonLoading.value = false));
|
||||||
}
|
}
|
||||||
proxy?.#[[$modal]]#.msgSuccess("操作成功");
|
modal.msgSuccess('操作成功');
|
||||||
dialog.visible = false;
|
dialog.visible = false;
|
||||||
await getList();
|
await getList();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
/** 删除按钮操作 */
|
/** 删除按钮操作 */
|
||||||
const handleDelete = async (row: ${BusinessName}VO) => {
|
const handleDelete = async (row: ${BusinessName}VO) => {
|
||||||
await proxy?.#[[$modal]]#.confirm('是否确认删除${functionName}编号为"' + row.${pkColumn.javaField} + '"的数据项?');
|
await modal.confirm('是否确认删除${functionName}编号为"' + row.${pkColumn.javaField} + '"的数据项?');
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
await del${BusinessName}(row.${pkColumn.javaField}).finally(() => loading.value = false);
|
await del${BusinessName}(row.${pkColumn.javaField}).finally(() => (loading.value = false));
|
||||||
await getList();
|
await getList();
|
||||||
proxy?.#[[$modal]]#.msgSuccess("删除成功");
|
modal.msgSuccess('删除成功');
|
||||||
}
|
};
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
getList();
|
getList();
|
||||||
|
|||||||
@@ -248,14 +248,27 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
#set($needAddDateRange = false)
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
|
||||||
|
#set($needAddDateRange = true)
|
||||||
|
#end
|
||||||
|
#end
|
||||||
<script setup name="${BusinessName}" lang="ts">
|
<script setup name="${BusinessName}" lang="ts">
|
||||||
import { list${BusinessName}, get${BusinessName}, del${BusinessName}, add${BusinessName}, update${BusinessName} } from '@/api/${moduleName}/${businessName}';
|
import { add${BusinessName}, del${BusinessName}, get${BusinessName}, list${BusinessName}, update${BusinessName} } from '@/api/${moduleName}/${businessName}';
|
||||||
import { ${BusinessName}VO, ${BusinessName}Query, ${BusinessName}Form } from '@/api/${moduleName}/${businessName}/types';
|
import { ${BusinessName}Form, ${BusinessName}Query, ${BusinessName}VO } from '@/api/${moduleName}/${businessName}/types';
|
||||||
|
#if(${dicts} != '')
|
||||||
|
import { useDict } from '@/utils/dict';
|
||||||
|
#end
|
||||||
|
#if($needAddDateRange)
|
||||||
|
import { addDateRange } from '@/utils/ruoyi';
|
||||||
|
#end
|
||||||
|
import modal from '@/plugins/modal';
|
||||||
|
import { download as requestDownload } from '@/utils/request';
|
||||||
|
|
||||||
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
|
||||||
#if(${dicts} != '')
|
#if(${dicts} != '')
|
||||||
#set($dictsNoSymbol=$dicts.replace("'", ""))
|
#set($dictsNoSymbol=$dicts.replace("'", ""))
|
||||||
const { ${dictsNoSymbol} } = toRefs<any>(proxy?.useDict(${dicts}));
|
const { ${dictsNoSymbol} } = toRefs<any>(useDict(${dicts}));
|
||||||
#end
|
#end
|
||||||
|
|
||||||
const ${businessName}List = ref<${BusinessName}VO[]>([]);
|
const ${businessName}List = ref<${BusinessName}VO[]>([]);
|
||||||
@@ -347,32 +360,32 @@ const getList = async () => {
|
|||||||
#foreach ($column in $columns)
|
#foreach ($column in $columns)
|
||||||
#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
|
#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
|
||||||
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
proxy?.addDateRange(queryParams.value, dateRange${AttrName}.value, '${AttrName}');
|
addDateRange(queryParams.value, dateRange${AttrName}.value, '${AttrName}');
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
const res = await list${BusinessName}(queryParams.value);
|
const res = await list${BusinessName}(queryParams.value);
|
||||||
${businessName}List.value = res.data?.rows;
|
${businessName}List.value = res.data?.rows;
|
||||||
total.value = res.data?.total;
|
total.value = res.data?.total;
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
}
|
};
|
||||||
|
|
||||||
/** 取消按钮 */
|
/** 取消按钮 */
|
||||||
const cancel = () => {
|
const cancel = () => {
|
||||||
reset();
|
reset();
|
||||||
dialog.visible = false;
|
dialog.visible = false;
|
||||||
}
|
};
|
||||||
|
|
||||||
/** 表单重置 */
|
/** 表单重置 */
|
||||||
const reset = () => {
|
const reset = () => {
|
||||||
form.value = { ...initFormData };
|
form.value = { ...initFormData };
|
||||||
${businessName}FormRef.value?.resetFields();
|
${businessName}FormRef.value?.resetFields();
|
||||||
}
|
};
|
||||||
|
|
||||||
/** 搜索按钮操作 */
|
/** 搜索按钮操作 */
|
||||||
const handleQuery = () => {
|
const handleQuery = () => {
|
||||||
queryParams.value.pageNum = 1;
|
queryParams.value.pageNum = 1;
|
||||||
getList();
|
getList();
|
||||||
}
|
};
|
||||||
|
|
||||||
/** 重置按钮操作 */
|
/** 重置按钮操作 */
|
||||||
const resetQuery = () => {
|
const resetQuery = () => {
|
||||||
@@ -384,26 +397,26 @@ const resetQuery = () => {
|
|||||||
#end
|
#end
|
||||||
queryFormRef.value?.resetFields();
|
queryFormRef.value?.resetFields();
|
||||||
handleQuery();
|
handleQuery();
|
||||||
}
|
};
|
||||||
|
|
||||||
/** 多选框选中数据 */
|
/** 多选框选中数据 */
|
||||||
const handleSelectionChange = (selection: ${BusinessName}VO[]) => {
|
const handleSelectionChange = (selection: ${BusinessName}VO[]) => {
|
||||||
ids.value = selection.map(item => item.${pkColumn.javaField});
|
ids.value = selection.map(item => item.${pkColumn.javaField});
|
||||||
single.value = selection.length != 1;
|
single.value = selection.length != 1;
|
||||||
multiple.value = !selection.length;
|
multiple.value = !selection.length;
|
||||||
}
|
};
|
||||||
|
|
||||||
/** 新增按钮操作 */
|
/** 新增按钮操作 */
|
||||||
const handleAdd = () => {
|
const handleAdd = () => {
|
||||||
reset();
|
reset();
|
||||||
dialog.visible = true;
|
dialog.visible = true;
|
||||||
dialog.title = "添加${functionName}";
|
dialog.title = '添加${functionName}';
|
||||||
}
|
};
|
||||||
|
|
||||||
/** 修改按钮操作 */
|
/** 修改按钮操作 */
|
||||||
const handleUpdate = async (row?: ${BusinessName}VO) => {
|
const handleUpdate = async (row?: ${BusinessName}VO) => {
|
||||||
reset();
|
reset();
|
||||||
const _${pkColumn.javaField} = row?.${pkColumn.javaField} || ids.value[0]
|
const _${pkColumn.javaField} = row?.${pkColumn.javaField} || ids.value[0];
|
||||||
const res = await get${BusinessName}(_${pkColumn.javaField});
|
const res = await get${BusinessName}(_${pkColumn.javaField});
|
||||||
Object.assign(form.value, res.data);
|
Object.assign(form.value, res.data);
|
||||||
#foreach ($column in $columns)
|
#foreach ($column in $columns)
|
||||||
@@ -412,8 +425,8 @@ const handleUpdate = async (row?: ${BusinessName}VO) => {
|
|||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
dialog.visible = true;
|
dialog.visible = true;
|
||||||
dialog.title = "修改${functionName}";
|
dialog.title = '修改${functionName}';
|
||||||
}
|
};
|
||||||
|
|
||||||
/** 提交按钮 */
|
/** 提交按钮 */
|
||||||
const submitForm = () => {
|
const submitForm = () => {
|
||||||
@@ -426,32 +439,36 @@ const submitForm = () => {
|
|||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
if (form.value.${pkColumn.javaField}) {
|
if (form.value.${pkColumn.javaField}) {
|
||||||
await update${BusinessName}(form.value).finally(() => buttonLoading.value = false);
|
await update${BusinessName}(form.value).finally(() => (buttonLoading.value = false));
|
||||||
} else {
|
} else {
|
||||||
await add${BusinessName}(form.value).finally(() => buttonLoading.value = false);
|
await add${BusinessName}(form.value).finally(() => (buttonLoading.value = false));
|
||||||
}
|
}
|
||||||
proxy?.#[[$modal]]#.msgSuccess("操作成功");
|
modal.msgSuccess('操作成功');
|
||||||
dialog.visible = false;
|
dialog.visible = false;
|
||||||
await getList();
|
await getList();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
/** 删除按钮操作 */
|
/** 删除按钮操作 */
|
||||||
const handleDelete = async (row?: ${BusinessName}VO) => {
|
const handleDelete = async (row?: ${BusinessName}VO) => {
|
||||||
const _${pkColumn.javaField}s = row?.${pkColumn.javaField} || ids.value;
|
const _${pkColumn.javaField}s = row?.${pkColumn.javaField} || ids.value;
|
||||||
await proxy?.#[[$modal]]#.confirm('是否确认删除${functionName}编号为"' + _${pkColumn.javaField}s + '"的数据项?').finally(() => loading.value = false);
|
await modal.confirm('是否确认删除${functionName}编号为"' + _${pkColumn.javaField}s + '"的数据项?').finally(() => (loading.value = false));
|
||||||
await del${BusinessName}(_${pkColumn.javaField}s);
|
await del${BusinessName}(_${pkColumn.javaField}s);
|
||||||
proxy?.#[[$modal]]#.msgSuccess("删除成功");
|
modal.msgSuccess('删除成功');
|
||||||
await getList();
|
await getList();
|
||||||
}
|
};
|
||||||
|
|
||||||
/** 导出按钮操作 */
|
/** 导出按钮操作 */
|
||||||
const handleExport = () => {
|
const handleExport = () => {
|
||||||
proxy?.download('${moduleName}/${businessName}/export', {
|
requestDownload(
|
||||||
|
'${moduleName}/${businessName}/export',
|
||||||
|
{
|
||||||
...queryParams.value
|
...queryParams.value
|
||||||
}, `${businessName}_#[[${new Date().getTime()}]]#.xlsx`)
|
},
|
||||||
}
|
`${businessName}_#[[${new Date().getTime()}]]#.xlsx`
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
getList();
|
getList();
|
||||||
|
|||||||
Reference in New Issue
Block a user