user_info.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <template>
  2. <view>
  3. <view class="top-back"></view>
  4. <view class="content">
  5. <view class="margin-top" >
  6. <uv-gap height="10" ></uv-gap>
  7. <!-- <p style="font-size: 25px;">个人信息</p> -->
  8. <uv-divider class="head-text" text="个人资料" textSize="26" textColor="#000"></uv-divider>
  9. <uv-gap height="10" ></uv-gap>
  10. <view class="margin-top"><!-- 昵称 -->
  11. <view class="title">昵称</view>
  12. <uv-gap height="10" ></uv-gap>
  13. <view class="flex justify-between">
  14. <input maxlength=20 class="" type="nickname" style="width: 60%;" v-model="user.name"
  15. placeholder-style="color: #cccccc; font-size: 24px; font-weight: 100;" placeholder="请输入昵称"
  16. />
  17. <image src="@/static/img/user.png" style="background-color: #fff;width: 15vw;height: 15vw;margin: 0 30px 5px;"></image>
  18. </view>
  19. </view>
  20. <uv-divider customStyle="margin: 0 0"></uv-divider>
  21. <uv-gap height="20" ></uv-gap>
  22. <view><!-- 性别 -->
  23. <view class="">
  24. <view class="title">性别</view>
  25. <uv-gap height="10" ></uv-gap>
  26. <view class="flex justify-between">
  27. <input placeholder="请选择性别" disabled="disabled" style="width: 60%;" name="input" v-model="gender" placeholder-style="color: #cccccc; font-size: 24px; font-weight: 100;" @click="changegender"></input>
  28. <image @click="confirm({'indexs': [0]})" src="@/static/img/man.png" style="background-color: #fff;width: 15vw;height: 15vw;"></image>
  29. <image @click="confirm({'indexs': [1]})" src="@/static/img/woman.png" style="background-color: #fff;width: 15vw;height: 15vw;"></image>
  30. </view>
  31. </view>
  32. <uv-picker ref="picker" :columns="columns" @confirm="confirm"></uv-picker>
  33. </view>
  34. <uv-divider customStyle="margin: 0 0"></uv-divider>
  35. <uv-gap height="20" ></uv-gap>
  36. <view class="" style="margin-bottom: -20upx;"><!-- 年龄 -->
  37. <view class="title">年龄</view>
  38. <uv-gap height="10" ></uv-gap>
  39. <input maxlength=3 class="weui-input" type="number" v-model="user.age" placeholder-style="color: #cccccc; font-size: 24px; font-weight: 100;" placeholder="请输入年龄" />
  40. </view>
  41. <uv-divider customStyle="margin: 0 0"></uv-divider>
  42. <uv-gap height="10" ></uv-gap>
  43. </view>
  44. <uv-modal width=260 ref="modal" title="请将信息填写完整" @confirm="confirm"></uv-modal>
  45. </view>
  46. <uv-button @click="update()" customStyle="position: fixed; bottom: 40px;width: calc(100vw - 60px);margin: 0 30px" shape="circle" size="large" color="#1678ff">保存</uv-button>
  47. </view>
  48. </template>
  49. <script>
  50. export default {
  51. onLoad() {
  52. this.user.name = uni.getStorageSync("name");
  53. this.$user_api.user_get().then(res => {
  54. this.user = this.$util.removeNullValues(res);
  55. this.gender = this.user.gender === 0 ? '男' : '女';
  56. uni.setStorageSync("name",res.name);
  57. uni.setStorageSync("user",this.user);
  58. });
  59. },
  60. onPullDownRefresh(){
  61. this.user.name = uni.getStorageSync("name");
  62. this.$user_api.user_get().then(res => {
  63. this.user = this.$util.removeNullValues(res);
  64. this.gender = this.user.gender === 0 ? '男' : '女';
  65. uni.setStorageSync("name",res.name);
  66. uni.setStorageSync("user",this.user);
  67. });
  68. setTimeout(() => {uni.stopPullDownRefresh();}, 1000);
  69. },
  70. data() {
  71. return {
  72. user:{
  73. name: '',
  74. gender: '',
  75. age: '',
  76. },
  77. gender: '',
  78. columns: [['男','女']],
  79. request: 1,
  80. }
  81. },
  82. methods: {
  83. // inputBindBlur(){
  84. // this.$content_check.textCheck(this.user.name, this, 'user.name');
  85. // },
  86. changegender() {
  87. this.$refs.picker.open();
  88. },
  89. confirm(e) {
  90. this.user.gender = e['indexs'][0];
  91. this.gender = this.user.gender === 0 ? '男' : '女';
  92. },
  93. async update(){
  94. if(this.user.name.length > 0){
  95. //用户名必须由1到20个字符组成,并且只能包含字母、数字、汉字。
  96. const regex = /^[a-zA-Z0-9\u4e00-\u9fa5]{1,20}$/;
  97. const isValid = regex.test(this.user.name);
  98. if (isValid) {
  99. console.log("用户名有效");
  100. if(this.request){
  101. let user = uni.getStorageSync("user");
  102. if(!this.$util.ObjectEqual(user,this.user)){
  103. let isCheck = await this.$content_check.textCheck(this.user.name, this, 'user.name');
  104. console.log('isCheck: ',isCheck);
  105. if(isCheck !== true) return ;
  106. this.request = 0;
  107. uni.showLoading({title: '加载中...'});
  108. console.log('this.user: ',this.user);
  109. this.$user_api.user_update(this.$util.removeNullValues(this.user))
  110. .then((res) => {
  111. uni.setStorageSync("name",this.user.name);
  112. uni.setStorageSync("user",this.user);
  113. this.request = 1;
  114. uni.hideLoading();
  115. uni.showToast({duration:1000,icon:'success',title: '保存成功 !'});
  116. }).catch((err) => {
  117. this.request = 1;
  118. uni.hideLoading();
  119. uni.showToast({icon:"error",title: '保存失败 !'});
  120. });
  121. }
  122. else{
  123. console.log("信息未改变");
  124. uni.showToast({duration:1500,icon:"error",title: '信息未发生改变'});
  125. }
  126. }
  127. } else {
  128. console.log("用户名无效");
  129. uni.showToast({duration:1500,icon:"none",title: '用户名只能包含字母和数字'});
  130. }
  131. }
  132. else{
  133. uni.showToast({duration:1500,icon:"none",title: '请输入用户名'});
  134. }
  135. }
  136. }
  137. }
  138. </script>
  139. <style>
  140. page {
  141. height: 100vh;
  142. }
  143. .top-back{
  144. height: 30px;
  145. background-color: #1678ff;
  146. color: #fff;
  147. margin-bottom: -40px;
  148. }
  149. .top-back p{
  150. height: 7.5vh;
  151. display: flex; /* 使用flex布局来实现居中 */
  152. justify-content: center; /* 水平居中 */
  153. align-items: center; /* 垂直居中 */
  154. font-size: 20px;
  155. letter-spacing: 10px;
  156. margin-left: 10px;
  157. font-weight: 600;
  158. }
  159. .head-text{
  160. letter-spacing: 5px;
  161. font-weight: 600;
  162. }
  163. .title{
  164. letter-spacing: 2px;
  165. color: #8c92ad;
  166. font-size: 18px;
  167. }
  168. input {
  169. letter-spacing: 1px;
  170. width: 100%;
  171. height: 8vh;
  172. padding-bottom: 5px;
  173. font-size: 24px;
  174. font-weight: 600;
  175. font-weight: 400;
  176. color: #000;
  177. outline: none; /* 移除聚焦时的默认边框 */
  178. }
  179. .content {
  180. padding: 0 35px;
  181. border-radius: 25px;
  182. border: none;
  183. background-color: #ffffff;
  184. }
  185. .content image:active {
  186. transform: translateY(2px) translateX(2px);
  187. }
  188. </style>