基于Taro.js开发的H5应用

This commit is contained in:
2025-07-05 23:13:44 +08:00
commit 3db95dbe9b
262 changed files with 18029 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
export default definePageConfig({
navigationBarTitleText: '学习'
})

View File

@@ -0,0 +1,50 @@
import {useEffect, useState} from "react";
import {ArrowRight} from '@nutui/icons-react-taro'
import {pageCmsArticle} from "@/api/cms/cmsArticle";
import {CmsArticle} from "@/api/cms/cmsArticle/model";
import Taro from '@tarojs/taro'
/**
* 文章终极列表
* @constructor
*/
const Article = () => {
// const {params} = useRouter();
// const [categoryId, setCategoryId] = useState<number>(3494)
const [list, setList] = useState<CmsArticle[]>([])
const reload = () => {
// if (params.id) {
// setCategoryId(Number(params.id))
// }
pageCmsArticle({}).then(res => {
if (res?.list) {
setList(res?.list)
}
})
}
useEffect(() => {
reload()
}, [])
return (
<div className={'px-3 mt-4 mb-10'}>
<div className={'flex flex-col justify-between items-center bg-white rounded-lg p-4'}>
<div className={'bg-white w-full'}>
{
list.map((item, index) => {
return (
<div key={index} className={'flex justify-between items-center py-2'} onClick={() => Taro.navigateTo({url: `/cms/help?id=${item.articleId}`}) }>
<div className={'text-sm'}>{item.title}</div>
<ArrowRight color={'#cccccc'} size={18} />
</div>
)
})
}
</div>
</div>
</div>
)
}
export default Article

View File

@@ -0,0 +1,37 @@
import { useEffect, useState } from 'react'
import { Swiper } from '@nutui/nutui-react-taro'
import {CmsAd} from "@/api/cms/cmsAd/model";
import {pageCmsAd} from "@/api/cms/cmsAd";
const MyPage = () => {
const [item, setItem] = useState<CmsAd>()
const [height, setHeight] = useState<string>()
const reload = () => {
pageCmsAd({keywords: '幻灯片'}).then(data => {
console.log(data,'幻灯片')
if(data && data?.count > 0){
const cmsAd = data.list[0];
setHeight(cmsAd.height)
setItem(data.list[0])
}
})
}
useEffect(() => {
reload()
}, [])
return (
<>
<Swiper defaultValue={0} height={height} indicator style={{ height: height + 'px' }}>
{item?.imageList?.map((item) => (
<Swiper.Item key={item}>
<img width="100%" height="100%" src={item.url} alt="" style={{ height: height + 'px' }} />
</Swiper.Item>
))}
</Swiper>
</>
)
}
export default MyPage

View File

@@ -0,0 +1,42 @@
import {useEffect} from "react";
import {Image, Space} from '@nutui/nutui-react-taro'
import Taro from '@tarojs/taro'
const BestSellers = (props: any) => {
const reload = () => {
}
useEffect(() => {
reload()
}, [])
return (
<div className={'px-2 mb-4'}>
<div className={'flex flex-col justify-between items-center rounded-lg p-3'}>
{props.data?.map((item, index) => {
return (
<div key={index} className={'flex bg-white rounded-lg w-full p-3 mb-2'}
onClick={() => Taro.navigateTo({url: '/hjm/location?id=' + item.id})}>
<Image src={item.image} mode={'scaleToFill'}
radius="10%" width="80" height="80"/>
<div className={'mx-3 flex flex-col'}>
<Space direction={'vertical'}>
<div className={'car-no text-lg font-bold'}>{item.code}</div>
<div className={'flex text-xs text-gray-500'}><span
className={'text-gray-700'}>{item.parentOrganization}</span></div>
<div className={'flex text-xs text-gray-500'}><span className={'text-green-600'}>{item.insuranceStatus}</span>
</div>
<div className={'flex text-xs text-gray-500'}><span
className={'text-gray-700'}>{item.driver}</span></div>
</Space>
</div>
</div>
)
})}
</div>
<div style={{height: '170px'}}></div>
</div>
)
}
export default BestSellers

69
src/pages/index/Chart.tsx Normal file
View File

@@ -0,0 +1,69 @@
import {useEffect, useState} from "react";
import {Tabs, TabPane} from '@nutui/nutui-react-taro'
const list = [
{
title: '今天',
id: 1
},
{
title: '昨天',
id: 2
},
{
title: '过去7天',
id: 3
},
{
title: '过去30天',
id: 4
}
]
const Chart = () => {
const [tapIndex, setTapIndex] = useState<string | number>('0')
const reload = () => {
}
useEffect(() => {
reload()
}, [])
return (
<>
<Tabs
align={'left'}
tabStyle={{position: 'sticky', top: '0px'}}
value={tapIndex}
onChange={(paneKey) => {
setTapIndex(paneKey)
}}
>
{
list?.map((item, index) => {
return (
<TabPane key={index} title={item.title}/>
)
})
}
</Tabs>
{
list?.map((item, index) => {
console.log(item.title)
return (
<div key={index} className={'px-3'}>
{
tapIndex != index ? null :
<div className={'bg-white rounded-lg p-4 flex justify-center items-center text-center text-gray-300'} style={{height: '200px'}}>
线
</div>
}
</div>
)
})
}
</>
)
}
export default Chart

