Explorar el Código

feat:新增设备管理mock数据,修改假勤管理部分逻辑

luoxu5 %!s(int64=4) %!d(string=hace) años
padre
commit
bf512f67c3

+ 77 - 16
security-protection-platform/.aid/mock/system.js

@ -2,10 +2,29 @@ const Mock = require('mockjs')
2 2
const data = Mock.mock({
3 3
  'data|100': [{
4 4
    deviceId: /SB\d{5}/,
5
    'deviceName|1': ['@integer(1,10)#人脸终端', '@integer(1,10)#摄像头', '@integer(1,10)#门禁'],
6
    'deviceType|': ['人脸终端', '摄像头', '门禁'],
5
    'deviceTypeId|1': [0, 1, 2],
6
    'deviceType': function () {
7
      if (this.deviceTypeId === 0) {
8
        return '人脸终端'
9
      } else if (this.deviceTypeId === 1) {
10
        return '摄像头'
11
      } else {
12
        return '门禁'
13
      }
14
    },
15
    'deviceName': function () {
16
      return parseInt(Math.random() * 10) + 1 + '#' + this.deviceType
17
    },
7 18
    // 'location|1': ['@integer(1,3)#风场SVG室', '@integer(1,3)#风场大门']
8
    imgUrl: ''
19
    imgUrl: function () {
20
      if (this.deviceTypeId === 0) {
21
        return "http://www.pt528.net/d/file/p/2019/04-03/6a1d8d84f188af227d9a8ffd3a748d8c.jpg"
22
      } else if (this.deviceTypeId === 1) {
23
        return "https://dss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=2579741018,2239188063&fm=26&gp=0.jpg"
24
      } else {
25
        return "http://www.pt528.net/d/file/p/2019/04-07/5847a0f1de97045f31753bfc5d33a6b8.jpg"
26
      }
27
    }
9 28
  }]
10 29
})
11 30
@ -103,16 +122,7 @@ module.exports = [
103 122
      const deviceId = res.deviceId
104 123
      const deviceName = res.deviceName
105 124
      const deviceType = ['人脸终端', '摄像头', '门禁']
106
      let result = data.data.filter(item => item.deviceType = item.deviceName.split('#')[1])
107
      result.forEach(item => {
108
        if (item.deviceType === '人脸终端') {
109
          item.imgUrl = "http://www.pt528.net/d/file/p/2019/04-03/6a1d8d84f188af227d9a8ffd3a748d8c.jpg"
110
        } else if (item.deviceType === '摄像头') {
111
          item.imgUrl = "https://dss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=2579741018,2239188063&fm=26&gp=0.jpg"
112
        } else {
113
          item.imgUrl = "http://www.pt528.net/d/file/p/2019/04-07/5847a0f1de97045f31753bfc5d33a6b8.jpg"
114
        }
115
      })
125
      let result = data.data
116 126
      if (res.deviceTypeId) {
117 127
        result = result.filter(item => item.deviceType === deviceType[deviceTypeId])
118 128
      }
@ -173,6 +183,13 @@ module.exports = [
173 183
      const res = parseQueryString(req.url)
174 184
      const id = res.deviceId
175 185
      const result = data.data.filter(item => item.deviceId === id)
186
      if (result[0].deviceType === '人脸终端') {
187
        result[0].deviceTypeId = 0
188
      } else if (result[0].deviceType === '摄像头') {
189
        result[0].deviceTypeId = 1
190
      } else {
191
        result[0].deviceTypeId = 2
192
      }
176 193
      return {
177 194
        success: true,
178 195
        data: result[0]
@ -180,13 +197,57 @@ module.exports = [
180 197
    }
181 198
  },
182 199
  {
183
    url: '/system/getDeviceTypeList',
184
    method: 'get',
200
    url: '/system/addDeviceData',
201
    method: 'post',
202
    type: 'func',
203
    response: req => {
204
      const res = req.body
205
      const name = ['人脸终端', '摄像头', '门禁']
206
      const id = parseInt(res.deviceTypeId)
207
      const deviceName = res.deviceName
208
      let imgUrl
209
      if (name[id] === '人脸终端') {
210
        imgUrl = "http://www.pt528.net/d/file/p/2019/04-03/6a1d8d84f188af227d9a8ffd3a748d8c.jpg"
211
      } else if (name[id] === '摄像头') {
212
        imgUrl = "https://dss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=2579741018,2239188063&fm=26&gp=0.jpg"
213
      } else {
214
        imgUrl = "http://www.pt528.net/d/file/p/2019/04-07/5847a0f1de97045f31753bfc5d33a6b8.jpg"
215
      }
216
      const result = Mock.mock({
217
        deviceId: /SB\d{5}/,
218
        deviceName,
219
        deviceType: name[id],
220
        imgUrl
221
      })
222
      data.data.unshift(result)
223
      return {
224
        success: true,
225
        data: result
226
      }
227
    }
228
  },
229
  {
230
    url: '/system/editDeviceData',
231
    method: 'put',
185 232
    type: 'func',
186 233
    response: req => {
234
      const res = req.body
235
      const deviceId = res.deviceId
236
      const name = ['人脸终端', '摄像头', '门禁']
237
      const id = parseInt(res.deviceTypeId)
238
      const deviceName = res.deviceName
239
      const imgUrl = res.imgUrl
240
      data.data.some(item => {
241
        if (item.deviceId === deviceId) {
242
          item.deviceName = deviceName
243
          item.deviceType = name[id]
244
          item.deviceTypeId = id
245
          item.imgUrl = imgUrl
246
        }
247
      })
187 248
      return {
188 249
        success: true,
189
        data: [{ id: 0, name: '人脸终端' }, { id: 1, name: '摄像头' }, { id: 2, name: '门禁' }]
250
        msg: '修改成功!'
190 251
      }
191 252
    }
192 253
  }

+ 11 - 5
security-protection-platform/src/api/system/index.js

@ -53,20 +53,26 @@ const api = {
53 53
    })
54 54
  },
