login.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. <!-- 手机号或者微信登录 -->
  29. <view class="login-form-content">
  30. <view class="input-item flex align-center">
  31. <view class="iconfont icon-user icon"></view>
  32. <input v-model="loginForm.phone" class="input" type="text" placeholder="请输入手机号码" maxlength="11" />
  33. </view>
  34. <view style="display: flex;flex-wrap: nowrap;margin-top: -40rpx;" class="align-center">
  35. <view class="input-item align-center" style="display: flex;flex-wrap: nowrap;width: 60%;">
  36. <view class="iconfont icon-code icon"></view>
  37. <input v-model="loginForm.code" type="password" class="input" placeholder="请输入验证码" maxlength="6" />
  38. </view>
  39. <view style="width: 35%;margin-left: 5%;" class="yanz_code">
  40. 验证码
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. import Verify from "@/components/verifition/Verify"
  48. export default {
  49. name: 'Login',
  50. components: {
  51. Verify
  52. },
  53. data() {
  54. return {
  55. captchaEnabled: true, // 验证码开关 TODO 芋艿:需要抽到配置里
  56. globalConfig: getApp().globalData.config,
  57. loginForm: {
  58. username: "admin",
  59. password: "admin123",
  60. captchaVerification: ""
  61. }
  62. }
  63. },
  64. methods: {
  65. // 隐私协议
  66. handlePrivacy() {
  67. let site = this.globalConfig.appInfo.agreements[0]
  68. this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`)
  69. },
  70. // 用户协议
  71. handleUserAgrement() {
  72. let site = this.globalConfig.appInfo.agreements[1]
  73. this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`)
  74. },
  75. // 登录方法
  76. async handleLogin(params) {
  77. if (this.loginForm.username === "") {
  78. this.$modal.msgError("请输入您的账号")
  79. } else if (this.loginForm.password === "") {
  80. this.$modal.msgError("请输入您的密码")
  81. } else {
  82. // 显示验证码
  83. if (this.captchaEnabled) {
  84. this.$refs.verify.show()
  85. } else { // 直接登录
  86. await this.pwdLogin({})
  87. }
  88. }
  89. },
  90. // 密码登录
  91. async pwdLogin(captchaParams) {
  92. this.$modal.loading("登录中,请耐心等待...")
  93. // 执行登录
  94. this.loginForm.captchaVerification = captchaParams.captchaVerification
  95. this.$store.dispatch('Login', this.loginForm).then(() => {
  96. this.$modal.closeLoading()
  97. this.loginSuccess()
  98. })
  99. },
  100. // 登录成功后,处理函数
  101. loginSuccess(result) {
  102. // 设置用户信息
  103. this.$store.dispatch('GetInfo').then(res => {
  104. this.$tab.reLaunch('/pages/index')
  105. })
  106. }
  107. }
  108. }
  109. </script>
  110. <style lang="scss">
  111. .yanz_code{
  112. padding: 20rpx;
  113. font-size: 24rpx;
  114. color: #fff;
  115. background-color: #42B983;
  116. border-radius: 40rpx;
  117. text-align: center;
  118. }
  119. page {
  120. background-color: #ffffff;
  121. }
  122. .normal-login-container {
  123. width: 100%;
  124. .logo-content {
  125. width: 100%;
  126. font-size: 21px;
  127. text-align: center;
  128. padding-top: 15%;
  129. image {
  130. border-radius: 4px;
  131. }
  132. .title {
  133. margin-left: 10px;
  134. }
  135. }
  136. .login-form-content {
  137. text-align: center;
  138. margin: 20px auto;
  139. margin-top: 15%;
  140. width: 80%;
  141. .input-item {
  142. margin: 20px auto;
  143. background-color: #f5f6f7;
  144. height: 45px;
  145. border-radius: 20px;
  146. .icon {
  147. font-size: 38rpx;
  148. margin-left: 10px;
  149. color: #999;
  150. }
  151. .input {
  152. width: 100%;
  153. font-size: 14px;
  154. line-height: 20px;
  155. text-align: left;
  156. padding-left: 15px;
  157. }
  158. }
  159. .login-btn {
  160. margin-top: 40px;
  161. height: 45px;
  162. }
  163. .xieyi {
  164. color: #333;
  165. margin-top: 20px;
  166. }
  167. }
  168. .easyinput {
  169. width: 100%;
  170. }
  171. }
  172. .login-code-img {
  173. height: 45px;
  174. }
  175. </style>