login.vue 4.0 KB

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