UNPKG

ttk-app-core

Version:
80 lines (71 loc) 2.51 kB
import React from 'react' import { action as MetaAction } from 'edf-meta-engine' import config from './config' import { FadeSlider } from 'edf-component' import moment from 'moment' class action { constructor(option) { this.metaAction = option.metaAction this.config = config.current this.webapi = this.config.webapi } onInit = ({ component, injections }) => { this.component = component this.injections = injections injections.reduce('init') this.load() } load = async () => { const response = this.component.props.data this.injections.reduce('load', response) } handleClick = async (url) => { let flag = url if(url == 'more') url = 'https://www.jchl.com/portal/tk/training/page/1/video_course.html' let xhr = new XMLHttpRequest() xhr.open('post','/v1/edf/connector/getcodefromuc', false) xhr.setRequestHeader('Accept', 'application/json') xhr.setRequestHeader('Content-Type', 'application/json') xhr.setRequestHeader('token', sessionStorage.getItem('_accessToken')) xhr.onreadystatechange = function() { if(xhr.readyState == 4 && xhr.status == 200) { let param = JSON.parse(xhr.responseText) if(param.value == null){ window.open(url) }else { if(flag == 'more') { window.open(url+ '?' + param.value.replace('&', '')) }else { window.open(url + param.value) } } } } xhr.send() } getCarouselData = (data) => { data = data.slice(0,3) return ( <FadeSlider> { data.map(item => { return ( <img src={item.logo} onClick={this.handleClick.bind(this, item.videoUrl)}/> ) }) } </FadeSlider> ) } parseTime = (v, format) => { return moment(v).format(format) } } export default function creator(option) { const metaAction = new MetaAction(option), o = new action({ ...option, metaAction }), ret = { ...metaAction, ...o } metaAction.config({ metaHandlers: ret }) return ret }