118
src/pages/index/Header.tsx Normal file
View File

@@ -0,0 +1,118 @@
import {useEffect, useState} from "react";
import Taro from '@tarojs/taro';
import {Button, Space} from '@nutui/nutui-react-taro'
import {TriangleDown} from '@nutui/icons-react-taro'
import {Popup, Avatar, NavBar} from '@nutui/nutui-react-taro'
import {TenantId} from "@/utils/config";
const Header = (props: any) => {
const [IsLogin, setIsLogin] = useState<boolean>(true)
const [showBasic, setShowBasic] = useState(false)
const [statusBarHeight, setStatusBarHeight] = useState<number>()
const onNav = () => {
if (!IsLogin) {
return false;
}
Taro.switchTab({
url: '/pages/user/user',
})
}
const reload = () => {
Taro.getSystemInfo({
success: (res) => {
setStatusBarHeight(res.statusBarHeight)
},
})
}
/* 获取用户手机号 */
const handleGetPhoneNumber = ({detail}) => {
const {code, encryptedData, iv} = detail
Taro.login({
success: function () {
if (code) {
Taro.request({
url: 'https://server.gxwebsoft.com/api/wx-login/loginByMpWxPhone',
method: 'POST',
data: {
code,
encryptedData,
iv,
notVerifyPhone: true,
refereeId: 0,
sceneType: 'save_referee',
tenantId: TenantId
},
header: {
'content-type': 'application/json',
TenantId
},
success: function (res) {
Taro.setStorageSync('access_token', res.data.data.access_token)
Taro.setStorageSync('UserId', res.data.data.user.userId)
setIsLogin(true)
// 重新加载小程序
Taro.reLaunch({
url: '/pages/index/index'
})
}
})
} else {
console.log('登录失败!')
}
}
})
}
useEffect(() => {
reload()
}, [])
return (
<>
<NavBar
fixed={true}
style={{marginTop: `${statusBarHeight}px`, backgroundColor: 'transparent'}}
onBackClick={() => {
}}
left={
!IsLogin ? (
<div style={{display: 'flex', alignItems: 'center'}}>
<Button style={{color: '#000'}} open-type="getPhoneNumber" onGetPhoneNumber={handleGetPhoneNumber}>
<Space>
<Avatar
size="22"
src={props.user?.avatar}
/>
<span style={{color: '#000'}}>{props.user?.nickname}</span>
</Space>
</Button>
<TriangleDown size={9}/>
</div>
) : (
<div style={{display: 'flex', alignItems: 'center', gap: '8px'}} onClick={onNav}>
<Avatar
size="22"
src={props.user?.avatar}
/>
{props.user?.nickname}
<TriangleDown size={9}/>
</div>
)}>
</NavBar>
<Popup
visible={showBasic}
position="bottom"
style={{width: '100%', height: '100%'}}
onClose={() => {
setShowBasic(false)
}}
>
<div style={{padding: '12px 0', fontWeight: 'bold', textAlign: 'center'}}></div>
</Popup>
</>
)
}
export default Header

68
src/pages/index/Help.tsx Normal file
View File

@@ -0,0 +1,68 @@
import {useEffect, useState} from "react";
import {ArrowRight} from '@nutui/icons-react-taro'
import {CmsArticle} from "@/api/cms/cmsArticle/model";
import Taro from '@tarojs/taro'
import {useRouter} from '@tarojs/taro'
import {BaseUrl} from "@/utils/config";
import {TEMPLATE_ID} from "@/utils/server";
/**
* 帮助中心
* @constructor
*/
const Help = () => {
const {params} = useRouter();
const [categoryId, setCategoryId] = useState<number>(3494)
const [list, setList] = useState<CmsArticle[]>([])
const reload = () => {
if (params.id) {
setCategoryId(Number(params.id))
}
Taro.request({
url: BaseUrl + '/cms/cms-article/page',
method: 'GET',
data: {
categoryId
},
header: {
'content-type': 'application/json',
TenantId: TEMPLATE_ID
},
success: function (res) {
const data = res.data.data;
if (data?.list) {
setList(data?.list)
}
}
})
}
useEffect(() => {
reload()
}, [])
return (
<div className={'px-3 mb-10'}>
<div className={'flex flex-col justify-between items-center bg-white rounded-lg p-4'}>
<div className={'title-bar flex justify-between items-center w-full mb-2'}>
<div className={'font-bold text-lg flex text-gray-800 justify-center items-center'}></div>
<a className={'text-gray-400 text-sm'} onClick={() => Taro.navigateTo({url: `/cms/article?id=${categoryId}`})}></a>
</div>
<div className={'bg-white min-h-36 w-full'}>
{
list.map((item, index) => {
return (
<div key={index} className={'flex justify-between items-center py-2'} onClick={() => Taro.navigateTo({url: `/cms/help?id=${item.articleId}`}) }>
<div className={'text-sm'}>{item.title}</div>
<ArrowRight color={'#cccccc'} size={18} />
</div>
)
})
}
</div>
</div>
</div>
)
}
export default Help

106
src/pages/index/Login.tsx Normal file
View File

