学员端小程序
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.

113 lines
2.4 KiB

1 year ago
  1. <template>
  2. <view class="pageBgImg">
  3. <topNavbar title="上传头像"></topNavbar>
  4. <view class="pad">
  5. <view class="card">
  6. <view class="h2">请上传或拍摄一张五官清晰的照片</view>
  7. <view class="phone" @click="chooseImages">
  8. <view class="phoneIcon">
  9. <image src="@/static/images/index/btn_tupian.png" mode=""></image>
  10. </view>
  11. <view class="lab">添加图片</view>
  12. </view>
  13. <view class="btnBg" @click="$goPage('/pages/indexEntry/enroll/registInfo/registInfo')">上传</view>
  14. </view>
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. import { APP_API, APP_HOST } from '@/site.config.js';
  20. const _url = APP_HOST + APP_API + '/util/manage/uploadFile.do';
  21. export default {
  22. data() {
  23. return {
  24. }
  25. },
  26. methods: {
  27. //选择图片
  28. chooseImages(type) {
  29. uni.chooseImage({
  30. count: 1, //允许选择的数量
  31. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  32. sourceType: ['album', 'camera'], //从相册选择
  33. success: res => {
  34. uni.showLoading({
  35. title: '图片上传中...'
  36. });
  37. res.tempFilePaths.forEach( (item,index)=>{
  38. this.uploadImgApi(item)
  39. })
  40. }
  41. })
  42. },
  43. uploadImgApi(filePath) {
  44. console.log(filePath)
  45. let _this = this
  46. // 上传图片到服务器
  47. uni.uploadFile({
  48. url: _url,//接口
  49. filePath: filePath,//要上传的图片的本地路径
  50. name: 'file',
  51. formData: {
  52. fileType: 1,
  53. fileSuffix: "png"
  54. },
  55. header: {
  56. token: uni.getStorageSync("Authorization") || '',
  57. },
  58. success(res) {
  59. console.log('上传成功')
  60. let res2 = JSON.parse(res.data)
  61. _this.imgArr.push(res2.data)
  62. console.log(res2)
  63. uni.hideLoading();
  64. },
  65. complete: ()=> {}
  66. })
  67. },
  68. }
  69. }
  70. </script>
  71. <style lang="scss" scoped>
  72. .card {
  73. display: flex;
  74. align-items: center;
  75. flex-direction: column;
  76. .h2 {
  77. padding: 126rpx 0 84rpx 0;
  78. font-size: 36rpx;
  79. font-weight: 600;
  80. }
  81. }
  82. .phone {
  83. border: 2rpx dashed #CDCED0;
  84. width: 290rpx;
  85. height: 290rpx;
  86. border-radius: 16rpx;
  87. overflow: hidden;
  88. display: flex;
  89. align-items: center;
  90. justify-content: center;
  91. flex-direction: column;
  92. .phoneIcon {
  93. width: 60rpx;
  94. height: 60rpx;
  95. }
  96. .lab {
  97. font-size: 20rpx;
  98. color: #686B73;
  99. margin-top: 8rpx;
  100. }
  101. }
  102. .btnBg {
  103. width: 396rpx;
  104. margin: 130rpx 0;
  105. }
  106. </style>