Skip to content

Commit 7cea566

Browse files
committed
Merge branch 'develop'
* develop: 1.0.13 feat: use utils from ntks/toolbox instead Fix issue's URL
2 parents e396e19 + 1c8c42f commit 7cea566

File tree

32 files changed

+181
-1042
lines changed

32 files changed

+181
-1042
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ Handie 的目标不是统一技术栈,更不是统一界面风格,而是—
2525

2626
## 怎么反馈问题
2727

28-
如果你有问题要反馈或什么好的建议,可以提交 [issue](https://github.com/anti-chaos/handie/issues) 或钉钉联系[欧雷](dingtalk://dingtalkclient/action/sendmsg?dingtalk_id=ourairyu)
28+
如果你有问题要反馈或什么好的建议,可以提交 [issue](https://github.com/ourai/handie/issues) 或钉钉联系[欧雷](dingtalk://dingtalkclient/action/sendmsg?dingtalk_id=ourairyu)

package-lock.json

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "handie",
3-
"version": "1.0.12",
3+
"version": "1.0.13",
44
"description": "为前端开发提供统一的布局、组件和工具方法",
55
"main": "handie.esm.js",
66
"typings": "typings/index.d.ts",
@@ -29,6 +29,9 @@
2929
"release": "cd dist && npm publish",
3030
"start": "rollup -c rollup.config.ts -w"
3131
},
32+
"dependencies": {
33+
"@ntks/toolbox": "0.0.3"
34+
},
3235
"devDependencies": {
3336
"@types/jquery": "^3.3.29",
3437
"@types/lodash": "^4.14.149",
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
1-
import { isFunction } from '../../../utils/is/type';
2-
import { mixin } from '../../../utils/collection';
3-
import { retrieveData } from '../../../utils/storage/helper';
1+
import { isFunction, mixin, retrieveData } from '@ntks/toolbox';
42

53
/**
64
* 调用钉钉 API
75
*
86
* @param {*} ref API 引用
97
* @param {*} opts 配置项
108
*/
11-
export function invokeDingTalkApi( ref: string, opts?: any ): any {
9+
export function invokeDingTalkApi(ref: string, opts?: any): any {
1210
// const handler = retrieveData(dd, ref);
13-
1411
// if ( !isFunction(handler) ) {
1512
// return;
1613
// }
17-
1814
// return handler(mixin({onFail: ( ...args: any[] ) => console.log(...args)}, opts));
1915
}
Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,94 @@
1-
import { isFunction, isPlainObject } from '../../../utils/is/type';
2-
import { map, mixin } from '../../../utils/collection';
1+
import { isFunction, isPlainObject, map, mixin } from '@ntks/toolbox';
32
import { invokeDingTalkApi } from './helper';
43

54
/**
65
* 调用通知类 API
7-
*
6+
*
87
* @param {*} shortcut API 简写
98
* @param {*} opts 配置项
109
*/
11-
function invokeNotificationApi( shortcut: string, opts: any ): void {
10+
function invokeNotificationApi(shortcut: string, opts: any): void {
1211
return invokeDingTalkApi(`device.notification.${shortcut}`, opts);
1312
}
1413

1514
export default {
16-
alert( message: any, callback: Function = function() {} ): void {
17-
invokeNotificationApi('alert', mixin({
18-
title: '',
19-
buttonName: '知道了',
20-
onSuccess: callback
21-
}, isPlainObject(message) ? message : {message}));
15+
alert(message: any, callback: Function = function () {}): void {
16+
invokeNotificationApi(
17+
'alert',
18+
mixin(
19+
{
20+
title: '',
21+
buttonName: '知道了',
22+
onSuccess: callback,
23+
},
24+
isPlainObject(message) ? message : { message },
25+
),
26+
);
2227
},
23-
confirm( message: any, agreed: Function = function() {}, cancelled: Function = function() {} ): void {
24-
invokeNotificationApi('confirm', mixin({
25-
title: '',
26-
buttonLabels: ['确定', '取消'],
27-
onSuccess: ( result: any ) => result.buttonIndex === 0 ? agreed() : cancelled()
28-
}, isPlainObject(message) ? message : {message}));
28+
confirm(message: any, agreed: Function = function () {}, cancelled: Function = function () {}): void {
29+
invokeNotificationApi(
30+
'confirm',
31+
mixin(
32+
{
33+
title: '',
34+
buttonLabels: ['确定', '取消'],
35+
onSuccess: (result: any) => (result.buttonIndex === 0 ? agreed() : cancelled()),
36+
},
37+
isPlainObject(message) ? message : { message },
38+
),
39+
);
2940
},
3041
// prompt() {},
31-
toast( opts: any ): void {
42+
toast(opts: any): void {
3243
const { text, icon, duration, callback: onSuccess } = opts;
3344

3445
invokeNotificationApi('toast', {
3546
text,
3647
icon: icon === 'fail' ? 'error' : icon,
3748
duration,
3849
delay: 0,
39-
onSuccess
50+
onSuccess,
4051
});
4152
},
4253
loading: {
43-
show( opts: any ): void {
54+
show(opts: any): void {
4455
const { text, callback: onSuccess } = opts;
4556

4657
invokeNotificationApi('showPreloader', {
4758
text,
4859
showIcon: true,
49-
onSuccess
60+
onSuccess,
5061
});
5162
},
52-
hide( callback: Function ): void {
53-
invokeNotificationApi('hidePreloader', {onSuccess: callback});
54-
}
63+
hide(callback: Function): void {
64+
invokeNotificationApi('hidePreloader', { onSuccess: callback });
65+
},
5566
},
56-
actionSheet( opts: any ): void {
67+
actionSheet(opts: any): void {
5768
const { title, cancel, actions } = opts;
5869

5970
invokeNotificationApi('actionSheet', {
6071
title,
6172
cancelButton: cancel.text,
62-
otherButtons: map(actions, ( action: any ) => action.text),
63-
onSuccess: ( result: any ) => {
73+
otherButtons: map(actions, (action: any) => action.text),
74+
onSuccess: (result: any) => {
6475
const { buttonIndex: idx } = result;
65-
76+
6677
let action, handler;
67-
68-
if ( idx === -1 ) {
78+
79+
if (idx === -1) {
6980
handler = cancel.handler;
70-
}
71-
else {
81+
} else {
7282
action = actions[idx];
7383
handler = action.handler;
7484
}
75-
76-
if ( !isFunction(handler) ) {
85+
86+
if (!isFunction(handler)) {
7787
handler = opts.handler;
7888
}
79-
89+
8090
return action ? handler(action) : handler();
81-
}
91+
},
8292
});
83-
}
84-
}
93+
},
94+
};
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { isNumeric } from '../../../utils/is/type';
1+
import { isNumeric } from '@ntks/toolbox';
22
import { invokeDingTalkApi } from './helper';
33

44
export default {
5-
image( opts: any ): void {
5+
image(opts: any): void {
66
const { urls = [], current = 0 } = opts;
77

88
invokeDingTalkApi('biz.util.previewImage', {
99
urls,
10-
current: isNumeric(current) ? urls[current * 1] : current
10+
current: isNumeric(current) ? urls[current * 1] : current,
1111
});
12-
}
13-
}
12+
},
13+
};

src/adapters/bridge/helper.ts

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
1-
import { isBoolean, isString, isFunction, isPlainObject } from '../../utils/is/type';
2-
import { each, keys } from '../../utils/collection';
3-
import { getDefaults, setPrivate, getPrivate } from '../../utils/storage/helper';
1+
import {
2+
isBoolean,
3+
isString,
4+
isFunction,
5+
isPlainObject,
6+
each,
7+
keys,
8+
getDefaults,
9+
setPrivate,
10+
getPrivate,
11+
} from '@ntks/toolbox';
412

513
/**
614
* 是否优先使用 native 组件
715
*
816
* @param {*} opts 包含抉择的配置项
917
*/
10-
export function isNativeFlavor( opts: any ): boolean {
11-
return isBoolean(opts) ? opts :
12-
isPlainObject(opts) && isBoolean(opts.native) ? opts.native :
13-
getDefaults('behavior') === 'native';
18+
export function isNativeFlavor(opts: any): boolean {
19+
return isBoolean(opts)
20+
? opts
21+
: isPlainObject(opts) && isBoolean(opts.native)
22+
? opts.native
23+
: getDefaults('behavior') === 'native';
1424
}
1525

1626
/**
@@ -19,7 +29,7 @@ export function isNativeFlavor( opts: any ): boolean {
1929
* @param {*} flag 标识符
2030
* @param {*} apis API
2131
*/
22-
export function setBridge( flag: string, apis: any ): any {
32+
export function setBridge(flag: string, apis: any): any {
2333
return setPrivate(`bridge.${flag}`, apis);
2434
}
2535

@@ -29,7 +39,7 @@ export function setBridge( flag: string, apis: any ): any {
2939
* @param {*} flag 标识符
3040
* @param {*} ref API 引用
3141
*/
32-
export function getBridge( flag: string, ref: string ): any {
42+
export function getBridge(flag: string, ref: string): any {
3343
return getPrivate(`bridge.${flag}.${ref}`);
3444
}
3545

@@ -39,26 +49,26 @@ export function getBridge( flag: string, ref: string ): any {
3949
* @param {*} ref API 引用
4050
* @param {*} isNativeFirst 是否 native 优先
4151
*/
42-
export function resolveBridge( ref: string, isNativeFirst: boolean ): any {
43-
if ( !isString(ref) ) {
52+
export function resolveBridge(ref: string, isNativeFirst: boolean): any {
53+
if (!isString(ref)) {
4454
return;
4555
}
4656

4757
let handler;
4858

49-
if ( isNativeFirst ) {
59+
if (isNativeFirst) {
5060
const envs = getPrivate('env');
5161

52-
each(keys(getPrivate('bridge')), ( k: string ) => {
53-
if ( k !== 'fallback' && envs[k] === true ) {
62+
each(keys(getPrivate('bridge')), (k: string) => {
63+
if (k !== 'fallback' && envs[k] === true) {
5464
handler = getBridge(k, ref);
5565

5666
return false;
5767
}
5868
});
5969
}
6070

61-
if ( !isFunction(handler) ) {
71+
if (!isFunction(handler)) {
6272
handler = getBridge('fallback', ref);
6373
}
6474

src/adapters/bridge/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isFunction } from '../../utils/is/type';
1+
import { isFunction } from '@ntks/toolbox';
22
import { isNativeFlavor, resolveBridge } from './helper';
33

44
/**
@@ -8,10 +8,10 @@ import { isNativeFlavor, resolveBridge } from './helper';
88
* @param {*} opts 处理函数的首个参数
99
* @param {*} rest 处理函数的其余参数
1010
*/
11-
export function invoke( ref: string, opts: any, ...rest: any[] ): any {
11+
export function invoke(ref: string, opts: any, ...rest: any[]): any {
1212
const handler = resolveBridge(ref, isNativeFlavor(opts));
1313

14-
if ( !isFunction(handler) ) {
14+
if (!isFunction(handler)) {
1515
return false;
1616
}
1717

src/adapters/flexible/index.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { mixin } from '../../utils/collection';
1+
import { mixin } from '@ntks/toolbox';
22

33
const DEFAULT_FONT_BASELINE = 14;
4-
const DEFAULT_DRAFT_BASELINE = 375; // iPhone 6/7
4+
const DEFAULT_DRAFT_BASELINE = 375; // iPhone 6/7
55

66
let flexibleAdaptorTimer: number;
77

@@ -11,15 +11,15 @@ let flexibleAdaptorTimer: number;
1111
* @param {*} fontBaseline 字体大小基准值
1212
* @param {*} draftBaseline 设计稿宽度基准值
1313
*/
14-
function setFontSize( fontBaseline: number, draftBaseline: number ): void {
14+
function setFontSize(fontBaseline: number, draftBaseline: number): void {
1515
const rootEl = document.documentElement;
1616
const width = rootEl.clientWidth;
1717

18-
if ( !width ) {
18+
if (!width) {
1919
return;
2020
}
2121

22-
rootEl.style.fontSize = `${fontBaseline * width / draftBaseline}px`;
22+
rootEl.style.fontSize = `${(fontBaseline * width) / draftBaseline}px`;
2323
}
2424

2525
/**
@@ -28,7 +28,7 @@ function setFontSize( fontBaseline: number, draftBaseline: number ): void {
2828
* @param {*} name 事件名称
2929
* @param {*} handler 事件处理函数
3030
*/
31-
function bindWindowEvent( name: string, handler: any ): void {
31+
function bindWindowEvent(name: string, handler: any): void {
3232
window.addEventListener(name, handler, false);
3333
}
3434

@@ -38,19 +38,19 @@ function bindWindowEvent( name: string, handler: any ): void {
3838
* @param {*} handler 处理函数
3939
* @param {*} timeout 延时时间
4040
*/
41-
function setFlexibleAdaptorTimer( handler: Function, timeout: number = 300 ): void {
41+
function setFlexibleAdaptorTimer(handler: Function, timeout: number = 300): void {
4242
clearTimeout(flexibleAdaptorTimer);
4343

4444
flexibleAdaptorTimer = setTimeout(handler, timeout);
4545
}
4646

47-
export default function( opts: any ) {
48-
opts = mixin({font: DEFAULT_FONT_BASELINE, draft: DEFAULT_DRAFT_BASELINE}, opts);
47+
export default function (opts: any) {
48+
opts = mixin({ font: DEFAULT_FONT_BASELINE, draft: DEFAULT_DRAFT_BASELINE }, opts);
4949

5050
const handler = () => setFontSize(opts.font, opts.draft);
5151

5252
bindWindowEvent('resize', () => setFlexibleAdaptorTimer(handler));
53-
bindWindowEvent('pageshow', ( evt: any ) => evt.persisted && setFlexibleAdaptorTimer(handler));
53+
bindWindowEvent('pageshow', (evt: any) => evt.persisted && setFlexibleAdaptorTimer(handler));
5454

5555
handler();
5656
}

0 commit comments

Comments
 (0)