$.fn.extend({ animateCss: function (animationName, callback) { var animationEnd = (function (el) { var animations = { animation: 'animationend', OAnimation: 'oAnimationEnd', MozAnimation: 'mozAnimationEnd', WebkitAnimation: 'webkitAnimationEnd', }; for (var t in animations) { if (el.style[t] !== undefined) { return animations[t]; } } })(document.createElement('div')); this.addClass('animated ' + animationName).one(animationEnd, function () { //$(this).removeClass('animated ' + animationName); callback && callback.call(this, $(this), animationName); }); return this; }, }); const ONEDAY = 86400000 var app = { /** * 请求id */ id: __utils.getUrlParam('ID'), /** * 请求时间戳 */ timestamp: __utils.getUrlParam('time'), /** * 切换风格id */ switchId: '', /** * 事件处理 */ events: function () { var self = this, $picList = $(".ai_pic>li"); var time; //画风切换 $picList.on("click", function () { var $this = $(this); var msg = $this.data('msg') app.checkOperationTimeout() console.log(msg); if ('switch ' + app.switchId == msg) { // 已选择的不再执行 return; } if (!app.sendCheck()) { return; } if (time && (Date.now() - time < __config.switchInterval * 1000)) { app.showLoadingSwitch(function () { $this.addClass("active").siblings().removeClass("active"); }) } else { $this.addClass("active").siblings().removeClass("active"); } time = Date.now(); app.switchId = msg.split(' ')[1] console.log(app.switchId,'app.switchId'); app.send(msg) }); //跳转拍照页面 $('.photo').on("click",function () { app.checkOperationTimeout() if (!app.sendCheck()) { return; } $(`.body > div[id="work"]`).fadeIn().siblings().fadeOut() $('.mask').show() self.send('readyphoto 1') }) // 确认拍照 $('#takePhoto').on("click",function () { app.checkOperationTimeout() if (!app.sendCheck()) { return; } $('#comfirmcon').fadeOut() $('#selectcon').css({'visibility':'visible'}) $('.mask').hide() self.send('photo 1') }) //返回 $('#back').on("click",function () { app.checkOperationTimeout() if (!app.sendCheck()) { return; } $(`.body > div[id="app"]`).fadeIn().siblings().fadeOut() self.send('menu 1') }) //返回拍照页面 $('#rephoto').on("click",function () { app.checkOperationTimeout() if (!app.sendCheck()) { return; } $('#comfirmcon').fadeIn() $('#selectcon').css({'visibility':'hidden'}) $('.mask').show() self.send('rephoto 1') }) //拍照完成 $('#useit').on("click",function () { app.checkOperationTimeout() if (!app.sendCheck()) { return; } self.send('usephoto 1') }) //返回拍照 $('#backtophoto').on("click",function () { window.location.reload() }) $('#download').on("click",function () { app.showAlert('请长按图片保存', 'save'); }) $('#quan').on("click",function () { app.showAlert('请长按图片保存,分享朋友圈', 'save'); }) $('.app-alert .btn-use').on('click', function () { var $alert = $('.app-alert') app.hideMask() $alert.removeClass($alert.data('class') + ' animated zoomIn') var text = $(this).text(); if (text == '尝试使用' || text == '再次使用'|| text == '重选画风') { app.send('request') $(`.body > div[id="app"]`).fadeIn().siblings().fadeOut() } }) $('.app-alert .btn-link').on('click', function () { if ($(this).text() == '确定'||$(this).text() == '取消') { var $alert = $('.app-alert') app.hideMask() $alert.removeClass($alert.data('class') + ' animated zoomIn') } }) }, /** * 检验时间戳 */ checkTimestamp(){ let del = (new Date()).getTime() - this.timestamp if (del>ONEDAY) { return false } return true }, showMask: function (clazz) { var $elem = $('.app-mask'); if (clazz) { $elem.addClass(this.showMask._clazz = clazz) } $elem.css('display', 'block') }, hideMask: function () { var $elem = $('.app-mask'); if (this.showMask._clazz) { $elem.removeClass(this.showMask._clazz) this.showMask._clazz = null } $elem.css('display', 'none') }, showAlert: function (msg, icon) { this.showMask(); var $alert = $('.app-alert'); var $btns = $alert.find('.btns a'); $alert.data('class', icon).addClass(icon).animateCss('zoomIn') $alert.find('.tips').html(msg) if (/error|used/.test(icon)) { $btns.eq(0).text('尝试使用') } else if (/timeout|stop/.test(icon)) { $btns.eq(0).text('再次使用') } else if (/fail/.test(icon)) { $btns.eq(0).text('重选画风') } else if (/save/.test(icon)) { $btns.eq(0).text('确定') } if (/used|timeout|stop|error|fail|save/.test(icon)) { $btns.eq(1).text('取消').attr('href', 'javascript:;') } }, showActionTips: function (delay, done) { var $elem = $('.app-action-tips'); var flag = flag || 1; delay = delay || 1000; app.showMask('white') $elem.find('.content').hide() $elem.find('.content.face-' + flag).show() $elem.animateCss('zoomIn', function () { var timer = setInterval(() => { if (++flag > 4) { $elem.removeClass('animated zoomIn'); clearInterval(timer) if (!app.is_action) { app.hideMask('white') done && done() } return; } $elem.find('.content').hide() $elem.find('.content.face-' + flag).show() }, delay); }) }, showLoading: function (msg) { msg = msg || '相片正在生成中,请耐心等候' this.showMask(); $('.app-action-tips .content').css('display', 'none'); $('.app-action-tips .content.loading').css('display', 'block').find('.tips').html(msg); $('.app-action-tips').addClass('animated zoomIn') //.animateCss('zoomIn') }, hideLoading: function () { this.hideMask(); $('.app-action-tips .content.loading').css('display', 'none'); $('.app-action-tips').removeClass('animated zoomIn') }, showLoadingSwitch: function (done) { this.showMask(); $('.app-action-tips .content').css('display', 'none'); $('.app-action-tips .content.loading-switch').css('display', 'block') $('.app-action-tips').animateCss('zoomIn', function ($elem, aname) { setTimeout(function () { app.hideMask(); $elem.removeClass('animated ' + aname); done && done() }, 1000); }) }, renderPictures() { var html = []; this.imgList.forEach(function (item) { html.push('
'); }) if (!html.length) { html.push(' '); } $('.pic-swiper .swiper-wrapper').html(html.join('')); $('.pic-swiper .swiper-wrapper img').click(function () { wx.previewImage({ current: this.src, urls: app.imgList.map(function (item) { return item.url }) }); }); this.picSwiper(); }, showView: function (json) { this.hideLoading() setTimeout(function () { // app.showMask(); // $('.app-view').animateCss('zoomIn', function () { // app.send('close') // }).find('.img').html('