Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  1.0.13
  feat: use utils from ntks/toolbox instead
  Fix issue's URL
  • Loading branch information
ourai committed Jun 2, 2020
2 parents e396e19 + 1c8c42f commit 7cea566
Show file tree
Hide file tree
Showing 32 changed files with 181 additions and 1,042 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ Handie 的目标不是统一技术栈,更不是统一界面风格,而是—

## 怎么反馈问题

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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "handie",
"version": "1.0.12",
"version": "1.0.13",
"description": "为前端开发提供统一的布局、组件和工具方法",
"main": "handie.esm.js",
"typings": "typings/index.d.ts",
Expand Down Expand Up @@ -29,6 +29,9 @@
"release": "cd dist && npm publish",
"start": "rollup -c rollup.config.ts -w"
},
"dependencies": {
"@ntks/toolbox": "0.0.3"
},
"devDependencies": {
"@types/jquery": "^3.3.29",
"@types/lodash": "^4.14.149",
Expand Down
8 changes: 2 additions & 6 deletions src/adapters/bridge/dingtalk/helper.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import { isFunction } from '../../../utils/is/type';
import { mixin } from '../../../utils/collection';
import { retrieveData } from '../../../utils/storage/helper';
import { isFunction, mixin, retrieveData } from '@ntks/toolbox';

/**
* 调用钉钉 API
*
* @param {*} ref API 引用
* @param {*} opts 配置项
*/
export function invokeDingTalkApi( ref: string, opts?: any ): any {
export function invokeDingTalkApi(ref: string, opts?: any): any {
// const handler = retrieveData(dd, ref);

// if ( !isFunction(handler) ) {
// return;
// }

// return handler(mixin({onFail: ( ...args: any[] ) => console.log(...args)}, opts));
}
84 changes: 47 additions & 37 deletions src/adapters/bridge/dingtalk/notification.ts
Original file line number Diff line number Diff line change
@@ -1,84 +1,94 @@
import { isFunction, isPlainObject } from '../../../utils/is/type';
import { map, mixin } from '../../../utils/collection';
import { isFunction, isPlainObject, map, mixin } from '@ntks/toolbox';
import { invokeDingTalkApi } from './helper';

/**
* 调用通知类 API
*
*
* @param {*} shortcut API 简写
* @param {*} opts 配置项
*/
function invokeNotificationApi( shortcut: string, opts: any ): void {
function invokeNotificationApi(shortcut: string, opts: any): void {
return invokeDingTalkApi(`device.notification.${shortcut}`, opts);
}

export default {
alert( message: any, callback: Function = function() {} ): void {
invokeNotificationApi('alert', mixin({
title: '',
buttonName: '知道了',
onSuccess: callback
}, isPlainObject(message) ? message : {message}));
alert(message: any, callback: Function = function () {}): void {
invokeNotificationApi(
'alert',
mixin(
{
title: '',
buttonName: '知道了',
onSuccess: callback,
},
isPlainObject(message) ? message : { message },
),
);
},
confirm( message: any, agreed: Function = function() {}, cancelled: Function = function() {} ): void {
invokeNotificationApi('confirm', mixin({
title: '',
buttonLabels: ['确定', '取消'],
onSuccess: ( result: any ) => result.buttonIndex === 0 ? agreed() : cancelled()
}, isPlainObject(message) ? message : {message}));
confirm(message: any, agreed: Function = function () {}, cancelled: Function = function () {}): void {
invokeNotificationApi(
'confirm',
mixin(
{
title: '',
buttonLabels: ['确定', '取消'],
onSuccess: (result: any) => (result.buttonIndex === 0 ? agreed() : cancelled()),
},
isPlainObject(message) ? message : { message },
),
);
},
// prompt() {},
toast( opts: any ): void {
toast(opts: any): void {
const { text, icon, duration, callback: onSuccess } = opts;

invokeNotificationApi('toast', {
text,
icon: icon === 'fail' ? 'error' : icon,
duration,
delay: 0,
onSuccess
onSuccess,
});
},
loading: {
show( opts: any ): void {
show(opts: any): void {
const { text, callback: onSuccess } = opts;

invokeNotificationApi('showPreloader', {
text,
showIcon: true,
onSuccess
onSuccess,
});
},
hide( callback: Function ): void {
invokeNotificationApi('hidePreloader', {onSuccess: callback});
}
hide(callback: Function): void {
invokeNotificationApi('hidePreloader', { onSuccess: callback });
},
},
actionSheet( opts: any ): void {
actionSheet(opts: any): void {
const { title, cancel, actions } = opts;

invokeNotificationApi('actionSheet', {
title,
cancelButton: cancel.text,
otherButtons: map(actions, ( action: any ) => action.text),
onSuccess: ( result: any ) => {
otherButtons: map(actions, (action: any) => action.text),
onSuccess: (result: any) => {
const { buttonIndex: idx } = result;

let action, handler;
if ( idx === -1 ) {

if (idx === -1) {
handler = cancel.handler;
}
else {
} else {
action = actions[idx];
handler = action.handler;
}
if ( !isFunction(handler) ) {

if (!isFunction(handler)) {
handler = opts.handler;
}

return action ? handler(action) : handler();
}
},
});
}
}
},
};
10 changes: 5 additions & 5 deletions src/adapters/bridge/dingtalk/previewer.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { isNumeric } from '../../../utils/is/type';
import { isNumeric } from '@ntks/toolbox';
import { invokeDingTalkApi } from './helper';

export default {
image( opts: any ): void {
image(opts: any): void {
const { urls = [], current = 0 } = opts;

invokeDingTalkApi('biz.util.previewImage', {
urls,
current: isNumeric(current) ? urls[current * 1] : current
current: isNumeric(current) ? urls[current * 1] : current,
});
}
}
},
};
40 changes: 25 additions & 15 deletions src/adapters/bridge/helper.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
import { isBoolean, isString, isFunction, isPlainObject } from '../../utils/is/type';
import { each, keys } from '../../utils/collection';
import { getDefaults, setPrivate, getPrivate } from '../../utils/storage/helper';
import {
isBoolean,
isString,
isFunction,
isPlainObject,
each,
keys,
getDefaults,
setPrivate,
getPrivate,
} from '@ntks/toolbox';

/**
* 是否优先使用 native 组件
*
* @param {*} opts 包含抉择的配置项
*/
export function isNativeFlavor( opts: any ): boolean {
return isBoolean(opts) ? opts :
isPlainObject(opts) && isBoolean(opts.native) ? opts.native :
getDefaults('behavior') === 'native';
export function isNativeFlavor(opts: any): boolean {
return isBoolean(opts)
? opts
: isPlainObject(opts) && isBoolean(opts.native)
? opts.native
: getDefaults('behavior') === 'native';
}

/**
Expand All @@ -19,7 +29,7 @@ export function isNativeFlavor( opts: any ): boolean {
* @param {*} flag 标识符
* @param {*} apis API
*/
export function setBridge( flag: string, apis: any ): any {
export function setBridge(flag: string, apis: any): any {
return setPrivate(`bridge.${flag}`, apis);
}

Expand All @@ -29,7 +39,7 @@ export function setBridge( flag: string, apis: any ): any {
* @param {*} flag 标识符
* @param {*} ref API 引用
*/
export function getBridge( flag: string, ref: string ): any {
export function getBridge(flag: string, ref: string): any {
return getPrivate(`bridge.${flag}.${ref}`);
}

Expand All @@ -39,26 +49,26 @@ export function getBridge( flag: string, ref: string ): any {
* @param {*} ref API 引用
* @param {*} isNativeFirst 是否 native 优先
*/
export function resolveBridge( ref: string, isNativeFirst: boolean ): any {
if ( !isString(ref) ) {
export function resolveBridge(ref: string, isNativeFirst: boolean): any {
if (!isString(ref)) {
return;
}

let handler;

if ( isNativeFirst ) {
if (isNativeFirst) {
const envs = getPrivate('env');

each(keys(getPrivate('bridge')), ( k: string ) => {
if ( k !== 'fallback' && envs[k] === true ) {
each(keys(getPrivate('bridge')), (k: string) => {
if (k !== 'fallback' && envs[k] === true) {
handler = getBridge(k, ref);

return false;
}
});
}

if ( !isFunction(handler) ) {
if (!isFunction(handler)) {
handler = getBridge('fallback', ref);
}

Expand Down
6 changes: 3 additions & 3 deletions src/adapters/bridge/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isFunction } from '../../utils/is/type';
import { isFunction } from '@ntks/toolbox';
import { isNativeFlavor, resolveBridge } from './helper';

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

if ( !isFunction(handler) ) {
if (!isFunction(handler)) {
return false;
}

Expand Down
20 changes: 10 additions & 10 deletions src/adapters/flexible/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { mixin } from '../../utils/collection';
import { mixin } from '@ntks/toolbox';

const DEFAULT_FONT_BASELINE = 14;
const DEFAULT_DRAFT_BASELINE = 375; // iPhone 6/7
const DEFAULT_DRAFT_BASELINE = 375; // iPhone 6/7

let flexibleAdaptorTimer: number;

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

if ( !width ) {
if (!width) {
return;
}

rootEl.style.fontSize = `${fontBaseline * width / draftBaseline}px`;
rootEl.style.fontSize = `${(fontBaseline * width) / draftBaseline}px`;
}

/**
Expand All @@ -28,7 +28,7 @@ function setFontSize( fontBaseline: number, draftBaseline: number ): void {
* @param {*} name 事件名称
* @param {*} handler 事件处理函数
*/
function bindWindowEvent( name: string, handler: any ): void {
function bindWindowEvent(name: string, handler: any): void {
window.addEventListener(name, handler, false);
}

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

flexibleAdaptorTimer = setTimeout(handler, timeout);
}

export default function( opts: any ) {
opts = mixin({font: DEFAULT_FONT_BASELINE, draft: DEFAULT_DRAFT_BASELINE}, opts);
export default function (opts: any) {
opts = mixin({ font: DEFAULT_FONT_BASELINE, draft: DEFAULT_DRAFT_BASELINE }, opts);

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

bindWindowEvent('resize', () => setFlexibleAdaptorTimer(handler));
bindWindowEvent('pageshow', ( evt: any ) => evt.persisted && setFlexibleAdaptorTimer(handler));
bindWindowEvent('pageshow', (evt: any) => evt.persisted && setFlexibleAdaptorTimer(handler));

handler();
}
Loading

0 comments on commit 7cea566

Please sign in to comment.