login.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <template>
  2. <view class="normal-login-container">
  3. <view class="avator-logo">
  4. <image src="@/static/images/xijiao/avator.png"></image>
  5. </view>
  6. <view class="logo-content align-center justify-center flex">
  7. <text class="title">欢迎登录</text>
  8. </view>
  9. <view class="login-form-content">
  10. <view class="input-item flex align-center">
  11. <view class="iconfont icon-user icon"></view>
  12. <input v-model="loginForm.username" class="input" type="text" placeholder="请输入账号" maxlength="30" />
  13. </view>
  14. <view class="input-item flex align-center">
  15. <view class="iconfont icon-password icon"></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-red lg round">登录</button>
  27. </view>
  28. <view class="reg text-center" v-if="register">
  29. <text class="text-grey1">没有账号?</text>
  30. <text @click="handleUserRegister" class="text-red">立即注册</text>
  31. </view>
  32. </view>
  33. </view>
  34. </template>
  35. <script>
  36. import { getCodeImg } from '@/api/login'
  37. export default {
  38. data() {
  39. return {
  40. codeUrl: "",
  41. captchaEnabled: true,
  42. // 用户注册开关
  43. register: true,
  44. globalConfig: getApp().globalData.config,
  45. loginForm: {
  46. username: "superadmin",
  47. password: "admin123",
  48. code: "",
  49. uuid: "",
  50. tenantId: '0',
  51. clientId: 'e5cd7e4891bf95d1d19206ce24a7b32e',
  52. grantType: 'password'
  53. }
  54. }
  55. },
  56. created() {
  57. this.getCode()
  58. },
  59. methods: {
  60. // 用户注册
  61. handleUserRegister() {
  62. this.$tab.redirectTo(`/pages/register`)
  63. },
  64. // 隐私协议
  65. handlePrivacy() {
  66. let site = this.globalConfig.appInfo.agreements[0]
  67. this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`)
  68. },
  69. // 用户协议
  70. handleUserAgrement() {
  71. let site = this.globalConfig.appInfo.agreements[1]
  72. this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`)
  73. },
  74. // 获取图形验证码
  75. getCode() {
  76. getCodeImg().then(res => {
  77. this.captchaEnabled = res.data.captchaEnabled === undefined ? true : res.data.captchaEnabled
  78. if (this.captchaEnabled) {
  79. this.codeUrl = 'data:image/gif;base64,' + res.data.img
  80. this.loginForm.uuid = res.data.uuid
  81. }
  82. })
  83. },
  84. // 登录方法
  85. async handleLogin() {
  86. if (this.loginForm.username === "") {
  87. this.$modal.msgError("请输入账号")
  88. } else if (this.loginForm.password === "") {
  89. this.$modal.msgError("请输入密码")
  90. } else if (this.loginForm.code === "" && this.captchaEnabled) {
  91. this.$modal.msgError("请输入验证码")
  92. } else {
  93. this.$modal.loading("登录中,请耐心等待...")
  94. this.pwdLogin()
  95. }
  96. },
  97. // 密码登录
  98. async pwdLogin() {
  99. this.$store.dispatch('Login', this.loginForm).then(() => {
  100. this.$modal.closeLoading()
  101. this.loginSuccess()
  102. }).catch(() => {
  103. if (this.captchaEnabled) {
  104. this.getCode()
  105. }
  106. })
  107. },
  108. // 登录成功后,处理函数
  109. loginSuccess(result) {
  110. this.$tab.reLaunch('/pages/index')
  111. // 设置用户信息
  112. this.$store.dispatch('GetInfo').then(res => {
  113. this.$tab.reLaunch('/pages/index')
  114. })
  115. }
  116. }
  117. }
  118. </script>
  119. <style lang="scss" scoped>
  120. page {
  121. background-color: #ffffff;
  122. }
  123. .normal-login-container {
  124. width: 100%;
  125. .avator-logo {
  126. text-align: center;
  127. padding-top: 5%;
  128. image{
  129. width: 200px;
  130. height: 200px;
  131. }
  132. }
  133. .logo-content {
  134. width: 100%;
  135. font-size: 21px;
  136. text-align: center;
  137. padding-top: 10%;
  138. image {
  139. border-radius: 4px;
  140. }
  141. .title {
  142. margin-left: 10px;
  143. }
  144. }
  145. .login-form-content {
  146. text-align: center;
  147. margin: 20px auto;
  148. margin-top: 15%;
  149. width: 80%;
  150. .input-item {
  151. margin: 20px auto;
  152. background-color: #f5f6f7;
  153. height: 45px;
  154. border-radius: 20px;
  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: 45px;
  171. }
  172. .reg {
  173. margin-top: 15px;
  174. }
  175. .xieyi {
  176. color: #333;
  177. margin-top: 20px;
  178. }
  179. .login-code {
  180. height: 38px;
  181. float: right;
  182. .login-code-img {
  183. height: 38px;
  184. position: absolute;
  185. margin-left: 10px;
  186. width: 200rpx;
  187. }
  188. }
  189. }
  190. }
  191. </style>