@@ -0,0 +1,106 @@
import {useEffect, useState} from "react";
import Taro from '@tarojs/taro'
import {Input, Radio, Button} from '@nutui/nutui-react-taro'
import {TenantId} from "@/utils/config";
import './login.scss';
import {saveStorageByLoginUser} from "@/utils/server";
const Login = (props:any) => {
const [isAgree, setIsAgree] = useState(false)
const [env, setEnv] = useState<string>()
/* 获取用户手机号 */
const handleGetPhoneNumber = ({detail}) => {
const {code, encryptedData, iv} = detail
Taro.login({
success: function () {
if (code) {
Taro.request({
url: 'https://server.gxwebsoft.com/api/wx-login/loginByMpWxPhone',
method: 'POST',
data: {
code,
encryptedData,
iv,
notVerifyPhone: true,
refereeId: 0,
sceneType: 'save_referee',
tenantId: TenantId
},
header: {
'content-type': 'application/json',
TenantId
},
success: function (res) {
saveStorageByLoginUser(res.data.data.access_token,res.data.data.user)
props.done(res.data.data.user);
}
})
} else {
console.log('登录失败!')
}
}
})
}
const reload = () => {
Taro.hideTabBar()
setEnv(Taro.getEnv())
}
useEffect(() => {
reload()
}, [])
return (
<>
<div style={{height: '80vh'}} className={'flex flex-col justify-center px-5'}>
<div className={'text-3xl text-center py-5 font-normal mb-10 '}></div>
{
env === 'WEAPP' && (
<>
<div className={'flex flex-col w-full text-white rounded-full justify-between items-center my-2'} style={{ background: 'linear-gradient(to right, #7e22ce, #9333ea)'}}>
<Button open-type="getPhoneNumber" onGetPhoneNumber={handleGetPhoneNumber}>
</Button>
</div>
</>
)
}
{
env === 'WEB' && (
<>
<div className={'flex flex-col justify-between items-center my-2'}>
<Input type="text" placeholder="手机号" maxLength={11}
style={{backgroundColor: '#ffffff', borderRadius: '8px'}}/>
</div>
<div className={'flex flex-col justify-between items-center my-2'}>
<Input type="password" placeholder="密码" style={{backgroundColor: '#ffffff', borderRadius: '8px'}}/>
</div>
<div className={'flex justify-between my-2 text-left px-1'}>
<a href={'#'} className={'text-blue-600 text-sm'}
onClick={() => Taro.navigateTo({url: '/passport/forget'})}></a>
<a href={'#'} className={'text-blue-600 text-sm'}
onClick={() => Taro.navigateTo({url: '/passport/setting'})}></a>
</div>
<div className={'flex justify-center my-5'}>
<Button type="info" size={'large'} className={'w-full rounded-lg p-2'} disabled={!isAgree}></Button>
</div>
<div className={'w-full bottom-20 my-2 flex justify-center text-sm items-center text-center'}>
<a href={''} onClick={() => Taro.navigateTo({url: '/passport/register'})}
className={'text-blue-600'}></a>
</div>
<div className={'my-2 flex fixed bottom-20 text-sm items-center px-1'}>
<Radio style={{color: '#333333'}} checked={isAgree} onClick={() => setIsAgree(!isAgree)}></Radio>
<span className={'text-gray-400'} onClick={() => setIsAgree(!isAgree)}></span><a
onClick={() => Taro.navigateTo({url: '/passport/agreement'})}
className={'text-blue-600'}></a>
</div>
</>
)
}
</div>
</>
)
}
export default Login

113
src/pages/index/Menu.tsx Normal file
View File

@@ -0,0 +1,113 @@
import {useEffect, useState} from 'react'
import {navigateTo} from '@tarojs/taro'
import Taro from '@tarojs/taro'
import {Button} from '@tarojs/components';
import {Image} from '@nutui/nutui-react-taro'
import {getSiteInfo} from "@/api/layout";
import {TenantId} from "@/utils/config";
import {CmsNavigation} from "@/api/cms/cmsNavigation/model";
const Page = () => {
const [loading, setLoading] = useState(true)
const [isLogin, setIsLogin] = useState<boolean>(false)
const [navItems, setNavItems] = useState<CmsNavigation[]>([])
/* 获取用户手机号 */
const handleGetPhoneNumber = ({detail}) => {
const {code, encryptedData, iv} = detail
Taro.login({
success: function () {
if (code) {
Taro.request({
url: 'https://server.gxwebsoft.com/api/wx-login/loginByMpWxPhone',
method: 'POST',
data: {
code,
encryptedData,
iv,
notVerifyPhone: true,
refereeId: 0,
sceneType: 'save_referee',
tenantId: TenantId
},
header: {
'content-type': 'application/json',
TenantId
},
success: function (res) {
Taro.setStorageSync('access_token', res.data.data.access_token)
Taro.setStorageSync('UserId', res.data.data.user.userId)
Taro.setStorageSync('Phone', res.data.data.user.phone)
setIsLogin(true)
Taro.showToast({
title: '登录成功',
icon: 'success'
});
}
})
} else {
console.log('登录失败!')
}
}
})
}
const onLogin = (item: any) => {
if(!isLogin){
return navigateTo({url: `/pages/category/category?id=${item.navigationId}`})
}else {
// 善款明细
if(item.navigationId == 4119){
return navigateTo({url: `/bszx/pay-record/pay-record`})
}
return navigateTo({url: `/pages/category/category?id=${item.navigationId}`})
}
}
const reload = () => {
getSiteInfo().then(res => {
console.log(res);
console.log(res.topNavs,'top');
setNavItems(res.topNavs || []);
})
setLoading(false);
};
useEffect(() => {
reload();
}, [])
return (
<div className={'my-3'}>
<div>
<div className={'flex justify-between pb-2 px-1'}>
{
navItems.map((item, index) => (
<div key={index} className={'text-center'}>
{
isLogin && !loading ?
<div className={'flex flex-col justify-center items-center'} onClick={() => {
onLogin(item)
}}>
<Image src={item.icon} height={28} width={28}/>
<div className={'mt-2'} style={{fontSize: '15px'}}>{item?.title}</div>
</div>
:
<Button className={'text-white'} open-type="getPhoneNumber" onGetPhoneNumber={handleGetPhoneNumber}>
<div className={'flex flex-col justify-center items-center'}>
<Image src={item.icon} height={28} width={28}/>
<div className={'mt-2 text-gray-700'} style={{fontSize: '15px'}}>{item?.title}</div>
</div>
</Button>
}
</div>
))
}
</div>
</div>
</div>
)
}
export default Page

