Commit e4490b83 by FE

share in wechat

parent f24b7235
...@@ -4,7 +4,7 @@ import {CopyToClipboard} from 'react-copy-to-clipboard'; ...@@ -4,7 +4,7 @@ import {CopyToClipboard} from 'react-copy-to-clipboard';
import AceEditor from 'react-ace'; import AceEditor from 'react-ace';
import { Toast } from "antd-mobile" import { Toast } from "antd-mobile"
import {HeaderBar} from '@/common'; import {HeaderBar} from '@/common';
import { browser, http, getParam } from '@/utils'; import { browser, http, getParam, wxShare } from '@/utils';
import './index.scss'; import './index.scss';
import 'ace-builds/src-noconflict/mode-python'; import 'ace-builds/src-noconflict/mode-python';
import 'ace-builds/src-noconflict/theme-dracula'; import 'ace-builds/src-noconflict/theme-dracula';
...@@ -80,13 +80,38 @@ class PythonClass extends Component { ...@@ -80,13 +80,38 @@ class PythonClass extends Component {
}) })
} }
handleToSend = () => { handleToSend = (params) => {
const { history } = this.props; const { history } = this.props;
const { isShare, entryMode } = this.state;
if(browser.isWeixin) { if(browser.isWeixin) {
this.setState({ this.setState({
entryMode: 1 entryMode: 1
}); });
history.push(`/pythonShare?id=${getParam('id')}&type=${getParam('type')}&ques=${getParam('ques')}&from=python`); history.replace(`/pythonShare?id=${getParam('id')}&type=${getParam('type')}&ques=${getParam('ques')}&from=python`);
let title = '';
let labelName = this.formatTitle(params);
if(entryMode !== 0 && !isShare) {
title = `我在${params.course_name}${labelName}遇到了困难`;
}
if(entryMode !== 0 && isShare) {
title = `我已在【${params.course_name}】上运行了行代码了${params.code_lines}`
}
wxShare({
title,
desc: labelName,
link: encodeURI(location.href),
imgUrl: params.course_img,
});
}
}
formatTitle = (params) => {
const { type } = this.state;
if(type === '1') {
return `练习-${params.ques_name}`;
}
if(type === '2') {
return `课堂-${params.video_name}`;
} }
} }
...@@ -110,7 +135,7 @@ class PythonClass extends Component { ...@@ -110,7 +135,7 @@ class PythonClass extends Component {
} }
render() { render() {
const { isWechat, isShare, isExecute, type, entryMode, command, isCopy, data } = this.state; const { isWechat, isShare, isExecute, entryMode, command, isCopy, data } = this.state;
return ( return (
<> <>
<HeaderBar <HeaderBar
...@@ -121,12 +146,12 @@ class PythonClass extends Component { ...@@ -121,12 +146,12 @@ class PythonClass extends Component {
<PythonContent <PythonContent
isWechat={isWechat} isWechat={isWechat}
isShare={isShare} isShare={isShare}
type={type}
isExecute={isExecute} isExecute={isExecute}
entryMode={entryMode} entryMode={entryMode}
isCopy={isCopy} isCopy={isCopy}
command={command} command={command}
data={data} data={data}
labelName={this.formatTitle(data)}
handleToExecute={this.handleToExecute} handleToExecute={this.handleToExecute}
handleToSend={this.handleToSend} handleToSend={this.handleToSend}
copyToSuccess={this.copyToSuccess} copyToSuccess={this.copyToSuccess}
...@@ -158,23 +183,16 @@ function PythonContent(props) { ...@@ -158,23 +183,16 @@ function PythonContent(props) {
isWechat, isWechat,
isShare, isShare,
isExecute, isExecute,
type,
entryMode, entryMode,
isCopy, isCopy,
command, command,
labelName,
data: { head_img, nickname, code_lines, code, result, ques_name, course_name, course_id, video_name }, data: { head_img, nickname, code_lines, code, result, ques_name, course_name, course_id, video_name },
handleToSend, handleToSend,
copyToSuccess, copyToSuccess,
handleToExecute, handleToExecute,
handleToHide handleToHide
} = props; } = props;
let labelName = '';
if(type === '1') {
labelName = `练习-${ques_name}`;
}
if(type === '2') {
labelName = `课堂-${video_name}`;
}
return ( return (
<div className="python-container"> <div className="python-container">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment