awei
7 months ago
22 changed files with 268 additions and 1105 deletions
@ -1,2 +1,2 @@
@@ -1,2 +1,2 @@
|
||||
VITE_APP_PREVIEW=false |
||||
VITE_APP_API_BASE_URL=https://api.example.com |
||||
VITE_APP_API_BASE_URL=/api |
||||
|
@ -0,0 +1,23 @@
@@ -0,0 +1,23 @@
|
||||
import request from '@/utils/request' |
||||
|
||||
/** |
||||
* 根据openid获取参会用户信息 |
||||
*/ |
||||
export function getApplyInfoByOpenId(data: { openId: string, miceLink: string }) { |
||||
return request({ |
||||
method: 'post', |
||||
url: '/backstageApply/getByOpenId', |
||||
data, |
||||
}) |
||||
} |
||||
|
||||
/** |
||||
* 根据手机号获取参会用户信息 |
||||
*/ |
||||
export function getApplyInfoByPhone(data: { phone: string, miceLink: string }) { |
||||
return request({ |
||||
method: 'post', |
||||
url: '/backstageApply/getByPhone', |
||||
data, |
||||
}) |
||||
} |
@ -0,0 +1,83 @@
@@ -0,0 +1,83 @@
|
||||
import { defineStore } from 'pinia' |
||||
import type { VueCookies } from 'vue-cookies' |
||||
import { getUserInfoByOpenId, userSign } from '@/api/weixin' |
||||
import { getApplyInfoByOpenId } from '@/api/user' |
||||
|
||||
/** |
||||
* 会议信息 |
||||
*/ |
||||
const useUserStore = defineStore('user', () => { |
||||
const wxInfo = ref<any>({}) |
||||
const router = useRouter() |
||||
const openId = ref('') |
||||
const userInfo = ref<any>({}) |
||||
const applyInfo = ref<any>({}) |
||||
|
||||
// 获取openid
|
||||
async function getOpenId() { |
||||
const APPID = 'wxa4d8f4b7c43cdf40' |
||||
const cookies = inject<VueCookies>('$cookies') |
||||
|
||||
let user = {} as any |
||||
user = cookies.get('user') |
||||
// user = {
|
||||
// openid: 'o_CUl6J2TlFYLbnTp8PqWle-DUSQ',
|
||||
// }
|
||||
|
||||
// 如果没有openId,跳转到授权页面
|
||||
if (!user || !user.openid) { |
||||
if (!router.currentRoute.value.query.code) { |
||||
window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${APPID}&redirect_uri=${window.location.href.split('#')[0]}&response_type=code&scope=snsapi_userinfo#wechat_redirect` |
||||
} |
||||
else { |
||||
const code = router.currentRoute.value.query.code as string |
||||
// 获取微信用户信息
|
||||
userSign(code).then((res: any) => { |
||||
cookies.set('user', JSON.stringify(res)) |
||||
wxInfo.value = res |
||||
openId.value = res.openid |
||||
getUserInfo() |
||||
}) |
||||
} |
||||
} |
||||
else { |
||||
openId.value = user.openid |
||||
wxInfo.value = user |
||||
getUserInfo() |
||||
} |
||||
} |
||||
|
||||
// 获取参会用户信息
|
||||
function getUserInfo() { |
||||
getUserInfoByOpenId(openId.value).then((res: any) => { |
||||
userInfo.value = res |
||||
}) |
||||
} |
||||
|
||||
// 根据手机号获取参会信息
|
||||
// function getApplyInfoByPhone() {
|
||||
|
||||
// }
|
||||
|
||||
// 根据openid获取参会信息
|
||||
function getApplyUserInfo(miceLink) { |
||||
return new Promise((resolve, reject) => { |
||||
getApplyInfoByOpenId({ openId: openId.value, miceLink }).then((res: any) => { |
||||
applyInfo.value = res.backstageApply |
||||
resolve(res.backstageApply) |
||||
}).catch((err) => { |
||||
reject(err) |
||||
}) |
||||
}) |
||||
} |
||||
|
||||
return { |
||||
wxInfo, |
||||
openId, |
||||
userInfo, |
||||
getOpenId, |
||||
getApplyUserInfo, |
||||
} |
||||
}) |
||||
|
||||
export default useUserStore |
@ -0,0 +1,20 @@
@@ -0,0 +1,20 @@
|
||||
<script setup lang="ts"> |
||||
import useUserStore from '@/stores/modules/user' |
||||
|
||||
const userStore = useUserStore() |
||||
|
||||
const userApplyInfo = ref<any>({}) |
||||
|
||||
onMounted(() => { |
||||
userStore.getApplyUserInfo(getUrlMiceLink()).then((res) => { |
||||
userApplyInfo.value = res |
||||
}) |
||||
}) |
||||
</script> |
||||
|
||||
<template> |
||||
<div> |
||||
个人中心 |
||||
{{ userApplyInfo }} |
||||
</div> |
||||
</template> |
Loading…
Reference in new issue