Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
XieYongHong 2023-07-16 00:50:56 +08:00
commit d9ca944945
7 changed files with 73 additions and 31 deletions

View File

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

View File

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

View File

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

View File

@ -1,37 +1,46 @@
<template><div id="login_container"></div></template> <template><div id="login_container"></div></template>
<script lang="ts" setup> <script lang="ts" setup>
import { LocalStore } from '@/utils/comm';
import { createScript } from '@/utils/document'; import { createScript } from '@/utils/document';
const props = defineProps({ const props = defineProps({
data: { data: {
type: Object, type: Object,
default: () => {} default: () => {},
} },
}) });
const timer = ref<any>(null)
const initData = async (appid: string) => { const emits = defineEmits(['success'])
const initData = async () => {
const _script = await createScript( 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) { if (_script) {
console.log(props.data) new WwLogin({
const obj = new WxLogin({
id: 'login_container', id: 'login_container',
appid: props.data.appid, appid: props.data.appid,
redirect_uri: props.data.redirect_uri, redirect_uri: encodeURIComponent(
`${location.origin}/#/oauth/wechat`,
),
state: props.data.state, state: props.data.state,
scope: 'snsapi_login', agentid: props.data.agentid,
style: 'white' self_redirect: true,
}); });
console.log(obj)
} }
}; };
watchEffect(() => { watchEffect(() => {
if(props.data?.appid) { if (props.data?.appid) {
initData(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> </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" :params="params"
:gridColumn="2" :gridColumn="2"
:alertRender="false"
:rowSelection="{ :rowSelection="{
selectedRowKeys: _selectedRowKeys, selectedRowKeys: _selectedRowKeys,
onChange: onSelectChange, onChange: onSelectChange,

View File

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