安全违章接口调试完成

This commit is contained in:
BianLzhaoMin 2025-04-07 11:27:47 +08:00
parent 67c26f9f77
commit 5395425ba5
10 changed files with 438 additions and 145 deletions

34
src/hooks/useCommon.js Normal file
View File

@ -0,0 +1,34 @@
import { ref } from 'vue'
import { getProjectApi, getMajorApi } from '@/services/common'
import { useCommonStore } from '@/stores/index'
const commonStore = useCommonStore()
export default function getProjectAndMajorData() {
// 定义公共 hooks 把项目数据和专业数据 return出去
const projectList = ref([])
const majorList = ref([])
// 先从store里面判断之前是否已经存过 如果没有存则发起请求获取数据并存入store里面 当存过之后 其他页面使用时则无需再重复发起请求获取
async function getData() {
// 项目数据
if (!commonStore.projectList || commonStore.projectList.length < 1) {
const { data: result } = await getProjectApi({})
commonStore.setProjectList(result)
projectList.value = result
} else {
projectList.value = commonStore.projectList
}
// 专业数据
if (!commonStore.majorList || commonStore.majorList.length < 1) {
const { data: res } = await getMajorApi()
commonStore.setMajorList(res)
majorList.value = res
} else {
majorList.value = commonStore.majorList
}
}
return { getData, projectList, majorList }
}

View File

@ -47,7 +47,7 @@
</up-input> </up-input>
</up-form-item> </up-form-item>
<TitleTipModal :TitleTip="`违章信息`" /> <TitleTipModal :TitleTip="`检查信息`" />
<up-form-item prop="examiner" label="检查人"> <up-form-item prop="examiner" label="检查人">
<up-input <up-input
border="none" border="none"

View File

