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: "username" }, { label: "用户昵称", prop: "nickname" }, { label: "性别", prop: "sex", cellRenderer: ({ row, props }) => ( {row.sex === 1 ? "女" : "男"} ) }, { label: "部门", prop: "dept", formatter: ({ dept }) => dept.name }, { label: "手机号码", prop: "mobile" }, { 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.username }用户吗?`, "系统提示", { 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 }; }