index.vue 3.9 KB

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