From d539544fa639cd9a447968ce1bcd81d79b8930c9 Mon Sep 17 00:00:00 2001 From: vapao Date: Wed, 29 Jul 2020 01:39:24 +0800 Subject: [PATCH] =?UTF-8?q?U=20=E5=8F=91=E5=B8=83=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=85=8B=E9=9A=86=E5=B7=B2=E6=94=AF=E6=8C=81=E8=B7=A8=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E5=85=8B=E9=9A=86=E5=B9=B6=E6=96=B0=E5=A2=9E=E6=9F=A5?= =?UTF-8?q?=E7=9C=8B=E9=85=8D=E7=BD=AE=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spug_web/src/pages/deploy/app/CloneConfirm.js | 60 ++++++++++++++++ spug_web/src/pages/deploy/app/Ext1Form.js | 9 ++- spug_web/src/pages/deploy/app/Ext1Setup1.js | 12 ++-- spug_web/src/pages/deploy/app/Ext1Setup2.js | 14 ++-- spug_web/src/pages/deploy/app/Ext1Setup3.js | 9 ++- spug_web/src/pages/deploy/app/Ext2Form.js | 9 ++- spug_web/src/pages/deploy/app/Ext2Setup1.js | 9 +-- spug_web/src/pages/deploy/app/Ext2Setup2.js | 5 +- spug_web/src/pages/deploy/app/Ext2Setup3.js | 71 +++++++++++-------- spug_web/src/pages/deploy/app/Table.js | 34 +++++++-- spug_web/src/pages/deploy/app/store.js | 6 +- 11 files changed, 182 insertions(+), 56 deletions(-) create mode 100644 spug_web/src/pages/deploy/app/CloneConfirm.js diff --git a/spug_web/src/pages/deploy/app/CloneConfirm.js b/spug_web/src/pages/deploy/app/CloneConfirm.js new file mode 100644 index 0000000..1d37797 --- /dev/null +++ b/spug_web/src/pages/deploy/app/CloneConfirm.js @@ -0,0 +1,60 @@ +/** + * Copyright (c) OpenSpug Organization. https://github.com/openspug/spug + * Copyright (c) + * Released under the AGPL-3.0 License. + */ +import React from 'react'; +import { observer } from 'mobx-react'; +import { Cascader, Form } from 'antd'; +import envStore from 'pages/config/environment/store'; +import store from './store'; +import lds from 'lodash'; +import { toJS } from "mobx"; + +@observer +class CloneConfirm extends React.Component { + handleLoadData = (selectedOptions) => { + const targetOption = selectedOptions[selectedOptions.length - 1]; + if (targetOption.deploys === undefined) { + targetOption.loading = true; + store.loadDeploys(targetOption.value).then(() => targetOption.loading = false) + } + } + + handleData = records => { + return records.map(x => { + const option = { + label: x.name, + value: x.id, + deploys: x.deploys, + isLeaf: false + } + if (x.children) { + option.children = x.children + } else if (x.deploys) { + option.children = x.deploys.map(item => ({ + label: lds.get(envStore.idMap, `${item.env_id}.name`), + value: JSON.stringify(item), + id: `${x.id},${item.env_id}`, + })) + } + return option + }) + } + + render() { + const options = this.handleData(Object.values(toJS(store.records))); + return ( +
+ + + +
+ ) + } +} + +export default CloneConfirm \ No newline at end of file diff --git a/spug_web/src/pages/deploy/app/Ext1Form.js b/spug_web/src/pages/deploy/app/Ext1Form.js index 650f321..967f84e 100644 --- a/spug_web/src/pages/deploy/app/Ext1Form.js +++ b/spug_web/src/pages/deploy/app/Ext1Form.js @@ -13,12 +13,19 @@ import store from './store'; import styles from './index.module.css'; export default observer(function Ext1From() { + const appName = store.records[store.app_id].name; + let title = `常规发布 - ${appName}`; + if (store.deploy.id) { + store.isReadOnly ? title = '查看' + title : title = '编辑' + title; + } else { + title = '新建' + title + } return ( store.ext1Visible = false} footer={null}> diff --git a/spug_web/src/pages/deploy/app/Ext1Setup1.js b/spug_web/src/pages/deploy/app/Ext1Setup1.js index baebdc4..0459e7a 100644 --- a/spug_web/src/pages/deploy/app/Ext1Setup1.js +++ b/spug_web/src/pages/deploy/app/Ext1Setup1.js @@ -16,21 +16,23 @@ export default observer(function Ext2Setup1() {
- info.env_id = v} placeholder="请选择发布环境"> {envStore.records.map(item => ( {item.name} ))} - 新建环境 + 新建环境 - info['git_repo'] = e.target.value} placeholder="请输入Git仓库地址"/> + info['git_repo'] = e.target.value} + placeholder="请输入Git仓库地址"/> 钉钉收不到通知? }> info['rst_notify']['mode'] = v}> 关闭 钉钉 @@ -50,7 +52,7 @@ export default observer(function Ext2Setup1() { Webhook )} - disabled={info['rst_notify']['mode'] === '0'} + disabled={store.isReadOnly || info['rst_notify']['mode'] === '0'} value={info['rst_notify']['value']} onChange={e => info['rst_notify']['value'] = e.target.value} placeholder="请输入"/> diff --git a/spug_web/src/pages/deploy/app/Ext1Setup2.js b/spug_web/src/pages/deploy/app/Ext1Setup2.js index f3ded10..633a482 100644 --- a/spug_web/src/pages/deploy/app/Ext1Setup2.js +++ b/spug_web/src/pages/deploy/app/Ext1Setup2.js @@ -28,7 +28,7 @@ class Ext1Setup2 extends React.Component { if (dst_repo.includes(dst_dir.replace(/\/*$/, '/'))) { message.error('仓库目录不能位于发布部署目录内') } else { - store.page += 1 + store.page += 1 } }; @@ -37,13 +37,14 @@ class Ext1Setup2 extends React.Component { return ( - info['dst_dir'] = e.target.value} placeholder="请输入目标主机部署路径"/> + info['dst_dir'] = e.target.value} + placeholder="请输入目标主机部署路径"/> - info['dst_repo'] = e.target.value} placeholder="请输入目标主机仓库路径"/> + info['dst_repo'] = e.target.value} placeholder="请输入目标主机仓库路径"/> - info['versions'] = e.target.value} placeholder="请输入保留历史版本数量"/> + info['versions'] = e.target.value} placeholder="请输入保留历史版本数量"/> {info['host_ids'].map((id, index) => ( @@ -52,6 +53,7 @@ class Ext1Setup2 extends React.Component { value={id} showSearch placeholder="请选择" + disabled={store.isReadOnly} style={{width: '80%', marginRight: 10}} optionFilterProp="children" filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0} @@ -62,14 +64,14 @@ class Ext1Setup2 extends React.Component { ))} - {info['host_ids'].length > 1 && ( + {!store.isReadOnly && info['host_ids'].length > 1 && ( store.delHost(index)}/> )} ))} - diff --git a/spug_web/src/pages/deploy/app/Ext1Setup3.js b/spug_web/src/pages/deploy/app/Ext1Setup3.js index eba92a4..c22d323 100644 --- a/spug_web/src/pages/deploy/app/Ext1Setup3.js +++ b/spug_web/src/pages/deploy/app/Ext1Setup3.js @@ -55,6 +55,7 @@ class Ext1Setup3 extends React.Component {
文件过滤: store.deploy['filter_rule']['type'] = e.target.value}> @@ -105,6 +106,7 @@ class Ext1Setup3 extends React.Component { className={full === '1' ? styles.fullScreen : null} label={}> }> }> }> }> }> - + diff --git a/spug_web/src/pages/deploy/app/Ext2Form.js b/spug_web/src/pages/deploy/app/Ext2Form.js index 42b9abf..e2d7e18 100644 --- a/spug_web/src/pages/deploy/app/Ext2Form.js +++ b/spug_web/src/pages/deploy/app/Ext2Form.js @@ -13,12 +13,19 @@ import Setup3 from './Ext2Setup3'; import store from './store'; export default observer(function Ext2From() { + const appName = store.records[store.app_id].name; + let title = `自定义发布 - ${appName}`; + if (store.deploy.id) { + store.isReadOnly ? title = '查看' + title : title = '编辑' + title; + } else { + title = '新建' + title + } return ( store.ext2Visible = false} footer={null}> diff --git a/spug_web/src/pages/deploy/app/Ext2Setup1.js b/spug_web/src/pages/deploy/app/Ext2Setup1.js index d9a4503..1af7460 100644 --- a/spug_web/src/pages/deploy/app/Ext2Setup1.js +++ b/spug_web/src/pages/deploy/app/Ext2Setup1.js @@ -16,18 +16,19 @@ export default observer(function Ext2Setup1() { - info.env_id = v} placeholder="请选择发布环境"> {envStore.records.map(item => ( {item.name} ))} - 新建环境 + 新建环境 钉钉收不到通知? }> info['rst_notify']['mode'] = v}> 关闭 钉钉 @@ -47,7 +48,7 @@ export default observer(function Ext2Setup1() { Webhook )} - disabled={info['rst_notify']['mode'] === '0'} + disabled={store.isReadOnly || info['rst_notify']['mode'] === '0'} value={info['rst_notify']['value']} onChange={e => info['rst_notify']['value'] = e.target.value} placeholder="请输入"/> diff --git a/spug_web/src/pages/deploy/app/Ext2Setup2.js b/spug_web/src/pages/deploy/app/Ext2Setup2.js index b6e13de..47f50b9 100644 --- a/spug_web/src/pages/deploy/app/Ext2Setup2.js +++ b/spug_web/src/pages/deploy/app/Ext2Setup2.js @@ -28,6 +28,7 @@ class Ext2Setup2 extends React.Component { - {info['host_ids'].length > 1 && ( + {!store.isReadOnly && info['host_ids'].length > 1 && ( store.delHost(index)}/> )} ))} - diff --git a/spug_web/src/pages/deploy/app/Ext2Setup3.js b/spug_web/src/pages/deploy/app/Ext2Setup3.js index d29ff25..2eadd19 100644 --- a/spug_web/src/pages/deploy/app/Ext2Setup3.js +++ b/spug_web/src/pages/deploy/app/Ext2Setup3.js @@ -64,11 +64,13 @@ class Ext2Setup3 extends React.Component { {server_actions.map((item, index) => (
- item['title'] = e.target.value} placeholder="请输入"/> + item['title'] = e.target.value} + placeholder="请输入"/> item['data'] = cleanCommand(v)} placeholder="请输入要执行的动作"/> -
server_actions.splice(index, 1)}> - 移除 -
+ {!store.isReadOnly && ( +
server_actions.splice(index, 1)}> + 移除 +
+ )}
))} - - - + {!store.isReadOnly && ( + + + + )} {host_actions.map((item, index) => (
- item['title'] = e.target.value} placeholder="请输入"/> + item['title'] = e.target.value} + placeholder="请输入"/> {item['type'] === 'transfer' ? ([ @@ -100,9 +107,10 @@ class Ext2Setup3 extends React.Component { placeholder="请输入逗号分割的过滤规则" value={item['rule']} onChange={e => item['rule'] = e.target.value.replace(',', ',')} - disabled={item['mode'] === '0'} + disabled={store.isReadOnly || item['mode'] === '0'} addonBefore={( - item['mode'] = v}> 关闭 包含 排除 @@ -113,11 +121,13 @@ class Ext2Setup3 extends React.Component { target="_blank" rel="noopener noreferrer" href="https://spug.dev/docs/deploy-config#%E6%95%B0%E6%8D%AE%E4%BC%A0%E8%BE%93">使用前请务必阅读官方文档。}> item['src'] = e.target.value}/> )} -
host_actions.splice(index, 1)}> - 移除 -
+ {!store.isReadOnly && ( +
host_actions.splice(index, 1)}> + 移除 +
+ )}
))} - - - - + {!store.isReadOnly && ( + + + + + )} diff --git a/spug_web/src/pages/deploy/app/Table.js b/spug_web/src/pages/deploy/app/Table.js index b7ec5fb..05eea8f 100644 --- a/spug_web/src/pages/deploy/app/Table.js +++ b/spug_web/src/pages/deploy/app/Table.js @@ -10,11 +10,17 @@ import { Table, Divider, Modal, Tag, Icon, message } from 'antd'; import http from 'libs/http'; import store from './store'; import { LinkButton } from "components"; +import CloneConfirm from './CloneConfirm'; import envStore from 'pages/config/environment/store'; import lds from 'lodash'; @observer class ComTable extends React.Component { + constructor(props) { + super(props); + this.cloneObj = {}; + } + componentDidMount() { store.fetchRecords(); if (envStore.records.length === 0) { @@ -43,6 +49,8 @@ class ComTable extends React.Component { store.showExtForm(e, info.id)}>新建发布 + this.handleClone(e, info.id)}>克隆发布 + store.showForm(e, info)}>编辑 this.handleDelete(e, info)}>删除 @@ -50,6 +58,19 @@ class ComTable extends React.Component { ) }]; + handleClone = (e, id) => { + e.stopPropagation(); + Modal.confirm({ + icon: 'exclamation-circle', + title: '选择克隆对象', + content: this.cloneObj = v[1]}/>, + onOk: () => { + const info = JSON.parse(this.cloneObj); + store.showExtForm(null, id, info, true) + }, + }) + }; + handleDelete = (e, text) => { e.stopPropagation(); Modal.confirm({ @@ -102,12 +123,13 @@ class ComTable extends React.Component { title: '操作', render: info => ( - store.showExtForm(e, record.id, info)}>编辑 - - store.showExtForm(e, record.id, info, true)}>克隆配置 - - this.handleDeployDelete(info)}>删除 - + store.showExtForm(e, record.id, info, false, true)}>查看 + + store.showExtForm(e, record.id, info)}>编辑 + + this.handleDeployDelete(info)}>删除 + ) }]; diff --git a/spug_web/src/pages/deploy/app/store.js b/spug_web/src/pages/deploy/app/store.js index 689c4a9..dc1971b 100644 --- a/spug_web/src/pages/deploy/app/store.js +++ b/spug_web/src/pages/deploy/app/store.js @@ -12,6 +12,7 @@ class Store { @observable deploy = {}; @observable page = 0; @observable loading = {}; + @observable isReadOnly = false; @observable isFetching = false; @observable formVisible = false; @observable addVisible = false; @@ -35,7 +36,7 @@ class Store { }; loadDeploys = (app_id) => { - http.get('/api/app/deploy/', {params: {app_id}}) + return http.get('/api/app/deploy/', {params: {app_id}}) .then(res => this.records[app_id]['deploys'] = res) }; @@ -45,10 +46,11 @@ class Store { this.formVisible = true; }; - showExtForm = (e, app_id, info, isClone) => { + showExtForm = (e, app_id, info, isClone, isReadOnly = false) => { if (e) e.stopPropagation(); this.page = 0; this.app_id = app_id; + this.isReadOnly = isReadOnly if (info) { if (info.extend === '1') { this.ext1Visible = true