Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.0.0 #1241

Merged
merged 734 commits into from
Oct 22, 2020
Merged

3.0.0 #1241

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
734 commits
Select commit Hold shift + click to select a range
e9becfd
fix: tabs
Sep 9, 2020
b69f087
fix: tabs
Sep 9, 2020
302292d
fix: rate
Sep 9, 2020
07bff04
fix: form
Sep 9, 2020
5b078b2
refactor: update notification color
solarjoker Sep 9, 2020
16d29b7
Merge branch 'next-generation' of https://github.com/XiaoMi/hiui into…
solarjoker Sep 9, 2020
886919e
补充校正 TS 定义类型
Sep 9, 2020
cf6734c
Merge branch 'next-generation' into feature/ts
Sep 9, 2020
9ce89dd
refactor: update tree color
solarjoker Sep 9, 2020
a7718f7
Merge pull request #1170 from XiaoMi/feature/ts
zhan8863 Sep 9, 2020
f3e67e7
补充新增组件导出
Sep 9, 2020
24f8df2
Merge branch 'next-generation' into feature/ts
Sep 9, 2020
ea97984
Merge pull request #1171 from XiaoMi/feature/ts
zhan8863 Sep 9, 2020
07e0f47
refactor: update tag color
solarjoker Sep 9, 2020
39cfbf3
refactor: update breadcrumb color
solarjoker Sep 9, 2020
d9e187a
fix: form table className
Sep 11, 2020
ade9456
fix: form table className
Sep 11, 2020
e1ba2fb
feat: upgrade docs
Sep 11, 2020
e8040e9
chore: remove useless code
solarjoker Sep 13, 2020
8638504
fix: upload preview bug
solarjoker Sep 13, 2020
5dedc6b
docs: update docs
solarjoker Sep 13, 2020
6b970cb
fix: gulp json
Sep 14, 2020
c22065e
fix: form
Sep 14, 2020
6941066
fix: popper
Sep 14, 2020
a69fd74
fix: table form
Sep 14, 2020
2839620
fix: upload docs
Sep 15, 2020
8ef1386
docs: update loading
solarjoker Sep 15, 2020
cbe4c61
fix: #upload docs
Sep 16, 2020
db5a023
Merge branch 'next-generation' of https://github.com/XiaoMi/hiui into…
Sep 16, 2020
bc6153f
fix: js-cookie --save
Sep 16, 2020
9528603
fix: BasePicker
Sep 16, 2020
5b66114
fix: BasePicker
Sep 16, 2020
b16071f
feat: add eslint
solarjoker Sep 16, 2020
283746a
Merge branch 'next-generation' of https://github.com/XiaoMi/hiui into…
solarjoker Sep 16, 2020
25a353d
fix: handle icon legacy
solarjoker Sep 16, 2020
5eda31e
refactor: update modal
solarjoker Sep 16, 2020
a7ab125
refactor: finish card
solarjoker Sep 17, 2020
2a7077b
fix: select params问题
Sep 17, 2020
03f1055
fix: select params
Sep 17, 2020
4582a1c
refactor: optimize modal
solarjoker Sep 17, 2020
ac31e95
fix: popover
Sep 18, 2020
82de2c4
Merge branch 'next-generation' of https://github.com/XiaoMi/hiui into…
Sep 18, 2020
81e6c19
fix: popover
Sep 18, 2020
7125955
fix: popover
Sep 18, 2020
d58b487
fix: datepicker
Sep 18, 2020
4b237e2
fix: onSave onBeforeSave
solarjoker Sep 21, 2020
ba9b752
feat: select single
Sep 21, 2020
eb818cd
feat: select single
Sep 21, 2020
a7eb817
feat: select single
Sep 21, 2020
8be69b5
feat: request
Sep 21, 2020
edb7877
fix: input
Sep 22, 2020
6e36787
fix: input
Sep 22, 2020
3be1a87
refactor: update modal
solarjoker Sep 22, 2020
abc31ee
docs: update icon
solarjoker Sep 22, 2020
c9bb39c
docs: update tree
solarjoker Sep 22, 2020
05fb620
fix: card select
Sep 22, 2020
6e2c537
Merge branch 'next-generation' of https://github.com/XiaoMi/hiui into…
Sep 22, 2020
0f054cb
refactor: update line tree
solarjoker Sep 22, 2020
a339309
feat: upload
Sep 23, 2020
3df31c4
feat: upload
Sep 23, 2020
be7179a
feat: form
Sep 23, 2020
0ca11e2
feat: form
Sep 23, 2020
7cc1035
refactor: update line tree
solarjoker Sep 23, 2020
e3e686a
Merge branch 'next-generation' of https://github.com/XiaoMi/hiui into…
solarjoker Sep 23, 2020
5179143
refactor: update line tree
solarjoker Sep 23, 2020
2a0e1c6
feat: form
Sep 24, 2020
a4a01fd
Merge branch 'next-generation' of https://github.com/XiaoMi/hiui into…
Sep 24, 2020
496a2e2
refactor: update line tree
solarjoker Sep 24, 2020
159acfa
refactor: update line tree
solarjoker Sep 24, 2020
5806e14
feat: message type
Sep 24, 2020
77192ec
Merge branch 'next-generation' of https://github.com/XiaoMi/hiui into…
Sep 24, 2020
c612593
feat: message type
Sep 24, 2020
fbbb4e0
feat: message type
Sep 24, 2020
4b8390c
feat: message type
Sep 24, 2020
322781d
chore: udpate pkg script
solarjoker Sep 24, 2020
84b6e77
feat: select
Sep 25, 2020
89bf18a
Merge branch 'next-generation' of https://github.com/XiaoMi/hiui into…
Sep 25, 2020
d9781a2
feat: select
Sep 25, 2020
7e6c6f2
feat: select
Sep 25, 2020
8914955
fix: modal shrink bug
solarjoker Sep 27, 2020
6f9378c
refactor: update tree line
solarjoker Sep 27, 2020
16df43b
feat: select
Sep 27, 2020
f35f342
Merge branch 'next-generation' of https://github.com/XiaoMi/hiui into…
Sep 27, 2020
03094d1
fix: upload docs
Sep 27, 2020
623e30c
docs: update icon
solarjoker Sep 27, 2020
e680bca
Merge branch 'next-generation' of https://github.com/XiaoMi/hiui into…
solarjoker Sep 27, 2020
7a1c6ce
fix: docs
Sep 27, 2020
8cbfabe
fix: date-picker
Sep 28, 2020
f5ded27
fix: date-picker
Sep 28, 2020
2754ca4
fix: date-picker
Sep 28, 2020
c39765b
fix: date-picker
Sep 28, 2020
7f3a1f0
fix: #1210
Sep 29, 2020
b05b262
fix: hirequest readme
Sep 29, 2020
d7a2779
fix: hirequest readme
Sep 29, 2020
f8784b7
fix: popper isFixed
Sep 29, 2020
42510c4
fix: card img width bug
solarjoker Sep 29, 2020
d0765ed
fix: upload
Oct 9, 2020
7592296
fix: upload
Oct 9, 2020
fc3e2bc
fix: datepicker
Oct 10, 2020
39d4910
fix: datepicker
Oct 10, 2020
6b00496
fix: input
Oct 10, 2020
16b4931
feat: code editor
Oct 10, 2020
941fc0f
feat: code editor
Oct 12, 2020
ce1c7cb
chore: update version
solarjoker Oct 12, 2020
80b2284
feat: json
Oct 12, 2020
12c6af1
feat: merge
Oct 12, 2020
5ea449b
feat: merge
Oct 12, 2020
030a03a
Merge branch 'feature/code-editor' into next-generation
Oct 12, 2020
d98a3a8
feat: code editor docs
Oct 13, 2020
8bded23
feat: code editor docs
Oct 13, 2020
fbcd12e
feat: code editor docs
Oct 13, 2020
6165ed6
fix: tree expanded bug when searchable
solarjoker Oct 13, 2020
f77a2b7
Merge branch 'next-generation' of https://github.com/XiaoMi/hiui into…
solarjoker Oct 13, 2020
78cc12d
feat: code editor docs
Oct 13, 2020
058cfc8
Merge branch 'next-generation' of https://github.com/XiaoMi/hiui into…
Oct 13, 2020
99b6967
feat: code editor docs
Oct 13, 2020
dd45770
feat: requet
Oct 14, 2020
b749272
feat: requet
Oct 14, 2020
a85d745
feat: requet
Oct 14, 2020
dd34a45
feat: requet
Oct 14, 2020
5bcf76a
refactor: udpate tree
solarjoker Oct 14, 2020
1ae70fc
Merge branch 'next-generation' of https://github.com/XiaoMi/hiui into…
solarjoker Oct 14, 2020
9cb5625
refactor: breadcrumb use css var
solarjoker Oct 14, 2020
f88c6fe
refactor: badge use css var
solarjoker Oct 14, 2020
8251ac3
refactor: alert use css var
solarjoker Oct 14, 2020
6bae808
refactor: upload use css var
solarjoker Oct 14, 2020
7b36371
refactor: carousel use css var
solarjoker Oct 14, 2020
45415ff
refactor: tree use css var
solarjoker Oct 14, 2020
e9d2052
feat: request md
Oct 15, 2020
0dbd605
Merge branch 'next-generation' of https://github.com/XiaoMi/hiui into…
Oct 15, 2020
c978fd3
refactor: collapse use css var
solarjoker Oct 15, 2020
17d82a0
Merge branch 'next-generation' of https://github.com/XiaoMi/hiui into…
solarjoker Oct 15, 2020
52e3b81
refactor: counter use css var
solarjoker Oct 15, 2020
e0549d1
refactor: update counter style
solarjoker Oct 15, 2020
86f2794
refactor: drawer use css var
solarjoker Oct 15, 2020
939bf48
refactor: tooltip use css var
solarjoker Oct 15, 2020
e3a1201
refactor: filter use css var
solarjoker Oct 15, 2020
c5058a0
chore: remove useless nav menu
solarjoker Oct 15, 2020
f13cdfc
refactor: switch use css var
solarjoker Oct 15, 2020
17fd6e7
refactor: timeline use css var
solarjoker Oct 15, 2020
09bae76
chore: remove useless panel
solarjoker Oct 15, 2020
6a413e4
refactor: slider use css var
solarjoker Oct 15, 2020
6484700
refactor: modal use css var
solarjoker Oct 15, 2020
a675484
refactor: message use css var
solarjoker Oct 15, 2020
875cf55
refactor: notification use css var
solarjoker Oct 15, 2020
3b85fb6
modify: 文档中事件单独分离
Oct 15, 2020
387ee30
refactor: stepper use css var
solarjoker Oct 15, 2020
49ab3ff
refactor: popover use css var
solarjoker Oct 15, 2020
a38d1c5
fex: tree doc
Oct 15, 2020
27f25ff
Merge pull request #1216 from XiaoMi/feature/callback-check
zhan8863 Oct 15, 2020
b80d91f
feat: upload docs
Oct 15, 2020
4a27720
Merge branch 'next-generation' of https://github.com/XiaoMi/hiui into…
Oct 15, 2020
55c5433
refactor: list use css var
solarjoker Oct 15, 2020
7408590
Merge branch 'next-generation' of https://github.com/XiaoMi/hiui into…
solarjoker Oct 15, 2020
4c2a754
refactor: progress use css var
solarjoker Oct 15, 2020
00923cf
refactor: tabs use css var
solarjoker Oct 15, 2020
8ba79f7
refactor: dropdown use css var
solarjoker Oct 15, 2020
3fe665c
refactor: form use css var
solarjoker Oct 15, 2020
886c0fe
refactor: transfer use css var
solarjoker Oct 16, 2020
0f1b090
refactor: transfer use css var
solarjoker Oct 16, 2020
cec5bf2
refactor: upload use css var
solarjoker Oct 16, 2020
8472234
refactor: tag use css var
solarjoker Oct 16, 2020
3d276b8
refactor: select-tree use css var
solarjoker Oct 16, 2020
4fc5892
refactor: search use css var
solarjoker Oct 16, 2020
bbfe8a4
refactor: select use css var
solarjoker Oct 16, 2020
dfcece5
refactor: date-picker use css var
solarjoker Oct 16, 2020
c38de21
refactor: dropdown use css var
solarjoker Oct 16, 2020
0a5c0a4
refactor: input use css var
solarjoker Oct 16, 2020
3948301
refactor: radio use css var
solarjoker Oct 16, 2020
c0ba550
refactor: menu use css var
solarjoker Oct 16, 2020
f8d0480
refactor: rich text editor use css var
solarjoker Oct 16, 2020
9db255d
refactor: notice use css var
solarjoker Oct 16, 2020
946793f
refactor: pagination use css var
solarjoker Oct 16, 2020
0ea64ae
style: selectTree
Oct 17, 2020
4027373
refactor: hi request remade
Oct 19, 2020
705d265
Merge branch 'next-generation' of https://github.com/XiaoMi/hiui into…
Oct 19, 2020
a869721
refactor: button use css var
solarjoker Oct 19, 2020
420b232
Merge branch 'next-generation' of https://github.com/XiaoMi/hiui into…
solarjoker Oct 19, 2020
7845a65
refactor: migrate from hi-table
solarjoker Oct 19, 2020
ea1f7bc
refactor: table use css var
solarjoker Oct 19, 2020
945ab5a
fix: table class name
solarjoker Oct 19, 2020
feb84dd
feat: add icon
solarjoker Oct 19, 2020
ad52b9f
chore: update version
solarjoker Oct 19, 2020
2ca0ef3
docs: update message doc
solarjoker Oct 19, 2020
f95e7d4
feat: hi-request
Oct 19, 2020
eb11b6a
Merge branch 'next-generation' of https://github.com/XiaoMi/hiui into…
Oct 19, 2020
dd8b640
feat: hi-request
Oct 19, 2020
ecb37db
fix: hi-request docs
Oct 19, 2020
76ab384
refactor: slider adapt theme
solarjoker Oct 19, 2020
95b25b8
Merge branch 'next-generation' of https://github.com/XiaoMi/hiui into…
solarjoker Oct 19, 2020
943163f
refactor: filter adapt theme
solarjoker Oct 19, 2020
364349e
refactor: switch adapt theme
solarjoker Oct 19, 2020
6a0158e
refactor: notification adapt theme
solarjoker Oct 20, 2020
cc1cd2a
refactor: upload adapt theme
solarjoker Oct 20, 2020
751334d
refactor: tree adapt theme
solarjoker Oct 20, 2020
2b64594
refactor: adapt theme
solarjoker Oct 20, 2020
96de55f
refactor: select-tree adapt theme
solarjoker Oct 20, 2020
ac221e1
refactor: datePicker i18n format
Oct 20, 2020
cb09824
Merge branch 'next-generation' of https://github.com/XiaoMi/hiui into…
Oct 20, 2020
f4b52e2
refactor: table adapt theme
solarjoker Oct 20, 2020
4d5d3c4
Merge branch 'next-generation' of https://github.com/XiaoMi/hiui into…
solarjoker Oct 20, 2020
9b0a8d8
refactor: modal i18n
Oct 20, 2020
a07ff9a
Merge branch 'next-generation' of https://github.com/XiaoMi/hiui into…
Oct 20, 2020
ded60a5
refactor: remove js-cookie
Oct 20, 2020
0b5acc3
refactor: remove js-cookie
Oct 20, 2020
f1a5177
refactor: selectTree i18n
Oct 21, 2020
ad07dd7
refactor: transfer i18n
Oct 21, 2020
866b751
docs: update 3.0 changelog
solarjoker Oct 21, 2020
924a883
Merge branch 'next-generation' of https://github.com/XiaoMi/hiui into…
solarjoker Oct 21, 2020
bc39a7b
refactor: transfer i18n
Oct 21, 2020
c970b7f
Merge branch 'next-generation' of https://github.com/XiaoMi/hiui into…
Oct 21, 2020
9df3ba5
docs: update switch doc
solarjoker Oct 21, 2020
4922b07
Merge branch 'next-generation' of https://github.com/XiaoMi/hiui into…
solarjoker Oct 21, 2020
6d008c9
refactor: tree i18n
Oct 21, 2020
32aa398
Merge branch 'next-generation' of https://github.com/XiaoMi/hiui into…
Oct 21, 2020
a4b59da
refactor: upload i18n
Oct 21, 2020
accae1e
fix: doc style bug
solarjoker Oct 21, 2020
1369806
Merge branch 'next-generation' of https://github.com/XiaoMi/hiui into…
solarjoker Oct 21, 2020
1c32296
refactor: watermark i18n
Oct 21, 2020
1747b59
Merge branch 'next-generation' of https://github.com/XiaoMi/hiui into…
Oct 21, 2020
8006265
chore: update changelog
solarjoker Oct 21, 2020
4f71185
Merge branch 'next-generation' of https://github.com/XiaoMi/hiui into…
solarjoker Oct 21, 2020
bcc4264
feat: legacy tree
Oct 21, 2020
3bba205
Merge branch 'next-generation' of https://github.com/XiaoMi/hiui into…
Oct 21, 2020
99d4d04
feat: switch tree
Oct 21, 2020
baa5e73
docs: update palette
solarjoker Oct 21, 2020
35a52da
Merge branch 'next-generation' of https://github.com/XiaoMi/hiui into…
solarjoker Oct 21, 2020
a5734b8
feat: add form changelog
Oct 21, 2020
6f189d7
Merge branch 'next-generation' of https://github.com/XiaoMi/hiui into…
Oct 21, 2020
ddd189f
feat: add form changelog
Oct 21, 2020
d190723
refactor: update site
solarjoker Oct 21, 2020
a85718e
refactor: update site
solarjoker Oct 21, 2020
c92a851
feat: add dropdown changelog
Oct 21, 2020
94a240c
Merge branch 'next-generation' of https://github.com/XiaoMi/hiui into…
Oct 21, 2020
aff979a
fix: upload maxSize
Oct 21, 2020
4eb86e6
chore: remove useless code
solarjoker Oct 21, 2020
418f06e
chore: remove useless code
solarjoker Oct 21, 2020
6ab80d0
fix: tag color bug
solarjoker Oct 21, 2020
7093598
docs: hide request
solarjoker Oct 21, 2020
d754b85
docs: update theme
solarjoker Oct 22, 2020
0f87ddb
Merge branch 'next-generation' of https://github.com/XiaoMi/hiui into…
solarjoker Oct 22, 2020
fe6d25b
fix: echarts rich-text-quill code-editor docs
Oct 22, 2020
23241b4
Merge branch 'next-generation' of https://github.com/XiaoMi/hiui into…
Oct 22, 2020
ab1d3cc
refactor: handle site style
solarjoker Oct 22, 2020
8f08b76
fix: datepicker
Oct 22, 2020
9e4426e
fix: datepicker
Oct 22, 2020
17fcfd9
Merge branch 'next-generation' of https://github.com/XiaoMi/hiui into…
Oct 22, 2020
1242b2b
chore: update version
solarjoker Oct 22, 2020
a2c4b9a
chore: handle conflict
solarjoker Oct 22, 2020
771ff7b
refactor: handle conflict
solarjoker Oct 22, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
21 changes: 21 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
env: {
browser: true,
es2021: true
},
extends: ['plugin:react/recommended', 'standard', 'prettier'],
parserOptions: {
ecmaFeatures: {
jsx: true
},
ecmaVersion: 12,
sourceType: 'module'
},
plugins: ['react', 'prettier'],
rules: {
'prettier/prettier': ['error', { singleQuote: true, semi: false, printWidth: 120, trailingComma: 'none' }],
'react/prop-types': 0,
'react/no-children-prop': 0,
'react/display-name': 0
}
}
701 changes: 88 additions & 613 deletions CHANGELOG.md

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions build/prerenderSite.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ const server = createSPAServer({
onCreated: renderUrls
})

