From 72419e2f826031a158173f46d723a672064e37cd Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期二, 31 八月 2021 22:42:51 +0800 Subject: [PATCH] 2021-08-31 --- src/menu/components/code/sandbox/editorcode/index.jsx | 34 +++++++++++++++++++++++++--------- 1 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/menu/components/code/sandbox/editorcode/index.jsx b/src/menu/components/code/sandbox/editorcode/index.jsx index dc9923a..5a51a66 100644 --- a/src/menu/components/code/sandbox/editorcode/index.jsx +++ b/src/menu/components/code/sandbox/editorcode/index.jsx @@ -1,7 +1,7 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' import { is, fromJS } from 'immutable' -import { Icon, Modal, Tabs } from 'antd' +import { Icon, Modal, Tabs, message } from 'antd' import zhCN from '@/locales/zh-CN/model.js' import enUS from '@/locales/en-US/model.js' @@ -18,10 +18,11 @@ } state = { - dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, + dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, visible: false, html: '', - css: '' + css: '', + js: '' } shouldComponentUpdate (nextProps, nextState) { @@ -34,18 +35,19 @@ this.setState({ visible: true, html: config.html || '', - css: config.css || '' + css: config.css || '', + js: config.js || '', }) } verifySubmit = () => { const { config } = this.props - const { html, css } = this.state + const { html, css, js } = this.state this.setState({ visible: false }) - this.props.updateConfig({...config, html, css}) + this.props.updateConfig({...config, html, css, js}) } onHtmlChange = (val) => { @@ -60,8 +62,19 @@ }) } + onJsChange = (val) => { + if (/document\.getElementsByTagName/g.test(val)) { + message.warning('涓洪槻姝唬鐮佸啿绐侊紝js涓笉鍙娇鐢╠ocument.getElementsByTagName鏂规硶!') + return + } + + this.setState({ + js: val + }) + } + render () { - const { visible, dict, html, css } = this.state + const { visible, dict, html, css, js } = this.state return ( <div style={{display: 'inline-block'}}> @@ -79,10 +92,13 @@ > <Tabs> <TabPane tab="HTML" key="HTML"> - <CodeMirror mode="text/xml" value={html} onChange={this.onHtmlChange} /> + <CodeMirror mode="text/xml" theme="cobalt" value={html} onChange={this.onHtmlChange} /> </TabPane> <TabPane tab="CSS" key="CSS"> - <CodeMirror mode="text/css" value={css} onChange={this.onCssChange} /> + <CodeMirror mode="text/css" theme="cobalt" value={css} onChange={this.onCssChange} /> + </TabPane> + <TabPane tab="JS" key="JS"> + <CodeMirror mode="text/javascript" theme="cobalt" value={js} onChange={this.onJsChange} /> </TabPane> </Tabs> </Modal> -- Gitblit v1.8.0