平安校园
 
 
 
 
 
 

177 lines
4.2 KiB

  1. <template>
  2. <view style="height: 100%;">
  3. <view class="logoBox">
  4. <image src="/static/image/logo.png" mode="heightFix"></image>
  5. <view class="logoText">
  6. AI监控预警分析平台
  7. </view>
  8. </view>
  9. <view class="loginBox">
  10. <view class="title">
  11. 账号登录
  12. </view>
  13. <u--form labelPosition="left" :model="form" labelWidth="30rpx" :rules="rules" ref="uForm">
  14. <u-form-item prop="account">
  15. <u--input v-model="form.account" border="none" placeholder="请输入账号"
  16. :customStyle="{backgroundColor:'#F5F5F5',height:'98rpx',borderRadius:'20rpx',padding:'0rpx 30rpx'}"></u--input>
  17. </u-form-item>
  18. <u-form-item prop="password">
  19. <u--input v-model="form.password" :type="passType" border="none" placeholder="请输入密码"
  20. :customStyle="{backgroundColor:'#F5F5F5',height:'98rpx',borderRadius:'20rpx',padding:'0rpx 30rpx'}">
  21. <view slot="suffix">
  22. <u-icon v-show="passType=='text'" name="eye" color="#777777" size="38rpx"
  23. @click="passType='password'"></u-icon>
  24. <image v-show="passType=='password'" src="/static/image/eyeclose.png"
  25. style="width: 38rpx;height: 38rpx;margin-top: 12rpx;" @click="passType='text'">
  26. </image>
  27. </view>
  28. </u--input>
  29. </u-form-item>
  30. <u-form-item>
  31. <u-button @click="login" :loading="isLoading" :disabled="isLoading" text="登录" :color="'#2388FF'"
  32. :customStyle="{height:'98rpx',borderRadius:'20rpx',marginTop:'60rpx'}"></u-button>
  33. </u-form-item>
  34. </u--form>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. import {
  40. login,
  41. } from '@/api/user.js'
  42. import smCrypto from '@/utils/smCrypto'
  43. export default {
  44. data() {
  45. return {
  46. form: {
  47. account: '',
  48. password: '',
  49. },
  50. passType: 'password',
  51. isLoading: false,
  52. redirect: '',
  53. rules: {
  54. account: [{
  55. required: true,
  56. message: '请输入账号',
  57. trigger: ['blur', 'change']
  58. }],
  59. password: [{
  60. required: true,
  61. message: '请输入密码',
  62. trigger: ['blur', 'change']
  63. }, {
  64. validator: (rule, value, callback) => {
  65. if (value.length < 6) {
  66. callback(new Error('请输入正确的密码'));
  67. return
  68. }
  69. callback();
  70. },
  71. }]
  72. }
  73. }
  74. },
  75. onLoad(e) {
  76. if (e.redirect) this.redirect = e.redirect
  77. if (process.env.NODE_ENV === 'development') {
  78. this.form.account = 'superAdmin'
  79. this.form.password = '123456'
  80. }
  81. },
  82. methods: {
  83. async login() {
  84. this.$refs.uForm.validate().then(() => {
  85. this.isLoading = true
  86. login({
  87. ...this.form,
  88. password: smCrypto.doSm2Encrypt(this.form.password)
  89. }).then(res => {
  90. this.isLoading = false
  91. if (res.code != 200) return
  92. let data = res.data
  93. this.$store.dispatch('setToken', {
  94. token: data.token
  95. })
  96. this.$store.dispatch('getUserInfo')
  97. this.$store.dispatch('getAllOptions')
  98. this.NAV_TO('/')
  99. }).finally(() => {
  100. this.isLoading = false
  101. })
  102. })
  103. },
  104. getLoginUser() {
  105. return getLoginUser().then(res => {
  106. if (res.code != 200) return
  107. this.$u.vuex('userInfo', res.data)
  108. })
  109. }
  110. },
  111. onReady() {
  112. //如果需要兼容微信小程序,并且校验规则中含有方法等,只能通过setRules方法设置规则。
  113. this.$refs.uForm.setRules(this.rules)
  114. },
  115. }
  116. </script>
  117. <style scoped lang="scss">
  118. body,
  119. uni-page-body {
  120. background-color: #fff;
  121. }
  122. uni-page-body {
  123. background-image: url('/static/image/loginBg.png');
  124. background-position: top;
  125. background-size: 100% auto;
  126. background-repeat: no-repeat;
  127. }
  128. input[type="password"]::-ms-reveal {
  129. display: none !important;
  130. }
  131. .logoBox {
  132. /* #ifdef H5*/
  133. padding-top: 42rpx;
  134. /* #endif */
  135. /* #ifndef H5*/
  136. padding-top: 88rpx;
  137. /* #endif */
  138. text-align: center;
  139. uni-image {
  140. height: 80rpx;
  141. margin-top: 160rpx;
  142. }
  143. .logoText {
  144. font-family: 'Alimama ShuHeiTi';
  145. font-weight: 700;
  146. color: #333;
  147. margin-top: 24rpx;
  148. font-size: 40rpx;
  149. }
  150. }
  151. .loginBox {
  152. border-radius: 40rpx;
  153. background-color: #fff;
  154. height: calc(100% - 880rpx);
  155. margin-top: 46rpx;
  156. padding: 60rpx 60rpx 0 60rpx;
  157. .title {
  158. color: #333;
  159. font-size: 42rpx;
  160. margin-bottom: 30rpx;
  161. // font-weight: 700;
  162. }
  163. /deep/.u-form-item__body {
  164. padding: 15rpx 0;
  165. }
  166. }
  167. </style>