moremind commented on code in PR #403: URL: https://github.com/apache/shenyu-dashboard/pull/403#discussion_r1522418819
########## src/utils/download.js: ########## @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import fetch from 'dva/fetch' + +/** + * Requests a URL, for downloading. + * + * @param {string} url The URL we want to request + * @param {object} [options] The options we want to pass to "fetch" + * @return {object} An object containing either "data" or "err" + */ +export default async function download (url, options) { + const defaultOptions = { + method: 'GET', + } + + const newOptions = { ...defaultOptions, ...options } + + // add token + let token = window.sessionStorage.getItem("token") + if (token) { + if (!newOptions.headers) { + newOptions.headers = {} + } + newOptions.headers = { ...newOptions.headers, "X-Access-Token": token } + } + try { + const response = await fetch(url, newOptions) + const disposition = response.headers.get('Content-Disposition') + const filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/ + const matches = filenameRegex.exec(disposition) + let filename = 'download' + if (matches != null && matches[1]) { + filename = matches[1].replace(/['"]/g, '') + } + + const blob = await response.blob() + + const a = document.createElement('a') + a.href = URL.createObjectURL(blob) // 使用 blob 对象创建 URL + a.download = filename // 使用后端返回的文件名 Review Comment: pls use english ########## src/routes/Home/ImportResultModal.js: ########## @@ -0,0 +1,108 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import React, { Component } from "react"; +import { Modal, Form, Tooltip } from "antd"; +import { connect } from "dva"; +import { getIntlContent } from "../../utils/IntlUtils"; + +const keyMap = { + metaImportSuccessCount: '元数据导入成功数量', + metaImportFailMessage: '元数据导入失败信息', + authImportSuccessCount: 'auth导入成功数量', + authImportFailMessage: 'auth导入失败信息', + pluginImportSuccessCount: '插件导入成功数量', + pluginImportFailMessage: '插件导入失败信息', + proxySelectorImportSuccessCount: 'proxySelector导入成功数量', + proxySelectorImportFailMessage: 'proxySelector导入失败信息', + discoveryImportSuccessCount: 'discovery导入成功数量', + discoveryImportFailMessage: 'discovery导入失败信息', + discoveryUpstreamImportSuccessCount: 'discoveryUpstream导入成功数量', + discoveryUpstreamImportFailMessage: 'discoveryUpstream导入失败信息', + dictImportSuccessCount: '字典导入成功数量', + dictImportFailMessage: '字典导入失败信息' +}; + +@connect(({ global }) => ({ + platform: global.platform +})) +class ImportResultModal extends Component { + handleSubmit = e => { + const { form, handleOk } = this.props; + e.preventDefault(); + form.validateFieldsAndScroll((err, values) => { + if (!err) { + let { file } = values; + handleOk({ file }); + } + }); + }; + + handleRes = (json, key) => { + // return data; + const data = json[key]; + const maxLength = 50; // 设置最大显示长度 Review Comment: use English -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