async function renderUrls () {
async function renderUrls() {
renderUrlsToString({
urls: getUrls(),
onItemRendered: render,
onFinished () {
onFinished() {
server.close()
process.exit(0)
}
})
}

async function render (content, url) {
async function render(content, url) {
const dir = getRelativePathFromUrl(url).replace(baseUrl, '')
writeFile(path.join(dist, dir), content)
}
Expand All @@ -41,44 +41,44 @@ async function render (content, url) {
* get all prerender needed urls.
* @returns {string[]}
*/
function getUrls () {
function getUrls() {
const urls = [...getComponentUrls(), ...getDesignUrls(), ...getTemplateUrls(), ...getExtraUrls()]
const zh = urls.map(v => `http://localhost:${port}${baseUrl}/zh-CN/${v}`)
const en = urls.map(v => `http://localhost:${port}${baseUrl}/en-US/${v}`)
const zh = urls.map((v) => `http://localhost:${port}${baseUrl}/zh-CN/${v}`)
const en = urls.map((v) => `http://localhost:${port}${baseUrl}/en-US/${v}`)
return [...zh, ...en]
}

/**
* get components dir pages.
* @returns {string[]}
*/
function getComponentUrls () {
function getComponentUrls() {
const compPath = path.resolve(__dirname, '../docs/zh-CN/components')
return fs.readdirSync(compPath).map(v => `docs/${v.replace('.mdx', '')}`)
return fs.readdirSync(compPath).map((v) => `docs/${v.replace('.mdx', '')}`)
}

/**
* get designs dir pages.
* @returns {string[]}
*/
function getDesignUrls () {
function getDesignUrls() {
const compPath = path.resolve(__dirname, '../docs/zh-CN/designs')
return fs.readdirSync(compPath).map(v => `designs/${v.replace('.mdx', '')}`)
return fs.readdirSync(compPath).map((v) => `designs/${v.replace('.mdx', '')}`)
}

/**
* get templates dir pages.
* @returns {string[]}
*/
function getTemplateUrls () {
function getTemplateUrls() {
const tempPath = path.resolve(__dirname, '../docs/zh-CN/templates')
return fs.readdirSync(tempPath).map(v => `templates/${v.replace('.md', '')}`)
return fs.readdirSync(tempPath).map((v) => `templates/${v.replace('.md', '')}`)
}

/**
* get non-regular pages
* @returns {string[]}
*/
function getExtraUrls () {
function getExtraUrls() {
return ['', 'docs/quick-start', 'docs/template', 'docs/theme', 'docs/i18n', 'docs/changelog']
}
4 changes: 2 additions & 2 deletions components/_util/depreactedPropsCompat.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const isDevelopment = /development/gi.test(process.env.NODE_ENV)
* @param {[[string, string, Function], [string, string, Function]]} compatPair
* @returns
*/
export const depreactedPropsCompat = (compatPair) => (WrappedComponent) => {
const WrapperComponent = (props) => {
export const depreactedPropsCompat = compatPair => WrappedComponent => {
const WrapperComponent = props => {
const compatProps = { ...props }
const componentName =
WrappedComponent.displayName ||
Expand Down
54 changes: 54 additions & 0 deletions components/_util/hi-request/axios.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import axios from 'axios'

const callBackInter = new Map()

const axiosInstance = axios.create({
type: 'basics',
url: '',
responseType: 'json'
})

axiosInstance.interceptors.request.use(
(config) => {
if (callBackInter.has('beforeRequest')) {
return callBackInter.get('beforeRequest')(config)
}
return config
},
(error) => {
if (callBackInter.has('errorRequest')) {
return callBackInter.get('errorRequest')(error)
}
callBackInter.has('errorCallback') && callBackInter.get('errorCallback')(error)
return error
}
)

axiosInstance.interceptors.response.use(
(response) => {
if (callBackInter.has('beforeResponse')) {
return callBackInter.get('beforeResponse')(response)
}
return response
},
(error) => {
if (callBackInter.has('errorResponse')) {
return callBackInter.get('errorResponse')(error)
}
callBackInter.has('errorCallback') && callBackInter.get('errorCallback')(error)
return error
}
)

const axiosIns = (options) => {
const { beforeResponse, errorResponse, beforeRequest, errorRequest, data, errorCallback } = options
beforeRequest && callBackInter.set('beforeRequest', beforeRequest)
errorResponse && callBackInter.set('errorResponse', errorResponse)
beforeResponse && callBackInter.set('beforeResponse', beforeResponse)
errorRequest && callBackInter.set('errorRequest', errorRequest)
errorCallback && callBackInter.set('errorCallback', errorCallback)

return axiosInstance({ ...options })
}
export { axios }
export default axiosIns
29 changes: 29 additions & 0 deletions components/_util/hi-request/download.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import axiosIns from './axios'

const download = (options, host) => {
const { filename = '未命名' } = options
const url = host ? host + options.url : options.url

// 设置类型,防止出现乱码
Object.assign(options, { responseType: 'blob' })
axiosIns({ ...options, url }).then(
(res) => {
const { downloadSuccess } = options
const blob = new window.Blob([res.data])
const downloadElement = document.createElement('a')
const href = window.URL.createObjectURL(blob) // 创建下载的链接
downloadElement.href = href
downloadElement.download = filename // 下载后文件名
document.body.appendChild(downloadElement)
downloadElement.click() // 点击下载
document.body.removeChild(downloadElement) // 下载完成移除元素
window.URL.revokeObjectURL(href) // 释放blob对象
downloadSuccess && downloadSuccess(res)
},
(error) => {
const { downloadFail } = options
downloadFail && downloadFail(error)
}
)
}
export default download
65 changes: 65 additions & 0 deletions components/_util/hi-request/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import jsonp from './jsonp'
import download from './download'
import upload from './upload'
import axiosIns, { axios } from './axios'

/**
* 请求方法
* @param options
* @param baseUrl
*/

const InternalRequest = (options, host) => {
const { type = 'basics' } = options
const url = host ? host + options.url : options.url
if (type === 'jsonp' || type === 'download') {
return type === 'jsonp' ? jsonp : download
}
return axiosIns(
type === 'upload'
? {
url,
method: 'post',
...upload(options).options
}
: {
url,
type: 'basics',
...options
}
)
}
const HiRequest = (options, host) => {
return InternalRequest(options, host)
}
// 请求语法糖: reguest.get HiRequest.post ……
const METHODS = ['get', 'post', 'delete', 'put', 'patch', 'head', 'options']
METHODS.forEach((method) => {
HiRequest[method] = (url, options) => HiRequest({ ...options, method, url })
})
// 取消请求
const CANCEL = ['CancelToken', 'Cancel', 'isCancel']
CANCEL.forEach((type) => {
HiRequest[type] = axios[type]
})
// add jsonp
HiRequest.jsonp = jsonp
// download
HiRequest.download = download
// upload
HiRequest.upload = (options, host) => {
options.type = 'upload'
return HiRequest(options, host)
}

// Expose all/spread
HiRequest.all = (promises) => {
return Promise.all(promises)
}
HiRequest.spread = (callback) => {
return (arr) => {
return callback.apply(null, arr)
}
}

export default HiRequest
77 changes: 77 additions & 0 deletions components/_util/hi-request/jsonp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
const defaultJsonpOptions = {
timeout: 5000,
jsonpCallback: 'callback'
}

const generateCallbackFunction = () => {
return `jsonp_${Date.now()}_${Math.ceil(Math.random() * 100000)}`
}
const clearFunction = (functionName) => {
try {
delete window[functionName]
} catch (e) {
window[functionName] = undefined
}
}

const removeScript = (scriptId) => {
const script = document.getElementById(scriptId)
if (script) {
document.getElementsByTagName('head')[0].removeChild(script)
}
}
const jsonp = (_url, options = defaultJsonpOptions) => {
const { timeout, jsonpCallback } = options
let url = _url
let timeoutId
return new Promise((resolve, reject) => {
const callbackFunction =
options && options.jsonpCallbackFunction ? options.jsonpCallbackFunction : generateCallbackFunction()

const scriptId = `${jsonpCallback}_${callbackFunction}`

window[callbackFunction] = (response) => {
resolve({
ok: true,
// keep consistent with fetch API
json: () => Promise.resolve(response)
})

if (timeoutId) clearTimeout(timeoutId)

removeScript(scriptId)

clearFunction(callbackFunction)
}

url += url.indexOf('?') === -1 ? '?' : '&'

const jsonpScript = document.createElement('script')
jsonpScript.setAttribute('src', `${url}${jsonpCallback}=${callbackFunction}`)
if (options && options.charset) {
jsonpScript.setAttribute('charset', options.charset)
}
jsonpScript.id = scriptId
document.getElementsByTagName('head')[0].appendChild(jsonpScript)

timeoutId = setTimeout(() => {
reject(new Error(`JSONP request to ${_url} timed out`))

clearFunction(callbackFunction)
removeScript(scriptId)
window[callbackFunction] = () => {
clearFunction(callbackFunction)
}
}, timeout)

// Caught if got 404/500
jsonpScript.onerror = () => {
reject(new Error(`JSONP request to ${_url} failed`))

clearFunction(callbackFunction)
removeScript(scriptId)
if (timeoutId) clearTimeout(timeoutId)
}
})
}
export default jsonp
21 changes: 21 additions & 0 deletions components/_util/hi-request/upload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const upload = (options) => {
const { file, name = 'file', params = {}, headers, data } = options
const formFile = new window.FormData()
if (file) {
formFile.append(name, file)
}
// 设置除file外需要带入的参数
if (params) {
Object.keys(params).forEach((key) => {
formFile.append(key, params[key])
})
}
return {
options: Object.assign({
...options,
data: data || formFile,
headers: { ...headers, 'Content-Type': 'multipart/form-data' }
})
}
}
export default upload
2 changes: 2 additions & 0 deletions components/_util/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export * from './depreactedPropsCompat'
export { default as SwitchVersion } from './SwitchVersion'


1 change: 1 addition & 0 deletions components/_util/warning.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export function warningOnce (condition, format, args) {
warned[format] = !condition
}
}

Loading