index.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <template>
  2. <div class="login">
  3. <van-nav-bar title="自然人开票" />
  4. <div class="login-content">
  5. <div class="text">xxx你好,欢迎您参加医疗峰会项目,请登录系统开具发票</div>
  6. <div class="bold-text">已注册电子税务局</div>
  7. <div class="form">
  8. <!-- 手机号输入 -->
  9. <van-cell-group inset class="grop">
  10. <van-field
  11. class="input"
  12. v-model="formData.mobile"
  13. placeholder="请输入手机号"
  14. clearable
  15. type="tel"
  16. maxlength="30"
  17. @update:model-value="onInputMobile"
  18. />
  19. </van-cell-group>
  20. <!-- 验证码输入 + 按钮 -->
  21. <van-cell-group inset class="grop">
  22. <van-field
  23. class="input code-input"
  24. v-model="formData.code"
  25. placeholder="请输入验证码"
  26. clearable
  27. type="tel"
  28. maxlength="6"
  29. @update:model-value="onInputCode"
  30. />
  31. <button class="code-btn" :disabled="isCounting || !formData.mobile" @click="sendCode">
  32. {{ isCounting ? countDown + 's后重发' : '获取验证码' }}
  33. </button>
  34. </van-cell-group>
  35. <!-- 同意协议 -->
  36. <div class="agree">
  37. <label>
  38. <input type="checkbox" v-model="agree" />
  39. 我已阅读并同意
  40. <a @click="toAgreement('auth')">《授权协议》</a>
  41. <a @click="toAgreement('privacy')">《隐私权政策》</a>
  42. </label>
  43. </div>
  44. <!-- 登录按钮 -->
  45. <div class="login-btn btn" @click="login">登录</div>
  46. </div>
  47. <div class="bold-text">未注册电子税务局</div>
  48. <div class="register-btn btn">立即注册</div>
  49. <div class="footer">技术支持:票易云(北京)科技有限公司</div>
  50. </div>
  51. </div>
  52. </template>
  53. <script setup lang="ts">
  54. import { ref, reactive, onMounted } from 'vue'
  55. import { useRouter } from 'vue-router'
  56. import { showFailToast, showSuccessToast, showToast } from 'vant'
  57. import { sendEtsSmsApi, loginEtssmsApi } from '@/services/modules/login'
  58. import type { SendTtsSmsRequest, LoginEtssmsRequest } from '@/services/modules/login/type.d'
  59. import { useUserStore } from '@/stores/modules/user'
  60. const userStore = useUserStore()
  61. const router = useRouter()
  62. /* 表单数据 */
  63. const formData = reactive<LoginEtssmsRequest>({
  64. mobile: '13800138001',
  65. code: '5657',
  66. })
  67. const sendEtsSms = reactive<SendTtsSmsRequest>({
  68. mobile: '',
  69. pushRecordId: '2',
  70. })
  71. /* 限制手机号只能输入数字,最多 30 位 */
  72. const onInputMobile = (val: string) => {
  73. formData.mobile = val.replace(/\D/g, '').slice(0, 30)
  74. }
  75. /* 限制验证码只能输入数字,最多 6 位 */
  76. const onInputCode = (val: string) => {
  77. formData.code = val.replace(/\D/g, '').slice(0, 6)
  78. }
  79. /* 是否同意协议 */
  80. const agree = ref(false)
  81. /* 验证码按钮逻辑 */
  82. const isCounting = ref(false)
  83. const countDown = ref(60)
  84. let timer: number | undefined
  85. /* 发送验证码 */
  86. const sendCode = async () => {
  87. if (!/^1\d{10}$/.test(formData.mobile)) {
  88. showToast('请输入正确的手机号')
  89. return
  90. }
  91. sendEtsSms.mobile = formData.mobile
  92. const res = await sendEtsSmsApi(sendEtsSms)
  93. if (res.code === 0 && res.data) {
  94. showSuccessToast('发送成功')
  95. startCountDown()
  96. }
  97. }
  98. /* 倒计时逻辑 */
  99. const startCountDown = () => {
  100. isCounting.value = true
  101. countDown.value = 60
  102. timer = window.setInterval(() => {
  103. countDown.value--
  104. if (countDown.value <= 0) {
  105. isCounting.value = false
  106. clearInterval(timer)
  107. }
  108. }, 1000)
  109. }
  110. /* 登录逻辑 */
  111. const login = async () => {
  112. if (!formData.mobile) {
  113. showFailToast('请输入手机号和验证码')
  114. return
  115. }
  116. if (!formData.code) {
  117. showFailToast('验证码不能为空')
  118. return
  119. }
  120. if (!agree.value) {
  121. showFailToast('请勾选阅读并同意')
  122. return
  123. }
  124. const res: any = await loginEtssmsApi(formData)
  125. if (res?.access_token) {
  126. userStore.setAccessToken(res.access_token)
  127. router.replace({ path: '/invoice-information' })
  128. }
  129. console.log('登录结果:', res)
  130. }
  131. /* 协议跳转 */
  132. const toAgreement = (type: string) => {
  133. router.push({
  134. path: '/agreement',
  135. query: { type },
  136. })
  137. }
  138. onMounted(() => {
  139. // 可在此自动聚焦手机号输入或初始化逻辑
  140. })
  141. </script>
  142. <style lang="scss" scoped>
  143. .login {
  144. min-height: 100vh;
  145. display: flex;
  146. flex-direction: column;
  147. background: linear-gradient(180deg, #ffffff 0%, #f5f7fb 100%);
  148. overflow-x: hidden;
  149. .van-nav-bar {
  150. background-color: #fff;
  151. border-bottom: 1px solid #f2f2f2;
  152. font-weight: 600;
  153. }
  154. .login-content {
  155. flex: 1;
  156. padding: 6vw 6vw 12vw;
  157. display: flex;
  158. flex-direction: column;
  159. align-items: center;
  160. .text {
  161. width: 90%;
  162. font-size: 4vw;
  163. text-align: center;
  164. line-height: 6vw;
  165. color: #333;
  166. margin-top: 8vw;
  167. margin-bottom: 6vw;
  168. }
  169. .bold-text {
  170. width: 100%;
  171. font-weight: 700;
  172. font-size: 4.5vw;
  173. text-align: left;
  174. color: #222;
  175. margin: 4vw 0 2vw;
  176. }
  177. .form {
  178. width: 96%;
  179. margin-top: 20px;
  180. background: #fff;
  181. border-radius: 3vw;
  182. box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
  183. padding: 6vw 4vw;
  184. margin-bottom: 8vw;
  185. .grop {
  186. margin-top: 3vw;
  187. display: flex;
  188. align-items: center;
  189. justify-content: space-between;
  190. }
  191. .input {
  192. width: 100%;
  193. border-radius: 6vw;
  194. border: 1px solid #e5e5e5;
  195. padding-left: 5vw;
  196. font-size: 3.8vw;
  197. background: #fff;
  198. transition: 0.3s;
  199. &:focus {
  200. border-color: #fe783d;
  201. box-shadow: 0 0 8px rgba(254, 120, 61, 0.3);
  202. }
  203. }
  204. .code-input {
  205. width: 55%;
  206. }
  207. .code-btn {
  208. background: linear-gradient(90deg, #fe783d 0%, #ff994f 100%);
  209. border: none;
  210. border-radius: 25px;
  211. height: 9vw;
  212. width: 30%;
  213. color: #fff;
  214. font-weight: 600;
  215. font-size: 3.4vw;
  216. cursor: pointer;
  217. transition: all 0.3s;
  218. &:active {
  219. opacity: 0.85;
  220. }
  221. &:disabled {
  222. background: #ccc;
  223. cursor: not-allowed;
  224. }
  225. }
  226. .agree {
  227. text-align: left;
  228. font-size: 3vw;
  229. line-height: 5vw;
  230. margin: 4vw 0;
  231. color: #666;
  232. padding-left: 36px;
  233. label {
  234. display: flex;
  235. align-items: center;
  236. flex-wrap: wrap;
  237. input {
  238. width: 3.5vw;
  239. height: 3.5vw;
  240. margin-right: 6px;
  241. }
  242. }
  243. a {
  244. color: #fe783d;
  245. text-decoration: none;
  246. margin-left: 2px;
  247. }
  248. }
  249. }
  250. .btn {
  251. box-sizing: border-box;
  252. width: 80%;
  253. height: 12vw;
  254. border-radius: 6vw;
  255. color: #fff;
  256. font-size: 4vw;
  257. line-height: 12vw;
  258. text-align: center;
  259. font-weight: 600;
  260. cursor: pointer;
  261. transition: all 0.3s ease;
  262. margin: 4vw 0;
  263. &:active {
  264. transform: scale(0.98);
  265. }
  266. }
  267. .login-btn {
  268. margin: 0 auto;
  269. background: linear-gradient(90deg, #ff8036 0%, #ffa253 100%);
  270. box-shadow: 0 4px 12px rgba(255, 128, 54, 0.3);
  271. }
  272. .register-btn {
  273. background: linear-gradient(90deg, #0072f8 0%, #3a9fff 100%);
  274. box-shadow: 0 4px 12px rgba(0, 114, 248, 0.25);
  275. }
  276. .footer {
  277. width: 100%;
  278. text-align: center;
  279. color: #999;
  280. font-size: 3vw;
  281. margin-top: auto;
  282. padding-bottom: 4vh;
  283. }
  284. }
  285. }
  286. </style>