Files
certd/packages/ui/certd-client/src/views/sys/plugin/crud.tsx
T

216 lines
5.2 KiB
TypeScript
Raw Normal View History

2024-10-13 01:27:08 +08:00
import * as api from "./api";
import { useI18n } from "vue-i18n";
import { computed, Ref, ref } from "vue";
import { useRouter } from "vue-router";
import { AddReq, CreateCrudOptionsProps, CreateCrudOptionsRet, DelReq, dict, EditReq, UserPageQuery, UserPageRes, utils } from "@fast-crud/fast-crud";
import { useUserStore } from "/src/store/modules/user";
import { useSettingStore } from "/src/store/modules/settings";
import { Modal } from "ant-design-vue";
export default function ({ crudExpose, context }: CreateCrudOptionsProps): CreateCrudOptionsRet {
const router = useRouter();
const { t } = useI18n();
const pageRequest = async (query: UserPageQuery): Promise<UserPageRes> => {
return await api.GetList(query);
};
const editRequest = async ({ form, row }: EditReq) => {
form.id = row.id;
const res = await api.UpdateObj(form);
return res;
};
const delRequest = async ({ row }: DelReq) => {
return await api.DelObj(row.id);
};
const addRequest = async ({ form }: AddReq) => {
form.content = JSON.stringify({
title: form.title
});
const res = await api.AddObj(form);
return res;
};
const userStore = useUserStore();
const settingStore = useSettingStore();
const selectedRowKeys: Ref<any[]> = ref([]);
context.selectedRowKeys = selectedRowKeys;
return {
crudOptions: {
settings: {
plugins: {
//这里使用行选择插件,生成行选择crudOptions配置,最终会与crudOptions合并
rowSelection: {
enabled: true,
order: -2,
before: true,
// handle: (pluginProps,useCrudProps)=>CrudOptions,
props: {
multiple: true,
crossPage: true,
selectedRowKeys
}
}
}
},
request: {
pageRequest,
addRequest,
editRequest,
delRequest
},
actionbar: {
buttons: {
add: {
show: false
}
}
},
rowHandle: {
2024-10-14 14:57:09 +08:00
show: false,
2024-10-13 01:27:08 +08:00
minWidth: 200,
fixed: "right",
buttons: {
edit: {
show: false
2024-10-14 00:19:55 +08:00
},
copy: {
show: false
},
remove: {
show: false
2024-10-13 01:27:08 +08:00
}
}
},
2024-10-14 14:57:09 +08:00
table: {
rowKey: "name"
},
2024-10-13 01:27:08 +08:00
columns: {
2024-10-14 14:57:09 +08:00
// id: {
// title: "ID",
// key: "id",
// type: "number",
// column: {
// width: 100
// },
// form: {
// show: false
// }
// },
2024-10-13 01:27:08 +08:00
name: {
title: "插件名称",
type: "text",
search: {
show: true
},
form: {
show: false
},
column: {
2024-10-14 00:19:55 +08:00
width: 200
}
},
icon: {
title: "图标",
type: "text",
form: {
show: false
},
column: {
width: 100,
align: "center",
component: {
name: "fs-icon",
vModel: "icon",
style: {
fontSize: "22px"
}
}
2024-10-13 01:27:08 +08:00
}
},
title: {
title: "标题",
type: "text",
column: {
width: 300
}
},
desc: {
title: "描述",
type: "text",
column: {
width: 300
}
},
group: {
title: "分组",
type: "text",
column: {
2024-10-14 00:19:55 +08:00
width: 100,
align: "center"
2024-10-13 01:27:08 +08:00
}
},
disabled: {
2024-10-14 14:57:09 +08:00
title: "点击禁用/启用",
2024-10-13 01:27:08 +08:00
type: "dict-switch",
dict: dict({
data: [
{ label: "启用", value: false, color: "success" },
{ label: "禁用", value: true, color: "error" }
]
}),
form: {
value: false
},
column: {
2024-10-14 14:57:09 +08:00
width: 120,
2024-10-14 00:19:55 +08:00
align: "center",
2024-10-13 01:27:08 +08:00
component: {
title: "点击可禁用/启用",
on: {
async click({ value, row }) {
Modal.confirm({
title: "提示",
content: `确定要${!value ? "禁用" : "启用"}吗?`,
onOk: async () => {
2024-10-14 00:19:55 +08:00
await api.SetDisabled({
id: row.id,
name: row.name,
type: row.type,
disabled: !value
});
2024-10-13 01:27:08 +08:00
await crudExpose.doRefresh();
}
});
}
}
}
}
},
createTime: {
title: "创建时间",
type: "datetime",
form: {
show: false
},
column: {
sorter: true,
width: 160,
align: "center"
}
},
updateTime: {
title: "更新时间",
type: "datetime",
form: {
show: false
},
column: {
show: true
}
}
}
}
};
}