Skip to content

Commit 21811d8

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 642e7cf + 05f0330 commit 21811d8

23 files changed

Lines changed: 394 additions & 52 deletions

File tree

Android/dokit/src/main/java/com/didichuxing/doraemonkit/kit/loginfo/util/StringUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static String[] split(String str, String delimiter) {
5252
}
5353

5454
/*
55-
* Replace all occurances of the searchString in the originalString with the replaceString. Faster than the
55+
* Replace all occurrences of the searchString in the originalString with the replaceString. Faster than the
5656
* String.replace() method. Does not use regexes.
5757
* <p/>
5858
* If your searchString is empty, this will spin forever.

DoraemonKit.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
Pod::Spec.new do |s|
99
s.name = 'DoraemonKit'
10-
s.version = '3.0.8'
10+
s.version = '3.1.0'
1111
s.summary = 'iOS各式各样的工具集合'
1212
s.description = <<-DESC
1313
iOS各式各样的工具集合 Desc

Web/lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"packages": [
44
"packages/*"
55
],
6-
"version": "0.0.1-alpha.1",
6+
"version": "0.0.1-alpha.4",
77
"npmClient": "npm",
88
"command": {
99
"bootstrap": {

Web/packages/core/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dokit/web-core",
3-
"version": "0.0.1-alpha.1",
3+
"version": "0.0.1-alpha.4",
44
"description": "Dokit",
55
"keywords": [
66
"Dokit"
@@ -29,7 +29,7 @@
2929
"url": "https://github.com/didi/DoraemonKit/issues"
3030
},
3131
"dependencies": {
32-
"@dokit/web-utils": "^0.0.1-alpha.1"
32+
"@dokit/web-utils": "^0.0.1-alpha.4"
3333
},
3434
"gitHead": "886ea7c19806526668e5da0179da335e7df9d012"
3535
}

Web/packages/utils/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dokit/web-utils",
3-
"version": "0.0.1-alpha.1",
3+
"version": "0.0.1-alpha.4",
44
"description": "Dokit",
55
"keywords": [
66
"Dokit"

Web/packages/utils/src/network.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,17 @@ export class Request extends EventEmitter{
3131
const originOpen = winXhrProto.open;
3232
const originSetRequestHeader = winXhrProto.setRequestHeader;
3333
// XMLHttp
34-
window.XMLHttpRequest.prototype.setRequestHeader = function(){
35-
36-
originSetRequestHeader.apply(this, arguments);
34+
window.XMLHttpRequest.prototype.setRequestHeader = function(...args){
35+
if(Req.hookXhrConfig.onBeforeSetRequestHeader) {
36+
args = Req.hookXhrConfig.onBeforeSetRequestHeader(args, this.reqConf);
37+
// 返回false则取消设置请求头 (api-mock拦截接口,会将post改为get 此时设置请求头Content-Type会报跨域错误)
38+
args && originSetRequestHeader.apply(this, args);
39+
} else {
40+
originSetRequestHeader.apply(this, args);
41+
}
3742
}
3843
window.XMLHttpRequest.prototype.open = function (...args) {
44+
let originArgs = {...args}
3945
args = Req.hookXhrConfig.onBeforeOpen && Req.hookXhrConfig.onBeforeOpen(args) || args
4046
const xhr = this;
4147
this.reqConf = {
@@ -44,6 +50,10 @@ export class Request extends EventEmitter{
4450
requestInfo: {
4551
method: args[0].toUpperCase(),
4652
url: args[1]
53+
},
54+
originRequestInfo: {
55+
method: originArgs[0].toUpperCase(),
56+
url: originArgs[1]
4757
}
4858
}
4959

Web/packages/web/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dokit/web",
3-
"version": "0.0.1-alpha.1",
3+
"version": "0.0.1-alpha.4",
44
"description": "Dokit Web Main Entry",
55
"keywords": [
66
"Dokit"
@@ -30,8 +30,8 @@
3030
"dev": "npx rollup -wc"
3131
},
3232
"dependencies": {
33-
"@dokit/web-core": "^0.0.1-alpha.1",
34-
"@dokit/web-utils": "^0.0.1-alpha.1"
33+
"@dokit/web-core": "^0.0.1-alpha.4",
34+
"@dokit/web-utils": "^0.0.1-alpha.4"
3535
},
3636
"gitHead": "886ea7c19806526668e5da0179da335e7df9d012"
3737
}

Web/packages/web/src/plugins/api-mock/index.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {getGlobalData, RouterPlugin} from '@dokit/web-core'
33
import { getPartUrlByParam } from "@dokit/web-utils";
44
import { request } from './../../assets/util'
55

6-
const mockBaseUrl = "https://pre.dokit.cn";
6+
const mockBaseUrl = "https://www.dokit.cn";
77

88
const getCheckedInterfaceList = function (interfaceList) {
99
return interfaceList.filter(i => i.checked)
@@ -80,9 +80,11 @@ export default new RouterPlugin({
8080
})
8181
}
8282
})
83+
sceneId && fetchArgs[1] && (fetchArgs[1].method = 'get') && (fetchArgs[1].headers && delete fetchArgs[1].headers)
8384
sceneId && (fetchArgs[0] = `${mockBaseUrl}/api/app/scene/${sceneId}`)
8485
return fetchArgs;
85-
}
86+
},
87+
8688
});
8789
request.hookXhr({
8890
onBeforeOpen: (args) => {
@@ -99,9 +101,29 @@ export default new RouterPlugin({
99101
})
100102
}
101103
})
104+
sceneId && (args[0] = 'get')
102105
sceneId && (args[1] = `${mockBaseUrl}/api/app/scene/${sceneId}`)
103106
return args;
104107
},
108+
onBeforeSetRequestHeader: (args, config) => {
109+
let checkedInterfaceList = getCheckedInterfaceList(state.interfaceList)
110+
let url = config.originRequestInfo.url;
111+
let path = `/`+getPartUrlByParam(url, 'path')
112+
let sceneId = ''
113+
checkedInterfaceList.forEach(i => {
114+
if(i.path === path) {
115+
i.sceneList.forEach(scene => {
116+
if(scene.checked) {
117+
sceneId = scene._id
118+
}
119+
})
120+
}
121+
})
122+
if (sceneId) {
123+
return false
124+
}
125+
return args
126+
}
105127
});
106128
},
107129
onUnload(){}

Web/packages/web/src/plugins/api-mock/main.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
<script>
1414
import interfaceItem from "./interface-item";
1515
16-
const mockBaseUrl = "https://pre.dokit.cn";
17-
1816
export default {
1917
components: {
2018
interfaceItem,

Web/playground/index.html

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,21 @@
1212
<h1>DoKit For Web</h1>
1313
<h2>Playground</h2>
1414
</body>
15-
<script src="https://unpkg.com/vue@next"></script>
15+
<script src="https://cdn.bootcdn.net/ajax/libs/vue/3.1.5/vue.global.js"></script>
1616
<script src="../packages/web/dist/dokit.js"></script>
1717
<script>
1818
Dokit.setProductId('379cca45571436f86c31d687578541fc')
1919
</script>
2020
<script>
2121
setTimeout(() => {
22-
// fetch('https://www.tianqiapi.com/free/day?appid=68852321&appsecret=BgGLDVc7', {
23-
// body: JSON.stringify({
24-
// a:1
22+
// fetch('https://www.tianqiapi.com/free/week?appid=68852321&appsecret=BgGLDVc7', {
23+
// // body: JSON.stringify({
24+
// // a:1
25+
// // }),
26+
// headers: new Headers({
27+
// 'Content-Type': 'text/html; charset=utf-8'
2528
// }),
26-
// method: 'get',
29+
// method: 'post',
2730
// })
2831
// .then((response) => {
2932
// let weatherInfo = response.json();
@@ -39,6 +42,7 @@ <h2>Playground</h2>
3942
var oReq = new XMLHttpRequest();
4043
oReq.addEventListener("load", reqListener);
4144
oReq.open("post", "https://www.tianqiapi.com/free/week?appid=68852321&appsecret=BgGLDVc7");
45+
oReq.setRequestHeader('Content-Type', 'text/html; charset=utf-8')
4246
oReq.send(JSON.stringify({
4347
a:1
4448
}));

0 commit comments

Comments
 (0)