login.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <template>
  2. <view class="normal-login-container">
  3. <image src="../static/images/login-bg.png" class="login-bg-img"></image>
  4. <view class="login-form-content">
  5. <view class="flex">
  6. <view class="login-title flex"><image src="../static/images/login-logo.png"></image>长春贞达市政施工管理平台</view>
  7. </view>
  8. <view class="input-item flex align-center" style="margin-top: 80rpx;justify-content: center;">
  9. <!-- <view class="iconfont icon-user icon"></view> -->
  10. <view class=""><image src="../static/images/username.png" style="width: 20px;height: 20px;margin-left:20px;"></image></view>
  11. <input v-model="loginForm.username" class="input" type="text" placeholder="账号" maxlength="30" />
  12. </view>
  13. <view class="input-item flex align-center">
  14. <!-- <view class="iconfont icon-password icon"></view> -->
  15. <view class=""><image src="../static/images/password.png" style="width: 20px;height: 20px;margin-left:20px;"></image></view>
  16. <input v-model="loginForm.password" type="password" class="input" placeholder="密码" maxlength="20" />
  17. </view>
  18. <view class="input-item flex align-center" style="width: 60%;margin: 0px;" v-if="captchaEnabled">
  19. <view class="iconfont icon-code icon"></view>
  20. <input v-model="loginForm.code" type="number" class="input" placeholder="请输入验证码" maxlength="4" />
  21. <view class="login-code">
  22. <image :src="codeUrl" @click="getCode" class="login-code-img"></image>
  23. </view>
  24. </view>
  25. <view class="action-btn">
  26. <button @click="handleLogin" class="login-btn cu-btn block bg-blue lg round">登录</button>
  27. </view>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. import {
  33. getCodeImg
  34. } from '@/api/login'
  35. export default {
  36. data() {
  37. return {
  38. codeUrl: "",
  39. captchaEnabled: true,
  40. // 用户注册开关
  41. register: false,
  42. globalConfig: getApp().globalData.config,
  43. loginForm: {
  44. username: "admin",
  45. password: "admin123",
  46. code: "",
  47. uuid: '',
  48. type: 'app'
  49. }
  50. }
  51. },
  52. created() {
  53. this.getCode()
  54. },
  55. methods: {
  56. // 获取图形验证码
  57. getCode() {
  58. getCodeImg().then(res => {
  59. console.log(res)
  60. this.captchaEnabled = res.data.captchaEnabled === undefined ? true : res.data.captchaEnabled
  61. if (this.captchaEnabled) {
  62. this.codeUrl = 'data:image/gif;base64,' + res.data.img
  63. this.loginForm.uuid = res.data.uuid
  64. }
  65. })
  66. },
  67. // 登录方法
  68. async handleLogin() {
  69. if (this.loginForm.username === "") {
  70. this.$modal.msgError("请输入您的账号")
  71. } else if (this.loginForm.password === "") {
  72. this.$modal.msgError("请输入您的密码")
  73. } else if (this.loginForm.code === "" && this.captchaEnabled) {
  74. this.$modal.msgError("请输入验证码")
  75. } else {
  76. this.$modal.loading("登录中,请耐心等待...")
  77. this.pwdLogin()
  78. }
  79. },
  80. // 密码登录
  81. async pwdLogin() {
  82. this.loginForm.type = 'app'
  83. this.$store.dispatch('Login', this.loginForm).then(() => {
  84. this.$modal.closeLoading()
  85. this.loginSuccess()
  86. }).catch(() => {
  87. if (this.captchaEnabled) {
  88. this.getCode()
  89. }
  90. })
  91. },
  92. // 登录成功后,处理函数
  93. loginSuccess(result) {
  94. // 设置用户信息
  95. this.$store.dispatch('GetInfo').then(res => {
  96. this.$tab.reLaunch('/pages/index')
  97. })
  98. }
  99. }
  100. }
  101. </script>
  102. <style lang="scss">
  103. page {
  104. background-color: #ffffff;
  105. }
  106. .normal-login-container {
  107. width: 100%;
  108. .login-bg-img {
  109. width: 100%;
  110. height: 100vh;
  111. position: absolute;
  112. top: 0;
  113. left: 0;
  114. z-index: -1;
  115. }
  116. .logo-content {
  117. width: 100%;
  118. font-size: 21px;
  119. text-align: center;
  120. padding-top: 15%;
  121. image {
  122. border-radius: 4px;
  123. }
  124. .title {
  125. margin-left: 10px;
  126. }
  127. }
  128. .login-form-content {
  129. text-align: center;
  130. width: 90%;
  131. min-height: 45vh;
  132. background-color: #ffffff;
  133. border-radius: 40rpx;
  134. padding: 5%;
  135. box-shadow: 0 0 10px #a7a7a7;
  136. position: absolute;
  137. bottom: 10vh;
  138. left: 50%;
  139. transform: translateX(-50%);
  140. .login-title{
  141. margin-top: 20px;
  142. font-size: 40rpx;
  143. color: #898989;
  144. image{
  145. width: 70rpx;
  146. height: 53rpx;
  147. margin-right: 20rpx;
  148. }
  149. }
  150. .input-item {
  151. margin: 20px auto;
  152. background-color: #f5f6f7;
  153. height: 96rpx;
  154. border-radius: 50px;
  155. .icon {
  156. font-size: 38rpx;
  157. margin-left: 10px;
  158. color: #999;
  159. }
  160. .input {
  161. width: 100%;
  162. font-size: 14px;
  163. line-height: 20px;
  164. text-align: left;
  165. padding-left: 15px;
  166. }
  167. }
  168. .login-btn {
  169. margin-top: 40px;
  170. height: 96rpx;
  171. background: linear-gradient(105deg, #72C6FF, #79A4F0);
  172. box-shadow: 0rpx 18rpx 24rpx 0rpx rgba(63,143,255,0.23);
  173. border-radius: 48rpx;
  174. color: #f5f6f7;
  175. }
  176. .reg {
  177. margin-top: 15px;
  178. }
  179. .xieyi {
  180. color: #333;
  181. margin-top: 20px;
  182. }
  183. .login-code {
  184. height: 38px;
  185. float: right;
  186. .login-code-img {
  187. height: 38px;
  188. position: absolute;
  189. margin-left: 10px;
  190. width: 200rpx;
  191. }
  192. }
  193. }
  194. }
  195. </style>