Commit 7c120bb4 by zhaochengxiang

防抖

parent 0767abb2
import { createStore, applyMiddleware } from 'redux' import { createStore, applyMiddleware } from 'redux'
import createSagaMiddleware from 'redux-saga' import createSagaMiddleware from 'redux-saga'
import { all, call, takeLatest, takeEvery, cancelled } from 'redux-saga/effects' import { all, call, takeLatest, takeEvery, delay } from 'redux-saga/effects'
import { SetSource, Cancel } from '../util/axios'
import { Connect, showErrorNotifaction } from '../util'; import { Connect, showErrorNotifaction } from '../util';
import { reducers } from './reducer'; import { reducers } from './reducer';
...@@ -15,9 +14,9 @@ const funcs = Connect({ user, datamodel, map, assetmanage, datasource }) ...@@ -15,9 +14,9 @@ const funcs = Connect({ user, datamodel, map, assetmanage, datasource })
function* request(args) { function* request(args) {
const { type, payload, callback, error } = args.args; const { type, payload, callback, error } = args.args;
SetSource();
try { try {
yield delay(300)
const rs = yield call(funcs[type], payload) const rs = yield call(funcs[type], payload)
if (callback) if (callback)
yield call(callback, rs) yield call(callback, rs)
...@@ -26,10 +25,6 @@ function* request(args) { ...@@ -26,10 +25,6 @@ function* request(args) {
ex.ApiError && ex.ApiError.cnMessage && showErrorNotifaction('系统异常', ex.ApiError.cnMessage, 5); ex.ApiError && ex.ApiError.cnMessage && showErrorNotifaction('系统异常', ex.ApiError.cnMessage, 5);
error && error(ex); error && error(ex);
} }
}finally {
if (yield cancelled()) {
yield Cancel('cancel request');
}
} }
} }
...@@ -37,6 +32,10 @@ function* watchLatest() { ...@@ -37,6 +32,10 @@ function* watchLatest() {
yield takeLatest('TAKE_LATEST', request) yield takeLatest('TAKE_LATEST', request)
} }
function* watchLatestHomepage() {
yield takeLatest('TAKE_LATEST_HOMEPAGE', request);
}
function* watchEvery() { function* watchEvery() {
yield takeEvery('TAKE_EVERY', request) yield takeEvery('TAKE_EVERY', request)
} }
...@@ -49,13 +48,14 @@ export const store = createStore( ...@@ -49,13 +48,14 @@ export const store = createStore(
function* rootSaga() { function* rootSaga() {
yield all([ yield all([
watchLatest(), watchEvery() watchLatest(), watchLatestHomepage(), watchEvery()
]) ])
} }
sagaMiddleware.run(rootSaga) sagaMiddleware.run(rootSaga)
export const dispatchLatest = ({ type, payload=null, callback=null, error=null }) => store.dispatch({ type: 'TAKE_LATEST', args: { type, payload, callback, error } }) export const dispatchLatest = ({ type, payload=null, callback=null, error=null }) => store.dispatch({ type: 'TAKE_LATEST', args: { type, payload, callback, error } })
export const dispatchLatestHomepage = ({ type, payload=null, callback=null, error=null }) => store.dispatch({ type: 'TAKE_LATEST_HOMEPAGE', args: { type, payload, callback, error } })
export const dispatch = ({ type, payload=null, callback=null, error=null }) => store.dispatch({ type: 'TAKE_EVERY', args: { type, payload, callback, error } }) export const dispatch = ({ type, payload=null, callback=null, error=null }) => store.dispatch({ type: 'TAKE_EVERY', args: { type, payload, callback, error } })
export const action = ({ type, args}) => store.dispatch({ type, args }) export const action = ({ type, args}) => store.dispatch({ type, args })
...@@ -14,7 +14,7 @@ import ImportAsset from './ImportAsset'; ...@@ -14,7 +14,7 @@ import ImportAsset from './ImportAsset';
import AssetEdit from './AssetEdit'; import AssetEdit from './AssetEdit';
import AssetDetail from "./AssetDetail"; import AssetDetail from "./AssetDetail";
import AssetItem from './AssetItem'; import AssetItem from './AssetItem';
import { dispatch, dispatchLatest } from '../../../../model'; import { dispatch, dispatchLatestHomepage } from '../../../../model';
import { showMessage, showNotifaction, getQueryParam } from '../../../../util'; import { showMessage, showNotifaction, getQueryParam } from '../../../../util';
import { AnchorId, AnchorTimestamp } from '../../../../util/constant'; import { AnchorId, AnchorTimestamp } from '../../../../util/constant';
...@@ -141,7 +141,7 @@ const AssetTable = (props) => { ...@@ -141,7 +141,7 @@ const AssetTable = (props) => {
const getDataAssets = (elmentsGroup = filterElementsGroup) => { const getDataAssets = (elmentsGroup = filterElementsGroup) => {
setLoading(true); setLoading(true);
dispatchLatest({ dispatchLatestHomepage({
type: 'assetmanage.listDataAssetsByPage', type: 'assetmanage.listDataAssetsByPage',
payload: { payload: {
dirId: nodeId, dirId: nodeId,
......
...@@ -4,7 +4,7 @@ import { DownOutlined, UpOutlined } from '@ant-design/icons'; ...@@ -4,7 +4,7 @@ import { DownOutlined, UpOutlined } from '@ant-design/icons';
import SmoothScroll from 'smooth-scroll'; import SmoothScroll from 'smooth-scroll';
import classnames from 'classnames'; import classnames from 'classnames';
import { dispatchLatest, dispatch } from '../../../../model'; import { dispatch } from '../../../../model';
import { showMessage, getQueryParam, paginate } from '../../../../util'; import { showMessage, getQueryParam, paginate } from '../../../../util';
import { AnchorId, AnchorTimestamp, Action, CatalogId, ModelerId } from '../../../../util/constant'; import { AnchorId, AnchorTimestamp, Action, CatalogId, ModelerId } from '../../../../util/constant';
...@@ -272,7 +272,7 @@ const ModelTable = (props) => { ...@@ -272,7 +272,7 @@ const ModelTable = (props) => {
title: '提示!', title: '提示!',
content: `您确定要${action.cnName||''}该模型吗?`, content: `您确定要${action.cnName||''}该模型吗?`,
onOk: () => { onOk: () => {
dispatchLatest({ dispatch({
type: 'datamodel.nextState', type: 'datamodel.nextState',
payload: { payload: {
easyDataModelerDataModelId: record.id, easyDataModelerDataModelId: record.id,
...@@ -311,7 +311,7 @@ const ModelTable = (props) => { ...@@ -311,7 +311,7 @@ const ModelTable = (props) => {
title: '提示!', title: '提示!',
content: '您确定要删除该模型吗?', content: '您确定要删除该模型吗?',
onOk: () => { onOk: () => {
dispatchLatest({ dispatch({
type: 'datamodel.deleteDataModel', type: 'datamodel.deleteDataModel',
payload: { payload: {
params: { params: {
......
...@@ -136,9 +136,9 @@ const VersionCompare = (props) => { ...@@ -136,9 +136,9 @@ const VersionCompare = (props) => {
</Form.Item> </Form.Item>
</Form> </Form>
<div className='py-3'> <div className='py-5'>
<Spin spinning={loadingCompare} > <Spin spinning={loadingCompare} >
<div id="model-version-compare-container" style={{ }}></div> <div id="model-version-compare-container"></div>
</Spin> </Spin>
</div> </div>
</div> </div>
......
...@@ -14,7 +14,7 @@ import RecatalogModal from './Component/RecatalogModal'; ...@@ -14,7 +14,7 @@ import RecatalogModal from './Component/RecatalogModal';
import HistoryAndVersionDrawer from './Component/HistoryAndVersionDrawer'; import HistoryAndVersionDrawer from './Component/HistoryAndVersionDrawer';
import StartFlowModal from './Component/StartFlowModal'; import StartFlowModal from './Component/StartFlowModal';
import { showMessage, showNotifaction } from '../../../util'; import { showMessage, showNotifaction } from '../../../util';
import { dispatch, dispatchLatest } from '../../../model'; import { dispatch, dispatchLatestHomepage } from '../../../model';
import { Action, CatalogId, ModelerId, Hints, ModelerData, PermitCheckOut, Editable, StateId } from '../../../util/constant'; import { Action, CatalogId, ModelerId, Hints, ModelerData, PermitCheckOut, Editable, StateId } from '../../../util/constant';
import { AppContext } from '../../../App'; import { AppContext } from '../../../App';
...@@ -109,7 +109,7 @@ class Model extends React.Component { ...@@ -109,7 +109,7 @@ class Model extends React.Component {
this.setState({ loadingTableData: true }, () => { this.setState({ loadingTableData: true }, () => {
if (keyword === '') { if (keyword === '') {
if (currentView === 'dir') { if (currentView === 'dir') {
dispatch({ dispatchLatestHomepage({
type: 'datamodel.getCurrentDataModelCatalog', type: 'datamodel.getCurrentDataModelCatalog',
payload: { payload: {
easyDataModelerCatalogId: catalogId, easyDataModelerCatalogId: catalogId,
...@@ -123,7 +123,7 @@ class Model extends React.Component { ...@@ -123,7 +123,7 @@ class Model extends React.Component {
} }
}) })
} else { } else {
dispatch({ dispatchLatestHomepage({
type: 'datamodel.getCurrentDataModelStateCatalog', type: 'datamodel.getCurrentDataModelStateCatalog',
payload: { payload: {
easyDataModelerStateCatalogId: catalogId easyDataModelerStateCatalogId: catalogId
...@@ -137,7 +137,7 @@ class Model extends React.Component { ...@@ -137,7 +137,7 @@ class Model extends React.Component {
}) })
} }
} else { } else {
dispatchLatest({ dispatchLatestHomepage({
type: 'datamodel.searchModel', type: 'datamodel.searchModel',
payload: { payload: {
term: keyword, term: keyword,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment