figure.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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. methods:{
  128. sure(){
  129. if(this.btnText==='从相册上传'){
  130. uni.chooseImage({
  131. count: 1, //默认9
  132. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  133. sourceType: ['album','camera'], //从相册选择
  134. success: res=>{
  135. this.tempFilePath = res.tempFiles[0].path;
  136. }
  137. });
  138. }
  139. else{
  140. if(this.icon===''){uni.showToast({title:'请上传头像',icon:'none'});return;}
  141. if(this.nickname===''){uni.showToast({title:'请填写昵称',icon:'none'});return;}
  142. if(this.introduce===''){uni.showToast({title:'请填写个人简介',icon:'none'});return;}
  143. uni.showLoading({mask:true});
  144. let user=JSON.parse(uni.getStorageSync('user'));
  145. user.nick=this.nickname;
  146. user.desc=this.introduce;
  147. user.shareCode=this.code;
  148. user.icon=this.icon;
  149. let saveOption={
  150. "completeUser": user,
  151. "weiXinStatusEnum": 'NoWeiXin',
  152. }
  153. uni.showLoading({
  154. title:'保存中',
  155. mask:true
  156. })
  157. this.$api.login.saveFigure(saveOption).then(res=>{
  158. uni.setStorageSync('regStep','SocialData');
  159. uni.setStorageSync('LL_Ukn',res.data.ukn);
  160. uni.setStorageSync('user',JSON.stringify(user));
  161. this.$api.login.editHead({completeUser:user,icon:this.icon}).then(res=>{
  162. uni.hideLoading();
  163. })
  164. uni.reLaunch({
  165. url:`/pages/info/datum`
  166. })
  167. }).catch(err=>{})
  168. }
  169. },
  170. randNick(){
  171. this.$api.login.randNick({}).then(res=>{
  172. this.nickname=res.data.nick;
  173. }).catch(err=>{})
  174. },
  175. confirm(e) {
  176. this.tempFilePath = ''
  177. this.cropFilePath = e.detail.tempFilePath;
  178. this.btnText="下一步";
  179. this.$refs.popup.close();
  180. const that=this;
  181. const policyText=getPolicy();
  182. const policy=encode(JSON.stringify(policyText));
  183. const key=getKey(0,this.cropFilePath.split('.')[1]);
  184. that.$api.public.aliossToken({}).then(resuslt=>{
  185. let formData={
  186. key:key,
  187. policy:policy,
  188. OSSAccessKeyId:resuslt.data.accessKeyId,
  189. signature:computeSignature(resuslt.data.accessKeySecret,policy),
  190. 'x-oss-security-token':resuslt.data.securityToken,
  191. success_action_status:'200'
  192. }
  193. uni.uploadFile({
  194. url: 'https://zhenyanapp-gen.oss-cn-qingdao.aliyuncs.com',
  195. filePath:this.cropFilePath,
  196. name: 'file',
  197. header:{
  198. "Content-Type": "multipart/form-data"
  199. },
  200. formData: formData,
  201. success: (data) => {
  202. if (data.statusCode === 200) {
  203. that.icon=`${that.$store.state.imageCdn}/${key}`;
  204. }
  205. },
  206. fail: err => {
  207. console.log(err);
  208. }
  209. })
  210. })
  211. },
  212. cancel() {
  213. console.log('canceled')
  214. },
  215. showHeadPopup(){
  216. this.btnText="从相册上传";
  217. this.$refs.popup.open();
  218. },
  219. hideHeadPopup(){
  220. this.btnText="下一步";
  221. this.$refs.popup.close();
  222. }
  223. }
  224. }
  225. </script>
  226. <style lang="scss" scoped>
  227. .container{
  228. width: 100vw;
  229. min-height: 100vh;
  230. background-color: $bgcolor1;
  231. .popup{
  232. width: 100vw;
  233. box-sizing: border-box;
  234. padding: 56rpx 60rpx;
  235. background-color: $bgcolor3;
  236. .p-title-box{
  237. .p-title{
  238. color: $fontcolor5;
  239. }
  240. .p-close{
  241. width: 40rpx;
  242. height: 40rpx;
  243. }
  244. }
  245. .p-title-tip{
  246. color: $fontcolor3;
  247. margin-top: 16rpx;
  248. }
  249. .p-img-box{
  250. margin-top: 80rpx;
  251. .p-img{
  252. .img{
  253. width: 200rpx;
  254. height: 200rpx;
  255. }
  256. .p-text{
  257. color: $fontcolor2;
  258. text-align: center;
  259. }
  260. }
  261. }
  262. }
  263. .line-bar{
  264. margin: 0 60rpx;
  265. margin-top: 30rpx;
  266. .span{
  267. width: 120rpx;
  268. height: 8rpx;
  269. border-radius: 4rpx 0rpx 0rpx 4rpx;
  270. background-color: $bgcolor4;
  271. }
  272. .active{
  273. background-color: $primary;
  274. }
  275. }
  276. .title{
  277. color: $fontcolor5;
  278. padding-left: 60rpx;
  279. margin-top: 108rpx;
  280. }
  281. .tip{
  282. color: $fontcolor3;
  283. padding-left: 60rpx;
  284. margin-top: 8rpx;
  285. }
  286. .head-info{
  287. position: relative;
  288. width: 184rpx;
  289. height: 184rpx;
  290. margin: 0 auto;
  291. .head-box{
  292. width: 184rpx;
  293. height: 184rpx;
  294. border-radius: 92rpx;
  295. margin: 0 auto;
  296. margin-top: 88rpx;
  297. overflow: hidden;
  298. .head-inner{
  299. width: 184rpx;
  300. height: 184rpx;
  301. background: linear-gradient(133deg, rgba(250, 92, 116, 1), rgba(188, 85, 191, 1), rgba(138, 79, 255, 1));
  302. .add{
  303. width: 40rpx;
  304. height: 40rpx;
  305. background-color: $bgcolor1;
  306. border-radius: 92rpx;
  307. padding: 68rpx;
  308. }
  309. }
  310. }
  311. .camera{
  312. position: absolute;
  313. right: 0;
  314. bottom: 0;
  315. width: 56rpx;
  316. height: 56rpx;
  317. }
  318. }
  319. .label-box{
  320. margin: 0 60rpx;
  321. margin-top: 56rpx;
  322. .left{
  323. color: $fontcolor3;
  324. }
  325. .right{
  326. .rand-btn{
  327. border-radius: 24rpx;
  328. border: 1rpx solid #7D7DA4;
  329. width: 136rpx;
  330. height: 40rpx;
  331. .rand{
  332. width: 24rpx;
  333. height: 24rpx;
  334. }
  335. .rand-text{
  336. color: $fontcolor2;
  337. margin-left: 10rpx;
  338. }
  339. }
  340. }
  341. }
  342. .input-box{
  343. margin: 0rpx 60rpx;
  344. margin-top: 16rpx;
  345. background-color: $bgcolor3;
  346. border-radius: 16rpx;
  347. height: 112rpx;
  348. padding: 0rpx 32rpx;
  349. .input{
  350. color: $fontcolor5;
  351. }
  352. }
  353. .textarea-box{
  354. border-radius: 16rpx;
  355. margin: 0rpx 60rpx;
  356. margin-top: 16rpx;
  357. background-color: $bgcolor3;
  358. padding: 0rpx 32rpx;
  359. min-height: 200rpx;
  360. .textarea{
  361. color: $fontcolor5;
  362. height: 136rpx;
  363. }
  364. }
  365. .btn{
  366. position: fixed;
  367. z-index: 999;
  368. left: 0;
  369. right: 0;
  370. bottom: 44rpx;
  371. margin: auto;
  372. width: 630rpx;
  373. height: 104rpx;
  374. border-radius: 52rpx;
  375. background-color: $primary;
  376. color: $fontcolor5;
  377. text-align: center;
  378. line-height: 104rpx;
  379. }
  380. }
  381. .input-num{
  382. color: $fontcolor2;
  383. }
  384. </style>