index.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <template>
  2. <app-statusbar class="login">
  3. <app-navback class="login-navback" />
  4. <app-statusbar class="login-luanguage">
  5. <app-luanguage v-if="globalStore.getSystemInfo('i18nEnabled')" />
  6. </app-statusbar>
  7. <div class="login-logo">
  8. <slot name="logo">
  9. <img :src="logoSrc" />
  10. </slot>
  11. </div>
  12. <Form ref="formRef" class="login-form" @submit="formValidate">
  13. <CellGroup inset>
  14. <Field v-model="formData.userName" name="account" :label="$t('user.login.username')" label-align="top"
  15. size="large" :placeholder="$t('user.login.Pleaseenterausername')"
  16. :rules="[{ required: true, message: $t('user.login.Pleaseenterausername') }]" />
  17. <Field v-model="formData.password" name="password" type="password" :label="$t('user.login.password')"
  18. label-align="top" size="large" :placeholder="$t('user.login.Pleaseenterthepassword')"
  19. :rules="[{ required: true, message: $t('user.login.Pleaseenterthepassword') }]" autocomplete="off" />
  20. </CellGroup>
  21. <ClickVerify class="button-submit" v-model:show="showClickVerify" @success="formSubmit">
  22. <Button type="primary" native-type="submit" @click="formRef?.submit" round block>
  23. {{ $t('user.login.login') }}
  24. </Button>
  25. </ClickVerify>
  26. </Form>
  27. <div class="login-link">
  28. <span @click="navigationTo('user-register')" v-if="globalStore.hasSystemModule('register')">{{
  29. $t('user.login.register') }}</span>
  30. <span @click="navigationTo('user-forget')">{{ $t('user.login.forgetpassword') }}</span>
  31. </div>
  32. <div class="login-footer">
  33. <div class="login-footer__trem">
  34. <Checkbox shape="square" icon-size="16px" v-model="checked">{{ $t('user.login.checked') }}</Checkbox>
  35. <span @click="routerTo('rules-zcxy')">{{ $t('user.login.ruleszcxy') }}</span>
  36. <template v-if="showYhkhfxgzs">
  37. <span>、</span>
  38. <span @click="routerTo('rules-yhkhfxgzs')">{{ $t('user.login.rulesyhkhfxgzs') }}</span>
  39. </template>
  40. <template v-if="showYszc">
  41. <span>、</span>
  42. <span @click="routerTo('rules-yszc')">{{ $t('user.login.rulesyszc') }}</span>
  43. </template>
  44. </div>
  45. <div class="login-footer__version">
  46. <span>v1.0.{{ appVersion }}</span>
  47. </div>
  48. </div>
  49. </app-statusbar>
  50. </template>
  51. <script lang="ts" setup>
  52. import { shallowRef } from 'vue'
  53. import { FormInstance, Button, Field, CellGroup, Cell, Form, Checkbox, showFailToast, showToast } from 'vant'
  54. import { fullloading, dialog } from '@/utils/vant'
  55. import { useLogin } from '@/business/login'
  56. import { useNavigation } from '@mobile/router/navigation'
  57. import { useGlobalStore, i18n } from '@/stores'
  58. import service from '@/services'
  59. import logoImage from '../../../assets/images/login-logo.png'
  60. import ClickVerify from '@mobile/components/base/click-verify/index.vue'
  61. import AppLuanguage from '@mobile/components/modules/luanguage/index.vue'
  62. const props = defineProps({
  63. logoSrc: {
  64. type: String,
  65. default: logoImage
  66. },
  67. showYhkhfxgzs: {
  68. type: Boolean,
  69. default: true
  70. },
  71. showYszc: {
  72. type: Boolean,
  73. default: true
  74. },
  75. showReport: {
  76. type: Boolean,
  77. default: true
  78. }
  79. })
  80. const { global: { t } } = i18n
  81. const globalStore = useGlobalStore()
  82. const { setGlobalUrlParams, routerTo, routerBack } = useNavigation()
  83. const { formData, userLogin } = useLogin()
  84. const formRef = shallowRef<FormInstance>()
  85. const checked = shallowRef(false) // 是否同意协议管理
  86. const showClickVerify = shallowRef(false) // 显示验证窗口
  87. const meta = document.getElementsByTagName('meta')
  88. const appVersion = meta.namedItem('revised')?.content ?? '0'
  89. // 导航跳转
  90. const navigationTo = (name: string) => {
  91. fullloading((hideLoading) => {
  92. service.onReady().then(() => {
  93. hideLoading()
  94. routerTo(name)
  95. }).catch(() => {
  96. showFailToast(t('user.login.startfailure'))
  97. })
  98. }, t('user.login.loading'))
  99. }
  100. // 表单验证
  101. const formValidate = () => {
  102. if (checked.value) {
  103. showClickVerify.value = true
  104. } else {
  105. showToast(t('user.login.tips2'))
  106. }
  107. }
  108. // 表单提交
  109. const formSubmit = () => {
  110. fullloading((hideLoading) => {
  111. userLogin().then((forcedPasswordChange) => {
  112. hideLoading()
  113. if (forcedPasswordChange) {
  114. dialog(t('user.login.tips1')).then(() => {
  115. setGlobalUrlParams({ forcedPasswordChange })
  116. routerTo('user-password', true)
  117. })
  118. } else if (props.showReport) {
  119. routerTo('report', true)
  120. } else {
  121. routerBack()
  122. }
  123. }).catch((err) => {
  124. formData.password = ''
  125. hideLoading(err, 'fail')
  126. })
  127. }, t('user.login.logining'))
  128. }
  129. </script>
  130. <style lang="less">
  131. @import './index.less';
  132. </style>