代码优化

This commit is contained in:
BianLzhaoMin 2024-11-07 20:21:02 +08:00
parent 90ae4eec8c
commit 80fdebcb4e
10 changed files with 486 additions and 123 deletions

View File

@ -16,3 +16,11 @@ export function getReportMessageApi(data) {
data: data
})
}
// 点击报告获取内容
export function messagePushApi(data) {
return request_yn({
url: '/ynPlanApp/home/setSendNessage',
method: 'post',
data: data
})
}

View File

@ -89,10 +89,9 @@
{{ submitParams.lon }}
</text>
<view @tap="getLocationAddress">点击获取</view>
<!-- <view @tap="getLocationAddress">点击获取</view> -->
</view>
<!-- <view>{{ demoAddress }}</view> -->
</view>
</uni-forms-item>
<uni-forms-item label="附件上传(1-6张照片)" required>
@ -450,7 +449,6 @@ export default {
const this_ = this
uni.chooseLocation({
success: function (res) {
this_.submitParams.address = res.address
this_.submitParams.lon = res.longitude
this_.submitParams.lat = res.latitude
@ -463,26 +461,42 @@ export default {
this.getMySceneListData()
this.getTodayRiskData()
//
// uni.getLocation({
// type: 'wgs84', // gcj02 'wgs84'
// // altitude: false,
// // geocode: true,
// success: res => {
// console.log(res, '--')
// // this.demoAddress = res
// const { latitude, longitude } = res
// // const { province, city, district, street, streetNum, poiName } = res.address
uni.getLocation({
type: 'gcj02', // gcj02 'wgs84'
altitude: false,
geocode: true,
success: res => {
console.log(res, '位置信息--')
this.demoAddress = res
const { latitude, longitude } = res
// const { province, city, district, street, streetNum, poiName } = res.address
// this.submitParams.lon = longitude
// this.submitParams.lat = latitude
// // console.log(province, 'province')
// // this.submitParams.address = `${province}${city}${district}${street}${streetNum}${poiName}`
// },
// fail: err => {
// console.error(':', err)
// uni.showToast({ title: '', icon: 'none' })
// }
// })
uni.request({
url: `https://api.map.baidu.com/reverse_geocoding/v3/?ak=PM43nB8eDNTBrXkQwGrTQFcmOni3Z9nO&output=json&coordtype=gcj02ll&location=${latitude},${longitude}`,
method: 'GET',
// data: {
// ak: 'PM43nB8eDNTBrXkQwGrTQFcmOni3Z9nO',
// output: JSON,
// coordtype: 'gcj02ll',
// location: `${longitude},${latitude}`
// },
success: res => {
console.log('解析的地址', res)
this.submitParams.address = res.data.result.formatted_address
}
})
this.submitParams.lon = longitude
this.submitParams.lat = latitude
// console.log(province, 'province')
// this.submitParams.address = `${province}${city}${district}${street}${streetNum}${poiName}`
},
fail: err => {
console.error('获取位置失败:', err)
uni.showToast({ title: '位置获取失败,请稍后尝试', icon: 'none' })
}
})
// uni.chooseLocation({
// success: function (res) {

View File

@ -2050,7 +2050,25 @@ export default {
(this.monthDataList[this.activeFormPages].imgList.length +
this.monthDataList[this.activeFormPages].imgViewList.length)
}
}
},
debounce(fn, delay) {
let timer = null
return (...args) => {
//
if (timer) {
clearTimeout(timer)
}
//
timer = setTimeout(() => {
fn.apply( ...args) // 使 `apply` `this` Vue
}, delay)
}
},
},
created() {
// `onSendMessage`
this.onSaveSubmit = this.debounce(this.onSaveSubmit, 1000);
},
onReady() {},

View File

@ -143,11 +143,11 @@
</view>
<view>
暂退人员:
<text v-for="(item, index) in tempPersonList" :key="index">{{ item }}</text>
<text v-for="(item, index) in returnPersonList" :key="index">{{ item }}</text>
</view>
<view>
临时人员:
<text v-for="(item, index) in returnPersonList" :key="index">{{ item }}</text>
<text v-for="(item, index) in tempPersonList" :key="index">{{ item }}</text>
</view>
</view>
@ -422,7 +422,9 @@ export default {
this.subUserList.forEach(e => {
console.log('选择的每一项', e)
this.fixedPersonList = []
this.tempPersonList = []
this.returnPersonList = []
if (e.isChecked) {
if (e.userState == 1) {
//

View File

@ -30,6 +30,7 @@
</view>
<view class="send-btn" @tap="onSendMessage">发送</view>
<!-- <view class="send-btn" @tap="handleClick">测试</view> -->
</view>
<!-- 人员弹框 -->
@ -88,7 +89,8 @@
</template>
<script>
import { getPushPersonListApi, getReportMessageApi } from '../../../api/workPlan/my'
import { getPushPersonListApi, getReportMessageApi, messagePushApi } from '../../../api/workPlan/my'
export default {
data() {
return {
@ -99,10 +101,26 @@ export default {
mobilePhoneNumber: '',
phoneList: [],
auditingUserList: [],
pushPersonListAll: []
pushPersonListAll: [],
isSending: false
}
},
methods: {
debounce(fn, delay) {
let timer = null
return (...args) => {
//
if (timer) {
clearTimeout(timer)
}
//
timer = setTimeout(() => {
fn.apply( ...args) // 使 `apply` `this` Vue
}, delay)
}
},
leftClick() {
uni.navigateBack()
},
@ -174,82 +192,251 @@ export default {
this.reportMessage = res
// console.log('', res)
},
//
onSendMessage() {
async onSendMessage() {
// console.log(this, 'this')
if (!this.phoneStr) {
uni.showToast({ title: '请选择收件人或填写收件人号码', icon: 'none' })
// this.isSending = false //
return
}
if (!this.reportMessage) {
uni.showToast({ title: '请填写短信内容', icon: 'none' })
// this.isSending = false //
return
}
const sendPhoneList = this.phoneStr.split(',')
const params = {
content: `【作业计划管控平台】${this.reportMessage}`,
phoneStr: sendPhoneList.join('@')
}
console.log('sendPhoneList', sendPhoneList)
uni.showLoading({ title: '短信正在发送,请勿刷新页面或重复点击!' })
new Promise((resolve, reject) => {
let promisesFun = []
uni.showLoading({ title: '短信正在发送,请不要重复点击', mask: true })
console.log('推送参数', params)
messagePushApi(params).then(res => {
console.log('推送结果', res)
uni.hideLoading()
sendPhoneList.forEach(e => {
console.log(e, '手机号码')
// uni.request Promise
let promise = new Promise((reqResolve, reqReject) => {
let params = {
ddtKey: 'bonusyn',
secretkey: 'IU0ypHbH',
mobile: e,
content: this.reportMessage
}
console.log('发送参数', params)
uni.request({
url: 'http://api.ktsms.cn/sms_token',
method: 'POST',
data: params,
header: {
'Content-Type': 'application/x-www-form-urlencoded'
},
// dataType: 'json',
success: res => {
console.log('短信发送成功', res)
reqResolve(res) // reqResolve
},
fail: err => {
console.log(err, '发送失败')
reqReject(err) // reqReject
}
})
})
// promise
promisesFun.push(promise)
})
//
Promise.all(promisesFun)
.then(() => {
resolve() // resolve
})
.catch(err => {
reject(err) // reject
})
})
.then(res => {
// console.log('---')
uni.hideLoading()
if (res.res === 1) {
uni.showToast({ title: '短信发送成功!', icon: 'none' })
setTimeout(() => {
uni.navigateBack()
}, 500)
})
.catch(err => {
uni.hideLoading()
console.log('短信发送失败')
})
} else {
uni.showToast({ title: '短信发送失败!', icon: 'none' })
}
})
}
// //
// async onSendMessage() {
// if (this.isSending) {
// //
// uni.showToast({ title: '', icon: 'none' })
// return
// }
// //
// this.isSending = true
// const sendPhoneList = this.phoneStr.split(',')
// const params = {
// content: `${this.reportMessage}`,
// phoneStr: sendPhoneList.join('@')
// }
// uni.showLoading({ title: '', mask: true })
// console.log(params, '')
// try {
// } catch (error) {
// uni.hideLoading()
// uni.showToast({ title: '', icon: 'none' })
// console.error(error)
// } finally {
// //
// this.isSending = false
// }
// // console.log(res, '')
// // if (!this.phoneStr) {
// // uni.showToast({ title: '', icon: 'none' })
// // return
// // }
// // if (!this.reportMessage) {
// // uni.showToast({ title: '', icon: 'none' })
// // return
// // }
// // const sendPhoneList = this.phoneStr.split(',')
// // const params = {
// // content: `${this.reportMessage}`,
// // phoneStr: sendPhoneList.join('@')
// // }
// // uni.showLoading({ title: '', mask: true })
// // console.log(params, '')
// // const res = await messagePushApi(params)
// // uni.hideLoading()
// // if (res.res == 1) {
// // uni.hideLoading()
// // uni.showToast({ title: '', icon: 'none' })
// // setTimeout(() => {
// // uni.navigateBack()
// // }, 500)
// // } else {
// // uni.showToast({ title: '', icon: 'none' })
// // }
// // console.log(res, '')
// if (true) return
// // console.log('sendPhoneList', sendPhoneList)
// uni.showLoading({ title: '' })
// new Promise((resolve, reject) => {
// let promisesFun = []
// sendPhoneList.forEach(e => {
// console.log(e, '')
// // uni.request Promise
// let promise = new Promise((reqResolve, reqReject) => {
// let params = {
// ddtKey: 'bonusyn',
// secretkey: 'IU0ypHbH',
// mobile: e,
// content: `${this.reportMessage}`
// }
// console.log('', params)
// uni.request({
// url: 'http://api.ktsms.cn/sms_token',
// method: 'POST',
// data: params,
// header: {
// 'Content-Type': 'application/x-www-form-urlencoded'
// },
// // dataType: 'json',
// success: res => {
// console.log('', res)
// reqResolve(res) // reqResolve
// },
// fail: err => {
// console.log(err, '')
// reqReject(err) // reqReject
// }
// })
// })
// // promise
// promisesFun.push(promise)
// })
// //
// Promise.all(promisesFun)
// .then(() => {
// resolve() // resolve
// })
// .catch(err => {
// reject(err) // reject
// })
// })
// .then(res => {
// // console.log('---')
// uni.hideLoading()
// uni.showToast({ title: '', icon: 'none' })
// setTimeout(() => {
// uni.navigateBack()
// }, 500)
// })
// .catch(err => {
// uni.hideLoading()
// console.log('')
// })
// },
// onSendMessage: debounce(
// function () {
// console.log(this,'this')
// // const this_ = this
// if (!this.phoneStr) {
// uni.showToast({ title: '', icon: 'none' })
// this.isSending = false //
// return
// }
// if (!this.reportMessage) {
// uni.showToast({ title: '', icon: 'none' })
// this.isSending = false //
// return
// }
// const sendPhoneList = this.phoneStr.split(',')
// const params = {
// content: `${this.reportMessage}`,
// phoneStr: sendPhoneList.join('@')
// }
// uni.showLoading({ title: '', mask: true })
// console.log('', params)
// messagePushApi(params).then(res => {
// console.log('', res)
// uni.hideLoading()
// if (res.res == 1) {
// uni.showToast({ title: '', icon: 'none' })
// setTimeout(() => {
// uni.navigateBack()
// }, 500)
// } else {
// uni.showToast({ title: '', icon: 'none' })
// }
// })
// }.bind(this),
// 1500
// )
// onSendMessage: debounce(() => {
// // 使 `this`
// console.log(this, 'this') // `this` Vue
// if (!this.phoneStr) {
// uni.showToast({ title: '', icon: 'none' })
// // this.isSending = false //
// return
// }
// if (!this.reportMessage) {
// uni.showToast({ title: '', icon: 'none' })
// // this.isSending = false //
// return
// }
// const sendPhoneList = this.phoneStr.split(',')
// const params = {
// content: `${this.reportMessage}`,
// phoneStr: sendPhoneList.join('@')
// }
// uni.showLoading({ title: '', mask: true })
// console.log('', params)
// messagePushApi(params).then(res => {
// console.log('', res)
// uni.hideLoading()
// if (res.res == 1) {
// uni.showToast({ title: '', icon: 'none' })
// setTimeout(() => {
// uni.navigateBack()
// }, 500)
// } else {
// uni.showToast({ title: '', icon: 'none' })
// }
// })
// }, 1500)
},
created() {
// `onSendMessage`
this.onSendMessage = this.debounce(this.onSendMessage, 1000);
}
}
</script>

View File

@ -242,10 +242,10 @@ export default {
{ title: '提交', id: 4, type: 'upload', isShow: ['1', '2', '3'], isRoles: ['22', '23'] }
],
productionFormLabel: [
{ form_label: '作业内容', items_type: 'ipt', name: 'area', required: true },
{ form_label: '实施单位', items_type: 'ipt', name: 'area', required: true },
{ form_label: '实施部门', items_type: 'ipt', name: 'area', required: true },
{ form_label: '任务来源', items_type: 'ipt', name: 'area', required: true },
{ form_label: '作业内容', items_type: 'area', name: 'zynr', required: true },
{ form_label: '实施单位', items_type: 'area', name: 'ssdw', required: true },
{ form_label: '实施部门', items_type: 'area', name: 'ssbm', required: true },
{ form_label: '任务来源', items_type: 'area', name: 'rwly', required: true },
{
form_label: '作业类型',
items_type: 'sel',
@ -331,7 +331,7 @@ export default {
]
},
{ form_label: '备注', items_type: 'ipt', name: 'bz', required: false },
{ form_label: '计划数量', items_type: 'ipt', name: 'planCount', isType: 'number', required: true }
{ form_label: '计划数量', items_type: 'ipt', isType: 'number', name: 'planCount', required: true }
],
kjsAmount: 0,
dfxAmount: 0,

View File

@ -13,7 +13,7 @@
<view>
<view class="item-header">
<text>{{ month }}</text>
<!-- <text>{{ month }}</text> -->
<text v-if="kjsAmount > 0" style="color: #06bd36">可接受风险:{{ kjsAmount }}</text>
<text v-if="dfxAmount > 0" style="color: #06bd36">低风险:{{ dfxAmount }}</text>
<text v-if="zfxAmount > 0" style="color: #f28b00">中风险:{{ zfxAmount }}</text>
@ -239,20 +239,17 @@ export default {
],
productionFormLabel: [
{ form_label: '作业内容', items_type: 'ipt', name: 'area', required: true },
{ form_label: '实施单位', items_type: 'ipt', name: 'area', required: true },
{ form_label: '实施部门', items_type: 'ipt', name: 'area', required: true },
{ form_label: '任务来源', items_type: 'ipt', name: 'area', required: true },
{ form_label: '作业内容', items_type: 'area', name: 'zynr', required: true },
{ form_label: '实施单位', items_type: 'area', name: 'ssdw', required: true },
{ form_label: '实施部门', items_type: 'area', name: 'ssbm', required: true },
{ form_label: '任务来源', items_type: 'area', name: 'rwly', required: true },
{
form_label: '作业类型',
items_type: 'sel',
name: 'zylx',
required: true,
options: [
{ value: 0, text: '检修' },
{ value: 1, text: '维护' }
]
options: []
},
{ form_label: '计划开始时间', items_type: 'date', name: 'kssj', required: true },
{ form_label: '计划结束时间', items_type: 'date', name: 'jssj', required: true },
@ -262,8 +259,8 @@ export default {
name: 'sftd',
required: true,
options: [
{ value: 1, text: '是' },
{ value: 0, text: '否' }
{ value: '1', text: '是' },
{ value: '0', text: '否' }
]
},
{ form_label: '停电设备(作业场所)', items_type: 'ipt', name: 'tdsb', required: true },
@ -288,12 +285,7 @@ export default {
items_type: 'sel',
name: 'gkfs',
required: true,
options: [
{ value: 0, text: '过程管控' },
{ value: 1, text: '巡视管控' },
{ value: 2, text: '驻点管控' },
{ value: 2, text: '节点管控' }
]
options: []
},
{
form_label: '施工方案',
@ -301,8 +293,8 @@ export default {
name: 'sgfa',
required: true,
options: [
{ value: 1, text: '是' },
{ value: 0, text: '否' }
{ value: '1', text: '是' },
{ value: '0', text: '否' }
]
},
{
@ -311,8 +303,8 @@ export default {
name: 'zyzds',
required: true,
options: [
{ value: 0, text: '是' },
{ value: 1, text: '否' }
{ value: '1', text: '是' },
{ value: '0', text: '否' }
]
},
{
@ -321,8 +313,8 @@ export default {
name: 'zybd',
required: true,
options: [
{ value: 0, text: '是' },
{ value: 1, text: '否' }
{ value: '1', text: '是' },
{ value: '0', text: '否' }
]
},
{
@ -331,12 +323,12 @@ export default {
name: 'gzp',
required: true,
options: [
{ value: 0, text: '是' },
{ value: 1, text: '否' }
{ value: '1', text: '是' },
{ value: '0', text: '否' }
]
},
{ form_label: '备注', items_type: 'ipt', name: 'bz' },
{ form_label: '计划数量', items_type: 'ipt', name: 'planCount', required: true, isType: 'number' }
{ form_label: '备注', items_type: 'ipt', name: 'bz', required: false },
{ form_label: '计划数量', items_type: 'ipt', isType: 'number', name: 'planCount', required: true }
],
kjsAmount: 0,
dfxAmount: 0,
@ -757,6 +749,93 @@ export default {
border-bottom: 1px solid #003778;
color: #003778 !important;
}
.process-container {
padding: 20rpx;
background-color: #fff;
border-top: 2px solid #ccc;
h1 {
margin-bottom: 20rpx;
font-size: 40rpx;
letter-spacing: 2px;
}
.process-item {
display: flex;
justify-content: space-between;
}
.process-item view:first-child {
position: relative;
width: 20%;
height: 80rpx;
color: #fff;
// background-color: #00337a;
border-radius: 12rpx;
image {
width: 100%;
height: 80rpx;
}
.type-icon {
// box-sizing: border-box;
position: absolute;
bottom: 0;
right: 0;
height: 35rpx;
width: 35rpx;
border-radius: 50%;
text-align: center;
line-height: 35rpx;
transform: translate(25%, 25%);
border: 3px solid #fff;
background-color: green;
}
}
.process-item .box-2 {
flex: 1;
padding-left: 26rpx;
display: flex;
flex-direction: column;
.text_1 {
font-size: 28rpx;
color: #7e7e7e;
}
.text_2 {
width: 100%;
display: flex;
// display: block;
justify-content: space-between;
align-items: center;
margin-top: 16rpx;
font-size: 24rpx;
color: #000;
}
}
.process-item .box-3 {
width: 30%;
font-size: 22rpx;
color: #333;
}
.line {
margin: 28rpx 0;
.line-content {
width: 20%;
view {
margin: 0 auto;
height: 60rpx;
width: 2px;
background-color: #00337a;
}
}
}
}
.auditing-content {
width: 95vw;
height: 60vh;

View File

@ -313,6 +313,10 @@
<text>{{ item.planTime }}</text>
</view>
<view class="item-pro">
<text>工程名称</text>
<text>{{ item.proName }}</text>
</view>
<view class="item-num">
<text>计划数量</text>
<text>{{ item.planCount }}</text>
@ -363,6 +367,10 @@
<text>{{ item.planTime }}</text>
</view>
<view class="item-pro">
<text>工程名称</text>
<text>{{ item.proName }}</text>
</view>
<view class="item-num">
<text>计划数量</text>
<text>{{ item.planCount }}</text>
@ -1780,7 +1788,8 @@ export default {
}
.item-num,
.item-time {
.item-time,
.item-pro {
width: 96%;
margin: 0 auto;
padding: 12rpx 0;
@ -1789,6 +1798,9 @@ export default {
justify-content: space-between;
font-size: 26rpx;
}
.item-pro text:first-child {
width: 30%;
}
.item-num {
margin-top: 18rpx;
}

View File

@ -313,6 +313,10 @@
<text>{{ item.planTime }}</text>
</view>
<view class="item-pro">
<text>工程名称</text>
<text>{{ item.proName }}</text>
</view>
<view class="item-num">
<text>计划数量</text>
@ -363,6 +367,10 @@
<text>{{ item.planTime }}</text>
</view>
<view class="item-pro">
<text>工程名称</text>
<text>{{ item.proName }}</text>
</view>
<view class="item-num">
<text>计划数量</text>
@ -1776,7 +1784,8 @@ export default {
}
.item-num,
.item-time {
.item-time,
.item-pro {
width: 96%;
margin: 0 auto;
padding: 12rpx 0;
@ -1788,6 +1797,9 @@ export default {
.item-num {
margin-top: 18rpx;
}
.item-pro text:first-child {
width: 30%;
}
.item-num text:last-child {
width: 60%;
text-align: left;

View File

@ -10,13 +10,26 @@ let timeout = 60000
const baseUrl = config.workPlanNewYnUrl
console.log('token', token)
let isRequesting = false // 请求锁,防止重复请求
const request = config => {
// 如果正在请求中,直接返回一个 rejected promise
if (isRequesting) {
return uni.showToast({ title: '请求正在处理中...请稍后', icon: 'none' })
// return Promise.reject('请求正在处理中,请稍后再试')
// uni.showToast({ title: '请求正在处理中...', icon: 'none' })
}
// 设置请求正在进行
isRequesting = true
// 是否需要设置 token
const isToken = (config.headers || {}).isToken === false
config.header = config.header || {}
if (token && !isToken) {
config.header['Authorization'] = 'Bearer ' + token
}
// get请求映射params参数
if (config.params) {
let url = config.url + '?' + tansParams(config.params)
@ -31,6 +44,7 @@ const request = config => {
}
// config.data = JSON.stringify(config.data);
}
return new Promise((resolve, reject) => {
uni
.request({
@ -42,15 +56,18 @@ const request = config => {
dataType: 'json'
})
.then(response => {
// console.log(response)
let [error, res] = response
if (error) {
toast('后端接口连接异常')
// 请求完成,解除锁定
isRequesting = false
reject('后端接口连接异常')
return
}
const code = res.data.code || 200
const msg = errorCode[code] || res.data.msg || errorCode['default']
if (code === 401) {
showConfirm('登录状态已过期,您可以继续留在该页面,或者重新登录?').then(res => {
if (res.confirm) {
@ -59,18 +76,29 @@ const request = config => {
})
}
})
// 请求完成,解除锁定
isRequesting = false
reject('无效的会话,或者会话已过期,请重新登录。')
} else if (code === 500) {
toast(msg)
// 请求完成,解除锁定
isRequesting = false
reject(msg)
} else if (code !== 200) {
toast(msg)
// 请求完成,解除锁定
isRequesting = false
reject(msg)
}
// 请求完成,解除锁定
isRequesting = false
resolve(res.data)
})
.catch(error => {
let { message } = error
// 请求异常处理
if (message === 'Network Error') {
message = '后端接口连接异常'
} else if (message.includes('timeout')) {
@ -78,6 +106,9 @@ const request = config => {
} else if (message.includes('Request failed with status code')) {
message = '系统接口' + message.substr(message.length - 3) + '异常'
}
// 请求完成,解除锁定
isRequesting = false
toast(message)
reject(error)
})