login.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. this.$refs.loading.showLoading('登录中..')
  91. setTimeout(()=>{
  92. this.doLogin()
  93. },300)
  94. }
  95. });
  96. },
  97. async doLogin(){
  98. let params={
  99. type:"SHOP",
  100. phone:this.form.phone,
  101. value:this.form.code,
  102. smsId:this.$cache.get('smsId')
  103. }
  104. let res=await this.$api.accout.phoneLogin(params)
  105. this.cacheToken(res.data)
  106. uni.setStorageSync("phone",this.form.phone)
  107. uni.reLaunch({
  108. url:'/pages/index/index'
  109. })
  110. this.$refs.loading.hide()
  111. this.$refs.toast.info('登录成功')
  112. },
  113. cacheToken(data){
  114. let tokenInfo={
  115. accessToken:data.access_token,
  116. //提前200秒过期
  117. expiresIn:new Date().getTime() + (data.expires_in - 200) * 1000,
  118. refreshToken:data.refresh_token,
  119. tenantId:data.tenant_id,
  120. nickName:data.nick_name
  121. }
  122. this.$cache.put('token',data.access_token)
  123. this.$cache.put("tokenInfo",tokenInfo)
  124. },
  125. codeChange(text) {
  126. this.codeTips = text;
  127. },
  128. // 获取验证码
  129. getCode() {
  130. if (this.$isEmpty(this.form.phone)) {
  131. this.$refs.toast.error('请输入手机号')
  132. return
  133. }
  134. if (this.$refs.uCode.canGetCode) {
  135. let params={
  136. phone:this.form.phone
  137. }
  138. let p=this.$u.queryParams(params)
  139. this.$api.sms.send(p).then(res=>{
  140. if (res.data.success) {
  141. this.$cache.put('smsId',res.data.id)
  142. this.$refs.toast.info('验证码已发送')
  143. // 通知验证码组件内部开始倒计时
  144. }else{
  145. this.$u.toast(res.data);
  146. }
  147. this.$refs.uCode.start();
  148. })
  149. } else {
  150. this.$refs.toast.warn('倒计时结束后再发送')
  151. }
  152. },
  153. }
  154. }
  155. </script>
  156. <style>
  157. page{
  158. background-color: #FFFFFF;
  159. }
  160. </style>
  161. <style lang="scss" scoped>
  162. page {
  163. background-color: #FFFFFF;
  164. }
  165. .btn {
  166. background-color: $color;
  167. color: #FFFFFF;
  168. }
  169. .bg {
  170. overflow: hidden;
  171. z-index: 99;
  172. height: 440rpx;
  173. width: 440rpx;
  174. position: absolute;
  175. right: -240rpx;
  176. top: -240rpx;
  177. background-color: #d18c42;
  178. border-radius: 50%;
  179. box-shadow: 0rpx 0rpx 50rpx #c5803b;
  180. }
  181. .bg1 {
  182. overflow: hidden;
  183. height: 500rpx;
  184. width: 500rpx;
  185. position: absolute;
  186. right: -240rpx;
  187. top: -240rpx;
  188. background-color: #d18c42;
  189. border-radius: 50%;
  190. box-shadow: #c6813b;
  191. }
  192. .back {
  193. position: absolute;
  194. top: var(--status-bar-height);
  195. left: 20rpx;
  196. padding-top: var(--status-bar-height);
  197. }
  198. .content {
  199. height: 90vh;
  200. display: flex;
  201. flex-direction: column;
  202. justify-content: center;
  203. align-items: center;
  204. .top {
  205. display: flex;
  206. .logo {
  207. padding-right: 20rpx;
  208. display: flex;
  209. justify-content: center;
  210. align-items: center;
  211. image {
  212. width: 120rpx;
  213. height: 120rpx;
  214. }
  215. }
  216. .title {
  217. margin-right: 20rpx;
  218. display: flex;
  219. flex-direction: column;
  220. justify-content: center;
  221. align-items: flex-start;
  222. text-align: left;
  223. text:first-child {
  224. font-weight: 800;
  225. font-size: 46rpx;
  226. color: #000;
  227. margin-bottom: 20rpx;
  228. }
  229. text:last-child {
  230. font-size: 26rpx;
  231. font-weight: 400;
  232. color: #7f7f7f;
  233. }
  234. }
  235. }
  236. }
  237. </style>