index.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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 } 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. phone:this.phone,
  69. code:this.code,
  70. })
  71. uni.showToast({
  72. title:'登录成功'
  73. })
  74. setTimeout(() => {
  75. uni.redirectTo({
  76. url:'/pages/gallery/index'
  77. })
  78. })
  79. },
  80. bindPhone() {
  81. console.log('绑定成功')
  82. },
  83. codeChange(text) {
  84. this.tips = text;
  85. },
  86. async getCode() {
  87. if (!this.phone) {
  88. uni.showToast({
  89. title: '请先输入手机号',
  90. icon: 'none'
  91. })
  92. return
  93. }
  94. if (!phoneValidate(openFilterPhone(this.phone))) {
  95. uni.showToast({
  96. title: '手机号格式不正确',
  97. icon: 'none'
  98. })
  99. return
  100. }
  101. if (this.$refs.uCode.canGetCode) {
  102. // 模拟向后端请求验证码
  103. uni.showLoading({
  104. title: '正在获取验证码',
  105. icon: 'none'
  106. })
  107. await sendCode({
  108. phone:this.phone
  109. })
  110. uni.hideLoading();
  111. // 这里此提示会被this.start()方法中的提示覆盖
  112. uni.showToast('验证码已发送');
  113. // 通知验证码组件内部开始倒计时
  114. this.$refs.uCode.start();
  115. } else {
  116. console.log('倒计时结束后再发送')
  117. }
  118. },
  119. end() {
  120. this.getCoding = false
  121. },
  122. start() {
  123. this.getCoding = true
  124. }
  125. },
  126. mounted() {
  127. },
  128. }
  129. </script>
  130. <style lang="scss" scoped>
  131. .login {
  132. background-repeat: no-repeat !important;
  133. background-size: 100% auto !important;
  134. width: 100%;
  135. position: absolute;
  136. top: 0;
  137. bottom: 0;
  138. display: flex;
  139. flex-direction: column;
  140. .logo{
  141. padding: 48rpx 0 0 48rpx;
  142. }
  143. .content{
  144. flex-grow: 1;
  145. padding: 58rpx 32rpx 92rpx;
  146. .form{
  147. height: 100%;
  148. background: #fff;
  149. padding: 40rpx 32rpx;
  150. border-radius: 24rpx;
  151. .input-wrapper {
  152. background:#fff;
  153. padding-bottom: 22rpx;
  154. font-size: 36rpx;
  155. margin-bottom: 50rpx;
  156. .label{
  157. font-weight: 500;
  158. font-size: 32rpx;
  159. color: #171717;
  160. margin-bottom: 20rpx;
  161. }
  162. .input-box{
  163. color: #171717;
  164. height: 84rpx;
  165. background: #F3F7FF;
  166. border-radius: 42rpx;
  167. padding: 0 32rpx;
  168. font-size: 28rpx
  169. }
  170. .icon-pad {
  171. padding: 10rpx;
  172. }
  173. }
  174. .btn{
  175. margin-top: 127rpx;
  176. button{
  177. color: #fff;
  178. background: linear-gradient( 140deg, #FF8500 0%, #FFA600 100%);
  179. border-radius: 48rpx;
  180. }
  181. }
  182. }
  183. }
  184. }
  185. </style>