七巧低代码开发——JS事件场景案例集

「全局事件」 openTodoFlow 案例

一、「全局事件」案例


openTodoFlow


01、页面悬浮元素(“在线客服”等入口场景)

场景案例:进入PC端任意页面时,右侧均会出现setFormData悬浮窗,鼠标悬浮时出现介绍文字,点击之后跳转至新的页面,可用于客服系统

实现效果(点击放大):

vNmxRvvO65f8ff2252995.png

关键词:PC端任意页面>系统扩展设置>系统JS脚本扩展>beforeEach事件

思路:

afterEach方法里编写自定义脚本

export async function afterEach() {
  // 自定义脚本案例-全局悬浮按钮
  // 定义按钮
  if (window.location.href.indexOf('mruntime') === -1) {
    console.log(window.location.href)
    const suspendBtn = document.createElement('div')
    suspendBtn.style.position = 'fixed'
    suspendBtn.style.zIndex = '9999'
    suspendBtn.style.top = '50%'
    suspendBtn.style.right = '0'
    suspendBtn.style.width = '80px'
    suspendBtn.style.height = '30px'
    suspendBtn.style.lineHeight = '30px'
    suspendBtn.style.background = 'yellow'
    suspendBtn.style.borderRadius = '25px'
    suspendBtn.style.textAlign = 'center'
    suspendBtn.style.fontSize = '15px'
    suspendBtn.style.color = 'black'
    suspendBtn.innerHTML = '在线客服'
    suspendBtn.style.cursor = 'pointer'
    document.body.appendChild(suspendBtn)

  //   // 定义hover提示框
    const textTips = document.createElement('div')
    textTips.style.position = 'absolute'
    textTips.style.top = '-124px'
    textTips.style.right = '85px'
    textTips.style.zIndex = '9999'
    textTips.style.width = '20px'
    textTips.style.background = 'yellow'
    textTips.style.height = '300px'
    textTips.style.fontSize = '15px'
    textTips.style.color = 'black'
    textTips.innerHTML = '自定义脚本案例测试'
    textTips.style.display = 'none'
    suspendBtn.appendChild(textTips)
    suspendBtn.addEventListener('click', () => {
      window.open("https://qiqiao.do1.com.cn/")
    })

    suspendBtn.addEventListener('mousemove', () => {
      textTips.style.display = 'block'
    })

    suspendBtn.addEventListener('mouseout', () => {
      textTips.style.display = 'none'
    })

  }

}
 

02、顶部走马灯提示(”代开发模式“下提示客户授权”)

FWkgjmHO65f8ff3813256.png

场景案例:当前用户进入七巧Plus应用时,根据当前用户ID查询有进行授权,没有授权的用户在顶部显示提示授权走马灯

思路:由需要用到用户ID来查询授权信息可知,此处需要用到自定义函数的服务端接口,通过当前用户id来判断是否生成跑马灯提示

1.  由进入应用时提示可知,当前需要用到pc端页面mouted脚本事件

IrLdwglL65f8ffd746266.png

2.  由于需要用到自定义函数,所以使用executeServiceAPI方法调用自定义函数

Qq8qVrGr65f8ffe5f2984.png

3.  编写自定义函数hello方法,查看函数库中的方法,获取当前用户信息

MTY4ODg1Nzc3NTI3NjE3OQ_4339_vms57j6YFcGh_ml0_1676367526?w=813&h=799

4.  判断id,编写跑马灯提示代码

export async function mounted() {

   const ret = await this.business.executeServiceAPI({

    applicationId: '63e5abaee4e3897c6ae8ac6f',

    customJsId: '7304274683993382913',

    params: [],

    methodName: 'hello'

  })

  if(ret.id!=="e43f7f7f8432ed1f31e25d10cf6d76aa"){

    var boxStyleStr = `

    .boxStyle {

      overflow: hidden;

      flex: 1;

      height: 24px;

      width: 500px;

      line-height: 24px;

      position: absolute;

      top:0;

      right:200px;

      z-index:9999;

    }

    .boxStyle .boxText {

      position: absolute;

      white-space: nowrap;

      padding-left: 100%;

      animation: notice 10s 0s linear infinite both;

      font-size: 24px;

      font-weight: 500;

      color: #757575;

      }

    @keyframes notice {

      100% {

        transform: translate3d(-100%, 0, 0);

      }

    }`

    var style = document.createElement('style')

    style.innerHTML = boxStyleStr

    document.querySelector("head").appendChild(style)

    var box = document.createElement('div')

    box.classList.add('boxStyle')

    var text = document.createElement('span')

    text.innerText="该用户没有权限"

    text.classList.add('boxText')

    box.appendChild(text)

    document.body.appendChild(box)

  }

}


5. 自定义函数代码

var API = {

    hello: function() {

     var user = $.context.getCurrentUser()

     //返回当前用户

     return user

    },

}

实现效果:

XlEV0q4Y65f8fff85dd37.png


  • 发表于 2024-03-19 10:08
  • 阅读 ( 1814 )
  • 分类:专题案例

你可能感兴趣的文章

相关问题

0 条评论

请先 登录 后评论

作家榜 »

  1. 七小妹 12 文章
  2. 你是猴子派来的吧 3 文章
  3. 七巧低代码 2 文章
  4. 低代码小刘 2 文章
  5. 彭杏怡 0 文章
  6. 林友景 0 文章
  7. 0 文章
  8. 赵泽伟 0 文章