login.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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" @blur="getTenantIdByName" 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. import {getTenantIdByName} from "@/api/system/tenant";
  33. import {setTenantId,removeTenantId} from "@/utils/auth";
  34. export default {
  35. name: 'Login',
  36. components: {
  37. Verify
  38. },
  39. data() {
  40. return {
  41. captchaEnabled:false, // 验证码开关 TODO 芋艿:需要抽到配置里
  42. globalConfig: getApp().globalData.config,
  43. loginForm: {
  44. // username: "admin",
  45. // password: "admin123",
  46. username: "",
  47. password: "",
  48. captchaVerification: ""
  49. }
  50. }
  51. },
  52. methods: {
  53. getTenantIdByName(e){
  54. removeTenantId()
  55. let value = e.target.value
  56. getTenantIdByName(value).then(res => {
  57. const tenantId = res.data;
  58. if (tenantId && tenantId >= 0) {
  59. setTenantId(tenantId)
  60. } else {
  61. this.$modal.msgError("该手机号未创建账号,请重新输入")
  62. }
  63. });
  64. },
  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" scoped>
  111. page {
  112. background-color: #ffffff;
  113. }
  114. .normal-login-container {
  115. width: 100%;
  116. .logo-content {
  117. width: 100%;
  118. font-size: 21px;
  119. text-align: center;
  120. padding-top: 15%;
  121. image {
  122. border-radius: 4px;
  123. }
  124. .title {
  125. margin-left: 10px;
  126. }
  127. }
  128. .login-form-content {
  129. text-align: center;
  130. margin: 20px auto;
  131. margin-top: 15%;
  132. width: 80%;
  133. .input-item {
  134. margin: 20px auto;
  135. background-color: #f5f6f7;
  136. height: 45px;
  137. border-radius: 20px;
  138. .icon {
  139. font-size: 38rpx;
  140. margin-left: 10px;
  141. color: #999;
  142. }
  143. .input {
  144. width: 100%;
  145. font-size: 14px;
  146. line-height: 20px;
  147. text-align: left;
  148. padding-left: 15px;
  149. }
  150. }
  151. .login-btn {
  152. margin-top: 40px;
  153. height: 45px;
  154. }
  155. .xieyi {
  156. color: #333;
  157. margin-top: 20px;
  158. }
  159. }
  160. .easyinput {
  161. width: 100%;
  162. }
  163. }
  164. .login-code-img {
  165. height: 45px;
  166. }
  167. </style>