Commit e4490b83 by FE

share in wechat

parent f24b7235
......@@ -4,7 +4,7 @@ import {CopyToClipboard} from 'react-copy-to-clipboard';
import AceEditor from 'react-ace';
import { Toast } from "antd-mobile"
import {HeaderBar} from '@/common';
import { browser, http, getParam } from '@/utils';
import { browser, http, getParam, wxShare } from '@/utils';
import './index.scss';
import 'ace-builds/src-noconflict/mode-python';
import 'ace-builds/src-noconflict/theme-dracula';
......@@ -80,13 +80,38 @@ class PythonClass extends Component {
})
}
handleToSend = () => {
handleToSend = (params) => {
const { history } = this.props;
const { isShare, entryMode } = this.state;
if(browser.isWeixin) {
this.setState({
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 {
}
render() {
const { isWechat, isShare, isExecute, type, entryMode, command, isCopy, data } = this.state;
const { isWechat, isShare, isExecute, entryMode, command, isCopy, data } = this.state;
return (
<>
<HeaderBar
......@@ -121,12 +146,12 @@ class PythonClass extends Component {
<PythonContent
isWechat={isWechat}
isShare={isShare}
type={type}
isExecute={isExecute}
entryMode={entryMode}
isCopy={isCopy}
command={command}
data={data}
labelName={this.formatTitle(data)}
handleToExecute={this.handleToExecute}
handleToSend={this.handleToSend}
copyToSuccess={this.copyToSuccess}
......@@ -158,23 +183,16 @@ function PythonContent(props) {
isWechat,
isShare,
isExecute,
type,
entryMode,
isCopy,
command,
labelName,
data: { head_img, nickname, code_lines, code, result, ques_name, course_name, course_id, video_name },
handleToSend,
copyToSuccess,
handleToExecute,
handleToHide
} = props;
let labelName = '';
if(type === '1') {
labelName = `练习-${ques_name}`;
}
if(type === '2') {
labelName = `课堂-${video_name}`;
}
return (
<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