import classnames from "classnames"; import dayjs from "dayjs"; import Taro from "@tarojs/taro"; import { Component, PropsWithChildren } from "react"; import { Block, View, Text, Image, PageMeta, Button } from "@tarojs/components"; /*** redux ***/ import { connect } from "react-redux"; import { userRefresh } from "../../store/features/userInfo"; import { otherSettingRefresh } from "../../store/features/otherSetting"; import { setIndexFlag } from "../../store/features/global"; /*** redux end ***/ /** 自定义组件 **/ import AtCalendar from "../../components/calendar"; import PopupPrivacy from "../../components/popup/popup-privacy"; import PopupAlert from "../../components/popup/popup-alert"; import PopupSiteSwiper from "../../components/popup/popup-site-swiper"; import type CustomTabBar from "../../custom-tab-bar"; import Navbar from "../../components/navbar/navbar"; /** 自定义组件 **/ import { Toast } from "@antmjs/vantui"; import { RefreshWxUserInfo, GetNoReadMessageNum, GetOtherSetting, GetSitePopupList, } from "../../utils/Interface"; // css引入 import "taro-ui/rn/style/components/calendar.scss"; import "./index.less"; import { go } from "../../utils/traoAPI"; // PropsWithChildren class Index extends Component { pageCtx = Taro.getCurrentInstance().page; constructor(props) { super(props); this.state = { isShowPrivacyPopup: false, isShowSiteSwiper: false, isNotRegister: false, // 是否未注册 isDev: false, // 正在开发提示 sitePopupList: [], // 站点管理列表 // imgUrl: this.app.globalData.imgUrl, userinfo: { mobile: this.props.mobile, }, connectInstrument: {}, yiqiinfo: {}, titleHeight: "", menu: { top: 44, height: 0, }, list: [], params: "", messageCount: Taro.getStorageSync("messageCount") || 0, offlineDialogType: 1, //1离线弹窗 2升级弹窗 offlineDialogForce: 0, //0可选是否升级 1强制升级 versioninfo: {}, //仪器版本号, info: {}, // 护理推荐点击参与活动的信息 weekinfo: undefined, currentDate: dayjs().format("YYYY-MM-DD"), }; } async onLoad() { const isFirst = Taro.getStorageSync("isWelcome"); if (!isFirst) { go("/pages/initiate/initiate"); } const menu = Taro.getMenuButtonBoundingClientRect(); this.setState({ menu }); } componentDidMount() {} componentWillUnmount() {} componentDidShow() { const tabbar = Taro.getTabBar(this.pageCtx); tabbar?.setSelected(0); this.showInit(); } componentDidHide() {} showInit() { const isFirst = Taro.getStorageSync("isWelcome"); const mobile = Taro.getStorageSync("mobile"); if (isFirst) { this.checkShowPrivacyPopup(); // this.GetOtherSetting(); // 获取小程序设置:商城地址和版本 if (mobile) { this.GetNoReadMessageNum(); // 查询是否有消息 this.RefreshWxUserInfo(); this.GetSitePopupList(); } } } // 检测是否弹出隐私协议 checkShowPrivacyPopup() { const isPrivacy = Taro.getStorageSync("isPrivacy"); if (isPrivacy !== "true") { Taro.getPrivacySetting({ success: (res) => { // console.log("检测是否弹出隐私协议", res); // 返回结果为: res = { needAuthorization: true/false, privacyContractName: '《xxx隐私保护指引》' } if (res.needAuthorization) { // 需要弹出隐私协议 const isPrivacyPopup = Taro.getStorageSync("isPrivacyPopup"); if (!isPrivacyPopup) { // 隐私确认弹窗 this.setState({ isShowPrivacyPopup: true }); Taro.setStorageSync("isPrivacy", "true"); } } else { // 用户已经同意过隐私协议,所以不需要再弹出隐私协议,也能调用隐私接口 } }, fail: () => {}, complete: () => {}, }); } } // 刷新用户信息 RefreshWxUserInfo = async () => { let res = await RefreshWxUserInfo(); if (res.data.code === 200) { this.props.userRefresh(res.data.data); } }; // 获取消息数量 GetNoReadMessageNum = async () => { let res = await GetNoReadMessageNum(); if (res.data.code === 200) { Taro.setStorageSync("messageCount", res.data.data); this.setState({ messagecount: res.data.data }); } }; // 获取小程序设置 GetOtherSetting = async () => { let res = await GetOtherSetting(); if (res.data.code === 200) { this.props.otherSettingRefresh(res.data.data); } }; // 获取站点管理-弹窗列表 1-首页 2-发现模块 3-活动模块 GetSitePopupList = async () => { let res = await GetSitePopupList(1); if (res.data.code === 200) { // console.log("GetSitePopupList", res); this.setState({ sitePopupList: res.data.data, isShowSiteSwiper: true }); } }; goRegister() { go("/pages/register/register"); } // 新增设备 addNewDevice = () => { this.isRegister(); if (this.isRegister()) { // todo go("/pages/instrument/instrument"); } }; // 是否已注册 isRegister() { let mobile = Taro.getStorageSync("mobile"); if (!mobile) { this.alertRegister(); return false; } return true; } showPrivacy = () => { this.setState({ isShowPrivacyPopup: true }); }; closePrivacy = () => { this.setState({ isShowPrivacyPopup: false }); }; closeAlert = () => { this.setState({ isNotRegister: false }); }; public alertRegister = () => { this.setState({ isNotRegister: true }); // 打开弹窗 // if (!this.props.mobile) { // this.setState({ isNotRegister: true }); // 打开弹窗 // return; // } else { // go("/pages/instrument/instrument"); // } }; onTimeChange = (value) => { console.log("onTimeChange", value); this.setState({ currentDate: value }); }; // 护理记录 toNursingRecords = () => { go("/pages/recording/recording"); }; gourl = (e) => { const { url } = e.currentTarget.dataset; if (this.isRegister()) { go(url); } }; closeDev = () => { this.setState({ isDev: false }); }; closeSiteSwiper = () => { this.setState({ isShowSiteSwiper: false }); }; render() { let { currentDate, messagecount, sitePopupList, isShowPrivacyPopup, isNotRegister, isShowSiteSwiper, isDev, } = this.state; return ( {messagecount ? : ""} } > 护理记录 前往护理 添加新设备 您暂时还没有绑定任何设备 ); } } const mapStateToProps = (state) => ({ background: state.navigation.background, mobile: state.userInfo.mobile, }); const mapDispatchToProps = (dispatch) => ({ userRefresh(data) { dispatch(userRefresh(data)); }, otherSettingRefresh(data) { dispatch(otherSettingRefresh(data)); }, setIndexFlag(data) { dispatch(setIndexFlag(data)); }, }); export default connect(mapStateToProps, mapDispatchToProps)(Index);