figure.vue 11 KB

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