Browse Source

任务计划

master
xuhuajiao 8 months ago
parent
commit
83b0e71d01
  1. 37
      src/api/storeManage/taskManage/index.js
  2. 890
      src/utils/index.js
  3. 264
      src/views/storeManage/taskManage/index.vue
  4. 24
      src/views/storeManage/taskManage/module/detail.vue

37
src/api/storeManage/taskManage/index.js

@ -1,35 +1,13 @@
import request from '@/utils/request'
// 获取所有的Role
export function getAll() {
return request({
url: 'api/roles/all',
method: 'get'
})
}
export function add(data) {
return request({
url: 'api/roles',
url: 'api/device/editTimedTasks',
method: 'post',
data
})
}
export function get(id) {
return request({
url: 'api/roles/' + id,
method: 'get'
})
}
export function getLevel() {
return request({
url: 'api/roles/level',
method: 'get'
})
}
export function del(ids) {
return request({
url: 'api/roles',
@ -40,18 +18,19 @@ export function del(ids) {
export function edit(data) {
return request({
url: 'api/roles',
method: 'put',
url: 'api/device/editTimedTasks',
method: 'post',
data
})
}
export function editMenu(data) {
// 更改计划任务状态
export function FetchStatus(data) {
return request({
url: 'api/roles/menu',
method: 'put',
url: 'api/device/changeTimedTasksStatus',
method: 'post',
data
})
}
export default { add, edit, del, get, editMenu, getLevel }
export default { add, edit, del, FetchStatus }

890
src/utils/index.js

@ -1,441 +1,449 @@
/**
* Created by PanJiaChen on 16/11/18.
*/
/**
* Parse the time to string
* @param {(Object|string|number)} time
* @param {string} cFormat
* @returns {string}
*/
export function parseTime(time, cFormat) {
if (arguments.length === 0) {
return null
}
const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
let date
if (typeof time === 'undefined' || time === null || time === 'null') {
return ''
} else if (typeof time === 'object') {
date = time
} else {
if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) {
time = parseInt(time)
}
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(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
let value = formatObj[key]
// Note: getDay() returns 0 on Sunday
if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value ] }
if (result.length > 0 && value < 10) {
value = '0' + value
}
return value || 0
})
return time_str
}
/**
* @param {number} time
* @param {string} option
* @returns {string}
*/
export function formatTime(time, option) {
if (('' + time).length === 10) {
time = parseInt(time) * 1000
} else {
time = +time
}
const d = new Date(time)
const now = Date.now()
const diff = (now - d) / 1000
if (diff < 30) {
return '刚刚'
} else if (diff < 3600) {
// less 1 hour
return Math.ceil(diff / 60) + '分钟前'
} else if (diff < 3600 * 24) {
return Math.ceil(diff / 3600) + '小时前'
} else if (diff < 3600 * 24 * 2) {
return '1天前'
}
if (option) {
return parseTime(time, option)
} else {
return (
d.getMonth() +
1 +
'月' +
d.getDate() +
'日' +
d.getHours() +
'时' +
d.getMinutes() +
'分'
)
}
}
/**
* @param {string} url
* @returns {Object}
*/
export function getQueryObject(url) {
url = url == null ? window.location.href : url
const search = url.substring(url.lastIndexOf('?') + 1)
const obj = {}
const reg = /([^?&=]+)=([^?&=]*)/g
search.replace(reg, (rs, $1, $2) => {
const name = decodeURIComponent($1)
let val = decodeURIComponent($2)
val = String(val)
obj[name] = val
return rs
})
return obj
}
/**
* @param {string} input value
* @returns {number} output value
*/
export function byteLength(str) {
// returns the byte length of an utf8 string
let s = str.length
for (var i = str.length - 1; i >= 0; i--) {
const code = str.charCodeAt(i)
if (code > 0x7f && code <= 0x7ff) s++
else if (code > 0x7ff && code <= 0xffff) s += 2
if (code >= 0xDC00 && code <= 0xDFFF) i--
}
return s
}
/**
* @param {Array} actual
* @returns {Array}
*/
export function cleanArray(actual) {
const newArray = []
for (let i = 0; i < actual.length; i++) {
if (actual[i]) {
newArray.push(actual[i])
}
}
return newArray
}
/**
* @param {Object} json
* @returns {Array}
*/
export function param(json) {
if (!json) return ''
return cleanArray(
Object.keys(json).map(key => {
if (json[key] === undefined) return ''
return encodeURIComponent(key) + '=' + encodeURIComponent(json[key])
})
).join('&')
}
/**
* @param {string} url
* @returns {Object}
*/
export function param2Obj(url) {
const search = url.split('?')[1]
if (!search) {
return {}
}
return JSON.parse(
'{"' +
decodeURIComponent(search)
.replace(/"/g, '\\"')
.replace(/&/g, '","')
.replace(/=/g, '":"')
.replace(/\+/g, ' ') +
'"}'
)
}
/**
* @param {string} val
* @returns {string}
*/
export function html2Text(val) {
const div = document.createElement('div')
div.innerHTML = val
return div.textContent || div.innerText
}
/**
* Merges two objects, giving the last one precedence
* @param {Object} target
* @param {(Object|Array)} source
* @returns {Object}
*/
export function objectMerge(target, source) {
if (typeof target !== 'object') {
target = {}
}
if (Array.isArray(source)) {
return source.slice()
}
Object.keys(source).forEach(property => {
const sourceProperty = source[property]
if (typeof sourceProperty === 'object') {
target[property] = objectMerge(target[property], sourceProperty)
} else {
target[property] = sourceProperty
}
})
return target
}
/**
* @param {HTMLElement} element
* @param {string} className
*/
export function toggleClass(element, className) {
if (!element || !className) {
return
}
let classString = element.className
const nameIndex = classString.indexOf(className)
if (nameIndex === -1) {
classString += '' + className
} else {
classString =
classString.substr(0, nameIndex) +
classString.substr(nameIndex + className.length)
}
element.className = classString
}
/**
* @param {string} type
* @returns {Date}
*/
export function getTime(type) {
if (type === 'start') {
return new Date().getTime() - 3600 * 1000 * 24 * 90
} else {
return new Date(new Date().toDateString())
}
}
/**
* @param {Function} func
* @param {number} wait
* @param {boolean} immediate
* @return {*}
*/
export function debounce(func, wait, immediate) {
let timeout, args, context, timestamp, result
const later = function() {
// 据上一次触发时间间隔
const last = +new Date() - timestamp
// 上次被包装函数被调用时间间隔 last 小于设定时间间隔 wait
if (last < wait && last > 0) {
timeout = setTimeout(later, wait - last)
} else {
timeout = null
// 如果设定为immediate===true,因为开始边界已经调用过了此处无需调用
if (!immediate) {
result = func.apply(context, args)
if (!timeout) context = args = null
}
}
}
return function(...args) {
context = this
timestamp = +new Date()
const callNow = immediate && !timeout
// 如果延时不存在,重新设定延时
if (!timeout) timeout = setTimeout(later, wait)
if (callNow) {
result = func.apply(context, args)
context = args = null
}
return result
}
}
/**
* This is just a simple version of deep copy
* Has a lot of edge cases bug
* If you want to use a perfect deep copy, use lodash's _.cloneDeep
* @param {Object} source
* @returns {Object}
*/
export function deepClone(source) {
if (!source && typeof source !== 'object') {
throw new Error('error arguments', 'deepClone')
}
const targetObj = source.constructor === Array ? [] : {}
Object.keys(source).forEach(keys => {
if (source[keys] && typeof source[keys] === 'object') {
targetObj[keys] = deepClone(source[keys])
} else {
targetObj[keys] = source[keys]
}
})
return targetObj
}
/**
* @param {Array} arr
* @returns {Array}
*/
export function uniqueArr(arr) {
return Array.from(new Set(arr))
}
/**
* @returns {string}
*/
export function createUniqueString() {
const timestamp = +new Date() + ''
const randomNum = parseInt((1 + Math.random()) * 65536) + ''
return (+(randomNum + timestamp)).toString(32)
}
/**
* Check if an element has a class
* @param {HTMLElement} elm
* @param {string} cls
* @returns {boolean}
*/
export function hasClass(ele, cls) {
return !!ele.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'))
}
/**
* Add class to element
* @param {HTMLElement} elm
* @param {string} cls
*/
export function addClass(ele, cls) {
if (!hasClass(ele, cls)) ele.className += ' ' + cls
}
/**
* Remove class from element
* @param {HTMLElement} elm
* @param {string} cls
*/
export function removeClass(ele, cls) {
if (hasClass(ele, cls)) {
const reg = new RegExp('(\\s|^)' + cls + '(\\s|$)')
ele.className = ele.className.replace(reg, ' ')
}
}
// 替换邮箱字符
export function regEmail(email) {
if (String(email).indexOf('@') > 0) {
const str = email.split('@')
let _s = ''
if (str[0].length > 3) {
for (var i = 0; i < str[0].length - 3; i++) {
_s += '*'
}
}
var new_email = str[0].substr(0, 3) + _s + '@' + str[1]
}
return new_email
}
// 替换手机字符
export function regMobile(mobile) {
if (mobile.length > 7) {
var new_mobile = mobile.substr(0, 3) + '****' + mobile.substr(7)
}
return new_mobile
}
// 下载文件
export function downloadFile(obj, name, suffix) {
const url = window.URL.createObjectURL(new Blob([obj]))
const link = document.createElement('a')
link.style.display = 'none'
link.href = url
const fileName = parseTime(new Date()) + '-' + name + '.' + suffix
link.setAttribute('download', fileName)
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
}
// new - 导出
export function exportFile(url, fileName) {
const link = document.createElement('a')
link.style.display = 'none'
link.href = url
link.setAttribute('target', '_blank')
link.setAttribute('download', fileName)
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
}
// 获取当前日期时间
export function getCurrentTime() {
const yy = new Date().getFullYear()
const mm = new Date().getMonth() + 1
const dd = new Date().getDate()
const hh = new Date().getHours()
const mf = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes() : new Date().getMinutes()
const ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds() : new Date().getSeconds()
const time = yy + '-' + mm + '-' + dd + ' ' + hh + ':' + mf + ':' + ss
return time
}
// 导出
export function getBlob(url, cb) {
var xhr = new XMLHttpRequest()
xhr.open('GET', url, true)
xhr.responseType = 'blob'
xhr.onload = function() {
if (xhr.status === 200) {
cb(xhr.response)
}
}
xhr.send()
}
export function saveAs(blob, filename) {
if (window.navigator.msSaveOrOpenBlob) {
navigator.msSaveBlob(blob, filename)
} else {
var link = document.createElement('a')
var body = document.querySelector('body')
link.href = window.URL.createObjectURL(blob)
link.download = filename
link.style.display = 'none'
body.appendChild(link)
link.click()
body.removeChild(link)
window.URL.revokeObjectURL(link.href)
}
}
/**
* Created by PanJiaChen on 16/11/18.
*/
/**
* Parse the time to string
* @param {(Object|string|number)} time
* @param {string} cFormat
* @returns {string}
*/
export function parseTime(time, cFormat) {
if (arguments.length === 0) {
return null
}
const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
let date
if (typeof time === 'undefined' || time === null || time === 'null') {
return ''
} else if (typeof time === 'object') {
date = time
} else {
if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) {
time = parseInt(time)
}
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(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
let value = formatObj[key]
// Note: getDay() returns 0 on Sunday
if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value ] }
if (result.length > 0 && value < 10) {
value = '0' + value
}
return value || 0
})
return time_str
}
/**
* @param {number} time
* @param {string} option
* @returns {string}
*/
export function formatTime(time, option) {
if (('' + time).length === 10) {
time = parseInt(time) * 1000
} else {
time = +time
}
const d = new Date(time)
const now = Date.now()
const diff = (now - d) / 1000
if (diff < 30) {
return '刚刚'
} else if (diff < 3600) {
// less 1 hour
return Math.ceil(diff / 60) + '分钟前'
} else if (diff < 3600 * 24) {
return Math.ceil(diff / 3600) + '小时前'
} else if (diff < 3600 * 24 * 2) {
return '1天前'
}
if (option) {
return parseTime(time, option)
} else {
return (
d.getMonth() +
1 +
'月' +
d.getDate() +
'日' +
d.getHours() +
'时' +
d.getMinutes() +
'分'
)
}
}
/**
* @param {string} url
* @returns {Object}
*/
export function getQueryObject(url) {
url = url == null ? window.location.href : url
const search = url.substring(url.lastIndexOf('?') + 1)
const obj = {}
const reg = /([^?&=]+)=([^?&=]*)/g
search.replace(reg, (rs, $1, $2) => {
const name = decodeURIComponent($1)
let val = decodeURIComponent($2)
val = String(val)
obj[name] = val
return rs
})
return obj
}
/**
* @param {string} input value
* @returns {number} output value
*/
export function byteLength(str) {
// returns the byte length of an utf8 string
let s = str.length
for (var i = str.length - 1; i >= 0; i--) {
const code = str.charCodeAt(i)
if (code > 0x7f && code <= 0x7ff) s++
else if (code > 0x7ff && code <= 0xffff) s += 2
if (code >= 0xDC00 && code <= 0xDFFF) i--
}
return s
}
/**
* @param {Array} actual
* @returns {Array}
*/
export function cleanArray(actual) {
const newArray = []
for (let i = 0; i < actual.length; i++) {
if (actual[i]) {
newArray.push(actual[i])
}
}
return newArray
}
/**
* @param {Object} json
* @returns {Array}
*/
export function param(json) {
if (!json) return ''
return cleanArray(
Object.keys(json).map(key => {
if (json[key] === undefined) return ''
return encodeURIComponent(key) + '=' + encodeURIComponent(json[key])
})
).join('&')
}
/**
* @param {string} url
* @returns {Object}
*/
export function param2Obj(url) {
const search = url.split('?')[1]
if (!search) {
return {}
}
return JSON.parse(
'{"' +
decodeURIComponent(search)
.replace(/"/g, '\\"')
.replace(/&/g, '","')
.replace(/=/g, '":"')
.replace(/\+/g, ' ') +
'"}'
)
}
/**
* @param {string} val
* @returns {string}
*/
export function html2Text(val) {
const div = document.createElement('div')
div.innerHTML = val
return div.textContent || div.innerText
}
/**
* Merges two objects, giving the last one precedence
* @param {Object} target
* @param {(Object|Array)} source
* @returns {Object}
*/
export function objectMerge(target, source) {
if (typeof target !== 'object') {
target = {}
}
if (Array.isArray(source)) {
return source.slice()
}
Object.keys(source).forEach(property => {
const sourceProperty = source[property]
if (typeof sourceProperty === 'object') {
target[property] = objectMerge(target[property], sourceProperty)
} else {
target[property] = sourceProperty
}
})
return target
}
/**
* @param {HTMLElement} element
* @param {string} className
*/
export function toggleClass(element, className) {
if (!element || !className) {
return
}
let classString = element.className
const nameIndex = classString.indexOf(className)
if (nameIndex === -1) {
classString += '' + className
} else {
classString =
classString.substr(0, nameIndex) +
classString.substr(nameIndex + className.length)
}
element.className = classString
}
/**
* @param {string} type
* @returns {Date}
*/
export function getTime(type) {
if (type === 'start') {
return new Date().getTime() - 3600 * 1000 * 24 * 90
} else {
return new Date(new Date().toDateString())
}
}
/**
* @param {Function} func
* @param {number} wait
* @param {boolean} immediate
* @return {*}
*/
export function debounce(func, wait, immediate) {
let timeout, args, context, timestamp, result
const later = function() {
// 据上一次触发时间间隔
const last = +new Date() - timestamp
// 上次被包装函数被调用时间间隔 last 小于设定时间间隔 wait
if (last < wait && last > 0) {
timeout = setTimeout(later, wait - last)
} else {
timeout = null
// 如果设定为immediate===true,因为开始边界已经调用过了此处无需调用
if (!immediate) {
result = func.apply(context, args)
if (!timeout) context = args = null
}
}
}
return function(...args) {
context = this
timestamp = +new Date()
const callNow = immediate && !timeout
// 如果延时不存在,重新设定延时
if (!timeout) timeout = setTimeout(later, wait)
if (callNow) {
result = func.apply(context, args)
context = args = null
}
return result
}
}
/**
* This is just a simple version of deep copy
* Has a lot of edge cases bug
* If you want to use a perfect deep copy, use lodash's _.cloneDeep
* @param {Object} source
* @returns {Object}
*/
export function deepClone(source) {
if (!source && typeof source !== 'object') {
throw new Error('error arguments', 'deepClone')
}
const targetObj = source.constructor === Array ? [] : {}
Object.keys(source).forEach(keys => {
if (source[keys] && typeof source[keys] === 'object') {
targetObj[keys] = deepClone(source[keys])
} else {
targetObj[keys] = source[keys]
}
})
return targetObj
}
/**
* @param {Array} arr
* @returns {Array}
*/
export function uniqueArr(arr) {
return Array.from(new Set(arr))
}
/**
* @returns {string}
*/
export function createUniqueString() {
const timestamp = +new Date() + ''
const randomNum = parseInt((1 + Math.random()) * 65536) + ''
return (+(randomNum + timestamp)).toString(32)
}
/**
* Check if an element has a class
* @param {HTMLElement} elm
* @param {string} cls
* @returns {boolean}
*/
export function hasClass(ele, cls) {
return !!ele.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'))
}
/**
* Add class to element
* @param {HTMLElement} elm
* @param {string} cls
*/
export function addClass(ele, cls) {
if (!hasClass(ele, cls)) ele.className += ' ' + cls
}
/**
* Remove class from element
* @param {HTMLElement} elm
* @param {string} cls
*/
export function removeClass(ele, cls) {
if (hasClass(ele, cls)) {
const reg = new RegExp('(\\s|^)' + cls + '(\\s|$)')
ele.className = ele.className.replace(reg, ' ')
}
}
// 替换邮箱字符
export function regEmail(email) {
if (String(email).indexOf('@') > 0) {
const str = email.split('@')
let _s = ''
if (str[0].length > 3) {
for (var i = 0; i < str[0].length - 3; i++) {
_s += '*'
}
}
var new_email = str[0].substr(0, 3) + _s + '@' + str[1]
}
return new_email
}
// 替换手机字符
export function regMobile(mobile) {
if (mobile.length > 7) {
var new_mobile = mobile.substr(0, 3) + '****' + mobile.substr(7)
}
return new_mobile
}
// 下载文件
export function downloadFile(obj, name, suffix) {
const url = window.URL.createObjectURL(new Blob([obj]))
const link = document.createElement('a')
link.style.display = 'none'
link.href = url
const fileName = parseTime(new Date()) + '-' + name + '.' + suffix
link.setAttribute('download', fileName)
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
}
// new - 导出
export function exportFile(url, fileName) {
const link = document.createElement('a')
link.style.display = 'none'
link.href = url
link.setAttribute('target', '_blank')
link.setAttribute('download', fileName)
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
}
// 获取当前日期时间
export function getCurrentTime() {
const yy = new Date().getFullYear()
const mm = new Date().getMonth() + 1
const dd = new Date().getDate()
const hh = new Date().getHours()
const mf = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes() : new Date().getMinutes()
const ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds() : new Date().getSeconds()
const time = yy + '-' + mm + '-' + dd + ' ' + hh + ':' + mf + ':' + ss
return time
}
// 导出
export function getBlob(url, cb) {
var xhr = new XMLHttpRequest()
xhr.open('GET', url, true)
xhr.responseType = 'blob'
xhr.onload = function() {
if (xhr.status === 200) {
cb(xhr.response)
}
}
xhr.send()
}
export function saveAs(blob, filename) {
if (window.navigator.msSaveOrOpenBlob) {
navigator.msSaveBlob(blob, filename)
} else {
var link = document.createElement('a')
var body = document.querySelector('body')
link.href = window.URL.createObjectURL(blob)
link.download = filename
link.style.display = 'none'
body.appendChild(link)
link.click()
body.removeChild(link)
window.URL.revokeObjectURL(link.href)
}
}
export function timeToTimestamp(time) {
const timestamp = Date.parse(new Date(time).toString())
// 在JavaScript中,new Date().getTime()得到的是13位的时间戳;
// 若要获取10位的时间戳需除以1000,获取13位的时间戳不需要除以1000;
// timestamp = timestamp / 1000
return timestamp
}

264
src/views/storeManage/taskManage/index.vue

@ -1,18 +1,14 @@
<template>
<div>
<div class="head-container">
<crudOperation :permission="permission">
<template v-slot:right>
<el-button :loading="crud.downloadLoading" :disabled="!crud.selections.length" size="mini" icon="el-icon-download" style="margin-right: 6px;" @click="downloadApi(crud.selections)">导出</el-button>
</template>
</crudOperation>
<crudOperation :permission="permission" />
<div class="head-search" style="margin-left: 40px;">
<!-- 搜索 -->
<el-select v-model="query.enabled" clearable size="small" placeholder="状态" class="filter-item" style="width: 100px" @change="crud.toQuery">
<el-select v-model="query.status" clearable size="small" placeholder="状态" class="filter-item" style="width: 100px" @change="crud.toQuery">
<i slot="prefix" class="iconfont icon-zhuangtai-fanbai" />
<el-option v-for="item in enabledTypeOptions" :key="item.key" :label="item.display_name" :value="item.key" />
</el-select>
<el-input v-model="query.blurry" size="small" clearable placeholder="输入任务名称搜索" prefix-icon="el-icon-search" style="width: 200px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
<el-input v-model="query.taskName" size="small" clearable placeholder="输入任务名称搜索" prefix-icon="el-icon-search" style="width: 200px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
<rrOperation />
</div>
</div>
@ -22,23 +18,38 @@
<!--表格渲染-->
<el-table ref="table" v-loading="crud.loading" :data="crud.data" style="width: 100%;" height="calc(100vh - 300px)" @row-click="clickRowHandler" @row-dblclick="handleDbClick" @selection-change="crud.selectionChangeHandler">
<el-table-column type="selection" width="55" align="center" />
<el-table-column align="center" prop="username" label="任务名称" />
<el-table-column align="center" prop="username" label="任务类型" />
<el-table-column align="center" prop="username" label="目标设备" />
<el-table-column align="center" prop="username" label="计划" />
<el-table-column prop="createTime" label="下次运行">
<el-table-column prop="taskName" label="任务名称" />
<el-table-column prop="taskType" label="任务类型">
<template slot-scope="scope">
<div>{{ scope.row.createTime | parseTime }}</div>
<div>{{ scope.row.taskType === 1 ? '通风任务' :'' }}</div>
</template>
</el-table-column>
<el-table-column prop="createTime" label="最后运行">
<el-table-column prop="deviceName" label="目标设备" />
<el-table-column prop="timeInterval" label="计划">
<template slot-scope="scope">
<div>{{ scope.row.createTime | parseTime }}</div>
<div v-if="scope.row.timerType===2">每隔{{ scope.row.timeInterval }}</div>
<div v-if="scope.row.timerType===1">每隔{{ scope.row.timeInterval }}小时</div>
<!-- 如果只选了整点或半点那么就是整点或半点每隔1小时运行1次 -->
<!-- 如果是都选中了就是整点和半点每间隔30分钟执行一次 -->
<div v-if="scope.row.timerType===4 && scope.row.timeInterval === '1'">整点</div>
<div v-if="scope.row.timerType===4 && scope.row.timeInterval === '2'">半点</div>
<div v-if="scope.row.timerType===4 && (scope.row.timeInterval && scope.row.timeInterval.split(',').length === 2)">整点/半点</div>
</template>
</el-table-column>
<el-table-column label="状态" prop="enabled">
<el-table-column prop="nextExecute" label="下次运行">
<template slot-scope="scope">
<el-switch v-model="scope.row.enabled" active-color="#409EFF" inactive-color="#F56C6C" @change="changeEnabled(scope.row, scope.row.enabled)" />
<div>{{ scope.row.nextExecute | parseTime }}</div>
</template>
</el-table-column>
<el-table-column prop="lastExecute" label="最后运行">
<template slot-scope="scope">
<div v-if="scope.row.lastExecute">{{ scope.row.lastExecute | parseTime }}</div>
<div v-else> - </div>
</template>
</el-table-column>
<el-table-column label="状态" prop="status">
<template slot-scope="scope">
<el-switch v-model="scope.row.status" active-color="#409EFF" inactive-color="#F56C6C" :active-value="1" :inactive-value="2" @change="changeStatus(scope.row, scope.row.status)" />
</template>
</el-table-column>
</el-table>
@ -56,9 +67,9 @@
</ul>
<el-form ref="form" :inline="true" :model="form" :rules="rules" size="small" label-width="80px">
<div v-show="tabIndex===0">
<el-form-item label="任务类型" prop="type">
<el-form-item label="任务类型" prop="taskType">
<el-select
v-model="form.type"
v-model="form.taskType"
style="width: 240px; height:30px"
clearable
placeholder="请选择"
@ -72,9 +83,9 @@
/>
</el-select>
</el-form-item>
<el-form-item label="目标设备" prop="deviceName">
<el-form-item label="目标设备" prop="deviceId">
<el-select
v-model="form.deviceName"
v-model="form.deviceId"
style="width: 240px; height:30px"
clearable
placeholder="请选择"
@ -87,22 +98,23 @@
/>
</el-select>
</el-form-item>
<el-form-item label="任务名称" prop="name">
<el-input v-model="form.name" style="width: 572px;" />
<el-form-item label="任务名称" prop="taskName">
<el-input v-model="form.taskName" style="width: 572px;" />
</el-form-item>
<el-form-item v-if="form.deviceName === 'DDAF09DDD05ED8ACF9928E'" label="说明" prop="remark">
<el-form-item v-if="form.deviceId === 'DDAF09DDD05ED8ACF9928E'" label="说明" prop="remark">
<div style="display:inline-block; width: 572px; color: #fff; border: 1px solid #339cff; border-radius: 4px; padding: 6px 10px; line-height: 24px;">通风任务是系统给 密集架设备 指定的专属计划任务根据计划设定的时间可开启通风作业作业完成后通风会自动停止同一个密集架设备可以设置多个任务注意每个任务的计划尽量不要有冲突或者重复否则会导致任务执行失败<span style="font-weight: bold; color: rgb(26, 174, 147);">如果用户在创建任务时未手动设置计划系统将默认从创建时间开始每隔1天执行1次该任务</span></div>
<!-- <el-input v-model="form.remark" type="textarea" style="width: 572px;" disabled :rows="4" /> -->
</el-form-item>
</div>
<div v-show="tabIndex===1">
<div>
<el-form-item label="定时类型" prop="timeType">
<el-form-item label="定时类型" prop="timerType">
<el-select
v-model="form.timeType"
v-model="form.timerType"
style="width: 240px; height:30px"
clearable
placeholder="请选择"
@change="handleTimerType"
>
<el-option
v-for="item in timeTypeOptions"
@ -113,34 +125,42 @@
</el-select>
</el-form-item>
</div>
<el-form-item v-if="form.timeType===1 || form.timeType===2" label="间隔" prop="interval">
<el-input-number v-model="form.interval" controls-position="right" :min="1" />
<span v-if="form.timeType===1" class="unit-name">小时</span>
<span v-if="form.timeType===2" class="unit-name"></span>
<el-form-item v-if="form.timerType===1 || form.timerType===2" label="间隔" prop="timeInterval">
<div>
<el-input-number v-model="form.timeInterval" controls-position="right" :min="1" />
<span v-if="form.timerType===1" class="unit-name">小时</span>
<span v-if="form.timerType===2" class="unit-name"></span>
</div>
</el-form-item>
<!-- <el-form-item v-if="form.timeType===3" label="" prop="weekly">
<!-- <el-form-item v-if="form.timerType===3" label="" prop="weekly">
<el-checkbox-group v-model="form.weekly" style="margin-left: 80px;" @change="handleWeeklyTypes">
<el-checkbox v-for="item in weeklyOptions" :key="item.value" :label="item.value">{{ item.label }}</el-checkbox>
</el-checkbox-group>
</el-form-item> -->
<el-form-item v-if="form.timeType===4" label="" prop="halfOrPart">
<el-radio-group v-model="form.halfOrPart" style="margin-left: 80px;">
<el-radio v-for="item in halfOrPartOptions" :key="item.value" :label="item.value">{{ item.label }}</el-radio>
</el-radio-group>
<el-form-item v-if="form.timerType===4" label="" prop="halfOrPart">
<el-checkbox-group v-if="form.timerType===4" v-model="form.halfOrPart" style="margin-left: 80px;">
<el-checkbox v-for="item in halfOrPartOptions" :key="item.value" :label="item.value">{{ item.label }}</el-checkbox>
</el-checkbox-group>
</el-form-item>
<div>
<el-form-item label="开始时间" prop="startTime">
<el-form-item label="开始时间" prop="startTime2">
<el-date-picker
v-model="form.startTime"
v-model="form.startTime2"
type="datetime"
placeholder="选择日期时间"
:disabled="form.nowTime === true"
format="yyyy-MM-dd HH:mm:ss"
value-format="yyyy-MM-dd HH:mm:ss"
:picker-options="{
disabledDate: (time) =>
time.getTime() <
new Date(new Date().setHours(0, 0, 0, 0))
disabledDate: (time) =>{
// if (form.endTime) {
// return time.getTime() > new Date(form.endTime).getTime()
// }else{
// return time.getTime() < new Date(new Date().setHours(0, 0, 0, 0))
// }
// return time.getTime() < new Date(new Date().setHours(0, 0, 0, 0))
return time.getTime() < Date.now() - 8.64e7
}
}"
style="width: 240px; height:30px"
/>
@ -150,9 +170,9 @@
</el-form-item>
</div>
<div>
<el-form-item label="结束时间" prop="endTime">
<el-form-item label="结束时间" prop="endTime2">
<el-date-picker
v-model="form.endTime"
v-model="form.endTime2"
class="task-date"
type="datetime"
placeholder="选择日期时间"
@ -187,26 +207,27 @@ import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import pagination from '@crud/Pagination'
import Detail from './module/detail'
import { parseTime } from '@/utils/index.js'
import { parseTime, timeToTimestamp } from '@/utils/index.js'
import { getAllDev } from '@/api/system/logs'
import qs from 'qs'
import { exportFile } from '@/utils/index'
import { mapGetters } from 'vuex'
const defaultForm = { id: null, type: null, deviceName: null, name: null, timeType: 2, halfOrPart: 1, interval: 1, startTime: parseTime(new Date().getTime()), endTime: null, nowTime: null, longTime: true, remark: null }
const defaultForm = { id: null, taskType: null, deviceId: null, taskName: null, timerType: 2, timeInterval: 1, status: 1, startTime2: parseTime(new Date().getTime()), endTime2: null, nowTime: null, longTime: true, remark: null, halfOrPart: [] }
export default {
name: 'TaskManage',
components: { rrOperation, crudOperation, pagination, Detail },
cruds() {
return CRUD({ title: '任务', url: 'api/roles', crudMethod: crudTask,
return CRUD({ title: '任务', url: 'api/device/initTimedTasks', crudMethod: crudTask,
optShow: {
add: true,
edit: true,
del: true,
download: false,
group: false
}
},
sort: []
})
},
mixins: [presenter(), header(), form(defaultForm), crud()],
@ -216,8 +237,8 @@ export default {
formVisible: false,
formTitle: '新增任务',
enabledTypeOptions: [
{ key: 'true', display_name: '激活' },
{ key: 'false', display_name: '锁定' }
{ key: 1, display_name: '激活' },
{ key: 2, display_name: '锁定' }
],
permission: {
add: ['admin', 'task:add'],
@ -290,29 +311,32 @@ export default {
}
],
rules: {
name: [
taskName: [
{ required: true, message: '请输入', trigger: 'blur' }
],
type: [
taskType: [
{ required: true, message: '请选择', trigger: 'change' }
],
deviceName: [
deviceId: [
{ required: true, message: '请选择', trigger: 'change' }
],
timeType: [
timerType: [
{ required: true, message: '请选择', trigger: 'change' }
],
interval: [
timeInterval: [
{ required: true, message: '请输入', trigger: 'blur' }
],
startTime: [
{ required: true, message: '请选择', trigger: 'change' }
{ required: true, message: '请选择', trigger: 'change' },
{ validator: this.validateDateRange, trigger: 'blur' }
],
endTime: [
{
validator: (rule, value, callback) => {
if (this.isRequired && !value) {
callback(new Error('请选择结束时间'))
} else if (this.form.startTime > value) {
callback(new Error('开始时间不得大于结束时间'))
} else {
callback()
}
@ -323,9 +347,15 @@ export default {
},
endPickerOptions: {
disabledDate: (time) => {
const startTime = this.form.startTime
const startTime = new Date(this.form.startTime).getTime()
// if (startTime) {
// return time.getTime() < new Date(startTime).getTime() - 1 * 24 * 60 * 60 * 1000 || time.getTime() < startTime
// }
if (startTime) {
return time.getTime() < new Date(startTime).getTime()
// return time.getTime() <= new Date(startTime).getTime()
return (time.getTime()) <= startTime - 8.64e7
} else {
return time.getTime() < Date.now() - 8.64e7
}
}
}
@ -346,21 +376,58 @@ export default {
methods: {
//
[CRUD.HOOK.afterToCU](crud, form) {
this.tabIndex = 0
if (form.taskType) {
this.getDev()
}
},
//
[CRUD.HOOK.beforeToAdd]() {
this.form.startTime2 = parseTime(new Date().getTime())
},
//
[CRUD.HOOK.beforeToEdit](crud, form) {
if (form.endTime === null) {
form.longTime = true
}
if (form.timerType === 4 && form.timeInterval) {
form.halfOrPart = form.timeInterval.split(',')
}
if (form.startTime) {
this.form.startTime2 = parseTime(form.startTime)
}
if (form.endTime) {
this.form.endTime2 = parseTime(form.endTime)
}
},
[CRUD.HOOK.beforeValidateCU](crud, form) {
if (this.form.taskType === null || this.form.deviceId === null || this.form.name === null) {
this.$message.error('请制定完善 “ 任务设定 ” ')
}
},
//
[CRUD.HOOK.afterValidateCU](crud) {
console.log(crud.form)
if (crud.form.timeType !== 4) {
this.form.halfOrPart = null
if (this.form.startTime2) {
this.form.startTime = timeToTimestamp(this.form.startTime2)
} else {
this.form.startTime = null
}
if (this.form.endTime2) {
this.form.endTime = timeToTimestamp(this.form.endTime2)
} else {
this.form.endTime = null
}
if (this.form.timerType === 4 && this.form.halfOrPart) {
this.form.timeInterval = this.form.halfOrPart.join(',')
}
delete crud.form.remark
return false
delete crud.form.longTime
delete crud.form.startTime2
delete crud.form.endTime2
delete crud.form.nowTime
delete crud.form.halfOrPart
console.log(crud.form)
return true
},
changeFormTab(index) {
this.tabIndex = index
@ -380,20 +447,33 @@ export default {
},
handleNowTime(val) {
if (val === true) {
this.form.startTime = parseTime(new Date().getTime())
this.form.startTime2 = parseTime(new Date().getTime())
}
},
// validateDateRange() {
// if (this.form.startTime > this.form.endTime) {
// this.$message.warning('')
// return false
// }
// return true
// },
handleTaskType(val) {
this.form.deviceName = null
this.form.deviceId = null
if (val) {
this.getDev()
}
},
handleTimerType(val) {
if (val === 4) {
this.form.timeInterval = null
this.form.halfOrPart = [1]
}
},
//
getDev() {
getAllDev().then(res => {
let arr = []
if (this.form.type === 1) {
if (this.form.taskType === 1) {
arr = res.filter(item => item.deviceTypeId.name === '密集架')
.map(item => ({
value: item.id,
@ -411,7 +491,6 @@ export default {
})
}
this.deviceOptions = arr
console.log('this.deviceOptions', this.deviceOptions)
})
},
clickRowHandler(row) {
@ -422,19 +501,24 @@ export default {
this.$refs.detailRefs.detailVisible = true
},
//
changeEnabled(data, val) {
this.$confirm('此操作将 "' + this.dict.label.user_status[val] + '" ' + data.username + ', 是否继续?', '提示', {
changeStatus(data, val) {
this.$confirm('此操作将改变任务状态,是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
// crudRoles.edit(data).then(res => {
// this.crud.notify(this.dict.label.user_status[val] + '', CRUD.NOTIFICATION_TYPE.SUCCESS)
const params = {
'id': data.id,
'status': val
}
console.log('params', params)
// crudTask.FetchStatus(params).then(res => {
// this.crud.notify('', CRUD.NOTIFICATION_TYPE.SUCCESS)
// }).catch(() => {
// data.enabled = !data.enabled
// data.status = !data.status
// })
}).catch(() => {
data.enabled = !data.enabled
// data.status = !data.status
})
},
//
@ -443,7 +527,9 @@ export default {
const params = {
'logIds': ids
}
exportFile(this.baseApi + '/api/case/exportCaseLogList?' + qs.stringify(params, { indices: false }))
console.log(params)
// /case/exportCaseLogList
exportFile(this.baseApi + '/api?' + qs.stringify(params, { indices: false }))
}
}
}
@ -458,26 +544,32 @@ export default {
.head-search{
margin-bottom:0 ;
}
::v-deep .form-dialog.el-dialog{
width: 712px !important;
.el-dialog__body{
padding: 0 0 30px 0;
.archives-tab{
margin-bottom: 20px;
}
.el-form{
padding: 0 20px;
.el-checkbox__label{
color: #fff !important;
.form-dialog{
::v-deep .el-dialog{
width: 712px !important;
.el-dialog__body{
padding: 0 0 30px 0;
.archives-tab{
margin-bottom: 20px;
}
.unit-name{
color: #fff;
margin-left: 15px;
.el-form{
padding: 0 20px;
.el-checkbox__label{
color: #fff !important;
}
.unit-name{
color: #fff;
margin-left: 15px;
}
}
}
.el-dialog__header .el-dialog__close::before{
position: absolute;
right: -60px;
bottom: -10px;
}
}
}
</style>
<style>
.el-picker-panel__footer .el-button,

24
src/views/storeManage/taskManage/module/detail.vue

@ -1,6 +1,6 @@
<template>
<div>
<el-dialog title="xxx通风任务1-日志" :visible.sync="detailVisible" append-to-body>
<el-dialog class="detail-dialog" title="xxx通风任务1-日志" :visible.sync="detailVisible" append-to-body>
<span class="dialog-right-top" />
<span class="dialog-left-bottom" />
<div class="setting-dialog">
@ -58,15 +58,17 @@ export default {
</script>
<style lang="scss" scoped>
::v-deep .el-dialog__body{
padding: 20px 0 60px 0;
}
::v-deep .el-dialog{
width: 800px;
}
::v-deep .el-dialog .el-dialog__header .el-dialog__close::before{
position: absolute;
right: -90px;
bottom: -10px;
.detail-dialog{
::v-deep .el-dialog{
width: 800px !important;
.el-dialog__body{
padding: 20px 0 60px 0;
}
.el-dialog__header .el-dialog__close::before{
position: absolute;
right: -90px;
bottom: -10px;
}
}
}
</style>
Loading…
Cancel
Save