import FormControl from '@mui/material/FormControl' import Stack from '@mui/material/Stack' import TextField from 'browser/components/UncontrolledTextField' import React, { FC, useContext } from 'react' import { ProjectShape } from '@seleniumhq/side-api' import message from './Message' import Button from '@mui/material/Button' import MenuItem from '@mui/material/MenuItem' import FormHelperText from '@mui/material/FormHelperText' import Select from '@mui/material/Select' import InputLabel from '@mui/material/InputLabel' import { styled } from '@mui/material/styles' import { context } from 'browser/contexts/session' import languageMap from 'browser/I18N/keys' import { FormattedMessage } from 'react-intl' const CustomButton = styled(Button)({ marginLeft: 'auto', marginRight: 'auto', width: '100px', boxShadow: 'none', textTransform: 'none', fontSize: 16, padding: '6px 12px', border: '1px solid', lineHeight: 1.5, backgroundColor: '#0063cc', borderColor: '#0063cc', fontFamily: [ '-apple-system', 'BlinkMacSystemFont', '"Segoe UI"', 'Roboto', '"Helvetica Neue"', 'Arial', 'sans-serif', '"Apple Color Emoji"', '"Segoe UI Emoji"', '"Segoe UI Symbol"', ].join(','), '&:hover': { backgroundColor: '#0069d9', borderColor: '#0062cc', boxShadow: 'none', }, '&:active': { boxShadow: 'none', backgroundColor: '#0062cc', borderColor: '#005cbf', }, '&:focus': { boxShadow: '0 0 0 0.2rem rgba(0,123,255,.5)', }, }) const OutPutSettings: FC = () => { const { project: outPut } = useContext(context) const [options, setOptions] = React.useState([]) const [host, setHost] = React.useState('http://127.0.0.1:9998') const [testPlatform, setTestPlatform] = React.useState( 'http://9.134.118.97/webUiCase/webUiCase' ) const [page, setPage] = React.useState('') const [insertUrl, setInsertUrl] = React.useState( '/webui/case/insertCaseByIde' ) const [pageUrl, setPageUrl] = React.useState('/webui/page/allPage') // 跳转至测试平台 const linkTestPlatform = async (url: string) => { if (url == '' || url == undefined) { message.alertMessage({ content: , duration: 6000, type: 'error', title: , }) } else { await window.sideAPI.windows.requestPlaybackWindow(url) } } /** * 将录制的用例导入到web项目中 * * @param url 导入的url地址 * @param project 用例所属项目 */ const exportToUi = async ( project: ProjectShape, host: string, url: string, pageId: any ) => { if (host === '' || url === '') { message.alertMessage({ content: ( ), duration: 6000, type: 'error', title: , }) } else { try { // 克隆project对象 let projectBackUp = JSON.parse(JSON.stringify(project)) // 将项目id置入克隆对象中 projectBackUp['pageId'] = pageId // 创建要发送的数据对象 const requestData = JSON.stringify(projectBackUp, undefined, 2) // 设置请求头部信息 const headers = new Headers() headers.append('Content-Type', 'application/json') // 构造请求参数 const options = { method: 'POST', body: requestData, headers: headers, } // 发起POST请求并获取响应结果 const response = await fetch(host + url, options) const result = await response.json() const code = result.code if (code !== null || code !== undefined) { if (code === '1000') { message.alertMessage({ content: + result.data[0] + '!', duration: 5000, type: 'success', title: , }) } else { message.alertMessage({ content: ( ), duration: 5000, type: 'error', title: , }) } } return result } catch (error) { console.error(error) } } } const changeUrl = () => { /** * 根据url地址获取项目列表 */ fetch(host + pageUrl) .then((response) => response.json()) .then((data) => { setOptions(data.data) }) .catch((error) => { setOptions([]) setPage('') console.log(error) }) } const checkUrl = () => { /** * 检查url地址是否正确 */ if (host === '' || pageUrl === '') { message.alertMessage({ content: ( ), duration: 5000, type: 'warning', title: , }) } else { changeUrl() } } return ( } name="host" helperText={ } onChange={(e: any) => { setTestPlatform(e.target.value) }} size="small" value={testPlatform} /> } name="host" helperText={ } onBlur={changeUrl} onChange={(e: any) => { setHost(e.target.value) }} size="small" value={host} /> } name="pageUrl" helperText={ } onBlur={changeUrl} onChange={(e: any) => { setPageUrl(e.target.value) }} size="small" value={pageUrl} /> {} { } } name="insertUrl" helperText={ } onChange={(e: any) => { setInsertUrl(e.target.value) }} size="small" value={insertUrl} /> { exportToUi(outPut, host, insertUrl, page) }} > {} ) } export default OutPutSettings