55 55
  getDeviceData (data) {
56
    return $http.get('/system/getDeviceData', data)
56
    return $http.get('/system/getDeviceData', data).catch((err) => { return err })
57 57
  },
58 58
  getDeviceTypes () {
59
    return $http.get('/system/getDeviceTypes')
59
    return $http.get('/system/getDeviceTypes').catch((err) => { return err })
60 60
  },
61 61
  deleteDeviceData (data) {
62 62
    if (Array.isArray(data.deviceId)) {
63
      return $http.delete(`/system/deleteDeviceData?deviceId=${data.deviceId.join(',')}`)
63
      return $http.delete(`/system/deleteDeviceData?deviceId=${data.deviceId.join(',')}`).catch((err) => { return err })
64 64
    } else {
65
      return $http.delete(`/system/deleteDeviceData?deviceId=${data.deviceId}`)
65
      return $http.delete(`/system/deleteDeviceData?deviceId=${data.deviceId}`).catch((err) => { return err })
66 66
    }
67 67
  },
68 68
  getDeviceInfo (id) {
69
    return $http.get(`/system/getDeviceInfo?deviceId=${id}`)
69
    return $http.get(`/system/getDeviceInfo?deviceId=${id}`).catch((err) => { return err })
70
  },
71
  addDeviceData (data) {
72
    return $http.post('/system/addDeviceData', data).catch((err) => { return err })
73
  },
74
  editDeviceData (data) {
75
    return $http.put('/system/editDeviceData', data).catch((err) => { return err })
70 76
  }
71 77
}
72 78

+ 121 - 14
security-protection-platform/src/modules/system/devicemana/components/modal/addDeviceModal.vue

@ -2,7 +2,7 @@
2 2
  <!-- 请假对话框 -->
3 3
  <t-modal :visibled.sync="visibled" :mask-closable="false" width="600px" height="500px">
