import Layout from '@/component/layout';
import './index.scss'
import { WebView as WxWebView } from '@tarojs/components';
import { useParams } from '@/component/routes/hooks/useParams';
import { useMemo } from 'react';
import ReduxUtil from '@/utils/reduxUtil';
import qs from 'qs';
import APPConfig from "@/config";

export interface IWebViewParams {
    url: string
}
// 跳转h5页面
const WebView = () => {
    const params = useParams<IWebViewParams>();
    const url = useMemo(() => {
        let _url = decodeURIComponent(params.url);
        console.log('params.url', decodeURIComponent(params.url))
        // http://192.168.1.109:8080/ 测试本地
        // let _url = 'http://192.168.0.168/apply?channelCode=chengyr'
        const userInfo = ReduxUtil.store.getState().userInfo!;
        console.log(APPConfig, '19-----userInfo', userInfo);
        console.log('APPConfig.APPID', APPConfig.APPID)
        let _qs = qs.stringify({ token: userInfo.token, phone: userInfo.userMobile, userId: userInfo.userId, APPID: APPConfig.APPID }, { encode: false });
        if (_url.indexOf("?") > -1) {
            _url += `&${_qs}`;
        }
        else {
            _url += `?${_qs}`;
        }
        return _url;
    }, [])
    console.log(555, url);
    return (
        <Layout>
            <WxWebView
                src={url} />
        </Layout>
    )
}

export default WebView;