|
|
|
@ -1,6 +1,4 @@ |
|
|
|
|
import Taro, { setGlobalDataPlugin, useDidShow, useLaunch, useLoad, usePullDownRefresh } from '@tarojs/taro' |
|
|
|
|
import { Component, PropsWithChildren, useEffect, useState } from 'react' |
|
|
|
|
// import 'taro-ui/dist/style/index.scss'
|
|
|
|
|
import Taro, { useDidShow, useLaunch, useDidHide } from '@tarojs/taro' |
|
|
|
|
import "taro-ui/dist/style/components/accordion.scss"; |
|
|
|
|
import "taro-ui/dist/style/components/icon.scss"; |
|
|
|
|
import './app.less' |
|
|
|
@ -8,6 +6,7 @@ import './app.less' |
|
|
|
|
export default function App(props: any) { |
|
|
|
|
useDidShow(()=>{ |
|
|
|
|
console.log('进入小程序并登录') |
|
|
|
|
Taro.setStorageSync('EntryTime', Date.now()) // 记录进入小程序的时间
|
|
|
|
|
Taro.login({ |
|
|
|
|
success:function(res) { |
|
|
|
|
console.log('微信登录成功', res.code) |
|
|
|
@ -38,6 +37,27 @@ export default function App(props: any) { |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
useDidHide(() => { |
|
|
|
|
const time = Taro.getStorageSync('EntryTime') |
|
|
|
|
if (time) { |
|
|
|
|
const duration = parseInt(((Date.now() - time) / 1000).toString()) |
|
|
|
|
Taro.request({ |
|
|
|
|
method: 'POST', |
|
|
|
|
url: 'https://interapi.jm-kid.com/api/user/online/duration', |
|
|
|
|
header: { |
|
|
|
|
authorization: `bearer ${Taro.getStorageSync('UserToken')}` |
|
|
|
|
}, |
|
|
|
|
data: { |
|
|
|
|
timestamp: Date.now(), |
|
|
|
|
duration |
|
|
|
|
}, |
|
|
|
|
success: (res: any) => { |
|
|
|
|
console.log('小程序离开:', res, duration) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
useLaunch(()=>{ |
|
|
|
|
const updateManager = Taro.getUpdateManager() |
|
|
|
|
updateManager.onCheckForUpdate(function (res) { |
|
|
|
|