1、基本属性
<template>
<!-- 基础组件 -->
<basic-container>
<!-- <el-button @click='exportHandle'>导出</el-button> -->
<avue-crud
:option="option"
v-model="form"
:data="data"
:table-loading="loading"
:page="page"
:permission="permissionList"
:before-open="beforeOpen"
:before-close="beforeClose"
ref="crud"
@row-update="rowUpdate"
@row-save="rowSave"
@row-del="rowDel"
@search-change="searchChange"
@search-reset="searchReset"
@selection-change="selectionChange"
@current-change="currentChange"
@size-change="sizeChange"
@refresh-change="onLoad(page)"
@on-load="onLoad"
>
</avue-crud>
</basic-container>
</template>
2、自定义列表
<avue-crud :data="data" :option="option" ref="crud">
<!-- 左边插槽 -->
<template slot-scope="scope" slot="menuLeft">
<el-button type="danger" @click="$refs.crud.rowAdd()">新增</el-button>
</template>
<!-- 右边插槽 -->
<template slot-scope="scope" slot="menuRight">
<el-button type="danger" @click=() => {}">刷新</el-button>
</template>
<!-- 自定义行内操作栏插槽 -->
<template slot-scope="{row,index}" slot="menu">
<el-button @click="$refs.crud.rowEdit(row,index)">编辑</el-button>
<el-button @click="$refs.crud.rowDel(row,index)">删除</el-button>
</template>
<!-- 自定义弹窗内按钮插槽 -->
<template slot-scope="{row,index,type}" slot="menuForm">
<el-button v-if="type=='add'" @click="$refs.crud.rowSave()">自定义新增</el-button>
<el-button v-if="type=='edit'" @click="$refs.crud.rowUpdate()>自定义修改</el-button>
<el-button @click="$refs.crud.closeDialog()">取消</el-button>
</template>
<!-- 自定义表单插槽,slot="propForm" -->
<template slot-scope="{type,disabled}" slot="nameForm"> // column: [{prop:'name',formslot:true}]
<el-tag v-if="type=='add'">新增</el-tag>
<el-tag v-else-if="type=='edit'">修改</el-tag>
<el-tag v-else-if="type=='view'">查看</el-tag>
<el-tag>{{user.name?user.name:'暂时没有内容'}}</el-tag>
<el-input :disabled="disabled" v-model="user.name"></el-input>
</template>
<!-- 自定义表单错误提示插槽,slot="propError" -->
<template slot-scope="{error}" slot="nameError"> // column: [{prop:'name',labelslot:true}]
<p style="color:green">自定义提示{{error}}</p>
</template>
<!-- 自定义表单标题,slot="propLabel" -->
<template slot-scope="scope" slot="nameLabel"> // column: [{prop:'name',errorslot:true}]
<span>姓名 </span>
<el-tooltip class="item" effect="dark" content="文字提示" placement="top-start">
<i class="el-icon-warning"></i>
</el-tooltip>
</template>
<!-- 向搜索表单插入一个额外的(column中没有的字段)输入框 -->
<template slot="search">
<el-form-item label="状态">
<el-input placeholder="状态" v-model="search.value"/>
</el-form-item>
</template>
<!-- 向表单中插入一个额外的输入框 -->
<template slot="menuForm">
<el-form-item label="维修">
<el-input placeholder="维修" v-model="search.value"/>
</el-form-item>
</template>
</avue-crud>
3、定义初始数据
option: {
align:'left',
width: '100%',
calcHeight: 'auto',
height: 'auto',
maxHeight: 'auto',
tip: false,
border: true,
index: true,
indexLabel: "序号",
printBtn: true
refreshBtn: true
viewBtn: true,
editBtn: false,
delBtn: false,
searchShow: true,
editBtnText:'编辑文案',
viewBtnText:'查看文案',
printBtnText:'打印文案',
excelBtnText:'导出文案',
updateBtnText:'修改文案',
saveBtnText:'保存文案',
cancelBtnText:'取消文案',
dialogWidth: 600,
column: [
{
label: "请假人",
prop: "userId",
type: "tree",
/daterange/timerange/datetimerange/week/month/year/dates/password/switch/tree/number
maxRows:4,
minRows:2,
search: true,
editDisabled: true,
addDisabled: true,
display: false,
addDisplay: false,
viewDisplay: true,
editDisplay: false,
hide: true,
multiple: true,
dicData: [],
props: {
value: "sysId",
label: "name",
},
dicUrl: "/api/blade-system/dict/dictionary?code=exam_state",
format: "yyyy-MM-dd hh:mm:ss",
valueFormat: "yyyy-MM-dd hh:mm:ss",
rules: [
{
required: true,
message: "请选择请假人",
trigger: "blur",
},
],
},
data: []
4、方法中使用方法
methods: {
rowSave(row, done, loading) {
add(row).then(() => {
done();
this.onLoad(this.page);
this.$message({
type: "success",
message: "操作成功!"
});
}, error => {
window.console.log(error);
loading();
});
},
rowUpdate(row, index, done, loading) {
update(row).then(() => {
done();
this.onLoad(this.page);
this.$message({
type: "success",
message: "操作成功!"
});
}, error => {
window.console.log(error);
loading();
});
},
rowDel(row) {
this.$confirm("确定将选择数据删除?", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
})
.then(() => {
return remove(row.id);
})
.then(() => {
this.onLoad(this.page);
this.$message({
type: "success",
message: "操作成功!"
});
});
},
handleDelete() {
if (this.selectionList.length === 0) {
this.$message.warning("请选择至少一条数据");
return;
}
this.$confirm("确定将选择数据删除?", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
})
.then(() => {
return remove(this.ids);
})
.then(() => {
this.onLoad(this.page);
this.$message({
type: "success",
message: "操作成功!"
});
this.$refs.crud.toggleSelection();
});
},
beforeOpen(done, type) {
if (["edit", "view"].includes(type)) {
getDetail(this.form.id).then(res => {
this.form = res.data.data;
});
}
done();
},
searchReset() {
this.query = {};
this.onLoad(this.page);
},
searchChange(params, done) {
if (params.dispatchDate) {
console.log(params.dispatchDate, '################');
let date = new Date(params.dispatchDate)
date.setDate(date.getDate())
console.log(date.toISOString().split('T')[0]);
let startTimes = date.toISOString().split('T')[0]
params.weekdate = startTimes
params.yearOfOperation = startTimes.substring(0, 4)
delete params.dispatchDate;
}
this.query = params;
this.page.currentPage = 1;
this.onLoad(this.page, params);
done();
},
selectionChange(list) {
this.selectionList = list;
},
selectionClear() {
this.selectionList = [];
this.$refs.crud.toggleSelection();
},
currentChange(currentPage) {
this.page.currentPage = currentPage;
},
sizeChange(pageSize) {
this.page.pageSize = pageSize;
},
onLoad(page, params = {}) {
this.loading = true;
getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
const data = res.data.data;
this.page.total = data.total;
this.data = data.records;
for (let i = 0; i < this.data.length; i++) {
const lv = this.data[i]
lv.riskAnalysisCompletionRate = lv.riskAnalysisCompletionRate + '%'
lv.hazardRectificationRate = lv.hazardRectificationRate + '%'
lv.completionRateOfTroubleshootingTasks = lv.completionRateOfTroubleshootingTasks + '%'
}
this.loading = false;
this.selectionClear();
});
}
}