基于Taro.js开发的H5应用
This commit is contained in:
137
src/pages/index/index.tsx
Normal file
137
src/pages/index/index.tsx
Normal file
@@ -0,0 +1,137 @@
|
||||
import './index.scss'
|
||||
import Taro from '@tarojs/taro';
|
||||
// import {useShareAppMessage, useShareTimeline} from "@tarojs/taro"
|
||||
import {useEffect, useState} from "react";
|
||||
import {getSiteInfo} from "@/api/layout";
|
||||
import Login from "./Login";
|
||||
import Banner from "./Banner";
|
||||
import Menu from "./Menu";
|
||||
import TopBanner from "./TopBanner";
|
||||
import TabBar from "@/components/TabBar";
|
||||
|
||||
export interface Market {
|
||||
// 自增ID
|
||||
id?: number;
|
||||
latitude?: number;
|
||||
longitude?: number;
|
||||
name?: string;
|
||||
title?: string;
|
||||
}
|
||||
|
||||
function Home() {
|
||||
const [loading, setLoading] = useState<boolean>(false)
|
||||
const [IsLogin, setIsLogin] = useState<boolean>(true)
|
||||
const [search, setSearch] = useState(false)
|
||||
|
||||
// useShareTimeline(() => {
|
||||
// return {
|
||||
// title: '注册即可开通 - webSoft云应用',
|
||||
// path: `/pages/index/index`
|
||||
// };
|
||||
// });
|
||||
|
||||
// useShareAppMessage(() => {
|
||||
// return {
|
||||
// title: '注册即可开通 - webSoft云应用',
|
||||
// path: `/pages/index/index`,
|
||||
// success: function (res) {
|
||||
// console.log('分享成功', res);
|
||||
// },
|
||||
// fail: function (res) {
|
||||
// console.log('分享失败', res);
|
||||
// }
|
||||
// };
|
||||
// });
|
||||
|
||||
// const reloadMore = async () => {
|
||||
// setPage(page + 1)
|
||||
// }
|
||||
|
||||
// const showAuthModal = () => {
|
||||
// Taro.showModal({
|
||||
// title: '授权提示',
|
||||
// content: '需要获取您的用户信息',
|
||||
// confirmText: '去授权',
|
||||
// cancelText: '取消',
|
||||
// success: (res) => {
|
||||
// if (res.confirm) {
|
||||
// // 用户点击确认,打开授权设置页面
|
||||
// openSetting();
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// };
|
||||
|
||||
// const openSetting = () => {
|
||||
// // Taro.openSetting:调起客户端小程序设置界面,返回用户设置的操作结果。设置界面只会出现小程序已经向用户请求过的权限。
|
||||
// Taro.openSetting({
|
||||
// success: (res) => {
|
||||
// if (res.authSetting['scope.userInfo']) {
|
||||
// // 用户授权成功,可以获取用户信息
|
||||
// reload();
|
||||
// } else {
|
||||
// // 用户拒绝授权,提示授权失败
|
||||
// Taro.showToast({
|
||||
// title: '授权失败',
|
||||
// icon: 'none'
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// };
|
||||
|
||||
// 登录成功后回调
|
||||
const handleLogin = () => {
|
||||
setIsLogin(true)
|
||||
Taro.showTabBar()
|
||||
reload();
|
||||
}
|
||||
|
||||
const reload = async () => {
|
||||
setLoading(true)
|
||||
if (!Taro.getStorageSync('access_token')) {
|
||||
return false;
|
||||
}
|
||||
console.log(loading)
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
// 获取站点信息
|
||||
getSiteInfo().then((data) => {
|
||||
console.log(data, 'siteInfo')
|
||||
if (data.search) {
|
||||
setSearch(false);
|
||||
}
|
||||
})
|
||||
// Taro.getSetting:获取用户的当前设置。返回值中只会出现小程序已经向用户请求过的权限。
|
||||
// Taro.getSetting({
|
||||
// success: (res) => {
|
||||
// if (res.authSetting['scope.userInfo']) {
|
||||
// // 用户已经授权过,可以直接获取用户信息
|
||||
// console.log('用户已经授权过,可以直接获取用户信息')
|
||||
// reload().then(() => {
|
||||
// setLoading(false)
|
||||
// });
|
||||
// } else {
|
||||
// // 用户未授权,需要弹出授权窗口
|
||||
// console.log('用户未授权,需要弹出授权窗口')
|
||||
// // showAuthModal();
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// 获取用户信息
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<>
|
||||
{!IsLogin && search ? (<Login done={handleLogin}/>) : (<>
|
||||
<TopBanner/>
|
||||
<Menu/>
|
||||
<Banner/>
|
||||
<TabBar/>
|
||||
</>)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export default Home
|
||||
Reference in New Issue
Block a user