Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
jtsky committed Sep 10, 2021
2 parents 642e7cf + 05f0330 commit 21811d8
Show file tree
Hide file tree
Showing 23 changed files with 394 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static String[] split(String str, String delimiter) {
}

/*
* Replace all occurances of the searchString in the originalString with the replaceString. Faster than the
* Replace all occurrences of the searchString in the originalString with the replaceString. Faster than the
* String.replace() method. Does not use regexes.
* <p/>
* If your searchString is empty, this will spin forever.
Expand Down
2 changes: 1 addition & 1 deletion DoraemonKit.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

Pod::Spec.new do |s|
s.name = 'DoraemonKit'
s.version = '3.0.8'
s.version = '3.1.0'
s.summary = 'iOS各式各样的工具集合'
s.description = <<-DESC
iOS各式各样的工具集合 Desc
Expand Down
2 changes: 1 addition & 1 deletion Web/lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"packages": [
"packages/*"
],
"version": "0.0.1-alpha.1",
"version": "0.0.1-alpha.4",
"npmClient": "npm",
"command": {
"bootstrap": {
Expand Down
4 changes: 2 additions & 2 deletions Web/packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dokit/web-core",
"version": "0.0.1-alpha.1",
"version": "0.0.1-alpha.4",
"description": "Dokit",
"keywords": [
"Dokit"
Expand Down Expand Up @@ -29,7 +29,7 @@
"url": "https://github.com/didi/DoraemonKit/issues"
},
"dependencies": {
"@dokit/web-utils": "^0.0.1-alpha.1"
"@dokit/web-utils": "^0.0.1-alpha.4"
},
"gitHead": "886ea7c19806526668e5da0179da335e7df9d012"
}
2 changes: 1 addition & 1 deletion Web/packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dokit/web-utils",
"version": "0.0.1-alpha.1",
"version": "0.0.1-alpha.4",
"description": "Dokit",
"keywords": [
"Dokit"
Expand Down
16 changes: 13 additions & 3 deletions Web/packages/utils/src/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,17 @@ export class Request extends EventEmitter{
const originOpen = winXhrProto.open;
const originSetRequestHeader = winXhrProto.setRequestHeader;
// XMLHttp
window.XMLHttpRequest.prototype.setRequestHeader = function(){

originSetRequestHeader.apply(this, arguments);
window.XMLHttpRequest.prototype.setRequestHeader = function(...args){
if(Req.hookXhrConfig.onBeforeSetRequestHeader) {
args = Req.hookXhrConfig.onBeforeSetRequestHeader(args, this.reqConf);
// 返回false则取消设置请求头 (api-mock拦截接口,会将post改为get 此时设置请求头Content-Type会报跨域错误)
args && originSetRequestHeader.apply(this, args);
} else {
originSetRequestHeader.apply(this, args);
}
}
window.XMLHttpRequest.prototype.open = function (...args) {
let originArgs = {...args}
args = Req.hookXhrConfig.onBeforeOpen && Req.hookXhrConfig.onBeforeOpen(args) || args
const xhr = this;
this.reqConf = {
Expand All @@ -44,6 +50,10 @@ export class Request extends EventEmitter{
requestInfo: {
method: args[0].toUpperCase(),
url: args[1]
},
originRequestInfo: {
method: originArgs[0].toUpperCase(),
url: originArgs[1]
}
}

Expand Down
6 changes: 3 additions & 3 deletions Web/packages/web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dokit/web",
"version": "0.0.1-alpha.1",
"version": "0.0.1-alpha.4",
"description": "Dokit Web Main Entry",
"keywords": [
"Dokit"
Expand Down Expand Up @@ -30,8 +30,8 @@
"dev": "npx rollup -wc"
},
"dependencies": {
"@dokit/web-core": "^0.0.1-alpha.1",
"@dokit/web-utils": "^0.0.1-alpha.1"
"@dokit/web-core": "^0.0.1-alpha.4",
"@dokit/web-utils": "^0.0.1-alpha.4"
},
"gitHead": "886ea7c19806526668e5da0179da335e7df9d012"
}
26 changes: 24 additions & 2 deletions Web/packages/web/src/plugins/api-mock/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {getGlobalData, RouterPlugin} from '@dokit/web-core'
import { getPartUrlByParam } from "@dokit/web-utils";
import { request } from './../../assets/util'

const mockBaseUrl = "https://pre.dokit.cn";
const mockBaseUrl = "https://www.dokit.cn";

const getCheckedInterfaceList = function (interfaceList) {
return interfaceList.filter(i => i.checked)
Expand Down Expand Up @@ -80,9 +80,11 @@ export default new RouterPlugin({
})
}
})
sceneId && fetchArgs[1] && (fetchArgs[1].method = 'get') && (fetchArgs[1].headers && delete fetchArgs[1].headers)
sceneId && (fetchArgs[0] = `${mockBaseUrl}/api/app/scene/${sceneId}`)
return fetchArgs;
}
},

});
request.hookXhr({
onBeforeOpen: (args) => {
Expand All @@ -99,9 +101,29 @@ export default new RouterPlugin({
})
}
})
sceneId && (args[0] = 'get')
sceneId && (args[1] = `${mockBaseUrl}/api/app/scene/${sceneId}`)
return args;
},
onBeforeSetRequestHeader: (args, config) => {
let checkedInterfaceList = getCheckedInterfaceList(state.interfaceList)
let url = config.originRequestInfo.url;
let path = `/`+getPartUrlByParam(url, 'path')
let sceneId = ''
checkedInterfaceList.forEach(i => {
if(i.path === path) {
i.sceneList.forEach(scene => {
if(scene.checked) {
sceneId = scene._id
}
})
}
})
if (sceneId) {
return false
}
return args
}
});
},
onUnload(){}
Expand Down
2 changes: 0 additions & 2 deletions Web/packages/web/src/plugins/api-mock/main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
<script>
import interfaceItem from "./interface-item";
const mockBaseUrl = "https://pre.dokit.cn";
export default {
components: {
interfaceItem,
Expand Down
14 changes: 9 additions & 5 deletions Web/playground/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,21 @@
<h1>DoKit For Web</h1>
<h2>Playground</h2>
</body>
<script src="https://unpkg.com/vue@next"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/vue/3.1.5/vue.global.js"></script>
<script src="../packages/web/dist/dokit.js"></script>
<script>
Dokit.setProductId('379cca45571436f86c31d687578541fc')
</script>
<script>
setTimeout(() => {
// fetch('https://www.tianqiapi.com/free/day?appid=68852321&appsecret=BgGLDVc7', {
// body: JSON.stringify({
// a:1
// fetch('https://www.tianqiapi.com/free/week?appid=68852321&appsecret=BgGLDVc7', {
// // body: JSON.stringify({
// // a:1
// // }),
// headers: new Headers({
// 'Content-Type': 'text/html; charset=utf-8'
// }),
// method: 'get',
// method: 'post',
// })
// .then((response) => {
// let weatherInfo = response.json();
Expand All @@ -39,6 +42,7 @@ <h2>Playground</h2>
var oReq = new XMLHttpRequest();
oReq.addEventListener("load", reqListener);
oReq.open("post", "https://www.tianqiapi.com/free/week?appid=68852321&appsecret=BgGLDVc7");
oReq.setRequestHeader('Content-Type', 'text/html; charset=utf-8')
oReq.send(JSON.stringify({
a:1
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#import <Foundation/Foundation.h>
#import "DoraemonMCMessagePackager.h"

#import "DoraemonMCEventHandler.h"
NS_ASSUME_NONNULL_BEGIN

@interface DoraemonMCCommandExcutor : NSObject
Expand All @@ -17,6 +17,10 @@ NS_ASSUME_NONNULL_BEGIN

+ (void)excuteMessage:(DoraemonMCMessage *)message;


//增加自定义事件
+ (void)addCustomMessage:(NSString *)type eventHandlerName:(DoraemonMCEventHandler *)eventHandler;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#import "DoraemonMCCommandExcutor.h"
#import "DoraemonMCEventHandler.h"

static NSMutableDictionary *eventHandlerMap = nil;
static NSMutableDictionary *externalEventHandlerMap = nil;

@implementation DoraemonMCCommandExcutor

+ (void)excuteMessageStrFromNet:(NSString *)message {
Expand All @@ -17,7 +20,6 @@ + (void)excuteMessageStrFromNet:(NSString *)message {
}

+ (void)excuteMessage:(DoraemonMCMessage *)message {
static NSDictionary *eventHandlerMap = nil ;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
DoraemonMCReuseCellEventHandler *handlerReuseCell = [DoraemonMCReuseCellEventHandler new];
Expand All @@ -29,6 +31,7 @@ + (void)excuteMessage:(DoraemonMCMessage *)message {
@(DoraemonMCMessageTypeTextInput) : [DoraemonMCTextFiledEventHandler new],
@(DoraemonMCMessageTypeTarbarSelected) : [DoraemonMCTabbarEventHandler new]
};
externalEventHandlerMap = [NSMutableDictionary new];
});

[eventHandlerMap enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull typeNumber, DoraemonMCEventHandler * _Nonnull eventHandler, BOOL * _Nonnull stop) {
Expand All @@ -38,6 +41,34 @@ + (void)excuteMessage:(DoraemonMCMessage *)message {
}
}];


[externalEventHandlerMap enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull typeString, DoraemonMCEventHandler * _Nonnull eventHandler, BOOL * _Nonnull stop) {
if ([message.customType isEqualToString:typeString]) {
[eventHandler handleEvent:message];
*stop = YES;
}
}];


}

//增加自定义事件
+ (void)addCustomMessage:(NSString *)type eventHandlerName:(DoraemonMCEventHandler *)eventHandler {
if (eventHandler && type) {

[externalEventHandlerMap enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull typeString, DoraemonMCEventHandler * _Nonnull eventHandler, BOOL * _Nonnull stop) {
if ([type isEqualToString:typeString]) {
*stop = YES;
NSAssert(stop, @"重复添加事件");
}
}];

[externalEventHandlerMap setValue:eventHandler forKey:type];
}
}





@end
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
indexPath:(NSIndexPath *)indexPath
messageType:(DoraemonMCMessageType)type;

+ (DoraemonMCMessage *)sendCustomMessageWithView:(UIView *)view
eventInfo:(NSDictionary *)eventInfo
messageType:(NSString *)type;



@end


Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,18 @@ + (void)sendMessageWithView:(UIView *)view
}

}


+ (DoraemonMCMessage *)sendCustomMessageWithView:(UIView *)view
eventInfo:(NSDictionary *)eventInfo
messageType:(NSString *)type {

DoraemonMCMessage *message = [DoraemonMCMessagePackager packageCustomMessageWithView:view
eventInfo:eventInfo
messageType:type];

[DoraemonMCServer sendMessage:message.toMessageString];
return message;
}
@end

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ NS_ASSUME_NONNULL_BEGIN

- (BOOL)handleEvent:(DoraemonMCMessage*)eventInfo;

- (UIView *)fetchTargetView;

@end

@interface DoraemonMCGestureRecognizerEventHandler : DoraemonMCEventHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ typedef NS_ENUM(NSInteger , DoraemonMCMessageType) {

// 消息类型
@property (nonatomic , assign) DoraemonMCMessageType type;

// 自定义消息类型
@property (nonatomic , assign) NSString * customType;
// 控件的xPath
@property (nonatomic , copy ) NSString *xPath;

Expand All @@ -54,6 +55,13 @@ typedef NS_ENUM(NSInteger , DoraemonMCMessageType) {
indexPath:(NSIndexPath *)indexPath
messageType:(DoraemonMCMessageType)type;

/**
自定义事件
*/
+ (DoraemonMCMessage *)packageCustomMessageWithView:(UIView *)view
eventInfo:(NSDictionary *)eventInfo
messageType:(NSString *)type;

/***
根据从网络上获取的消息字符串, 解析出消息对象
*/
Expand Down
Loading

0 comments on commit 21811d8

Please sign in to comment.