View File

@@ -0,0 +1,29 @@
import {useEffect, useState} from "react";
import {Input, Button} from '@nutui/nutui-react-taro'
import {copyText} from "@/utils/common";
import Taro from '@tarojs/taro'
const SiteUrl = (props: any) => {
const [siteUrl, setSiteUrl] = useState<string>('')
const reload = () => {
if(props.tenantId){
setSiteUrl(`https://${props.tenantId}.shoplnk.cn`)
}else {
setSiteUrl(`https://${Taro.getStorageSync('TenantId')}.shoplnk.cn`)
}
}
useEffect(() => {
reload()
}, [props])
return (
<div className={'px-3 mt-1 mb-4'}>
<div className={'flex justify-between items-center bg-gray-300 rounded-lg pr-2'}>
<Input type="text" value={siteUrl} disabled style={{backgroundColor: '#d1d5db', borderRadius: '8px'}}/>
<Button type={'info'} onClick={() => copyText(siteUrl)}></Button>
</div>
</div>
)
}
export default SiteUrl

View File

@@ -0,0 +1,33 @@
import { useEffect, useState } from 'react'
import { Swiper } from '@nutui/nutui-react-taro'
import {CmsAd} from "@/api/cms/cmsAd/model";
import {pageCmsAd} from "@/api/cms/cmsAd";
const MyPage = () => {
const [item, setItem] = useState<CmsAd>()
const reload = () => {
pageCmsAd({keywords: 'TopBanner'}).then(data => {
console.log(data,'幻灯片')
if(data && data?.count > 0){
setItem(data.list[0])
}
})
}
useEffect(() => {
reload()
}, [])
return (
<>
<Swiper defaultValue={0} height={279} indicator style={{ height: '280px' }}>
{item?.imageList?.map((item) => (
<Swiper.Item key={item}>
<img width="100%" height="100%" src={item.url} alt="" style={{ height: '280px' }} />
</Swiper.Item>
))}
</Swiper>
</>
)
}
export default MyPage

View File

@@ -0,0 +1,4 @@
export default definePageConfig({
navigationBarTitleText: '传承红色基因,担当强军重任',
navigationBarTextStyle: 'black'
})

View File

@@ -0,0 +1,2 @@
page {
}

137
src/pages/index/index.tsx Normal file
View 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

View File

@@ -0,0 +1,10 @@
// 微信授权按钮的特殊样式
button[open-type="getPhoneNumber"] {
width: 100%;
padding: 8px 0 !important;
height: 80px;
color: #ffffff !important;
margin: 0 !important;
border: none !important;
border-radius: 50px !important;
}

View File

@@ -0,0 +1,5 @@
export default definePageConfig({
navigationBarTitleText: '商品列表',
navigationBarTextStyle: 'black',
navigationStyle: 'custom'
})

64
src/pages/kefu/kefu.tsx Normal file
View File

@@ -0,0 +1,64 @@
import {useEffect, useState} from "react"; // 添加 useCallback 引入
import Taro, {useShareAppMessage, useShareTimeline} from '@tarojs/taro';
import {Space, NavBar} from '@nutui/nutui-react-taro'
import {Search, Received, Scan} from '@nutui/icons-react-taro'
function Kefu() {
const [statusBarHeight, setStatusBarHeight] = useState<number>()
useShareTimeline(() => {
return {
title: '注册即可开通 - webSoft云应用'
};
});
useShareAppMessage(() => {
return {
title: '注册即可开通 - webSoft云应用',
success: function (res) {
console.log('分享成功', res);
},
fail: function (res) {
console.log('分享失败', res);
}
};
});
useEffect(() => {
Taro.getSystemInfo({
success: (res) => {
setStatusBarHeight(res.statusBarHeight)
},
})
// 设置导航栏背景色(含状态栏)
Taro.setNavigationBarColor({
backgroundColor: '#ffffff', // 状态栏+导航栏背景色
frontColor: 'black', // 状态栏文字颜色(仅支持 black/white
});
}, []); // 新增: 添加滚动事件监听
return (
<>
<NavBar
fixed={true}
style={{marginTop: `${statusBarHeight}px`}}
onBackClick={() => {
}}
left={
<>
<div className={'flex justify-between items-center w-full'}>
<Space>
<Search size={18} className={'mx-1'}/>
<Received size={18} className={'mx-1'}/>
<Scan size={18} className={'mx-1'}/>
</Space>
</div>
</>
}
>
</NavBar>
</>
);
}
export default Kefu;

