login2.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <template>
  2. <view>
  3. <view class="login-logo">
  4. <u-image width="120rpx" height="120rpx" src="../../static/img/logo.png" border-radius="20"></u-image>
  5. <h3>停车场管理端</h3>
  6. </view>
  7. <view class="login-form">
  8. <u-form :model="form" ref="uForm">
  9. <view class="login-form-row">
  10. <u-icon name="account-fill" color="#b0b8c8" size="40"></u-icon>
  11. <u-line color="#c3c9d3" length="30" direction="col" margin="20rpx"/>
  12. <u-form-item label="" prop="phone" :border-bottom="false">
  13. <u-input v-model="form.phone" placeholder="请输入手机号" type="number" maxlength="11"/>
  14. </u-form-item>
  15. </view>
  16. <view class="login-form-row">
  17. <u-icon name="more-circle-fill" color="#b0b8c8" size="40"></u-icon>
  18. <u-line color="#c3c9d3" length="30" direction="col" margin="20rpx"/>
  19. <u-form-item label="" prop="code" :border-bottom="false">
  20. <u-input v-model="form.code" placeholder="请输入验证码" type="number"/>
  21. </u-form-item>
  22. </view>
  23. <view class="login-code" >
  24. <span @click="getCode" >{{codeTips}}</span>
  25. </view>
  26. </u-form>
  27. <u-verification-code :seconds="sendMsgSecond" ref="uCode" @change="codeChange" @end="end" @start="start" keep-running>
  28. </u-verification-code>
  29. <u-button :disabled="!(form.phone&&form.code)" style="margin-top: 30px;" type="primary" @click="finish">登录</u-button>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. import * as API from '@/apis/login.js'
  35. import app from '@/utils/app.js'
  36. export default {
  37. data() {
  38. return {
  39. form: {
  40. name: '',
  41. intro: '',
  42. phone: '',
  43. code: '',
  44. },
  45. backUrl: "",
  46. message: "",
  47. codeTips: '',
  48. isSendMsgIng: false,
  49. sendMsgSecond: 60 * 2
  50. }
  51. },
  52. onLoad(op) {
  53. //登录过直接进入主页
  54. let settting=app.getSetting();
  55. if(settting&&settting.user_id){
  56. uni.switchTab({
  57. url: '../index/index'
  58. })
  59. }
  60. this.message = op.message;
  61. this.backUrl = op.back;
  62. if (op.phone) {
  63. this.form.phone = op.phone;
  64. }
  65. },
  66. methods: {
  67. codeChange(text) {
  68. this.codeTips = text;
  69. },
  70. //倒计时
  71. end() {
  72. this.sendMsgSecond = 2 * 60;
  73. this.isSendMsgIng = false;
  74. },
  75. finish() {
  76. uni.showLoading({
  77. title: "登录中",
  78. mask: true
  79. })
  80. //登录请求,后台校验验证码
  81. API.checkLogin({
  82. verifyCode: this.form.code,
  83. phoneNum: this.form.phone
  84. }).then((response) => {
  85. uni.hideLoading();
  86. if(!response.success){
  87. uni.showToast({
  88. title: response.msg||' 登录失败',
  89. icon: "none"
  90. })
  91. return;
  92. }
  93. //console.log(response.data);
  94. app.addSetting(response.data);
  95. uni.switchTab({
  96. url: '../index/index'
  97. })
  98. }).catch(error => {
  99. //console.log(error)
  100. uni.hideLoading();
  101. })
  102. },
  103. start() {
  104. let _this=this;
  105. if (!this.isSendMsgIng) {
  106. API.getVerifyCode(this.form.phone).then((response) => {
  107. if(!response.success){
  108. uni.showToast({
  109. title:response.msg||'验证码发送失败',
  110. icon:'error'
  111. });
  112. _this.$refs.uCode.reset();
  113. return;
  114. }
  115. uni.showToast({
  116. title:'验证码已发送'
  117. })
  118. }).catch(error => {
  119. uni.showToast({
  120. title: error,
  121. icon: "none"
  122. })
  123. })
  124. }
  125. },
  126. // 获取验证码
  127. getCode() {
  128. if(!this.$refs.uCode.canGetCode){
  129. uni.showToast({
  130. title: '倒计时结束后再发送',
  131. icon: "none"
  132. })
  133. return
  134. }
  135. var checkPhoneResult = API.checkPhone(this.form.phone);
  136. if (checkPhoneResult !== true) {
  137. uni.showToast({
  138. title: checkPhoneResult,
  139. icon:'none'
  140. })
  141. return;
  142. }
  143. this.$refs.uCode.start();
  144. },
  145. /* query(){
  146. uni.showLoading({
  147. title: "加载中",
  148. mask: true,
  149. })
  150. API.findByOpenId({
  151. openId: this.carhelp.getOpenId(),
  152. }).then((response) => {
  153. this.loginset(response)
  154. }).catch(error => {
  155. uni.hideLoading();
  156. // if (!this.carhelp.getOpenId()) {
  157. // uni.showToast({
  158. // title: "请使用“微信”访问本系统登录"
  159. // })
  160. // return
  161. // }
  162. var time = this.carhelp.get("getvcodetime");
  163. if (time) {
  164. //this.$refs.uCode.start();
  165. var nowtime = new Date().getTime()
  166. var differ = (nowtime - time) / 1000
  167. if (differ < 2 * 60) {
  168. this.sendMsgSecond = 2 * 60 - parseInt(differ)
  169. this.isSendMsgIng = true;
  170. this.$refs.uCode.start();
  171. }
  172. }
  173. })
  174. } */
  175. },
  176. onReady() {
  177. //this.query()
  178. }
  179. }
  180. </script>
  181. <style>
  182. page{
  183. background: url(../../static/img/bgbg.png) no-repeat;
  184. background-size: 100%;
  185. }
  186. </style>
  187. <style lang="scss" scoped>
  188. .login-logo{
  189. display: flex;
  190. flex-direction: column;
  191. align-items: center;
  192. padding-top: 20%;
  193. h3{
  194. margin:15px 0;
  195. }
  196. }
  197. /deep/.u-form-item{
  198. padding: 0;
  199. flex: 1;
  200. }
  201. .login-form{
  202. width: 80%;
  203. margin:50px auto 0;
  204. }
  205. .login-form-row{
  206. height: 80rpx;
  207. border: 1rpx solid #c7d1e2;
  208. background-color: #fff;
  209. border-radius: 20rpx;
  210. display: flex;
  211. align-items: center;
  212. padding: 4rpx 20rpx;
  213. margin-bottom: 30rpx;
  214. }
  215. .login-code{
  216. text-align: right;
  217. span{
  218. color:#005AD9;
  219. }
  220. }
  221. .login-btn{
  222. background-color: #cdd7e8;
  223. border-color:#cdd7e8 ;
  224. color:#fff;
  225. margin-top: 30px;
  226. }
  227. </style>