auth-server-java/common/common-generator/src/main/resources/vms/web/handler.vm

99 lines
2.3 KiB
Plaintext
Raw Normal View History

2024-09-30 16:22:10 +08:00
import {reactive, ref} from 'vue';
import {messageBox} from '@/utils/message';
import { use${className}Store } from '${storePath}${lowercaseName}';
import { ${className}AddDto, ${className}State, ${className}UpdateDto, ${className}Vo } from '${storeTypePath}${lowercaseName}';
const ${storeId}Store = use${className}Store();
export const ids = ref([]);
export const updateForm = reactive<${className}UpdateDto>({});
/**
* * 获取用户数据
*/
export const getDataList = async (flag: boolean = true) => {
if (flag) {
${storeId}Store.loading = true;
await ${storeId}Store.get${className}List();
${storeId}Store.loading = false;
}
};
/**
* * 当前页改变时
*/
export const onCurrentPageChange = async (value: number) => {
${storeId}Store.pagination.currentPage = value;
await getDataList();
};
/**
* * 当分页发生变化
* @param value
*/
export const onPageSizeChange = (value: number) => {
${storeId}Store.pagination.pageSize = value;
getDataList().then();
};
/**
* * 选择行
* @param itemList
*/
export const handleSelectionChange = (itemList: ${className}Vo[]) => {
ids.value = itemList.map(item => item.id);
};
/**
* * 添加操作
*/
export const onAdd = () => {
${storeId}Store.addDialogVisible = true;
};
/**
* * 当更新时
*/
export const onUpdate = ({row}): void => {
// 合并数据
Object.assign(updateForm, row);
#foreach($item in $addDtoFormList)
#if($item.name == 'sex')
// 设置基础数据格式
updateForm.sex = row.sex === '女' ? 0 : 1;
#end
#end
// 打开弹窗
${storeId}Store.updateDialogVisible = true;
};
/**
* * 当删除时
*/
export const onDelete = async ({row}) => {
const result = await ${storeId}Store.delete${className}([row.id]).then();
// 成功刷新数据
await getDataList(result)
};
/**
* * 批量删除
*/
export const onDeleteBatch = async () => {
const isConfirm = await messageBox({
message: '是否确认批量删除',
title: '删除警告',
showMessage: false,
confirmMessage: '删除成功',
cancelMessage: '取消删除',
});
// 确认删除时执行
if (isConfirm) {
const result = await ${storeId}Store.delete${className}(ids.value);
// 成功刷新数据
await getDataList(result)
}
};