login.vue 6.3 KB

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