import type {
LoadingConfig,
AdaptiveConfig,
PaginationProps
} from "@pureadmin/table";
import { ref, reactive } from "vue";
import { delObjectProperty } from "@pureadmin/utils";
import { clone, delay } from "@pureadmin/utils";
import Project from "@/model/project.js";
export function useColumns() {
const loading = ref(true);
const editMap = ref({});
const dataList = ref([]);
const options = ref([
{
value: 0,
label: "未开始",
type: "info"
},
{
value: 1,
label: "进行中",
type: ""
},
{
value: 2,
label: "已完成",
type: "success"
}
]);
const columns: TableColumnList = [
{
label: "ID",
prop: "id",
cellRenderer: ({ row, index }) => (
<>
{editMap.value[index]?.editable ? (
) : (
{row.id}
)}
>
)
},
{
label: "项目名称",
prop: "name",
cellRenderer: ({ row, index }) => (
<>
{editMap.value[index]?.editable ? (
) : (
{row.name}
)}
>
)
},
{
label: "项目版本",
prop: "version",
cellRenderer: ({ row, index }) => (
<>
{editMap.value[index]?.editable ? (
) : (
{row.version}
)}
>
)
},
{
label: "区域数量",
prop: "locations",
cellRenderer: ({ row, index }) => (
{row.locations.length}
)
},
{
label: "人员数量",
prop: "persons",
cellRenderer: ({ row, index }) => (
{row.persons.length}
)
},
{
label: "项目状态",
prop: "status",
cellRenderer: ({ row, index }) => (
opt.value == row.status)[0]?.type}>
{options.value.filter(opt => opt.value == row.status)[0]?.label}
)
},
{
label: "操作",
fixed: "right",
slot: "operation"
}
];
/** 分页配置 */
const pagination = reactive({
pageSize: 20,
currentPage: 1,
pageSizes: [20, 40, 60],
total: 0,
align: "right",
background: true,
size: "default"
});
/** 加载动画配置 */
const loadingConfig = reactive({
text: "正在加载第一页...",
viewBox: "-10, -10, 50, 50",
spinner: `
`
// svg: "",
// background: rgba()
});
/** 撑满内容区自适应高度相关配置 */
const adaptiveConfig: AdaptiveConfig = {
/** 表格距离页面底部的偏移量,默认值为 `96` */
offsetBottom: 110
/** 是否固定表头,默认值为 `true`(如果不想固定表头,fixHeader设置为false并且表格要设置table-layout="auto") */
// fixHeader: true
/** 页面 `resize` 时的防抖时间,默认值为 `60` ms */
// timeout: 60
/** 表头的 `z-index`,默认值为 `100` */
// zIndex: 100
};
function onSizeChange(val) {
console.log("onSizeChange", val);
}
function onCurrentChange(val) {
loadingConfig.text = `正在加载第${val}页...`;
loading.value = true;
delay(600).then(() => {
loading.value = false;
});
}
function onEdit(row, index) {
editMap.value[index] = Object.assign({ ...row, editable: true });
}
function onSave(index) {
editMap.value[index].editable = false;
}
function onCancel(index) {
editMap.value[index].editable = false;
dataList.value[index] = delObjectProperty(editMap.value[index], "editable");
}
function onAdd() {
const v = new Project();
v.id = dataList.value.length + 1;
dataList.value.push(v);
}
function onDel(row) {
const index = dataList.value.indexOf(row);
if (index !== -1) dataList.value.splice(index, 1);
}
return {
loading,
editMap,
columns,
dataList,
options,
pagination,
loadingConfig,
adaptiveConfig,
onAdd,
onDel,
onEdit,
onSave,
onCancel,
onSizeChange,
onCurrentChange
};
}