import React, { useEffect } from 'react'
import { api } from '@/services/api'
/**微信授权中间页 */
const WxCode = React.memo(() => {
    useEffect(() => {
        if (window.location.hash.indexOf('?') !== -1) {
            let url = location.hash?.split('?')[1];
            fetch(api + `/system/mp/authSuccess?${url}`).then(res => {
                console.log(res)
                return res.json()
            }).then((data) => {
                console.log('data==>',data)
                if (data?.code == 200) {
                    localStorage.setItem("code", "ok");
                    console.log('执行成功逻辑====>',localStorage.getItem('code'))
                }
                if (data?.code == 500) {
                    localStorage.setItem("code", "false");
                    localStorage.setItem("errMsg", data?.msg);
                    console.log('执行失败逻辑====>',localStorage.getItem('code'),localStorage.getItem('errMsg'))
                }
                window.close()
            })
        }
    }, [])

    return <div></div>
})

export default WxCode