feat: first commit

This commit is contained in:
eleanor.mao
2025-03-31 22:34:22 +08:00
commit d25187c9c8
390 changed files with 57031 additions and 0 deletions

134
src/hooks/use-config.tsx Normal file
View File

@ -0,0 +1,134 @@
import Taro from '@tarojs/taro';
import { omit } from 'lodash-es';
import { PageType, PageUrl } from '@/constants/app';
export type TabItemType = Taro.TabBarItem & { type: PageType };
export type AppConfigType = Taro.AppConfig & { tabBar: Taro.AppConfig['tabBar'] & { list: TabItemType[] } };
const CommonTabs: TabItemType[] = [
{
type: PageType.Message,
pagePath: PageUrl.Message,
text: ' 消息',
},
{
type: PageType.User,
pagePath: PageUrl.User,
text: ' 我的',
},
// {
// type: PageType.DEV,
// pagePath: PageUrl.DevDebug,
// text: ' 调试页面',
// },
];
const AnchorTabs: TabItemType[] = [
{
type: PageType.JOB,
pagePath: PageUrl.Job,
text: '通告',
},
{
type: PageType.GroupV2,
pagePath: PageUrl.GroupV2,
text: '通告群',
},
];
const CompanyTabs: TabItemType[] = [
{
type: PageType.Anchor,
pagePath: PageUrl.Anchor,
text: '主播',
},
{
type: PageType.BatchPublish,
pagePath: PageUrl.UserBatchPublish,
text: '群代发',
},
];
export const ANCHOR_TAB_LIST: TabItemType[] = AnchorTabs.concat(CommonTabs);
export const COMPANY_TAB_LIST: TabItemType[] = CompanyTabs.concat(CommonTabs);
const ALL_TABS = AnchorTabs.concat(CompanyTabs.concat(CommonTabs));
export const APP_CONFIG: AppConfigType = {
entryPagePath: PageUrl.Start,
pages: [
PageUrl.Start,
PageUrl.Job,
PageUrl.JobDetail,
PageUrl.JobSearch,
PageUrl.JobPublish,
// PageUrl.JobPublishAddress,
PageUrl.JobPublishDescribe,
PageUrl.JobSelectMyPublish,
// PageUrl.Group,
PageUrl.GroupV2,
PageUrl.GroupList,
// PageUrl.GroupJob,
PageUrl.Anchor,
PageUrl.Message,
PageUrl.MessageChat,
PageUrl.User,
PageUrl.UserInfo,
PageUrl.UserBatchPublish,
PageUrl.CitySearch,
PageUrl.MyDeclaration,
PageUrl.MyPublish,
// PageUrl.FollowGroup,
PageUrl.MaterialProfile,
PageUrl.MaterialUploadVideo,
PageUrl.MaterialCreateProfile,
PageUrl.MaterialEditProfile,
PageUrl.MaterialView,
PageUrl.MaterialWebview,
PageUrl.Certification,
PageUrl.CertificationStart,
PageUrl.CertificationManage,
PageUrl.ProtocolWebview,
PageUrl.PrivacyWebview,
// PageUrl.DevDebug,
],
window: {
backgroundColor: '#F5F6FA',
backgroundTextStyle: 'light',
navigationBarBackgroundColor: '#F5F6FA',
backgroundColorTop: '#F5F6FA',
backgroundColorBottom: '#F5F6FA',
navigationBarTextStyle: 'black',
},
permission: {
'scope.userLocation': {
desc: '获取经纬度',
},
},
requiredPrivateInfos: ['getLocation'],
tabBar: {
custom: true,
color: '#999999',
selectedColor: '#333333',
backgroundColor: '#fff',
position: 'bottom',
list: ALL_TABS.map(tab => omit(tab, 'type')),
},
lazyCodeLoading: 'requiredComponents',
plugins: {
chooseLocation: {
version: '1.1.1',
provider: 'wx76a9a06e5b4e693e',
},
},
};
function useConfig() {
return APP_CONFIG;
}
export default useConfig;

View File

@ -0,0 +1,61 @@
import Taro, { NodesRef, useReady } from '@tarojs/taro';
import { useEffect, useRef, useState } from 'react';
import { CollectEventName } from '@/constants/event';
import { logWithPrefix } from '@/utils/common';
import { collectEvent } from '@/utils/event';
export interface IUseListHeightProps {
selectors: string[];
calc: (rects: NodesRef.BoundingClientRectCallbackResult[]) => number;
}
const log = logWithPrefix('useListHeight');
function useListHeight(props: IUseListHeightProps) {
const [height, setHeight] = useState(Taro.getWindowInfo().screenHeight);
const isCalculated = useRef(false);
const calcHeight = () => {
log('default ListHeight:', height);
const query = Taro.createSelectorQuery();
props.selectors.forEach(selector => {
query.select(selector).boundingClientRect();
});
query.exec(function (nodes: NodesRef.BoundingClientRectCallbackResult[]) {
log('rects:', nodes);
try {
const contentHeight = props.calc(nodes);
log('real ListHeight: ', contentHeight);
setHeight(contentHeight);
} catch (e) {
collectEvent(CollectEventName.DEBUG, {
action: 'calc_list_height_error',
selectors: props.selectors,
nodes: nodes,
});
}
});
};
useReady(() => {
if (isCalculated.current) {
return;
}
isCalculated.current = true;
calcHeight();
});
useEffect(() => {
if (isCalculated.current) {
return;
}
isCalculated.current = true;
calcHeight();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
return height;
}
export default useListHeight;

View File

@ -0,0 +1,10 @@
import { useSelector } from 'react-redux';
import { selectLocation } from '@/store/selector';
function useLocation() {
const location = useSelector(selectLocation);
return location;
}
export default useLocation;

13
src/hooks/use-message.ts Normal file
View File

@ -0,0 +1,13 @@
import { useSelector } from 'react-redux';
import { selectMessage } from '@/store/selector';
function useMessage() {
const message = useSelector(selectMessage);
return {
hasUnread: message.count > 0,
unReadCount: message.count,
};
}
export default useMessage;

View File

@ -0,0 +1,36 @@
import Taro from '@tarojs/taro';
import { useRef } from 'react';
function useNavigation() {
const statusBarHeight = useRef(0);
const barHeight = useRef(0);
const systemInfo = Taro.getWindowInfo();
if (systemInfo.statusBarHeight) {
statusBarHeight.current = systemInfo.statusBarHeight;
}
// #ifndef MP
// if (process.env.TARO_ENV !== 'weapp') {
// barHeight.current = statusBarHeight.current + (systemInfo.platform === 'android' ? 50 : 40);
// }
// #endif
// #ifdef MP-WEIXIN
if (process.env.TARO_ENV === 'weapp') {
const custom = Taro.getMenuButtonBoundingClientRect();
barHeight.current = custom.bottom + custom.top - statusBarHeight.current;
}
// #endif
// #ifdef MP-ALIPAY
// barHeight.current = statusBarHeight.current + systemInfo.titleBarHeight!;
// #endif
return {
barHeight,
statusBarHeight,
};
}
export default useNavigation;

View File

@ -0,0 +1,10 @@
import { useSelector } from 'react-redux';
import { selectUserInfo } from '@/store/selector/user';
function useUserInfo() {
const useInfo = useSelector(selectUserInfo);
return useInfo;
}
export default useUserInfo;

View File

@ -0,0 +1,9 @@
import { useSelector } from 'react-redux';
import { selectRoleType } from '@/store/selector';
function useRoleType() {
return useSelector(selectRoleType);
}
export default useRoleType;