forked from gxwebsoft/mp-10550
117 lines
2.9 KiB
TypeScript
117 lines
2.9 KiB
TypeScript
import Header from './Header';
|
||
import MySearch from "./MySearch";
|
||
import BestSellers from './BestSellers';
|
||
import Taro from '@tarojs/taro';
|
||
import {useShareAppMessage, useShareTimeline} from "@tarojs/taro"
|
||
import {useEffect} from "react";
|
||
import {getSiteInfo} from "@/api/layout";
|
||
import Menu from "./Menu";
|
||
import Banner from "./Banner";
|
||
import './index.scss'
|
||
|
||
function Home() {
|
||
|
||
useShareTimeline(() => {
|
||
return {
|
||
title: '云上商店 - 网宿软件',
|
||
path: `/pages/index/index`
|
||
};
|
||
});
|
||
|
||
useShareAppMessage(() => {
|
||
return {
|
||
title: '云上商店 - 网宿软件',
|
||
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 reload = () => {
|
||
|
||
};
|
||
|
||
useEffect(() => {
|
||
// 获取站点信息
|
||
getSiteInfo().then(() => {
|
||
|
||
})
|
||
// Taro.getSetting:获取用户的当前设置。返回值中只会出现小程序已经向用户请求过的权限。
|
||
Taro.getSetting({
|
||
success: (res) => {
|
||
if (res.authSetting['scope.userInfo']) {
|
||
// 用户已经授权过,可以直接获取用户信息
|
||
console.log('用户已经授权过,可以直接获取用户信息')
|
||
reload();
|
||
} else {
|
||
// 用户未授权,需要弹出授权窗口
|
||
console.log('用户未授权,需要弹出授权窗口')
|
||
showAuthModal();
|
||
}
|
||
}
|
||
});
|
||
// 获取用户信息
|
||
Taro.getUserInfo({
|
||
success: (res) => {
|
||
const avatar = res.userInfo.avatarUrl;
|
||
console.log(avatar,'avatarUrl')
|
||
}
|
||
});
|
||
}, []);
|
||
|
||
return (
|
||
<>
|
||
<Header/>
|
||
<MySearch done={reload}/>
|
||
<div className={'flex flex-col mt-3'}>
|
||
<Banner />
|
||
<Menu />
|
||
<BestSellers/>
|
||
</div>
|
||
</>
|
||
)
|
||
}
|
||
|
||
export default Home
|