打卡上传照片

This commit is contained in:
lSun 2026-01-16 18:04:09 +08:00
parent 0f34148494
commit dac24ccd17
3 changed files with 180 additions and 37 deletions

View File

@ -12,6 +12,40 @@
</view>
<view class="tle">我的位置</view>
<view class="curAdres">{{curAdres}}</view>
<!-- 图片上传 -->
<view class="tle" style="margin-top: 40rpx;">工作地证明必填1-3</view>
<view class="upload_nav">
<view
class="upload_item"
v-for="(item, index) in imgList"
:key="index"
>
<image :src="item" class="upload_img" mode="aspectFill"></image>
<view class="del" @click="removeImg(index)">×</view>
</view>
<view
class="upload_add"
v-if="imgList.length < maxImg"
@click="chooseImage"
>
<view class="plus">+</view>
<view class="txt">拍照 / 相册</view>
</view>
</view>
<view class="tle" style="margin-top: 40rpx;">说明选填</view>
<view class="input_nav">
<textarea
style="width: 100%;height: 100%;"
placeholder="请输入"
v-model="describe"
/>
</view>
<view class="tle" style="margin-top: 40rpx;">备注选填</view>
<view class="input_nav">
<textarea style="width: 100%;height: 100%;" placeholder="请输入" v-model="remark" />
@ -32,6 +66,7 @@
import tabbar from "@/components/tabbar/tabbar.vue"
const bmap = require('@/utils/bmapjs/bmap-wx.min.js');
import {selectFaceInfo} from "@/api/index.js"
import { uploadFile } from '@/utils/http'
export default {
components: {
tabbar
@ -47,7 +82,13 @@
timer: null,
subscribe: [], //
BMap: null,
isNext: false
isNext: false,
//
imgList: [],
serverImgs: [],
maxImg: 3,
describe: '',
}
},
onLoad() {
@ -179,13 +220,55 @@
})
},
clockClick() {
if(!this.isNext) {
/* 选图 */
chooseImage() {
uni.chooseImage({
count: this.maxImg - this.imgList.length,
sourceType: ['camera', 'album'],
sizeType: ['compressed'],
success: (res) => {
this.imgList = this.imgList.concat(res.tempFilePaths)
}
})
},
removeImg(index) {
this.imgList.splice(index, 1)
this.serverImgs.splice(index, 1)
},
/* 上传图片 */
uploadImages() {
return new Promise((resolve, reject) => {
let count = 0
this.serverImgs = []
this.imgList.forEach(path => {
uploadFile({
url: '/file/upload',
filePath: path
}).then(res => {
// 访
this.serverImgs.push(res.url)
count++
if (count === this.imgList.length) {
resolve()
}
}).catch(err => {
reject(err)
})
})
})
},
async clockClick() {
if (!this.isNext) {
uni.showModal({
title: '提示',
content: '您当前还未录入人脸信息,请先录入',
success: res => {
if(res.confirm) {
if (res.confirm) {
uni.redirectTo({
url: '/pages/face/index'
})
@ -194,7 +277,20 @@
})
return
}
if(this.subscribe.length <= 0) {
if (this.imgList.length < 1) {
uni.showToast({title: '请至少上传一张现场照片', icon: 'none'})
return
}
try {
await this.uploadImages()
} catch (e) {
uni.showToast({title: '图片上传失败', icon: 'none'})
return
}
if (this.subscribe.length <= 0) {
this.requestSubscribeMessage()
}
// let data = {
@ -206,10 +302,9 @@
// uni.navigateTo({
// url: '/pages/clock/detail',
// })
console.log("remark",this.remark);
console.log("remark", this.remark);
uni.redirectTo({
url: '/pages/clock/detail?attLon=' + this.longitude + '&attLat=' + this.latitude + '&remark=' + this.remark
url: '/pages/clock/detail?attLon=' + this.longitude + '&attLat=' + this.latitude + '&remark=' + this.remark + '&describe='+this.describe + '&imgUrl=' + this.serverImgs
})
}
}

View File

@ -70,10 +70,10 @@
data() {
return {
form: {
// phone: '15240004260',
// password: 'GZkq@123456!',
phone: '',
password: '',
phone: '15240004260',
password: 'GZkq@123456!',
// phone: '',
// password: '',
},
version: '3.6.2',
}

View File

@ -172,3 +172,51 @@ const request = (options) => {
// }
export default request
/**
* 文件上传MultipartFile
* @param {String} url 接口地址
* @param {String} filePath 本地文件路径
* @param {Object} formData 额外参数可选
*/
export function uploadFile({ url, filePath, formData = {} }) {
return new Promise((resolve, reject) => {
const token = uni.getStorageSync('token')
uni.uploadFile({
url: BASE_URL + url,
filePath: filePath,
name: 'file', // ⚠️ 必须是 file对应后台 @RequestParam("file")
formData: formData,
header: {
token: token || '',
Authorization: token || ''
},
success: (res) => {
try {
const data = JSON.parse(res.data)
if (data.code === 200) {
resolve(data)
} else {
reject(data)
uni.showToast({
title: data.msg || '上传失败',
icon: 'none'
})
}
} catch (e) {
reject(e)
}
},
fail: (err) => {
reject(err)
uni.showToast({
title: '文件上传失败',
icon: 'none'
})
}
})
})
}