diff --git a/spug_web/src/pages/deploy/app/Ext1Form.js b/spug_web/src/pages/deploy/app/Ext1Form.js index 967f84e..db0ac28 100644 --- a/spug_web/src/pages/deploy/app/Ext1Form.js +++ b/spug_web/src/pages/deploy/app/Ext1Form.js @@ -13,7 +13,7 @@ import store from './store'; import styles from './index.module.css'; export default observer(function Ext1From() { - const appName = store.records[store.app_id].name; + const appName = store.currentRecord.name; let title = `常规发布 - ${appName}`; if (store.deploy.id) { store.isReadOnly ? title = '查看' + title : title = '编辑' + title; diff --git a/spug_web/src/pages/deploy/app/Ext1Setup1.js b/spug_web/src/pages/deploy/app/Ext1Setup1.js index 7d23391..c93c85a 100644 --- a/spug_web/src/pages/deploy/app/Ext1Setup1.js +++ b/spug_web/src/pages/deploy/app/Ext1Setup1.js @@ -14,12 +14,12 @@ export default observer(function Ext1Setup1() { const [envs, setEnvs] = useState([]); function updateEnvs() { - const ids = store.records[store.app_id]['deploys'].map(x => x.env_id); + const ids = store.currentRecord['deploys'].map(x => x.env_id); setEnvs(ids.filter(x => x !== store.deploy.env_id)) } useEffect(() => { - if (store.records[store.app_id]['deploys'] === undefined) { + if (store.currentRecord['deploys'] === undefined) { store.loadDeploys(store.app_id).then(updateEnvs) } else { updateEnvs() diff --git a/spug_web/src/pages/deploy/app/Ext2Form.js b/spug_web/src/pages/deploy/app/Ext2Form.js index e2d7e18..34db9dc 100644 --- a/spug_web/src/pages/deploy/app/Ext2Form.js +++ b/spug_web/src/pages/deploy/app/Ext2Form.js @@ -13,7 +13,7 @@ import Setup3 from './Ext2Setup3'; import store from './store'; export default observer(function Ext2From() { - const appName = store.records[store.app_id].name; + const appName = store.currentRecord.name; let title = `自定义发布 - ${appName}`; if (store.deploy.id) { store.isReadOnly ? title = '查看' + title : title = '编辑' + title; diff --git a/spug_web/src/pages/deploy/app/Ext2Setup1.js b/spug_web/src/pages/deploy/app/Ext2Setup1.js index 647e349..0c6c00f 100644 --- a/spug_web/src/pages/deploy/app/Ext2Setup1.js +++ b/spug_web/src/pages/deploy/app/Ext2Setup1.js @@ -14,12 +14,12 @@ export default observer(function Ext2Setup1() { const [envs, setEnvs] = useState([]); function updateEnvs() { - const ids = store.records[store.app_id]['deploys'].map(x => x.env_id); + const ids = store.currentRecord['deploys'].map(x => x.env_id); setEnvs(ids.filter(x => x !== store.deploy.env_id)) } useEffect(() => { - if (store.records[store.app_id]['deploys'] === undefined) { + if (store.currentRecord['deploys'] === undefined) { store.loadDeploys(store.app_id).then(updateEnvs) } else { updateEnvs() diff --git a/spug_web/src/pages/deploy/app/store.js b/spug_web/src/pages/deploy/app/store.js index dc1971b..732bd11 100644 --- a/spug_web/src/pages/deploy/app/store.js +++ b/spug_web/src/pages/deploy/app/store.js @@ -3,7 +3,7 @@ * Copyright (c) * Released under the AGPL-3.0 License. */ -import { observable } from "mobx"; +import { observable, computed } from "mobx"; import http from 'libs/http'; class Store { @@ -22,13 +22,17 @@ class Store { @observable f_name; @observable f_desc; + @computed get currentRecord() { + return this.records[`a${this.app_id}`] + } + fetchRecords = () => { this.isFetching = true; http.get('/api/app/') .then(res => { const tmp = {}; for (let item of res) { - tmp[item.id] = item + tmp[`a${item.id}`] = item } this.records = tmp }) @@ -37,7 +41,7 @@ class Store { loadDeploys = (app_id) => { return http.get('/api/app/deploy/', {params: {app_id}}) - .then(res => this.records[app_id]['deploys'] = res) + .then(res => this.records[`a${app_id}`]['deploys'] = res) }; showForm = (e, info) => {