From e7921e4171c19b3601bb0ced6b7a22534eab70ce Mon Sep 17 00:00:00 2001 From: yombo Date: Wed, 1 Mar 2023 14:54:18 +0800 Subject: [PATCH 1/4] =?UTF-8?q?U:=20Web=E7=BB=88=E7=AB=AF=E7=9A=84?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=AE=A1=E7=90=86=E5=99=A8=EF=BC=8C=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E6=8C=89=E6=96=87=E4=BB=B6=E4=BF=AE=E6=94=B9=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spug_web/src/pages/ssh/FileManager.js | 84 ++++++++++++++------------- 1 file changed, 43 insertions(+), 41 deletions(-) diff --git a/spug_web/src/pages/ssh/FileManager.js b/spug_web/src/pages/ssh/FileManager.js index 9df0cd9..eec26fc 100644 --- a/spug_web/src/pages/ssh/FileManager.js +++ b/spug_web/src/pages/ssh/FileManager.js @@ -18,6 +18,7 @@ import { AuthButton, Action } from 'components'; import { http, uniqueId, X_TOKEN } from 'libs'; import lds from 'lodash'; import styles from './index.module.less' +import moment from 'moment'; class FileManager extends React.Component { @@ -44,7 +45,7 @@ class FileManager extends React.Component { componentDidUpdate(prevProps) { if (this.props.id !== prevProps.id) { this.fetchFiles() - this.setState({objects: []}) + this.setState({ objects: [] }) } } @@ -52,14 +53,14 @@ class FileManager extends React.Component { title: '名称', key: 'name', render: info => info.kind === 'd' ? ( -
this.handleChdir(info.name, '1')} style={{cursor: 'pointer'}}> - - {info.name} +
this.handleChdir(info.name, '1')} style={{ cursor: 'pointer' }}> + + {info.name}
) : ( - - {info.name} + + {info.name} ), ellipsis: true @@ -72,6 +73,7 @@ class FileManager extends React.Component { }, { title: '修改时间', dataIndex: 'date', + sorter: (a, b) => moment(a.date).unix() - moment(b.date).unix(), width: 190 }, { title: '属性', @@ -84,10 +86,10 @@ class FileManager extends React.Component { key: 'action', render: info => info.kind === '-' ? ( - } - onClick={() => this.handleDownload(info.name)}/> - } - onClick={() => this.handleDelete(info.name)}/> + } + onClick={() => this.handleDownload(info.name)} /> + } + onClick={() => this.handleDelete(info.name)} /> ) : null }]; @@ -97,23 +99,23 @@ class FileManager extends React.Component { }; fetchFiles = (pwd) => { - this.setState({fetching: true}); + this.setState({ fetching: true }); pwd = pwd || this.state.pwd; const path = '/' + pwd.join('/'); - return http.get('/api/file/', {params: {id: this.props.id, path}}) + return http.get('/api/file/', { params: { id: this.props.id, path } }) .then(res => { const objects = lds.orderBy(res, [this._kindSort, 'name'], ['desc', 'asc']); - this.setState({objects, pwd}) - this.state.inputPath !== null && this.setState({inputPath: path}) + this.setState({ objects, pwd }) + this.state.inputPath !== null && this.setState({ inputPath: path }) }) - .finally(() => this.setState({fetching: false})) + .finally(() => this.setState({ fetching: false })) }; handleChdir = (name, action) => { let pwd = this.state.pwd.map(x => x); if (action === '1') { pwd.push(name) - this.setState({inputPath: null}) + this.setState({ inputPath: null }) } else if (action === '2') { const index = pwd.indexOf(name); pwd = pwd.splice(0, index + 1) @@ -126,23 +128,23 @@ class FileManager extends React.Component { handleInputEnter = () => { if (this.state.inputPath === null) { if (this.state.pwd.length > 0) { - this.setState({inputPath: `/${this.state.pwd.join('/')}/`}) + this.setState({ inputPath: `/${this.state.pwd.join('/')}/` }) } else { - this.setState({inputPath: '/'}) + this.setState({ inputPath: '/' }) } setTimeout(() => this.input2.focus(), 100) } else { let pwdStr = this.state.inputPath.replace(/^\/+/, '') pwdStr = pwdStr.replace(/\/+$/, '') this.fetchFiles(pwdStr.split('/')) - .then(() => this.setState({inputPath: null})) + .then(() => this.setState({ inputPath: null })) } } handleUpload = () => { this.input.click(); this.input.onchange = e => { - this.setState({uploading: true, uploadStatus: 'active', percent: 0}); + this.setState({ uploading: true, uploadStatus: 'active', percent: 0 }); const file = e.target['files'][0]; const formData = new FormData(); const token = uniqueId(); @@ -152,18 +154,18 @@ class FileManager extends React.Component { formData.append('token', token); formData.append('path', '/' + this.state.pwd.join('/')); this.input.value = ''; - http.post('/api/file/object/', formData, {timeout: 600000, onUploadProgress: this._updateLocal}) + http.post('/api/file/object/', formData, { timeout: 600000, onUploadProgress: this._updateLocal }) .then(() => { - this.setState({uploadStatus: 'success'}); + this.setState({ uploadStatus: 'success' }); this.fetchFiles() - }, () => this.setState({uploadStatus: 'exception'})) - .finally(() => setTimeout(() => this.setState({uploading: false}), 2000)) + }, () => this.setState({ uploadStatus: 'exception' })) + .finally(() => setTimeout(() => this.setState({ uploading: false }), 2000)) } }; _updateLocal = (e) => { const percent = e.loaded / e.total * 100 / 2 - this.setState({percent: Number(percent.toFixed(1))}) + this.setState({ percent: Number(percent.toFixed(1)) }) } _updatePercent = token => { @@ -175,7 +177,7 @@ class FileManager extends React.Component { this.socket.send('ping') } else { const percent = this.state.percent + Number(e.data) / 2; - if (percent > this.state.percent) this.setState({percent: Number(percent.toFixed(1))}); + if (percent > this.state.percent) this.setState({ percent: Number(percent.toFixed(1)) }); if (percent === 100) { this.socket.close() } @@ -200,7 +202,7 @@ class FileManager extends React.Component { title: '删除文件确认', content: `确认删除文件:${file} ?`, onOk: () => { - return http.delete('/api/file/object/', {params: {id: this.props.id, file}}) + return http.delete('/api/file/object/', { params: { id: this.props.id, file } }) .then(() => { message.success('删除成功'); this.fetchFiles() @@ -217,18 +219,18 @@ class FileManager extends React.Component { const scrollY = document.body.clientHeight - 168; return ( - this.input = ref}/> + this.input = ref} />
{this.state.inputPath !== null ? ( this.input2 = ref} size="small" className={styles.input} - suffix={
回车确认
} - value={this.state.inputPath} onChange={e => this.setState({inputPath: e.target.value})} - onBlur={this.handleInputEnter} - onPressEnter={this.handleInputEnter}/> + suffix={
回车确认
} + value={this.state.inputPath} onChange={e => this.setState({ inputPath: e.target.value })} + onBlur={this.handleInputEnter} + onPressEnter={this.handleInputEnter} /> ) : ( this.handleChdir('', '0')}> - + {this.state.pwd.map(item => ( this.handleChdir(item, '2')}> @@ -236,7 +238,7 @@ class FileManager extends React.Component { ))} - + )} @@ -247,17 +249,17 @@ class FileManager extends React.Component { checked={this.state.showDot} checkedChildren="开启" unCheckedChildren="关闭" - onChange={v => this.setState({showDot: v})}/> + onChange={v => this.setState({ showDot: v })} /> {this.state.uploading ? ( + percent={this.state.percent} /> ) : ( } + icon={} onClick={this.handleUpload}>上传文件 )}
@@ -268,9 +270,9 @@ class FileManager extends React.Component { loading={this.state.fetching} pagination={false} columns={this.columns} - scroll={{y: scrollY}} - style={{fontFamily: 'Source Code Pro, Courier New, Courier, Monaco, monospace, PingFang SC, Microsoft YaHei'}} - dataSource={objects}/> + scroll={{ y: scrollY }} + style={{ fontFamily: 'Source Code Pro, Courier New, Courier, Monaco, monospace, PingFang SC, Microsoft YaHei' }} + dataSource={objects} />
) } From baf2d8c5d354fb9ea0db88e3f4d83f1d32fa4100 Mon Sep 17 00:00:00 2001 From: yombo Date: Wed, 1 Mar 2023 17:51:23 +0800 Subject: [PATCH 2/4] U: #589 --- spug_web/src/pages/ssh/FileManager.js | 187 ++++++++++++++++---------- 1 file changed, 119 insertions(+), 68 deletions(-) diff --git a/spug_web/src/pages/ssh/FileManager.js b/spug_web/src/pages/ssh/FileManager.js index eec26fc..4b1a964 100644 --- a/spug_web/src/pages/ssh/FileManager.js +++ b/spug_web/src/pages/ssh/FileManager.js @@ -26,6 +26,7 @@ class FileManager extends React.Component { super(props); this.input = null; this.input2 = null + this.pwdHistoryCaches = new Map() this.state = { fetching: false, showDot: false, @@ -100,12 +101,18 @@ class FileManager extends React.Component { fetchFiles = (pwd) => { this.setState({ fetching: true }); - pwd = pwd || this.state.pwd; + pwd = pwd || (this.pwdHistoryCaches.get(this.props.id) || []); + if (this.pwdHistoryCaches.has(this.props.id)) { + let pwdCache = this.pwdHistoryCaches.get(this.props.id) + pwdCache.push(pwd.length > 0 ? pwd.splice(-1) : null) + pwd = pwdCache.filter(x => !!x) + } const path = '/' + pwd.join('/'); return http.get('/api/file/', { params: { id: this.props.id, path } }) .then(res => { const objects = lds.orderBy(res, [this._kindSort, 'name'], ['desc', 'asc']); this.setState({ objects, pwd }) + this.pwdHistoryCaches.set(this.props.id, pwd) this.state.inputPath !== null && this.setState({ inputPath: path }) }) .finally(() => this.setState({ fetching: false })) @@ -118,122 +125,154 @@ class FileManager extends React.Component { this.setState({ inputPath: null }) } else if (action === '2') { const index = pwd.indexOf(name); - pwd = pwd.splice(0, index + 1) + pwd = pwd.splice(0, index + 1); } else { - pwd = [] + pwd = []; } - this.fetchFiles(pwd) + this.fetchFiles(pwd); }; handleInputEnter = () => { if (this.state.inputPath === null) { if (this.state.pwd.length > 0) { - this.setState({ inputPath: `/${this.state.pwd.join('/')}/` }) + this.setState({ inputPath: `/${this.state.pwd.join("/")}/` }); } else { - this.setState({ inputPath: '/' }) + this.setState({ inputPath: "/" }); } - setTimeout(() => this.input2.focus(), 100) + setTimeout(() => this.input2.focus(), 100); } else { - let pwdStr = this.state.inputPath.replace(/^\/+/, '') - pwdStr = pwdStr.replace(/\/+$/, '') - this.fetchFiles(pwdStr.split('/')) - .then(() => this.setState({ inputPath: null })) + let pwdStr = this.state.inputPath.replace(/^\/+/, ""); + pwdStr = pwdStr.replace(/\/+$/, ""); + this.fetchFiles(pwdStr.split("/")).then(() => + this.setState({ inputPath: null }) + ); } - } + }; handleUpload = () => { this.input.click(); - this.input.onchange = e => { - this.setState({ uploading: true, uploadStatus: 'active', percent: 0 }); - const file = e.target['files'][0]; + this.input.onchange = (e) => { + this.setState({ uploading: true, uploadStatus: "active", percent: 0 }); + const file = e.target["files"][0]; const formData = new FormData(); const token = uniqueId(); this._updatePercent(token); - formData.append('file', file); - formData.append('id', this.props.id); - formData.append('token', token); - formData.append('path', '/' + this.state.pwd.join('/')); - this.input.value = ''; - http.post('/api/file/object/', formData, { timeout: 600000, onUploadProgress: this._updateLocal }) - .then(() => { - this.setState({ uploadStatus: 'success' }); - this.fetchFiles() - }, () => this.setState({ uploadStatus: 'exception' })) - .finally(() => setTimeout(() => this.setState({ uploading: false }), 2000)) - } + formData.append("file", file); + formData.append("id", this.props.id); + formData.append("token", token); + formData.append("path", "/" + this.state.pwd.join("/")); + this.input.value = ""; + http + .post("/api/file/object/", formData, { + timeout: 600000, + onUploadProgress: this._updateLocal, + }) + .then( + () => { + this.setState({ uploadStatus: "success" }); + this.fetchFiles(); + }, + () => this.setState({ uploadStatus: "exception" }) + ) + .finally(() => + setTimeout(() => this.setState({ uploading: false }), 2000) + ); + }; }; _updateLocal = (e) => { - const percent = e.loaded / e.total * 100 / 2 - this.setState({ percent: Number(percent.toFixed(1)) }) - } + const percent = ((e.loaded / e.total) * 100) / 2; + this.setState({ percent: Number(percent.toFixed(1)) }); + }; - _updatePercent = token => { - const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'; - this.socket = new WebSocket(`${protocol}//${window.location.host}/api/ws/subscribe/${token}/?x-token=${X_TOKEN}`); - this.socket.onopen = () => this.socket.send('ok'); - this.socket.onmessage = e => { - if (e.data === 'pong') { - this.socket.send('ping') + _updatePercent = (token) => { + const protocol = window.location.protocol === "https:" ? "wss:" : "ws:"; + this.socket = new WebSocket( + `${protocol}//${window.location.host}/api/ws/subscribe/${token}/?x-token=${X_TOKEN}` + ); + this.socket.onopen = () => this.socket.send("ok"); + this.socket.onmessage = (e) => { + if (e.data === "pong") { + this.socket.send("ping"); } else { const percent = this.state.percent + Number(e.data) / 2; - if (percent > this.state.percent) this.setState({ percent: Number(percent.toFixed(1)) }); + if (percent > this.state.percent) + this.setState({ percent: Number(percent.toFixed(1)) }); if (percent === 100) { - this.socket.close() + this.socket.close(); } } - } + }; }; handleDownload = (name) => { - const file = `/${this.state.pwd.join('/')}/${name}`; - const link = document.createElement('a'); + const file = `/${this.state.pwd.join("/")}/${name}`; + const link = document.createElement("a"); link.download = name; link.href = `/api/file/object/?id=${this.props.id}&file=${file}&x-token=${X_TOKEN}`; document.body.appendChild(link); link.click(); document.body.removeChild(link); - message.warning('即将开始下载,请勿重复点击。') + message.warning("即将开始下载,请勿重复点击。"); }; handleDelete = (name) => { - const file = `/${this.state.pwd.join('/')}/${name}`; + const file = `/${this.state.pwd.join("/")}/${name}`; Modal.confirm({ - title: '删除文件确认', + title: "删除文件确认", content: `确认删除文件:${file} ?`, onOk: () => { - return http.delete('/api/file/object/', { params: { id: this.props.id, file } }) + return http + .delete("/api/file/object/", { params: { id: this.props.id, file } }) .then(() => { - message.success('删除成功'); - this.fetchFiles() - }) - } - }) + message.success("删除成功"); + this.fetchFiles(); + }); + }, + }); }; render() { let objects = this.state.objects; if (!this.state.showDot) { - objects = objects.filter(x => !x.name.startsWith('.')) + objects = objects.filter((x) => !x.name.startsWith(".")); } const scrollY = document.body.clientHeight - 168; return ( - this.input = ref} /> + (this.input = ref)} + />
{this.state.inputPath !== null ? ( - this.input2 = ref} size="small" className={styles.input} - suffix={
回车确认
} - value={this.state.inputPath} onChange={e => this.setState({ inputPath: e.target.value })} + (this.input2 = ref)} + size="small" + className={styles.input} + suffix={ +
回车确认
+ } + value={this.state.inputPath} + onChange={(e) => this.setState({ inputPath: e.target.value })} onBlur={this.handleInputEnter} - onPressEnter={this.handleInputEnter} /> + onPressEnter={this.handleInputEnter} + /> ) : ( - this.handleChdir('', '0')}> + this.handleChdir("", "0")} + > - {this.state.pwd.map(item => ( - this.handleChdir(item, '2')}> + {this.state.pwd.map((item) => ( + this.handleChdir(item, "2")} + > {item} ))} @@ -249,10 +288,15 @@ class FileManager extends React.Component { checked={this.state.showDot} checkedChildren="开启" unCheckedChildren="关闭" - onChange={v => this.setState({ showDot: v })} /> + onChange={(v) => this.setState({ showDot: v })} + /> {this.state.uploading ? ( - + ) : ( } - onClick={this.handleUpload}>上传文件 + onClick={this.handleUpload} + > + 上传文件 + )}
@@ -271,11 +318,15 @@ class FileManager extends React.Component { pagination={false} columns={this.columns} scroll={{ y: scrollY }} - style={{ fontFamily: 'Source Code Pro, Courier New, Courier, Monaco, monospace, PingFang SC, Microsoft YaHei' }} - dataSource={objects} /> + style={{ + fontFamily: + "Source Code Pro, Courier New, Courier, Monaco, monospace, PingFang SC, Microsoft YaHei", + }} + dataSource={objects} + /> - ) + ); } } -export default FileManager \ No newline at end of file +export default FileManager; From f9e28f4738c4eaaa1bc9ec5f769f89a385e1f3cb Mon Sep 17 00:00:00 2001 From: yombo Date: Thu, 2 Mar 2023 10:10:20 +0800 Subject: [PATCH 3/4] u: code format reset --- spug_web/src/pages/ssh/FileManager.js | 220 +++++++++++--------------- 1 file changed, 88 insertions(+), 132 deletions(-) diff --git a/spug_web/src/pages/ssh/FileManager.js b/spug_web/src/pages/ssh/FileManager.js index 4b1a964..9f999b7 100644 --- a/spug_web/src/pages/ssh/FileManager.js +++ b/spug_web/src/pages/ssh/FileManager.js @@ -46,7 +46,7 @@ class FileManager extends React.Component { componentDidUpdate(prevProps) { if (this.props.id !== prevProps.id) { this.fetchFiles() - this.setState({ objects: [] }) + this.setState({objects: []}) } } @@ -54,14 +54,14 @@ class FileManager extends React.Component { title: '名称', key: 'name', render: info => info.kind === 'd' ? ( -
this.handleChdir(info.name, '1')} style={{ cursor: 'pointer' }}> - - {info.name} +
this.handleChdir(info.name, '1')} style={{cursor: 'pointer'}}> + + {info.name}
) : ( - - {info.name} + + {info.name} ), ellipsis: true @@ -87,10 +87,10 @@ class FileManager extends React.Component { key: 'action', render: info => info.kind === '-' ? ( - } - onClick={() => this.handleDownload(info.name)} /> - } - onClick={() => this.handleDelete(info.name)} /> + } + onClick={() => this.handleDownload(info.name)}/> + } + onClick={() => this.handleDelete(info.name)}/> ) : null }]; @@ -108,176 +108,144 @@ class FileManager extends React.Component { pwd = pwdCache.filter(x => !!x) } const path = '/' + pwd.join('/'); - return http.get('/api/file/', { params: { id: this.props.id, path } }) + return http.get('/api/file/', {params: {id: this.props.id, path}}) .then(res => { const objects = lds.orderBy(res, [this._kindSort, 'name'], ['desc', 'asc']); - this.setState({ objects, pwd }) + this.setState({objects, pwd}) this.pwdHistoryCaches.set(this.props.id, pwd) - this.state.inputPath !== null && this.setState({ inputPath: path }) + this.state.inputPath !== null && this.setState({inputPath: path}) }) - .finally(() => this.setState({ fetching: false })) + .finally(() => this.setState({fetching: false})) }; handleChdir = (name, action) => { let pwd = this.state.pwd.map(x => x); if (action === '1') { pwd.push(name) - this.setState({ inputPath: null }) + this.setState({inputPath: null}) } else if (action === '2') { const index = pwd.indexOf(name); - pwd = pwd.splice(0, index + 1); + pwd = pwd.splice(0, index + 1) } else { - pwd = []; + pwd = [] } - this.fetchFiles(pwd); + this.fetchFiles(pwd) }; handleInputEnter = () => { if (this.state.inputPath === null) { if (this.state.pwd.length > 0) { - this.setState({ inputPath: `/${this.state.pwd.join("/")}/` }); + this.setState({inputPath: `/${this.state.pwd.join('/')}/`}) } else { - this.setState({ inputPath: "/" }); + this.setState({inputPath: '/'}) } - setTimeout(() => this.input2.focus(), 100); + setTimeout(() => this.input2.focus(), 100) } else { - let pwdStr = this.state.inputPath.replace(/^\/+/, ""); - pwdStr = pwdStr.replace(/\/+$/, ""); - this.fetchFiles(pwdStr.split("/")).then(() => - this.setState({ inputPath: null }) - ); + let pwdStr = this.state.inputPath.replace(/^\/+/, '') + pwdStr = pwdStr.replace(/\/+$/, '') + this.fetchFiles(pwdStr.split('/')) + .then(() => this.setState({inputPath: null})) } - }; + } handleUpload = () => { this.input.click(); - this.input.onchange = (e) => { - this.setState({ uploading: true, uploadStatus: "active", percent: 0 }); - const file = e.target["files"][0]; + this.input.onchange = e => { + this.setState({uploading: true, uploadStatus: 'active', percent: 0}); + const file = e.target['files'][0]; const formData = new FormData(); const token = uniqueId(); this._updatePercent(token); - formData.append("file", file); - formData.append("id", this.props.id); - formData.append("token", token); - formData.append("path", "/" + this.state.pwd.join("/")); - this.input.value = ""; - http - .post("/api/file/object/", formData, { - timeout: 600000, - onUploadProgress: this._updateLocal, - }) - .then( - () => { - this.setState({ uploadStatus: "success" }); - this.fetchFiles(); - }, - () => this.setState({ uploadStatus: "exception" }) - ) - .finally(() => - setTimeout(() => this.setState({ uploading: false }), 2000) - ); - }; + formData.append('file', file); + formData.append('id', this.props.id); + formData.append('token', token); + formData.append('path', '/' + this.state.pwd.join('/')); + this.input.value = ''; + http.post('/api/file/object/', formData, {timeout: 600000, onUploadProgress: this._updateLocal}) + .then(() => { + this.setState({uploadStatus: 'success'}); + this.fetchFiles() + }, () => this.setState({uploadStatus: 'exception'})) + .finally(() => setTimeout(() => this.setState({uploading: false}), 2000)) + } }; _updateLocal = (e) => { - const percent = ((e.loaded / e.total) * 100) / 2; - this.setState({ percent: Number(percent.toFixed(1)) }); - }; + const percent = e.loaded / e.total * 100 / 2 + this.setState({percent: Number(percent.toFixed(1))}) + } - _updatePercent = (token) => { - const protocol = window.location.protocol === "https:" ? "wss:" : "ws:"; - this.socket = new WebSocket( - `${protocol}//${window.location.host}/api/ws/subscribe/${token}/?x-token=${X_TOKEN}` - ); - this.socket.onopen = () => this.socket.send("ok"); - this.socket.onmessage = (e) => { - if (e.data === "pong") { - this.socket.send("ping"); + _updatePercent = token => { + const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'; + this.socket = new WebSocket(`${protocol}//${window.location.host}/api/ws/subscribe/${token}/?x-token=${X_TOKEN}`); + this.socket.onopen = () => this.socket.send('ok'); + this.socket.onmessage = e => { + if (e.data === 'pong') { + this.socket.send('ping') } else { const percent = this.state.percent + Number(e.data) / 2; - if (percent > this.state.percent) - this.setState({ percent: Number(percent.toFixed(1)) }); + if (percent > this.state.percent) this.setState({percent: Number(percent.toFixed(1))}); if (percent === 100) { - this.socket.close(); + this.socket.close() } } - }; + } }; handleDownload = (name) => { - const file = `/${this.state.pwd.join("/")}/${name}`; - const link = document.createElement("a"); + const file = `/${this.state.pwd.join('/')}/${name}`; + const link = document.createElement('a'); link.download = name; link.href = `/api/file/object/?id=${this.props.id}&file=${file}&x-token=${X_TOKEN}`; document.body.appendChild(link); link.click(); document.body.removeChild(link); - message.warning("即将开始下载,请勿重复点击。"); + message.warning('即将开始下载,请勿重复点击。') }; handleDelete = (name) => { - const file = `/${this.state.pwd.join("/")}/${name}`; + const file = `/${this.state.pwd.join('/')}/${name}`; Modal.confirm({ - title: "删除文件确认", + title: '删除文件确认', content: `确认删除文件:${file} ?`, onOk: () => { - return http - .delete("/api/file/object/", { params: { id: this.props.id, file } }) + return http.delete('/api/file/object/', {params: {id: this.props.id, file}}) .then(() => { - message.success("删除成功"); - this.fetchFiles(); - }); - }, - }); + message.success('删除成功'); + this.fetchFiles() + }) + } + }) }; render() { let objects = this.state.objects; if (!this.state.showDot) { - objects = objects.filter((x) => !x.name.startsWith(".")); + objects = objects.filter(x => !x.name.startsWith('.')) } const scrollY = document.body.clientHeight - 168; return ( - (this.input = ref)} - /> + this.input = ref}/>
{this.state.inputPath !== null ? ( - (this.input2 = ref)} - size="small" - className={styles.input} - suffix={ -
回车确认
- } - value={this.state.inputPath} - onChange={(e) => this.setState({ inputPath: e.target.value })} - onBlur={this.handleInputEnter} - onPressEnter={this.handleInputEnter} - /> + this.input2 = ref} size="small" className={styles.input} + suffix={
回车确认
} + value={this.state.inputPath} onChange={e => this.setState({inputPath: e.target.value})} + onBlur={this.handleInputEnter} + onPressEnter={this.handleInputEnter}/> ) : ( - this.handleChdir("", "0")} - > - + this.handleChdir('', '0')}> + - {this.state.pwd.map((item) => ( - this.handleChdir(item, "2")} - > + {this.state.pwd.map(item => ( + this.handleChdir(item, '2')}> {item} ))} - + )} @@ -288,26 +256,18 @@ class FileManager extends React.Component { checked={this.state.showDot} checkedChildren="开启" unCheckedChildren="关闭" - onChange={(v) => this.setState({ showDot: v })} - /> + onChange={v => this.setState({showDot: v})}/> {this.state.uploading ? ( - + ) : ( } - onClick={this.handleUpload} - > - 上传文件 - + icon={} + onClick={this.handleUpload}>上传文件 )}
@@ -317,16 +277,12 @@ class FileManager extends React.Component { loading={this.state.fetching} pagination={false} columns={this.columns} - scroll={{ y: scrollY }} - style={{ - fontFamily: - "Source Code Pro, Courier New, Courier, Monaco, monospace, PingFang SC, Microsoft YaHei", - }} - dataSource={objects} - /> + scroll={{y: scrollY}} + style={{fontFamily: 'Source Code Pro, Courier New, Courier, Monaco, monospace, PingFang SC, Microsoft YaHei'}} + dataSource={objects}/> - ); + ) } } -export default FileManager; +export default FileManager \ No newline at end of file From 206bbcbc126ab5ceb0b3db2b575902587e5db0c8 Mon Sep 17 00:00:00 2001 From: yombo Date: Thu, 2 Mar 2023 11:20:38 +0800 Subject: [PATCH 4/4] =?UTF-8?q?fix:=20=E8=A7=92=E8=89=B2=E8=83=BD=E7=9C=8B?= =?UTF-8?q?=E5=88=B0=E6=9C=AA=E6=8E=88=E6=9D=83=E9=A1=B9=E7=9B=AE=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spug_api/apps/repository/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spug_api/apps/repository/views.py b/spug_api/apps/repository/views.py index 2b20186..292e14a 100644 --- a/spug_api/apps/repository/views.py +++ b/spug_api/apps/repository/views.py @@ -17,11 +17,12 @@ import json class RepositoryView(View): @auth('deploy.repository.view|deploy.request.add|deploy.request.edit') def get(self, request): + apps = request.user.deploy_perms['apps'] deploy_id = request.GET.get('deploy_id') data = Repository.objects.annotate( app_name=F('app__name'), env_name=F('env__name'), - created_by_user=F('created_by__nickname')) + created_by_user=F('created_by__nickname')).filter(deploy_id__in=apps) if deploy_id: data = data.filter(deploy_id=deploy_id, status='5') return json_response([x.to_view() for x in data])