一、初始化页面
<template>
<basic-container>
<avue-crud
:table-loading="loading"
:data="tableData"
:option="option"
v-model="form"
:page.sync="page"
@row-del="rowDel"
@search-change="searchChange"
@selection-change="selectionChange"
@search-reset="searchReset"
ref="crud"
@on-load="onLoad"
@current-change="currentChange"
@size-change="sizeChange"
@refresh-change="refreshChange"
:permission="permissionList"
>
<template slot="menuLeft">
<!-- 左菜单左上角-新增 -->
<el-button
type="primary"
icon="el-icon-plus"
size="small"
@click="rowAdd"
>
新 增
</el-button>
<!-- 左菜单左上角-删除 -->
<el-button
type="danger"
size="small"
icon="el-icon-delete"
plain
@click="handleBtn('delete')"
>
删 除
</el-button>
<el-button
type="default"
size="small"
plain
@click="handleBtn('enable')"
>
启 用
</el-button>
<el-button
type="default"
size="small"
plain
@click="handleBtn('disable')"
>
停 用
</el-button>
</template>
<!-- 导航类型 -->
<template slot-scope="{ row }" slot="navigationType">
{
{
navigationTypeData(row) }}
</template>
<template slot-scope="{ row }" slot="menu">
<el-button type="text" size="small" @click="rowEdit(row)">
编辑
</el-button>
<el-button type="text" size="small" @click="rowDel(row)">
删除
</el-button>
</template>
<!-- 显隐列设置 -->
<template slot="menuRight">
<showHidden
:column.sync="option.column"
moduleType="TASK"
:constData.sync="constOptionData"
></showHidden>
</template>
</avue-crud>
</template>
<script>
import {
startMapAction } from '@/views/base/map/http/request';
import detailForm from '@/components/detail-form/index.vue';
import {
getStore } from '@/utils/store';
import showHidden from '@/components/table-implicit/index.vue';
let customConstant = [
'code',
'name',
'priority',
'isOnLoad',
];
export default {
components: {
detailForm,
showHidden,
},
data() {
return {
page: {
pageSize: 10,
currentPage: 1,
total: 0,
},
loading: false,
form: {
},
query: {
},
search: {
},
selectionList: [],
constOptionData: [],
tableData: [],
addDrawer: false,
editDrawer: false,
};
},
created() {
let column = localStorage.getItem(this.$route.path);
if (column) {
this.option.column = JSON.parse(column);
console.log(this.option);
}
this.constOptionData = customConstant;
if (getStore({
name: 'TASK' })) {
let data = getStore({
name: 'TASK' });
data.forEach((item) => {
this.option.column.forEach((chileItem) => {
if (item.prop === chileItem.prop) {
chileItem.hide = item.hide;
}
});
});
}
},
methods: {
onLoad(page, params = {
}) {
this.loading = true;
getList(
page.currentPage,
page.pageSize,
Object.assign(params, this.query)
).then((res) => {
this.page.total = res.data.total;
console.log('列表被打印啦:', res);
this.tableData = res.data.records;
this.loading = false;
});
},
searchChange(params, done) {
this.query = params;
this.page.currentPage = 1;
this.onLoad(this.page, this.query);
done();
},
currentChange(currentPage) {
this.page.currentPage = currentPage;
},
sizeChange(pageSize) {
this.page.pageSize = pageSize;
},
refreshChange() {
this.onLoad(this.page, this.query);
},
searchReset() {
this.query = {
};
this.search = {
};
this.onLoad(this.page);
},
selectionChange(list) {
this.selectionList = list;
},
},
};
</script>
<style scoped></style>
import request from '@/router/axios';
export const getList = (pageNum, pageSize, data) => {
const requestData = {
pageNum,
pageSize,
...data,
};
return request({
url: '/api/order/onQueryLcsOrders',
method: 'post',
data: requestData,
})
}
import request from '@/router/axios';
export const getList = (current, size, params) => {
const requestData = {
current,
size,
...params,
};
return request({
url: '/api/lcsTask/page',
method: 'get',
params: requestData,
})
}
- 传参(图)
![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/198faef87e61473a8a1f6fb4e205cced.png)
1. 有 avue ,js 补 option
data() {
var validateCode = (rule, value, callback) => {
if (value == '') {
callback(new Error('请输入任务模板编号'));
} else {
if (validateNumberCase(value)) {
if (value.length > 16) {
callback(new Error('最多16位,支持数字和字母'));
} else {
callback();
}
} else {
callback(new Error('最多16位,支持数字和字母'));
}
}
};
return {
...
}
}
return {
option: {
menu: true,
selection: true,
tip: false,
searchLabelWidth: 90,
labelWidth: 120,
menuAlign: 'center',
menuWidth: '160',
grid: false,
searchMenuPosition: 'right',
searchMenuSpan: 6,
border: true,
viewBtn: false,
copyBtn: false,
addBtn: false,
editBtn: false,
delBtn: false,
saveBtn: false,
cancelBtn: false,
viewBtnIcon: ' ',
editBtnIcon: ' ',
delBtnIcon: ' ',
updateBtnIcon: ' ',
cancelBtnIcon: ' ',
dialogWidth: 600,
reserveSelection: false,
columnBtn: false,
searchBtnText: '查询',
emptyBtnText: '重置',
column: [
{
label: '编号',
prop: 'code',
width: 120,
span: 20,
labelWidth: '180',
align: 'center',
row: true,
hide: false,
showColumn: true,
search: false,
disabled: true,
slot: true,
sortable: true,
rules: [
{
required: true, validator: validateCode, trigger: 'blur' },
],
},
{
label: '地图名称',
prop: 'codeOrName',
search: true,
searchLabel: '地图',
searchPlaceholder: '请输入名称',
align: 'center',
labelWidth: '180',
span: 20,
searchLabelWidth: 60,
searchSpan: 4,
showColumn: true,
slot: true,
sortable: true,
minWidth: '100',
},
{
label: '点位',
prop: 'codeOrName',
width: 130,
searchSpan: 4,
searchLabelWidth: 60,
hide: true,
showColumn: true,
search: true,
searchPlaceholder: '编号或名称',
slot: true,
viewDisplay: false,
addDisplay: false,
editDisplay: false,
},
{
label: '名称',
prop: 'name',
width: 120,
span: 20,
labelWidth: '180',
row: true,
hide: false,
showColumn: true,
align: 'center',
search: false,
slot: true,
sortable: true,
},
{
label: '类型',
prop: 'type',
span: 20,
labelWidth: '180',
row: true,
hide: false,
showColumn: true,
align: 'center',
search: true,
slot: true,
sortable: true,
type: 'select',
dicUrl: '/api/dict/list?code=charge_station',
props: {
label: 'label',
value: 'value',
},
},
{
label: '优先级',
prop: 'priority',
width: 100,
span: 20,
labelWidth: '180',
row: true,
hide: false,
showColumn: true,
align: 'center',
search: false,
slot: true,
sortable: true,
},
{
label: '是否允许充电',
prop: 'isOnLoad',
width: 150,
span: 20,
labelWidth: '190',
row: true,
hide: false,
showColumn: true,
align: 'center',
slot: true,
sortable: true,
type: 'select',
dicData: [
{
label: '是',
value: true,
},
{
label