step4.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <view>
  3. <u-navbar :background="background" :border-bottom="false"></u-navbar>
  4. <view class="jpLogin">
  5. <view class="jpLogin-title">
  6. <h2>上传您的头像 <span>4</span>/4</h2>
  7. <p>选择一张你的优质照片作为头像吧~</p>
  8. </view>
  9. <view class="jpLogin-main">
  10. <view class="jpLogin-upload" @click="uploadPhoto">
  11. <u-image class="newsList-img" src="/static/img/head.png" height="320" width="320" border-radius="10"></u-image>
  12. </view>
  13. <p>点击上传头像</p>
  14. <view class="jpLogin-case">
  15. <view class="jpLogin-case-item">
  16. <u-image class="newsList-img" src="/static/img/user1.jpg" height="170" width="170" border-radius="10"></u-image>
  17. </view>
  18. <view class="jpLogin-case-item">
  19. <u-image class="newsList-img" src="/static/img/user4.jpg" height="170" width="170" border-radius="10"></u-image>
  20. </view>
  21. <view class="jpLogin-case-item">
  22. <u-image class="newsList-img" src="/static/img/user3.jpg" height="170" width="170" border-radius="10"></u-image>
  23. </view>
  24. </view>
  25. </view>
  26. <view style="margin-top: 60px;">
  27. <u-button type="error" shape="circle" :custom-style="customStyle" @click="formsubmit">确认提交</u-button>
  28. <view class="step-btn" @click="previous">返回上一步</view>
  29. </view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. let _self;
  35. import * as loginApi from '@/apis/login.js'
  36. import { pathToBase64, base64ToPath } from '../../utils/image-tools/index.js'
  37. export default {
  38. data() {
  39. return {
  40. personal_info:{},
  41. action: 'http://www.example.com/upload',
  42. fileList: [
  43. {
  44. url: 'http://pics.sc.chinaz.com/files/pic/pic9/201912/hpic1886.jpg',
  45. }
  46. ],
  47. background:{
  48. background: 'none'
  49. }
  50. }
  51. },
  52. onLoad(){
  53. _self = this;
  54. _self.get_options();
  55. },
  56. onReady(){
  57. _self.get_options();
  58. },
  59. methods:{
  60. uploadPhoto(){
  61. // 上传图片
  62. const ctx = uni.createCanvasContext('myCanvas');
  63. //console.log('url'+this.uploadUrl)
  64. let _this = this;
  65. uni.chooseImage({
  66. count: 5, //默认9
  67. // sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  68. sourceType: ['album','camera'], //从相册选择
  69. success:(res)=> {
  70. let imgFile = res.tempFilePaths;
  71. for(let i = 0;i < imgFile.length;i++)
  72. {
  73. pathToBase64(imgFile[i])
  74. .then(base64 => {
  75. let data = {photoName:imgFile[i],photoBase64Data: base64};
  76. console.log('图片数据'+JSON.stringify(data));
  77. let ret = loginApi.uploadFile(data).then(function(res){
  78. console.log('result1' + JSON.stringify(res));
  79. if(res.statusCode == 200)
  80. {
  81. let imgUrls = JSON.parse(res.data) //百度支持 this.site_url +'/' +
  82. //let image ={src: imgUrls.data.filePath,fileId:imgUrls.data.fileId};
  83. _this.fileList.push(imgUrls); //微信
  84. }
  85. },function(err){
  86. console.log('上传图片失败'+JSON.stringify(err))
  87. })
  88. })
  89. .catch(error => {
  90. console.error(error)
  91. })
  92. }
  93. },
  94. });
  95. },
  96. get_options(){
  97. console.log('get options')
  98. // #ifdef APP-NVUE
  99. const eventChannel = this.$scope.eventChannel; // 兼容APP-NVUE
  100. // #endif
  101. // #ifndef APP-NVUE
  102. const eventChannel = this.getOpenerEventChannel();
  103. // #endif
  104. eventChannel.on('acceptDataFromOpenerPage', function(data) {
  105. _self.personal_info = data;
  106. console.log('options'+JSON.stringify(data))
  107. });
  108. },
  109. previous(){
  110. uni.navigateBack({
  111. deta:1
  112. })
  113. },
  114. formsubmit(){
  115. }
  116. }
  117. }
  118. </script>
  119. <style lang="scss" scoped>
  120. .jpLogin {
  121. background: url(/static/img/loginBg.png) top center no-repeat;
  122. background-size: 100%;
  123. min-height: 100vh;
  124. padding: 50px;
  125. margin-top: -44px;
  126. }
  127. .step-btn {
  128. text-align: center;
  129. margin-top: 20px;
  130. color: #444953;
  131. }
  132. .jpLogin-title {
  133. h2 {
  134. font-size: 24px;
  135. font-weight: normal;
  136. }
  137. span{
  138. color: #FF5E5E;
  139. margin-left: 5px;
  140. }
  141. p {
  142. color: #777;
  143. font-size: 14px;
  144. margin-top: 3px;
  145. }
  146. }
  147. .jpLogin-main {
  148. margin-top: 40px;
  149. p{
  150. font-size: 16px;
  151. color:#958F90;
  152. text-align: center;
  153. margin: 10px 0 60px;
  154. }
  155. }
  156. .jpLogin-case{
  157. display: flex;
  158. justify-content: space-between;
  159. }
  160. .jpLogin-upload{
  161. border: 1px dashed #FFA199;
  162. border-radius: 12px;
  163. overflow: hidden;
  164. width: 160px;
  165. margin: 0 auto;
  166. p{
  167. margin-top: 5px;
  168. }
  169. }
  170. </style>