4 4
    <template slot="header">
5
      <div class="leave-modal-title">设备新增</div>
5
      <div class="device-modal-title">{{ isEdit?'设备编辑':'设备新增' }}</div>
6 6
    </template>
7 7
    <template slot="close">
8 8
      <i @click="resetModalData">
@ -11,17 +11,28 @@
11 11
    </template>
12 12
    <t-form ref="addDeviceModalForm" :model="addDeviceModalForm" :rules="addDeviceModalFormRules" :label-span="2" label-position="right">
13 13
      <t-form-item label="设备名称:" prop="deviceName">
14
        <t-input v-model="addDeviceModalForm.deviceName" :maxlength="100" :rows="3" count placeholder="请输入请假事由"></t-input>
14
        <t-input v-model="addDeviceModalForm.deviceName" :maxlength="100" :rows="3" count placeholder="请输入设备名称"></t-input>
15 15
      </t-form-item>
16 16
      <t-form-item label="设备类型:" prop="deviceTypeId">
17
        <t-select v-model="addDeviceModalForm.deviceTypeId" placeholder="请选择请假类型">
17
        <t-select v-model="addDeviceModalForm.deviceTypeId" placeholder="请选择设备类型">
18 18
          <t-option v-for="item in types" :value="item.id" :key="item.id">{{ item.name }}</t-option>
19 19
        </t-select>
20 20
      </t-form-item>
21
      <t-form-item label="图片上传:">
22
        <div style="display:flex;flex-direction:row">
23
          <t-upload ref="uploader" :format="['jpg','jpeg','png']" :show-uploaded="false" :before-upload="$_onUploadBeforeUpload" :action="action" multiple type="drag" style="width:180px;height:180px" @success="$_onUploadSuccess" @remove-file="$_onUploadRemoveFile" @error="$_onUploadError" @file-ext-error="$_onUploadFormatError" @file-exceeded-size="$_onUploadExceededSize">
24
            <div style="width: 180px;height:180px;line-height: 180px">
25
              <t-icon icon="plus-outline" size="40"></t-icon>
26
            </div>
27
          </t-upload>
28
          <img v-show="addDeviceModalForm.imgUrl?true:false" :src="addDeviceModalForm.imgUrl" style="margin-left:20px;width: 180px;height:180px;">
29
        </div>
30
      </t-form-item>
21 31
    </t-form>
22 32
    <template slot="footer">
23 33
      <t-button @click="resetModalData">取消</t-button>
24
      <t-button :loading="loadingSubmit" color="primary" @click="submitModalData">提交</t-button>
34
      <t-button v-if="isEdit" :loading="loadingSubmit" color="primary" @click="submitModalData">修改</t-button>
35
      <t-button v-else :loading="loadingSubmit" color="primary" @click="submitModalData">提交</t-button>
25 36
    </template>
26 37
  </t-modal>
27 38
</template>
@ -39,6 +50,11 @@ export default {
39 50
    types: {
40 51
      type: Array,
41 52
      default: () => []
53
    },
54
    // 当前编辑的设备
55
    currentEditDevice: {
56
      type: Object,
57
      default: () => { }
42 58
    }
43 59
  },
44 60
  data () {
@ -46,22 +62,26 @@ export default {
46 62
      // 新增设备对话框表单
47 63
      addDeviceModalForm: {
48 64
        deviceName: '', // 设备名称
49
        deviceTypeId: '' // 设备类型id
65
        deviceTypeId: '', // 设备类型id
66
        imgUrl: ''
50 67
      },
51 68
      // 请假对话框表单验证规则
52 69
      addDeviceModalFormRules: {
53 70
        deviceName: [
54
          { required: true, message: '请假类型不能为空', trigger: blur }
71
          { required: true, message: '设备名称不能为空', trigger: 'blur' }
55 72
        ],
56 73
        deviceTypeId: [
57
          { required: true, message: '开始时间不能为空' }
74
          { required: true, message: '设备类型不能为空' }
58 75
        ]
59 76
      },
60 77
      // 提交表单是否显示loading
61
      loadingSubmit: false
78
      loadingSubmit: false,
79
      action: '',
80
      uploadList: () => []
62 81
    }
63 82
  },
