安全违章接口调试完成

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-form-item>
<TitleTipModal :TitleTip="`违章信息`" />
<TitleTipModal :TitleTip="`检查信息`" />
<up-form-item prop="examiner" label="检查人">
<up-input
border="none"

View File

@ -105,7 +105,6 @@
:label="props.addAndEditFormType == 3 ? '违章照片' : '违章照片(最多9张)'"
>
<up-upload
name="1"
multiple
@delete="onDeletePicVrImgList"
@afterRead="onAfterReadVrImgList"
@ -149,17 +148,21 @@
:label="props.addAndEditFormType == 3 ? '整改照片' : '整改照片(最多9张)'"
>
<up-upload
name="1"
multiple
@delete="onDeleteCorrectionImgList"
@afterRead="onAfterReadCorrectionImgList"
:deletable="!props.addAndEditFormType == 3"
:fileList="addAndEditModel.correctionImgList"
:maxCount="props.addAndEditFormType == 3 ? 1 : 9"
/>
</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>
<!-- 项目选择弹框 -->
@ -233,10 +236,15 @@
</template>
<script setup>
import { reactive, ref } from 'vue'
import { debounce, set } from 'lodash-es' //
import { reactive, ref, watch } from 'vue'
import { debounce } from 'lodash-es' //
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'
const addAndEditModelRef = ref(null)
@ -248,16 +256,26 @@ const onSearchProjectName = ref('') // 项目搜索条件
const dateValue = ref(Date.now()) //
const sendLoading = ref(false) //
const dateType = ref(1)
// const { projectList, majorList, getData } = getProjectAndMajorData()
// onMounted(async () => {
// await getData()
// })
const props = defineProps({
// 1. 2. 3.
addAndEditFormType: {
type: [Number, String],
default: () => 1,
},
// id
detailsId: {
type: [Number, String],
default: () => '',
},
})
console.log(props.addAndEditFormType, '表单类型')
//
const deleteFileList = []
//
const addAndEditModel = reactive({
dataSource: 2,
@ -275,17 +293,7 @@ const addAndEditModel = reactive({
rectUserName: '', //
rectTime: '', //
rectDesc: '', //
// procedure: '',
// major: '',
// examiner: '',
// inspectTime: '',
// correctionTerm: '',
// vrLocation: '',
// vrDescribe: '',
vrImgList: [], //
// correctionPerson: '',
// correctionDescribe: '',
// correctionTime: '',
correctionImgList: [], //
})
@ -509,6 +517,7 @@ const formatDate = (timestamp) => {
//
const onAfterReadVrImgList = (event) => {
console.log('event', event)
let lists = [].concat(event.file)
lists.map((item) => {
addAndEditModel.vrImgList.push({
@ -519,6 +528,10 @@ const onAfterReadVrImgList = (event) => {
//
const onDeletePicVrImgList = (event) => {
addAndEditModel.vrImgList.splice(event.index, 1)
if (props.addAndEditFormType == 2 && addAndEditModel.vrImgList[event.index]?.id) {
deleteFileList.push(addAndEditModel.vrImgList[event.index]?.id)
}
}
//
@ -533,35 +546,51 @@ const onAfterReadCorrectionImgList = (event) => {
//
const onDeleteCorrectionImgList = (event) => {
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(() => {
console.log(
'%c🔍 表单提交入参 %c',
'background: linear-gradient(90deg, #FF6B6B, #4ECDC4); color: white; padding: 5px 10px; border-radius: 5px; font-weight: bold;',
'',
addAndEditModel,
)
addAndEditModelRef.value
.validate()
.then(async (valid) => {
if (valid) {
//
sendLoading.value = true
const uploadImages = new Promise(async (resolve, reject) => {
try {
let successVrImgList = []
let successCorrectionImgList = []
let successVrImgListNoEdit = []
let successCorrectionImgListNoEdit = []
if (addAndEditModel.vrImgList.length > 0) {
successVrImgList = await uploadImgFun(addAndEditModel.vrImgList, 1)
successVrImgListNoEdit = addAndEditModel.vrImgList.map((e) => !e.isEdit)
successVrImgList = await uploadImgFun(successVrImgListNoEdit, 1)
}
if (addAndEditModel.correctionImgList.length > 0) {
successCorrectionImgListNoEdit = addAndEditModel.correctionImgList.map(
(e) => !e.isEdit,
)
successCorrectionImgList = await uploadImgFun(
addAndEditModel.correctionImgList,
successCorrectionImgListNoEdit,
2,
)
}
resolve({ successVrImgList, successCorrectionImgList }) //
} catch (error) {
reject(error) //
}
})
uploadImages
.then(async ({ successVrImgList, successCorrectionImgList }) => {
console.log('图片上传成功,开始提交表单...')
//
//
const {
dataSource,
@ -601,7 +630,25 @@ const onSubmitForm = debounce(() => {
uploadType: 1,
}
const res = await addSafetyViolationsApi(addParams)
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;',
@ -611,15 +658,19 @@ const onSubmitForm = debounce(() => {
sendLoading.value = false
if (res.code === 200) {
uni.$u.toast('新增成功')
uni.$u.toast(res.data)
setTimeout(() => {
uni.navigateBack({
delta: 1,
})
}, 500)
} else {
uni.$u.toast('新增失败' + res.data)
uni.$u.toast(res.data)
}
})
.catch((error) => {
console.error('图片上传失败:', error)
})
}
})
.catch((error) => {})
@ -674,16 +725,88 @@ const uploadImgFun = async (list, type) => {
}
//
const getFormDetail = () => {
console.log('---获取详情数据')
}
// props.addAndEditFormType 2
if (props.addAndEditFormType == 2) {
//
getFormDetail()
const getFormDetail = async () => {
const res = await getSafetyViolationsDetailsByIdApi({ id: props?.detailsId })
if (res.code === 200) {
const {
dataSource,
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>
<style scoped lang="scss">

View File

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

View File

@ -8,8 +8,8 @@
<up-input
clearable
placeholder="输入搜索关键词"
v-model.trim="onSearchKeyword"
suffixIconStyle="color: #909399"
v-model.trim="queryParams.keyWord"
>
<template #suffix>
<up-icon name="search" size="24" @tap="onSearchRecord" />
@ -19,58 +19,47 @@
</view>
<view class="upload-record-list">
<up-list
ref="upListRef"
style="width: 100%"
@scroll="onScrollUpList"
@scrolltolower="onScrollTolower"
>
<up-list-item v-for="item in 10" :key="item">
<up-list ref="upListRef" style="width: 100%" @scrolltolower="onScrollTolower">
<up-list-item v-for="item in safetyViolationsList" :key="item.id">
<view class="record-item">
<view @tap="onHandleViewDetails">
<!-- 日期 -->
<view class="item-date">
<text>2024-05-06</text>
<text>{{ item.vioDate }}</text>
<view>
<up-button
size="mini"
text="修改"
type="primary"
@tap="onHandleEditRecord"
@tap="onHandleEditRecord(item.id)"
/>
</view>
</view>
<!-- 名称 -->
<view class="item-name">
<text>N3917</text>
<text>{{ item.proName }}</text>
</view>
<!-- 文字内容 -->
<view class="text-content">
<up-text
:lines="2"
text="关于uview-plus的取名来由首字母u来自于uni-app首字母
uni-app是基VuejsVue和View(延伸为UI视图之意)同音同时view组件uni-app中
最础最重要的组件故取名uview-plus表达源于uni-app和Vue之意同时在此也对它示感谢"
/>
<up-text :lines="2" :text="item.vioDesc" />
</view>
</view>
<!-- 图片内容 -->
<view class="swiper-container">
<up-swiper
:list="list1"
:indicator="true"
:list="item.vioPhotoList"
interval="5000"
@click="onClickSwiper"
/>
<view class="swiper-count"> 3 </view>
<view class="swiper-count">{{ item.vioPhotoNum }} </view>
</view>
<!-- 检查人 -->
<view class="inspect-person">
<view> 检查人武松 </view>
<view> 整改日期2025-05-06 </view>
<view> 检查人{{ item.checkUserName }} </view>
<view> 整改日期{{ item.rectTime }} </view>
</view>
</view>
</up-list-item>
@ -79,8 +68,6 @@ uni-app是基VuejsVue和View(延伸为UI、视图之意)同音同时view
<view class="loading-text">
{{ finish ? '没有更多数据了~' : '正在加载...' }}
</view>
<!-- <up-back-top :scroll-top="scrollTop" icon="arrow-up" @tap="onHandleBackTop" /> -->
</view>
</view>
</view>
@ -88,40 +75,91 @@ uni-app是基VuejsVue和View(延伸为UI、视图之意)同音同时view
<script setup>
import NavBarModal from '@/components/NavBarModal/index'
import { ref, reactive } from 'vue'
import { ref, computed } from 'vue'
import { debounce } from 'lodash-es' //
import { getSafetyViolationsListApi } from '@/services/safetyViolations.js'
const { safeAreaInsets } = uni.getSystemInfoSync()
const onSearchKeyword = ref('')
const finish = ref(false)
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 = []
}
}
}
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',
])
getSafetyViolationsListData()
//
const onScrollTolower = debounce(() => {
console.log('onScrollTolower')
console.log('onScrollTolower', '滚动触底')
//
if (safetyViolationsList.value.length < total.value) {
queryParams.value.page++
getSafetyViolationsListData(false)
}
}, 500)
//
const finish = computed(() => {
if (total.value === safetyViolationsList.value.length) return true
})
//
const onSearchRecord = () => {
console.log('onSearchRecord', onSearchKeyword.value)
console.log('onSearchRecord', queryParams.value.keyWord)
getSafetyViolationsListData(true)
}
//
const onHandleEditRecord = () => {
const onHandleEditRecord = (id) => {
console.log('onHandleEditRecord')
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/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. 其他错误
uni.showToast({
icon: 'none',
title: '请求错误',
title: '请求失败,请切换网络后尝试',
})
reject(res)
}
@ -111,7 +111,7 @@ export const http = (options) => {
fail(err) {
uni.showToast({
icon: 'none',
title: '请求失败',
title: '请求失败,请切换网络后尝试',
})
console.log(err, '请求失败')
reject(err)