login.vue 5.4 KB

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