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

dev/supplier-email-drawer
LiaoYijun 1 year 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_USE_WHATSAPP = 'use-whatsapp'
export const PERM_IMPORT_EMAIL = 'import-email' export const PERM_IMPORT_EMAIL = 'import-email'
const WAI_SERVER_KEY = 'G-STR:WAI_SERVER'
const useAuthStore = create(devtools((set, get) => ({ const useAuthStore = create(devtools((set, get) => ({
loginUser: { loginUser: {
userId: -1, userId: -1,
@ -29,10 +31,11 @@ const useAuthStore = create(devtools((set, get) => ({
loginStatus: 0, loginStatus: 0,
isPermitted: (perm) => { isPermitted: (perm) => {
const { waiServer } = usingStorage(WAI_SERVER_KEY)
const { loginUser } = get() const { loginUser } = get()
if (perm === PERM_USE_WHATSAPP) { 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) { if (perm === PERM_USE_EMAL) {

@ -11,7 +11,7 @@ import {
FloatButton, FloatButton,
theme, theme,
} from 'antd' } from 'antd'
import { BugOutlined } from '@ant-design/icons' import { BugOutlined, CustomerServiceOutlined } from '@ant-design/icons'
import zhLocale from 'antd/locale/zh_CN' import zhLocale from 'antd/locale/zh_CN'
import 'dayjs/locale/zh-cn' import 'dayjs/locale/zh-cn'
import { useEffect } from 'react' import { useEffect } from 'react'
@ -111,6 +111,13 @@ function AuthApp() {
// /p... // /p...
const needToLogin = loginUser.userId === -1 && href.indexOf('/p/') === -1 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(() => { useEffect(() => {
if (needToLogin) { if (needToLogin) {
navigate('/p/dingding/login?origin_url=' + href) navigate('/p/dingding/login?origin_url=' + href)
@ -136,10 +143,12 @@ function AuthApp() {
<AntApp> <AntApp>
<ErrorBoundary> <ErrorBoundary>
<FloatButton.Group <FloatButton.Group
shape="square" shape='square'
trigger='click'
style={{ style={{
insetInlineEnd: 94, insetInlineEnd: floatButtonLineEnd,
}} }}
icon={<CustomerServiceOutlined />}
> >
<EmailFetch /> <EmailFetch />
<FloatButton icon={<BugOutlined />} tooltip={<div>上传日志给研发部</div>} onClick={() => uploadLog()} /> <FloatButton icon={<BugOutlined />} tooltip={<div>上传日志给研发部</div>} onClick={() => uploadLog()} />

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

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

Loading…
Cancel
Save