import Magix from 'magix' import View from 'dmp-new/view' Magix.applyStyle('@./default.less') // 另外加一个新参数,用来新引导上线时,所有人弹一次引导 // 每次+1 export default View.extend({ tmpl: '@new-guide.html', init(options) { this.options = options }, async render() { const data = await this.getData() const { user, all } = this.updater.get() if (!data) { return this.updater.digest() } data.list = data.list.filter(item => { return item.isShow }) data.list.push({ title: data.list[0].title, isLast: true, // 最后一帧自定义 cards: [ { imgUrl: 'https://img.alicdn.com/tfs/TB1L4pHcq67gK0jSZFHXXa9jVXa-246-270.png', title: '达摩盘新手操作指导', href: 'https://www.yuque.com/docs/share/40179c38-65ac-4f98-ae51-7c3ee785e0d4?#' }, { imgUrl: 'https://img.alicdn.com/tfs/TB1EMFIcAL0gK0jSZFtXXXQCXXa-302-248.png', title: '达摩盘白皮书介绍', href: 'https://www.yuque.com/ziyin-pgsv4/kb' }, { imgUrl: 'https://img.alicdn.com/tfs/TB1hnJLcuH2gK0jSZJnXXaT1FXa-276-274.png', title: '达摩盘营销课程推荐', href: 'https://shuyuan.taobao.com/#!/product/detail/index?id=108' } ] }) // 如果判断用户是需要流程引导的新手,则不展示浮层型新手引导 const isShowGuide = user.userExtra.newbie_guide_2_0_2 != '1' && user.USER_STATE != all.NEWBIE_GUIDE_STATE const pos = this.getPos() this.updater.digest({ list: data.list, curr: 0, top: pos.top, left: pos.left, isShowGuide }) }, // 数据存在alp上 async getData() { try { const models = [ { name: 'alp_dmp_dmp_newbie_guide_get' } ] const [model] = await this.fetch(models) const data = model.get('data') return data } catch (error) { // this.alert('错误提示', error.msg) } }, getPos() { // 900,600 const windowWidth = $(window).width() const windowHeight = $(window).height() let top = (windowHeight - 660) / 2 let left = (windowWidth - 980) / 2 top = top < 0 ? 0 : top left = left < 0 ? 0 : left return { top, left } }, 'showGuide'(e) { const pos = this.getPos() this.updater.digest({ top: pos.top, left: pos.left, isShowGuide: true }) }, 'prev'(e) { const list = this.updater.get('list') let curr = this.updater.get('curr') curr-- if (curr < 0) { curr = list.length - 1 } this.updater.digest({ curr }) }, 'next'(e) { let curr = this.updater.get('curr') const list = this.updater.get('list') curr++ if (curr > list.length - 1) { curr = 0 } this.updater.digest({ curr }) }, 'dot'(e) { this.updater.digest({ curr: e.params.index }) }, async 'close'(e) { this.updater.digest({ isShowGuide: false }) const user = this.updater.get('user') if (user.userExtra.newbie_guide_2_0_2 != '1') { try { const models = [ { name: 'api_user_newbie_guide_2_0_2_post' } ] const [model] = await this.fetch(models) } catch (error) { this.alert('错误提示', error.msg || error.message) } } } })