Skip to content

Commit

Permalink
fix: umi ui mini open project failed
Browse files Browse the repository at this point in the history
  • Loading branch information
sorrycc committed Sep 17, 2019
1 parent e288b27 commit 839dad7
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/umi-ui/client/src/PluginAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default class PluginAPI {
this.send = send;
this._ = lodash;
this.debug = _debug.extend('UIPlugin');
window.g_currentProject = this.currentProject =
this.currentProject =
{
...currentProject
} || {};
Expand Down
20 changes: 13 additions & 7 deletions packages/umi-ui/client/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,19 @@ export async function render(oldRender) {
document.getElementById('root'),
);

// mini 模式下允许通过加 key 的参数打开
// 比如: ?mini&key=xxx
let miniKey = null;
const qs = querystring.parse(location.search.slice(1));
const isMini = 'mini' in qs;
if (isMini && qs.key) {
miniKey = qs.key;
}

// 不同路由在渲染前的初始化逻辑
if (history.location.pathname === '/') {
const { data } = await callRemote({ type: '@@project/list' });
if (data.currentProject) {
if (miniKey || data.currentProject) {
history.replace('/dashboard');
} else {
history.replace('/project/select');
Expand All @@ -82,13 +91,10 @@ export async function render(oldRender) {
const props = {
data,
};
let key = data.currentProject;
const qs = querystring.parse(location.search.slice(1));
const isMini = 'mini' in qs;
if (isMini && qs.key) {
key = qs.key;
}
let key = miniKey || data.currentProject;
if (key) {
// 在 callRemote 里使用
window.g_currentProject = key;
const currentProject = {
key,
...get(data, `projectsByKey.${key}`, {}),
Expand Down
2 changes: 1 addition & 1 deletion packages/umi-ui/client/src/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export function callRemote<T = object, K = object>(
JSON.stringify({
...action,
$lang: getLocale(),
$key: window.g_currentProject ? window.g_currentProject.key : '',
$key: window.g_currentProject,
}),
);
});
Expand Down
14 changes: 9 additions & 5 deletions packages/umi-ui/src/UmiUI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ export default class UmiUI {
launchEditor(configFile);
}

getExtraAssets() {
const service = this.servicesByKey[this.config.data.currentProject];
getExtraAssets({ key }) {
const service = this.servicesByKey[key];
const uiPlugins = service.applyPlugins('addUIPlugin', {
initialValue: [],
});
Expand Down Expand Up @@ -525,10 +525,14 @@ export default class UmiUI {

reloadProject(key: string) {}

handleCoreData({ type, payload, lang }, { log, send, success, failure, progress }) {
handleCoreData({ type, payload, lang, key }, { log, send, success, failure, progress }) {
switch (type) {
case '@@project/getExtraAssets':
success(this.getExtraAssets());
success(
this.getExtraAssets({
key,
}),
);
break;
case '@@project/list':
success({
Expand Down Expand Up @@ -871,7 +875,7 @@ export default class UmiUI {
console.log(chalk.blue.bold('<<<<'), formatLogMessage(message));
if (type.startsWith('@@')) {
this.handleCoreData(
{ type, payload, lang },
{ type, payload, lang, key },
{
log,
send,
Expand Down
1 change: 1 addition & 0 deletions scripts/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ function buildUIApp(opts = {}) {
env: {
APP_ROOT: './packages/umi-ui/client',
UMI_UI: 'none',
UMI_UI_SERVER: 'none',
},
});
process.on('SIGINT', () => {
Expand Down

0 comments on commit 839dad7

Please sign in to comment.