View File

@@ -0,0 +1,3 @@
export default definePageConfig({
navigationBarTitleText: 'AI问答'
})

24
src/pages/study/study.tsx Normal file
View File

@@ -0,0 +1,24 @@
import {useEffect} from "react";
import TabBar from "@/components/TabBar";
/**
* 文章终极列表
* @constructor
*/
const Study = () => {
const reload = async () => {
}
useEffect(() => {
reload().then(() => {
console.log('初始化完成')
})
}, [])
return (
<>
<TabBar/>
</>
)
}
export default Study

View File

@@ -0,0 +1,211 @@
import {useEffect, useState} from 'react'
import {navigateTo} from '@tarojs/taro'
import Taro from '@tarojs/taro'
import {Button} from '@tarojs/components';
import {Image} from '@nutui/nutui-react-taro'
import {getUserInfo, getWxOpenId} from "@/api/layout";
import {TenantId} from "@/utils/config";
import {User} from "@/api/system/user/model";
// import News from "./News";
import {myPageBszxBm} from "@/api/bszx/bszxBm";
import {listCmsNavigation} from "@/api/cms/cmsNavigation";
const OrderIcon = () => {
const [loading, setLoading] = useState(true)
const [isLogin, setIsLogin] = useState<boolean>(false)
const [userInfo, setUserInfo] = useState<User>()
const [bmLogs, setBmLogs] = useState<any>()
const [navItems, setNavItems] = useState<any>([])
/* 获取用户手机号 */
const handleGetPhoneNumber = ({detail}) => {
const {code, encryptedData, iv} = detail
Taro.login({
success: function () {
if (code) {
Taro.request({
url: 'https://server.gxwebsoft.com/api/wx-login/loginByMpWxPhone',
method: 'POST',
data: {
code,
encryptedData,
iv,
notVerifyPhone: true,
refereeId: 0,
sceneType: 'save_referee',
tenantId: TenantId
},
header: {
'content-type': 'application/json',
TenantId
},
success: function (res) {
Taro.setStorageSync('access_token', res.data.data.access_token)
Taro.setStorageSync('UserId', res.data.data.user.userId)
setUserInfo(res.data.data.user)
Taro.setStorageSync('Phone', res.data.data.user.phone)
setIsLogin(true)
Taro.showToast({
title: '登录成功',
icon: 'success'
});
}
})
} else {
console.log('登录失败!')
}
}
})
}
const onLogin = (item: any, index: number) => {
if(!isLogin){
return navigateTo({url: `/pages/category/category?id=${item.navigationId}`})
}else {
// 报名链接
if(index == 0){
console.log(bmLogs,'bmLogs')
if(bmLogs && bmLogs.length > 0){
return navigateTo({url: `/bszx/bm-cert/bm-cert?id=${bmLogs[0].id}`})
}else {
navigateTo({url: `/user/profile/profile`})
}
}
// 善款明细
if(item.navigationId == 4119){
return navigateTo({url: `/bszx/pay-record/pay-record`})
}
return navigateTo({url: `/pages/category/category?id=${item.navigationId}`})
}
}
const reload = () => {
// 读取栏目
listCmsNavigation({parentId: 2828,hide: 0}).then(res => {
console.log(res,'9999')
setNavItems(res);
})
Taro.getUserInfo({
success: (res) => {
const avatar = res.userInfo.avatarUrl;
setUserInfo({
avatar,
nickname: res.userInfo.nickName,
sexName: res.userInfo.gender == 1 ? '男' : '女'
})
getUserInfo().then((data) => {
if (data) {
setUserInfo(data)
setIsLogin(true);
console.log(userInfo, 'userInfo...')
Taro.setStorageSync('UserId', data.userId)
// 获取openId
if (!data.openid) {
Taro.login({
success: (res) => {
getWxOpenId({code: res.code}).then(() => {
})
}
})
}
}
}).catch(() => {
console.log('未登录')
});
}
});
// 报名日志
myPageBszxBm({limit: 1}).then(res => {
if (res.list) {
setBmLogs(res.list);
}
})
setLoading(false);
};
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'
});
}
}
});
};
useEffect(() => {
Taro.getSetting({
success: (res) => {
if (res.authSetting['scope.userInfo']) {
// 用户已经授权过,可以直接获取用户信息
console.log('用户已经授权过,可以直接获取用户信息')
reload();
} else {
// 用户未授权,需要弹出授权窗口
console.log('用户未授权,需要弹出授权窗口')
showAuthModal();
}
}
});
reload();
}, [])
return (
<div className={'my-3'}>
<div className={'pt-4 bg-yellow-50 rounded-2xl'}
style={{background: 'linear-gradient(to bottom, #ffffff, #ffffcc)'}}>
<div className={'flex justify-between pb-2 px-1'}>
{
navItems.map((item, index) => (
<div key={index} className={'text-center'}>
{
isLogin && !loading ?
<div className={'flex flex-col justify-center items-center'} onClick={() => {
onLogin(item, index)
}}>
<Image src={item.icon} height={28} width={28}/>
<div className={'mt-2'} style={{fontSize: '15px'}}>{item?.title}</div>
</div>
:
<Button className={'text-white'} open-type="getPhoneNumber" onGetPhoneNumber={handleGetPhoneNumber}>
<div className={'flex flex-col justify-center items-center'}>
<Image src={item.icon} height={28} width={28}/>
<div className={'mt-2 text-gray-700'} style={{fontSize: '15px'}}>{item?.title}</div>
</div>
</Button>
}
</div>
))
}
</div>
</div>
{/*<image src={'https://oss.wsdns.cn/20250224/18a2f3b807c94aac8a67af34e95534d6.jpeg'} className={'book'}>倡议书</image>*/}
{/*<News id={categoryId}/>*/}
</div>
)
}
export default OrderIcon

