login.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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="password" v-model="form.loginPwd" placeholder="请输入密码" />
  16. </u-form-item>
  17. <view class="remember-pass">
  18. <u-checkbox v-model="rememberPass" shape="circle" active-color="#7A4398">记住密码</u-checkbox>
  19. </view>
  20. <u-button class="submit-btn" type="default" @click="submit" >登录</u-button>
  21. </u-form>
  22. <!-- <u-bottom></u-bottom> -->
  23. </view>
  24. </template>
  25. <script>
  26. // import sha256 from 'crypto-js/sha256';
  27. import crypto from 'utils/crypto.js'
  28. export default {
  29. data() {
  30. return {
  31. form:{
  32. officerNo:'',//9349
  33. loginPwd:'',//000000
  34. },
  35. rules: {
  36. officerNo: [
  37. {
  38. required: true,
  39. message: '请输入帐号',
  40. // 可以单个或者同时写两个触发验证方式
  41. trigger: ['change','blur'],
  42. }
  43. ],
  44. loginPwd: [
  45. {
  46. required: true,
  47. min: 6,
  48. message: '密码不能少于6个字符',
  49. trigger: 'change'
  50. }
  51. ]
  52. },
  53. rememberPass:false,
  54. }
  55. },
  56. computed: {
  57. },
  58. onLoad() {
  59. let that = this;
  60. uni.getStorage({
  61. key: 'session_login_info',
  62. success: function (res) {
  63. let loginInfo = JSON.parse(res.data);
  64. if(loginInfo.officerNo&&loginInfo.loginPwd){
  65. that.form.officerNo = loginInfo.officerNo;
  66. that.form.loginPwd = loginInfo.loginPwd;
  67. }
  68. console.log(loginInfo.officerNo);
  69. console.log(loginInfo.loginPwd);
  70. }
  71. });
  72. },
  73. onReady() {
  74. this.$refs.uForm.setRules(this.rules);
  75. },
  76. methods: {
  77. submit() {
  78. // uni.switchTab({
  79. // url: '../index/index'
  80. // });
  81. this.$refs.uForm.validate(valid => {
  82. if (valid) {
  83. // this.form.password = crypto.Encrypt(this.form.password)
  84. let askParms = Object.assign({}, this.form);
  85. askParms.password = crypto.Encrypt(askParms.password);
  86. this.$u.api.getLogin(askParms).then(res=>{
  87. if(res.code==200){
  88. this.$u.vuex('vuex_user', res.data);
  89. this.jumpIndex();
  90. if(this.rememberPass){
  91. uni.setStorageSync('session_login_info', JSON.stringify(this.form));
  92. }
  93. }else{
  94. uni.showToast({
  95. icon:'none',
  96. title:res.msg
  97. })
  98. }
  99. console.log('res',res);
  100. }).catch(err=>{
  101. console.log('err',err);
  102. })
  103. // console.log('验证通过');
  104. } else {
  105. // console.log('验证失败');
  106. }
  107. });
  108. },
  109. //登录跳转
  110. jumpIndex() {
  111. //#ifdef H5
  112. let ret = localStorage.getItem('backUrl')
  113. if (ret && ret.indexOf('phoneLogin') < 0) {
  114. // 截取url
  115. const pagesIndex = ret.indexOf('pages')
  116. let switchTabList = ['pages/index/index','pages/center/index','pages/maintenanceCenter/maintenanceCenter','pages/warningCenter/warningCenter'];
  117. // debugger
  118. if (pagesIndex > (-1)) {
  119. const pageUrl = ret.slice(pagesIndex)
  120. console.log('switchTabList.includes(pageUrl)',switchTabList.includes(pageUrl));
  121. if(switchTabList.includes(pageUrl)){
  122. setTimeout(() => {
  123. uni.switchTab({
  124. url: '/' + pageUrl
  125. })
  126. }, 100)
  127. }else{
  128. console.log('pageUrl',pageUrl);
  129. setTimeout(() => {
  130. uni.navigateTo({
  131. url: '/' + pageUrl
  132. })
  133. }, 100)
  134. }
  135. } else {
  136. uni.switchTab({
  137. url: '../index/index'
  138. })
  139. }
  140. } else {
  141. uni.switchTab({
  142. url: '../index/index'
  143. })
  144. }
  145. //#endif
  146. //#ifdef APP-PLUS
  147. uni.switchTab({
  148. url: '../index/index'
  149. })
  150. //#endif
  151. },
  152. }
  153. };
  154. </script>
  155. <style lang="scss" scoped>
  156. .pages{
  157. position: relative;
  158. background: linear-gradient(99deg, #7A4398 0%, #5A5DB9 100%);
  159. background-size: 100% auto;
  160. min-height: 100vh;
  161. overflow: hidden;
  162. }
  163. .top{
  164. text-align: center;
  165. font-size: 70rpx;
  166. color: #fff;
  167. line-height: 98rpx;
  168. font-weight: 600;
  169. padding: 0 0 68rpx;
  170. margin-top: 15vh;
  171. .til{
  172. }
  173. .sub-til{
  174. letter-spacing: 20rpx;
  175. }
  176. }
  177. .wrap {
  178. background-color: transparent;
  179. .login-title{
  180. height: 133rpx;
  181. }
  182. .form{
  183. padding: 0 30rpx;
  184. .u-form-item{
  185. background: rgba(255,255,255,.2);
  186. border-radius: 5px;
  187. border: none;
  188. margin-bottom: 30rpx;
  189. padding-left: 25rpx;
  190. padding-right: 25rpx;
  191. font-size: 36rpx;
  192. /deep/ .uni-input-input{
  193. color: #fff;
  194. }
  195. }
  196. .submit-btn{
  197. margin-top: 45rpx;
  198. background: transparent;
  199. color: #fff;
  200. border-color: rgba(255,255,255,.4);
  201. }
  202. }
  203. }
  204. .remember-pass{
  205. text-align: right;
  206. /deep/ .u-checkbox__label{
  207. color: #fff;
  208. }
  209. }
  210. </style>