login.vue 5.0 KB

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