mirror of
https://github.com/pure-admin/vue-pure-admin.git
synced 2025-06-30 09:24:46 +08:00
128 lines
2.9 KiB
TypeScript
128 lines
2.9 KiB
TypeScript
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 }) => (
|
|
<el-tag
|
|
size={props.size}
|
|
type={row.type === 1 ? "danger" : ""}
|
|
effect="plain"
|
|
>
|
|
{row.type === 1 ? "内置" : "自定义"}
|
|
</el-tag>
|
|
)
|
|
},
|
|
{
|
|
label: "显示顺序",
|
|
prop: "sort"
|
|
},
|
|
{
|
|
label: "状态",
|
|
prop: "status",
|
|
width: 130,
|
|
cellRenderer: scope => (
|
|
<el-switch
|
|
size={scope.props.size === "small" ? "small" : "default"}
|
|
loading={switchLoadMap.value[scope.index]?.loading}
|
|
v-model={scope.row.status}
|
|
active-value={1}
|
|
inactive-value={0}
|
|
active-text="已开启"
|
|
inactive-text="已关闭"
|
|
inline-prompt
|
|
onChange={() => 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(
|
|
`确认要<strong>${
|
|
row.status === 0 ? "停用" : "启用"
|
|
}</strong><strong style='color:var(--el-color-primary)'>${
|
|
row.name
|
|
}</strong>角色吗?`,
|
|
"系统提示",
|
|
{
|
|
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
|
|
};
|
|
}
|