学员端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

114 lines
2.4 KiB

<template>
<view class="pageBgImg">
<topNavbar title="上传头像"></topNavbar>
<view class="pad">
<view class="card">
<view class="h2">请上传或拍摄一张五官清晰的照片</view>
<view class="phone" @click="chooseImages">
<view class="phoneIcon">
<image src="@/static/images/index/btn_tupian.png" mode=""></image>
</view>
<view class="lab">添加图片</view>
</view>
<view class="btnBg" @click="$goPage('/pages/indexEntry/enroll/registInfo/registInfo')">上传</view>
</view>
</view>
</view>
</template>
<script>
import { APP_API, APP_HOST } from '@/site.config.js';
const _url = APP_HOST + APP_API + '/util/manage/uploadFile.do';
export default {
data() {
return {
}
},
methods: {
//选择图片
chooseImages(type) {
uni.chooseImage({
count: 1, //允许选择的数量
sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'], //从相册选择
success: res => {
uni.showLoading({
title: '图片上传中...'
});
res.tempFilePaths.forEach( (item,index)=>{
this.uploadImgApi(item)
})
}
})
},
uploadImgApi(filePath) {
console.log(filePath)
let _this = this
// 上传图片到服务器
uni.uploadFile({
url: _url,//接口
filePath: filePath,//要上传的图片的本地路径
name: 'file',
formData: {
fileType: 1,
fileSuffix: "png"
},
header: {
token: uni.getStorageSync("Authorization") || '',
},
success(res) {
console.log('上传成功')
let res2 = JSON.parse(res.data)
_this.imgArr.push(res2.data)
console.log(res2)
uni.hideLoading();
},
complete: ()=> {}
})
},
}
}
</script>
<style lang="scss" scoped>
.card {
display: flex;
align-items: center;
flex-direction: column;
.h2 {
padding: 126rpx 0 84rpx 0;
font-size: 36rpx;
font-weight: 600;
}
}
.phone {
border: 2rpx dashed #CDCED0;
width: 290rpx;
height: 290rpx;
border-radius: 16rpx;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
.phoneIcon {
width: 60rpx;
height: 60rpx;
}
.lab {
font-size: 20rpx;
color: #686B73;
margin-top: 8rpx;
}
}
.btnBg {
width: 396rpx;
margin: 130rpx 0;
}
</style>