This commit is contained in:
gtz217 2022-08-02 18:05:16 +08:00
parent b0a5be471b
commit d61171ee58
5 changed files with 149 additions and 11 deletions

View File

@ -2,7 +2,7 @@
* @Author: gtz * @Author: gtz
* @Date: 2022-07-25 14:18:00 * @Date: 2022-07-25 14:18:00
* @LastEditors: gtz * @LastEditors: gtz
* @LastEditTime: 2022-07-29 13:31:29 * @LastEditTime: 2022-08-02 13:55:00
* @Description: file content * @Description: file content
* @FilePath: \hf-pda\src\api\eqInspection.js * @FilePath: \hf-pda\src\api\eqInspection.js
*/ */
@ -17,6 +17,24 @@ export const list = data => {
}) })
} }
// 获取巡检记录列表
export const add = data => {
return request({
url: '/api/equipment/inspectionLog/add',
method: 'POST',
data
})
}
// 获取巡检记录列表
export const update = data => {
return request({
url: '/api/equipment/inspectionLog/update',
method: 'POST',
data
})
}
// 获取巡检记录详情 // 获取巡检记录详情
export const detail = data => { export const detail = data => {
return request({ return request({

View File

@ -1,3 +1,11 @@
/*
* @Author: gtz
* @Date: 2022-08-02 08:42:08
* @LastEditors: gtz
* @LastEditTime: 2022-08-02 14:54:43
* @Description: file content
* @FilePath: \hf-pda\src\api\file.js
*/
import request from '@/util/request' import request from '@/util/request'
// 文件上传 // 文件上传
@ -8,4 +16,15 @@ export const uploadFile = data => {
file: true, file: true,
data data
}) })
} }
// 文件下载
export const downloadFile = params => {
return request({
url: '/api/common/attachment/downloadFile',
method: 'GET',
formState: true,
params,
responseType: 'blob'
})
}

View File

@ -2,7 +2,7 @@
* @Author: gtz * @Author: gtz
* @Date: 2022-07-28 10:22:30 * @Date: 2022-07-28 10:22:30
* @LastEditors: gtz * @LastEditors: gtz
* @LastEditTime: 2022-07-29 17:06:04 * @LastEditTime: 2022-08-02 15:15:11
* @Description: file content * @Description: file content
* @FilePath: \hf-pda\src\pages\eqInspection\eqInspection-edit.vue * @FilePath: \hf-pda\src\pages\eqInspection\eqInspection-edit.vue
--> -->
@ -61,6 +61,7 @@
clear-trigger="always" clear-trigger="always"
disabled disabled
placeholder="选择巡检时间" placeholder="选择巡检时间"
@click="handleDate"
/> />
</van-col> </van-col>
</van-row> </van-row>
@ -119,15 +120,32 @@
:after-read="upload" :after-read="upload"
/> />
</van-col> </van-col>
<van-col :span="22" :offset="1">
<van-button type="info" round size="large" @click="handleSubmit">
提交
</van-button>
</van-col>
</van-row> </van-row>
</div> </div>
</div> </div>
<van-popup v-model="show" position="bottom">
<van-datetime-picker
v-model="currentDate"
type="datetime"
:title="dateType ? '选择结束时间' : '选择开始时间'"
:min-date="minDate"
@confirm="setDate"
@cancel="show = false"
/>
</van-popup>
</div> </div>
</template> </template>
<script> <script>
import { detail, eqList, getInsList, updateInsStatus } from '@/api/eqInspection' import moment from 'moment'
import { uploadFile } from '@/api/file' import { detail, eqList, getInsList, updateInsStatus, add, update } from '@/api/eqInspection'
import { uploadFile, downloadFile } from '@/api/file'
import { blobToBase64 } from '@/util/utils'
import shortLine from '@/components/shortLine.vue' import shortLine from '@/components/shortLine.vue'
import { Toast } from 'vant' import { Toast } from 'vant'
@ -150,7 +168,11 @@ export default {
insList: [], insList: [],
insTime: null, insTime: null,
fileList: [], fileList: [],
eqId: null eqId: null,
show: false,
currentDate: null,
minDate: new Date(2020, 0, 1),
dateType: 0
} }
}, },
mounted () { mounted () {
@ -191,20 +213,39 @@ export default {
}) })
if (result1.success) { if (result1.success) {
this.insList = result1.data.map(item => { this.insList = result1.data.map(item => {
item.statusBoolean = item.status === '1' ? true : false if (item.status === '1') {
item.statusBoolean = true
} else {
item.statusBoolean = false
}
return item return item
}) })
} }
if (result.data.annexUrl) {
const result2 = await downloadFile({
type: 'file',
attachmentId: result.data.annexUrl
})
blobToBase64(result2.data.data, (v) => {
const file = new File([result2.data.data], result2.data.headers['content-disposition'].slice(result2.data.headers['content-disposition'].indexOf('filename=') + 9), { type: '*' })
this.fileList.push({
content: v,
file
})
})
}
} }
}, },
// //
async upload (file) { async upload (file) {
console.log(this.fileList)
const data = new FormData() const data = new FormData()
data.append('files', file.file) data.append('files', file.file)
data.append('typeCode', 'file') data.append('typeCode', 'file')
setTimeout(async () => { const result = await uploadFile(data)
const result = await uploadFile(data) if (result.success) {
}, 1000) this.dataForm.annexUrl = result.data[0].id
}
}, },
// //
async updateStatus (item) { async updateStatus (item) {
@ -220,6 +261,45 @@ export default {
} else { } else {
item.statusBoolean = !item.statusBoolean item.statusBoolean = !item.statusBoolean
} }
},
//
setDate (v) {
if (this.dateType) {
if (v.valueOf() - new Date(this.dataForm.inspectionStartTime).valueOf()) {
this.dataForm.inspectionEndTime = moment(v).format('YYYY-MM-DDTHH:mm:ss')
this.show = false
this.insTime = moment(this.dataForm.inspectionStartTime).format('YYYY-MM-DD HH:mm:ss') + '-' + moment(v).format('YYYY-MM-DD HH:mm:ss')
this.dateType = 0
} else {
this.$notify('结束时间必须大于开始时间!')
}
} else {
this.dataForm.inspectionStartTime = moment(v).format('YYYY-MM-DDTHH:mm:ss')
this.dateType = 1
}
},
//
handleDate () {
this.show = true
},
//
async handleSubmit () {
let result = {}
if (this.$route.query.id) {
result = await update(this.dataForm)
} else {
result = await add(this.dataForm)
}
if (result.success) {
Toast.success({
message: '操作成功',
onClose: () => {
this.$router.push({
name: 'eqInspection'
})
}
})
}
} }
} }
} }

