fix: 微信登录
This commit is contained in:
parent
1dc252d6f2
commit
4319ea97e1
|
@ -3,7 +3,7 @@
|
||||||
<template v-if="getType === 'notifier-weixin'">
|
<template v-if="getType === 'notifier-weixin'">
|
||||||
<j-spin :spinning="loading">
|
<j-spin :spinning="loading">
|
||||||
<div class="code" style="height: 450px">
|
<div class="code" style="height: 450px">
|
||||||
<iframe
|
<!-- <iframe
|
||||||
id="notifier_iframe"
|
id="notifier_iframe"
|
||||||
class="code-item"
|
class="code-item"
|
||||||
width="100%"
|
width="100%"
|
||||||
|
@ -11,13 +11,14 @@
|
||||||
:src="url"
|
:src="url"
|
||||||
sandbox="allow-forms allow-scripts allow-same-origin allow-popups"
|
sandbox="allow-forms allow-scripts allow-same-origin allow-popups"
|
||||||
v-if="!loading"
|
v-if="!loading"
|
||||||
></iframe>
|
></iframe> -->
|
||||||
|
<Wechat :data="_current" />
|
||||||
</div>
|
</div>
|
||||||
</j-spin>
|
</j-spin>
|
||||||
</template>
|
</template>
|
||||||
<template v-else-if="getType === 'notifier-dingTalk'">
|
<template v-else-if="getType === 'notifier-dingTalk'">
|
||||||
<j-spin :spinning="loading">
|
<j-spin :spinning="loading">
|
||||||
<div class="code" style="height: 600px;">
|
<div class="code" style="height: 600px">
|
||||||
<iframe
|
<iframe
|
||||||
id="notifier_iframe"
|
id="notifier_iframe"
|
||||||
class="code-item"
|
class="code-item"
|
||||||
|
@ -44,6 +45,7 @@ import {
|
||||||
getUserBind,
|
getUserBind,
|
||||||
getWechatOAuth2,
|
getWechatOAuth2,
|
||||||
} from '@/api/account/notificationSubscription';
|
} from '@/api/account/notificationSubscription';
|
||||||
|
import Wechat from './Wechat.vue';
|
||||||
|
|
||||||
const emit = defineEmits(['close', 'save']);
|
const emit = defineEmits(['close', 'save']);
|
||||||
|
|
||||||
|
@ -67,6 +69,8 @@ const getType = computed(() => {
|
||||||
return props.current?.channelProvider;
|
return props.current?.channelProvider;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const _current = ref<any>({})
|
||||||
|
|
||||||
const onBindHandle = (
|
const onBindHandle = (
|
||||||
type: 'notifier-weixin' | 'notifier-dingTalk',
|
type: 'notifier-weixin' | 'notifier-dingTalk',
|
||||||
code: string,
|
code: string,
|
||||||
|
@ -107,24 +111,13 @@ const updateIframeStyle = () => {
|
||||||
) as HTMLIFrameElement;
|
) as HTMLIFrameElement;
|
||||||
iframe.onload = () => {
|
iframe.onload = () => {
|
||||||
const currentUrl = iframe?.contentWindow?.location?.search || '';
|
const currentUrl = iframe?.contentWindow?.location?.search || '';
|
||||||
|
const _url = new URLSearchParams(currentUrl);
|
||||||
|
const params = Object.fromEntries(_url?.entries());
|
||||||
let authCode = '';
|
let authCode = '';
|
||||||
if (currentUrl.startsWith('?')) {
|
if (props.current?.channelProvider === 'notifier-dingTalk') {
|
||||||
currentUrl
|
authCode = params?.authCode
|
||||||
.substring(1)
|
|
||||||
.split('&')
|
|
||||||
.map((item) => {
|
|
||||||
if (
|
|
||||||
props.current?.channelProvider === 'notifier-dingTalk'
|
|
||||||
) {
|
|
||||||
if (item.split('=')?.[0] === 'authCode') {
|
|
||||||
authCode = item.split('=')?.[1] || '';
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (item.split('=')?.[0] === 'code') {
|
authCode = params?.code
|
||||||
authCode = item.split('=')?.[1] || '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (authCode) {
|
if (authCode) {
|
||||||
|
@ -137,18 +130,21 @@ const updateIframeStyle = () => {
|
||||||
const handleSearch = async () => {
|
const handleSearch = async () => {
|
||||||
if (props.current?.channelProvider === 'notifier-weixin') {
|
if (props.current?.channelProvider === 'notifier-weixin') {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
const resp = await getWechatOAuth2(
|
const resp: any = await getWechatOAuth2(
|
||||||
props.current?.channelConfiguration.notifierId,
|
props.current?.channelConfiguration.notifierId,
|
||||||
props.current?.channelConfiguration.templateId,
|
props.current?.channelConfiguration.templateId,
|
||||||
location.href
|
location.href,
|
||||||
).finally(() => {
|
).finally(() => {
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
});
|
});
|
||||||
if (resp.status === 200) {
|
if (resp.status === 200) {
|
||||||
url.value = resp.result as string;
|
const _url = new URLSearchParams(resp?.result);
|
||||||
nextTick(() => {
|
const params = Object.fromEntries(_url?.entries());
|
||||||
updateIframeStyle();
|
_current.value = params;
|
||||||
});
|
// url.value = resp.result as string;
|
||||||
|
// nextTick(() => {
|
||||||
|
// updateIframeStyle();
|
||||||
|
// });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (props.current?.channelProvider === 'notifier-dingTalk') {
|
if (props.current?.channelProvider === 'notifier-dingTalk') {
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
<template><div id="login_container"></div></template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { createScript } from '@/utils/document';
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
data: {
|
||||||
|
type: Object,
|
||||||
|
default: () => {}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const initData = async (appid: string) => {
|
||||||
|
const _script = await createScript(
|
||||||
|
'http://res.wx.qq.com/connect/zh_CN/htmledition/js/wxLogin.js',
|
||||||
|
);
|
||||||
|
if(_script) {
|
||||||
|
console.log(props.data)
|
||||||
|
const obj = new WxLogin({
|
||||||
|
id: 'login_container',
|
||||||
|
appid: props.data.appid,
|
||||||
|
redirect_uri: props.data.redirect_uri,
|
||||||
|
state: props.data.state,
|
||||||
|
scope: 'snsapi_login',
|
||||||
|
style: 'white'
|
||||||
|
});
|
||||||
|
console.log(obj)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
watchEffect(() => {
|
||||||
|
if(props.data?.appid) {
|
||||||
|
initData(props.data?.appid)
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
</script>
|
Loading…
Reference in New Issue