index.vue 8.4 KB

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