View File

@ -2,7 +2,7 @@
* @Author: gtz * @Author: gtz
* @Date: 2022-07-25 14:18:00 * @Date: 2022-07-25 14:18:00
* @LastEditors: gtz * @LastEditors: gtz
* @LastEditTime: 2022-07-29 13:18:34 * @LastEditTime: 2022-08-02 15:08:29
* @Description: file content * @Description: file content
* @FilePath: \hf-pda\src\util\request.js * @FilePath: \hf-pda\src\util\request.js
*/ */
@ -58,6 +58,11 @@ service.interceptors.response.use(
data: response.data.data, data: response.data.data,
pagetotal: response.data.pagetotal pagetotal: response.data.pagetotal
} }
} else if (response.config.responseType === 'blob') {
return {
success: true,
data: response
}
} else { } else {
Notify(response.data.msg) Notify(response.data.msg)
return { return {

16
src/util/utils.js Normal file
View File

@ -0,0 +1,16 @@
/*
* @Author: gtz
* @Date: 2022-08-02 15:00:02
* @LastEditors: gtz
* @LastEditTime: 2022-08-02 15:03:00
* @Description: file content
* @FilePath: \hf-pda\src\util\utils.js
*/
export const blobToBase64 = (blob, callback) => {
var reader = new FileReader()
reader.onload = function (e) {
callback(e.target.result)
}
reader.readAsDataURL(blob)
}