移动端长按,点击,滑动问题解决

var ismoved = false;
        function longTouch() {
            $(".equipment").on("touchmove", function (event) {
                // event.preventDefault()
                ismoved = true;
            });
            $(".equipment").on("touchstart", function (event) {
                if (ismoved === false) {
                    lastTime = new Date().getTime();
                    // event.preventDefault();//阻止触摸时浏览器的缩放、滚动条滚动
                    clearTimeout(timeout);
                    state = 0;
                    timeout = setTimeout(function () {
                        state = 1;
                    }, 1000);
                    // event.returnValue = true;
                }
            });

            $(".equipment").on("touchend", function (event) {
                if (ismoved === false) {
                    // event.preventDefault();//阻止触摸时浏览器的缩放、滚动条滚动
                    clearTimeout(timeout);
                    var delId = $(this).attr('deviceid');
                    nowTime = new Date().getTime();
                    var timeLength = nowTime - lastTime;

                    if (timeLength > 1000) {
                        layer.msg('<span style="height:60px;">是否删除该设备?<span>', {
                            area: ['60%', '80px'],
                            time: 22220000,
                            shade: 0.3,
                            btn: ['是', '否'],
                            yes: function () {
                                $.ajax({
                                    url: common.baseUrl + 'product/industry/canceldevicejoin',
                                    type: 'post',
                                    contentType: 'application/json',
                                    dataType: 'json',
                                    data: JSON.stringify(
                                        common.getSign({
                                            pageIndex: 0,
                                            pageSize: 10,
                                            token: localStorage.getItem('token'),
                                            timestamp: +new Date(),
                                            deviceId: delId
                                        })
                                    ),
                                    success: function (res) {
                                        if (res && res.code === "00000") {
                                            // layer.msg('<span style="fontSize:16px;">删除设备成功!</span>', {
                                            //     area: ['60%', '80px'],
                                            //     time: 30000000000000
                                            // })
                                            setTimeout(function () {
                                                location.reload();
                                            }, 1000)

                                        } else {
                                            layer.msg(res.msg);
                                        }
                                    },
                                    error: function () {
                                        layer.msg('删除设备失败');
                                    }
                                });
                            }
                        })
                    }
                    if (timeLength <= 1000) {
                        var deviceId = $(this).attr('deviceId')
                        var deviceModel = $(this).attr('deviceModel')
                        var deviceName = $(this).attr('deviceName')
                        var categoryId = categoryIdObj[deviceModel]
                        if ($(this).attr('deviceModel') === "screen") {
                            if ($(this).attr('status') === "0") {
                                window.location.href = './intelligent-display.html' + '?screenid=' + deviceId;
                            }
                            else {
                                window.location.href = './select-sence.html' + '?screenid=' + deviceId;
                            }
                        }
                        if ($(this).attr('deviceModel') === "waterenv") {
                            window.location.href = './water-equipment.html' + '?deviceId=' + deviceId + '&deviceName=' + deviceName + '&deviceModel=' + deviceModel;
                        }
                        if ($(this).attr('deviceModel') === "ecotope") {
                            window.location.href = './meteorological-equipment.html' + '?deviceId=' + deviceId + '&deviceName=' + deviceName + '&deviceModel=' + deviceModel;
                        }
                        if ($(this).attr('deviceModel') === "roomenv") {
                            window.location.href = './water-equipment.html' + '?deviceId=' + deviceId + '&deviceName=' + deviceName + '&deviceModel=' + deviceModel;
                        }
                        if ($(this).attr('deviceModel') === "gateway") {
                            window.location.href = './water-equipment.html' + '?deviceId=' + deviceId + '&deviceName=' + deviceName + '&deviceModel=' + deviceModel;
                        }
                    }
                    state = 0;
                    // event.returnValue = true;
                }
                ismoved = false;
            });
        }
发布了121 篇原创文章 · 获赞 13 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/Vansal/article/details/102622996
今日推荐