login.vue 5.7 KB

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