login.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <template>
  2. <view style="position: relative;">
  3. <!-- <view class="bg"></view>
  4. <view class="bg1"></view> -->
  5. <view class="back" @click="$back">
  6. <u-icon name="arrow-left" size="50" color="#919191"></u-icon>
  7. </view>
  8. <view class="content">
  9. <view class="top">
  10. <view class="logo">
  11. <image src="@/static/icon/logo.png" mode=""></image>
  12. </view>
  13. <view class="title">
  14. <text>欢迎进入联兑通</text>
  15. <text>输入手机号快捷登录</text>
  16. </view>
  17. </view>
  18. <view style="width: 76%;margin-top: 80rpx;">
  19. <u-form ref="uForm" label-width="150" :model="form" label-position="top" :error-type="['message']">
  20. <u-form-item label="手机号" prop="phone"
  21. label-width="150">
  22. <u-input :border="false" placeholder="请输入手机号" v-model="form.phone" type="number"></u-input>
  23. </u-form-item>
  24. <u-form-item label="验证码" prop="code" >
  25. <u-input style="width: 100%;" :border="false" placeholder="请输入验证码" v-model="form.code"
  26. type="text"></u-input>
  27. <u-button shape="circle" slot="right" :custom-style="customStyle" size="mini"
  28. @click="getCode">{{codeTips}}</u-button>
  29. </u-form-item>
  30. </u-form>
  31. </view>
  32. <view style="width: 86%;margin-top: 80rpx;">
  33. <view @click="login" class="btn cu-btn round" style="width:100%;height: 90rpx;font-size: 34rpx;">
  34. 立即登录
  35. </view>
  36. <!-- <view class="center" style="margin-top: 100rpx;">
  37. <text style="color: #949494;">登录即代表已阅读并同意</text>
  38. <text style="color: #0000ff;">《软件服务协议》</text>
  39. </view> -->
  40. </view>
  41. </view>
  42. <u-verification-code seconds="60" ref="uCode" @change="codeChange"></u-verification-code>
  43. </view>
  44. </template>
  45. <script>
  46. export default {
  47. data() {
  48. return {
  49. customStyle: {
  50. 'backgroundColor': '#d18c42',
  51. 'color': '#ffffff'
  52. },
  53. codeTips: '',
  54. form:{
  55. phone:'',
  56. code:''
  57. },
  58. rules: {
  59. phone: [{
  60. required: true,
  61. message: '请输入账号',
  62. trigger: ['change', 'blur'],
  63. }],
  64. code: [{
  65. required: true,
  66. message: '请输入验证码',
  67. trigger: ['change', 'blur'],
  68. }],
  69. }
  70. }
  71. },
  72. onReady() {
  73. this.$refs.uForm.setRules(this.rules);
  74. },
  75. methods: {
  76. login() {
  77. this.$refs.uForm.validate(valid => {
  78. if (valid) {
  79. this.$dialog.showLoading('登录中..')
  80. setTimeout(()=>{
  81. this.doLogin()
  82. },500)
  83. }
  84. });
  85. },
  86. async doLogin(){
  87. let flag=await this.verifyCode()
  88. if (!flag) {
  89. return
  90. }
  91. let params={
  92. personTel:this.form.phone
  93. }
  94. let res=await this.$api.mall.getListByPhone(params)
  95. if (this.$isEmpty(res.data)){
  96. this.$u.toast('账号或者密码错误!')
  97. return
  98. }else{
  99. this.$cache.put('phone',this.form.phone)
  100. uni.reLaunch({
  101. url:"/pages/index/index"
  102. })
  103. }
  104. uni.hideLoading()
  105. },
  106. codeChange(text) {
  107. this.codeTips = text;
  108. },
  109. async verifyCode(){
  110. let p=this.$u.queryParams(this.form)
  111. let res=await this.$api.sms.validCode(p)
  112. if (res.data == "success") {
  113. return true
  114. }else{
  115. this.$u.toast(res.data)
  116. return false
  117. }
  118. },
  119. // 获取验证码
  120. getCode() {
  121. if (this.$isEmpty(this.form.phone)) {
  122. this.$u.toast('请输入手机号')
  123. return
  124. }
  125. if (this.$refs.uCode.canGetCode) {
  126. // 模拟向后端请求验证码
  127. uni.showLoading({
  128. title: '正在获取验证码',
  129. mask: true
  130. })
  131. setTimeout(() => {
  132. uni.hideLoading();
  133. let params={
  134. phone:this.form.phone
  135. }
  136. let p=this.$u.queryParams(params)
  137. this.$api.sms.send(p).then(res=>{
  138. if (res.data=="success") {
  139. this.$u.toast('验证码已发送');
  140. // 通知验证码组件内部开始倒计时
  141. }else{
  142. this.$u.toast(res.data);
  143. }
  144. this.$refs.uCode.start();
  145. })
  146. }, 2000);
  147. } else {
  148. this.$u.toast('倒计时结束后再发送');
  149. }
  150. },
  151. }
  152. }
  153. </script>
  154. <style>
  155. page{
  156. background-color: #FFFFFF;
  157. }
  158. </style>
  159. <style lang="scss" scoped>
  160. $color:#d18c42;
  161. page {
  162. background-color: #FFFFFF;
  163. }
  164. .btn {
  165. background-color: $color;
  166. color: #FFFFFF;
  167. }
  168. .bg {
  169. z-index: 99;
  170. height: 440rpx;
  171. width: 440rpx;
  172. position: absolute;
  173. right: -240rpx;
  174. top: -240rpx;
  175. background-color: #d18c42;
  176. border-radius: 50%;
  177. box-shadow: 0rpx 0rpx 50rpx #c5803b;
  178. }
  179. .bg1 {
  180. height: 500rpx;
  181. width: 500rpx;
  182. position: absolute;
  183. right: -240rpx;
  184. top: -240rpx;
  185. background-color: #d18c42;
  186. border-radius: 50%;
  187. box-shadow: #c6813b;
  188. }
  189. .back {
  190. position: absolute;
  191. top: var(--status-bar-height);
  192. left: 20rpx;
  193. padding-top: var(--status-bar-height);
  194. }
  195. .content {
  196. height: 90vh;
  197. display: flex;
  198. flex-direction: column;
  199. justify-content: center;
  200. align-items: center;
  201. .top {
  202. display: flex;
  203. .logo {
  204. background-color: $color;
  205. width: 130rpx;
  206. height: 130rpx;
  207. border-radius: 30rpx;
  208. display: flex;
  209. justify-content: center;
  210. align-items: center;
  211. margin-right: 20rpx;
  212. image {
  213. width: 90rpx;
  214. height: 90rpx;
  215. }
  216. }
  217. .title {
  218. margin-right: 20rpx;
  219. display: flex;
  220. flex-direction: column;
  221. justify-content: center;
  222. align-items: flex-start;
  223. text-align: left;
  224. text:first-child {
  225. font-weight: 800;
  226. font-size: 50rpx;
  227. color: #000;
  228. margin-bottom: 20rpx;
  229. }
  230. text:last-child {
  231. font-size: 28rpx;
  232. color: #7f7f7f;
  233. }
  234. }
  235. }
  236. }
  237. </style>