View File

@@ -0,0 +1,112 @@
import {Button} from '@nutui/nutui-react-taro'
import {Avatar, Tag, Space} from '@nutui/nutui-react-taro'
import Taro from '@tarojs/taro';
import {useEffect, useState} from "react";
import {User} from "@/api/system/user/model";
import navTo from "@/utils/common";
import {TenantId} from "@/utils/config";
function UserCard() {
const [IsLogin, setIsLogin] = useState<boolean>(false)
const [userInfo, setUserInfo] = useState<User>()
useEffect(() => {
reload()
}, []);
const reload = () => {
};
/* 获取用户手机号 */
const handleGetPhoneNumber = ({detail}) => {
const {code, encryptedData, iv} = detail
Taro.login({
success: function () {
if (code) {
Taro.request({
url: 'https://server.gxwebsoft.com/api/wx-login/loginByMpWxPhone',
method: 'POST',
data: {
code,
encryptedData,
iv,
notVerifyPhone: true,
refereeId: 0,
sceneType: 'save_referee',
tenantId: TenantId
},
header: {
'content-type': 'application/json',
TenantId
},
success: function (res) {
Taro.setStorageSync('access_token', res.data.data.access_token)
Taro.setStorageSync('UserId', res.data.data.user.userId)
setUserInfo(res.data.data.user)
setIsLogin(true)
}
})
} else {
console.log('登录失败!')
}
}
})
}
return (
<>
<div className={'p-4'}>
<div
className={'user-card w-full bg-blue-900 flex flex-col justify-center rounded-xl'}
style={{
background: 'linear-gradient(to bottom, #e1dfff, #f3f2f7)', // 这种情况建议使用类名来控制样式(引入外联样式)
// width: '720rpx',
// margin: '10px auto 0px auto',
height: '144px',
// borderRadius: '22px 22px 0 0',
}}
>
<div className={'user-card-header flex w-full justify-between items-center'}>
<div className={'flex items-center mx-4'}>
{
IsLogin ? (
<Avatar size="large" src={userInfo?.avatar} shape="round"/>
) : (
<Button className={'text-black'} open-type="getPhoneNumber" onGetPhoneNumber={handleGetPhoneNumber}>
<Avatar size="large" src={userInfo?.avatar} shape="round"/>
</Button>
)
}
<div className={'user-info flex flex-col px-2'}>
<div className={'py-1 text-black font-bold'}>{IsLogin ? userInfo?.mobile : '请点击头像登录'}</div>
{IsLogin ? (
<Space className={'grade text-xs py-1'}>
<Tag type="success" round>
<div className={'p-1'}>{'注册用户'}</div>
</Tag>
{/*{*/}
{/* userInfo?.organizationName && (*/}
{/* <Tag type="warning" round>*/}
{/* <div className={'p-1'}>{userInfo?.organizationName}</div>*/}
{/* </Tag>*/}
{/* )*/}
{/*}*/}
</Space>
) : ''}
</div>
</div>
<div className={'mx-4 text-sm px-3 py-1 text-black border-gray-400 border-solid border-2 rounded-3xl'}
onClick={() => navTo('/user/profile/profile', true)}>
{'个人资料'}
</div>
</div>
</div>
</div>
</>
)
}
export default UserCard;

View File

