Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Nocobase
Commits
31ddfbee
Commit
31ddfbee
authored
3 years ago
by
chenos
Browse files
Options
Download
Email Patches
Plain Diff
feat: add status field to multi-apps
parent
55f6564e
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/simple/src/index.ts
+1
-1
examples/simple/src/index.ts
packages/plugin-multi-apps/src/server.ts
+45
-11
packages/plugin-multi-apps/src/server.ts
with
46 additions
and
12 deletions
+46
-12
examples/simple/src/index.ts
+
1
-
1
View file @
31ddfbee
...
...
@@ -43,7 +43,7 @@ app.parse(process.argv);
/*
根据配置生成相关数据表
yarn examples simple db
sync
yarn examples simple db
:
sync
启动服务
yarn examples simple start
...
...
This diff is collapsed.
Click to expand it.
packages/plugin-multi-apps/src/server.ts
+
45
-
11
View file @
31ddfbee
import
compose
from
'
koa-compose
'
;
import
{
Application
,
PluginOptions
}
from
'
@nocobase/server
'
;
import
Koa
from
'
koa
'
;
import
{
Model
}
from
'
@nocobase/database
'
;
function
createApp
(
opts
)
{
const
{
name
}
=
opts
;
...
...
@@ -35,14 +35,15 @@ function createApp(opts) {
bodyParser
:
false
,
// dataWrapping: false,
resourcer
:
{
prefix
:
`/api/
saa
s/
${
name
}
`
,
prefix
:
`/api/
multiapp
s/
${
name
}
`
,
},
};
const
app
=
new
Application
(
options
);
app
.
db
.
sequelize
.
beforeDefine
((
model
,
options
)
=>
{
options
.
tableName
=
`saas_
${
name
}
_
${
options
.
tableName
||
options
.
name
.
plural
}
`
;
options
.
tableName
=
`multiapps_
${
name
}
_
${
options
.
tableName
||
options
.
name
.
plural
}
`
;
});
app
.
resource
({
...
...
@@ -50,7 +51,9 @@ function createApp(opts) {
actions
:
{
async
getInfo
(
ctx
,
next
)
{
ctx
.
body
=
{
m
:
Object
.
values
(
ctx
.
db
.
sequelize
.
models
).
map
((
m
:
any
)
=>
m
.
tableName
),
m
:
Object
.
values
(
ctx
.
db
.
sequelize
.
models
).
map
(
(
m
:
any
)
=>
m
.
tableName
,
),
};
await
next
();
},
...
...
@@ -102,7 +105,7 @@ function multiApps({ getAppName }) {
apps
.
set
(
appName
,
app
);
}
console
.
log
(
'
..........................start........................
'
)
console
.
log
(
'
..........................start........................
'
)
;
// 完全隔离的做法
const
app
=
apps
.
get
(
appName
)
as
Application
;
const
bodyParser
=
async
(
ctx2
,
next
)
=>
{
...
...
@@ -115,7 +118,7 @@ function multiApps({ getAppName }) {
await
handleRequest
(
ctx
.
req
,
ctx
.
res
);
const
index
=
app
.
middleware
.
indexOf
(
bodyParser
);
app
.
middleware
.
splice
(
index
,
1
);
console
.
log
(
'
..........................end........................
'
)
console
.
log
(
'
..........................end........................
'
)
;
// await next();
};
}
...
...
@@ -129,16 +132,44 @@ export default {
title
:
'
应用
'
,
fields
:
[
{
type
:
'
string
'
,
type
:
'
uid
'
,
name
:
'
name
'
,
prefix
:
'
a
'
,
interface
:
'
string
'
,
unique
:
true
,
uiSchema
:
{
type
:
'
string
'
,
title
:
'
应用标识
'
,
'
x-component
'
:
'
Input
'
,
},
},
{
type
:
'
string
'
,
name
:
'
title
'
,
interface
:
'
string
'
,
unique
:
true
,
uiSchema
:
{
type
:
'
string
'
,
title
:
'
名称
'
,
title
:
'
应用
名称
'
,
'
x-component
'
:
'
Input
'
,
},
},
{
type
:
'
string
'
,
name
:
'
status
'
,
interface
:
'
select
'
,
uiSchema
:
{
type
:
'
string
'
,
title
:
'
状态
'
,
'
x-component
'
:
'
Select
'
,
default
:
'
initializing
'
,
enum
:
[
{
value
:
'
initializing
'
,
label
:
'
正在初始化
'
},
{
value
:
'
running
'
,
label
:
'
运行中
'
},
{
value
:
'
stopped
'
,
label
:
'
已停止
'
},
],
},
},
],
});
this
.
app
.
use
(
...
...
@@ -148,7 +179,7 @@ export default {
},
}),
);
this
.
app
.
db
.
on
(
'
applications.afterCreate
'
,
async
(
model
)
=>
{
this
.
app
.
db
.
on
(
'
applications.afterCreate
'
,
async
(
model
:
Model
)
=>
{
const
name
=
model
.
get
(
'
name
'
);
const
app
=
createApp
({
name
,
...
...
@@ -163,7 +194,10 @@ export default {
});
await
app
.
emitAsync
(
'
db.init
'
);
await
app
.
destroy
();
})()
this
.
app
[
'
apps
'
].
set
(
name
,
app
);
model
.
set
(
'
status
'
,
'
running
'
);
await
model
.
save
({
hooks
:
false
});
})();
});
this
.
app
.
command
(
'
app:create
'
)
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help