<!--
* @Author:
* @Description:
* @Date: 2023-09-08 14:39:48
* @LastEditTime: 2023-09-08 16:11:45
-->
<template>
<div class="firingPoint">
<!-- 上方:查询表单 -->
<el-form :model="form" ref="form" :inline="true" size="small">
<el-row type="flex" justify="space-between">
<el-col :span="20">
<el-form-item label="提交日期:" prop="queryDate">
<el-date-picker
v-model="form.queryDate"
type="daterange"
align="right"
unlink-panels
range-separator="至"
start-placeholder="开始日期"
end-placeholder="结束日期"
:picker-options="this.$global.pickerOptions"
:clearable="false"
></el-date-picker>
</el-form-item>
<el-form-item label="关键字:" prop="keyword">
<el-input v-model="form.keyword" maxlength="30"></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="onQuery">查询</el-button>
<el-button type="primary" @click="onReset">重置</el-button>
</el-form-item>
</el-col>
</el-row>
</el-form>
<div style="width: 100%; height: calc(100% - 83px)">
<el-table
ref="table"
:data="tableData"
stripe
height="100%"
@row-dblclick="onRowDblclick"
@sort-change="onSortChanged"
>
<el-table-column
type="index"
label="序号"
align="center"
width="50"
:index="
(index) =>
this.$common.pageIndexMethod(index, form.pageIndex, form.pageSize)
"
></el-table-column>
<el-table-column
prop="measure"
label="提交日期"
align="center"
sortable="custom"
width="250"
>
<template slot-scope="scope">
{{ scope.row.startTime + "-" + scope.row.endTime }}
</template>
</el-table-column>
<el-table-column
prop="problem"
label="运行中存在的问题"
align="center"
width="300"
></el-table-column>
<el-table-column
prop="measure"
label="解决措施及建议"
align="center"
width="300"
></el-table-column>
</el-table>
</div>
<pagination :total="total" :page.sync="form.pageIndex" :limit.sync="form.pageSize" @pagination="onQuery" />
</div>
</template>
<script>
import pagination from "@/components/Pagination";
import { pageSuggestionForm } from "@/api/firingPoint.js";
export default {
components: { pagination,},
data() {
return {
//查询表单
form: {
queryDate: [
this.$common.getMonthFirstAndLastDay().firstDay,
this.$common.getMonthFirstAndLastDay().lastDay,
],
startTime: null,
endTime: null,
keyword: "",
pageIndex: 0,
pageSize: 30,
sortField: "", //排序字段
sortOrder: "", //排序方向
},
tableData: [], //表格数据
total: 0,//数据总数量
};
},
methods: {
//获取查询条件(主要处理时间段)
getQueryCondition() {
var vdata = { ...this.form };
if (vdata.queryDate) {
vdata.startTime = vdata.queryDate[0];
vdata.endTime = vdata.queryDate[1];
}
return vdata;
},
// 获取表格数据
onQuery() {
var that = this;
var vdata = this.getQueryCondition();
pageSuggestionForm(vdata).then((res) => {
that.tableData = res.data.data.data || [];
that.total = res.data.data.total;
});
},
//重置
onReset() {
if (this.$refs.form) {
this.$refs.form.resetFields();
this.onQuery();
}
},
// ————————————————————————————————表格操作——————————————————————————————
//表格排序
onSortChanged(column) {
var order = column.order;
this.form.sortField = column.prop;
this.form.sortOrder = order
? order === "descending"
? "desc"
: "asc"
: "";
this.onQuery();
},
//双击表格行事件
onRowDblclick(row) {
// this.flag = "look";
// this.selectId = row.id;
// this.dialogVisible = true;
},
},
};
</script>
<style scoped>
.firingPoint {
width: 100%;
height: 100%;
}
</style>
pagination组件代码:
<template>
<div :class="{'hidden':hidden}" class="pagination-container">
<el-pagination :background="background" :current-page.sync="currentPage" :page-size.sync="pageSize" :layout="layout" :page-sizes="pageSizes" :total="total" v-bind="$attrs" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
</div>
</template>
<script>
import { scrollTo } from '@/utils/scroll-to'
export default {
name: 'Pagination',
props: {
total: {
required: true,
type: Number
},
pageIndex: {
type: Number,
default: 0
},
limit: {
type: Number,
default: 30
},
pageSizes: {
type: Array,
default() {
return [10, 20, 30, 50]
}
},
layout: {
type: String,
default: 'total, sizes, prev, pager, next, jumper'
},
background: {
type: Boolean,
default: true
},
autoScroll: {
type: Boolean,
default: true
},
hidden: {
type: Boolean,
default: false
}
},
computed: {
currentPage: {
get() {
return this.pageIndex
},
set(val) {
this.$emit('update:page', val - 1)
}
},
pageSize: {
get() {
return this.limit
},
set(val) {
this.$emit('update:limit', val)
}
}
},
methods: {
handleSizeChange(val) {
this.$emit('pagination', { page: this.currentPage, limit: val })
if (this.autoScroll) {
scrollTo(0, 800)
}
},
handleCurrentChange(val) {
this.$emit('pagination', { page: val, limit: this.pageSize })
if (this.autoScroll) {
scrollTo(0, 800)
}
}
}
}
</script>
<style scoped>
.pagination-container {
padding: 0px !important;
padding-left: 16px !important;
background: #4a4a4a !important;
}
.pagination-container.hidden {
display: none;
}
.el-pagination.is-background .btn-next,
.el-pagination.is-background .btn-prev,
.el-pagination.is-background .el-pager li {
background-color: #595959 !important;
}
</style>
scrollTo组件代码:
Math.easeInOutQuad = function(t, b, c, d) {
t /= d / 2
if (t < 1) {
return c / 2 * t * t + b
}
t--
return -c / 2 * (t * (t - 2) - 1) + b
}
// requestAnimationFrame for Smart Animating http://goo.gl/sx5sts
var requestAnimFrame = (function() {
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function(callback) { window.setTimeout(callback, 1000 / 60) }
})()
/**
* Because it's so fucking difficult to detect the scrolling element, just move them all
* @param {number} amount
*/
function move(amount) {
document.documentElement.scrollTop = amount
document.body.parentNode.scrollTop = amount
document.body.scrollTop = amount
}
function position() {
return document.documentElement.scrollTop || document.body.parentNode.scrollTop || document.body.scrollTop
}
/**
* @param {number} to
* @param {number} duration
* @param {Function} callback
*/
export function scrollTo(to, duration, callback) {
const start = position()
const change = to - start
const increment = 20
let currentTime = 0
duration = (typeof (duration) === 'undefined') ? 500 : duration
var animateScroll = function() {
// increment the time
currentTime += increment
// find the value with the quadratic in-out easing function
var val = Math.easeInOutQuad(currentTime, start, change, duration)
// move the document.body
move(val)
// do the animation unless its over
if (currentTime < duration) {
requestAnimFrame(animateScroll)
} else {
if (callback && typeof (callback) === 'function') {
// the animation is done so lets callback
callback()
}
}
}
animateScroll()
}
限制日期只能选择一个月内(这是个common插件,在main.js注册一下):
import Common from "@/utils/common.js";
Vue.prototype.$common = Common;
export default {
//地址栏参数转对象
param2Obj: function (url) {
const search = decodeURIComponent(url.split("?")[1]).replace(/\+/g, " ");
if (!search) {
return {};
}
const obj = {};
const searchArr = search.split("&");
searchArr.forEach((v) => {
const index = v.indexOf("=");
if (index !== -1) {
const name = v.substring(0, index);
const val = v.substring(index + 1, v.length);
obj[name] = val;
}
});
return obj;
},
//格式化时间
parseTime: function (time, cFormat) {
if (arguments.length === 0 || !time) {
return null;
}
const format = cFormat || "{y}-{m}-{d} {h}:{i}:{s}";
let date;
if (typeof time === "object") {
date = time;
} else {
if (typeof time === "string") {
if (/^[0-9]+$/.test(time)) {
// support "1548221490638"
time = parseInt(time);
} else {
// support safari
// https://stackoverflow.com/questions/4310953/invalid-date-in-safari
time = time.replace(new RegExp(/-/gm), "/");
}
}
if (typeof time === "number" && time.toString().length === 10) {
time = time * 1000;
}
date = new Date(time);
}
const formatObj = {
y: date.getFullYear(),
m: date.getMonth() + 1,
d: date.getDate(),
h: date.getHours(),
i: date.getMinutes(),
s: date.getSeconds(),
a: date.getDay(),
};
const time_str = format.replace(/{([ymdhisa])+}/g, (result, key) => {
const value = formatObj[key];
// Note: getDay() returns 0 on Sunday
if (key === "a") {
return ["日", "一", "二", "三", "四", "五", "六"][value];
}
return value.toString().padStart(2, "0");
});
return time_str;
},
//把bizcode转中文
renderCodeId: function (e, obj) {
if (e && obj) {
for (var m = 0; m < obj.length; m++) {
if (e == obj[m].ID) {
return obj[m].TEXT;
}
}
} else {
return "";
}
},
//分页序号
pageIndexMethod: function (index, pageIndex, pageSize) {
index = index + 1 + pageIndex * pageSize;
return index;
},
//根据后端值渲染文字
//参数
//valueStr : 逗号分隔的字符串 或 单个值的字符串
//list : 键值对对应的集合
//idKey : 标识id的键 字符串
//textKey : 标识name键 字符串
renderCode: function (valueStr, idKey, textKey, list) {
if (valueStr && list) {
var valList = valueStr.split(",");
var result = [];
for (let i = 0; i < valList.length; i++) {
for (let j = 0; j < list.length; j++) {
if (valList[i] == list[j][idKey]) {
result.push(list[j][textKey]);
break;
}
}
}
return result.join(",");
} else {
return "";
}
},
//判断字符是否为空的方法
strIsEmpty: function (obj) {
if (typeof obj == "undefined" || obj == null || obj == "") {
return true;
} else {
return false;
}
},
getDeptTree: function (data, pid) {
const result = [];
let temp;
for (let i = 0; i < data.length; i++) {
if (data[i].pid === pid) {
temp = getDeptTree(data, data[i].id);
if (temp.length > 0) {
data[i].children = temp;
}
result.push(data[i]);
}
}
return result;
},
displayYear: function () {
//获取系统当前的年、月、日、小时、分钟、毫秒
var date = new Date();
var year = date.getFullYear();
var month = date.getMonth() + 1;
if (month < 10) {
month = "0" + month;
}
var day = date.getDate();
if (day < 10) {
day = "0" + day;
}
var timestr = year + "/" + month + "/" + day;
//将系统时间设置到div元素中
return timestr;
},
showHourTime: function () {
//获取系统当前的年、月、日、小时、分钟、毫秒
var date = new Date();
var hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
var minutes =
date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
var second =
date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
var hourTime = hour + ":" + minutes;
//将系统时间设置到div元素中
return hourTime;
},
//获取当前月份 第一天和最后一天
getMonthFirstAndLastDay: function () {
var date = new Date(),
y = date.getFullYear(),
m = date.getMonth();
var firstDay = new Date(y, m, 1);
var lastDay = new Date(y, m + 1, 0);
var time = {
firstDay: new Date(firstDay),
lastDay: new Date(lastDay),
};
return time;
},
// Debounce: function(fn, t) {
// const delay = t || 500
// let timeout
// return function() {
// const context = this
// const args = arguments
// if (!timeout) {
// timeout = setTimeout(() => {
// timeout = null
// fn.apply(context, args)
// }, delay)
// }
// }
// },
Debounce: function (fn, t) {
let delay = t || 500;
let timer;
console.log(fn);
console.log(typeof fn);
return function () {
let args = arguments;
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(() => {
timer = null;
fn.apply(this, args);
}, delay);
};
},
//将字段驼峰转大写下划线
toXHXUpper: function (val) {
return val ? val.replace(/([A-Z])/g, "_$1").toUpperCase() : "";
},
/**
* 获取上一个月
* @date 格式为yyyy-mm-dd的日期,如:2014-01-25
*/
getPreMonth: function (date) {
var arr = date.split("-");
var year = arr[0]; //获取当前日期的年份
var month = arr[1]; //获取当前日期的月份
var day = arr[2]; //获取当前日期的日
var year2 = year;
var month2 = parseInt(month) - 1;
if (month2 == 0) {
year2 = parseInt(year2) - 1;
month2 = 12;
}
var day2 = day;
var days2 = new Date(year2, month2, 0);
days2 = days2.getDate();
if (day2 > days2) {
day2 = days2;
}
if (month2 < 10) {
month2 = "0" + month2;
}
var t2 = year2 + "-" + month2 + "-" + day2;
return t2;
},
/**
* 获取下一个月
* @date 格式为yyyy-mm-dd的日期,如:2014-01-25
*/
getNextMonth: function (date) {
var arr = date.split("-");
var year = arr[0]; //获取当前日期的年份
var month = arr[1]; //获取当前日期的月份
var day = arr[2]; //获取当前日期的日
var year2 = year;
var month2 = parseInt(month) + 1;
if (month2 == 13) {
year2 = parseInt(year2) + 1;
month2 = 1;
}
var day2 = day;
var days2 = new Date(year2, month2, 0);
days2 = days2.getDate();
if (day2 > days2) {
day2 = days2;
}
if (month2 < 10) {
month2 = "0" + month2;
}
var t2 = year2 + "-" + month2 + "-" + day2;
return t2;
},
// 转成children树
getTree: function (data) {
let result = [];
if (!Array.isArray(data)) {
return result;
}
data.forEach((item) => {
delete item.children;
});
let map = {};
data.forEach((item) => {
map[item.id] = item;
});
data.forEach((item) => {
let parent = map[item.pid];
if (parent) {
(parent.children || (parent.children = [])).push(item);
} else {
result.push(item);
}
});
return result;
},
//根据日期判断是周几
getWeekByDate: function (date) {
if (arguments.length === 0 || !date) {
return null;
}
var weekList = new Array("日", "一", "二", "三", "四", "五", "六");
if (typeof date === "object") {
return weekList[date.getDay()];
} else if (typeof date == "string") {
return weekList[new Date(date).getDay()];
}
},
//经度校验
lontitudeValidation: function (e) {
var lonExpStr =
/^-?(((\d{1,2})|(1[0-7]\d))((0|[1-5])\d)((0|[1-5])\d))$|^1800000$|^-1800000$/;
var lonExp = new RegExp(lonExpStr);
if (lonExp.test(e)) {
return true;
} else {
return false;
}
},
//纬度校验
latitudeValidation: function (e) {
var latExpStr =
/^-?(((\d)|([1-8]\d))((0|[1-5])\d)((0|[1-5])\d))$|^900000$|^-900000$/;
var latExp = new RegExp(latExpStr);
if (latExp.test(e)) {
return true;
} else {
return false;
}
},
/**
* 根据年月获取当月最后一天,或者根据年月获取最大的天数
* @param {*} month 2023-03
* @returns 31
*/
queryMaxDayByMonth: function (month) {
var arr = month.split("-");
const maxDay = new Date(arr[0], arr[1], 0).getDate();
return maxDay;
},
//根据数据字典渲染文字,若没有对应字典,则返回原值
//参数
//valueStr : 逗号分隔的字符串 或 单个值的字符串
//list : 键值对对应的集合
//idKey : 标识id的键 字符串
//textKey : 标识name键 字符串
renderCodeNotEmpty: function (valueStr, idKey, textKey, list) {
if (valueStr && list) {
var valList = valueStr.split(",");
var result = [];
for (let i = 0; i < valList.length; i++) {
var isMatch = false;
for (let j = 0; j < list.length; j++) {
if (valList[i] == list[j][idKey]) {
result.push(list[j][textKey]);
isMatch = true;
break;
}
}
if (!isMatch) {
result.push(valList[i]);
}
}
return result.join(",");
} else {
return "";
}
},
};
想要使用的时候输入:
queryDate: [
this.$common.getMonthFirstAndLastDay().firstDay,
this.$common.getMonthFirstAndLastDay().lastDay,
],