| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325 |
- <template>
- <div class="login">
- <van-nav-bar title="自然人开票" />
- <div class="login-content">
- <div class="text">xxx你好,欢迎您参加医疗峰会项目,请登录系统开具发票</div>
- <div class="bold-text">已注册电子税务局</div>
- <div class="form">
- <!-- 手机号输入 -->
- <van-cell-group inset class="grop">
- <van-field
- class="input"
- v-model="formData.mobile"
- placeholder="请输入手机号"
- clearable
- type="tel"
- maxlength="30"
- @update:model-value="onInputMobile"
- />
- </van-cell-group>
- <!-- 验证码输入 + 按钮 -->
- <van-cell-group inset class="grop">
- <van-field
- class="input code-input"
- v-model="formData.code"
- placeholder="请输入验证码"
- clearable
- type="tel"
- maxlength="6"
- @update:model-value="onInputCode"
- />
- <button class="code-btn" :disabled="isCounting || !formData.mobile" @click="sendCode">
- {{ isCounting ? countDown + 's后重发' : '获取验证码' }}
- </button>
- </van-cell-group>
- <!-- 同意协议 -->
- <div class="agree">
- <label>
- <input type="checkbox" v-model="agree" />
- 我已阅读并同意
- <a @click="toAgreement('auth')">《授权协议》</a>
- <a @click="toAgreement('privacy')">《隐私权政策》</a>
- </label>
- </div>
- <!-- 登录按钮 -->
- <div class="login-btn btn" @click="login">登录</div>
- </div>
- <div class="bold-text">未注册电子税务局</div>
- <div class="register-btn btn">立即注册</div>
- <div class="footer">技术支持:票易云(北京)科技有限公司</div>
- </div>
- </div>
- </template>
- <script setup lang="ts">
- import { ref, reactive, onMounted } from 'vue'
- import { useRouter } from 'vue-router'
- import { showFailToast, showSuccessToast, showToast } from 'vant'
- import { sendEtsSmsApi, loginEtssmsApi } from '@/services/modules/login'
- import type { SendTtsSmsRequest, LoginEtssmsRequest } from '@/services/modules/login/type.d'
- import { useUserStore } from '@/stores/modules/user'
- const userStore = useUserStore()
- const router = useRouter()
- /* 表单数据 */
- const formData = reactive<LoginEtssmsRequest>({
- mobile: '13800138001',
- code: '5657',
- })
- const sendEtsSms = reactive<SendTtsSmsRequest>({
- mobile: '',
- pushRecordId: '2',
- })
- /* 限制手机号只能输入数字,最多 30 位 */
- const onInputMobile = (val: string) => {
- formData.mobile = val.replace(/\D/g, '').slice(0, 30)
- }
- /* 限制验证码只能输入数字,最多 6 位 */
- const onInputCode = (val: string) => {
- formData.code = val.replace(/\D/g, '').slice(0, 6)
- }
- /* 是否同意协议 */
- const agree = ref(false)
- /* 验证码按钮逻辑 */
- const isCounting = ref(false)
- const countDown = ref(60)
- let timer: number | undefined
- /* 发送验证码 */
- const sendCode = async () => {
- if (!/^1\d{10}$/.test(formData.mobile)) {
- showToast('请输入正确的手机号')
- return
- }
- sendEtsSms.mobile = formData.mobile
- const res = await sendEtsSmsApi(sendEtsSms)
- if (res.code === 0 && res.data) {
- showSuccessToast('发送成功')
- startCountDown()
- }
- }
- /* 倒计时逻辑 */
- const startCountDown = () => {
- isCounting.value = true
- countDown.value = 60
- timer = window.setInterval(() => {
- countDown.value--
- if (countDown.value <= 0) {
- isCounting.value = false
- clearInterval(timer)
- }
- }, 1000)
- }
- /* 登录逻辑 */
- const login = async () => {
- if (!formData.mobile) {
- showFailToast('请输入手机号和验证码')
- return
- }
- if (!formData.code) {
- showFailToast('验证码不能为空')
- return
- }
- if (!agree.value) {
- showFailToast('请勾选阅读并同意')
- return
- }
- const res: any = await loginEtssmsApi(formData)
- if (res?.access_token) {
- userStore.setAccessToken(res.access_token)
- router.replace({ path: '/invoice-information' })
- }
- console.log('登录结果:', res)
- }
- /* 协议跳转 */
- const toAgreement = (type: string) => {
- router.push({
- path: '/agreement',
- query: { type },
- })
- }
- onMounted(() => {
- // 可在此自动聚焦手机号输入或初始化逻辑
- })
- </script>
- <style lang="scss" scoped>
- .login {
- min-height: 100vh;
- display: flex;
- flex-direction: column;
- background: linear-gradient(180deg, #ffffff 0%, #f5f7fb 100%);
- overflow-x: hidden;
- .van-nav-bar {
- background-color: #fff;
- border-bottom: 1px solid #f2f2f2;
- font-weight: 600;
- }
- .login-content {
- flex: 1;
- padding: 6vw 6vw 12vw;
- display: flex;
- flex-direction: column;
- align-items: center;
- .text {
- width: 90%;
- font-size: 4vw;
- text-align: center;
- line-height: 6vw;
- color: #333;
- margin-top: 8vw;
- margin-bottom: 6vw;
- }
- .bold-text {
- width: 100%;
- font-weight: 700;
- font-size: 4.5vw;
- text-align: left;
- color: #222;
- margin: 4vw 0 2vw;
- }
- .form {
- width: 96%;
- margin-top: 20px;
- background: #fff;
- border-radius: 3vw;
- box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
- padding: 6vw 4vw;
- margin-bottom: 8vw;
- .grop {
- margin-top: 3vw;
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
- .input {
- width: 100%;
- border-radius: 6vw;
- border: 1px solid #e5e5e5;
- padding-left: 5vw;
- font-size: 3.8vw;
- background: #fff;
- transition: 0.3s;
- &:focus {
- border-color: #fe783d;
- box-shadow: 0 0 8px rgba(254, 120, 61, 0.3);
- }
- }
- .code-input {
- width: 55%;
- }
- .code-btn {
- background: linear-gradient(90deg, #fe783d 0%, #ff994f 100%);
- border: none;
- border-radius: 25px;
- height: 9vw;
- width: 30%;
- color: #fff;
- font-weight: 600;
- font-size: 3.4vw;
- cursor: pointer;
- transition: all 0.3s;
- &:active {
- opacity: 0.85;
- }
- &:disabled {
- background: #ccc;
- cursor: not-allowed;
- }
- }
- .agree {
- text-align: left;
- font-size: 3vw;
- line-height: 5vw;
- margin: 4vw 0;
- color: #666;
- padding-left: 36px;
- label {
- display: flex;
- align-items: center;
- flex-wrap: wrap;
- input {
- width: 3.5vw;
- height: 3.5vw;
- margin-right: 6px;
- }
- }
- a {
- color: #fe783d;
- text-decoration: none;
- margin-left: 2px;
- }
- }
- }
- .btn {
- box-sizing: border-box;
- width: 80%;
- height: 12vw;
- border-radius: 6vw;
- color: #fff;
- font-size: 4vw;
- line-height: 12vw;
- text-align: center;
- font-weight: 600;
- cursor: pointer;
- transition: all 0.3s ease;
- margin: 4vw 0;
- &:active {
- transform: scale(0.98);
- }
- }
- .login-btn {
- margin: 0 auto;
- background: linear-gradient(90deg, #ff8036 0%, #ffa253 100%);
- box-shadow: 0 4px 12px rgba(255, 128, 54, 0.3);
- }
- .register-btn {
- background: linear-gradient(90deg, #0072f8 0%, #3a9fff 100%);
- box-shadow: 0 4px 12px rgba(0, 114, 248, 0.25);
- }
- .footer {
- width: 100%;
- text-align: center;
- color: #999;
- font-size: 3vw;
- margin-top: auto;
- padding-bottom: 4vh;
- }
- }
- }
- </style>
|