feat: 使用个人 WA 权限根据是否有服务器地址判断;Web 端收定时件时间改为两分钟;优化收件和小虫子大小、位置

dev/supplier-email-drawer
LiaoYijun 9 months ago
parent d5763ba820
commit 5a973ea114

@ -11,6 +11,8 @@ export const PERM_USE_EMAL = 'use-email'
export const PERM_USE_WHATSAPP = 'use-whatsapp'
export const PERM_IMPORT_EMAIL = 'import-email'
const WAI_SERVER_KEY = 'G-STR:WAI_SERVER'
const useAuthStore = create(devtools((set, get) => ({
loginUser: {
userId: -1,
@ -29,10 +31,11 @@ const useAuthStore = create(devtools((set, get) => ({
loginStatus: 0,
isPermitted: (perm) => {
const { waiServer } = usingStorage(WAI_SERVER_KEY)
const { loginUser } = get()
if (perm === PERM_USE_WHATSAPP) {
return ['370', '143', '495', '404', '383', '227'].includes(loginUser.userId)
return isNotEmpty(waiServer) // ['370', '143', '495', '404', '383', '227'].includes(loginUser.userId)
}
if (perm === PERM_USE_EMAL) {

@ -11,7 +11,7 @@ import {
FloatButton,
theme,
} from 'antd'
import { BugOutlined } from '@ant-design/icons'
import { BugOutlined, CustomerServiceOutlined } from '@ant-design/icons'
import zhLocale from 'antd/locale/zh_CN'
import 'dayjs/locale/zh-cn'
import { useEffect } from 'react'
@ -111,6 +111,13 @@ function AuthApp() {
// /p...
const needToLogin = loginUser.userId === -1 && href.indexOf('/p/') === -1
const isMobileApp =
navigator.userAgent.match(
/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i,
) !== null
const floatButtonLineEnd = isMobileApp ? 0 : 24
useEffect(() => {
if (needToLogin) {
navigate('/p/dingding/login?origin_url=' + href)
@ -136,10 +143,12 @@ function AuthApp() {
<AntApp>
<ErrorBoundary>
<FloatButton.Group
shape="square"
shape='square'
trigger='click'
style={{
insetInlineEnd: 94,
insetInlineEnd: floatButtonLineEnd,
}}
icon={<CustomerServiceOutlined />}
>
<EmailFetch />
<FloatButton icon={<BugOutlined />} tooltip={<div>上传日志给研发部</div>} onClick={() => uploadLog()} />

@ -1,10 +1,12 @@
import { useEffect, useCallback } from 'react'
import { Row, Col, Space, Input, Descriptions, Avatar, Tag, Divider, List, App, Button, Flex, Select, Form, Typography, Tooltip } from 'antd'
import { Row, Col, Space, Input, Descriptions, Avatar, Tag, Divider, List, App, Button, Flex, Select, Form, Typography, Tooltip, Result } from 'antd'
import { UserOutlined, InfoCircleOutlined } from '@ant-design/icons'
import useAuthStore from '@/stores/AuthStore'
import { Conditional } from '@/components/Conditional'
import { PERM_USE_WHATSAPP } from '@/stores/AuthStore'
import { usingStorage } from '@/utils/usingStorage';
import { isEmpty } from '@/utils/commons'
import { WAI_SERVER_KEY } from '@/config';
import WAIQRCode from './WAIQRCode';
@ -112,7 +114,7 @@ function Profile() {
<Form.Item
label='WhatsApp'
name='whatsAppNo'>
<Input />
<Input placeholder='e.g. 8618212345678' />
</Form.Item>
<Form.Item>
<Button type='primary' onClick={handelUpdateWABA}>
@ -155,7 +157,7 @@ function Profile() {
</Typography.Paragraph>
<Typography.Paragraph>
WhatsApp 服务{waiServer}
WhatsApp 服务{isEmpty(waiServer) ? '请联系你的主管申请开通' : waiServer}
</Typography.Paragraph>
</Typography>
</Col>
@ -164,6 +166,11 @@ function Profile() {
<Conditional
condition={isPermitted(PERM_USE_WHATSAPP)}
whenTrue={<WAIQRCode />}
whenFalse={
<Result
status='403'
/>
}
/>
</Flex>
</Col>

@ -3,31 +3,25 @@ import { getEmailFetchAction } from './../actions/EmailActions'
let timeoutID;
self.onmessage = (event) => {
if (event.data.command === 'fetchEmail') {
// Get the parameter
const param = event.data.param // { opi_sn: userId }
console.log('Worker: Received command `fetchEmail` with param:', param)
// Do something......
const fetchEmails = () => {
try {
getEmailFetchAction(param);
} catch (error) {
console.error(error)
}
timeoutID = setTimeout(fetchEmails, 60 * 1000);
timeoutID = setTimeout(fetchEmails, 60 * 1000 * 2);
};
// Start fetching emails
fetchEmails();
}
if (event.data.command === 'logout') {
console.log('logout')
// clearInterval(intervalID)
clearTimeout(timeoutID)
}
}
self.onerror = function (error) {
console.error('Error in worker', error)
// You can also post the error back to the main thread
postMessage({ error: error.message })
}

Loading…
Cancel
Save