login.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <template>
  2. <view style="position: relative;">
  3. <!-- <view class="bg"></view>
  4. <view class="bg1"></view> -->
  5. <back></back>
  6. <view class="content">
  7. <view class="top">
  8. <view class="logo">
  9. <image src="@/static/icon/logo2.png" mode=""></image>
  10. </view>
  11. <view class="title">
  12. <text>欢迎进入联兑通</text>
  13. <text>输入手机号快捷登录</text>
  14. </view>
  15. </view>
  16. <view style="width: 76%;margin-top: 80rpx;">
  17. <u-form ref="uForm" label-width="150" :model="form" label-position="top" :error-type="['message']">
  18. <u-form-item label="手机号" prop="phone"
  19. label-width="150">
  20. <u-input :border="false" placeholder="请输入手机号" v-model="form.phone" type="number"></u-input>
  21. </u-form-item>
  22. <u-form-item label="验证码" prop="code" >
  23. <view class="flex" >
  24. <u-input style="width: 100%;" :border="false" placeholder="请输入验证码" v-model="form.code"
  25. type="text"></u-input>
  26. <u-button shape="circle" slot="right" :custom-style="customStyle" size="mini"
  27. @click="getCode">{{codeTips}}</u-button>
  28. </view>
  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;" @click="protocol">《软件服务协议》</text>
  39. </view> -->
  40. </view>
  41. </view>
  42. <toast ref="toast" ></toast>
  43. <loading ref="loading" type="3"/>
  44. <u-verification-code seconds="60" ref="uCode" @change="codeChange"></u-verification-code>
  45. </view>
  46. </template>
  47. <script>
  48. import back from "@/components/back.vue"
  49. export default {
  50. components:{
  51. back
  52. },
  53. data() {
  54. return {
  55. customStyle: {
  56. 'backgroundColor': '#EF9944',
  57. 'color': '#ffffff'
  58. },
  59. codeTips: '',
  60. form:{
  61. phone:'',
  62. code:''
  63. },
  64. rules: {
  65. phone: [{
  66. required: true,
  67. message: '请输入手机号',
  68. trigger: ['change', 'blur'],
  69. }],
  70. code: [{
  71. required: true,
  72. message: '请输入验证码',
  73. trigger: ['change', 'blur'],
  74. }],
  75. }
  76. }
  77. },
  78. onReady() {
  79. this.$refs.uForm.setRules(this.rules);
  80. },
  81. methods: {
  82. protocol(){
  83. uni.navigateTo({
  84. url:"/pages/webView/webView?url="+this.$global.protocol
  85. })
  86. },
  87. login() {
  88. this.$refs.uForm.validate(valid => {
  89. if (valid) {
  90. setTimeout(()=>{
  91. this.doLogin()
  92. },300)
  93. }
  94. });
  95. },
  96. async doLogin(){
  97. let params={
  98. type:"SHOP",
  99. phone:this.form.phone,
  100. value:this.form.code,
  101. smsId:this.$cache.get('smsId')
  102. }
  103. let res=await this.$api.accout.phoneLogin(params)
  104. this.cacheToken(res.data)
  105. uni.setStorageSync("phone",this.form.phone)
  106. uni.reLaunch({
  107. url:'/pages/index/index'
  108. })
  109. this.$refs.toast.info('登录成功')
  110. },
  111. cacheToken(data){
  112. let tokenInfo={
  113. accessToken:data.access_token,
  114. //提前200秒过期
  115. expiresIn:new Date().getTime() + (data.expires_in - 200) * 1000,
  116. refreshToken:data.refresh_token,
  117. tenantId:data.tenant_id,
  118. nickName:data.nick_name
  119. }
  120. this.$cache.put('token',data.access_token)
  121. this.$cache.put("tokenInfo",tokenInfo)
  122. },
  123. codeChange(text) {
  124. this.codeTips = text;
  125. },
  126. // 获取验证码
  127. getCode() {
  128. if (this.$isEmpty(this.form.phone)) {
  129. this.$refs.toast.error('请输入手机号')
  130. return
  131. }
  132. if (this.$refs.uCode.canGetCode) {
  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.$cache.put('smsId',res.data.id)
  140. this.$refs.toast.info('验证码已发送')
  141. // 通知验证码组件内部开始倒计时
  142. }else{
  143. this.$u.toast(res.data);
  144. }
  145. this.$refs.uCode.start();
  146. })
  147. } else {
  148. this.$refs.toast.warn('倒计时结束后再发送')
  149. }
  150. },
  151. }
  152. }
  153. </script>
  154. <style>
  155. page{
  156. background-color: #FFFFFF;
  157. }
  158. </style>
  159. <style lang="scss" scoped>
  160. page {
  161. background-color: #FFFFFF;
  162. }
  163. .btn {
  164. background-color: $color;
  165. color: #FFFFFF;
  166. }
  167. .bg {
  168. overflow: hidden;
  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. overflow: hidden;
  181. height: 500rpx;
  182. width: 500rpx;
  183. position: absolute;
  184. right: -240rpx;
  185. top: -240rpx;
  186. background-color: #d18c42;
  187. border-radius: 50%;
  188. box-shadow: #c6813b;
  189. }
  190. .back {
  191. position: absolute;
  192. top: var(--status-bar-height);
  193. left: 20rpx;
  194. padding-top: var(--status-bar-height);
  195. }
  196. .content {
  197. height: 90vh;
  198. display: flex;
  199. flex-direction: column;
  200. justify-content: center;
  201. align-items: center;
  202. .top {
  203. display: flex;
  204. .logo {
  205. padding-right: 20rpx;
  206. display: flex;
  207. justify-content: center;
  208. align-items: center;
  209. image {
  210. width: 120rpx;
  211. height: 120rpx;
  212. }
  213. }
  214. .title {
  215. margin-right: 20rpx;
  216. display: flex;
  217. flex-direction: column;
  218. justify-content: center;
  219. align-items: flex-start;
  220. text-align: left;
  221. text:first-child {
  222. font-weight: 800;
  223. font-size: 46rpx;
  224. color: #000;
  225. margin-bottom: 20rpx;
  226. }
  227. text:last-child {
  228. font-size: 26rpx;
  229. font-weight: 400;
  230. color: #7f7f7f;
  231. }
  232. }
  233. }
  234. }
  235. </style>