login.vue 6.7 KB

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