taro 小程序组件加载失败
-
/* eslint-disable prefer-const */ import Taro, { Component } from "@tarojs/taro"; import { View, Text } from "@tarojs/components"; import Home from "@/pages/home/home"; import ClHomeLink from '@/components/cl-home-link'; import CourseModule from "@/components/course-module/CourseModule"; import Discover from "@/components/discover/index"; import Mine from "@/pages/mine"; import enterpriseSetting from "@/project-setting/enterprise"; import { connect } from "@tarojs/redux"; import { setHomeNavigationBarTitle } from "@/utils/taro/setNavigations"; import { globalSetNavigationBarColor } from "@/utils/utils"; import store from "@/store"; import connectSocket from "@/utils/connectSocket"; import { getMessageCount } from "@/pages/message-center/service"; import ContactService from "@/pages/home/components/contact-service"; import CreateProject from '@/pages/home/components/create-project-guide'; import SignIn from '@/pages/home/components/sign-in/index'; import GuidePage from '@/pages/home/components/guide-page'; import pageConfig from "./utils/messageRedirect"; import { getDiscoverDot, updateDiscoverDot,queryFace } from "./services/enteriseRequest"; import "./enterprise.scss"; if(process.env.TARO_ENV === 'h5') { window.getParams = function(event) { let urlParams = []; if (!!event.url){ urlParams = (event.url + "&readId=" + event.id) .split(":/")[1] .split("?")[1] .split("&"); let query = {}; urlParams.forEach((val) => { query[val.split("=")[0]] = val.split("=")[1]; }); pageConfig.redirect(query, store.getState()); } }; } @connect(({ userInfo, local, themeColor, customSetting }) => ({ enterpriseName: userInfo.enterpriseName, userId: userInfo.userId, enterpriseId: userInfo.enterpriseId, local: local, themeColor: themeColor, isIpx: userInfo.isIpx, isVip: userInfo.isVip, isAdmin: userInfo.isAdmin, isCorpCreator: userInfo.isCorpCreator, showMineDot: userInfo.showMineDot, defaultSelect: customSetting.defaultSelect })) class Enterprise extends Component { // static options = { // addGlobalClass: true, // }; constructor(props) { super(props); this.state = { curType: enterpriseSetting(this.props.local).tabsList[0].type, shouldUpdate: false, // 用于控制的刷新 courses: { classify_id: "", classfy_name: "", }, showDot: false, // 发现tab显示小红点 tabs: enterpriseSetting(this.props.local).tabsList, messageCount: 0, hasFaceRecognition: false }; } componentDidMount() { this.getDiscoverDot(); // 我的模块显示圆点 h5显示消息数量 alipay显示是否录入人脸识别 if(process.env.TARO_ENV === 'h5') { getMessageCount().then(res => { const count = Number(res.data.study) + Number(res.data.notice); this.setState({ messageCount: count }); }); }else if(process.env.TARO_ENV === 'alipay'){ this.getMineDot(); } connectSocket.connectSocketFun(this.props.enterpriseId,this.props.userId); } /** * @desc 设置首页导航栏颜色 */ setHomePageNavigationColor = () => { if ( this.state.curType === enterpriseSetting(this.props.local).projectType.study ) { globalSetNavigationBarColor( this.props.themeColor.primaryColor, "#ffffff" ); } else { globalSetNavigationBarColor("#ffffff", "#000000"); } }; /** * @desc 设置子页面导航栏颜色 */ setSubPageNavigationColor = () => { globalSetNavigationBarColor("#ffffff", "#000000"); }; componentDidShow() { this.setNavigationBarTitle(); this.setHomePageNavigationColor(); // 页面显示 this.setState({ shouldUpdate: !this.state.shouldUpdate, }); // 只有 h5 才显示消息入口 if(process.env.TARO_ENV === 'h5') { if(this.state.curType === 'mine') { this.setMessageTitle(); } else { sp&&sp.updateTitleRightView({ isShowRight: false }); } } } setMessageTitle = () => { getMessageCount().then(res => { const count = Number(res.data.study) + Number(res.data.notice); this.setState({ messageCount: count }); if (process.env.TARO_ENV === 'h5') { sp.setNavigationBarRightButton({ title: count > 0 ? `消息(${count})` : '消息', show: true, onSuccess: function() { //按钮点击事件 Taro.navigateTo({ url: "/pages/message-center/index" }); }, }); } }).catch(() => { if (process.env.TARO_ENV === 'h5') { sp.setNavigationBarRightButton({ title: '消息', show: true, onSuccess: function() { //按钮点击事件 Taro.navigateTo({ url: "/pages/message-center/index" }); }, }); } }); } componentDidHide() { if (process.env.TARO_ENV === 'h5') { sp.updateTitleRightView({ isShowRight: false }); } this.setSubPageNavigationColor(); } switchTab(type) { this.setState({ curType: type }, () => { this.setNavigationBarTitle(); this.setHomePageNavigationColor(); if(this.state.curType === 'mine') { this.setMessageTitle(); } else { if (process.env.TARO_ENV === 'h5') { sp.updateTitleRightView({ isShowRight: false }); } } }); } /** * 判断模块类型及是否显示企业名称 * 注意:当用户上次选择了部门即 [defaultSelect] 有值 直接显示 [defaultSelect.name] 部门名称 */ setNavigationBarTitle() { const { defaultSelect } = this.props; let title = ""; enterpriseSetting(this.props.local).tabsList && enterpriseSetting(this.props.local).tabsList.forEach((item) => { if (item.type === this.state.curType) { if (item.enterpriseName) { title = defaultSelect ? defaultSelect.name : this.props.enterpriseName; } else { title = item.name ? item.name : item.defaultName; } } }); if (this.state.curType === "discover") { this.getUpdateDiscoverDot(); } setHomeNavigationBarTitle(title); } getUpdateDiscoverDot() { updateDiscoverDot().then(() => { this.setState({ showDot: false }); }); } getDiscoverDot() { getDiscoverDot().then(res => { this.setState({ showDot: res.data.data.click_flag === "unclicked" }); }); } //钉钉端 我的旁边的小红点 (实际是显示你有没有录入人脸识别) getMineDot() { queryFace().then(res=>{ this.setState({ hasFaceRecognition: res.data.result === 'false' }); }); } render() { const { curType, shouldUpdate, courses, tabs, showDot,messageCount,hasFaceRecognition } = this.state; const { themeColor, isIpx,isVip,isAdmin,isCorpCreator } = this.props; console.log('curType:'+ (curType !== 'course' && (isVip && isAdmin) || !isVip)); const showMineDot = process.env.TARO_ENV === 'h5' ? messageCount > 0 : hasFaceRecognition; // let content = ''; // if (curType === 'study') { // content = (<Home shouldUpdate={shouldUpdate} />); // } // if (curType === 'course') { // content = (<CourseModule courseFilter={courses} shouldUpdate={shouldUpdate} />); // } // if (curType === 'discover') { // content = (<Discover />); // } // if (curType === 'mine') { // content = (<Mine />); // } console.log(curType); return ( <View className={isIpx ? "iphonex-container" : "container"}> {curType === 'study' && ( <Home shouldUpdate={shouldUpdate} /> )} {curType === "course" && ( <CourseModule courseFilter={courses} shouldUpdate={shouldUpdate} /> )} {curType === "discover" && <Discover />} {curType === "mine" && <Mine />} <View className={isIpx ? "fix-iphonex-button" : "tabs"}> {tabs.map((item, index) => { return ( <View className={`tab ${item.type == curType ? "tab_active" : ""}`} key={index} onClick={() => this.switchTab(item.type)} > <Text className={`iconfont ${ item.type == curType ? item.activeIcon : item.icon }`} style={{ fontSize: Taro.pxTransform(42), color: item.type == curType ? themeColor.primaryColor : "#53555B", }} /> {(item.type === "discover" && showDot) || (item.type == "mine" && showMineDot) ? ( <View className='redDot'></View> ) : null} <View className='name' style={{ color: item.type == curType ? themeColor.primaryColor : "#53555B", }} > {item.name} </View> </View> ); })} </View> {/* 联系客服 */} {((curType !== 'course' && curType !== 'discover') && ((isVip && isAdmin) || !isVip)) && <ContactService source={curType}/>} {/* 引导创建学习项目 */} {(isAdmin || isCorpCreator) && <CreateProject/>} {/* 每日签到 */} <SignIn/> {/* 新开通企业的普通学员展示引导页面*/} {!isAdmin && <GuidePage/>} {/* 返回首页的入口 */} <ClHomeLink /> </View> ); } } export default Enterprise;
home组件死活加载不出来是写法有问题吗?