index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <template>
  2. <div>
  3. <div class="ibps-login">
  4. <div class="login-bg">
  5. <div class="login-top">
  6. <van-icon name="comment-circle-o" class="logo-icon" />
  7. <div class="logo-text">{{ $t('common.platform') }}</div>
  8. <br>
  9. <div class="logo-text">(移动端)</div>
  10. </div>
  11. </div>
  12. <div class="ibps-p">
  13. <van-form ref="form" @submit="handleLogin" @failed="onFailed">
  14. <van-field
  15. v-model="loginForm.username"
  16. :placeholder="$t('system.login.usernamePlaceholder')"
  17. :rules="usernameRules"
  18. name="username"
  19. icon-prefix="ibps-icon"
  20. left-icon="user-circle-o"
  21. clearable />
  22. <van-field
  23. v-model="loginForm.password"
  24. :type="passwordType"
  25. :placeholder="$t('system.login.passwordPlaceholder')"
  26. :rules="[{ required: true, message: ' ' }]"
  27. :right-icon="passwordType==='password'?'eye-slash':'eye'"
  28. name="password"
  29. icon-prefix="ibps-icon"
  30. left-icon="lock"
  31. clearable
  32. @click-right-icon="showPassword" />
  33. <van-field
  34. v-if="enabledValidCode"
  35. v-model="loginForm.captcha"
  36. :placeholder="$t('system.login.codePlaceholder')"
  37. :rules="[{ required: true, message: ' ' }]"
  38. name="captcha"
  39. icon-prefix="ibps-icon"
  40. left-icon="qrcode"
  41. clearable>
  42. <template #button>
  43. <img :src="code.src" class="login-code-img" @click="refreshCode">
  44. </template>
  45. </van-field>
  46. <div class="ibps-mt">
  47. <van-button round block type="info" native-type="submit">
  48. {{ $t('system.login.logIn') }}
  49. </van-button>
  50. </div>
  51. </van-form>
  52. <switch-environment v-if="$nodeEnv === 'development'" class="ibps-mt ibps-text-center" type="link" />
  53. <div v-if="outSideSingInShow" class="outSideSingInClass">
  54. <span @click="goOutSideSingIn()">非内部人员签到</span>
  55. </div>
  56. </div>
  57. <div class="copyright">
  58. {{ $t('common.company') }}©{{ $t('common.copyright') }}
  59. </div>
  60. </div>
  61. </div>
  62. </template>
  63. <script>
  64. import { mapActions } from 'vuex'
  65. import Utils from '@/utils/util'
  66. import '@/assets/styles/pages/login.scss'
  67. import SwitchEnvironment from '@/views/system/switch-environment'
  68. const loginForm = process.env.NODE_ENV === 'development'
  69. ? {
  70. username: 'shekou',
  71. password: 'szjbd168'
  72. } : {
  73. username: '',
  74. password: ''
  75. }
  76. export default {
  77. components: {
  78. SwitchEnvironment
  79. },
  80. data() {
  81. return {
  82. passwordType: 'password',
  83. loginForm: {
  84. username: loginForm.username,
  85. password: loginForm.password,
  86. requestId: '',
  87. captcha: ''
  88. },
  89. // redirect: undefined,
  90. redirect: null,
  91. isRegOpen: false,
  92. enabledValidCode: false,
  93. code: {
  94. src: '',
  95. value: '',
  96. len: 5,
  97. type: 'src'
  98. },
  99. usernameRules: [{ required: true, message: ' ' }],
  100. outSideSingInShow: false
  101. }
  102. },
  103. watch: {
  104. $route: {
  105. handler: function(route) {
  106. // if (route.query.codeId) {
  107. // this.redirect = '/dashboard'
  108. // this.redirect = `${route.path}?codeId=${route.query.codeId}`;
  109. // } else {
  110. this.redirect = route.query && route.query.redirect
  111. if (this.redirect && this.redirect.indexOf('/bpmn/siginin/index?codeId=') !== -1) {
  112. this.outSideSingInShow = true
  113. }
  114. // }
  115. },
  116. immediate: true
  117. }
  118. },
  119. created() {
  120. this.isRegisterOpen()
  121. this.loadValidCode(true)
  122. },
  123. mounted() {
  124. // 注销退出清空验证码
  125. this.loginForm.captcha = ''
  126. // 注销退出清空请求ID
  127. this.loginForm.requestId = ''
  128. },
  129. methods: {
  130. ...mapActions('ibps/account', [
  131. 'login',
  132. 'getCaptcha',
  133. 'getRegisterOpen'
  134. ]),
  135. isRegisterOpen() {
  136. this.getRegisterOpen().then((data) => {
  137. this.isRegOpen = data.data
  138. if (this.isRegOpen) {
  139. this.usernameRules = [
  140. { required: true, message: ' ' },
  141. { validator: this.validateMobile, message: ' ' }
  142. ]
  143. } else {
  144. this.usernameRules = [{ required: true, message: ' ' }]
  145. }
  146. }).catch((e) => { })
  147. },
  148. validateMobile(value) {
  149. if (Utils.isEmpty(value)) {
  150. return false
  151. } else {
  152. const isPhone = /^1(3|4|5|6|7|8|9)\d{9}$/
  153. if (value.length === 11) {
  154. if (!isPhone.test(value)) {
  155. return false
  156. } else {
  157. return true
  158. }
  159. } else {
  160. if (!isPhone.test(value)) {
  161. return false
  162. } else {
  163. return false
  164. }
  165. }
  166. }
  167. },
  168. // 获取验证码
  169. loadValidCode(isBackfill) {
  170. this.getCaptcha({ params: { requestId: this.loginForm.requestId }}).then((data) => {
  171. // 返回状态501,说明系统没有开启验证码
  172. if (data.state === 501) {
  173. this.enabledValidCode = false
  174. } else {
  175. this.enabledValidCode = true
  176. this.code.src = data.data
  177. this.loginForm.requestId = data.variables.requestId
  178. }
  179. this.initValidCode()
  180. if (isBackfill) {
  181. this.loginForm.code = this.code.value
  182. }
  183. }).catch((e) => {
  184. })
  185. },
  186. refreshCode() {
  187. this.loadValidCode()
  188. },
  189. showPassword() {
  190. this.passwordType === 'text'
  191. ? (this.passwordType = 'password')
  192. : (this.passwordType = 'text')
  193. },
  194. onFailed({ values }) {
  195. if (this.enabledValidCode && this.$utils.isEmpty(values.captcha)) {
  196. this.$toast(this.$t('system.login.codeCorrect'))
  197. return
  198. }
  199. if (this.$utils.isNotEmpty(values.username) && this.isRegOpen) {
  200. this.$toast(this.$t('system.login.mobileCorrect'))
  201. } else {
  202. this.$toast(this.$t('system.login.usernamePasswordCorrect'))
  203. }
  204. },
  205. handleLogin() {
  206. this.login({
  207. form: this.loginForm
  208. }).then(() => {
  209. // let path = '/'
  210. // if (this.redirect) {
  211. // path = '/dashboard'
  212. // }
  213. const redirectPath = this.redirect || '/'
  214. this.$router.push({ path: redirectPath })
  215. }).catch((err) => {
  216. // 验证码错误自动清空&密码输入错误3次后触发验证码填写模块
  217. if (err && err.state === 6020104) {
  218. this.loginForm.captcha = ''
  219. this.enabledValidCode = true
  220. this.refreshCode()
  221. }
  222. if (err && err.state && this.enabledValidCode) {
  223. this.loginForm.captcha = ''
  224. this.refreshCode()
  225. }
  226. })
  227. },
  228. goOutSideSingIn() {
  229. const redirectPath = this.redirect.replace('index', 'outIndex')
  230. this.$router.push({ path: redirectPath })
  231. }
  232. }
  233. }
  234. </script>
  235. <style lang="scss" scoped>
  236. .outSideSingInClass{
  237. text-align: center;
  238. font-size: 12px;
  239. color: #409EFF;
  240. margin-top: 20px;
  241. // text-decoration: underline;
  242. span{
  243. padding: 0 4px 1px 4px;
  244. border-bottom: 1px solid #409EFF;
  245. }
  246. }
  247. </style>