figure.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. <template>
  2. <view class="container">
  3. <image-cropper :src="tempFilePath" @confirm="confirm" @cancel="cancel"></image-cropper>
  4. <TopBar></TopBar>
  5. <uni-popup ref="popup" type="bottom" :is-mask-click="false">
  6. <view class="popup" @touchmove.prevent>
  7. <view class="p-title-box flex-between">
  8. <view class="p-title font36 fw600">
  9. 上传头像
  10. </view>
  11. <image :src="`${assetsUrl}info-figure-close.png`" mode="aspectFill" class="p-close" @click="hideHeadPopup"></image>
  12. </view>
  13. <view class="p-title-tip font28 fw400">
  14. 上传清晰本人照片更容易交到好友哦
  15. </view>
  16. <view class="p-img-box flex-between">
  17. <view class="p-img">
  18. <image :src="`${assetsUrl}info-figure-img1.png`" mode="aspectFill" class="img"></image>
  19. <view class="p-text font22 fw400">
  20. 五官清晰
  21. </view>
  22. </view>
  23. <view class="p-img">
  24. <image :src="`${assetsUrl}info-figure-img2.png`" mode="aspectFill" class="img"></image>
  25. <view class="p-text font22 fw400">
  26. 半身照
  27. </view>
  28. </view>
  29. <view class="p-img">
  30. <image :src="`${assetsUrl}info-figure-img3.png`" mode="aspectFill" class="img"></image>
  31. <view class="p-text font22 fw400">
  32. 风景和人
  33. </view>
  34. </view>
  35. </view>
  36. <view style="height: 60rpx;">
  37. </view>
  38. </view>
  39. </uni-popup>
  40. <view class="line-bar flex-between">
  41. <view class="span active"></view>
  42. <view class="span active"></view>
  43. <view class="span"></view>
  44. <view class="span"></view>
  45. <view class="span"></view>
  46. </view>
  47. <view class="title font44 fw600">
  48. 设置你的社交形象
  49. </view>
  50. <view class="tip font28 fw400">
  51. 展示你的真实一面,给大家留一个好印象
  52. </view>
  53. <view class="head-info" @click="showHeadPopup">
  54. <view class="head-box flex-center">
  55. <view class="head-inner flex-center" v-if="cropFilePath===''">
  56. <image :src="`${assetsUrl}info-figure-add.png`" mode="aspectFill" class="add"></image>
  57. </view>
  58. <image :src="cropFilePath" mode="aspectFit" v-else></image>
  59. </view>
  60. <image :src="`${assetsUrl}info-figure-camera.png`" mode="aspectFill" class="camera"></image>
  61. </view>
  62. <view class="label-box flex-between">
  63. <view class="left font28 fw400">
  64. 昵称
  65. </view>
  66. <view class="right flex-center" @click="randNick">
  67. <view class="rand-btn flex-center">
  68. <image :src="`${assetsUrl}info-figure-tou.png`" mode="aspectFill" class="rand"></image>
  69. <view class="rand-text font20 fw400">
  70. 随机昵称
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. <view class="input-box flex-between">
  76. <input type="text" maxlength="10" placeholder="请输入你的昵称" placeholder-style="color:#494667;font-size:28rpx;" class="input fw500 font32" v-model="nickname">
  77. <view class="input-num font22 fw400">
  78. {{nickname.length}}/10
  79. </view>
  80. </view>
  81. <view class="label-box flex-between">
  82. <view class="left font28 fw400">
  83. 个人简介
  84. </view>
  85. <view class="right flex-center">
  86. <view class="input-num font22 fw400">
  87. {{introduce.length}}/200
  88. </view>
  89. </view>
  90. </view>
  91. <view class="textarea-box flex-between">
  92. <textarea maxlength="200" placeholder="可以填写个人介绍、人生经历、交友期望等" placeholder-style="color:#494667;font-size:28rpx;" class="textarea fw500 font32" v-model="introduce"></textarea>
  93. </view>
  94. <view class="label-box flex-between">
  95. <view class="left font28 fw400">
  96. 邀请码<span class="font22">(可不填)</span>
  97. </view>
  98. </view>
  99. <view class="input-box flex-between">
  100. <input type="text" maxlength="6" placeholder="请输入你的邀请码" placeholder-style="color:#494667;font-size:28rpx;" class="input fw500 font32" v-model="code" >
  101. </view>
  102. <view style="height: 200rpx;"></view>
  103. <view class="btn font32 fw600" @click="sure">
  104. {{btnText}}
  105. </view>
  106. </view>
  107. </template>
  108. <script>
  109. import TopBar from '@/components/TopBar/TopBar.vue';
  110. import ImageCropper from "@/components/invinbg-image-cropper/invinbg-image-cropper.vue";
  111. import {getPolicy,computeSignature,getKey} from '@/util/oss.js';
  112. import {encode} from '@/util/base64.js'
  113. export default {
  114. components:{TopBar,ImageCropper},
  115. data() {
  116. return {
  117. assetsUrl:this.$util.assetsUrl,
  118. nickname:'',
  119. introduce:'',
  120. code:'',
  121. icon:'',
  122. btnText:'下一步',
  123. tempFilePath: '',
  124. cropFilePath: '',
  125. };
  126. },
  127. onLoad() {
  128. this.code=uni.getStorageSync('invited')?uni.getStorageSync('invited'):'';
  129. },
  130. methods:{
  131. sure(){
  132. if(this.btnText==='从相册上传'){
  133. uni.chooseImage({
  134. count: 1, //默认9
  135. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  136. sourceType: ['album','camera'], //从相册选择
  137. success: res=>{
  138. this.tempFilePath = res.tempFiles[0].path;
  139. }
  140. });
  141. }
  142. else{
  143. if(this.icon===''){uni.showToast({title:'请上传头像',icon:'none'});return;}
  144. if(this.nickname===''){uni.showToast({title:'请填写昵称',icon:'none'});return;}
  145. if(this.introduce===''){uni.showToast({title:'请填写个人简介',icon:'none'});return;}
  146. uni.showLoading({mask:true});
  147. let user=JSON.parse(uni.getStorageSync('user'));
  148. user.nick=this.nickname;
  149. user.desc=this.introduce;
  150. user.shareCode=this.code;
  151. user.icon=this.icon;
  152. let saveOption={
  153. "completeUser": user,
  154. "weiXinStatusEnum": 'NoWeiXin',
  155. }
  156. uni.showLoading({
  157. title:'保存中',
  158. mask:true
  159. })
  160. this.$api.login.saveFigure(saveOption).then(res=>{
  161. uni.setStorageSync('regStep','SocialData');
  162. uni.setStorageSync('LL_Ukn',res.data.ukn);
  163. uni.setStorageSync('user',JSON.stringify(user));
  164. this.$api.login.editHead({completeUser:user,icon:this.icon}).then(res=>{
  165. uni.hideLoading();
  166. })
  167. uni.reLaunch({
  168. url:`/pages/info/datum`
  169. })
  170. }).catch(err=>{})
  171. }
  172. },
  173. randNick(){
  174. this.$api.login.randNick({}).then(res=>{
  175. this.nickname=res.data.nick;
  176. }).catch(err=>{})
  177. },
  178. confirm(e) {
  179. this.tempFilePath = ''
  180. this.cropFilePath = e.detail.tempFilePath;
  181. this.btnText="下一步";
  182. this.$refs.popup.close();
  183. const that=this;
  184. const policyText=getPolicy();
  185. const policy=encode(JSON.stringify(policyText));
  186. const key=getKey(0,this.cropFilePath.split('.')[1]);
  187. that.$api.public.aliossToken({}).then(resuslt=>{
  188. let formData={
  189. key:key,
  190. policy:policy,
  191. OSSAccessKeyId:resuslt.data.accessKeyId,
  192. signature:computeSignature(resuslt.data.accessKeySecret,policy),
  193. 'x-oss-security-token':resuslt.data.securityToken,
  194. success_action_status:'200'
  195. }
  196. uni.uploadFile({
  197. url: 'https://zhenyanapp-gen.oss-cn-qingdao.aliyuncs.com',
  198. filePath:this.cropFilePath,
  199. name: 'file',
  200. header:{
  201. "Content-Type": "multipart/form-data"
  202. },
  203. formData: formData,
  204. success: (data) => {
  205. if (data.statusCode === 200) {
  206. that.icon=`${that.$store.state.imageCdn}/${key}`;
  207. }
  208. },
  209. fail: err => {
  210. console.log(err);
  211. }
  212. })
  213. })
  214. },
  215. cancel() {
  216. console.log('canceled')
  217. },
  218. showHeadPopup(){
  219. this.btnText="从相册上传";
  220. this.$refs.popup.open();
  221. },
  222. hideHeadPopup(){
  223. this.btnText="下一步";
  224. this.$refs.popup.close();
  225. }
  226. }
  227. }
  228. </script>
  229. <style lang="scss" scoped>
  230. .container{
  231. width: 100vw;
  232. min-height: 100vh;
  233. background-color: $bgcolor1;
  234. .popup{
  235. width: 100vw;
  236. box-sizing: border-box;
  237. padding: 56rpx 60rpx;
  238. background-color: $bgcolor3;
  239. .p-title-box{
  240. .p-title{
  241. color: $fontcolor5;
  242. }
  243. .p-close{
  244. width: 40rpx;
  245. height: 40rpx;
  246. }
  247. }
  248. .p-title-tip{
  249. color: $fontcolor3;
  250. margin-top: 16rpx;
  251. }
  252. .p-img-box{
  253. margin-top: 80rpx;
  254. .p-img{
  255. .img{
  256. width: 200rpx;
  257. height: 200rpx;
  258. }
  259. .p-text{
  260. color: $fontcolor2;
  261. text-align: center;
  262. }
  263. }
  264. }
  265. }
  266. .line-bar{
  267. margin: 0 60rpx;
  268. margin-top: 30rpx;
  269. .span{
  270. width: 120rpx;
  271. height: 8rpx;
  272. border-radius: 4rpx 0rpx 0rpx 4rpx;
  273. background-color: $bgcolor4;
  274. }
  275. .active{
  276. background-color: $primary;
  277. }
  278. }
  279. .title{
  280. color: $fontcolor5;
  281. padding-left: 60rpx;
  282. margin-top: 108rpx;
  283. }
  284. .tip{
  285. color: $fontcolor3;
  286. padding-left: 60rpx;
  287. margin-top: 8rpx;
  288. }
  289. .head-info{
  290. position: relative;
  291. width: 184rpx;
  292. height: 184rpx;
  293. margin: 0 auto;
  294. .head-box{
  295. width: 184rpx;
  296. height: 184rpx;
  297. border-radius: 92rpx;
  298. margin: 0 auto;
  299. margin-top: 88rpx;
  300. overflow: hidden;
  301. .head-inner{
  302. width: 184rpx;
  303. height: 184rpx;
  304. background: linear-gradient(133deg, rgba(250, 92, 116, 1), rgba(188, 85, 191, 1), rgba(138, 79, 255, 1));
  305. .add{
  306. width: 40rpx;
  307. height: 40rpx;
  308. background-color: $bgcolor1;
  309. border-radius: 92rpx;
  310. padding: 68rpx;
  311. }
  312. }
  313. }
  314. .camera{
  315. position: absolute;
  316. right: 0;
  317. bottom: 0;
  318. width: 56rpx;
  319. height: 56rpx;
  320. }
  321. }
  322. .label-box{
  323. margin: 0 60rpx;
  324. margin-top: 56rpx;
  325. .left{
  326. color: $fontcolor3;
  327. }
  328. .right{
  329. .rand-btn{
  330. border-radius: 24rpx;
  331. border: 1rpx solid #7D7DA4;
  332. width: 136rpx;
  333. height: 40rpx;
  334. .rand{
  335. width: 24rpx;
  336. height: 24rpx;
  337. }
  338. .rand-text{
  339. color: $fontcolor2;
  340. margin-left: 10rpx;
  341. }
  342. }
  343. }
  344. }
  345. .input-box{
  346. margin: 0rpx 60rpx;
  347. margin-top: 16rpx;
  348. background-color: $bgcolor3;
  349. border-radius: 16rpx;
  350. height: 112rpx;
  351. padding: 0rpx 32rpx;
  352. .input{
  353. color: $fontcolor5;
  354. }
  355. }
  356. .textarea-box{
  357. border-radius: 16rpx;
  358. margin: 0rpx 60rpx;
  359. margin-top: 16rpx;
  360. background-color: $bgcolor3;
  361. padding: 0rpx 32rpx;
  362. min-height: 200rpx;
  363. .textarea{
  364. color: $fontcolor5;
  365. height: 136rpx;
  366. }
  367. }
  368. .btn{
  369. position: fixed;
  370. z-index: 999;
  371. left: 0;
  372. right: 0;
  373. bottom: 44rpx;
  374. margin: auto;
  375. width: 630rpx;
  376. height: 104rpx;
  377. border-radius: 52rpx;
  378. background-color: $primary;
  379. color: $fontcolor5;
  380. text-align: center;
  381. line-height: 104rpx;
  382. }
  383. }
  384. .input-num{
  385. color: $fontcolor2;
  386. }
  387. </style>