mirror of
https://github.com/MrXujiang/h5-Dooring.git
synced 2026-01-20 12:48:13 +00:00
添加umi过滤文件提交样式文件
This commit is contained in:
parent
c1856acfc9
commit
acde12bc23
@ -1,51 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
|
|
||||||
if (window.g_initWebpackHotDevClient) {
|
|
||||||
function tryApplyUpdates(onHotUpdateSuccess?: Function) {
|
|
||||||
// @ts-ignore
|
|
||||||
if (!module.hot) {
|
|
||||||
window.location.reload();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
function isUpdateAvailable() {
|
|
||||||
// @ts-ignore
|
|
||||||
return window.g_getMostRecentCompilationHash() !== __webpack_hash__;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: is update available?
|
|
||||||
// @ts-ignore
|
|
||||||
if (!isUpdateAvailable() || module.hot.status() !== 'idle') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleApplyUpdates(err: Error | null, updatedModules: any) {
|
|
||||||
if (err || !updatedModules || window.g_getHadRuntimeError()) {
|
|
||||||
window.location.reload();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
onHotUpdateSuccess?.();
|
|
||||||
|
|
||||||
if (isUpdateAvailable()) {
|
|
||||||
// While we were updating, there was a new update! Do it again.
|
|
||||||
tryApplyUpdates();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
module.hot.check(true).then(
|
|
||||||
function (updatedModules: any) {
|
|
||||||
handleApplyUpdates(null, updatedModules);
|
|
||||||
},
|
|
||||||
function (err: Error) {
|
|
||||||
handleApplyUpdates(err, null);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
window.g_initWebpackHotDevClient({
|
|
||||||
tryApplyUpdates,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -1,26 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
import { createBrowserHistory } from '/Users/apple/Desktop/github/zhiku.tec/h5-visible-tool/node_modules/@umijs/runtime';
|
|
||||||
|
|
||||||
let options = {
|
|
||||||
"basename": "h5_plus"
|
|
||||||
};
|
|
||||||
if ((<any>window).routerBase) {
|
|
||||||
options.basename = (<any>window).routerBase;
|
|
||||||
}
|
|
||||||
|
|
||||||
// remove initial history because of ssr
|
|
||||||
let history: any = process.env.__IS_SERVER ? null : createBrowserHistory(options);
|
|
||||||
export const createHistory = (hotReload = false) => {
|
|
||||||
if (!hotReload) {
|
|
||||||
history = createBrowserHistory(options);
|
|
||||||
}
|
|
||||||
|
|
||||||
return history;
|
|
||||||
};
|
|
||||||
|
|
||||||
// 通常仅微前端场景需要调用这个 API
|
|
||||||
export const setCreateHistoryOptions = (newOpts: any = {}) => {
|
|
||||||
options = { ...options, ...newOpts };
|
|
||||||
};
|
|
||||||
|
|
||||||
export { history };
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
import { Plugin } from '/Users/apple/Desktop/github/zhiku.tec/h5-visible-tool/node_modules/@umijs/runtime';
|
|
||||||
|
|
||||||
const plugin = new Plugin({
|
|
||||||
validKeys: ['modifyClientRenderOpts','patchRoutes','rootContainer','render','onRouteChange','dva','getInitialState','request',],
|
|
||||||
});
|
|
||||||
|
|
||||||
export { plugin };
|
|
||||||
210
src/.umi/core/pluginConfig.d.ts
vendored
210
src/.umi/core/pluginConfig.d.ts
vendored
@ -1,210 +0,0 @@
|
|||||||
/** Created by Umi Plugin **/
|
|
||||||
|
|
||||||
export interface IConfigFromPlugins {
|
|
||||||
routes?: {
|
|
||||||
/**
|
|
||||||
* Any valid URL path
|
|
||||||
*/
|
|
||||||
path?: string;
|
|
||||||
/**
|
|
||||||
* A React component to render only when the location matches.
|
|
||||||
*/
|
|
||||||
component?: string | (() => any);
|
|
||||||
wrappers?: string[];
|
|
||||||
/**
|
|
||||||
* navigate to a new location
|
|
||||||
*/
|
|
||||||
redirect?: string;
|
|
||||||
/**
|
|
||||||
* When true, the active class/style will only be applied if the location is matched exactly.
|
|
||||||
*/
|
|
||||||
exact?: boolean;
|
|
||||||
routes?: any[];
|
|
||||||
[k: string]: any;
|
|
||||||
}[];
|
|
||||||
history?: {
|
|
||||||
type?: "browser" | "hash" | "memory";
|
|
||||||
options?: {};
|
|
||||||
};
|
|
||||||
polyfill?: {
|
|
||||||
imports?: string[];
|
|
||||||
};
|
|
||||||
alias?: {};
|
|
||||||
analyze?: {
|
|
||||||
analyzerMode?: "server" | "static" | "disabled";
|
|
||||||
analyzerHost?: string;
|
|
||||||
analyzerPort?: any;
|
|
||||||
openAnalyzer?: boolean;
|
|
||||||
generateStatsFile?: boolean;
|
|
||||||
statsFilename?: string;
|
|
||||||
logLevel?: "info" | "warn" | "error" | "silent";
|
|
||||||
defaultSizes?: "stat" | "parsed" | "gzip";
|
|
||||||
[k: string]: any;
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* postcss autoprefixer, default flexbox: no-2009
|
|
||||||
*/
|
|
||||||
autoprefixer?: {};
|
|
||||||
base?: string;
|
|
||||||
chainWebpack?: () => any;
|
|
||||||
chunks?: string[];
|
|
||||||
/**
|
|
||||||
* more css-loader options see https://webpack.js.org/loaders/css-loader/#options
|
|
||||||
*/
|
|
||||||
cssLoader?: {
|
|
||||||
url?: boolean | (() => any);
|
|
||||||
import?: boolean | (() => any);
|
|
||||||
modules?: boolean | string | {};
|
|
||||||
sourceMap?: boolean;
|
|
||||||
importLoaders?: number;
|
|
||||||
onlyLocals?: boolean;
|
|
||||||
esModule?: boolean;
|
|
||||||
localsConvention?: "asIs" | "camelCase" | "camelCaseOnly" | "dashes" | "dashesOnly";
|
|
||||||
};
|
|
||||||
cssModulesTypescriptLoader?: {
|
|
||||||
mode?: "emit" | "verify";
|
|
||||||
};
|
|
||||||
cssnano?: {};
|
|
||||||
copy?: string[];
|
|
||||||
define?: {};
|
|
||||||
devScripts?: {};
|
|
||||||
/**
|
|
||||||
* devServer configs
|
|
||||||
*/
|
|
||||||
devServer?: {
|
|
||||||
/**
|
|
||||||
* devServer port, default 8000
|
|
||||||
*/
|
|
||||||
port?: number;
|
|
||||||
host?: string;
|
|
||||||
https?:
|
|
||||||
| {
|
|
||||||
key?: string;
|
|
||||||
cert?: string;
|
|
||||||
[k: string]: any;
|
|
||||||
}
|
|
||||||
| boolean;
|
|
||||||
headers?: {};
|
|
||||||
writeToDisk?: boolean | (() => any);
|
|
||||||
[k: string]: any;
|
|
||||||
};
|
|
||||||
devtool?: string;
|
|
||||||
/**
|
|
||||||
* Code splitting for performance optimization
|
|
||||||
*/
|
|
||||||
dynamicImport?: {
|
|
||||||
/**
|
|
||||||
* loading the component before loaded
|
|
||||||
*/
|
|
||||||
loading?: string;
|
|
||||||
};
|
|
||||||
exportStatic?: {
|
|
||||||
htmlSuffix?: boolean;
|
|
||||||
dynamicRoot?: boolean;
|
|
||||||
/**
|
|
||||||
* extra render paths only enable in ssr
|
|
||||||
*/
|
|
||||||
extraRoutePaths?: () => any;
|
|
||||||
};
|
|
||||||
externals?: {} | string | (() => any);
|
|
||||||
extraBabelPlugins?: any[];
|
|
||||||
extraBabelPresets?: any[];
|
|
||||||
extraPostCSSPlugins?: any[];
|
|
||||||
/**
|
|
||||||
* fork-ts-checker-webpack-plugin options see https://github.com/TypeStrong/fork-ts-checker-webpack-plugin#options
|
|
||||||
*/
|
|
||||||
forkTSChecker?: {
|
|
||||||
async?: boolean;
|
|
||||||
typescript?: boolean | {};
|
|
||||||
eslint?: {};
|
|
||||||
issue?: {};
|
|
||||||
formatter?: string | {};
|
|
||||||
logger?: {};
|
|
||||||
[k: string]: any;
|
|
||||||
};
|
|
||||||
hash?: boolean;
|
|
||||||
ignoreMomentLocale?: boolean;
|
|
||||||
inlineLimit?: number;
|
|
||||||
lessLoader?: {};
|
|
||||||
manifest?: {
|
|
||||||
fileName?: string;
|
|
||||||
publicPath?: "";
|
|
||||||
basePath?: string;
|
|
||||||
writeToFileEmit?: boolean;
|
|
||||||
};
|
|
||||||
mountElementId?: "";
|
|
||||||
mpa?: {};
|
|
||||||
nodeModulesTransform?: {
|
|
||||||
type?: "all" | "none";
|
|
||||||
exclude?: string[];
|
|
||||||
};
|
|
||||||
outputPath?: "";
|
|
||||||
plugins?: string[];
|
|
||||||
postcssLoader?: {};
|
|
||||||
presets?: string[];
|
|
||||||
proxy?: {};
|
|
||||||
publicPath?: string;
|
|
||||||
runtimePublicPath?: boolean;
|
|
||||||
ssr?: {
|
|
||||||
/**
|
|
||||||
* remove window.g_initialProps in html, to force execing Page getInitialProps functions
|
|
||||||
*/
|
|
||||||
forceInitial?: boolean;
|
|
||||||
/**
|
|
||||||
* disable serve-side render in umi dev mode.
|
|
||||||
*/
|
|
||||||
devServerRender?: boolean;
|
|
||||||
mode?: "stream" | "string";
|
|
||||||
/**
|
|
||||||
* static markup in static site
|
|
||||||
*/
|
|
||||||
staticMarkup?: boolean;
|
|
||||||
};
|
|
||||||
singular?: boolean;
|
|
||||||
styleLoader?: {};
|
|
||||||
targets?: {};
|
|
||||||
terserOptions?: {};
|
|
||||||
theme?: {};
|
|
||||||
runtimeHistory?: {};
|
|
||||||
favicon?: string;
|
|
||||||
headScripts?: any[];
|
|
||||||
links?: any[];
|
|
||||||
metas?: any[];
|
|
||||||
scripts?: any[];
|
|
||||||
styles?: any[];
|
|
||||||
title?: string;
|
|
||||||
mock?: {
|
|
||||||
exclude?: string[];
|
|
||||||
};
|
|
||||||
antd?: {
|
|
||||||
dark?: boolean;
|
|
||||||
compact?: boolean;
|
|
||||||
config?: {};
|
|
||||||
};
|
|
||||||
dva?: {
|
|
||||||
immer?: boolean;
|
|
||||||
hmr?: boolean;
|
|
||||||
skipModelValidate?: boolean;
|
|
||||||
extraModels?: string[];
|
|
||||||
};
|
|
||||||
locale?: {
|
|
||||||
default?: string;
|
|
||||||
useLocalStorage?: boolean;
|
|
||||||
baseNavigator?: boolean;
|
|
||||||
title?: boolean;
|
|
||||||
antd?: boolean;
|
|
||||||
baseSeparator?: string;
|
|
||||||
};
|
|
||||||
layout?: {};
|
|
||||||
request?: {
|
|
||||||
dataField?: "";
|
|
||||||
};
|
|
||||||
sass?: {
|
|
||||||
implementation?: any;
|
|
||||||
sassOptions?: {};
|
|
||||||
prependData?: string | (() => any);
|
|
||||||
sourceMap?: boolean;
|
|
||||||
webpackImporter?: boolean;
|
|
||||||
};
|
|
||||||
[k: string]: any;
|
|
||||||
}
|
|
||||||
@ -1,18 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
import { plugin } from './plugin';
|
|
||||||
import * as Plugin_0 from '/Users/apple/Desktop/github/zhiku.tec/h5-visible-tool/src/.umi/plugin-dva/runtime.tsx';
|
|
||||||
import * as Plugin_1 from '../plugin-initial-state/runtime';
|
|
||||||
import * as Plugin_2 from '../plugin-model/runtime';
|
|
||||||
|
|
||||||
plugin.register({
|
|
||||||
apply: Plugin_0,
|
|
||||||
path: '/Users/apple/Desktop/github/zhiku.tec/h5-visible-tool/src/.umi/plugin-dva/runtime.tsx',
|
|
||||||
});
|
|
||||||
plugin.register({
|
|
||||||
apply: Plugin_1,
|
|
||||||
path: '../plugin-initial-state/runtime',
|
|
||||||
});
|
|
||||||
plugin.register({
|
|
||||||
apply: Plugin_2,
|
|
||||||
path: '../plugin-model/runtime',
|
|
||||||
});
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
import 'core-js';
|
|
||||||
import 'regenerator-runtime/runtime';
|
|
||||||
@ -1,38 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
import { ApplyPluginsType, dynamic } from '/Users/apple/Desktop/github/zhiku.tec/h5-visible-tool/node_modules/@umijs/runtime';
|
|
||||||
import { plugin } from './plugin';
|
|
||||||
import LoadingComponent from '@/components/LoadingCp';
|
|
||||||
|
|
||||||
export function getRoutes() {
|
|
||||||
const routes = [
|
|
||||||
{
|
|
||||||
"path": "/",
|
|
||||||
"routes": [
|
|
||||||
{
|
|
||||||
"path": "/editor",
|
|
||||||
"component": dynamic({ loader: () => import(/* webpackChunkName: 'p__editor' */'/Users/apple/Desktop/github/zhiku.tec/h5-visible-tool/src/pages/editor'), loading: LoadingComponent}),
|
|
||||||
"exact": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "/login",
|
|
||||||
"component": dynamic({ loader: () => import(/* webpackChunkName: 'p__login' */'/Users/apple/Desktop/github/zhiku.tec/h5-visible-tool/src/pages/login'), loading: LoadingComponent}),
|
|
||||||
"exact": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "/preview",
|
|
||||||
"component": dynamic({ loader: () => import(/* webpackChunkName: 'p__editor__preview' */'/Users/apple/Desktop/github/zhiku.tec/h5-visible-tool/src/pages/editor/preview'), loading: LoadingComponent}),
|
|
||||||
"exact": true
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
// allow user to extend routes
|
|
||||||
plugin.applyPlugins({
|
|
||||||
key: 'patchRoutes',
|
|
||||||
type: ApplyPluginsType.event,
|
|
||||||
args: { routes },
|
|
||||||
});
|
|
||||||
|
|
||||||
return routes;
|
|
||||||
}
|
|
||||||
@ -1,9 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
export { history, setCreateHistoryOptions } from './history';
|
|
||||||
export { plugin } from './plugin';
|
|
||||||
export * from '../plugin-dva/exports';
|
|
||||||
export * from '../plugin-dva/connect';
|
|
||||||
export * from '../plugin-initial-state/exports';
|
|
||||||
export * from '../plugin-model/useModel';
|
|
||||||
export * from '../plugin-request/request';
|
|
||||||
export * from '../plugin-helmet/exports';
|
|
||||||
@ -1,83 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
import { IRoute } from '@umijs/core';
|
|
||||||
import { AnyAction } from 'redux';
|
|
||||||
import React from 'react';
|
|
||||||
import { EffectsCommandMap, SubscriptionAPI } from 'dva';
|
|
||||||
import { match } from 'react-router-dom';
|
|
||||||
import { Location, LocationState, History } from 'history';
|
|
||||||
|
|
||||||
export * from '/Users/apple/Desktop/github/zhiku.tec/h5-visible-tool/src/pages/editor/models/editorModal';
|
|
||||||
|
|
||||||
export interface Action<T = any> {
|
|
||||||
type: T
|
|
||||||
}
|
|
||||||
|
|
||||||
export type Reducer<S = any, A extends Action = AnyAction> = (
|
|
||||||
state: S | undefined,
|
|
||||||
action: A
|
|
||||||
) => S;
|
|
||||||
|
|
||||||
export type ImmerReducer<S = any, A extends Action = AnyAction> = (
|
|
||||||
state: S,
|
|
||||||
action: A
|
|
||||||
) => void;
|
|
||||||
|
|
||||||
export type Effect = (
|
|
||||||
action: AnyAction,
|
|
||||||
effects: EffectsCommandMap,
|
|
||||||
) => void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @type P: Type of payload
|
|
||||||
* @type C: Type of callback
|
|
||||||
*/
|
|
||||||
export type Dispatch = <P = any, C = (payload: P) => void>(action: {
|
|
||||||
type: string;
|
|
||||||
payload?: P;
|
|
||||||
callback?: C;
|
|
||||||
[key: string]: any;
|
|
||||||
}) => any;
|
|
||||||
|
|
||||||
export type Subscription = (api: SubscriptionAPI, done: Function) => void | Function;
|
|
||||||
|
|
||||||
export interface Loading {
|
|
||||||
global: boolean;
|
|
||||||
effects: { [key: string]: boolean | undefined };
|
|
||||||
models: {
|
|
||||||
[key: string]: any;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @type P: Params matched in dynamic routing
|
|
||||||
*/
|
|
||||||
export interface ConnectProps<
|
|
||||||
P extends { [K in keyof P]?: string } = {},
|
|
||||||
S = LocationState,
|
|
||||||
T = {}
|
|
||||||
> {
|
|
||||||
dispatch?: Dispatch;
|
|
||||||
// https://github.com/umijs/umi/pull/2194
|
|
||||||
match?: match<P>;
|
|
||||||
location: Location<S> & { query: T };
|
|
||||||
history: History;
|
|
||||||
route: IRoute;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type RequiredConnectProps<
|
|
||||||
P extends { [K in keyof P]?: string } = {},
|
|
||||||
S = LocationState,
|
|
||||||
T = {}
|
|
||||||
> = Required<ConnectProps<P, S, T>>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @type T: React props
|
|
||||||
* @type U: match props types
|
|
||||||
*/
|
|
||||||
export type ConnectRC<
|
|
||||||
T = {},
|
|
||||||
U = {},
|
|
||||||
S = {},
|
|
||||||
Q = {}
|
|
||||||
> = React.ForwardRefRenderFunction<any, T & RequiredConnectProps<U, S, Q>>;
|
|
||||||
|
|
||||||
@ -1,68 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
import { Component } from 'react';
|
|
||||||
import { ApplyPluginsType } from 'umi';
|
|
||||||
import dva from 'dva';
|
|
||||||
// @ts-ignore
|
|
||||||
import createLoading from '/Users/apple/Desktop/github/zhiku.tec/h5-visible-tool/node_modules/dva-loading/dist/index.esm.js';
|
|
||||||
import { plugin, history } from '../core/umiExports';
|
|
||||||
|
|
||||||
let app:any = null;
|
|
||||||
|
|
||||||
export function _onCreate(options = {}) {
|
|
||||||
const runtimeDva = plugin.applyPlugins({
|
|
||||||
key: 'dva',
|
|
||||||
type: ApplyPluginsType.modify,
|
|
||||||
initialValue: {},
|
|
||||||
});
|
|
||||||
app = dva({
|
|
||||||
history,
|
|
||||||
|
|
||||||
...(runtimeDva.config || {}),
|
|
||||||
// @ts-ignore
|
|
||||||
...(typeof window !== 'undefined' && window.g_useSSR ? { initialState: window.g_initialProps } : {}),
|
|
||||||
...(options || {}),
|
|
||||||
});
|
|
||||||
|
|
||||||
app.use(createLoading());
|
|
||||||
app.use(require('/Users/apple/Desktop/github/zhiku.tec/h5-visible-tool/node_modules/dva-immer/dist/index.js')());
|
|
||||||
(runtimeDva.plugins || []).forEach((plugin:any) => {
|
|
||||||
app.use(plugin);
|
|
||||||
});
|
|
||||||
app.model({ namespace: 'editorModal', ...(require('/Users/apple/Desktop/github/zhiku.tec/h5-visible-tool/src/pages/editor/models/editorModal.js').default) });
|
|
||||||
return app;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getApp() {
|
|
||||||
return app;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class _DvaContainer extends Component {
|
|
||||||
constructor(props: any) {
|
|
||||||
super(props);
|
|
||||||
// run only in client, avoid override server _onCreate()
|
|
||||||
if (typeof window !== 'undefined') {
|
|
||||||
_onCreate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
componentWillUnmount() {
|
|
||||||
let app = getApp();
|
|
||||||
app._models.forEach((model:any) => {
|
|
||||||
app.unmodel(model.namespace);
|
|
||||||
});
|
|
||||||
app._models = [];
|
|
||||||
try {
|
|
||||||
// 释放 app,for gc
|
|
||||||
// immer 场景 app 是 read-only 的,这里 try catch 一下
|
|
||||||
app = null;
|
|
||||||
} catch(e) {
|
|
||||||
console.error(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
const app = getApp();
|
|
||||||
app.router(() => this.props.children);
|
|
||||||
return app.start()();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
|
|
||||||
export { connect, useDispatch, useStore, useSelector } from '/Users/apple/Desktop/github/zhiku.tec/h5-visible-tool/node_modules/dva';
|
|
||||||
export { getApp as getDvaApp } from './dva';
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
import React from 'react';
|
|
||||||
import { _DvaContainer, getApp, _onCreate } from './dva';
|
|
||||||
|
|
||||||
export function rootContainer(container) {
|
|
||||||
return React.createElement(_DvaContainer, null, container);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
// @ts-ignore
|
|
||||||
export { Helmet } from '/Users/apple/Desktop/github/zhiku.tec/h5-visible-tool/node_modules/react-helmet';
|
|
||||||
@ -1,26 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
|
|
||||||
import React, { useRef, useEffect } from 'react';
|
|
||||||
import { useModel } from '../plugin-model/useModel';
|
|
||||||
if (typeof useModel !== 'function') {
|
|
||||||
throw new Error('[plugin-initial-state]: useModel is not a function, @umijs/plugin-model is required.')
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Props {
|
|
||||||
children: React.ReactNode;
|
|
||||||
}
|
|
||||||
export default (props: Props) => {
|
|
||||||
const { children } = props;
|
|
||||||
const appLoaded = useRef(false);
|
|
||||||
const { loading = false } = useModel('@@initialState') || {};
|
|
||||||
useEffect(()=>{
|
|
||||||
if(!loading){
|
|
||||||
appLoaded.current = true
|
|
||||||
}
|
|
||||||
}, [loading])
|
|
||||||
// initial state loading 时,阻塞渲染
|
|
||||||
if (loading && !appLoaded.current) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return children;
|
|
||||||
};
|
|
||||||
@ -1,7 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
import { InitialState as InitialStateType } from '../plugin-initial-state/models/initialState';
|
|
||||||
|
|
||||||
export type InitialState = InitialStateType;
|
|
||||||
export const __PLUGIN_INITIAL_STATE = 1;
|
|
||||||
@ -1,2 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
export default () => ({ loading: false, refresh: () => {} })
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
import React from 'react';
|
|
||||||
import Provider from './Provider';
|
|
||||||
|
|
||||||
export function rootContainer(container: React.ReactNode) {
|
|
||||||
return React.createElement(
|
|
||||||
// 这里的 plugin-initial-state 不能从 constant 里取,里面有 path 依赖
|
|
||||||
// 但 webpack-5 没有 node 补丁(包括 path)
|
|
||||||
Provider,
|
|
||||||
null,
|
|
||||||
container,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@ -1,39 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
import React from 'react';
|
|
||||||
import initialState from '/Users/apple/Desktop/github/zhiku.tec/h5-visible-tool/src/.umi/plugin-initial-state/models/initialState';
|
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
import Dispatcher from '/Users/apple/Desktop/github/zhiku.tec/h5-visible-tool/node_modules/@umijs/plugin-model/lib/helpers/dispatcher';
|
|
||||||
// @ts-ignore
|
|
||||||
import Executor from '/Users/apple/Desktop/github/zhiku.tec/h5-visible-tool/node_modules/@umijs/plugin-model/lib/helpers/executor';
|
|
||||||
// @ts-ignore
|
|
||||||
import { UmiContext } from '/Users/apple/Desktop/github/zhiku.tec/h5-visible-tool/node_modules/@umijs/plugin-model/lib/helpers/constant';
|
|
||||||
|
|
||||||
export const models = { '@@initialState': initialState, };
|
|
||||||
|
|
||||||
export type Model<T extends keyof typeof models> = {
|
|
||||||
[key in keyof typeof models]: ReturnType<typeof models[T]>;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type Models<T extends keyof typeof models> = Model<T>[T]
|
|
||||||
|
|
||||||
const dispatcher = new Dispatcher!();
|
|
||||||
const Exe = Executor!;
|
|
||||||
|
|
||||||
export default ({ children }: { children: React.ReactNode }) => {
|
|
||||||
|
|
||||||
return (
|
|
||||||
<UmiContext.Provider value={dispatcher}>
|
|
||||||
{
|
|
||||||
Object.entries(models).map(pair => (
|
|
||||||
<Exe key={pair[0]} namespace={pair[0]} hook={pair[1] as any} onUpdate={(val: any) => {
|
|
||||||
const [ns] = pair as [keyof typeof models, any];
|
|
||||||
dispatcher.data[ns] = val;
|
|
||||||
dispatcher.update(ns);
|
|
||||||
}} />
|
|
||||||
))
|
|
||||||
}
|
|
||||||
{children}
|
|
||||||
</UmiContext.Provider>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
/* eslint-disable import/no-dynamic-require */
|
|
||||||
import React from 'react';
|
|
||||||
import Provider from './Provider';
|
|
||||||
|
|
||||||
export function rootContainer(container: React.ReactNode) {
|
|
||||||
return React.createElement(
|
|
||||||
Provider,
|
|
||||||
null,
|
|
||||||
container,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@ -1,53 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
import { useState, useEffect, useContext, useRef } from 'react';
|
|
||||||
// @ts-ignore
|
|
||||||
import isEqual from '/Users/apple/Desktop/github/zhiku.tec/h5-visible-tool/node_modules/fast-deep-equal/index.js';
|
|
||||||
// @ts-ignore
|
|
||||||
import { UmiContext } from '/Users/apple/Desktop/github/zhiku.tec/h5-visible-tool/node_modules/@umijs/plugin-model/lib/helpers/constant';
|
|
||||||
import { Model, models } from './Provider';
|
|
||||||
|
|
||||||
export type Models<T extends keyof typeof models> = Model<T>[T]
|
|
||||||
|
|
||||||
export function useModel<T extends keyof Model<T>>(model: T): Model<T>[T]
|
|
||||||
export function useModel<T extends keyof Model<T>, U>(model: T, selector: (model: Model<T>[T]) => U): U
|
|
||||||
|
|
||||||
export function useModel<T extends keyof Model<T>, U>(
|
|
||||||
namespace: T,
|
|
||||||
updater?: (model: Model<T>[T]) => U
|
|
||||||
) : typeof updater extends undefined ? Model<T>[T] : ReturnType<NonNullable<typeof updater>>{
|
|
||||||
|
|
||||||
type RetState = typeof updater extends undefined ? Model<T>[T] : ReturnType<NonNullable<typeof updater>>
|
|
||||||
const dispatcher = useContext<any>(UmiContext);
|
|
||||||
const updaterRef = useRef(updater);
|
|
||||||
updaterRef.current = updater;
|
|
||||||
const [state, setState] = useState<RetState>(
|
|
||||||
() => updaterRef.current ? updaterRef.current(dispatcher.data![namespace]) : dispatcher.data![namespace]
|
|
||||||
);
|
|
||||||
const stateRef = useRef<any>(state);
|
|
||||||
stateRef.current = state;
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const handler = (e: any) => {
|
|
||||||
if(updater && updaterRef.current){
|
|
||||||
const currentState = updaterRef.current(e);
|
|
||||||
const previousState = stateRef.current
|
|
||||||
if(!isEqual(currentState, previousState)){
|
|
||||||
setState(currentState);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
setState(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
dispatcher.callbacks![namespace]!.add(handler);
|
|
||||||
} catch (e) {
|
|
||||||
dispatcher.callbacks![namespace] = new Set();
|
|
||||||
dispatcher.callbacks![namespace]!.add(handler);
|
|
||||||
}
|
|
||||||
return () => {
|
|
||||||
dispatcher.callbacks![namespace]!.delete(handler);
|
|
||||||
}
|
|
||||||
}, [namespace]);
|
|
||||||
|
|
||||||
return state;
|
|
||||||
};
|
|
||||||
@ -1,274 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
/**
|
|
||||||
* Base on https://github.com/umijs//Users/apple/Desktop/github/zhiku.tec/h5-visible-tool/node_modules/umi-request
|
|
||||||
*/
|
|
||||||
import {
|
|
||||||
extend,
|
|
||||||
Context,
|
|
||||||
RequestOptionsInit,
|
|
||||||
OnionMiddleware,
|
|
||||||
RequestOptionsWithoutResponse,
|
|
||||||
RequestMethod,
|
|
||||||
RequestOptionsWithResponse,
|
|
||||||
RequestResponse,
|
|
||||||
RequestInterceptor,
|
|
||||||
ResponseInterceptor,
|
|
||||||
} from '/Users/apple/Desktop/github/zhiku.tec/h5-visible-tool/node_modules/umi-request';
|
|
||||||
// @ts-ignore
|
|
||||||
|
|
||||||
import { ApplyPluginsType } from 'umi';
|
|
||||||
import { history, plugin } from '../core/umiExports';
|
|
||||||
|
|
||||||
import { message, notification } from 'antd';
|
|
||||||
import useUmiRequest, { UseRequestProvider } from '/Users/apple/Desktop/github/zhiku.tec/h5-visible-tool/node_modules/@ahooksjs/use-request';
|
|
||||||
import {
|
|
||||||
BaseOptions,
|
|
||||||
BasePaginatedOptions,
|
|
||||||
BaseResult,
|
|
||||||
CombineService,
|
|
||||||
LoadMoreFormatReturn,
|
|
||||||
LoadMoreOptions,
|
|
||||||
LoadMoreOptionsWithFormat,
|
|
||||||
LoadMoreParams,
|
|
||||||
LoadMoreResult,
|
|
||||||
OptionsWithFormat,
|
|
||||||
PaginatedFormatReturn,
|
|
||||||
PaginatedOptionsWithFormat,
|
|
||||||
PaginatedParams,
|
|
||||||
PaginatedResult,
|
|
||||||
} from '/Users/apple/Desktop/github/zhiku.tec/h5-visible-tool/node_modules/@ahooksjs/use-request/lib/types';
|
|
||||||
|
|
||||||
type ResultWithData<T = any> = { data?: T; [key: string]: any };
|
|
||||||
|
|
||||||
function useRequest<
|
|
||||||
R = any,
|
|
||||||
P extends any[] = any,
|
|
||||||
U = any,
|
|
||||||
UU extends U = any
|
|
||||||
>(
|
|
||||||
service: CombineService<R, P>,
|
|
||||||
options: OptionsWithFormat<R, P, U, UU>,
|
|
||||||
): BaseResult<U, P>;
|
|
||||||
function useRequest<R extends ResultWithData = any, P extends any[] = any>(
|
|
||||||
service: CombineService<R, P>,
|
|
||||||
options?: BaseOptions<R['data'], P>,
|
|
||||||
): BaseResult<R['data'], P>;
|
|
||||||
function useRequest<R extends LoadMoreFormatReturn = any, RR = any>(
|
|
||||||
service: CombineService<RR, LoadMoreParams<R>>,
|
|
||||||
options: LoadMoreOptionsWithFormat<R, RR>,
|
|
||||||
): LoadMoreResult<R>;
|
|
||||||
function useRequest<
|
|
||||||
R extends ResultWithData<LoadMoreFormatReturn | any> = any,
|
|
||||||
RR extends R = any
|
|
||||||
>(
|
|
||||||
service: CombineService<R, LoadMoreParams<R['data']>>,
|
|
||||||
options: LoadMoreOptions<RR['data']>,
|
|
||||||
): LoadMoreResult<R['data']>;
|
|
||||||
|
|
||||||
function useRequest<R = any, Item = any, U extends Item = any>(
|
|
||||||
service: CombineService<R, PaginatedParams>,
|
|
||||||
options: PaginatedOptionsWithFormat<R, Item, U>,
|
|
||||||
): PaginatedResult<Item>;
|
|
||||||
function useRequest<Item = any, U extends Item = any>(
|
|
||||||
service: CombineService<
|
|
||||||
ResultWithData<PaginatedFormatReturn<Item>>,
|
|
||||||
PaginatedParams
|
|
||||||
>,
|
|
||||||
options: BasePaginatedOptions<U>,
|
|
||||||
): PaginatedResult<Item>;
|
|
||||||
function useRequest(service: any, options: any = {}) {
|
|
||||||
return useUmiRequest(service, {
|
|
||||||
formatResult: result => result?.data,
|
|
||||||
requestMethod: (requestOptions: any) => {
|
|
||||||
if (typeof requestOptions === 'string') {
|
|
||||||
return request(requestOptions);
|
|
||||||
}
|
|
||||||
if (typeof requestOptions === 'object') {
|
|
||||||
const { url, ...rest } = requestOptions;
|
|
||||||
return request(url, rest);
|
|
||||||
}
|
|
||||||
throw new Error('request options error');
|
|
||||||
},
|
|
||||||
...options,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface RequestConfig extends RequestOptionsInit {
|
|
||||||
errorConfig?: {
|
|
||||||
errorPage?: string;
|
|
||||||
adaptor?: (resData: any, ctx: Context) => ErrorInfoStructure;
|
|
||||||
};
|
|
||||||
middlewares?: OnionMiddleware[];
|
|
||||||
requestInterceptors?: RequestInterceptor[];
|
|
||||||
responseInterceptors?: ResponseInterceptor[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum ErrorShowType {
|
|
||||||
SILENT = 0,
|
|
||||||
WARN_MESSAGE = 1,
|
|
||||||
ERROR_MESSAGE = 2,
|
|
||||||
NOTIFICATION = 4,
|
|
||||||
REDIRECT = 9,
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ErrorInfoStructure {
|
|
||||||
success: boolean;
|
|
||||||
data?: any;
|
|
||||||
errorCode?: string;
|
|
||||||
errorMessage?: string;
|
|
||||||
showType?: ErrorShowType;
|
|
||||||
traceId?: string;
|
|
||||||
host?: string;
|
|
||||||
[key: string]: any;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface RequestError extends Error {
|
|
||||||
data?: any;
|
|
||||||
info?: ErrorInfoStructure;
|
|
||||||
request?: Context['req'];
|
|
||||||
response?: Context['res'];
|
|
||||||
}
|
|
||||||
|
|
||||||
const DEFAULT_ERROR_PAGE = '/exception';
|
|
||||||
|
|
||||||
let requestMethodInstance: RequestMethod;
|
|
||||||
const getRequestMethod = () => {
|
|
||||||
if (requestMethodInstance) {
|
|
||||||
// request method 已经示例化
|
|
||||||
return requestMethodInstance;
|
|
||||||
}
|
|
||||||
|
|
||||||
// runtime 配置可能应为依赖顺序的问题在模块初始化的时候无法获取,所以需要封装一层在异步调用后初始化相关方法
|
|
||||||
// 当用户的 app.ts 中依赖了该文件的情况下就该模块的初始化时间就会被提前,无法获取到运行时配置
|
|
||||||
const requestConfig: RequestConfig = plugin.applyPlugins({
|
|
||||||
key: 'request',
|
|
||||||
type: ApplyPluginsType.modify,
|
|
||||||
initialValue: {},
|
|
||||||
});
|
|
||||||
|
|
||||||
const errorAdaptor =
|
|
||||||
requestConfig.errorConfig?.adaptor || (resData => resData);
|
|
||||||
|
|
||||||
requestMethodInstance = extend({
|
|
||||||
errorHandler: (error: RequestError) => {
|
|
||||||
// @ts-ignore
|
|
||||||
if (error?.request?.options?.skipErrorHandler) {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
let errorInfo: ErrorInfoStructure | undefined;
|
|
||||||
if (error.name === 'ResponseError' && error.data && error.request) {
|
|
||||||
const ctx: Context = {
|
|
||||||
req: error.request,
|
|
||||||
res: error.response,
|
|
||||||
};
|
|
||||||
errorInfo = errorAdaptor(error.data, ctx);
|
|
||||||
error.message = errorInfo?.errorMessage || error.message;
|
|
||||||
error.data = error.data;
|
|
||||||
error.info = errorInfo;
|
|
||||||
}
|
|
||||||
errorInfo = error.info;
|
|
||||||
|
|
||||||
if (errorInfo) {
|
|
||||||
const errorMessage = errorInfo?.errorMessage;
|
|
||||||
const errorCode = errorInfo?.errorCode;
|
|
||||||
const errorPage =
|
|
||||||
requestConfig.errorConfig?.errorPage || DEFAULT_ERROR_PAGE;
|
|
||||||
|
|
||||||
switch (errorInfo?.showType) {
|
|
||||||
case ErrorShowType.SILENT:
|
|
||||||
// do nothing
|
|
||||||
break;
|
|
||||||
case ErrorShowType.WARN_MESSAGE:
|
|
||||||
message.warn(errorMessage);
|
|
||||||
break;
|
|
||||||
case ErrorShowType.ERROR_MESSAGE:
|
|
||||||
message.error(errorMessage);
|
|
||||||
break;
|
|
||||||
case ErrorShowType.NOTIFICATION:
|
|
||||||
notification.open({
|
|
||||||
message: errorMessage,
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
case ErrorShowType.REDIRECT:
|
|
||||||
// @ts-ignore
|
|
||||||
history.push({
|
|
||||||
pathname: errorPage,
|
|
||||||
query: { errorCode, errorMessage },
|
|
||||||
});
|
|
||||||
// redirect to error page
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
message.error(errorMessage);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
message.error(error.message || 'Request error, please retry.');
|
|
||||||
}
|
|
||||||
throw error;
|
|
||||||
},
|
|
||||||
...requestConfig,
|
|
||||||
});
|
|
||||||
|
|
||||||
// 中间件统一错误处理
|
|
||||||
// 后端返回格式 { success: boolean, data: any }
|
|
||||||
// 按照项目具体情况修改该部分逻辑
|
|
||||||
requestMethodInstance.use(async (ctx, next) => {
|
|
||||||
await next();
|
|
||||||
const { req, res } = ctx;
|
|
||||||
// @ts-ignore
|
|
||||||
if (req.options?.skipErrorHandler) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const { options } = req;
|
|
||||||
const { getResponse } = options;
|
|
||||||
const resData = getResponse ? res.data : res;
|
|
||||||
const errorInfo = errorAdaptor(resData, ctx);
|
|
||||||
if (errorInfo.success === false) {
|
|
||||||
// 抛出错误到 errorHandler 中处理
|
|
||||||
const error: RequestError = new Error(errorInfo.errorMessage);
|
|
||||||
error.name = 'BizError';
|
|
||||||
error.data = resData;
|
|
||||||
error.info = errorInfo;
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Add user custom middlewares
|
|
||||||
const customMiddlewares = requestConfig.middlewares || [];
|
|
||||||
customMiddlewares.forEach(mw => {
|
|
||||||
requestMethodInstance.use(mw);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Add user custom interceptors
|
|
||||||
const requestInterceptors = requestConfig.requestInterceptors || [];
|
|
||||||
const responseInterceptors = requestConfig.responseInterceptors || [];
|
|
||||||
requestInterceptors.map(ri => {
|
|
||||||
requestMethodInstance.interceptors.request.use(ri);
|
|
||||||
});
|
|
||||||
responseInterceptors.map(ri => {
|
|
||||||
requestMethodInstance.interceptors.response.use(ri);
|
|
||||||
});
|
|
||||||
|
|
||||||
return requestMethodInstance;
|
|
||||||
};
|
|
||||||
|
|
||||||
interface RequestMethodInUmi<R = false> {
|
|
||||||
<T = any>(
|
|
||||||
url: string,
|
|
||||||
options: RequestOptionsWithResponse & { skipErrorHandler?: boolean },
|
|
||||||
): Promise<RequestResponse<T>>;
|
|
||||||
<T = any>(
|
|
||||||
url: string,
|
|
||||||
options: RequestOptionsWithoutResponse & { skipErrorHandler?: boolean },
|
|
||||||
): Promise<T>;
|
|
||||||
<T = any>(
|
|
||||||
url: string,
|
|
||||||
options?: RequestOptionsInit & { skipErrorHandler?: boolean },
|
|
||||||
): R extends true ? Promise<RequestResponse<T>> : Promise<T>;
|
|
||||||
}
|
|
||||||
const request: RequestMethodInUmi = (url: any, options: any) => {
|
|
||||||
const requestMethod = getRequestMethod();
|
|
||||||
return requestMethod(url, options);
|
|
||||||
};
|
|
||||||
|
|
||||||
export { request, useRequest, UseRequestProvider };
|
|
||||||
@ -1,59 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
import './core/polyfill';
|
|
||||||
import '@@/core/devScripts';
|
|
||||||
import { plugin } from './core/plugin';
|
|
||||||
import './core/pluginRegister';
|
|
||||||
import { createHistory } from './core/history';
|
|
||||||
import { ApplyPluginsType } from '/Users/apple/Desktop/github/zhiku.tec/h5-visible-tool/node_modules/@umijs/runtime';
|
|
||||||
import { renderClient } from '/Users/apple/Desktop/github/zhiku.tec/h5-visible-tool/node_modules/@umijs/renderer-react/dist/index.js';
|
|
||||||
import { getRoutes } from './core/routes';
|
|
||||||
|
|
||||||
|
|
||||||
require('../global.css');
|
|
||||||
|
|
||||||
const getClientRender = (args: { hot?: boolean; routes?: any[] } = {}) => plugin.applyPlugins({
|
|
||||||
key: 'render',
|
|
||||||
type: ApplyPluginsType.compose,
|
|
||||||
initialValue: () => {
|
|
||||||
const opts = plugin.applyPlugins({
|
|
||||||
key: 'modifyClientRenderOpts',
|
|
||||||
type: ApplyPluginsType.modify,
|
|
||||||
initialValue: {
|
|
||||||
routes: args.routes || getRoutes(),
|
|
||||||
plugin,
|
|
||||||
history: createHistory(args.hot),
|
|
||||||
isServer: process.env.__IS_SERVER,
|
|
||||||
dynamicImport: true,
|
|
||||||
rootElement: 'root',
|
|
||||||
defaultTitle: `趣谈前端-h5-visible-tool`,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
return renderClient(opts);
|
|
||||||
},
|
|
||||||
args,
|
|
||||||
});
|
|
||||||
|
|
||||||
const clientRender = getClientRender();
|
|
||||||
export default clientRender();
|
|
||||||
|
|
||||||
|
|
||||||
window.g_umi = {
|
|
||||||
version: '3.2.16',
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// hot module replacement
|
|
||||||
// @ts-ignore
|
|
||||||
if (module.hot) {
|
|
||||||
// @ts-ignore
|
|
||||||
module.hot.accept('./core/routes', () => {
|
|
||||||
const ret = require('./core/routes');
|
|
||||||
if (ret.then) {
|
|
||||||
ret.then(({ getRoutes }) => {
|
|
||||||
getClientRender({ hot: true, routes: getRoutes() })();
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
getClientRender({ hot: true, routes: ret.getRoutes() })();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@ -46,7 +46,7 @@ export default memo(function MutiText(props) {
|
|||||||
<Popconfirm
|
<Popconfirm
|
||||||
title="确定要删除吗?"
|
title="确定要删除吗?"
|
||||||
onConfirm={handleDel.bind(this, i)}
|
onConfirm={handleDel.bind(this, i)}
|
||||||
placement="leftTop "
|
placement="leftTop"
|
||||||
okText="确定"
|
okText="确定"
|
||||||
cancelText="取消"
|
cancelText="取消"
|
||||||
>
|
>
|
||||||
|
|||||||
@ -1,25 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
|
|
||||||
export default class UmiReactTitle extends React.Component {
|
|
||||||
componentDidMount() {
|
|
||||||
document.title = this.props.route._title;
|
|
||||||
}
|
|
||||||
getTitle() {
|
|
||||||
const separator = '' || ' - ';
|
|
||||||
const title = this.props.route._title.split(separator).map(item => {
|
|
||||||
return formatMessage({
|
|
||||||
id: item.trim(),
|
|
||||||
defaultMessage: item.trim(),
|
|
||||||
});
|
|
||||||
})
|
|
||||||
return title.join(separator);
|
|
||||||
}
|
|
||||||
componentWillUnmount() {
|
|
||||||
if (document.title === this.props.route._title) {
|
|
||||||
document.title = this.props.route._title;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
render() {
|
|
||||||
return this.props.children;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,37 +0,0 @@
|
|||||||
import dva from 'dva';
|
|
||||||
import { Component } from 'react';
|
|
||||||
import createLoading from 'dva-loading';
|
|
||||||
import history from '@tmp/history';
|
|
||||||
|
|
||||||
let app = null;
|
|
||||||
|
|
||||||
export function _onCreate() {
|
|
||||||
const plugins = require('umi/_runtimePlugin');
|
|
||||||
const runtimeDva = plugins.mergeConfig('dva');
|
|
||||||
app = dva({
|
|
||||||
history,
|
|
||||||
|
|
||||||
...(runtimeDva.config || {}),
|
|
||||||
...(window.g_useSSR ? { initialState: window.g_initialData } : {}),
|
|
||||||
});
|
|
||||||
|
|
||||||
app.use(createLoading());
|
|
||||||
(runtimeDva.plugins || []).forEach(plugin => {
|
|
||||||
app.use(plugin);
|
|
||||||
});
|
|
||||||
app.use(require('/Users/xujiang/Documents/qk/h5-visible-plat/node_modules/dva-immer/dist/index.js')());
|
|
||||||
|
|
||||||
return app;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getApp() {
|
|
||||||
return app;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class _DvaContainer extends Component {
|
|
||||||
render() {
|
|
||||||
const app = getApp();
|
|
||||||
app.router(() => this.props.children);
|
|
||||||
return app.start()();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
// create history
|
|
||||||
const history = require('umi/lib/createHistory').default({
|
|
||||||
basename: window.routerBase,
|
|
||||||
});
|
|
||||||
window.g_history = history;
|
|
||||||
export default history;
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
import 'core-js';
|
|
||||||
import 'regenerator-runtime/runtime';
|
|
||||||
|
|
||||||
@ -1,135 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import {
|
|
||||||
Router as DefaultRouter,
|
|
||||||
Route,
|
|
||||||
Switch,
|
|
||||||
StaticRouter,
|
|
||||||
} from 'react-router-dom';
|
|
||||||
import dynamic from 'umi/dynamic';
|
|
||||||
import renderRoutes from 'umi/lib/renderRoutes';
|
|
||||||
import history from '@@/history';
|
|
||||||
import { routerRedux, dynamic as _dvaDynamic } from 'dva';
|
|
||||||
|
|
||||||
const Router = routerRedux.ConnectedRouter;
|
|
||||||
|
|
||||||
const routes = [
|
|
||||||
{
|
|
||||||
path: '/editor',
|
|
||||||
component: __IS_BROWSER
|
|
||||||
? _dvaDynamic({
|
|
||||||
app: require('@tmp/dva').getApp(),
|
|
||||||
models: () => [
|
|
||||||
import(/* webpackChunkName: 'p__editor__models__editorModal.js' */ '/Users/xujiang/Documents/qk/h5-visible-plat/src/pages/editor/models/editorModal.js').then(
|
|
||||||
m => {
|
|
||||||
return { namespace: 'editorModal', ...m.default };
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
component: () =>
|
|
||||||
import(/* webpackChunkName: "p__editor" */ '../editor'),
|
|
||||||
LoadingComponent: require('/Users/xujiang/Documents/qk/h5-visible-plat/src/components/LoadingCp/index')
|
|
||||||
.default,
|
|
||||||
})
|
|
||||||
: require('../editor').default,
|
|
||||||
exact: true,
|
|
||||||
_title: 'test',
|
|
||||||
_title_default: 'test',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/preview',
|
|
||||||
component: __IS_BROWSER
|
|
||||||
? _dvaDynamic({
|
|
||||||
app: require('@tmp/dva').getApp(),
|
|
||||||
models: () => [
|
|
||||||
import(/* webpackChunkName: 'p__editor__models__editorModal.js' */ '/Users/xujiang/Documents/qk/h5-visible-plat/src/pages/editor/models/editorModal.js').then(
|
|
||||||
m => {
|
|
||||||
return { namespace: 'editorModal', ...m.default };
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
component: () =>
|
|
||||||
import(/* webpackChunkName: "p__editor__preview" */ '../editor/preview'),
|
|
||||||
LoadingComponent: require('/Users/xujiang/Documents/qk/h5-visible-plat/src/components/LoadingCp/index')
|
|
||||||
.default,
|
|
||||||
})
|
|
||||||
: require('../editor/preview').default,
|
|
||||||
exact: true,
|
|
||||||
_title: 'test',
|
|
||||||
_title_default: 'test',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/prevH5',
|
|
||||||
component: __IS_BROWSER
|
|
||||||
? _dvaDynamic({
|
|
||||||
app: require('@tmp/dva').getApp(),
|
|
||||||
models: () => [
|
|
||||||
import(/* webpackChunkName: 'p__editor__models__editorModal.js' */ '/Users/xujiang/Documents/qk/h5-visible-plat/src/pages/editor/models/editorModal.js').then(
|
|
||||||
m => {
|
|
||||||
return { namespace: 'editorModal', ...m.default };
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
component: () =>
|
|
||||||
import(/* webpackChunkName: "p__editor__preH5" */ '../editor/preH5'),
|
|
||||||
LoadingComponent: require('/Users/xujiang/Documents/qk/h5-visible-plat/src/components/LoadingCp/index')
|
|
||||||
.default,
|
|
||||||
})
|
|
||||||
: require('../editor/preH5').default,
|
|
||||||
exact: true,
|
|
||||||
_title: 'test',
|
|
||||||
_title_default: 'test',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
component: () =>
|
|
||||||
React.createElement(
|
|
||||||
require('/Users/xujiang/Documents/qk/h5-visible-plat/node_modules/umi-build-dev/lib/plugins/404/NotFound.js')
|
|
||||||
.default,
|
|
||||||
{ pagesPath: 'src/pages', hasRoutesInConfig: true },
|
|
||||||
),
|
|
||||||
_title: 'test',
|
|
||||||
_title_default: 'test',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
window.g_routes = routes;
|
|
||||||
const plugins = require('umi/_runtimePlugin');
|
|
||||||
plugins.applyForEach('patchRoutes', { initialValue: routes });
|
|
||||||
|
|
||||||
export { routes };
|
|
||||||
|
|
||||||
export default class RouterWrapper extends React.Component {
|
|
||||||
unListen() {}
|
|
||||||
|
|
||||||
constructor(props) {
|
|
||||||
super(props);
|
|
||||||
|
|
||||||
// route change handler
|
|
||||||
function routeChangeHandler(location, action) {
|
|
||||||
plugins.applyForEach('onRouteChange', {
|
|
||||||
initialValue: {
|
|
||||||
routes,
|
|
||||||
location,
|
|
||||||
action,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
this.unListen = history.listen(routeChangeHandler);
|
|
||||||
// dva 中 history.listen 会初始执行一次
|
|
||||||
// 这里排除掉 dva 的场景,可以避免 onRouteChange 在启用 dva 后的初始加载时被多执行一次
|
|
||||||
const isDva =
|
|
||||||
history.listen
|
|
||||||
.toString()
|
|
||||||
.indexOf('callback(history.location, history.action)') > -1;
|
|
||||||
if (!isDva) {
|
|
||||||
routeChangeHandler(history.location);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
componentWillUnmount() {
|
|
||||||
this.unListen();
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
const props = this.props || {};
|
|
||||||
return <Router history={history}>{renderRoutes(routes, props)}</Router>;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,222 +0,0 @@
|
|||||||
import './polyfills';
|
|
||||||
import history from './history';
|
|
||||||
|
|
||||||
import React from 'react';
|
|
||||||
import ReactDOM from 'react-dom';
|
|
||||||
import findRoute, {
|
|
||||||
getUrlQuery,
|
|
||||||
} from '/Users/xujiang/Documents/qk/h5-visible-plat/node_modules/umi-build-dev/lib/findRoute.js';
|
|
||||||
|
|
||||||
// runtime plugins
|
|
||||||
const plugins = require('umi/_runtimePlugin');
|
|
||||||
window.g_plugins = plugins;
|
|
||||||
plugins.init({
|
|
||||||
validKeys: [
|
|
||||||
'patchRoutes',
|
|
||||||
'render',
|
|
||||||
'rootContainer',
|
|
||||||
'modifyRouteProps',
|
|
||||||
'onRouteChange',
|
|
||||||
'modifyInitialProps',
|
|
||||||
'initialProps',
|
|
||||||
'dva',
|
|
||||||
],
|
|
||||||
});
|
|
||||||
plugins.use(require('../../../node_modules/umi-plugin-dva/lib/runtime'));
|
|
||||||
|
|
||||||
const app = require('@tmp/dva')._onCreate();
|
|
||||||
window.g_app = app;
|
|
||||||
|
|
||||||
// render
|
|
||||||
let clientRender = async () => {
|
|
||||||
window.g_isBrowser = true;
|
|
||||||
let props = {};
|
|
||||||
// Both support SSR and CSR
|
|
||||||
if (window.g_useSSR) {
|
|
||||||
// 如果开启服务端渲染则客户端组件初始化 props 使用服务端注入的数据
|
|
||||||
props = window.g_initialData;
|
|
||||||
} else {
|
|
||||||
const pathname = location.pathname;
|
|
||||||
const activeRoute = findRoute(require('@@/router').routes, pathname);
|
|
||||||
// 在客户端渲染前,执行 getInitialProps 方法
|
|
||||||
// 拿到初始数据
|
|
||||||
if (
|
|
||||||
activeRoute &&
|
|
||||||
activeRoute.component &&
|
|
||||||
activeRoute.component.getInitialProps
|
|
||||||
) {
|
|
||||||
const initialProps = plugins.apply('modifyInitialProps', {
|
|
||||||
initialValue: {},
|
|
||||||
});
|
|
||||||
props = activeRoute.component.getInitialProps
|
|
||||||
? await activeRoute.component.getInitialProps({
|
|
||||||
route: activeRoute,
|
|
||||||
isServer: false,
|
|
||||||
location,
|
|
||||||
...initialProps,
|
|
||||||
})
|
|
||||||
: {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const rootContainer = plugins.apply('rootContainer', {
|
|
||||||
initialValue: React.createElement(require('./router').default, props),
|
|
||||||
});
|
|
||||||
ReactDOM[window.g_useSSR ? 'hydrate' : 'render'](
|
|
||||||
rootContainer,
|
|
||||||
document.getElementById('root'),
|
|
||||||
);
|
|
||||||
};
|
|
||||||
const render = plugins.compose(
|
|
||||||
'render',
|
|
||||||
{ initialValue: clientRender },
|
|
||||||
);
|
|
||||||
|
|
||||||
const moduleBeforeRendererPromises = [];
|
|
||||||
// client render
|
|
||||||
if (__IS_BROWSER) {
|
|
||||||
Promise.all(moduleBeforeRendererPromises)
|
|
||||||
.then(() => {
|
|
||||||
render();
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
window.console && window.console.error(err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// export server render
|
|
||||||
let serverRender, ReactDOMServer;
|
|
||||||
if (!__IS_BROWSER) {
|
|
||||||
const { matchRoutes } = require('react-router-config');
|
|
||||||
const { StaticRouter } = require('react-router');
|
|
||||||
// difference: umi-history has query object
|
|
||||||
const { createLocation } = require('umi-history');
|
|
||||||
// don't remove, use stringify html map
|
|
||||||
const stringify = require('serialize-javascript');
|
|
||||||
const router = require('./router');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 1. Load dynamicImport Component
|
|
||||||
* 2. Get Component initialProps function data
|
|
||||||
* return Component props
|
|
||||||
* @param pathname
|
|
||||||
* @param props
|
|
||||||
*/
|
|
||||||
const getInitialProps = async (pathname, props) => {
|
|
||||||
const { routes } = router;
|
|
||||||
const matchedComponents = matchRoutes(routes, pathname)
|
|
||||||
.map(({ route }) => {
|
|
||||||
if (route.component) {
|
|
||||||
return !route.component.preload
|
|
||||||
? // 同步
|
|
||||||
route.component
|
|
||||||
: // 异步,支持 dynamicImport
|
|
||||||
route.component.preload().then(component => component.default);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.filter(c => c);
|
|
||||||
const loadedComponents = await Promise.all(matchedComponents);
|
|
||||||
|
|
||||||
// get Store
|
|
||||||
const initialProps = plugins.apply('modifyInitialProps', {
|
|
||||||
initialValue: {},
|
|
||||||
});
|
|
||||||
// support getInitialProps
|
|
||||||
const promises = loadedComponents.map(component => {
|
|
||||||
if (component && component.getInitialProps) {
|
|
||||||
return component.getInitialProps({
|
|
||||||
isServer: true,
|
|
||||||
...props,
|
|
||||||
...initialProps,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return Promise.resolve(null);
|
|
||||||
});
|
|
||||||
|
|
||||||
return Promise.all(promises);
|
|
||||||
};
|
|
||||||
|
|
||||||
serverRender = async (ctx = {}) => {
|
|
||||||
// ctx.req.url may be `/bar?locale=en-US`
|
|
||||||
const [pathname] = (ctx.req.url || '').split('?');
|
|
||||||
// global
|
|
||||||
global.req = {
|
|
||||||
url: ctx.req.url,
|
|
||||||
};
|
|
||||||
const location = createLocation(ctx.req.url);
|
|
||||||
const activeRoute = findRoute(router.routes, pathname);
|
|
||||||
// omit component
|
|
||||||
const { component, ...restRoute } = activeRoute || {};
|
|
||||||
// router context hook
|
|
||||||
// get current router status 40x / 30x, share with server
|
|
||||||
const context = {};
|
|
||||||
// TODO: getInitialProps timeout handle
|
|
||||||
const initialData = await getInitialProps(pathname, {
|
|
||||||
route: restRoute,
|
|
||||||
// only exist in server
|
|
||||||
req: ctx.req || {},
|
|
||||||
res: ctx.res || {},
|
|
||||||
context,
|
|
||||||
location,
|
|
||||||
});
|
|
||||||
|
|
||||||
// 当前路由(不包含 Layout)的 getInitialProps 有返回值
|
|
||||||
// Page 值为 undefined 时,有 getInitialProps 无返回,此时 return dva model
|
|
||||||
const pageData = initialData[initialData.length - 1];
|
|
||||||
if (pageData === undefined) {
|
|
||||||
initialData[initialData.length - 1] = plugins.apply('initialProps', {
|
|
||||||
initialValue: pageData,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// reduce all match component getInitialProps
|
|
||||||
// in the same object key
|
|
||||||
// page data key will override layout key
|
|
||||||
const props = Array.isArray(initialData)
|
|
||||||
? initialData.reduce(
|
|
||||||
(acc, curr) => ({
|
|
||||||
...acc,
|
|
||||||
...curr,
|
|
||||||
}),
|
|
||||||
{},
|
|
||||||
)
|
|
||||||
: {};
|
|
||||||
|
|
||||||
const App = React.createElement(
|
|
||||||
StaticRouter,
|
|
||||||
{
|
|
||||||
location: ctx.req.url,
|
|
||||||
context,
|
|
||||||
},
|
|
||||||
React.createElement(router.default, props),
|
|
||||||
);
|
|
||||||
|
|
||||||
// render rootContainer for htmlTemplateMap
|
|
||||||
const rootContainer = plugins.apply('rootContainer', {
|
|
||||||
initialValue: App,
|
|
||||||
});
|
|
||||||
const htmlTemplateMap = {};
|
|
||||||
const matchPath = activeRoute ? activeRoute.path : undefined;
|
|
||||||
return {
|
|
||||||
htmlElement: matchPath ? htmlTemplateMap[matchPath] : '',
|
|
||||||
rootContainer,
|
|
||||||
matchPath,
|
|
||||||
g_initialData: props,
|
|
||||||
context,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
// using project react-dom version
|
|
||||||
// https://github.com/facebook/react/issues/13991
|
|
||||||
ReactDOMServer = require('react-dom/server');
|
|
||||||
}
|
|
||||||
|
|
||||||
export { ReactDOMServer };
|
|
||||||
export default (__IS_BROWSER ? null : serverRender);
|
|
||||||
|
|
||||||
require('../../global.css');
|
|
||||||
|
|
||||||
// hot module replacement
|
|
||||||
if (__IS_BROWSER && module.hot) {
|
|
||||||
module.hot.accept('./router', () => {
|
|
||||||
clientRender();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@ -1,57 +1,15 @@
|
|||||||
.layout{
|
.layout{
|
||||||
.editorWrap {
|
.editorWrap {
|
||||||
background-color: rgba(245,245,245,1);
|
background-color: rgba(245,245,245,1);
|
||||||
.header {
|
|
||||||
position: relative;
|
|
||||||
z-index: 10;
|
|
||||||
padding-left: 30px;
|
|
||||||
padding-right: 30px;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
height: 80px;
|
|
||||||
background: #fff;
|
|
||||||
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
|
||||||
.logoArea {
|
|
||||||
width: 300px;
|
|
||||||
.backBtn {
|
|
||||||
display: inline-block;
|
|
||||||
padding: 12px 10px;
|
|
||||||
margin-right: 26px;
|
|
||||||
background-color: rgba(222, 224, 230, 0.3);
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
.logo {
|
|
||||||
display: inline-block;
|
|
||||||
width: 105px;
|
|
||||||
font-size: 24px;
|
|
||||||
font-weight: bold;
|
|
||||||
img {
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.controlArea {
|
|
||||||
flex: 1;
|
|
||||||
text-align: center;
|
|
||||||
.tit {
|
|
||||||
font-size: 18px;
|
|
||||||
color: #000;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.btnArea {
|
|
||||||
width: 400px;
|
|
||||||
text-align: right;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.container {
|
.container {
|
||||||
width: 100vw;
|
width: 100vw;
|
||||||
// height: 100vh;
|
// height: 100vh;
|
||||||
display: flex;
|
display: flex;
|
||||||
.list{
|
.list{
|
||||||
width: 380px;
|
width: 350px;
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
padding: 20px;
|
padding: 10px 16px 16px;
|
||||||
box-shadow: 2px 0px 10px rgba(0,0,0,0.2);
|
box-shadow: 2px 0px 10px rgba(0,0,0,0.2);
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
@ -82,7 +40,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.tickMark{
|
.tickMark{
|
||||||
width: calc(100% - 780px);
|
width: calc(100% - 750px);
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
position: relative;
|
position: relative;
|
||||||
@ -107,7 +65,7 @@
|
|||||||
position: relative;
|
position: relative;
|
||||||
left: 50%;
|
left: 50%;
|
||||||
margin-left: -200px;
|
margin-left: -200px;
|
||||||
top: 100px;
|
top: 80px;
|
||||||
.canvas{
|
.canvas{
|
||||||
position: relative;
|
position: relative;
|
||||||
width: 375px;
|
width: 375px;
|
||||||
@ -128,6 +86,7 @@
|
|||||||
border: 2px solid #06c;
|
border: 2px solid #06c;
|
||||||
}
|
}
|
||||||
:global(a) {
|
:global(a) {
|
||||||
|
display: block;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -135,11 +94,11 @@
|
|||||||
}
|
}
|
||||||
.sliderWrap {
|
.sliderWrap {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
width: 200px;
|
width: 30px;
|
||||||
right: 60px;
|
right: 10px;
|
||||||
bottom: 90px;
|
bottom: 130px;
|
||||||
.slider {
|
.slider {
|
||||||
width: 120px;
|
height: 120px;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
}
|
}
|
||||||
@ -155,7 +114,7 @@
|
|||||||
}
|
}
|
||||||
.backSize {
|
.backSize {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
right: 30px;
|
right: 18px;
|
||||||
bottom: 95px;
|
bottom: 95px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user