提交 117edf77 编写于 作者: KK's avatar KK

新增动画服务类 & 新增第三方震动 & 视图工具类

上级 8a67ac84
import { ViewTool } from '@/utils';
/**
* 动画服务类
*
* @class AnimationService
*/
export class AnimationService {
/**
* 工具类
*/
public static $viewTool:ViewTool = ViewTool.getInstance();
/**
* 长按元素拖动
*/
public static draggable(ele:HTMLElement|null,event:Function) {
if(!ele){
return
}
let l:number = 0;
let x :number= 0;
let y :number= 0;
let right :number= 0;
let bottom :number= 0;
let time = 0
let canMove:boolean = false
// 开始长按
ele.addEventListener("touchstart",(e:any)=>{
l = e.srcElement.offsetLeft
x = e.targetTouches[0].clientX;
y = e.targetTouches[0].clientY;
if(ele){
right = Number(ele.style.right .replace('px',""));
bottom = Number(ele.style.bottom.replace('px',""));
}
time = setTimeout(() => {
if(this.$viewTool.getThirdPartyName()){
this.$viewTool.thirdPartyEvent('vibrate',100);
}else{
// navigator.vibrate(100);
}
canMove = true;
}, 1000);
})
// 开始移动
ele.addEventListener("touchmove",(e:any)=>{
clearTimeout(time);
if(!canMove){
return
}
let _x = e.targetTouches[0].clientX;
let _y = e.targetTouches[0].clientY;
let move_x = (_x - x );
let move_y = (_y - y);
event(`right:${right - move_x}px;bottom:${bottom - move_y}px`);
})
// 开始移动
ele.addEventListener("touchend",(e:any)=>{
clearTimeout(time);
canMove = false;
})
}
}
\ No newline at end of file
......@@ -264,12 +264,24 @@ export class DingTalkService {
resolve(res);
},
onFail: (err: any) => {
// alert(JSON.stringify(err));
},
});
});
}
/**
* 震动
*/
public vibrate(arg:any) : Promise<any> {
return new Promise((resolve, reject) => {
dd.device.notification.vibrate({
duration: arg, //震动时间,android可配置 iOS忽略
})
resolve({});
});
}
/**
* 清楚登录用户信息
*
......@@ -340,6 +352,8 @@ export class DingTalkService {
}
}
/**
* 钉钉导航栏返回事件
*
......@@ -394,5 +408,8 @@ export class DingTalkService {
if (Object.is(tag, "close")) {
return this.close();
}
if (Object.is(tag, "vibrate")) {
return this.vibrate(arg);
}
}
}
\ No newline at end of file
......@@ -424,4 +424,11 @@ export class ViewTool {
public destroyBackEvent() {
this.thirdPartyService.destroyBackEvent();
}
/**
* 第三方事件
*/
public thirdPartyEvent(tag:string,arg:any={}){
this.thirdPartyService.thirdPartyEvent(tag,arg);
}
}
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册