index.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <app-statusbar class="login">
  3. <app-navback class="login-navback" />
  4. <div class="login-logo">
  5. <slot name="logo">
  6. <img :src="logoSrc" />
  7. </slot>
  8. </div>
  9. <Form class="login-form" @submit="formSubmit">
  10. <CellGroup inset>
  11. <Field v-model="formData.userName" name="account" :label="$t('user.login.username')" label-align="top" size="large" :placeholder="$t('user.login.Pleaseenterausername')"
  12. :rules="[{ required: true, message: $t('user.login.Pleaseenterausername') }]" />
  13. <Field v-model="formData.password" name="password" type="password" :label="$t('user.login.password')" label-align="top" size="large"
  14. :placeholder="$t('user.login.Pleaseenterthepassword')" :rules="[{ required: true, message: $t('user.login.Pleaseenterthepassword') }]" autocomplete="off" />
  15. <Field>
  16. <template #input>
  17. <SliderVerify @statu="slide" style="max-width: 100%;margin: auto;" v-if="showSliderVerify" />
  18. </template>
  19. </Field>
  20. </CellGroup>
  21. <div class="button-submit">
  22. <Button type="primary" native-type="submit" round block>{{ $t('user.login.login') }}</Button>
  23. </div>
  24. </Form>
  25. <div class="login-link">
  26. <span @click="navigationTo('user-register')" v-if="globalStore.hasSystemModule('register')">{{ $t('user.login.register') }}</span>
  27. <span @click="navigationTo('user-forget')">{{ $t('user.login.forgetpassword') }}</span>
  28. </div>
  29. <div class="login-footer">
  30. <div class="login-footer__trem">
  31. <Checkbox shape="square" icon-size="16px" v-model="checked">{{ $t('user.login.checked') }}</Checkbox>
  32. <span @click="routerTo('rules-zcxy')">{{ $t('user.login.ruleszcxy') }}</span>
  33. <span>、</span>
  34. <span @click="routerTo('rules-yhkhfxgzs')" v-if="showYhkhfxgzs">{{ $t('user.login.rulesyhkhfxgzs') }}</span>
  35. <span v-if="showYhkhfxgzs">、</span>
  36. <span @click="routerTo('rules-yszc')">{{ $t('user.login.rulesyszc') }}</span>
  37. </div>
  38. <div class="login-footer__version">
  39. <span>v1.0.{{ appVersion }}</span>
  40. </div>
  41. </div>
  42. </app-statusbar>
  43. </template>
  44. <script lang="ts" setup>
  45. import { shallowRef } from 'vue'
  46. import { Button, Field, CellGroup, Form, Checkbox, showFailToast, showToast } from 'vant'
  47. import { fullloading, dialog } from '@/utils/vant'
  48. import { useLogin } from '@/business/login'
  49. import { useNavigation } from '@mobile/router/navigation'
  50. import { useGlobalStore } from '@/stores'
  51. import service from '@/services'
  52. import SliderVerify from '@/components/base/slider-verify/index.vue' // 临时调用,待优化
  53. import logoImage from '../../../assets/images/login-logo.png'
  54. defineProps({
  55. logoSrc: {
  56. type: String,
  57. default: logoImage
  58. },
  59. showYhkhfxgzs: {
  60. type: Boolean,
  61. default: true
  62. }
  63. })
  64. const globalStore = useGlobalStore()
  65. const { setGlobalUrlParams, routerTo } = useNavigation()
  66. const { formData, userLogin } = useLogin()
  67. const checked = shallowRef(false) // 是否同意协议管理
  68. const showSliderVerify = shallowRef(true) // 验证滑块组件重载
  69. const sliderVerifyStatus = shallowRef(false) // 滑块验证状态
  70. const meta = document.getElementsByTagName('meta')
  71. const appVersion = meta.namedItem('revised')?.content ?? '0'
  72. // 导航跳转
  73. const navigationTo = (name: string) => {
  74. fullloading((hideLoading) => {
  75. service.onReady().then(() => {
  76. hideLoading()
  77. routerTo(name)
  78. }).catch(() => {
  79. showFailToast('初始化失败')
  80. })
  81. }, '加载中...')
  82. }
  83. // 滑块验证
  84. const slide = (vfcStatu: { statu: string }) => {
  85. if (vfcStatu.statu === 'success') {
  86. sliderVerifyStatus.value = true
  87. } else {
  88. sliderVerifyStatus.value = false
  89. }
  90. }
  91. const formSubmit = () => {
  92. if (sliderVerifyStatus.value) {
  93. if (checked.value) {
  94. fullloading((hideLoading) => {
  95. userLogin().then((forcedPasswordChange) => {
  96. hideLoading()
  97. if (forcedPasswordChange) {
  98. dialog('为了您的账户安全,请修改密码!').then(() => {
  99. setGlobalUrlParams({ forcedPasswordChange })
  100. routerTo('user-password', true)
  101. })
  102. } else {
  103. routerTo('report', true)
  104. }
  105. }).catch((err) => {
  106. showSliderVerify.value = false
  107. sliderVerifyStatus.value = false
  108. formData.password = ''
  109. hideLoading(err, 'fail')
  110. setTimeout(() => {
  111. showSliderVerify.value = true
  112. }, 0)
  113. })
  114. }, '登录中...')
  115. } else {
  116. showToast('请先同意使用条款')
  117. }
  118. }
  119. }
  120. </script>
  121. <style lang="less">
  122. @import './index.less';
  123. </style>