fix: 修改微信

This commit is contained in:
100011797 2023-07-16 00:49:26 +08:00
parent 2ba9542748
commit 9094f90a59
7 changed files with 73 additions and 31 deletions

View File

@ -275,6 +275,7 @@ const stopAction = () => {
if (ws.value) {
ws.value.unsubscribe?.();
}
window.clearInterval(timer.value)
timer.value = null
};
const clearAction = () => {
@ -286,6 +287,7 @@ onUnmounted(() => {
ws.value.unsubscribe?.();
}
clearAction();
window.clearInterval(timer.value)
timer.value = null
});

View File

@ -79,5 +79,12 @@ export default [
},
component: () => import('@/views/oauth/index.vue')
},
{
path: '/oauth/wechat',
meta: {
title: '微信授权页'
},
component: () => import('@/views/oauth/WeChat.vue')
},
AccountMenu
]

View File

@ -9,10 +9,9 @@
width="100%"
height="100%"
:src="url"
sandbox="allow-forms allow-scripts allow-same-origin allow-popups"
v-if="!loading"
></iframe> -->
<Wechat :data="_current" />
<Wechat :data="_current" @success="onSuccess" />
</div>
</j-spin>
</template>
@ -45,10 +44,10 @@ import {
getUserBind,
getWechatOAuth2,
} from '@/api/account/notificationSubscription';
import { LocalStore } from '@/utils/comm';
import Wechat from './Wechat.vue';
const emit = defineEmits(['close', 'save']);
const props = defineProps({
data: {
//
@ -69,7 +68,7 @@ const getType = computed(() => {
return props.current?.channelProvider;
});
const _current = ref<any>({})
const _current = ref<any>({});
const onBindHandle = (
type: 'notifier-weixin' | 'notifier-dingTalk',
@ -115,11 +114,12 @@ const updateIframeStyle = () => {
const params = Object.fromEntries(_url?.entries());
let authCode = '';
if (props.current?.channelProvider === 'notifier-dingTalk') {
authCode = params?.authCode
} else {
authCode = params?.code
}
authCode = params?.authCode;
}
// else {
// authCode = params?.code;
// }
if (authCode) {
loading.value = true;
onBindHandle(props.current?.channelProvider, authCode);
@ -128,6 +128,7 @@ const updateIframeStyle = () => {
};
const handleSearch = async () => {
LocalStore.remove('wexin_code')
if (props.current?.channelProvider === 'notifier-weixin') {
loading.value = true;
const resp: any = await getWechatOAuth2(
@ -141,10 +142,7 @@ const handleSearch = async () => {
const _url = new URLSearchParams(resp?.result);
const params = Object.fromEntries(_url?.entries());
_current.value = params;
// url.value = resp.result as string;
// nextTick(() => {
// updateIframeStyle();
// });
url.value = resp.result as string;
}
}
if (props.current?.channelProvider === 'notifier-dingTalk') {
@ -164,6 +162,10 @@ const handleSearch = async () => {
}
};
const onSuccess = (code: string) => {
onBindHandle(props.current?.channelProvider, code);
}
watch(
() => props.current,
() => {

View File

@ -1,37 +1,46 @@
<template><div id="login_container"></div></template>
<script lang="ts" setup>
import { LocalStore } from '@/utils/comm';
import { createScript } from '@/utils/document';
const props = defineProps({
data: {
type: Object,
default: () => {}
}
})
const initData = async (appid: string) => {
default: () => {},
},
});
const timer = ref<any>(null)
const emits = defineEmits(['success'])
const initData = async () => {
const _script = await createScript(
'http://res.wx.qq.com/connect/zh_CN/htmledition/js/wxLogin.js',
'https://wwcdn.weixin.qq.com/node/wework/wwopen/js/wwLogin-1.2.7.js',
);
if(_script) {
console.log(props.data)
const obj = new WxLogin({
if (_script) {
new WwLogin({
id: 'login_container',
appid: props.data.appid,
redirect_uri: props.data.redirect_uri,
redirect_uri: encodeURIComponent(
`${location.origin}/#/oauth/wechat`,
),
state: props.data.state,
scope: 'snsapi_login',
style: 'white'
agentid: props.data.agentid,
self_redirect: true,
});
console.log(obj)
}
};
watchEffect(() => {
if(props.data?.appid) {
initData(props.data?.appid)
if (props.data?.appid) {
initData();
}
})
});
timer.value = setInterval(() => {
const code = LocalStore.get('wexin_code')
if(code) {
emits('success', code)
window.clearInterval(timer.value)
timer.value = null
}
}, 2000)
</script>

View File

@ -0,0 +1,20 @@
<template>
<j-spin style="margin: 50%;"></j-spin>
</template>
<script lang="ts" setup>
import { LocalStore } from "@/utils/comm";
watch(
() => location?.hash,
() => {
const _url = new URLSearchParams(location?.hash);
const params = Object.fromEntries(_url?.entries());
LocalStore.set('wexin_code', params?.['#/oauth/wechat?code'])
},
{
deep: true,
immediate: true
}
);
</script>

View File

@ -16,6 +16,7 @@
}"
:params="params"
:gridColumn="2"
:alertRender="false"
:rowSelection="{
selectedRowKeys: _selectedRowKeys,
onChange: onSelectChange,

View File

@ -18,6 +18,7 @@
:params="params"
:gridColumn="2"
:noPagination="true"
:alertRender="false"
:rowSelection="{
selectedRowKeys: _selectedRowKeys,
onChange: onSelectChange,