<template>
|
<div class="search">
|
<add v-if="currView=='add'" @close="currView='index'" @submited="submited" />
|
<edit v-if="currView=='edit'" @close="currView='index'" @submited="submited" :data="formData" />
|
<Card v-show="currView=='index'">
|
<%
|
if(searchSize>0&&!hideSearch){
|
%>
|
<Row v-show="openSearch" @keydown.enter.native="handleSearch">
|
<Form ref="searchForm" :model="searchForm" inline :label-width="70">
|
<%
|
for(item in fields){
|
if(item.searchable){
|
%>
|
<%
|
if(item.searchType=="text"){
|
%>
|
<FormItem label="${item.name}" prop="${item.field}">
|
<Input type="text" v-model="searchForm.${item.field}" placeholder="请输入${item.name}" clearable style="width: 200px"/>
|
</FormItem>
|
<%
|
}
|
%>
|
<%
|
if(item.searchType=="select"){
|
%>
|
<FormItem label="${item.name}" prop="${item.field}">
|
<Select v-model="searchForm.${item.field}" placeholder="请选择" clearable style="width: 200px">
|
<Option value="0">请自行编辑下拉菜单</Option>
|
</Select>
|
</FormItem>
|
<%
|
}
|
%>
|
<%
|
if(item.searchType=="date"){
|
%>
|
<FormItem label="${item.name}" prop="${item.field}">
|
<DatePicker type="date" v-model="searchForm.${item.field}" placeholder="请选择" clearable style="width: 200px"></DatePicker>
|
</FormItem>
|
<%
|
}
|
%>
|
<%
|
if(item.searchType=="daterange"){
|
%>
|
<FormItem label="${item.name}" prop="${item.field}">
|
<DatePicker :options="options" v-model="selectDate" type="daterange" format="yyyy-MM-dd" clearable @on-change="selectDateRange" placeholder="选择起始时间" style="width: 200px"></DatePicker>
|
</FormItem>
|
<%
|
}
|
%>
|
<%
|
if(item.searchType=="area"){
|
%>
|
<FormItem label="${item.name}" prop="${item.field}">
|
<al-cascader v-model="searchForm.${item.field}" data-type="name" level="${item.searchLevel}" style="width:200px"/>
|
</FormItem>
|
<%
|
}
|
%>
|
<%
|
if(item.searchType=="dict"){
|
%>
|
<FormItem label="${item.name}" prop="${item.field}">
|
<dict v-model="searchForm.${item.field}" dict="${item.searchDictType}" transfer style="width:200px"/>
|
</FormItem>
|
<%
|
}
|
%>
|
<%
|
if(item.searchType=="customList"){
|
%>
|
<FormItem label="${item.name}" prop="${item.field}">
|
<customList v-model="searchForm.${item.field}" url="${item.searchCustomUrl}" transfer style="width:200px"/>
|
</FormItem>
|
<%
|
}
|
%>
|
<%
|
}
|
}
|
%>
|
<FormItem style="margin-left:-35px;" class="br">
|
<Button @click="handleSearch" type="primary" icon="ios-search">搜索</Button>
|
<Button @click="handleReset">重置</Button>
|
</FormItem>
|
</Form>
|
</Row>
|
<%
|
}
|
%>
|
<%
|
if(searchSize>0&&hideSearch){
|
%>
|
<Row v-show="openSearch" @keydown.enter.native="handleSearch">
|
<Form ref="searchForm" :model="searchForm" inline :label-width="70" class="search-form">
|
<%
|
for(item in firstTwo){
|
%>
|
<%
|
if(item.searchType=="text"){
|
%>
|
<FormItem label="${item.name}" prop="${item.field}">
|
<Input type="text" v-model="searchForm.${item.field}" placeholder="请输入${item.name}" clearable style="width: 200px"/>
|
</FormItem>
|
<%
|
}
|
%>
|
<%
|
if(item.searchType=="select"){
|
%>
|
<FormItem label="${item.name}" prop="${item.field}">
|
<Select v-model="searchForm.${item.field}" placeholder="请选择" clearable style="width: 200px">
|
<Option value="0">请自行编辑下拉菜单</Option>
|
</Select>
|
</FormItem>
|
<%
|
}
|
%>
|
<%
|
if(item.searchType=="date"){
|
%>
|
<FormItem label="${item.name}" prop="${item.field}">
|
<DatePicker type="date" v-model="searchForm.${item.field}" placeholder="请选择" clearable style="width: 200px"></DatePicker>
|
</FormItem>
|
<%
|
}
|
%>
|
<%
|
if(item.searchType=="daterange"){
|
%>
|
<FormItem label="${item.name}" prop="${item.field}">
|
<DatePicker :options="options" v-model="selectDate" type="daterange" format="yyyy-MM-dd" clearable @on-change="selectDateRange" placeholder="选择起始时间" style="width: 200px"></DatePicker>
|
</FormItem>
|
<%
|
}
|
%>
|
<%
|
if(item.searchType=="area"){
|
%>
|
<FormItem label="${item.name}" prop="${item.field}">
|
<al-cascader v-model="searchForm.${item.field}" data-type="name" level="${item.searchLevel}" style="width:200px"/>
|
</FormItem>
|
<%
|
}
|
%>
|
<%
|
if(item.searchType=="dict"){
|
%>
|
<FormItem label="${item.name}" prop="${item.field}">
|
<dict v-model="searchForm.${item.field}" dict="${item.searchDictType}" transfer style="width:200px"/>
|
</FormItem>
|
<%
|
}
|
%>
|
<%
|
if(item.searchType=="customList"){
|
%>
|
<FormItem label="${item.name}" prop="${item.field}">
|
<customList v-model="searchForm.${item.field}" url="${item.searchCustomUrl}" transfer style="width:200px"/>
|
</FormItem>
|
<%
|
}
|
%>
|
<%
|
}
|
%>
|
<span v-if="drop">
|
<%
|
for(item in rest){
|
%>
|
<%
|
if(item.searchType=="text"){
|
%>
|
<FormItem label="${item.name}" prop="${item.field}">
|
<Input type="text" v-model="searchForm.${item.field}" placeholder="请输入${item.name}" clearable style="width: 200px"/>
|
</FormItem>
|
<%
|
}
|
%>
|
<%
|
if(item.searchType=="select"){
|
%>
|
<FormItem label="${item.name}" prop="${item.field}">
|
<Select v-model="searchForm.${item.field}" placeholder="请选择" clearable style="width: 200px">
|
<Option value="0">请自行编辑下拉菜单</Option>
|
</Select>
|
</FormItem>
|
<%
|
}
|
%>
|
<%
|
if(item.searchType=="date"){
|
%>
|
<FormItem label="${item.name}" prop="${item.field}">
|
<DatePicker type="date" v-model="searchForm.${item.field}" placeholder="请选择" clearable style="width: 200px"></DatePicker>
|
</FormItem>
|
<%
|
}
|
%>
|
<%
|
if(item.searchType=="daterange"){
|
%>
|
<FormItem label="${item.name}" prop="${item.field}">
|
<DatePicker :options="options" v-model="selectDate" type="daterange" format="yyyy-MM-dd" clearable @on-change="selectDateRange" placeholder="选择起始时间" style="width: 200px"></DatePicker>
|
</FormItem>
|
<%
|
}
|
%>
|
<%
|
if(item.searchType=="area"){
|
%>
|
<FormItem label="${item.name}" prop="${item.field}">
|
<al-cascader v-model="searchForm.${item.field}" data-type="name" level="${item.searchLevel}" style="width:200px"/>
|
</FormItem>
|
<%
|
}
|
%>
|
<%
|
if(item.searchType=="dict"){
|
%>
|
<FormItem label="${item.name}" prop="${item.field}">
|
<dict v-model="searchForm.${item.field}" dict="${item.searchDictType}" transfer style="width:200px"/>
|
</FormItem>
|
<%
|
}
|
%>
|
<%
|
if(item.searchType=="customList"){
|
%>
|
<FormItem label="${item.name}" prop="${item.field}">
|
<customList v-model="searchForm.${item.field}" url="${item.searchCustomUrl}" transfer style="width:200px"/>
|
</FormItem>
|
<%
|
}
|
%>
|
<%
|
}
|
%>
|
</span>
|
<FormItem style="margin-left:-35px;" class="br">
|
<Button @click="handleSearch" type="primary" icon="ios-search">搜索</Button>
|
<Button @click="handleReset">重置</Button>
|
<a class="drop-down" @click="dropDown">
|
{{dropDownContent}}
|
<Icon :type="dropDownIcon"></Icon>
|
</a>
|
</FormItem>
|
</Form>
|
</Row>
|
<%
|
}
|
%>
|
<Row class="operation">
|
<Button @click="add" type="primary" icon="md-add">添加</Button>
|
<Button @click="delAll" icon="md-trash">批量删除</Button>
|
<Button @click="getDataList" icon="md-refresh">刷新</Button>
|
<Button type="dashed" @click="openTip=!openTip">{{openTip ? "关闭提示" : "开启提示"}}</Button>
|
</Row>
|
<Alert show-icon v-show="openTip">
|
已选择
|
<span class="select-count">{{selectList.length}}</span> 项
|
<a class="select-clear" @click="clearSelectAll">清空</a>
|
</Alert>
|
<Table
|
:loading="loading"
|
border
|
:columns="columns"
|
:data="data"
|
ref="table"
|
sortable="custom"
|
@on-sort-change="changeSort"
|
@on-selection-change="changeSelect"
|
></Table>
|
<Row type="flex" justify="end" class="page">
|
<Page
|
:current="searchForm.pageNumber"
|
:total="total"
|
:page-size="searchForm.pageSize"
|
@on-change="changePage"
|
@on-page-size-change="changePageSize"
|
:page-size-opts="[10,20,50]"
|
size="small"
|
show-total
|
show-elevator
|
show-sizer
|
></Page>
|
</Row>
|
</Card>
|
</div>
|
</template>
|
|
<script>
|
<%
|
if(api){
|
%>
|
// 根据你的实际请求api.js位置路径修改
|
import { get${apiName}List, delete${apiName} } from "@/api/index";
|
<%
|
}
|
%>
|
// 根据你的实际添加编辑组件位置路径修改
|
import add from "./add.vue";
|
import edit from "./edit.vue";
|
<%
|
if(searchDict){
|
%>
|
import dict from "@/views/my-components/xboot/dict";
|
<%
|
}
|
%>
|
<%
|
if(searchCustomList){
|
%>
|
import customList from "@/views/my-components/xboot/custom-list";
|
<%
|
}
|
%>
|
import { shortcuts } from "@/libs/shortcuts";
|
export default {
|
name: "${vueName}",
|
components: {
|
add,
|
edit,
|
<%
|
if(searchDict){
|
%>
|
dict,
|
<%
|
}
|
%>
|
<%
|
if(searchCustomList){
|
%>
|
customList,
|
<%
|
}
|
%>
|
},
|
data() {
|
return {
|
<% if(searchSize>0){ %>
|
openSearch: true, // 显示搜索
|
<% }%>
|
openTip: true, // 显示提示
|
formData: {},
|
currView: "index",
|
loading: true, // 表单加载状态
|
<% if(hideSearch) { %>
|
drop: false,
|
dropDownContent: "展开",
|
dropDownIcon: "ios-arrow-down",
|
<% } %>
|
searchForm: { // 搜索框初始化对象
|
pageNumber: 1, // 当前页数
|
pageSize: 10, // 页面大小
|
sort: "createTime", // 默认排序字段
|
order: "desc", // 默认排序方式
|
<% if(daterangeSearch){ %>
|
startDate: "", // 起始时间
|
endDate: "", // 终止时间
|
<% } %>
|
<%
|
for(item in fields){
|
if(item.searchable && item.searchType=="area"){
|
%>
|
${item.field}: [],
|
<%
|
}
|
}
|
%>
|
},
|
<% if(daterangeSearch){ %>
|
selectDate: null,
|
options: {
|
shortcuts: shortcuts,
|
},
|
<% } %>
|
selectList: [], // 多选数据
|
columns: [
|
// 表头
|
{
|
type: "selection",
|
width: 60,
|
align: "center"
|
},
|
{
|
type: "index",
|
width: 60,
|
align: "center"
|
},
|
<%
|
for(item in fields){
|
if(item.tableShow){
|
%>
|
{
|
title: "${item.name}",
|
key: "${item.field}",
|
minWidth: 120,
|
<%
|
if(item.sortable){
|
%>
|
sortable: true,
|
<%
|
}else{
|
%>
|
sortable: false,
|
<%
|
}
|
%>
|
<%
|
if(item.defaultSort){
|
%>
|
sortType: "${item.defaultSortType}"
|
<%
|
}
|
%>
|
},
|
<%
|
}
|
}
|
%>
|
{
|
title: "操作",
|
key: "action",
|
align: "center",
|
width: 150,
|
render: (h, params) => {
|
return h("div", [
|
h(
|
"a",
|
{
|
on: {
|
click: () => {
|
this.edit(params.row);
|
}
|
}
|
},
|
"编辑"
|
),
|
h("Divider", {
|
props: {
|
type: "vertical",
|
},
|
}),
|
h(
|
"a",
|
{
|
on: {
|
click: () => {
|
this.remove(params.row);
|
}
|
}
|
},
|
"删除"
|
)
|
]);
|
}
|
}
|
],
|
data: [], // 表单数据
|
pageNumber: 1, // 当前页数
|
pageSize: 10, // 页面大小
|
total: 0 // 表单数据总数
|
};
|
},
|
methods: {
|
init() {
|
this.getDataList();
|
},
|
submited() {
|
this.currView = "index";
|
this.getDataList();
|
},
|
changePage(v) {
|
this.searchForm.pageNumber = v;
|
this.getDataList();
|
this.clearSelectAll();
|
},
|
changePageSize(v) {
|
this.searchForm.pageSize = v;
|
this.getDataList();
|
},
|
<% if(searchSize>0){ %>
|
handleSearch() {
|
this.searchForm.pageNumber = 1;
|
this.searchForm.pageSize = 10;
|
this.getDataList();
|
},
|
<% } %>
|
handleReset() {
|
this.$refs.searchForm.resetFields();
|
this.searchForm.pageNumber = 1;
|
this.searchForm.pageSize = 10;
|
<% if(daterangeSearch){ %>
|
this.selectDate = null;
|
this.searchForm.startDate = "";
|
this.searchForm.endDate = "";
|
<% } %>
|
// 重新加载数据
|
this.getDataList();
|
},
|
changeSort(e) {
|
this.searchForm.sort = e.key;
|
this.searchForm.order = e.order;
|
if (e.order === "normal") {
|
this.searchForm.order = "";
|
}
|
this.getDataList();
|
},
|
<% if(daterangeSearch){ %>
|
selectDateRange(v) {
|
if (v) {
|
this.searchForm.startDate = v[0];
|
this.searchForm.endDate = v[1];
|
}
|
},
|
<% } %>
|
<% if(hideSearch){ %>
|
dropDown() {
|
if (this.drop) {
|
this.dropDownContent = "展开";
|
this.dropDownIcon = "ios-arrow-down";
|
} else {
|
this.dropDownContent = "收起";
|
this.dropDownIcon = "ios-arrow-up";
|
}
|
this.drop = !this.drop;
|
},
|
<% } %>
|
clearSelectAll() {
|
this.$refs.table.selectAll(false);
|
},
|
changeSelect(e) {
|
this.selectList = e;
|
},
|
getDataList() {
|
this.loading = true;
|
<%
|
if(api){
|
%>
|
get${apiName}List(this.searchForm).then(res => {
|
this.loading = false;
|
if (res.success) {
|
this.data = res.result.content;
|
this.total = res.result.totalElements;
|
if (this.data.length == 0 && this.searchForm.pageNumber > 1) {
|
this.searchForm.pageNumber -= 1;
|
this.getDataList();
|
}
|
}
|
});
|
<%
|
} else {
|
%>
|
// 带多条件搜索参数获取表单数据 请自行修改接口
|
// this.getRequest("请求路径", this.searchForm).then(res => {
|
// this.loading = false;
|
// if (res.success) {
|
// this.data = res.result.content;
|
// this.total = res.result.totalElements;
|
// if (this.data.length == 0 && this.searchForm.pageNumber > 1) {
|
// this.searchForm.pageNumber -= 1;
|
// this.getDataList();
|
// }
|
// }
|
// });
|
// 以下为模拟数据
|
//this.data = [
|
//];
|
this.total = this.data.length;
|
this.loading = false;
|
<%
|
}
|
%>
|
},
|
add() {
|
this.currView = "add";
|
},
|
edit(v) {
|
// 转换null为""
|
for (let attr in v) {
|
if (v[attr] == null) {
|
v[attr] = "";
|
}
|
}
|
let str = JSON.stringify(v);
|
let data = JSON.parse(str);
|
this.formData = data;
|
this.currView = "edit";
|
},
|
remove(v) {
|
this.$Modal.confirm({
|
title: "确认删除",
|
// 记得确认修改此处
|
content: "您确认要删除该条数据?",
|
loading: true,
|
onOk: () => {
|
// 删除
|
<%
|
if(api){
|
%>
|
delete${apiName}({ids: v.id}).then(res => {
|
this.$Modal.remove();
|
if (res.success) {
|
this.$Message.success("操作成功");
|
this.clearSelectAll();
|
this.getDataList();
|
}
|
});
|
<%
|
} else {
|
%>
|
// this.deleteRequest("请求地址,如/deleteByIds/" + v.id).then(res => {
|
// this.$Modal.remove();
|
// if (res.success) {
|
// this.$Message.success("操作成功");
|
// this.clearSelectAll();
|
// this.getDataList();
|
// }
|
// });
|
// 模拟请求成功
|
this.$Message.success("操作成功");
|
this.clearSelectAll();
|
this.$Modal.remove();
|
this.getDataList();
|
<%
|
}
|
%>
|
}
|
});
|
},
|
delAll() {
|
if (this.selectList.length <= 0) {
|
this.$Message.warning("您还未选择要删除的数据");
|
return;
|
}
|
this.$Modal.confirm({
|
title: "确认删除",
|
content: "您确认要删除所选的 " + this.selectList.length + " 条数据?",
|
loading: true,
|
onOk: () => {
|
let ids = "";
|
this.selectList.forEach(function(e) {
|
ids += e.id + ",";
|
});
|
ids = ids.substring(0, ids.length - 1);
|
// 批量删除
|
<%
|
if(api){
|
%>
|
delete${apiName}({ids: ids}).then(res => {
|
this.$Modal.remove();
|
if (res.success) {
|
this.$Message.success("操作成功");
|
this.clearSelectAll();
|
this.getDataList();
|
}
|
});
|
<%
|
} else {
|
%>
|
// this.deleteRequest("请求地址,如/deleteByIds/" + ids).then(res => {
|
// this.$Modal.remove();
|
// if (res.success) {
|
// this.$Message.success("操作成功");
|
// this.clearSelectAll();
|
// this.getDataList();
|
// }
|
// });
|
// 模拟请求成功
|
this.$Message.success("操作成功");
|
this.$Modal.remove();
|
this.clearSelectAll();
|
this.getDataList();
|
<%
|
}
|
%>
|
}
|
});
|
}
|
},
|
mounted() {
|
this.init();
|
}
|
};
|
</script>
|
<style lang="less">
|
@import "@/styles/table-common.less";
|
</style>
|