diff --git a/package.json b/package.json index 0193ce0..56c8b94 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "serve": "vite preview" }, "dependencies": { + "@fingerprintjs/fingerprintjs": "^4.4.3", "@unocss/reset": "^0.61.9", "@vueuse/core": "^10.11.0", "axios": "^1.7.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1721fa8..ca39efe 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,6 +8,9 @@ importers: .: dependencies: + '@fingerprintjs/fingerprintjs': + specifier: ^4.4.3 + version: 4.4.3 '@unocss/reset': specifier: ^0.61.9 version: 0.61.9 @@ -1099,6 +1102,9 @@ packages: cpu: [x64] os: [win32] + '@fingerprintjs/fingerprintjs@4.4.3': + resolution: {integrity: sha512-sm0ZmDp5Oeq8hQTf+bAHKsuuteVAYme/YOY9UPP/GrUBrR5Fzl1P5oOv6F5LvyBrO7qLjU5HQkfU0MmFte/8xA==} + '@iconify/types@2.0.0': resolution: {integrity: sha512-+wluvCrRhXrhyOmRDJ3q8mux9JkKy5SJ/v8ol2tu4FVjyYvtEzkc/3pK15ET6RKg4b4w4BmTk1+gsCUhf21Ykg==} @@ -2392,6 +2398,9 @@ packages: treemate@0.3.11: resolution: {integrity: sha512-M8RGFoKtZ8dF+iwJfAJTOH/SM4KluKOKRJpjCMhI8bG3qB74zrFoArKZ62ll0Fr3mqkMJiQOmWYkdYgDeITYQg==} + tslib@2.6.3: + resolution: {integrity: sha512-xNvxJEOUiWPGhUuUdQgAJPKOOJfGnIyKySOc09XkKsgdUV/3E2zvwZYdejjmRgPCgcym1juLH3226yA7sEFJKQ==} + tsx@4.16.5: resolution: {integrity: sha512-ArsiAQHEW2iGaqZ8fTA1nX0a+lN5mNTyuGRRO6OW3H/Yno1y9/t1f9YOI1Cfoqz63VAthn++ZYcbDP7jPflc+A==} engines: {node: '>=18.0.0'} @@ -3739,6 +3748,10 @@ snapshots: '@esbuild/win32-x64@0.21.5': optional: true + '@fingerprintjs/fingerprintjs@4.4.3': + dependencies: + tslib: 2.6.3 + '@iconify/types@2.0.0': {} '@iconify/utils@2.1.30': @@ -5172,6 +5185,8 @@ snapshots: treemate@0.3.11: {} + tslib@2.6.3: {} + tsx@4.16.5: dependencies: esbuild: 0.21.5 diff --git a/src/api/auth/index.js b/src/api/auth/index.js index 38b17a7..4a7a72c 100644 --- a/src/api/auth/index.js +++ b/src/api/auth/index.js @@ -1,4 +1,6 @@ import request from '@/service/index.js' +import {useAuth} from "@/store/auth/index.js"; + export const sendCode = (data) => { return request({ url: '/api/children/competition/sendCode', @@ -69,8 +71,21 @@ export const voteStatus = (data) => { export const cWxApi = (data) => { return request({ url: '/api/children/competition/wx', - maxRedirects: 0, method: 'GET', data, }) } +export const GToken = (data) => { + return request({ + url: '/api/children/competition/view/login', + method: 'POST', + data, + }) +} +export const viewOpenId = (data) => { + return request({ + url: '/api/children/competition/view/openId', + method: 'POST', + data + }) +} diff --git a/src/router/index.js b/src/router/index.js index 1ff2d93..5108ca8 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -1,6 +1,5 @@ // router/index.js import { createRouter, createWebHistory } from 'vue-router'; -import {deadlineAPI} from "@/api/auth/index.js"; const routes = [ { path: '/', diff --git a/src/service/index.js b/src/service/index.js index acc46a6..dc74b8e 100644 --- a/src/service/index.js +++ b/src/service/index.js @@ -1,4 +1,5 @@ import { useRouter } from 'vue-router'; + import Request from '@/service/request/index.js' import {message} from "@/utils/message.js"; const request = new Request({ @@ -8,14 +9,17 @@ const request = new Request({ //实例的请求拦截器 requestInterceptors: (config) => { const token=localStorage.getItem('token') + config.headers['Content-Type'] = config.method === 'get' ? 'application/x-www-form-urlencoded' : 'application/json' if (config.isFormData) { config.headers['Content-Type'] = 'multipart/form-data'; config.headers['Authorization'] = token + config.headers['Authorization2'] ='1234567' } else { config.headers['Authorization'] = token + config.headers['Authorization2'] ='1234567' } return config; }, diff --git a/src/store/auth/index.js b/src/store/auth/index.js index 4e6e3b9..88eb295 100644 --- a/src/store/auth/index.js +++ b/src/store/auth/index.js @@ -1,8 +1,9 @@ -import {ref,computed} from 'vue' -import {createGlobalState,useStorage} from '@vueuse/core' +import {computed, ref} from 'vue' +import {createGlobalState, useStorage} from '@vueuse/core' import { competitionApply, - competitionWorks, deadlineAPI, + competitionWorks, + GToken, loginRegister, sendCode, uploadFile, @@ -10,16 +11,21 @@ import { workInfo } from '@/api/auth/index.js' import {message} from "@/utils/message.js" -import { useRouter } from 'vue-router'; -import { showImagePreview } from 'vant'; +import {useRouter} from 'vue-router'; +import {showImagePreview} from 'vant'; import useImgModalPopup from "@/components/imgModal/imgModal.js"; -export const useAuth=createGlobalState(()=>{ +export const useAuth=createGlobalState(()=>{ + console.log('useRouter',useRouter) const router = useRouter() const token = useStorage('token', '', localStorage) const workUid = useStorage('workUid', '', localStorage) const telNum =useStorage('telNum', '', localStorage) const code=ref('') + const voteToken=useStorage('voteToken', { + authorization: '', + expireTime: '' + }, localStorage) const workData=useStorage('workData', {}, localStorage) const countdown = ref(0) const isCountingDown = ref(false) @@ -27,6 +33,18 @@ export const useAuth=createGlobalState(()=>{ return isCountingDown.value ? `${countdown.value}s` : '获取验证码' }) const resultType=useStorage('resultType', '', localStorage) + + const getVoteToken=async ()=>{ + const res=await GToken() + if (res.status===0){ + const currentTimestamp = Date.now(); + const millisecondsIn48Hours = 48 * 60 * 60 * 1000; + voteToken.value.expireTime=currentTimestamp + millisecondsIn48Hours + voteToken.value.authorization=res.data?.authorization + console.log('voteToken',voteToken.value) + } + + } const sendVote=async ()=>{ const res= await voteAPI({workUid:workUid.value}) @@ -40,6 +58,14 @@ export const useAuth=createGlobalState(()=>{ }) } } + const isWechat=()=>{ + const os = window.navigator.userAgent.toLowerCase(); + if(os.match(/micromessenger/i) == 'micromessenger'){ + return true; + }else{ + return false; + } + } const getWorkInfo=async ()=>{ const res=await workInfo({workUid:workUid.value}) if (res.status===0){ @@ -139,7 +165,9 @@ export const useAuth=createGlobalState(()=>{ } const viewDetails=async ()=>{ await getDetail() - router.push('/details') + router.push({ + path: '/details', + }) } const clickApply=async ()=>{ const isValid = validateFormData(); @@ -191,11 +219,15 @@ export const useAuth=createGlobalState(()=>{ if (res.data.status===1){ message.warning('您已经报名') await getDetail() - router.push('/details') + console.log('router',router) + router.push({ + path: '/details', + }) }else { message.success('登录成功') - - router.push('/signup') + router.push({ + path: '/signup', + }) } } @@ -249,6 +281,9 @@ export const useAuth=createGlobalState(()=>{ } }; return { + voteToken, + isWechat, + getVoteToken, beforeUploadImage, showText, resultType, diff --git a/src/views/vote/index.vue b/src/views/vote/index.vue index 5bf86ac..6c9f3e5 100644 --- a/src/views/vote/index.vue +++ b/src/views/vote/index.vue @@ -1,19 +1,32 @@