平安校园
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

login.vue 4.7 KiB

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