开始

昵称修改

改成Input
image.png

  1. <input type="text" v-model="username" />

image.png

  1. username:'哈哈哈'

文本框内容居右
image.png

  1. /* 右侧文本框 */
  2. .user-set-userinfo-list>view:last-child>input{
  3. text-align: right;
  4. }

image.png
可以输入文字
image.png

性别选择

image.png

image.png

用通用的选择
image.png

  1. <view class="u-f-ac" @tap="changeOne('sex')">
  2. <view>{{sex}}</view>
  3. <view class="icon iconfont icon-bianji1"></view>
  4. </view>

情感
image.png
image.png

  1. <view class="user-set-userinfo-list u-f-ac u-f-jsb">
  2. <view>情感</view>
  3. <view class="u-f-ac" @tap="changeOne('qg')">
  4. <view>{{qg}}</view>
  5. <view class="icon iconfont icon-bianji1"></view>
  6. </view>
  7. </view>

职业
image.png

  1. <view class="user-set-userinfo-list u-f-ac u-f-jsb">
  2. <view>职业</view>
  3. <view class="u-f-ac" @tap="changeOne('job')">
  4. <view>{{job}}</view>
  5. <view class="icon iconfont icon-bianji1"></view>
  6. </view>
  7. </view>

image.png
data内定义这几个属性

  1. data() {
  2. return {
  3. userpic: '../../static/demo/userpic/11.jpg',
  4. username:'哈哈哈',
  5. sex:"不限",
  6. qg:"未婚",
  7. job:"IT"
  8. }
  9. },

image.png

image.png

image.png

  1. let sex=['不限','男','女'];

image.png

image.png

image.png

image.png

image.png

image.png

  1. let qg=['秘密','未婚','已婚'];
  2. let job=['秘密','IT','老师'];

image.png

image.png

image.png

image.png
这里写错了 改过来
image.png

本节代码

  1. <template>
  2. <view class="body">
  3. <view class="user-set-userinfo-list u-f-ac u-f-jsb">
  4. <view>头像</view>
  5. <view class="u-f-ac" @tap="changeimg">
  6. <image :src="userpic" mode="aspectFill" lazy-load="true"></image>
  7. <view class="icon iconfont icon-bianji1"></view>
  8. </view>
  9. </view>
  10. <view class="user-set-userinfo-list u-f-ac u-f-jsb">
  11. <view>昵称</view>
  12. <view class="u-f-ac">
  13. <!-- <view>昵称</view> -->
  14. <input type="text" v-model="username" />
  15. <view class="icon iconfont icon-bianji1"></view>
  16. </view>
  17. </view>
  18. <view class="user-set-userinfo-list u-f-ac u-f-jsb">
  19. <view>性别</view>
  20. <view class="u-f-ac" @tap="changeOne('sex')">
  21. <view>{{sex}}</view>
  22. <view class="icon iconfont icon-bianji1"></view>
  23. </view>
  24. </view>
  25. <view class="user-set-userinfo-list u-f-ac u-f-jsb">
  26. <view>生日</view>
  27. <view class="u-f-ac">
  28. <view>1987-02-07</view>
  29. <view class="icon iconfont icon-bianji1"></view>
  30. </view>
  31. </view>
  32. <view class="user-set-userinfo-list u-f-ac u-f-jsb">
  33. <view>情感</view>
  34. <view class="u-f-ac" @tap="changeOne('qg')">
  35. <view>{{qg}}</view>
  36. <view class="icon iconfont icon-bianji1"></view>
  37. </view>
  38. </view>
  39. <view class="user-set-userinfo-list u-f-ac u-f-jsb">
  40. <view>职业</view>
  41. <view class="u-f-ac" @tap="changeOne('job')">
  42. <view>{{job}}</view>
  43. <view class="icon iconfont icon-bianji1"></view>
  44. </view>
  45. </view>
  46. <view class="user-set-userinfo-list u-f-ac u-f-jsb">
  47. <view>家乡</view>
  48. <view class="u-f-ac">
  49. <view>中国广州</view>
  50. <view class="icon iconfont icon-bianji1"></view>
  51. </view>
  52. </view>
  53. <button class="user-set-btn" :class="{'user-set-btn-disable':disabled}" :loading="loading" @tap="submit"
  54. type="primary" :disabled="disabled">完成</button>
  55. </view>
  56. </template>
  57. <script>
  58. import {
  59. pathToBase64
  60. } from '../../js_sdk/mmmm-image-tools/index.js'
  61. let sex=['不限','男','女'];
  62. let qg=['秘密','未婚','已婚'];
  63. let job=['秘密','IT','老师'];
  64. export default {
  65. data() {
  66. return {
  67. userpic: '../../static/demo/userpic/11.jpg',
  68. username:'哈哈哈',
  69. sex:"不限",
  70. qg:"未婚",
  71. job:"IT"
  72. }
  73. },
  74. methods: {
  75. changeOne(val){
  76. let arr=[];
  77. switch(val){
  78. case 'sex':
  79. arr=sex;
  80. break;
  81. case 'qg':
  82. arr=qg;
  83. break;
  84. case 'job':
  85. arr=job;
  86. break;
  87. }
  88. uni.showActionSheet({
  89. itemList:arr,
  90. success: res => {
  91. switch(val){
  92. case 'sex':
  93. this.sex=arr[res.tapIndex];
  94. break;
  95. case 'qg':
  96. this.qg=arr[res.tapIndex];
  97. break;
  98. case 'job':
  99. this.job=arr[res.tapIndex];
  100. break;
  101. }
  102. console.log(res);
  103. }
  104. })
  105. },
  106. // 修改头像
  107. changeimg() {
  108. uni.chooseImage({
  109. count: 1, //默认9
  110. sizeType: ['compressed'], //可以指定是原图还是压缩图,默认二者都有
  111. // sourceType: ['album'], //从相册选择
  112. success: function(res) {
  113. console.log(JSON.stringify(res));
  114. // this.userpic=res.tempFilePaths;
  115. //解决跨越问题,让通过微信上传的图片你能够展示在浏览器前端
  116. uni.getImageInfo({
  117. src: res.tempFilePaths[0],
  118. success: (path) => {
  119. pathToBase64(path.path).then(base64 => {
  120. // console.log(base64); // 这就是转为base64格式的图片
  121. console.log('base64赋值');
  122. this.userpic=base64;
  123. })
  124. .catch(error => {
  125. console.error(error)
  126. })
  127. }
  128. });
  129. }
  130. });;
  131. },
  132. submit(){
  133. }
  134. }
  135. }
  136. </script>
  137. <style>
  138. @import url('@/common/form.css');
  139. .user-set-userinfo-list {
  140. padding: 20upx;
  141. border-bottom: 1upx solid #F4F4F4;
  142. }
  143. /* 左侧的文字 */
  144. .user-set-userinfo-list>view:first-child {
  145. font-size: 32upx;
  146. font-weight: bold;
  147. color: #9B9B9B;
  148. }
  149. /* 右侧头像 */
  150. .user-set-userinfo-list>view:last-child>image {
  151. width: 80upx;
  152. height: 80upx;
  153. border-radius: 100%;
  154. }
  155. /* 右侧文本框 */
  156. .user-set-userinfo-list>view:last-child>input{
  157. text-align: right;
  158. }
  159. /* 最右侧的修改的铅笔图标 */
  160. .user-set-userinfo-list>view:last-child>view:last-of-type {
  161. margin-left: 20upx;
  162. color: #9B9B9B;
  163. }
  164. </style>

结束