-
page(页面) 和 item(table行元素)
+ // ① 初始化page类型
+ if (initContent.page) {
+ Object.keys(initContent.page).forEach(key => {
+ const { path: url, method } = initContent.page[key]
+ // 对话框
+ tempState = dialog(tempState, url, method, key, prefix, baseAction)
+ // 按钮
+ const { title, buttonType, newKey } = getBaseAttributes(key)
+ const cardButton = {
+ label: title,
+ action: [
+ {
+ name: key !== 'export' ? 'flows/tablePage/open' + newKey + 'Dialog' : 'flows/tablePage/export',
+ params: key !== 'export' ? {} : {
+ url: url,
+ method: method,
+ }
+ }
+ ],
+ type: buttonType,
+ }
+ tempState.card?.buttons?.push(cardButton)
+ })
+ }
+
+ // ② 初始化item类型
+ if (initContent.item) {
+ Object.keys(initContent.item).forEach(key => {
+ const action = initContent.item[key]
+ let url = action.path || action.write.path
+ let method = action.method || action.write.method
+ // 对话框
+ tempState = dialog(tempState, url, method, key, prefix, baseAction)
+ // 按钮
+ if (action.read) {
+ url = action.read.path
+ method = action.read.method
+ }
+ const { title, buttonType, newKey } = getBaseAttributes(key)
+ const buttonState = {
+ label: title,
+ type: buttonType,
+ action: [
+ {
+ name: action.method === 'delete' ? 'flows/tablePage/delete' : 'flows/tablePage/open' + newKey + 'Dialog',
+ params: {
+ url,
+ method,
+ ...this.inputs.baseAction
+ }
+ }
+ ]
+ }
+ const len = tempState.table?.columns?.length as number
+ if (tempState.table!.columns![len-1].prop !== 'actions') {
+ const columnUpdate = {
+ prop: 'actions',
+ label: '操作',
+ scope: {
+ type: 'ButtonArray',
+ state: []
+ }
+ }
+ tempState.table?.columns?.push(columnUpdate)
+ tempState.table?.columns![len]?.scope?.state?.push(buttonState)
+ }
+ tempState.table?.columns![len - 1]?.scope?.state?.push(buttonState)
+ })
+ }
+
+ return {
+ data: this.inputs.data,
+ state: tempState,
+ baseAction: this.inputs.baseAction
+ }
+ }
+}
diff --git a/src/flows/tablePage/init/nodes/initCreate.ts b/src/flows/tablePage/init/nodes/initCreate.ts
deleted file mode 100644
index e8639558..00000000
--- a/src/flows/tablePage/init/nodes/initCreate.ts
+++ /dev/null
@@ -1,72 +0,0 @@
-import { FunctionNode } from 'arkfbp/lib/functionNode'
-import OpenAPI from '@/config/openapi'
-import DialogState from '@/admin/common/Others/Dialog/DialogState'
-import generateDialogForm from '@/utils/generate-dialog-form'
-import getSchemaByContent from '@/utils/get-schema-by-content'
-import whetherImportListDialog from '@/utils/list-dialog'
-import TablePageState from '@/admin/TablePage/TablePageState'
-
-export class InitCreate extends FunctionNode {
- async run() {
- const tempState = this.inputs.state as TablePageState
- const initContent = this.inputs.data.initContent
- if (initContent.create) {
- const listOperationPath = initContent.list.path
- const listOperationMethod = initContent.list.method
- const createOperationPath = initContent.create.path
- const createOperationMethod = initContent.create.method
- const createOperation = OpenAPI.instance.getOperation(createOperationPath, createOperationMethod)
- if (createOperation) {
- const content = createOperation.requestBody.content
- const schema = getSchemaByContent(content)
- const createDialogState:DialogState = {}
- createDialogState.title = createOperation.summary || '创建'
- createDialogState.visible = false
- createDialogState.data = {}
- createDialogState.actions = [
- {
- label: createOperation.summary || '创建',
- action: [
- {
- name: 'flows/tablePage/create',
- params: {
- createUrl: createOperationPath,
- createMethod: createOperationMethod,
- fetchUrl: listOperationPath,
- fetchMethod: listOperationMethod
- }
- }
- ],
- type: 'primary'
- }
- ]
- // const tempItems: Array = generateDialogForm(schema, false)
- createDialogState.type = 'FormPage'
- createDialogState.state = generateDialogForm(schema, false)
-
- // 在这里进行是否有 InputList 第二层弹出框的判断,如果有,进行初始化 selected 弹出框, 没有则跳过此步骤
- const importListDialog = whetherImportListDialog(createDialogState.state)
- if (importListDialog && !tempState.dialogs!.selected) {
- tempState.dialogs!.selected = importListDialog
- }
-
- tempState.dialogs!.create = createDialogState
- const createButton = {
- label: createOperation.summary || '创建',
- action: [
- {
- name: 'flows/tablePage/openCreateDialog'
- }
- ],
- type: 'primary'
- }
- tempState.card?.buttons?.push(createButton)
- }
- }
-
- return {
- data: this.inputs.data,
- state: tempState
- }
- }
-}
diff --git a/src/flows/tablePage/init/nodes/initDelete.ts b/src/flows/tablePage/init/nodes/initDelete.ts
deleted file mode 100644
index 3a123246..00000000
--- a/src/flows/tablePage/init/nodes/initDelete.ts
+++ /dev/null
@@ -1,39 +0,0 @@
-import { FunctionNode } from 'arkfbp/lib/functionNode'
-import OpenAPI from '@/config/openapi'
-
-export class InitDelete extends FunctionNode {
- async run() {
- const tempState = this.inputs.state
- const initContent = this.inputs.data.initContent
- if (initContent.delete) {
- const listOperationPath = initContent.list.path
- const listOperationMethod = initContent.list.method
- const deleteOperationPath = initContent.delete.path
- const deleteOperationMethod = initContent.delete.method
- const deleteOperation = OpenAPI.instance.getOperation(deleteOperationPath, deleteOperationMethod)
- if (deleteOperation) {
- // button
- const deleteAction = {
- label: deleteOperation.summary || '删除',
- type: 'danger',
- action: [
- {
- name: 'flows/tablePage/delete',
- params: {
- deleteUrl: deleteOperationPath,
- deleteMethod: deleteOperationMethod,
- fetchUrl: listOperationPath,
- fetchMethod: listOperationMethod
- }
- }
- ]
- }
- tempState.table?.columns[tempState.table.columns.length - 1]?.scope?.state?.push(deleteAction)
- }
- }
- return {
- data: this.inputs.data,
- state: tempState
- }
- }
-}
diff --git a/src/flows/tablePage/init/nodes/initList.ts b/src/flows/tablePage/init/nodes/initList.ts
deleted file mode 100644
index d16c3a7a..00000000
--- a/src/flows/tablePage/init/nodes/initList.ts
+++ /dev/null
@@ -1,68 +0,0 @@
-import { FunctionNode } from 'arkfbp/lib/functionNode'
-import OpenAPI, { ISchema } from '@/config/openapi'
-import TableColumnState from '@/admin/common/data/Table/TableColumn/TableColumnState'
-import getSchemaByContent from '@/utils/get-schema-by-content'
-
-export class InitList extends FunctionNode {
- async run() {
- const tempState = this.inputs.state
- const initContent = this.inputs.data.initContent
- if (initContent.list) {
- const listOperationPath = initContent.list.path
- const listOperationMethod = initContent.list.method
- const listOperation = OpenAPI.instance.getOperation(listOperationPath, listOperationMethod)
- if (listOperation) {
- // 给 created 赋值
- tempState.created.push({
- name: 'flows/tablePage/fetch',
- params: {
- fetchUrl: listOperationPath,
- fetchMethod: listOperationMethod
- }
- })
- // 给 destroyed 赋值
- tempState.destroyed.push({
- name: 'flows/hookFlow/destroyed',
- params: {
- fetchUrl: listOperationPath,
- fetchMethod: listOperationMethod
- }
- })
- // 给 title 赋值
- tempState.card.title = listOperation.summary || ''
- // 对 table 进行初始化操作
- const content = listOperation.responses[200].content
- const schema = getSchemaByContent(content)
- for (const prop in schema.properties) {
- const iprop = schema.properties[prop]
- if (iprop.writeOnly) continue
- if (initContent.hiddenReadOnly && iprop.readOnly) continue
- const columnState:TableColumnState = {}
- columnState.label = iprop.title
- columnState.prop = prop
- columnState.type = iprop.type
- tempState.table?.columns?.push(columnState)
- }
- // 对 pagination 分页进行初始化操作
- tempState.pagination = {
- currentPage: 1,
- pageSize: 10,
- total: 0,
- action: [
- {
- name: 'flows/tablePage/fetch',
- params: {
- fetchUrl: listOperationPath,
- fetchMethod: listOperationMethod
- }
- }
- ]
- }
- }
- }
- return {
- data: this.inputs.data,
- state: tempState
- }
- }
-}
diff --git a/src/flows/tablePage/init/nodes/initTablePage.ts b/src/flows/tablePage/init/nodes/initPage.ts
similarity index 70%
rename from src/flows/tablePage/init/nodes/initTablePage.ts
rename to src/flows/tablePage/init/nodes/initPage.ts
index 59a94300..2871c434 100644
--- a/src/flows/tablePage/init/nodes/initTablePage.ts
+++ b/src/flows/tablePage/init/nodes/initPage.ts
@@ -1,17 +1,18 @@
import { FunctionNode } from 'arkfbp/lib/functionNode'
import TablePageState from '@/admin/TablePage/TablePageState'
-export class InitTablePage extends FunctionNode {
+export class InitPage extends FunctionNode {
async run() {
+ const isHooks = this.inputs.isHooks
const tempState: TablePageState = {
type: 'TablePage',
pages: [],
- created: [
+ created: isHooks === false ? [] : [
{
'name': 'flows/hookFlow/created'
}
],
- beforeDestroy: [
+ beforeDestroy: isHooks === false ? [] : [
{
'name': 'flows/hookFlow/beforeDestroy'
}
@@ -21,13 +22,11 @@ export class InitTablePage extends FunctionNode {
title: '',
buttons: []
},
- dialogs: {
- create: {},
- update: {}
- },
+ dialogs: {},
table: {
columns: [],
- data: []
+ data: [],
+ selection: {}
}
}
return {
diff --git a/src/flows/tablePage/init/nodes/initSortable.ts b/src/flows/tablePage/init/nodes/initSortable.ts
index dc76a772..6009eafd 100644
--- a/src/flows/tablePage/init/nodes/initSortable.ts
+++ b/src/flows/tablePage/init/nodes/initSortable.ts
@@ -5,22 +5,20 @@ export class InitSortable extends FunctionNode {
async run() {
const tempState = this.inputs.state as TablePageState
const initContent = this.inputs.data.initContent
+ const baseAction = this.inputs.baseAction
if (initContent.sort) {
const sortOperationPath = initContent.sort.batch.path
const sortOperationMethod = initContent.sort.batch.method
- const listOperationPath = initContent.list.path
- const listOperationMethod = initContent.list.method
if (tempState.table) {
tempState.table.sortable = true
tempState.table.sortAction = [
{
name: 'flows/tablePage/sort',
params: {
- sortUrl: sortOperationPath,
- sortMethod: sortOperationMethod,
- fetchUrl: listOperationPath,
- fetchMethod: listOperationMethod,
- sortType: 'batch'
+ url: sortOperationPath,
+ method: sortOperationMethod,
+ sortType: 'batch',
+ ...baseAction
}
}
]
@@ -43,11 +41,10 @@ export class InitSortable extends FunctionNode {
{
name: 'flows/tablePage/sort',
params: {
- sortUrl: initContent.sort[sortName].path,
- sortMethod: initContent.sort[sortName].method,
- fetchUrl: listOperationPath,
- fetchMethod: listOperationMethod,
+ url: initContent.sort[sortName].path,
+ method: initContent.sort[sortName].method,
sortType: sortName,
+ ...baseAction
}
}
]
@@ -60,7 +57,8 @@ export class InitSortable extends FunctionNode {
return {
data: this.inputs.data,
- state: tempState
+ state: tempState,
+ baseAction: this.inputs.baseAction
}
}
}
diff --git a/src/flows/tablePage/init/nodes/initTable.ts b/src/flows/tablePage/init/nodes/initTable.ts
new file mode 100644
index 00000000..cd65278b
--- /dev/null
+++ b/src/flows/tablePage/init/nodes/initTable.ts
@@ -0,0 +1,64 @@
+import { FunctionNode } from 'arkfbp/lib/functionNode'
+import OpenAPI from '@/config/openapi'
+import TableColumnState from '@/admin/common/data/Table/TableColumn/TableColumnState'
+import getSchemaByContent from '@/utils/get-schema-by-content'
+
+export class InitTable extends FunctionNode {
+ async run() {
+ const tempState = this.inputs.state
+ const { initContent, ...otherInitContent } = this.inputs.data
+ let baseAction = {
+ fetchUrl: '',
+ fetchMethod: ''
+ }
+ if (initContent?.init?.path) {
+ const initTablePath = initContent.init.path as string
+ const initTableMethod = initContent.init.method as string || 'GET'
+ const initTableOperation = OpenAPI.instance.getOperation(initTablePath, initTableMethod)
+ baseAction.fetchUrl = initTablePath
+ baseAction.fetchMethod = initTableMethod
+ if (initTableOperation) {
+ // 给页面hook添加内容
+ if (otherInitContent.isHooks !== false) {
+ tempState.created.push({
+ name: 'flows/tablePage/fetch',
+ params: baseAction
+ })
+ tempState.destroyed.push({
+ name: 'flows/hookFlow/destroyed',
+ params: baseAction
+ })
+ }
+
+ // 给页面元素添加state
+ tempState.card.title = initTableOperation.summary || ''
+ const content = initTableOperation.responses[200].content
+ const schema = getSchemaByContent(content)
+ for (const prop in schema.properties) {
+ const iprop = schema.properties[prop]
+ if (otherInitContent.hiddenReadOnly && iprop.readOnly) continue
+ const columnState: TableColumnState = {
+ label: iprop.title,
+ prop: prop
+ }
+ tempState.table?.columns?.push(columnState)
+ }
+ tempState.pagination = {
+ currentPage: 1,
+ pageSize: 10,
+ total: 0,
+ action: [{
+ name: 'flows/tablePage/fetch',
+ params: baseAction
+ }]
+ }
+ }
+ }
+
+ return {
+ data: this.inputs.data,
+ state: tempState,
+ baseAction: baseAction
+ }
+ }
+}
diff --git a/src/flows/tablePage/init/nodes/initUpdate.ts b/src/flows/tablePage/init/nodes/initUpdate.ts
deleted file mode 100644
index da683e38..00000000
--- a/src/flows/tablePage/init/nodes/initUpdate.ts
+++ /dev/null
@@ -1,85 +0,0 @@
-import { FunctionNode } from 'arkfbp/lib/functionNode'
-import OpenAPI from '@/config/openapi'
-import DialogState from '@/admin/common/Others/Dialog/DialogState'
-import generateDialogForm from '@/utils/generate-dialog-form'
-import getSchemaByContent from '@/utils/get-schema-by-content'
-import TablePageState from '@/admin/TablePage/TablePageState'
-import whetherImportListDialog from '@/utils/list-dialog'
-
-export class InitUpdate extends FunctionNode {
- async run() {
- const tempState = this.inputs.state as TablePageState
- const initContent = this.inputs.data.initContent
- if (initContent.update) {
- const listOperationPath = initContent.list.path
- const listOperationMethod = initContent.list.method
- const updateOperationPath = initContent.update.path
- const updateOperationMethod = initContent.update.method
- const updateOperation = OpenAPI.instance.getOperation(updateOperationPath, updateOperationMethod)
- if (updateOperation) {
- // button
- const columnUpdate = {
- prop: 'action',
- label: '操作',
- scope: {
- type: 'ButtonArray',
- state: [
- {
- label: updateOperation.summary || '编辑',
- type: 'primary',
- action: [
- {
- name: 'flows/tablePage/openUpdateDialog',
- params: {
- updateUrl: updateOperationPath,
- updateMethod: 'get'
- }
- }
- ]
- }
- ]
- }
- }
- tempState.table?.columns?.push(columnUpdate)
- // dialog
- const content = updateOperation.requestBody.content
- const schema = getSchemaByContent(content)
- const updateDialogState:DialogState = {}
- updateDialogState.title = updateOperation.summary || '编辑'
- updateDialogState.visible = false
- updateDialogState.data = {}
- updateDialogState.actions = [
- {
- label: updateOperation.summary || '确定',
- action: [
- {
- name: 'flows/tablePage/update',
- params: {
- updateUrl: updateOperationPath,
- updateMethod: updateOperationMethod,
- fetchUrl: listOperationPath,
- fetchMethod: listOperationMethod
- }
- }
- ],
- type: 'primary'
- }
- ]
- updateDialogState.type = 'FormPage'
- updateDialogState.state = generateDialogForm(schema)
- tempState.dialogs!.update = updateDialogState
-
- // 在这里进行是否有 InputList 第二层弹出框的判断,如果有,进行初始化 selected 弹出框, 没有则跳过此步骤
- const importListDialog = whetherImportListDialog(updateDialogState.state)
- if (importListDialog && !tempState.dialogs!.selected) {
- tempState.dialogs!.selected = importListDialog
- }
-
- }
- }
- return {
- data: this.inputs.data,
- state: tempState
- }
- }
-}
diff --git a/src/flows/tablePage/openImportDialog/index.ts b/src/flows/tablePage/openImportDialog/index.ts
new file mode 100644
index 00000000..6a5f1815
--- /dev/null
+++ b/src/flows/tablePage/openImportDialog/index.ts
@@ -0,0 +1,29 @@
+import { Flow } from 'arkfbp/lib/flow'
+import { Graph } from 'arkfbp/lib/graph'
+import { StartNode } from 'arkfbp/lib/startNode'
+import { StopNode } from 'arkfbp/lib/stopNode'
+import { Open } from './nodes/open'
+export class Main extends Flow {
+ createNodes() {
+ return [{
+ cls: StartNode,
+ id: 'start',
+ next: 'openCreateDialog'
+ }, {
+ cls: Open,
+ id: 'openCreateDialog',
+ next: 'stop'
+ }, {
+ cls: StopNode,
+ id: 'stop',
+ x: 455,
+ y: 70
+ }]
+ }
+
+ createGraph() {
+ const g = new Graph()
+ g.nodes = this.createNodes()
+ return g
+ }
+}
diff --git a/src/flows/tablePage/openImportDialog/nodes/open.ts b/src/flows/tablePage/openImportDialog/nodes/open.ts
new file mode 100644
index 00000000..4cc97fc9
--- /dev/null
+++ b/src/flows/tablePage/openImportDialog/nodes/open.ts
@@ -0,0 +1,14 @@
+import DialogState from '@/admin/common/Others/Dialog/DialogState'
+import TreePageState from '@/admin/TreePage/TreePageState'
+import OpenDialog from '@/nodes/openDialog'
+
+export class Open extends OpenDialog {
+ get dialog():DialogState | null {
+ const tempState: TreePageState = this.getState()
+ if (tempState?.table?.dialogs) {
+ return tempState.table.dialogs.import
+ } else {
+ return null
+ }
+ }
+}
diff --git a/src/flows/tablePage/sort/nodes/sort.ts b/src/flows/tablePage/sort/nodes/sort.ts
index f520b5a6..e6d08974 100644
--- a/src/flows/tablePage/sort/nodes/sort.ts
+++ b/src/flows/tablePage/sort/nodes/sort.ts
@@ -17,8 +17,8 @@ export class Sort extends AuthApiNode {
})
}
- this.url = getUrl(this.inputs.params.sortUrl, targetData)
- this.method = this.inputs.params.sortMethod || 'post'
+ this.url = getUrl(this.inputs.params.url, targetData)
+ this.method = this.inputs.params.method || 'post'
if (!this.url) {
throw Error('tablePage sort flow is not url')
}
diff --git a/src/flows/tablePage/update/nodes/update.ts b/src/flows/tablePage/update/nodes/update.ts
index aaee7f88..d473c63e 100644
--- a/src/flows/tablePage/update/nodes/update.ts
+++ b/src/flows/tablePage/update/nodes/update.ts
@@ -10,8 +10,8 @@ export class Update extends AuthApiNode {
const tempState: TablePageState = this.getState()
const data = tempState.dialogs?.update.data
- this.url = getUrl(this.inputs.params.updateUrl, data)
- this.method = this.inputs.params.updateMethod || 'put'
+ this.url = getUrl(this.inputs.params.url, data)
+ this.method = this.inputs.params.method || 'put'
if (!this.url) {
throw Error('tablePage update flow is not url')
}
diff --git a/src/flows/tenant/addSwitchTenant/nodes/addSwitchTenantButton.ts b/src/flows/tenant/addSwitchTenant/nodes/addSwitchTenantButton.ts
index 1599e39f..b64eab23 100644
--- a/src/flows/tenant/addSwitchTenant/nodes/addSwitchTenantButton.ts
+++ b/src/flows/tenant/addSwitchTenant/nodes/addSwitchTenantButton.ts
@@ -12,8 +12,8 @@ export class AddSwitchTenantButton extends StateNode {
{
name: 'flows/tenant/openSwitchTenantDialog',
params: {
- updateUrl: '/api/v1/tenant/{id}/',
- updateMethod: 'get'
+ url: '/api/v1/tenant/{id}/',
+ method: 'get'
}
}
]
diff --git a/src/flows/treePage/addTreeNode/index.ts b/src/flows/treePage/create/index.ts
similarity index 100%
rename from src/flows/treePage/addTreeNode/index.ts
rename to src/flows/treePage/create/index.ts
diff --git a/src/flows/treePage/addTreeNode/nodes/addTreeNode.ts b/src/flows/treePage/create/nodes/addTreeNode.ts
similarity index 89%
rename from src/flows/treePage/addTreeNode/nodes/addTreeNode.ts
rename to src/flows/treePage/create/nodes/addTreeNode.ts
index b518e9b0..301b0ecf 100644
--- a/src/flows/treePage/addTreeNode/nodes/addTreeNode.ts
+++ b/src/flows/treePage/create/nodes/addTreeNode.ts
@@ -9,8 +9,8 @@ export class AddTreeNode extends AuthApiNode {
async run() {
const tempState: TreePageState = this.getState()
- this.url = getUrl(this.inputs.params.createUrl)
- this.method = this.inputs.params.createMethod || 'post'
+ this.url = getUrl(this.inputs.params.url)
+ this.method = this.inputs.params.method || 'post'
if (!this.url) {
throw Error('treePage addTreeNode flow is not url')
}
diff --git a/src/flows/treePage/deleteTreeNode/index.ts b/src/flows/treePage/delete/index.ts
similarity index 100%
rename from src/flows/treePage/deleteTreeNode/index.ts
rename to src/flows/treePage/delete/index.ts
diff --git a/src/flows/treePage/deleteTreeNode/nodes/deleteTreeNode.ts b/src/flows/treePage/delete/nodes/deleteTreeNode.ts
similarity index 79%
rename from src/flows/treePage/deleteTreeNode/nodes/deleteTreeNode.ts
rename to src/flows/treePage/delete/nodes/deleteTreeNode.ts
index 69b68cc6..268f1704 100644
--- a/src/flows/treePage/deleteTreeNode/nodes/deleteTreeNode.ts
+++ b/src/flows/treePage/delete/nodes/deleteTreeNode.ts
@@ -6,8 +6,8 @@ export class DeleteTreeNode extends AuthApiNode {
async run() {
const data = this.inputs.com.state.data
- this.url = getUrl(this.inputs.params.deleteUrl, data)
- this.method = this.inputs.params.deleteMethod || 'delete'
+ this.url = getUrl(this.inputs.params.url, data)
+ this.method = this.inputs.params.method || 'delete'
if (!this.url) {
throw Error('treePage delete flow is not url')
}
diff --git a/src/flows/treePage/dragTreeNode/index.ts b/src/flows/treePage/drag/index.ts
similarity index 100%
rename from src/flows/treePage/dragTreeNode/index.ts
rename to src/flows/treePage/drag/index.ts
diff --git a/src/flows/treePage/dragTreeNode/nodes/dragTreeNode.ts b/src/flows/treePage/drag/nodes/dragTreeNode.ts
similarity index 100%
rename from src/flows/treePage/dragTreeNode/nodes/dragTreeNode.ts
rename to src/flows/treePage/drag/nodes/dragTreeNode.ts
diff --git a/src/flows/treePage/fetchTableList/nodes/fetch.ts b/src/flows/treePage/fetchTableList/nodes/fetch.ts
index 9d520529..69f96422 100644
--- a/src/flows/treePage/fetchTableList/nodes/fetch.ts
+++ b/src/flows/treePage/fetchTableList/nodes/fetch.ts
@@ -5,8 +5,8 @@ export class Fetch extends AuthApiNode {
async run() {
const tempState = this.getState()
- this.url = getUrl(this.inputs.params.tableUrl, this.inputs.params.data)
- this.method = this.inputs.params.tableMethod || 'get'
+ this.url = getUrl(this.inputs.params.fetchUrl, this.inputs.params.data)
+ this.method = this.inputs.params.fetchMethod || 'get'
this.$state.commit((state: any) => {
state.client = tempState
diff --git a/src/flows/treePage/fetchTreeNodeChildren/nodes/fetchTreeNodeChildren.ts b/src/flows/treePage/fetchTreeNodeChildren/nodes/fetchTreeNodeChildren.ts
index 44d20a92..1f2573b9 100644
--- a/src/flows/treePage/fetchTreeNodeChildren/nodes/fetchTreeNodeChildren.ts
+++ b/src/flows/treePage/fetchTreeNodeChildren/nodes/fetchTreeNodeChildren.ts
@@ -10,8 +10,8 @@ export class FetchTreeNodeChildren extends AuthApiNode {
const tempState: TreePageState = this.getState()
const data = this.inputs.params.data as TreeNodeProps
- this.url = getUrl(this.inputs.params.fetchUrl, data)
- this.method = this.inputs.params.fetchMethod || 'get'
+ this.url = getUrl(this.inputs.params.url, data)
+ this.method = this.inputs.params.method || 'get'
this.$state.commit((state: any) => {
state.client = tempState
})
diff --git a/src/flows/treePage/init/index.ts b/src/flows/treePage/init/index.ts
index 3ce03f7b..36c4829a 100644
--- a/src/flows/treePage/init/index.ts
+++ b/src/flows/treePage/init/index.ts
@@ -2,12 +2,10 @@ import { Flow } from 'arkfbp/lib/flow'
import { Graph } from 'arkfbp/lib/graph'
import { StartNode } from 'arkfbp/lib/startNode'
import { StopNode } from 'arkfbp/lib/stopNode'
-import { InitTreePage } from './nodes/initTreePage'
+import { InitPage } from './nodes/initPage'
+import { InitTable } from './nodes/initTable'
import { InitTree } from './nodes/initTree'
-import { InitAddTreeNode } from './nodes/initAddTreeNode'
-import { InitTreeNodeSlot } from './nodes/initTreeNodeSlot'
-import { InitTablePage } from './nodes/initTablePage'
-import { InitTableList } from './nodes/initTableList'
+import { InitAction } from './nodes/initAction'
export class Main extends Flow {
createNodes() {
@@ -15,30 +13,22 @@ export class Main extends Flow {
{
cls: StartNode,
id: 'start',
- next: '1'
+ next: 'initPage'
}, {
- cls: InitTreePage,
- id: '1',
- next: '2'
+ cls: InitPage,
+ id: 'initPage',
+ next: 'initTable'
}, {
- cls: InitTree,
- id: '2',
- next: '3'
- }, {
- cls: InitAddTreeNode,
- id: '3',
- next: '4'
+ cls: InitTable,
+ id: 'initTable',
+ next: 'initTree'
}, {
- cls: InitTreeNodeSlot,
- id: '4',
- next: '5'
- }, {
- cls: InitTablePage,
- id: '5',
- next: '6',
+ cls: InitTree,
+ id: 'initTree',
+ next: 'initAction'
}, {
- cls: InitTableList,
- id: '6',
+ cls: InitAction,
+ id: 'initAction',
next: 'stop'
}, {
cls: StopNode,
diff --git a/src/flows/treePage/init/nodes/initAction.ts b/src/flows/treePage/init/nodes/initAction.ts
new file mode 100644
index 00000000..4235c2b6
--- /dev/null
+++ b/src/flows/treePage/init/nodes/initAction.ts
@@ -0,0 +1,79 @@
+import { FunctionNode } from 'arkfbp/lib/functionNode'
+import TreePageState from '@/admin/TreePage/TreePageState'
+import { getBaseAttributes, dialog } from '@/utils/initpage'
+
+export class InitAction extends FunctionNode {
+ async run() {
+ let tempState: TreePageState = this.inputs.state
+ const { initContent } = this.inputs.data
+ const baseAction = this.inputs.baseAction
+ const prefix = 'flows/treePage/'
+ const showReadOnly = false
+
+ // 对树进行操作
+ if (initContent.page) {
+ Object.keys(initContent.page).forEach(key => {
+ const { path: url, method } = initContent.page[key]
+ tempState = dialog(tempState, url, method, key, prefix, baseAction, showReadOnly)
+ const { title, buttonType, newKey } = getBaseAttributes(key)
+ const cardButton = {
+ label: title,
+ action: [
+ {
+ name: 'flows/treePage/open' + newKey + 'Dialog'
+ }
+ ],
+ type: buttonType,
+ }
+ tempState.tree?.header?.buttons?.push(cardButton)
+ })
+ }
+
+ // 对节点进行操作
+ if (initContent.item) {
+ // 先给item添加插槽内容
+ tempState.tree!.nodes!['slot'] = {
+ buttons: {
+ type: 'ButtonArray',
+ state: []
+ }
+ }
+ Object.keys(initContent.item).forEach(key => {
+ if (key !== 'children') {
+ const action = initContent.item[key]
+ let url = action.path || action.write.path
+ let method = action.method || action.write.method
+ // 对话框
+ tempState = dialog(tempState, url, method, key, prefix, baseAction, showReadOnly)
+ // 按钮
+ if (action.read) {
+ url = action.read.path
+ method = action.read.method
+ }
+ const { title, newKey } = getBaseAttributes(key)
+ const buttonState = {
+ label: title,
+ type: 'text',
+ action: [
+ {
+ name: action.method === 'delete' ? 'flows/treePage/delete' : 'flows/treePage/open' + newKey + 'Dialog',
+ params: {
+ url,
+ method,
+ ...this.inputs.baseAction
+ }
+ }
+ ]
+ }
+ tempState.tree?.nodes!['slot'].buttons.state.push(buttonState)
+ }
+ })
+ }
+
+ return {
+ data: this.inputs.data,
+ state: tempState,
+ baseAction: baseAction
+ }
+ }
+}
diff --git a/src/flows/treePage/init/nodes/initAddTreeNode.ts b/src/flows/treePage/init/nodes/initAddTreeNode.ts
deleted file mode 100644
index 7bdb0138..00000000
--- a/src/flows/treePage/init/nodes/initAddTreeNode.ts
+++ /dev/null
@@ -1,75 +0,0 @@
-import { FunctionNode } from 'arkfbp/lib/functionNode'
-import OpenAPI from '@/config/openapi'
-import DialogState from '@/admin/common/Others/Dialog/DialogState'
-import generateDialogForm from '@/utils/generate-dialog-form'
-import getSchemaByContent from '@/utils/get-schema-by-content'
-import whetherImportListDialog from '@/utils/list-dialog'
-
-export class InitAddTreeNode extends FunctionNode {
- async run() {
- const tempState = this.inputs.state
- const initContent = this.inputs.data.initContent
- // 设置添加节点的功能
- if (initContent.treeCreate) {
- const treeCreateNodeOperationPath = initContent.treeCreate.path
- const treeCreateNodeOperationMethod = initContent.treeCreate.method
- const treeListOperationPath = initContent.treeList.path
- const treeListOperationMethod = initContent.treeList.method
- const treeCreateNodeOperation = OpenAPI.instance.getOperation(treeCreateNodeOperationPath, treeCreateNodeOperationMethod)
- if (treeCreateNodeOperation) {
- // 添加相对应的弹出框内容
- const content = treeCreateNodeOperation.requestBody.content
- const schema = getSchemaByContent(content)
- const addTreeNodeDialogState:DialogState = {}
- addTreeNodeDialogState.title = treeCreateNodeOperation.summary || '新建节点'
- addTreeNodeDialogState.visible = false
- addTreeNodeDialogState.data = {}
- addTreeNodeDialogState.actions = [
- {
- label: treeCreateNodeOperation.summary || '新建节点',
- action: [
- {
- name: 'flows/treePage/addTreeNode',
- params: {
- createUrl: treeCreateNodeOperationPath,
- createMethod: treeCreateNodeOperationMethod,
- fetchUrl: treeListOperationPath,
- fetchMethod: treeListOperationMethod,
- }
- }
- ],
- type: 'primary'
- }
- ]
- addTreeNodeDialogState.type = 'FormPage'
- addTreeNodeDialogState.state = generateDialogForm(schema, false)
- tempState.dialogs['addTreeNode'] = addTreeNodeDialogState
-
- // 在这里进行是否有 InputList 第二层弹出框的判断,如果有,进行初始化 selected 弹出框, 没有则跳过此步骤
- const importListDialog = whetherImportListDialog(addTreeNodeDialogState.state)
- if (importListDialog && !tempState.dialogs.selected) {
- tempState.dialogs['selected'] = importListDialog
- }
-
- // 给tree结构顶层添加创建树节点按钮和事件流
- // 在该事件中,打算添加的节点可以添加到任意一个已存在节点的同级或者下级中去
- tempState.tree.header.buttons = [
- {
- label: treeCreateNodeOperation.summary || '添加',
- action: [
- {
- name: 'flows/treePage/openAddTreeNodeDialog'
- }
- ],
- type: 'primary',
- size: 'small'
- }
- ]
- }
- }
- return {
- data: this.inputs.data,
- state: tempState,
- }
- }
-}
diff --git a/src/flows/treePage/init/nodes/initTreePage.ts b/src/flows/treePage/init/nodes/initPage.ts
similarity index 94%
rename from src/flows/treePage/init/nodes/initTreePage.ts
rename to src/flows/treePage/init/nodes/initPage.ts
index ecfb69bf..04474673 100644
--- a/src/flows/treePage/init/nodes/initTreePage.ts
+++ b/src/flows/treePage/init/nodes/initPage.ts
@@ -1,7 +1,7 @@
import { FunctionNode } from 'arkfbp/lib/functionNode'
import TreePageState from '@/admin/TreePage/TreePageState'
-export class InitTreePage extends FunctionNode {
+export class InitPage extends FunctionNode {
async run() {
const tempState: TreePageState = {
type: 'TreePage',
diff --git a/src/flows/treePage/init/nodes/initTable.ts b/src/flows/treePage/init/nodes/initTable.ts
new file mode 100644
index 00000000..d8c4b02e
--- /dev/null
+++ b/src/flows/treePage/init/nodes/initTable.ts
@@ -0,0 +1,24 @@
+import { FunctionNode } from 'arkfbp/lib/functionNode'
+import TreePageState from '@/admin/TreePage/TreePageState'
+import { runFlowByFile } from '@/arkfbp/index'
+
+export class InitTable extends FunctionNode {
+ async run() {
+ const tempState: TreePageState = this.inputs.state
+ const { initContent } = this.inputs.data
+ if (initContent.table) {
+ initContent.table.init.path = initContent.table.init.path.split('?')[0]
+ await runFlowByFile('flows/tablePage/init', {
+ initContent: initContent.table,
+ isHooks: false
+ }).then(async (data) => {
+ const tableState = data.state
+ tempState.table = tableState
+ })
+ }
+ return {
+ data: this.inputs.data,
+ state: tempState
+ }
+ }
+}
diff --git a/src/flows/treePage/init/nodes/initTableList.ts b/src/flows/treePage/init/nodes/initTableList.ts
deleted file mode 100644
index cea4ec0e..00000000
--- a/src/flows/treePage/init/nodes/initTableList.ts
+++ /dev/null
@@ -1,39 +0,0 @@
-import { FunctionNode } from 'arkfbp/lib/functionNode'
-import OpenAPI from '@/config/openapi'
-import TableColumnState from '@/admin/common/data/Table/TableColumn/TableColumnState'
-import getSchemaByContent from '@/utils/get-schema-by-content'
-
-export class InitTableList extends FunctionNode {
- async run() {
- const tempState = this.inputs.state
- const initContent = this.inputs.data.initContent
-
- // 对table表格机进行初始化操作
- if (initContent.tableList) {
- const tableListNodeOperationPath = initContent.tableList.path.split('?')[0]
- const tableListNodeOperationMethod = initContent.tableList.method
- const tableListNodeOperation = OpenAPI.instance.getOperation(tableListNodeOperationPath, tableListNodeOperationMethod)
- if (tableListNodeOperation) {
- // 给treePage页面中的表格添加元素信息
- const content = tableListNodeOperation.responses[200].content
- const schema = getSchemaByContent(content)
- // 给 title 赋值
- tempState.table.card.title = tableListNodeOperation.summary || ''
- // 对 table 进行初始化操作
- for (const prop in schema.properties) {
- const iprop = schema.properties[prop]
- const columnState: TableColumnState = {}
- columnState.label = iprop.title
- columnState.prop = prop
- columnState.type = iprop.type
- tempState.table.table.columns.push(columnState)
- }
- }
- }
-
- return {
- data: this.inputs.data,
- state: tempState,
- }
- }
-}
diff --git a/src/flows/treePage/init/nodes/initTablePage.ts b/src/flows/treePage/init/nodes/initTablePage.ts
deleted file mode 100644
index 522149e5..00000000
--- a/src/flows/treePage/init/nodes/initTablePage.ts
+++ /dev/null
@@ -1,27 +0,0 @@
-import { FunctionNode } from 'arkfbp/lib/functionNode'
-
-export class InitTablePage extends FunctionNode {
- async run() {
- const tempState = this.inputs.state
- tempState.table = {
- type: 'TablePage',
- created: [],
- card: {
- title: '',
- buttons: []
- },
- dialogs: {
- create: {},
- update: {}
- },
- table: {
- columns: [],
- data: []
- }
- }
- return {
- data: this.inputs.data,
- state: tempState
- }
- }
-}
diff --git a/src/flows/treePage/init/nodes/initTree.ts b/src/flows/treePage/init/nodes/initTree.ts
index bd99e0a6..1173ed8c 100644
--- a/src/flows/treePage/init/nodes/initTree.ts
+++ b/src/flows/treePage/init/nodes/initTree.ts
@@ -4,56 +4,60 @@ import OpenAPI from '@/config/openapi'
export class InitTree extends FunctionNode {
async run() {
const tempState = this.inputs.state
- const initContent = this.inputs.data.initContent
+ const { initContent } = this.inputs.data
+ let baseAction = {
+ fetchUrl: '',
+ fetchMethod: ''
+ }
// 获取节点列表
- if (initContent.treeList) {
- const treeListOperationPath = initContent.treeList.path
- const treeListOperationMethod = initContent.treeList.method
- const treeListOperation = OpenAPI.instance.getOperation(treeListOperationPath, treeListOperationMethod)
- if (treeListOperation) {
+ if (initContent.init) {
+ const initTreePath = initContent.init.path
+ const initTreeMethod = initContent.init.method
+ baseAction.fetchUrl = initTreePath
+ baseAction.fetchMethod = initTreeMethod
+ const initTreeOperation = OpenAPI.instance.getOperation(initTreePath, initTreeMethod)
+ if (initTreeOperation) {
// 给treePage页面的created赋值 -- 获取tree节点数据和默认的table表格内容
tempState.created.push({
name: "flows/treePage/fetchTreeNode",
- params: {
- fetchUrl: treeListOperationPath,
- fetchMethod: treeListOperationMethod,
- }
+ params: baseAction
})
// 给 destroyed 赋值
tempState.destroyed.push({
name: "flows/hookFlow/destroyed",
- params: {
- fetchUrl: treeListOperationPath,
- fetchMethod: treeListOperationMethod,
- }
+ params: baseAction
})
// 给tree结构的最上方header模块的title赋值
- tempState.tree.header.title = treeListOperation.summary || ''
+ tempState.tree.header.title = initTreeOperation.summary || ''
// 给tree添加控制节点展开的内容属性 defaultExpandedKeys
tempState.tree.nodes.defaultExpandedKeys = []
}
}
- if (initContent.childrenList && initContent.tableList) {
- const treeNodeDataOperationPath = initContent.childrenList.path
- const treeNodeDataOperationMethod = initContent.childrenList.method
- const tableListOperationPath = initContent.tableList.path
- const tableListOperationMethod = initContent.tableList.method
+
+ // 子节点内容
+ if (initContent.item.children) {
+ const treeNodeDataOperationPath = initContent.item.children.path
+ const treeNodeDataOperationMethod = initContent.item.children.method
+ const tableListOperationPath = initContent.table.init.path
+ const tableListOperationMethod = initContent.table.init.method
// 给tree添加节点触发事件
tempState.tree.nodes.action = [
{
name: "flows/treePage/fetchTreeNodeChildren",
params: {
- fetchUrl: treeNodeDataOperationPath,
- fetchMethod: treeNodeDataOperationMethod,
- tableUrl: tableListOperationPath,
- tableMethod: tableListOperationMethod
+ url: treeNodeDataOperationPath,
+ method: treeNodeDataOperationMethod,
+ fetchUrl: tableListOperationPath,
+ fetchMethod: tableListOperationMethod
}
}
]
}
+
return {
data: this.inputs.data,
state: tempState,
+ baseAction: baseAction
}
}
}
diff --git a/src/flows/treePage/init/nodes/initTreeNodeSlot.ts b/src/flows/treePage/init/nodes/initTreeNodeSlot.ts
deleted file mode 100644
index 63988b79..00000000
--- a/src/flows/treePage/init/nodes/initTreeNodeSlot.ts
+++ /dev/null
@@ -1,127 +0,0 @@
-import { FunctionNode } from 'arkfbp/lib/functionNode'
-import OpenAPI from '@/config/openapi'
-import DialogState from '@/admin/common/Others/Dialog/DialogState'
-import generateDialogForm from '@/utils/generate-dialog-form'
-import getSchemaByContent from '@/utils/get-schema-by-content'
-import whetherImportListDialog from '@/utils/list-dialog'
-
-export class InitTreeNodeSlot extends FunctionNode {
- async run() {
- const tempState = this.inputs.state
- const initContent = this.inputs.data.initContent
- // 设置添加节点的功能
- if (initContent.treeCreate && initContent.treeUpdate) {
- const treeListOperationPath = initContent.treeList.path
- const treeListOperationMethod = initContent.treeList.method
- const treeCreateNodeOperationPath = initContent.treeCreate.path
- const treeCreateNodeOperationMethod = initContent.treeCreate.method
- const treeCreateNodeOperation = OpenAPI.instance.getOperation(treeCreateNodeOperationPath, treeCreateNodeOperationMethod)
- const treeUpdateNodeOperationPath = initContent.treeUpdate.path
- const treeUpdateNodeOperationMethod = initContent.treeUpdate.method
- const treeUpdateNodeOperation = OpenAPI.instance.getOperation(treeUpdateNodeOperationPath, treeUpdateNodeOperationMethod)
- const treeDeleteNodeOperationPath = initContent.treeDelete.path
- const treeDeleteNodeOperationMethod = initContent.treeDelete.method
- const treeDeleteNodeOperation = OpenAPI.instance.getOperation(treeDeleteNodeOperationPath, treeDeleteNodeOperationMethod)
-
- // 定义 slot 插槽内容为 ButtonArray
- tempState.tree.nodes['slot'] = {
- buttons: {
- type: 'ButtonArray',
- state: []
- }
- }
-
- // 给每一个tree节点添加创建按钮
- if (treeCreateNodeOperation) {
- const addTreeNodeSlot = {
- label: treeCreateNodeOperation.summary || '添加',
- type: 'text',
- action: [
- {
- name: 'flows/treePage/openAddTreeNodeDialog',
- }
- ]
- }
- tempState.tree.nodes['slot'].buttons.state.push(addTreeNodeSlot)
- }
-
- // 给每一个tree节点添加编辑按钮
- if (treeUpdateNodeOperation) {
- const editTreeNodeSlot = {
- label: treeUpdateNodeOperation.summary || '编辑',
- type: 'text',
- action: [
- {
- name: 'flows/treePage/openEditTreeNodeDialog',
- params: {
- updateUrl: treeUpdateNodeOperationPath,
- updateMethod: treeUpdateNodeOperationMethod,
- fetchUrl: treeListOperationPath,
- fetchMethod: treeListOperationMethod,
- }
- }
- ]
- }
- tempState.tree.nodes['slot'].buttons.state.push(editTreeNodeSlot)
- // 编辑按钮对应的dialog
- const content = treeUpdateNodeOperation.requestBody.content
- const schema = getSchemaByContent(content)
- const editTreeNodeDialogState:DialogState = {}
- editTreeNodeDialogState.title = treeUpdateNodeOperation.summary || '编辑'
- editTreeNodeDialogState.visible = false
- editTreeNodeDialogState.data = {}
- editTreeNodeDialogState.actions = [
- {
- label: treeUpdateNodeOperation.summary || '编辑',
- action: [
- {
- name: 'flows/treePage/editTreeNode',
- params: {
- updateUrl: treeUpdateNodeOperationPath,
- updateMethod: treeUpdateNodeOperationMethod,
- fetchUrl: treeListOperationPath,
- fetchMethod: treeListOperationMethod,
- }
- }
- ],
- type: 'primary'
- }
- ]
- editTreeNodeDialogState.type = 'FormPage'
- editTreeNodeDialogState.state = generateDialogForm(schema, false)
- tempState.dialogs['editTreeNode'] = editTreeNodeDialogState
-
- // 在这里进行是否有 InputList 第二层弹出框的判断,如果有,进行初始化 selected 弹出框, 没有则跳过此步骤
- const importListDialog = whetherImportListDialog(editTreeNodeDialogState.state)
- if (importListDialog && !tempState.dialogs.selected) {
- tempState.dialogs['selected'] = importListDialog
- }
-
- }
-
- // 给每一个tree节点添加删除按钮
- if (treeDeleteNodeOperation) {
- const deleteTreeNodeSlot = {
- label: treeDeleteNodeOperation.summary || '删除',
- type: 'text',
- action: [
- {
- name: 'flows/treePage/deleteTreeNode',
- params: {
- deleteUrl: treeDeleteNodeOperationPath,
- deleteMethod: treeDeleteNodeOperationMethod,
- fetchUrl: treeListOperationPath,
- fetchMethod: treeListOperationMethod,
- }
- }
- ]
- }
- tempState.tree.nodes['slot'].buttons.state.push(deleteTreeNodeSlot)
- }
- }
- return {
- data: this.inputs.data,
- state: tempState,
- }
- }
-}
diff --git a/src/flows/treePage/openAddTreeNodeDialog/index.ts b/src/flows/treePage/openCreateDialog/index.ts
similarity index 100%
rename from src/flows/treePage/openAddTreeNodeDialog/index.ts
rename to src/flows/treePage/openCreateDialog/index.ts
diff --git a/src/flows/treePage/openAddTreeNodeDialog/nodes/open.ts b/src/flows/treePage/openCreateDialog/nodes/open.ts
similarity index 81%
rename from src/flows/treePage/openAddTreeNodeDialog/nodes/open.ts
rename to src/flows/treePage/openCreateDialog/nodes/open.ts
index f25fdbba..23598f3e 100644
--- a/src/flows/treePage/openAddTreeNodeDialog/nodes/open.ts
+++ b/src/flows/treePage/openCreateDialog/nodes/open.ts
@@ -3,10 +3,10 @@ import DialogState from '@/admin/common/Others/Dialog/DialogState'
import TreePageState from '@/admin/TreePage/TreePageState'
export class Open extends OpenDialog {
- get dialog():DialogState | null {
+ get dialog(): DialogState | null {
const tempState: TreePageState = this.getState()
if (tempState && tempState.dialogs) {
- return tempState.dialogs.addTreeNode
+ return tempState.dialogs.create
} else {
return null
}
diff --git a/src/flows/treePage/openEditTreeNodeDialog/index.ts b/src/flows/treePage/openUpdateDialog/index.ts
similarity index 100%
rename from src/flows/treePage/openEditTreeNodeDialog/index.ts
rename to src/flows/treePage/openUpdateDialog/index.ts
diff --git a/src/flows/treePage/openEditTreeNodeDialog/nodes/open.ts b/src/flows/treePage/openUpdateDialog/nodes/open.ts
similarity index 94%
rename from src/flows/treePage/openEditTreeNodeDialog/nodes/open.ts
rename to src/flows/treePage/openUpdateDialog/nodes/open.ts
index ea981da3..c8e49e7c 100644
--- a/src/flows/treePage/openEditTreeNodeDialog/nodes/open.ts
+++ b/src/flows/treePage/openUpdateDialog/nodes/open.ts
@@ -7,7 +7,7 @@ export class Open extends OpenDialog {
get dialog():DialogState | null {
const tempState: TreePageState = this.getState()
if (tempState && tempState.dialogs) {
- return tempState.dialogs.editTreeNode
+ return tempState.dialogs.update
} else {
return null
}
diff --git a/src/flows/treePage/editTreeNode/index.ts b/src/flows/treePage/update/index.ts
similarity index 100%
rename from src/flows/treePage/editTreeNode/index.ts
rename to src/flows/treePage/update/index.ts
diff --git a/src/flows/treePage/editTreeNode/nodes/editTreeNode.ts b/src/flows/treePage/update/nodes/editTreeNode.ts
similarity index 88%
rename from src/flows/treePage/editTreeNode/nodes/editTreeNode.ts
rename to src/flows/treePage/update/nodes/editTreeNode.ts
index a49adf82..0c3f6d76 100644
--- a/src/flows/treePage/editTreeNode/nodes/editTreeNode.ts
+++ b/src/flows/treePage/update/nodes/editTreeNode.ts
@@ -11,8 +11,8 @@ export class EditTreeNode extends AuthApiNode {
const data = tempState.dialogs!['editTreeNode'].data
- this.url = getUrl(this.inputs.params.updateUrl, data)
- this.method = this.inputs.params.updateMethod || 'post'
+ this.url = getUrl(this.inputs.params.url, data)
+ this.method = this.inputs.params.method || 'post'
if (tempState && tempState.dialogs) {
const formPage = tempState.dialogs['editTreeNode'].state as FormPageState
diff --git a/src/layout/components/TagsView/ScrollPane.vue b/src/layout/components/TagsView/ScrollPane.vue
index 5ca85856..56c0776d 100644
--- a/src/layout/components/TagsView/ScrollPane.vue
+++ b/src/layout/components/TagsView/ScrollPane.vue
@@ -23,11 +23,15 @@ export default class extends Vue {
}
mounted() {
- this.scrollWrapper.addEventListener('scroll', this.emitScroll, true)
+ if (this.scrollWrapper) {
+ this.scrollWrapper.addEventListener('scroll', this.emitScroll, true)
+ }
}
beforeDestroy() {
- this.scrollWrapper.removeEventListener('scroll', this.emitScroll)
+ if (this.scrollWrapper) {
+ this.scrollWrapper.removeEventListener('scroll', this.emitScroll)
+ }
}
private handleScroll(e: MouseWheelEvent) {
diff --git a/src/nodes/authApiNode.ts b/src/nodes/authApiNode.ts
index 390a064f..d21595f2 100644
--- a/src/nodes/authApiNode.ts
+++ b/src/nodes/authApiNode.ts
@@ -7,7 +7,8 @@ export class AuthApiNode extends APINode {
const token = getToken()
if (token) {
this.headers = {
- Authorization: 'Token ' + token
+ Authorization: 'Token ' + token,
+ ...this.getHeaders()
}
}
return super.run()
@@ -24,4 +25,8 @@ export class AuthApiNode extends APINode {
getBaseState() {
return getBaseState()
}
+
+ getHeaders() {
+ return {}
+ }
}
diff --git a/src/nodes/getDialogValues.ts b/src/nodes/getDialogValues.ts
index 849da452..644be4cf 100644
--- a/src/nodes/getDialogValues.ts
+++ b/src/nodes/getDialogValues.ts
@@ -7,8 +7,8 @@ export class GetDialogValues extends AuthApiNode {
if (!data) {
throw Error('dialogs is not data')
}
- this.url = getUrl(this.inputs.params.updateUrl, data)
- this.method = 'get'
+ this.url = getUrl(this.inputs.params.url, data)
+ this.method = this.inputs.params.method || 'get'
const outputs = await super.run()
return {
outputs: outputs,
diff --git a/src/utils/initpage.ts b/src/utils/initpage.ts
new file mode 100644
index 00000000..10b24bb6
--- /dev/null
+++ b/src/utils/initpage.ts
@@ -0,0 +1,128 @@
+import { IOperation } from '@/config/openapi'
+import ButtonState from '@/admin/common/Button/ButtonState'
+import DialogState from '@/admin/common/Others/Dialog/DialogState'
+import generateDialogForm from '@/utils/generate-dialog-form'
+import getSchemaByContent from '@/utils/get-schema-by-content'
+import OpenAPI from '@/config/openapi'
+import whetherImportListDialog from '@/utils/list-dialog'
+
+// 参数说明:
+// path: 获取Dialog元素的必备参数 -- 必须
+// method: 方式 -- 必须
+// type: 类型,由于Dialog可以展示任意组件,需要指明其类型,默认为“FormPage” - 非必须
+// title: Dialog标题信息 -- 非必须
+// actions: 操作,填入Dialog的按钮中 -- 非必须
+// showReadOnly 是否需要展示 readOnly 的字段内容 - 非必须
+export interface GenerateDialogStateParams {
+ initActionOperation: IOperation
+ method: string
+ type?: string
+ title?: string
+ actions?: Array
+ showReadOnly?: boolean
+ key?: string
+}
+
+interface InitBaseAction {
+ fetchUrl: string
+ fetchMethod: string
+}
+
+export function generateDialogState(params: GenerateDialogStateParams): DialogState | undefined {
+ const { initActionOperation, method, type, title, actions, showReadOnly, key } = params
+ if (!initActionOperation || method === 'delete' || key === 'export') return undefined
+ const isResponses = method.toLowerCase() === "get" ? true : false
+ const content = isResponses ? initActionOperation.responses[200].content : initActionOperation.requestBody.content
+ const schema = getSchemaByContent(content)
+ const dialogState: DialogState = {}
+ dialogState.title = title
+ dialogState.visible = false
+ dialogState.data = {}
+ dialogState.type = type || 'FormPage'
+ if (type === 'Upload') {
+ dialogState.state = {
+ type: 'xlsx'
+ }
+ } else {
+ dialogState.state = generateDialogForm(schema, showReadOnly)
+ }
+ dialogState.actions = actions
+ return dialogState
+}
+
+
+// 初始化按钮或弹出框时,对进行属性的操作,包括 title(标题)、buttonType(按钮类型)、dialogType(弹出框类型-默认为FormPage)
+export function getBaseAttributes(key: string) {
+ let title = '', dialogType = 'FormPage', buttonType = 'primary'
+ let newKey = key.slice(0,1).toUpperCase() + key.slice(1).toLowerCase()
+ switch (key) {
+ case 'create':
+ title = '创建'
+ break
+ case 'import':
+ title = '导入'
+ dialogType = 'Upload'
+ break
+ case 'export':
+ title = '导出'
+ break
+ case 'update':
+ title = '编辑'
+ break
+ case 'delete':
+ title = '删除'
+ buttonType = 'danger'
+ break
+ case 'retrieve':
+ title = '查看'
+ buttonType = 'info'
+ break
+ }
+ return {
+ title,
+ dialogType,
+ buttonType,
+ newKey
+ }
+}
+
+
+export function dialog(tempState: any, url: string, method: string, key: string, prefix: string, baseAction: InitBaseAction, showReadOnly: boolean = true) {
+ const initActionOperation = OpenAPI.instance.getOperation(url, method)
+ if (!initActionOperation) return tempState
+ const { title, dialogType, buttonType } = getBaseAttributes(key)
+ const dialogAction = [
+ {
+ label: initActionOperation.summary || title,
+ type: buttonType,
+ action: [
+ {
+ name: prefix + key,
+ params: {
+ url,
+ method,
+ ...baseAction
+ }
+ }
+ ]
+ }
+ ]
+ const dialogParams: GenerateDialogStateParams = {
+ initActionOperation: initActionOperation,
+ method,
+ type: dialogType,
+ title: initActionOperation.summary || title,
+ actions: dialogAction,
+ showReadOnly,
+ key
+ }
+ const dialogState = generateDialogState(dialogParams)
+ if (dialogState) {
+ tempState.dialogs![key] = dialogState as DialogState
+ const importListDialog = whetherImportListDialog(dialogState.state)
+ if (importListDialog && !tempState.dialogs!.selected) {
+ tempState.dialogs!.selected = importListDialog
+ }
+ }
+ return tempState
+}