64 83
  computed: {
84
    // 显示/隐藏对话框
65 85
    visibled: {
66 86
      set (val) {
67 87
        this.$emit('update:add-device-modal', val)
@ -69,12 +89,29 @@ export default {
69 89
      get () {
70 90
        return this.addDeviceModal
71 91
      }
92
    },
93
    // 是否为编辑状态
94
    isEdit: {
95
      get () {
96
        return this.addDeviceModalForm.deviceId != null
97
      }
98
    }
99
  },
100
  watch: {
101
    // 当前编辑设备
102
    currentEditDevice (val) {
103
      this.addDeviceModalForm = val
72 104
    }
73 105
  },
106
  mounted () {
107
    this.uploadList = this.$refs.uploader.files
108
  },
74 109
  methods: {
75 110
    // 重置表单数据
76 111
    resetModalData () {
77 112
      this.$refs.addDeviceModalForm.resetFields()
113
      this.addDeviceModalForm.deviceId = null
114
      this.addDeviceModalForm.imgUrl = ''
78 115
      this.visibled = false
79 116
    },
80 117
    // 提交表单数据
@ -82,7 +119,11 @@ export default {
82 119
      this.loadingSubmit = true
83 120
      this.$refs['addDeviceModalForm'].validate((valid) => {
84 121
        if (valid) {
85
          this.addLeaveData()
122
          if (this.isEdit) {
123
            this.editDeviceData()
124
          } else {
125
            this.addDeviceData()
126
          }
86 127
          this.$emit('refresh-data')
87 128
        } else {
88 129
          console.log('error--------->请输入完整的表单信息!')
@ -90,9 +131,9 @@ export default {
90 131
        }
91 132
      })
92 133
    },
93
    // 向服务器发送请求 添加请假数据
94
    async addLeaveData () {
95
      const res = await sysapi.addWorkOrderData({ ...this.leaveModalForm, duration: this.duration })
134
    // 向服务器发送请求 添加设备数据
135
    async addDeviceData () {
136
      const res = await sysapi.addDeviceData(this.addDeviceModalForm)
96 137
      if (res.status === 200) {
97 138
        this.resetModalData()
98 139
        // 如果数据有误
@ -105,10 +146,76 @@ export default {
105 146
        this.$Message.danger('提交失败!')
106 147
      }
107 148
      this.loadingSubmit = false
149
    },
150
    // 向服务器发送请求 添加设备数据
151
    async editDeviceData () {
152
      const res = await sysapi.editDeviceData(this.addDeviceModalForm)
153
      if (res.status === 200) {
154
        this.resetModalData()
155
        // 如果数据有误
156
        if (res.data.fail) {
157
          this.$Message.warning(res.data.fail)
158
        } else {
159
          this.$Message.success('修改成功!')
160
        }
161
      } else {
162
        this.$Message.danger('修改失败!')
163
      }
164
      this.loadingSubmit = false
165
    },
166
    $_onDeleteIconClick (file) {
167
      this.$refs.uploader.removeFile(file)
168
    },
169
    $_onUploadRemoveFlie (file, fileList) {
170
      this.uploadList = fileList
171
    },
172
    $_onUploadPreviewFlie (file) {
173
      console.log(file)
174
    },
175
    $_onUploadProgress (e, file) {
176
      console.log(e)
177
      console.log(file)
178
    },
179
    $_onUploadSuccess (res, file) {
180
      // 因为演示用的上传服务器返回数据格式的原因,这里模拟添加 url
181
      console.log(file)
182
      this.uploadList.push(file)
183
    },
184
    $_onUploadRemoveFile () { },
185
    $_onUploadExceededSize () { },
186
    $_onUploadError (errMsg, response, file) {
187
      console.log(errMsg.message)
188
      this.$Notice.warning({
189
        title: `文件${file.name}上传失败`,
190
        desc:
191
          '原因:' + errMsg
192
      })
193
    },
194
    $_onUploadFileExtError (file, files) {
195
      this.$Notice.warning({
196
        title: '文件格式不正确',
197
        desc:
198
          '文件 ' + file.name + ' 格式不正确,请上传 jpg 或 png 格式的图片。'
199
      })
200
      console.log(files)
201
    },
202
    $_onUploadFileExceededSize (file) {
203
      this.$Notice.warning({
204
        title: '超出文件大小限制',
205
        desc: '文件 ' + file.name + ' 太大,不能超过 2M。'
206
      })
207
    },
208
    $_onUploadFormatError () { },
209
    $_onUploadBeforeUpload () {
210
      const check = this.uploadList.length < 5
211
      if (!check) {
212
        this.$Notice.warning({
213
          title: '最多只能上传 5 张图片。'
214
        })
215
      }
216
      return check
108 217
    }
109 218
  }
110 219
}
111 220
</script>
112 221
113
<style>
114
</style>

+ 14 - 6
security-protection-platform/src/modules/system/devicemana/index.vue

@ -33,7 +33,7 @@
33 33
          <t-table-column label="操作">
34 34
            <template v-slot="{row}">
35 35
              <a href="javascript:;" style="color:#0089D4;" @click="getDeviceInfo(row.deviceId)">详情</a>
36
              <a href="javascript:;" style="color:#0089D4;">编辑</a>
36
              <a href="javascript:;" style="color:#0089D4;" @click="editDeviceData(row.deviceId)">编辑</a>
37 37
              <a href="javascript:;" style="color:#0089D4;" @click="deleteDeviceData(row)">删除</a>
38 38
            </template>
39 39
          </t-table-column>
@ -50,7 +50,7 @@
50 50
    </template> -->
51 51
    <!-- 新增设备对话框 -->
52 52
    <template>
53
      <add-device-modal :types="deviceTypeList" :add-device-modal.sync="addDeviceModal" @refresh-data="getDeviceData()">
53
      <add-device-modal :types="deviceTypesList" :add-device-modal.sync="addDeviceModal" :current-edit-device="currentEditDevice" @refresh-data="getDeviceData()">
54 54
      </add-device-modal>
55 55
    </template>
56 56
    <!-- 设备详情对话框 -->
@ -97,8 +97,7 @@ export default {
97 97
      currentDeviceData: {},
98 98
      // 显示/隐藏新增设备对话框
99 99
      addDeviceModal: false,
100
      // 设备类型列表
101
      deviceTypeList: []
100
      currentEditDevice: {}
102 101
    }
103 102
  },
104 103
  created () {
@ -197,7 +196,7 @@ export default {
197 196
      })
198 197
    },
199 198
    // 获取设备详情数据
200
    async getDeviceInfo(id) {
199
    async getDeviceInfo (id) {
201 200
      const res = await sysapi.getDeviceInfo(id)
202 201
      if (res.status === 200) {
203 202
        this.currentDeviceData = res.data.data
@ -206,7 +205,16 @@ export default {
206 205
      }
207 206
    },
208 207
    // 显示新增设备对话框
209
    showAddDeviceModal() {
208
    showAddDeviceModal () {
209
      this.addDeviceModal = true
210
    },
211
    async editDeviceData (id) {
212
      const res = await sysapi.getDeviceInfo(id)
213
      if (res.status === 200) {
214
        this.currentEditDevice = res.data.data
215
      } else {
216
        this.$Message.danger('设备数据获取失败!')
217
      }
210 218
      this.addDeviceModal = true
211 219
    }
212 220
  }

+ 2 - 2
security-protection-platform/src/modules/workorder/components/modal/approvalmodal.vue

@ -20,8 +20,8 @@
20 20
    <t-form ref="approvalModalForm" :model="approvalModalForm" :rules="approvalModalFormRules" :label-span="2" label-position="right">
21 21
      <t-form-item label="审批结果:" prop="result">
22 22
        <t-radio-group v-model="approvalModalForm.result">
23
          <t-radio label="0">同意</t-radio>
24
          <t-radio label="1">拒绝</t-radio>
23
          <t-radio label="1">同意</t-radio>
24
          <t-radio label="0">拒绝</t-radio>
25 25
        </t-radio-group>
26 26
      </t-form-item>
27 27
      <t-form-item label="审批意见:" prop="comments">

+ 2 - 1
security-protection-platform/src/modules/workorder/components/modal/fieldservicemodal.vue

@ -155,7 +155,7 @@ export default {
155 155
      if (startDate && endDate) {
156 156
        const start = +new Date(startDate)
157 157
        const end = +new Date(endDate)
158
        return (end - start) / (24 * 60 * 60 * 1000)
158
        return (end - start) / (24 * 60 * 60 * 1000) + 1
159 159
      } else {
160 160
        return 0
161 161
      }
@ -163,6 +163,7 @@ export default {
163 163
    // 计算结束时间
164 164
    calEndTime (startDate, duration) {
165 165
      if (startDate && duration) {
166
        duration = duration - 1
166 167
        const endDate = formatDateTime(new Date(+new Date(startDate) + (duration * 24 * 60 * 60 * 1000)))
167 168
        return endDate
168 169
      } else {

+ 2 - 1
security-protection-platform/src/modules/workorder/components/modal/leavemodal.vue

@ -153,7 +153,7 @@ export default {
153 153
      if (startDate && endDate) {
154 154
        const start = +new Date(startDate)
155 155
        const end = +new Date(endDate)
156
        return (end - start) / (24 * 60 * 60 * 1000)
156
        return (end - start) / (24 * 60 * 60 * 1000) + 1
157 157
      } else {
158 158
        return 0
159 159
      }
@ -161,6 +161,7 @@ export default {
161 161
    // 计算结束时间
162 162
    calEndTime (startDate, duration) {
163 163
      if (startDate && duration) {
164
        duration = duration - 1
164 165
        const endDate = formatDateTime(new Date(+new Date(startDate) + (duration * 24 * 60 * 60 * 1000)))
165 166
        return endDate
166 167
      } else {

+ 2 - 1
security-protection-platform/src/modules/workorder/components/modal/overtimemodal.vue

@ -142,7 +142,7 @@ export default {
142 142
      if (startDate && endDate) {
143 143
        const start = +new Date(startDate)
144 144
        const end = +new Date(endDate)
145
        return (end - start) / (24 * 60 * 60 * 1000)
145
        return (end - start) / (24 * 60 * 60 * 1000) + 1
146 146
      } else {
147 147
        return 0
148 148
      }
@ -150,6 +150,7 @@ export default {
150 150
    // 计算结束时间
151 151
    calEndTime (startDate, duration) {
152 152
      if (startDate && duration) {
153
        duration = duration - 1
153 154
        const endDate = formatDateTime(new Date(+new Date(startDate) + (duration * 24 * 60 * 60 * 1000)))
154 155
        return endDate
155 156
      } else {

+ 1 - 1
security-protection-platform/src/modules/workorder/components/modal/workorderinfomodal.vue

@ -15,7 +15,7 @@
15 15
    </div>
16 16
    <div v-if="status" class="approval-info row">
17 17
      <div class="col-6">审批人:<span>{{ data.approver }}</span></div>
18
      <div class="col-6">审批结果:<span>{{ data.result===0?'同意':'驳回' }}</span></div>
18
      <div class="col-6">审批结果:<span>{{ data.result==='0'?'失败':'成功' }}</span></div>
19 19
      <div class="col-12">审批时间:<span>{{ data.approveTime }}</span></div>
20 20
      <div class="col-12">审批意见:<span>{{ data.comments }}</span></div>
21 21
    </div>