@ -105,7 +105,6 @@
:label="props.addAndEditFormType == 3 ? '违章照片' : '违章照片(最多9张)'" :label="props.addAndEditFormType == 3 ? '违章照片' : '违章照片(最多9张)'"
> >
<up-upload <up-upload
name="1"
multiple multiple
@delete="onDeletePicVrImgList" @delete="onDeletePicVrImgList"
@afterRead="onAfterReadVrImgList" @afterRead="onAfterReadVrImgList"
@ -149,17 +148,21 @@
:label="props.addAndEditFormType == 3 ? '整改照片' : '整改照片(最多9张)'" :label="props.addAndEditFormType == 3 ? '整改照片' : '整改照片(最多9张)'"
> >
<up-upload <up-upload
name="1"
multiple multiple
@delete="onDeleteCorrectionImgList" @delete="onDeleteCorrectionImgList"
@afterRead="onAfterReadCorrectionImgList" @afterRead="onAfterReadCorrectionImgList"
:deletable="!props.addAndEditFormType == 3"
:fileList="addAndEditModel.correctionImgList" :fileList="addAndEditModel.correctionImgList"
:maxCount="props.addAndEditFormType == 3 ? 1 : 9" :maxCount="props.addAndEditFormType == 3 ? 1 : 9"
/> />
</up-form-item> </up-form-item>
<up-button type="primary" text="提交" @tap="onSubmitForm" style="width: 100%" /> <up-button
text="提交"
type="primary"
@tap="onSubmitForm"
style="width: 100%"
v-if="addAndEditFormType != 3"
/>
</up-form> </up-form>
<!-- 项目选择弹框 --> <!-- 项目选择弹框 -->
@ -233,10 +236,15 @@
</template> </template>
<script setup> <script setup>
import { reactive, ref } from 'vue' import { reactive, ref, watch } from 'vue'
import { debounce, set } from 'lodash-es' // import { debounce } from 'lodash-es' //
import { getProjectApi, getMajorApi, getProcedureApi } from '@/services/common.js' import { getProjectApi, getMajorApi, getProcedureApi } from '@/services/common.js'
import { addSafetyViolationsApi } from '@/services/safetyViolations.js' import {
addSafetyViolationsApi,
editSafetyViolationsApi,
getSafetyViolationsDetailsByIdApi,
} from '@/services/safetyViolations.js'
import getProjectAndMajorData from '@/hooks/useCommon.js'
import TitleTipModal from '@/components/TitleTipModal/index' import TitleTipModal from '@/components/TitleTipModal/index'
const addAndEditModelRef = ref(null) const addAndEditModelRef = ref(null)
@ -248,16 +256,26 @@ const onSearchProjectName = ref('') // 项目搜索条件
const dateValue = ref(Date.now()) // const dateValue = ref(Date.now()) //
const sendLoading = ref(false) // const sendLoading = ref(false) //
const dateType = ref(1) const dateType = ref(1)
// const { projectList, majorList, getData } = getProjectAndMajorData()
// onMounted(async () => {
// await getData()
// })
const props = defineProps({ const props = defineProps({
// 1. 2. 3. // 1. 2. 3.
addAndEditFormType: { addAndEditFormType: {
type: [Number, String], type: [Number, String],
default: () => 1, default: () => 1,
}, },
// id
detailsId: {
type: [Number, String],
default: () => '',
},
}) })
console.log(props.addAndEditFormType, '表单类型') //
const deleteFileList = []
// //
const addAndEditModel = reactive({ const addAndEditModel = reactive({
dataSource: 2, dataSource: 2,
@ -275,17 +293,7 @@ const addAndEditModel = reactive({
rectUserName: '', // rectUserName: '', //
rectTime: '', // rectTime: '', //
rectDesc: '', // rectDesc: '', //
// procedure: '',
// major: '',
// examiner: '',
// inspectTime: '',
// correctionTerm: '',
// vrLocation: '',
// vrDescribe: '',
vrImgList: [], // vrImgList: [], //
// correctionPerson: '',
// correctionDescribe: '',
// correctionTime: '',
correctionImgList: [], // correctionImgList: [], //
}) })
@ -509,6 +517,7 @@ const formatDate = (timestamp) => {
// //
const onAfterReadVrImgList = (event) => { const onAfterReadVrImgList = (event) => {
console.log('event', event)
let lists = [].concat(event.file) let lists = [].concat(event.file)
lists.map((item) => { lists.map((item) => {
addAndEditModel.vrImgList.push({ addAndEditModel.vrImgList.push({
@ -519,6 +528,10 @@ const onAfterReadVrImgList = (event) => {
// //
const onDeletePicVrImgList = (event) => { const onDeletePicVrImgList = (event) => {
addAndEditModel.vrImgList.splice(event.index, 1) addAndEditModel.vrImgList.splice(event.index, 1)
if (props.addAndEditFormType == 2 && addAndEditModel.vrImgList[event.index]?.id) {
deleteFileList.push(addAndEditModel.vrImgList[event.index]?.id)
}
} }
// //
@ -533,93 +546,131 @@ const onAfterReadCorrectionImgList = (event) => {
// //
const onDeleteCorrectionImgList = (event) => { const onDeleteCorrectionImgList = (event) => {
addAndEditModel.correctionImgList.splice(event.index, 1) addAndEditModel.correctionImgList.splice(event.index, 1)
if (props.addAndEditFormType == 2 && addAndEditModel.correctionImgList[event.index]?.id) {
deleteFileList.push(addAndEditModel.correctionImgList[event.index]?.id)
}
} }
// //
const onSubmitForm = debounce(() => { const onSubmitForm = debounce(() => {
console.log(
'%c🔍 表单提交入参 %c',
'background: linear-gradient(90deg, #FF6B6B, #4ECDC4); color: white; padding: 5px 10px; border-radius: 5px; font-weight: bold;',
'',
addAndEditModel,
)
addAndEditModelRef.value addAndEditModelRef.value
.validate() .validate()
.then(async (valid) => { .then(async (valid) => {
if (valid) { if (valid) {
// //
sendLoading.value = true sendLoading.value = true
let successVrImgList = [] const uploadImages = new Promise(async (resolve, reject) => {
let successCorrectionImgList = [] try {
if (addAndEditModel.vrImgList.length > 0) { let successVrImgList = []
successVrImgList = await uploadImgFun(addAndEditModel.vrImgList, 1) let successCorrectionImgList = []
}
if (addAndEditModel.correctionImgList.length > 0) {
successCorrectionImgList = await uploadImgFun(
addAndEditModel.correctionImgList,
2,
)
}
// let successVrImgListNoEdit = []
const { let successCorrectionImgListNoEdit = []
dataSource,
proId, // id
proName, //
majorId, // id
majorName, //
gxId, // id
gxName, //
checkUserName, //
vioDate, //
vioPlace, //
vioDesc, //
rectDate, //
rectUserName, //
rectTime, //
rectDesc, //
} = addAndEditModel
const addParams = { if (addAndEditModel.vrImgList.length > 0) {
dataSource, successVrImgListNoEdit = addAndEditModel.vrImgList.map((e) => !e.isEdit)
proId, // id successVrImgList = await uploadImgFun(successVrImgListNoEdit, 1)
proName, // }
majorId, // id if (addAndEditModel.correctionImgList.length > 0) {
majorName, // successCorrectionImgListNoEdit = addAndEditModel.correctionImgList.map(
gxId, // id (e) => !e.isEdit,
gxName, // )
checkUserName, // successCorrectionImgList = await uploadImgFun(
vioDate, // successCorrectionImgListNoEdit,
vioPlace, // 2,
vioDesc, // )
rectDate, // }
rectUserName, //
rectTime, //
rectDesc, //
fileList: [...successVrImgList, ...successCorrectionImgList],
uploadType: 1,
}
const res = await addSafetyViolationsApi(addParams) resolve({ successVrImgList, successCorrectionImgList }) //
console.log( } catch (error) {
'%c🔍 表单提交出参 %c', reject(error) //
'background: linear-gradient(90deg, #FF6B6B, #4ECDC4); color: white; padding: 5px 10px; border-radius: 5px; font-weight: bold;', }
'', })
res,
)
sendLoading.value = false uploadImages
if (res.code === 200) { .then(async ({ successVrImgList, successCorrectionImgList }) => {
uni.$u.toast('新增成功') console.log('图片上传成功,开始提交表单...')
setTimeout(() => { //
uni.navigateBack({ //
delta: 1, const {
}) dataSource,
}, 500) proId, // id
} else { proName, //
uni.$u.toast('新增失败' + res.data) majorId, // id
} majorName, //
gxId, // id
gxName, //
checkUserName, //
vioDate, //
vioPlace, //
vioDesc, //
rectDate, //
rectUserName, //
rectTime, //
rectDesc, //
} = addAndEditModel
const addParams = {
dataSource,
proId, // id
proName, //
majorId, // id
majorName, //
gxId, // id
gxName, //
checkUserName, //
vioDate, //
vioPlace, //
vioDesc, //
rectDate, //
rectUserName, //
rectTime, //
rectDesc, //
fileList: [...successVrImgList, ...successCorrectionImgList],
uploadType: 1,
}
const SED_API =
props.addAndEditFormType == 1
? addSafetyViolationsApi
: editSafetyViolationsApi
if (props.addAndEditFormType == 2) {
Object.assign(addParams, {
id: props.detailsId,
delFileList: deleteFileList,
})
}
console.log(
'%c🔍 表单提交入参 %c',
'background: linear-gradient(90deg, #FF6B6B, #4ECDC4); color: white; padding: 5px 10px; border-radius: 5px; font-weight: bold;',
'',
addParams,
)
const res = await SED_API(addParams)
console.log(
'%c🔍 表单提交出参 %c',
'background: linear-gradient(90deg, #FF6B6B, #4ECDC4); color: white; padding: 5px 10px; border-radius: 5px; font-weight: bold;',
'',
res,
)
sendLoading.value = false
if (res.code === 200) {
uni.$u.toast(res.data)
setTimeout(() => {
uni.navigateBack({
delta: 1,
})
}, 500)
} else {
uni.$u.toast(res.data)
}
})
.catch((error) => {
console.error('图片上传失败:', error)
})
} }
}) })
.catch((error) => {}) .catch((error) => {})
@ -674,16 +725,88 @@ const uploadImgFun = async (list, type) => {
} }
// //
const getFormDetail = () => { const getFormDetail = async () => {
console.log('---获取详情数据') const res = await getSafetyViolationsDetailsByIdApi({ id: props?.detailsId })
}
// props.addAndEditFormType 2 if (res.code === 200) {
if (props.addAndEditFormType == 2) { const {
// dataSource,
getFormDetail() proId, // id
proName, //
majorId, // id
majorName, //
gxId, // id
gxName, //
checkUserName, //
vioDate, //
vioPlace, //
vioDesc, //
rectDate, //
rectUserName, //
rectTime, //
rectDesc, //
rectPhotoList,
vioPhotoList,
} = res.data
let rectPhotoListEdit = []
let vioPhotoListEdit = []
if (rectPhotoList.length > 0) {
rectPhotoListEdit = rectPhotoList.map((e) => {
return {
idEdit: true,
url: e.url,
}
})
}
if (vioPhotoList.length > 0) {
vioPhotoListEdit = vioPhotoList.map((e) => {
return {
idEdit: true,
url: e.url,
}
})
}
Object.assign(addAndEditModel, {
proId, // id
proName, //
majorId, // id
majorName, //
gxId, // id
gxName, //
checkUserName, //
vioDate, //
vioPlace, //
vioDesc, //
rectDate, //
rectUserName, //
rectTime, //
rectDesc, //
vrImgList: vioPhotoList,
correctionImgList: rectPhotoList,
})
getProcedureData(majorId)
}
} }
// //
watch(
() => props.addAndEditFormType,
(newValue) => {
console.log('newValue当前表单的类型', newValue)
if (newValue != 1) {
getFormDetail()
}
},
{
deep: true,
immediate: true,
},
)
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">

View File

@ -8,7 +8,7 @@
/> />
<view class="container"> <view class="container">
<AddAndEditForm :addAndEditFormType="addAndEditFormType" /> <AddAndEditForm :addAndEditFormType="addAndEditFormType" :detailsId="detailsId" />
</view> </view>
</view> </view>
</template> </template>
@ -22,12 +22,16 @@ import { onLoad } from '@dcloudio/uni-app'
const { safeAreaInsets } = uni.getSystemInfoSync() const { safeAreaInsets } = uni.getSystemInfoSync()
const addAndEditFormType = ref(1) const addAndEditFormType = ref(1)
const detailsId = ref('')
const uploadRecordUrl = ref('/pages/safetyViolations/upload-record/index') const uploadRecordUrl = ref('/pages/safetyViolations/upload-record/index')
onLoad((query) => { onLoad((query) => {
if (query.type) { if (query.type) {
addAndEditFormType.value = query.type addAndEditFormType.value = query.type
} }
if (query.id) {
detailsId.value = query.id
}
}) })
</script> </script>

View File

@ -8,8 +8,8 @@
<up-input <up-input
clearable clearable
placeholder="输入搜索关键词" placeholder="输入搜索关键词"
v-model.trim="onSearchKeyword"
suffixIconStyle="color: #909399" suffixIconStyle="color: #909399"
v-model.trim="queryParams.keyWord"
> >
<template #suffix> <template #suffix>
<up-icon name="search" size="24" @tap="onSearchRecord" /> <up-icon name="search" size="24" @tap="onSearchRecord" />
@ -19,58 +19,47 @@
</view> </view>
<view class="upload-record-list"> <view class="upload-record-list">
<up-list <up-list ref="upListRef" style="width: 100%" @scrolltolower="onScrollTolower">
ref="upListRef" <up-list-item v-for="item in safetyViolationsList" :key="item.id">
style="width: 100%"
@scroll="onScrollUpList"
@scrolltolower="onScrollTolower"
>
<up-list-item v-for="item in 10" :key="item">
<view class="record-item"> <view class="record-item">
<view @tap="onHandleViewDetails"> <view @tap="onHandleViewDetails">
<!-- 日期 --> <!-- 日期 -->
<view class="item-date"> <view class="item-date">
<text>2024-05-06</text> <text>{{ item.vioDate }}</text>
<view> <view>
<up-button <up-button
size="mini" size="mini"
text="修改" text="修改"
type="primary" type="primary"
@tap="onHandleEditRecord" @tap="onHandleEditRecord(item.id)"
/> />
</view> </view>
</view> </view>
<!-- 名称 --> <!-- 名称 -->
<view class="item-name"> <view class="item-name">
<text>N3917</text> <text>{{ item.proName }}</text>
</view> </view>
<!-- 文字内容 --> <!-- 文字内容 -->
<view class="text-content"> <view class="text-content">
<up-text <up-text :lines="2" :text="item.vioDesc" />
:lines="2"
text="关于uview-plus的取名来由首字母u来自于uni-app首字母
uni-app是基VuejsVue和View(延伸为UI视图之意)同音同时view组件uni-app中
最础最重要的组件故取名uview-plus表达源于uni-app和Vue之意同时在此也对它示感谢"
/>
</view> </view>
</view> </view>
<!-- 图片内容 --> <!-- 图片内容 -->
<view class="swiper-container"> <view class="swiper-container">
<up-swiper <up-swiper
:list="list1" :list="item.vioPhotoList"
:indicator="true"
interval="5000" interval="5000"
@click="onClickSwiper" @click="onClickSwiper"
/> />
<view class="swiper-count"> 3 </view> <view class="swiper-count">{{ item.vioPhotoNum }} </view>
</view> </view>
<!-- 检查人 --> <!-- 检查人 -->
<view class="inspect-person"> <view class="inspect-person">
<view> 检查人武松 </view> <view> 检查人{{ item.checkUserName }} </view>
<view> 整改日期2025-05-06 </view> <view> 整改日期{{ item.rectTime }} </view>
</view> </view>
</view> </view>
</up-list-item> </up-list-item>
@ -79,8 +68,6 @@ uni-app是基VuejsVue和View(延伸为UI、视图之意)同音同时view
<view class="loading-text"> <view class="loading-text">
{{ finish ? '没有更多数据了~' : '正在加载...' }} {{ finish ? '没有更多数据了~' : '正在加载...' }}
</view> </view>
<!-- <up-back-top :scroll-top="scrollTop" icon="arrow-up" @tap="onHandleBackTop" /> -->
</view> </view>
</view> </view>
</view> </view>
@ -88,40 +75,91 @@ uni-app是基VuejsVue和View(延伸为UI、视图之意)同音同时view
<script setup> <script setup>
import NavBarModal from '@/components/NavBarModal/index' import NavBarModal from '@/components/NavBarModal/index'
import { ref, reactive } from 'vue' import { ref, computed } from 'vue'
import { debounce } from 'lodash-es' // import { debounce } from 'lodash-es' //
import { getSafetyViolationsListApi } from '@/services/safetyViolations.js'
const { safeAreaInsets } = uni.getSystemInfoSync() const { safeAreaInsets } = uni.getSystemInfoSync()
const onSearchKeyword = ref('')
const finish = ref(false)
const upListRef = ref(null) // const upListRef = ref(null) //
const total = ref(0)
const safetyViolationsList = ref([])
const scrollTop = ref(0) //
const queryParams = ref({
page: 1,
limit: 10,
keyWord: '',
})
const onScrollUpList = (e) => { //
scrollTop.value = e const getSafetyViolationsListData = async (isTap = false) => {
try {
console.log(
'%c🔍 获取安全违章上传记录入参 %c',
'background: linear-gradient(90deg, #FF6B6B, #4ECDC4); color: white; padding: 5px 10px; border-radius: 5px; font-weight: bold;',
'',
queryParams.value,
)
const res = await getSafetyViolationsListApi(queryParams.value)
console.log(
'%c🔍 获取安全违章上传记录出参 %c',
'background: linear-gradient(90deg, #FF6B6B, #4ECDC4); color: white; padding: 5px 10px; border-radius: 5px; font-weight: bold;',
'',
res,
)
//
total.value = res.count
//
if (isTap) {
//
safetyViolationsList.value = res?.data || []
//
queryParams.value.page = 1
} else {
//
if (res.data && res.data.length > 0) {
safetyViolationsList.value = [...safetyViolationsList.value, ...res.data]
}
}
safetyViolationsList.value.forEach((e) => {
e.vioPhotoList = e.vioPhoto?.split(',')
})
} catch (error) {
//
if (isTap) {
safetyViolationsList.value = []
}
}
} }
getSafetyViolationsListData()
const list1 = reactive([
'https://img1.baidu.com/it/u=1361177696,203903602&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=1455',
'https://img1.baidu.com/it/u=1361177696,203903602&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=1455',
'https://img1.baidu.com/it/u=1361177696,203903602&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=1455',
])
// //
const onScrollTolower = debounce(() => { const onScrollTolower = debounce(() => {
console.log('onScrollTolower') console.log('onScrollTolower', '滚动触底')
//
if (safetyViolationsList.value.length < total.value) {
queryParams.value.page++
getSafetyViolationsListData(false)
}
}, 500) }, 500)
//
const finish = computed(() => {
if (total.value === safetyViolationsList.value.length) return true
})
// //
const onSearchRecord = () => { const onSearchRecord = () => {
console.log('onSearchRecord', onSearchKeyword.value) console.log('onSearchRecord', queryParams.value.keyWord)
getSafetyViolationsListData(true)
} }
// //
const onHandleEditRecord = () => { const onHandleEditRecord = (id) => {
console.log('onHandleEditRecord') console.log('onHandleEditRecord')
uni.redirectTo({ uni.redirectTo({
url: `/pages/safetyViolations/index?type=2&id=1`, // url: `/pages/safetyViolations/index?type=2&id=${id}`, //
}) })
} }

View File

@ -0,0 +1,40 @@
import { http } from '@/utils/http'
// 质量检查表单提交接口
export const addQualityInspectionApi = (data) => {
return http({
method: 'POST',
url: '/imgTool/imgUpload/qualityInspection/insertQualityInspection',
data,
header: {
'Content-Type': 'application/x-www-form-urlencoded',
},
})
}
// 质量检查数据列表
export const getQualityInspectionListApi = (data) => {
return http({
method: 'GET',
url: '/imgTool/imgUpload/qualityInspection/getList',
data,
})
}
// 质量检查表单获取详情
export const getQualityInspectionDetailsByIdApi = (data) => {
return http({
method: 'GET',
url: '/imgTool/imgUpload/qualityInspection/getQualityInspectionById',
data,
})
}
// 质量检查表单修改
export const editQualityInspectionApi = (data) => {
return http({
method: 'POST',
url: '/imgTool/imgUpload/qualityInspection/updateQualityInspectionById',
data,
header: {
'Content-Type': 'application/x-www-form-urlencoded',
},
})
}

View File

@ -11,3 +11,30 @@ export const addSafetyViolationsApi = (data) => {
}, },
}) })
} }
// 安全违章数据列表
export const getSafetyViolationsListApi = (data) => {
return http({
method: 'GET',
url: '/imgTool/imgUpload/safetyViolation/getList',
data,
})
}
// 安全违章表单获取详情
export const getSafetyViolationsDetailsByIdApi = (data) => {
return http({
method: 'GET',
url: '/imgTool/imgUpload/safetyViolation/getSafetyViolationById',
data,
})
}
// 安全违章表单修改
export const editSafetyViolationsApi = (data) => {
return http({
method: 'POST',
url: '/imgTool/imgUpload/safetyViolation/updateSafetyViolationById',
data,
header: {
'Content-Type': 'application/x-www-form-urlencoded',
},
})
}

View File

@ -11,3 +11,4 @@ export default pinia
// 模块统一导出 // 模块统一导出
export * from './modules/member' export * from './modules/member'
export * from './modules/common'

View File

@ -0,0 +1,26 @@
import { defineStore } from 'pinia'
import { ref } from 'vue'
export const useCommonStore = defineStore('common', () => {
// 项目数据
const projectList = ref([])
// 专业数据
const majorList = ref([])
// 存储项目数据
const setProjectList = (val) => {
projectList.value = val
}
// 存储专业数据
const setMajorList = (val) => {
majorList.value = val
}
// 把数据和方法 return 出去
return {
projectList,
majorList,
setProjectList,
setMajorList,
}
})

View File

@ -102,7 +102,7 @@ export const http = (options) => {
// 3. 其他错误 // 3. 其他错误
uni.showToast({ uni.showToast({
icon: 'none', icon: 'none',
title: '请求错误', title: '请求失败,请切换网络后尝试',
}) })
reject(res) reject(res)
} }
@ -111,7 +111,7 @@ export const http = (options) => {
fail(err) { fail(err) {
uni.showToast({ uni.showToast({
icon: 'none', icon: 'none',
title: '请求失败', title: '请求失败,请切换网络后尝试',
}) })
console.log(err, '请求失败') console.log(err, '请求失败')
reject(err) reject(err)