login.vue 5.0 KB

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