@@ -0,0 +1,268 @@
import {Cell, InfiniteLoading} from '@nutui/nutui-react-taro'
import navTo from "@/utils/common";
import UserFooter from "./UserFooter";
import Taro from '@tarojs/taro'
import {ArrowRight, ShieldCheck, Truck, LogisticsError} from '@nutui/icons-react-taro'
import {CSSProperties, useEffect, useState} from "react";
const UserCell = () => {
const [roleName, setRoleName] = useState<string>('')
const InfiniteUlStyle: CSSProperties = {
height: '88vh',
padding: '16px',
overflowY: 'auto',
overflowX: 'hidden',
}
const onLogout = () => {
Taro.showModal({
title: '提示',
content: '确定要退出登录吗?',
success: function (res) {
if (res.confirm) {
Taro.clearStorageSync()
Taro.removeStorageSync('access_token')
Taro.removeStorageSync('TenantId')
Taro.removeStorageSync('UserId')
Taro.removeStorageSync('userInfo')
Taro.reLaunch({
url: '/pages/index/index'
})
}
}
})
}
useEffect(() => {
setRoleName(Taro.getStorageSync('RoleCode'))
}, []);
return (
<>
<div style={InfiniteUlStyle} id="scroll">
<InfiniteLoading>
<Cell.Group divider={true}>
<Cell
className="nutui-cell-clickable"
title={
<div style={{display: 'inline-flex', alignItems: 'center'}}>
<ShieldCheck size={16}/>
<span className={'pl-3 text-sm'}></span>
</div>
}
align="center"
extra={<ArrowRight color="#cccccc" size={18}/>}
onClick={() => {
navTo('/user/userVerify/index', true)
}}
/>
</Cell.Group>
{
(roleName === 'kuaidi' || roleName == 'zhandian') && (
<>
<Cell.Group divider={true}>
<Cell
className="nutui-cell-clickable"
title={
<div style={{display: 'inline-flex', alignItems: 'center'}}>
<ShieldCheck size={16}/>
<span className={'pl-3 text-sm'}></span>
</div>
}
align="center"
extra={<ArrowRight color="#cccccc" size={18}/>}
onClick={() => {
navTo('/user/userVerify/admin', true)
}}
/>
</Cell.Group>
<Cell.Group divider={true}>
<Cell
className="nutui-cell-clickable"
title={
<div style={{display: 'inline-flex', alignItems: 'center'}}>
<Truck size={16}/>
<span className={'pl-3 text-sm'}></span>
</div>
}
align="center"
extra={<ArrowRight color="#cccccc" size={18}/>}
onClick={() => {
navTo('/hjm/violation/list', true)
}}
/>
</Cell.Group>
</>
)
}
{
roleName === 'kuaidiyuan' && (
<>
<Cell.Group divider={true}>
<Cell
className="nutui-cell-clickable"
title={
<div style={{display: 'inline-flex', alignItems: 'center'}}>
<Truck size={16}/>
<span className={'pl-3 text-sm'}></span>
</div>
}
align="center"
extra={<ArrowRight color="#cccccc" size={18}/>}
onClick={() => {
navTo('/user/car/index', true)
}}
/>
</Cell.Group>
<Cell.Group divider={true}>
<Cell
className="nutui-cell-clickable"
title={
<div style={{display: 'inline-flex', alignItems: 'center'}}>
<LogisticsError size={16}/>
<span className={'pl-3 text-sm'}></span>
</div>
}
align="center"
extra={<ArrowRight color="#cccccc" size={18}/>}
onClick={() => {
navTo('/hjm/bx/bx', true)
}}
/>
</Cell.Group>
</>
)
}
{
roleName === 'jiaojing' && (
<Cell.Group divider={true}>
<Cell
className="nutui-cell-clickable"
title={
<div style={{display: 'inline-flex', alignItems: 'center'}}>
<Truck size={16}/>
<span className={'pl-3 text-sm'}></span>
</div>
}
align="center"
extra={<ArrowRight color="#cccccc" size={18}/>}
onClick={() => {
navTo('/hjm/violation/list', true)
}}
/>
</Cell.Group>
)
}
{/*<Cell.Group divider={true} description={*/}
{/* <div style={{display: 'inline-flex', alignItems: 'center'}}>*/}
{/* <span style={{marginTop: '12px'}}>管理</span>*/}
{/* </div>*/}
{/*}>*/}
{/* <Cell*/}
{/* className="nutui-cell-clickable"*/}
{/* title={*/}
{/* <div style={{display: 'inline-flex', alignItems: 'center'}}>*/}
{/* <Presentation size={18}/>*/}
{/* <span style={{marginLeft: '5px'}}>分析</span>*/}
{/* </div>*/}
{/* }*/}
{/* align="center"*/}
{/* extra={<ArrowRight color="#cccccc" size={18}/>}*/}
{/* onClick={() => {*/}
{/* navTo('/bszx/bm-cert/bm-cert', true)*/}
{/* }}*/}
{/* />*/}
{/* <Cell*/}
{/* className="nutui-cell-clickable"*/}
{/* title={*/}
{/* <div style={{display: 'inline-flex', alignItems: 'center'}}>*/}
{/* <PickedUp size={18}/>*/}
{/* <span style={{marginLeft: '5px'}}>客户</span>*/}
{/* </div>*/}
{/* }*/}
{/* align="center"*/}
{/* extra={<ArrowRight color="#cccccc" size={18}/>}*/}
{/* onClick={() => {*/}
{/* navTo('/bszx/pay-log/pay-log', true)*/}
{/* }}*/}
{/* />*/}
{/* <Cell*/}
{/* className="nutui-cell-clickable"*/}
{/* title={*/}
{/* <div style={{display: 'inline-flex', alignItems: 'center'}}>*/}
{/* <Coupon size={18}/>*/}
{/* <span style={{marginLeft: '5px'}}>折扣</span>*/}
{/* </div>*/}
{/* }*/}
{/* align="center"*/}
{/* extra={<ArrowRight color="#cccccc" size={18}/>}*/}
{/* onClick={() => {*/}
{/* navTo('/user/profile/profile', true)*/}
{/* }}*/}
{/* />*/}
{/*</Cell.Group>*/}
{/*<Cell.Group divider={true} description={*/}
{/* <div style={{display: 'inline-flex', alignItems: 'center'}}>*/}
{/* <span style={{marginTop: '12px'}}>设置与帮助</span>*/}
{/* </div>*/}
{/*}>*/}
{/* <Cell*/}
{/* className="nutui-cell-clickable"*/}
{/* title="店铺设置"*/}
{/* align="center"*/}
{/* extra={<ArrowRight color="#cccccc" size={18}/>}*/}
{/* onClick={() => Taro.navigateTo({url: '/website/modify'})}*/}
{/* />*/}
{/* <Cell*/}
{/* className="nutui-cell-clickable"*/}
{/* title="帮助中心"*/}
{/* align="center"*/}
{/* extra={<ArrowRight color="#cccccc" size={18}/>}*/}
{/* onClick={() => {*/}
{/* navTo('/user/profile/profile', true)*/}
{/* }}*/}
{/* />*/}
{/* <Cell*/}
{/* className="nutui-cell-clickable"*/}
{/* title="问题反馈"*/}
{/* align="center"*/}
{/* extra={<ArrowRight color="#cccccc" size={18}/>}*/}
{/* onClick={() => {*/}
{/* navTo('/user/profile/profile', true)*/}
{/* }}*/}
{/* />*/}
{/*</Cell.Group>*/}
<Cell.Group divider={true} description={
<div style={{display: 'inline-flex', alignItems: 'center'}}>
<span style={{marginTop: '12px'}}></span>
</div>
}>
<Cell
className="nutui-cell-clickable"
title="账号安全"
align="center"
extra={<ArrowRight color="#cccccc" size={18}/>}
onClick={() => navTo('/user/profile/profile', true)}
/>
<Cell
className="nutui-cell-clickable"
title="短信登录"
align="center"
extra={<ArrowRight color="#cccccc" size={18}/>}
onClick={() => navTo('/passport/sms-login', true)}
/>
<Cell
className="nutui-cell-clickable"
title="退出登录"
align="center"
extra={<ArrowRight color="#cccccc" size={18}/>}
onClick={onLogout}
/>
</Cell.Group>
<UserFooter/>
</InfiniteLoading>
</div>
</>
)
}
export default UserCell

