index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <template>
  2. <view class="login" :style="{background:'url('+ bannerImage +')'}">
  3. <view><nav-bar title="none" icon="none" background="transparent" border-color="transparent" ></nav-bar></view>
  4. <view class="logo"><re-image imgSrc="/retail/login/img_logo_login.png" width="442" height="130"></re-image></view>
  5. <view class="content">
  6. <view class="form">
  7. <view class="input-wrapper">
  8. <view class="label">手机号码</view>
  9. <view class="input-box flex aic"><u-input maxlength="11" v-model="phone" fontSize="32rpx"
  10. border="none" type="text" placeholder="请输入手机号" ></u-input></view>
  11. </view>
  12. <view class="input-wrapper">
  13. <view class="label">验证码</view>
  14. <view class="input-box flex aic">
  15. <u-input maxlength="6" v-model="code" fontSize="30rpx" border="none" type="text" placeholder="请输入验证码"></u-input>
  16. <u-code change-text="重新获取(Xs)" startText="获取验证码" endText="重新获取" @end="end" @start="start" ref="uCode"
  17. @change="codeChange"></u-code>
  18. <view :class="{'getting': getCoding}" class="get-code-btn" @tap="getCode">{{tips}}</view>
  19. </view>
  20. </view>
  21. <view class="btn">
  22. <u-button @click="toLogin()">登录</u-button>
  23. </view>
  24. </view>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. import { toRpx } from '@/utils/calculate.js'
  30. import defaultConfig from '@/config/default.js'
  31. import { navigateTo,phoneValidate,filterPhone,openFilterPhone } from '@/utils/utils.js'
  32. import { login,sendCode,getUserInfo } from '@/apis/user'
  33. export default {
  34. components: {},
  35. computed: {
  36. statusBarHeight() {
  37. return this.$store.state.info.systemInfo?.statusBarHeight
  38. },
  39. },
  40. data() {
  41. return {
  42. bannerImage: defaultConfig.ossImgUrl + '/retail/login/login-bg.png',
  43. navBarHeight: uni.getStorageSync('navBarHeight'),
  44. phone:'',
  45. code:'',
  46. tips:'',
  47. getCoding: false,
  48. wxopenId:uni.getStorageSync('wxOpenId')
  49. }
  50. },
  51. onLoad() {
  52. },
  53. computed:{
  54. canClick() {
  55. return this.phone.length && this.code.length
  56. },
  57. ftPhone() {
  58. return (v) => {
  59. return filterPhone(v)
  60. }
  61. }
  62. },
  63. methods: {
  64. // 登录
  65. async toLogin(){
  66. const res = await login({
  67. channel:1,
  68. username:this.phone,
  69. code:this.code,
  70. })
  71. const { accessToken,username } = res
  72. uni.setStorageSync('accessToken', accessToken)
  73. uni.setStorageSync('username', username)
  74. const userInfo = await getUserInfo()
  75. uni.setStorageSync('userInfo',userInfo)
  76. uni.setStorageSync('avatar',userInfo.avatar)
  77. uni.showToast({
  78. title: '登录成功'
  79. });
  80. uni.reLaunch({
  81. url:'/pages/gallery/index'
  82. })
  83. },
  84. bindPhone() {
  85. console.log('绑定成功')
  86. },
  87. codeChange(text) {
  88. this.tips = text;
  89. },
  90. async getCode() {
  91. if (!this.phone) {
  92. uni.showToast({
  93. title: '请先输入手机号',
  94. icon: 'none'
  95. })
  96. return
  97. }
  98. if (!phoneValidate(openFilterPhone(this.phone))) {
  99. uni.showToast({
  100. title: '手机号格式不正确',
  101. icon: 'none'
  102. })
  103. return
  104. }
  105. if (this.$refs.uCode.canGetCode) {
  106. // 模拟向后端请求验证码
  107. uni.showLoading({
  108. title: '正在获取验证码',
  109. icon: 'none'
  110. })
  111. await sendCode({
  112. phone:this.phone
  113. })
  114. uni.hideLoading();
  115. // 这里此提示会被this.start()方法中的提示覆盖
  116. uni.showToast({
  117. title: '验证码已发送'
  118. });
  119. // 通知验证码组件内部开始倒计时
  120. this.$refs.uCode.start();
  121. } else {
  122. console.log('倒计时结束后再发送')
  123. }
  124. },
  125. end() {
  126. this.getCoding = false
  127. },
  128. start() {
  129. this.getCoding = true
  130. }
  131. },
  132. mounted() {
  133. },
  134. }
  135. </script>
  136. <style lang="scss" scoped>
  137. .login {
  138. background-repeat: no-repeat !important;
  139. background-size: 100% auto !important;
  140. width: 100%;
  141. position: absolute;
  142. top: 0;
  143. bottom: 0;
  144. display: flex;
  145. flex-direction: column;
  146. .logo{
  147. padding: 48rpx 0 0 48rpx;
  148. }
  149. .content{
  150. flex-grow: 1;
  151. padding: 58rpx 32rpx 92rpx;
  152. .form{
  153. height: 100%;
  154. background: #fff;
  155. padding: 40rpx 32rpx;
  156. border-radius: 24rpx;
  157. .input-wrapper {
  158. background:#fff;
  159. padding-bottom: 22rpx;
  160. font-size: 36rpx;
  161. margin-bottom: 50rpx;
  162. .label{
  163. font-weight: 500;
  164. font-size: 32rpx;
  165. color: #171717;
  166. margin-bottom: 20rpx;
  167. }
  168. .input-box{
  169. color: #171717;
  170. height: 84rpx;
  171. background: #F3F7FF;
  172. border-radius: 42rpx;
  173. padding: 0 32rpx;
  174. font-size: 28rpx
  175. }
  176. .icon-pad {
  177. padding: 10rpx;
  178. }
  179. }
  180. .btn{
  181. margin-top: 127rpx;
  182. button{
  183. color: #fff;
  184. background: linear-gradient( 140deg, #FF8500 0%, #FFA600 100%);
  185. border-radius: 48rpx;
  186. }
  187. }
  188. }
  189. }
  190. }
  191. </style>