From 1c30a81ac92abd31f75b7691ee11d5ebc09d8bf6 Mon Sep 17 00:00:00 2001 From: 2betop <2betop.cn@gmail.com> Date: Fri, 20 Nov 2020 10:11:30 +0800 Subject: [PATCH 1/6] =?UTF-8?q?api.adaptor=20=E6=94=AF=E6=8C=81=E5=BC=82?= =?UTF-8?q?=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I220f4f6aab1e9de3a2ac03e9ad5bba47acda543d --- src/utils/api.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/utils/api.ts b/src/utils/api.ts index 29ffc4daa..43e9bedee 100644 --- a/src/utils/api.ts +++ b/src/utils/api.ts @@ -232,10 +232,18 @@ export function wrapAdaptor(promise: Promise, api: ApiObject) { const adaptor = api.adaptor; return adaptor ? promise - .then(response => ({ - ...response, - data: adaptor((response as any).data, response, api) - })) + .then(async response => { + let result = adaptor((response as any).data, response, api); + + if (result?.then) { + result = await result; + } + + return { + ...response, + data: result + }; + }) .then(responseAdaptor) : promise.then(responseAdaptor); } From eb4655519ce39fedb2176354c2bc949c65dfe8ff Mon Sep 17 00:00:00 2001 From: 2betop <2betop.cn@gmail.com> Date: Fri, 20 Nov 2020 10:28:42 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=88=A4=E6=96=AD,?= =?UTF-8?q?=E6=9B=B4=E5=87=86=E7=A1=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I4ed1ea9f40f6f13330e45518bea117bdddfd2e3a --- src/renderers/Form/ButtonGroup.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderers/Form/ButtonGroup.tsx b/src/renderers/Form/ButtonGroup.tsx index 49b55a20e..416a83b59 100644 --- a/src/renderers/Form/ButtonGroup.tsx +++ b/src/renderers/Form/ButtonGroup.tsx @@ -110,7 +110,7 @@ export default class ButtonGroupControl extends React.Component< } ); }); - } else if (buttons) { + } else if (Array.isArray(buttons)) { body = buttons.map((button, key) => render( `button/${key}`, From 05823dd240ee3781e7b5194940caf2a1b93e5c78 Mon Sep 17 00:00:00 2001 From: 2betop <2betop.cn@gmail.com> Date: Wed, 25 Nov 2020 11:41:52 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20City=20=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=20disabled=20=E6=97=A0=E6=95=88=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderers/Form/City.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/renderers/Form/City.tsx b/src/renderers/Form/City.tsx index 8ac2b0d8a..7298d4c58 100644 --- a/src/renderers/Form/City.tsx +++ b/src/renderers/Form/City.tsx @@ -377,6 +377,7 @@ export class CityPicker extends React.Component< onChange={this.handleStreetChange} onBlur={this.handleStreetEnd} placeholder={__('请输入街道信息')} + disabled={disabled} /> ) : null} @@ -405,7 +406,8 @@ export class LocationControl extends React.Component { allowDistrict, extractValue, joinValues, - allowStreet + allowStreet, + disabled } = this.props; return ( { extractValue={extractValue} joinValues={joinValues} allowStreet={allowStreet} + disabled={disabled} /> ); } From a7ca1e8e8a8e4cc2fb6c1f001554ab460c24ee96 Mon Sep 17 00:00:00 2001 From: wuduoyi Date: Wed, 25 Nov 2020 12:29:00 +0800 Subject: [PATCH 4/6] =?UTF-8?q?loader=20=E9=87=8C=E8=A1=A5=E4=B8=8A=20exce?= =?UTF-8?q?ljs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/loader.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/loader.ts b/examples/loader.ts index 3b98c6557..30a86ef42 100644 --- a/examples/loader.ts +++ b/examples/loader.ts @@ -11,6 +11,7 @@ const mapping: { 'react-dropzone': __moduleId('react-dropzone'), 'classnames': __moduleId('classnames'), 'axios': __moduleId('axios'), + 'exceljs': __moduleId('exceljs'), 'moment': __moduleId('moment'), 'mobx': __moduleId('mobx'), 'mobx-state-tree': __moduleId('mobx-state-tree'), From 27497f5bbfc9e8c5aa1709718207343693091af2 Mon Sep 17 00:00:00 2001 From: RickCole Date: Wed, 25 Nov 2020 14:08:03 +0800 Subject: [PATCH 5/6] fix doc (#1109) --- docs/components/form/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/components/form/index.md b/docs/components/form/index.md index ed375556d..fd12392f7 100755 --- a/docs/components/form/index.md +++ b/docs/components/form/index.md @@ -802,7 +802,7 @@ Form 支持轮训初始化接口,步骤如下: { "label": "关键字", "type": "static", - "name": "${keywords}" + "name": "keywords" }, { "label": "请求时间", From 53cd48731cc528c05a1354c909d38840a6685d89 Mon Sep 17 00:00:00 2001 From: 2betop <2betop.cn@gmail.com> Date: Thu, 26 Nov 2020 11:03:33 +0800 Subject: [PATCH 6/6] =?UTF-8?q?jssdk=20=E7=94=A8=E6=B3=95=E6=94=AF?= =?UTF-8?q?=E6=8C=81=20ajax=20=E4=B8=8B=E8=BD=BD=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/embed.tsx | 88 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 87 insertions(+), 1 deletion(-) diff --git a/examples/embed.tsx b/examples/embed.tsx index c73aa5160..3899d8552 100644 --- a/examples/embed.tsx +++ b/examples/embed.tsx @@ -35,6 +35,90 @@ export function embed( container.classList.add('amis-scope'); let scoped: any; + const attachmentAdpator = (response: any) => { + if ( + response && + response.headers && + response.headers['content-disposition'] + ) { + const disposition = response.headers['content-disposition']; + let filename = ''; + if (disposition && disposition.indexOf('attachment') !== -1) { + let filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/; + let matches = filenameRegex.exec(disposition); + if (matches != null && matches[1]) { + filename = matches[1].replace(/['"]/g, ''); + } + + // 很可能是中文被 url-encode 了 + if (filename && filename.replace(/[^%]/g, '').length > 2) { + filename = decodeURIComponent(filename); + } + + let type = response.headers['content-type']; + let blob = + response.data.toString() === '[object Blob]' + ? response.data + : new Blob([response.data], {type: type}); + if (typeof window.navigator.msSaveBlob !== 'undefined') { + // IE workaround for "HTML7007: One or more blob URLs were revoked by closing the blob for which they were created. These URLs will no longer resolve as the data backing the URL has been freed." + window.navigator.msSaveBlob(blob, filename); + } else { + let URL = window.URL || (window as any).webkitURL; + let downloadUrl = URL.createObjectURL(blob); + if (filename) { + // use HTML5 a[download] attribute to specify filename + let a = document.createElement('a'); + // safari doesn't support this yet + if (typeof a.download === 'undefined') { + (window as any).location = downloadUrl; + } else { + a.href = downloadUrl; + a.download = filename; + document.body.appendChild(a); + a.click(); + } + } else { + (window as any).location = downloadUrl; + } + setTimeout(function () { + URL.revokeObjectURL(downloadUrl); + }, 100); // cleanup + } + + return { + ...response, + data: { + status: 0, + msg: '文件即将开始下载。。' + } + }; + } + } else if (response.data.toString() === '[object Blob]') { + return new Promise((resolve, reject) => { + let reader = new FileReader(); + reader.addEventListener('loadend', e => { + const text = reader.result as string; + + try { + resolve({ + ...response, + data: { + ...JSON.parse(text) + } + }); + } catch (e) { + reject(e); + } + }); + + reader.readAsText(response.data); + }); + } + + return response; + }; + const responseAdpater = (api: any) => (value: any) => { let response = value.data; if (env && env.responseAdpater) { @@ -173,7 +257,9 @@ export function embed( } data && (config.data = data); - return axios(url, config).then(responseAdpater(api)); + return axios(url, config) + .then(attachmentAdpator) + .then(responseAdpater(api)); }, isCancel: (value: any) => (axios as any).isCancel(value), copy: (contents: string, options: any = {}) => {