View File

@@ -0,0 +1,102 @@
import {loginBySms} from "@/api/passport/login";
import {useState} from "react";
import Taro from '@tarojs/taro'
import {Popup} from '@nutui/nutui-react-taro'
import {UserParam} from "@/api/system/user/model";
import {Button} from '@nutui/nutui-react-taro'
import {Form, Input} from '@nutui/nutui-react-taro'
import {Copyright, Version} from "@/utils/config";
const UserFooter = () => {
const [openLoginByPhone, setOpenLoginByPhone] = useState(false)
const [clickNum, setClickNum] = useState<number>(0)
const [FormData, setFormData] = useState<UserParam>(
{
phone: undefined,
password: undefined
}
)
const onLoginByPhone = () => {
setFormData({})
setClickNum(clickNum + 1);
if (clickNum > 10) {
setOpenLoginByPhone(true);
}
}
const closeLoginByPhone = () => {
setClickNum(0)
setOpenLoginByPhone(false)
}
// 提交表单
const submitByPhone = (values: any) => {
loginBySms({
phone: values.phone,
code: values.code
}).then(() => {
setOpenLoginByPhone(false);
setTimeout(() => {
Taro.reLaunch({
url: '/pages/index/index'
})
},1000)
})
}
return (
<>
<div className={'text-center py-4 w-full text-gray-300'} onClick={onLoginByPhone}>
<div className={'text-xs text-gray-400 py-1'}>{Version}</div>
<div className={'text-xs text-gray-400 py-1'}>Copyright © { new Date().getFullYear() } {Copyright}</div>
</div>
<Popup
style={{width: '350px', padding: '10px'}}
visible={openLoginByPhone}
closeOnOverlayClick={false}
closeable={true}
onClose={closeLoginByPhone}
>
<Form
style={{width: '350px',padding: '10px'}}
divider
initialValues={FormData}
labelPosition="left"
onFinish={(values) => submitByPhone(values)}
footer={
<div
style={{
display: 'flex',
justifyContent: 'center',
width: '100%'
}}
>
<Button nativeType="submit" block style={{backgroundColor: '#000000',color: '#ffffff'}}>
</Button>
</div>
}
>
<Form.Item
label={'手机号码'}
name="phone"
required
rules={[{message: '手机号码'}]}
>
<Input placeholder="请输入手机号码" maxLength={11} type="text"/>
</Form.Item>
<Form.Item
label={'短信验证码'}
name="code"
required
rules={[{message: '短信验证码'}]}
>
<Input placeholder="请输入短信验证码" maxLength={6} type="text"/>
</Form.Item>
</Form>
</Popup>
</>
)
}
export default UserFooter

View File

@@ -0,0 +1,3 @@
export default definePageConfig({
navigationBarTitleText: '我的'
})

21
src/pages/user/user.tsx Normal file
View File

@@ -0,0 +1,21 @@
import {useEffect} from 'react'
import UserCard from "./components/UserCard";
import UserCell from "./components/UserCell";
import TabBar from "@/components/TabBar";
function User() {
useEffect(() => {
}, []);
return (
<>
<div className={'fixed w-full'}>
<UserCard />
<UserCell />
<TabBar/>
</div>
</>
)
}
export default User