login.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. <u-verification-code seconds="60" ref="uCode" @change="codeChange"></u-verification-code>
  43. </view>
  44. </template>
  45. <script>
  46. import back from "@/components/back.vue"
  47. export default {
  48. components:{
  49. back
  50. },
  51. data() {
  52. return {
  53. customStyle: {
  54. 'backgroundColor': '#EF9944',
  55. 'color': '#ffffff'
  56. },
  57. codeTips: '',
  58. form:{
  59. phone:'',
  60. code:''
  61. },
  62. rules: {
  63. phone: [{
  64. required: true,
  65. message: '请输入账号',
  66. trigger: ['change', 'blur'],
  67. }],
  68. code: [{
  69. required: true,
  70. message: '请输入验证码',
  71. trigger: ['change', 'blur'],
  72. }],
  73. }
  74. }
  75. },
  76. onReady() {
  77. this.$refs.uForm.setRules(this.rules);
  78. },
  79. methods: {
  80. protocol(){
  81. uni.navigateTo({
  82. url:"/pages/webView/webView?url="+this.$global.protocol
  83. })
  84. },
  85. login() {
  86. this.$refs.uForm.validate(valid => {
  87. if (valid) {
  88. this.$dialog.showLoading('登录中..')
  89. setTimeout(()=>{
  90. this.doLogin()
  91. },500)
  92. }
  93. });
  94. },
  95. async doLogin(){
  96. let params={
  97. type:"SHOP",
  98. phone:this.form.phone,
  99. value:this.form.code,
  100. smsId:this.$cache.get('smsId')
  101. }
  102. let res=await this.$api.accout.phoneLogin(params)
  103. this.cacheToken(res.data)
  104. uni.setStorageSync("phone",this.form.phone)
  105. uni.navigateTo({
  106. url:'/pages/index/index'
  107. })
  108. this.$u.toast('登录成功')
  109. console.log(res);
  110. return
  111. },
  112. cacheToken(data){
  113. let tokenInfo={
  114. accessToken:data.access_token,
  115. //提前200秒过期
  116. expiresIn:new Date().getTime() + (data.expires_in - 200) * 1000,
  117. refreshToken:data.refresh_token,
  118. tenantId:data.tenant_id,
  119. nickName:data.nick_name
  120. }
  121. this.$cache.put('token',data.access_token)
  122. this.$cache.put("tokenInfo",tokenInfo)
  123. },
  124. codeChange(text) {
  125. this.codeTips = text;
  126. },
  127. // 获取验证码
  128. getCode() {
  129. if (this.$isEmpty(this.form.phone)) {
  130. this.$u.toast('请输入手机号')
  131. return
  132. }
  133. if (this.$refs.uCode.canGetCode) {
  134. // 模拟向后端请求验证码
  135. uni.showLoading({
  136. title: '正在获取验证码',
  137. mask: true
  138. })
  139. setTimeout(() => {
  140. let params={
  141. phone:this.form.phone
  142. }
  143. let p=this.$u.queryParams(params)
  144. this.$api.sms.send(p).then(res=>{
  145. if (res.data.success) {
  146. this.$cache.put('smsId',res.data.id)
  147. this.$u.toast('验证码已发送');
  148. // 通知验证码组件内部开始倒计时
  149. }else{
  150. this.$u.toast(res.data);
  151. }
  152. this.$refs.uCode.start();
  153. })
  154. }, 200);
  155. } else {
  156. this.$u.toast('倒计时结束后再发送');
  157. }
  158. },
  159. }
  160. }
  161. </script>
  162. <style>
  163. page{
  164. background-color: #FFFFFF;
  165. }
  166. </style>
  167. <style lang="scss" scoped>
  168. page {
  169. background-color: #FFFFFF;
  170. }
  171. .btn {
  172. background-color: $color;
  173. color: #FFFFFF;
  174. }
  175. .bg {
  176. overflow: hidden;
  177. z-index: 99;
  178. height: 440rpx;
  179. width: 440rpx;
  180. position: absolute;
  181. right: -240rpx;
  182. top: -240rpx;
  183. background-color: #d18c42;
  184. border-radius: 50%;
  185. box-shadow: 0rpx 0rpx 50rpx #c5803b;
  186. }
  187. .bg1 {
  188. overflow: hidden;
  189. height: 500rpx;
  190. width: 500rpx;
  191. position: absolute;
  192. right: -240rpx;
  193. top: -240rpx;
  194. background-color: #d18c42;
  195. border-radius: 50%;
  196. box-shadow: #c6813b;
  197. }
  198. .back {
  199. position: absolute;
  200. top: var(--status-bar-height);
  201. left: 20rpx;
  202. padding-top: var(--status-bar-height);
  203. }
  204. .content {
  205. height: 90vh;
  206. display: flex;
  207. flex-direction: column;
  208. justify-content: center;
  209. align-items: center;
  210. .top {
  211. display: flex;
  212. .logo {
  213. padding-right: 20rpx;
  214. display: flex;
  215. justify-content: center;
  216. align-items: center;
  217. image {
  218. width: 140rpx;
  219. height: 140rpx;
  220. }
  221. }
  222. .title {
  223. margin-right: 20rpx;
  224. display: flex;
  225. flex-direction: column;
  226. justify-content: center;
  227. align-items: flex-start;
  228. text-align: left;
  229. text:first-child {
  230. font-weight: 800;
  231. font-size: 46rpx;
  232. color: #000;
  233. margin-bottom: 20rpx;
  234. }
  235. text:last-child {
  236. font-size: 26rpx;
  237. font-weight: 400;
  238. color: #7f7f7f;
  239. }
  240. }
  241. }
  242. }
  243. </style>