login.vue 5.6 KB

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