import { ref } from "vue"; import dayjs from "dayjs"; import { message } from "@/utils/message"; import { ElMessageBox } from "element-plus"; export function useColumns() { const switchLoadMap = ref({}); const columns: TableColumnList = [ { type: "selection", width: 55, align: "left", hide: ({ checkList }) => !checkList.includes("勾选列") }, { label: "序号", type: "index", width: 70, hide: ({ checkList }) => !checkList.includes("序号列") }, { label: "角色编号", prop: "id" }, { label: "角色名称", prop: "name" }, { label: "角色标识", prop: "code" }, { label: "角色类型", prop: "type", cellRenderer: ({ row, props }) => ( {row.type === 1 ? "内置" : "自定义"} ) }, { label: "显示顺序", prop: "sort" }, { label: "状态", prop: "status", width: 130, cellRenderer: scope => ( onChange(scope as any)} /> ) }, { label: "创建时间", width: 180, prop: "createTime", formatter: ({ createTime }) => dayjs(createTime).format("YYYY-MM-DD HH:mm:ss") }, { label: "操作", fixed: "right", width: 180, slot: "operation" } ]; function onChange({ row, index }) { ElMessageBox.confirm( `确认要${ row.status === 0 ? "停用" : "启用" }${ row.name }角色吗?`, "系统提示", { confirmButtonText: "确定", cancelButtonText: "取消", type: "warning", dangerouslyUseHTMLString: true, draggable: true } ) .then(() => { switchLoadMap.value[index] = Object.assign( {}, switchLoadMap.value[index], { loading: true } ); setTimeout(() => { switchLoadMap.value[index] = Object.assign( {}, switchLoadMap.value[index], { loading: false } ); message("已成功修改角色状态", "success"); }, 300); }) .catch(() => { row.status === 0 ? (row.status = 1) : (row.status = 0); }); } return { columns }; }