login.vue 5.1KB

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