login.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <view class="pages login wrap f-padding">
  3. <view class="top">
  4. <!-- <view class="logo u-text-center">
  5. <image class="login-title" src="../../static/img/login-title.png" mode="aspectFit"></image>
  6. </view> -->
  7. <view class="til">智慧停车</view>
  8. <view class="sub-til">设备巡检系统</view>
  9. </view>
  10. <u-form class="form" :model="form" ref="uForm" :error-type="['toast','toast']">
  11. <u-form-item label="" prop="officerNo" left-icon="account-fill" :left-icon-style="{color:'#fff'}" :border-bottom="false" label-width="120">
  12. <u-input v-model="form.officerNo" placeholder="请输入工号" />
  13. </u-form-item>
  14. <u-form-item label="" prop="loginPwd" left-icon="lock-fill" :left-icon-style="{color:'#fff'}" :border-bottom="false" label-width="120">
  15. <u-input :loginPwd-icon="true" type="loginPwd" v-model="form.loginPwd" placeholder="请输入密码" />
  16. </u-form-item>
  17. <u-button class="submit-btn" type="default" @click="submit" >登录</u-button>
  18. </u-form>
  19. <u-bottom></u-bottom>
  20. </view>
  21. </template>
  22. <script>
  23. // import sha256 from 'crypto-js/sha256';
  24. import crypto from 'utils/crypto.js'
  25. export default {
  26. data() {
  27. return {
  28. form:{
  29. officerNo:'9349',
  30. loginPwd:'000000',
  31. },
  32. rules: {
  33. officerNo: [
  34. {
  35. required: true,
  36. message: '请输入帐号',
  37. // 可以单个或者同时写两个触发验证方式
  38. trigger: ['change','blur'],
  39. }
  40. ],
  41. loginPwd: [
  42. {
  43. required: true,
  44. min: 6,
  45. message: '密码不能少于6个字符',
  46. trigger: 'change'
  47. }
  48. ]
  49. }
  50. }
  51. },
  52. computed: {
  53. },
  54. onReady() {
  55. this.$refs.uForm.setRules(this.rules);
  56. },
  57. methods: {
  58. submit() {
  59. // uni.switchTab({
  60. // url: '../index/index'
  61. // });
  62. this.$refs.uForm.validate(valid => {
  63. if (valid) {
  64. // this.form.loginPwd = crypto.Encrypt(this.form.loginPwd)
  65. this.$u.api.getLogin(this.form).then(res=>{
  66. if(res.code==200){
  67. this.$u.vuex('vuex_user', res.data);
  68. this.jumpIndex();
  69. }else{
  70. uni.showToast({
  71. icon:'none',
  72. title:res.msg
  73. })
  74. }
  75. console.log('res',res);
  76. }).catch(err=>{
  77. console.log('err',err);
  78. })
  79. // console.log('验证通过');
  80. } else {
  81. // console.log('验证失败');
  82. }
  83. });
  84. },
  85. //登录跳转
  86. jumpIndex() {
  87. //#ifdef H5
  88. let ret = localStorage.getItem('backUrl')
  89. if (ret && ret.indexOf('phoneLogin') < 0) {
  90. // 截取url
  91. const pagesIndex = ret.indexOf('pages')
  92. let switchTabList = ['pages/index/index','pages/center/index','pages/maintenanceCenter/maintenanceCenter','pages/warningCenter/warningCenter'];
  93. // debugger
  94. if (pagesIndex > (-1)) {
  95. const pageUrl = ret.slice(pagesIndex)
  96. console.log('switchTabList.includes(pageUrl)',switchTabList.includes(pageUrl));
  97. if(switchTabList.includes(pageUrl)){
  98. setTimeout(() => {
  99. uni.switchTab({
  100. url: '/' + pageUrl
  101. })
  102. }, 100)
  103. }else{
  104. console.log('pageUrl',pageUrl);
  105. setTimeout(() => {
  106. uni.navigateTo({
  107. url: '/' + pageUrl
  108. })
  109. }, 100)
  110. }
  111. } else {
  112. uni.switchTab({
  113. url: '../index/index'
  114. })
  115. }
  116. } else {
  117. uni.switchTab({
  118. url: '../index/index'
  119. })
  120. }
  121. //#endif
  122. //#ifdef APP-PLUS
  123. uni.switchTab({
  124. url: '../index/index'
  125. })
  126. //#endif
  127. },
  128. }
  129. };
  130. </script>
  131. <style lang="scss" scoped>
  132. .pages{
  133. position: relative;
  134. background: linear-gradient(99deg, #7A4398 0%, #5A5DB9 100%);
  135. background-size: 100% auto;
  136. min-height: 100vh;
  137. }
  138. .top{
  139. text-align: center;
  140. font-size: 70rpx;
  141. color: #fff;
  142. line-height: 98rpx;
  143. font-weight: 800;
  144. padding: 180rpx 0 68rpx;
  145. .til{
  146. }
  147. .sub-til{
  148. letter-spacing: 20rpx;
  149. }
  150. }
  151. .wrap {
  152. background-color: transparent;
  153. .login-title{
  154. height: 133rpx;
  155. }
  156. .form{
  157. padding: 0 30rpx;
  158. .u-form-item{
  159. background: rgba(255,255,255,.2);
  160. border-radius: 5px;
  161. border: none;
  162. margin-bottom: 30rpx;
  163. padding-left: 25rpx;
  164. padding-right: 25rpx;
  165. font-size: 36rpx;
  166. /deep/ .uni-input-input{
  167. color: #fff;
  168. }
  169. }
  170. .submit-btn{
  171. margin-top: 45rpx;
  172. background: transparent;
  173. color: #fff;
  174. border-color: rgba(255,255,255,.4);
  175. }
  176. }
  177. }
  178. </style>