|
const Mock = require('mockjs')
const data = Mock.mock({
'data|100': [{
deviceId: /SB\d{5}/,
'deviceTypeId|1': [0, 1, 2],
'deviceType': function () {
if (this.deviceTypeId === 0) {
return '人脸终端'
} else if (this.deviceTypeId === 1) {
return '摄像头'
} else {
return '门禁'
}
},
'deviceName': function () {
return parseInt(Math.random() * 10) + 1 + '#' + this.deviceType
},
// 'location|1': ['@integer(1,3)#风场SVG室', '@integer(1,3)#风场大门']
imgUrl: function () {
if (this.deviceTypeId === 0) {
return "http://www.pt528.net/d/file/p/2019/04-03/6a1d8d84f188af227d9a8ffd3a748d8c.jpg"
} else if (this.deviceTypeId === 1) {
return "https://dss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=2579741018,2239188063&fm=26&gp=0.jpg"
} else {
return "http://www.pt528.net/d/file/p/2019/04-07/5847a0f1de97045f31753bfc5d33a6b8.jpg"
}
}
}]
})
module.exports = [
{
url: '/system/querySchedules',
method: 'get',
type: 'func',
response: req => {
return Mock.mock({
'data|8': [{
'scheduleId|+1': 1, // 班次表编号
title: '班次时间@scheduleId', // 班次表名称
'shifts|2-4': [{
'shiftId|+1': 0,
label: function () {
return `班组${this.shiftId}`
},
startTime: '00:00', // 开始时间
endTime: '08:00' // 结束时间
}]
}]
}).data
}
},
{
url: '/system/deleteSchedule',
method: 'delete',
type: 'func',
response: req => {
return { code: 0, msg: '删除成功' }
}
},
{
url: '/system/createSchedule',
method: 'post',
type: 'func',
response: req => {
return Mock.mock({ code: 0, msg: '新增成功', scheduleId: '@increment' })
}
},
{
url: '/system/editSchedule',
method: 'put',
type: 'func',
response: req => {
return { code: 0, msg: '修改成功' }
}
},
{
url: '/system/getDepAttendanceRules',
method: 'get',
type: 'func',
response: req => {
return Mock.mock({
scheduleId: '@integer(1,8)',
minLateMinus: '@integer(10,60)', // 计算为迟到的最小分钟数(签到可延迟分钟数)
maxLateMinus: '@integer(10,60)', // 计算为迟到的最大分钟数(超过计算为旷工)
minEarlyLeftMinus: '@integer(10,20)', // 计算为早退的最小分钟数(签退可提前分钟数)
maxEarlyLeftMinus: '@integer(10,20)', // 计算为早退的最大分钟数(超过计算为旷工)
maxLateTimes: '@integer(1,5)', // 最大迟到次数
maxEarlyLeftTimes: '@integer(1,5)', // 最大早退次数
maxAbsenceTimes: '@integer(1,5)', // 最大旷工次数
attendanceMonth: 'natural', // 考勤月【 natural / custom 】
monthStart: { // 自定义考勤月起始日
type: -1, // 类型【上月/当月/下月】
day: 25 // 日序号
},
monthEnd: { // 自定义考勤月结束日
type: 0,
day: 24
}
})
}
}, {
url: '/system/putAttendanceRule',
method: 'put',
type: 'func',
response: req => {
return { code: 0, msg: '修改成功' }
}
},
{
url: '/system/getDeviceData',
method: 'get',
type: 'func',
response: req => {
const url = decodeURIComponent(req.url)
const res = parseQueryString(url)
const page = parseInt(res.page)
const limit = parseInt(res.limit)
const start = (page - 1) * limit
const end = start + limit
const deviceTypeId = parseInt(res.deviceTypeId)
const deviceId = res.deviceId
const deviceName = res.deviceName
const deviceType = ['人脸终端', '摄像头', '门禁']
let result = data.data
if (res.deviceTypeId) {
result = result.filter(item => item.deviceType === deviceType[deviceTypeId])
}
if (res.deviceId) {
result = result.filter(item => item.deviceId.indexOf(deviceId) !== -1)
}
if (res.deviceName) {
result = result.filter(item => item.deviceName.indexOf(deviceName) !== -1)
}
return {
success: true,
page,
size: limit,
total: result.length,
data: { data: result.slice(start, end) }
}
}
},
{
url: '/system/getDeviceTypes',
method: 'get',
type: 'func',
response: req => {
return Mock.mock({
success: true,
'data|3': [{
'id|+1': 0,
'name|+1': ['人脸终端', '摄像头', '门禁']
}]
})
}
},
{
url: '/system/deleteDeviceData',
method: 'delete',
type: 'func',
response: req => {
const res = parseQueryString(req.url)
let deviceId = res.deviceId.split(',')
for (let i = 0; i < deviceId.length; i++) {
data.data.some((item, index) => {
if (item.deviceId === deviceId[i]) {
data.data.splice(index, 1)
}
})
}
return {
success: true,
msg: '删除成功!'
}
}
},
{
url: '/system/getDeviceInfo',
method: 'get',
type: 'func',
response: req => {
const res = parseQueryString(req.url)
const id = res.deviceId
const result = data.data.filter(item => item.deviceId === id)
if (result[0].deviceType === '人脸终端') {
result[0].deviceTypeId = 0
} else if (result[0].deviceType === '摄像头') {
result[0].deviceTypeId = 1
} else {
result[0].deviceTypeId = 2
}
return {
success: true,
data: result[0]
}
}
},
{
url: '/system/addDeviceData',
method: 'post',
type: 'func',
response: req => {
const res = req.body
const name = ['人脸终端', '摄像头', '门禁']
const id = parseInt(res.deviceTypeId)
const deviceName = res.deviceName
let imgUrl
if (name[id] === '人脸终端') {
imgUrl = "http://www.pt528.net/d/file/p/2019/04-03/6a1d8d84f188af227d9a8ffd3a748d8c.jpg"
} else if (name[id] === '摄像头') {
imgUrl = "https://dss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=2579741018,2239188063&fm=26&gp=0.jpg"
} else {
imgUrl = "http://www.pt528.net/d/file/p/2019/04-07/5847a0f1de97045f31753bfc5d33a6b8.jpg"
}
const result = Mock.mock({
deviceId: /SB\d{5}/,
deviceName,
deviceType: name[id],
imgUrl
})
data.data.unshift(result)
return {
success: true,
data: result
}
}
},
{
url: '/system/editDeviceData',
method: 'put',
type: 'func',
response: req => {
const res = req.body
const deviceId = res.deviceId
const name = ['人脸终端', '摄像头', '门禁']
const id = parseInt(res.deviceTypeId)
const deviceName = res.deviceName
const imgUrl = res.imgUrl
data.data.some(item => {
if (item.deviceId === deviceId) {
item.deviceName = deviceName
item.deviceType = name[id]
item.deviceTypeId = id
item.imgUrl = imgUrl
}
})
return {
success: true,
msg: '修改成功!'
}
}
}
]
function parseQueryString (url) { // 获取当前浏览器的URL
let arr = [] // 存储参数的数组
let res = {} // 存储最终JSON结果对象
if (url.split('?')[1]) {
arr = url.split('?')[1].split('&') // 获取浏览器地址栏中的参数
for (let i = 0; i < arr.length; i++) { // 遍历参数
if (arr[i].indexOf('=') != -1) { // 如果参数中有值
let str = arr[i].split('=')
res[str[0]] = str[1]
} else { // 如果参数中无值
res[arr[i]] = ''
}
}
return res
} else {
return
}
}
|