1.3.13 • Published 2 years ago

yt-tool v1.3.13

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

yt-tool 易推公共方法及组件说明

使用安装

// npm安装
npm install yt-tool --save

// main.js 引入
import ytTool from 'yt-tool'
import { unit_id } from '@/config' //请设置项目公共配置</a>

Vue.use(ytTool,{
  rewarded_id:unit_id.rewarded, // 激励广告ID
  routeIntercept:null // 路由拦截,function(params,resolve)
})

tips:引入完成后会在全局页面和组件的实例this下挂载一个$yt对象,

点击查看公共配置示例

$yt 对象说明 (vm表示当前页面或者组件的this)

方法名称方法说明参数<类型>
requestajax请求:第三方请求可以加上original:true配置项-
test规则校验:查看详情-
route路由跳转:查看详情-
inspectText\<Promise>校验文字contents\<Array | String >
inspectImage\<Promise>校验图片images\<Array | String>
auth\<Promise>授权,隐私协议授权使用scope:privacyopt:{scope,msg:保存图片需要开启相册权限!,required:true} , vm
uv\<Promise>记录UVnode,product_id,agent_id,spread_id
getImageInfo\<Promise>获取图片信息images\<Array | String>
imageToBase64\<Promise>图片临时路径转base64imageUrl\<String>
base64ToImage\<Promise>base64转图片临时路径base64\<String>
randomNumber生成范围内随机数,包含上限和下限本身lowerValue, upperValue
randomString生成指定长度随机字符串,已移除部分易混淆字符length = 32
throttle节流函数fun,wait=500,immediate=true
debounce防抖函数fun, wait = 500, immediate = true
deepMerge-
deepClone-
dateFormat-
queryComponent查询组件实例,component在查询公共组件内的组件时传name,vm,component = 'global'
rewardedAd播放广告,不包含统计方法,推荐使用yt-ad组件isAgent
message\<Promise>弹框方法,调用yt-message组件,以下方法都是对此方法的简写options,vm
alert-title,content,vm
confirm-title,content,vm
toast-title,vm
loading-title,image,vm
actionSheet-itemList,vm
messageClose关闭弹框或者loading-

组件注册使用及目录

tips:使用easycom规范

{
  "easycom": {
    "autoscan": true,
    "custom": {
      "^yt-(.*)": "yt-tool/components/yt-$1/yt-$1.vue"
    }
  }
}
组件名称组件简述
yt-ad广告唤起组件
yt-back-home返回首页(顶部)按钮
yt-bind-agent绑定代理商
yt-canvas生成海报
yt-constellation选择星座
yt-lunar选择时间(带时辰、农历)
yt-message消息弹框、loading
yt-navbar自定义导航栏
yt-privacy隐私协议授权弹框
yt-protocol隐私协议内容
yt-protocol-entry查看隐私协议入口
yt-qq-shareQQ端分享好友、发说说
yt-recommend热门推荐列表
yt-transition状态过度组件
yt-video-share剪映视频模板生成

公共配置示例

/* src/config/index.js */

/* eslint-disable no-dupe-keys */
let platform = '';
  // #ifdef MP-TOUTIAO
  platform = 'tt';
  // #endif
  // #ifdef MP-QQ
  platform = 'qq';
  // #endif
  // #ifdef MP-WEIXIN
  platform = 'wx';
  // #endif

const config = {
  /* 当前宿主平台 */
  platform,
  /* 服务地址 */
  devApi:'https://yitui-dev-product.yizhiqianjie.com',
  prodApi:'https://product-api.yizhiweixin.com',
  /* 广告ID 分平台 */
  ad:{
    tt:{
      rewarded:'1sho3o6a3kf524kbdl', /* 激励视频广告 */
      banner:'3b6bueuggh1jja9p5a', /* banner广告 */
      card:'', /* 卡片广告 */
      interstitial:'', /* 插屏广告 */
      // #ifdef PANGOLIN
      rewarded:'4hwfvefw1e015b42c7'
      // #endif
    },
    wx:{
      rewarded:'adunit-7b767fc03487f1dc',
      banner:'',
      card:'',
      interstitial:'',
    },
    qq:{
      rewarded:'770f543e1c7dba910be2752f347681e1',
      banner:'',
      card:'',
      interstitial:'',
    },
    ks:{
      rewarded:'',
      banner:'',
      card:'',
      interstitial:'',
    }
  }
}

export default config

export const unit_id = config.ad[platform];

yt-ad 广告播放组件

参数说明类型默认值可选值
statistics组件内部是否统计广告Booleantruefalse
initiative主动调用广告,如果设置为false,通过ref.trigger()调用Booleantruefalse
事件说明参数
triggerinitiative为false时,点击按钮触发-
success广告观看结束,可获取奖励code:场景值,查看详情
close-ad提前关闭广告Boolean
场景值说明
0广告播放中断
1金额支付成功
2广告视频播放完毕
3宿主平台不支持广告
4宿主是代理商
5抖音版本过低
6抖音播放异常
7超出后台设置的广告次数

yt-back-home 返回首页(顶部)按钮

参数说明类型默认值可选值
type样式选择,home为QQ小程序加群Stringmorehome
groupIdQQ群号,type为home时传String--
showTop显示返回顶部Booleanfalsetrue
homePath首页路径String/pages/index/indextid-

yt-bind-agent 绑定代理商页面

参数说明类型默认值可选值
indexPath首页路径String/pages/index/index-

yt-canvas 生成海报

参数说明类型默认值可选值
rect画布宽高Object{width:750,height:2000}-
事件说明参数
callback绘制完成并转为临时路径的回调tempFilePath
方法说明参数
savePhoto传入tempFilePath保存至相册tempFilePath
init开始绘制:options为绘制参数;autoSave是否自动保存.默认为trueoptions,autoSave

tips:画布组件的绘制是使用this.$refs['yt-canvas'].init()方法传参调用, init方法为Promise

options参数说明

// 示例
this.$refs['yt-canvas'].init({
    bgImg:'https://***.png', // 背景图片路径
    width:750, // 保存的结果宽度
    height:2000, // 保存的结果高度
    qrcodePath:`/pages/***/index?product_id=*`,// 二维码的落地页路径
    userinfo:{  //用户信息,以下为默认信息
      avatarUrl:'匿名用户',
      nickName:'https://ttmini.yizhiwechat.com/yzInterstTest/fission/default-avatar.png'
    }
    steps:[ // 绘制步骤,以下style内的值均为默认值
      // 绘制单行文本
      {
        type:'text',
        context:``, // 文本内容,特殊字段`{{nickname}}`为绘制用户昵称
        x:0,
        y:0,
        style:{
          color:`#000000`, // 文本颜色
          font:'32px', // 文本字体大小 , 加粗 : `bold 34px`
          align:'left', // 水平对齐方式
          base:'middle', // 垂直对齐方式
          stroke:"" , // 文字描边的颜色,不填不描, 且头条小程序不支持
        }
      },
      // 绘制多行文本
      {
        type:'longtext',
        context:``, // 文本内容
        x:0,
        y:0,
        style:{
          color:`#000000`, // 文本颜色
          font:'32px', // 文本字体大小 , 加粗 : `bold 34px`
          align:'left', // 水平对齐方式
          base:'middle', // 垂直对齐方式
          width:0, // 文本宽度, 超过会自动换行,默认行高 字体大小 * 1.3
          autoHeight:false // 是否根据内容高度自动延长结果图片高度
        }
      },
      // 绘制图片
      {
        type:'image',
        context:``, // 图片路径, 特殊字段`{{avatar}}`为绘制用户头像,`{{qrcode}}`为绘制产品二维码
        x:0,
        y:0,
        style:{
          width:0, // 图片宽度,原字段 w
          height:0, // 图片高度,原字段 h
          arc:false // 是否裁剪为圆形
        }
      },
      // 绘制图形
      {
        type:'path',
        context:``, // 图形路径, 示例在原点绘制 200*100图形: [[0,0],[200,0],[200,100],[0,100]]
        style:{
          color: 'ffffff', // 填充颜色 ,渐变色格式示例(从0到1,从透明到黑色): [[0,'rgba(0,0,0,0'],[1,'rgba(0,0,0,1)']]
          gradient_direction:'', // 渐变色方向 : [x1,y1,x2,y2],两点的连线表示渐变方向和距离
          fill:false //是否填充 , false为描边
        }
      },
    ]
  
  },
  false // autoSave ,是否自动保存相册
  );

yt-constellation 选择星座

参数说明类型默认值可选值
visible是否显示,支持.syncBooleanfalsetrue
banner弹框banner图片Stringhttps://ttmini.yizhiwechat.com/constellationPavilion/constellationIcon/banner.jpg-
事件说明参数
change选择了某个星座event:{ id:1,name:'摩羯座',date:'12.22~1.19' }
方法说明参数
show通过实例方法唤起弹框,返回一个Promise返回内容同chang事件
close关闭弹框-

yt-lunar 选择时间(农历)

参数说明类型默认值可选值
visible是否显示,支持.syncBooleanfalsetrue
value设置默认年份以及是否需要选择时辰String1985-01-01 0-
theme主题颜色String#C3201B-

tips:前面的年月日只能控制默认选中的年,月日没有实际功能,最后一位数字代表是否启用选择时辰,如果不需要则传入1985-01-01即可。

事件说明参数
change时间变化回调event:{ id:1,name:'摩羯座',date:'12.22~1.19' }
方法说明参数
show通过实例方法唤起弹框,返回一个Promise返回内容同chang事件

yt-message 界面交互组件

方法说明参数
show通过实例方法唤起弹框,返回一个Promiseoptions

tips:通过options进行覆盖默认配置,以下是默认配置示例

options配置项说明(支持调用类型)类型默认值可选值
type调用类型String-alert / confirm / toast / loading / action-sheet
title标题,alert / confirm / toast / loadingString--
content内容,alert / confirmString--
confirmText确认按钮文字,alert / confirmString确认-
confirmColor确认按钮文字颜色,alert / confirmString#3c76ff-
showCancel是否显示取消按钮,confirmBooleantruefalse
cancelText取消按钮文字,confirmString取消-
cancelColor取消按钮文字颜色,confirmString#666666-
mask是否显示遮罩,loading / toastStringtruefalse
image图片类型,可填写网络路径,loading / toastStringloadinglongtap / pie / agentia / sketch / tail / sandglass
imageWidth图片宽度,loading / toastNumber--
imageHidth图片高度,loading / toastNumber--
duration持续时长,toastNumber2400-
itemList选项列表,action-sheetArray--
itemColor选项颜色,action-sheetString#333333-
popover位置,action-sheetStringbottomcenter

tips:``action-sheet传入普通数组会转成对象数组,例

this.$refs['yt-message'].show({
  type:'action-sheet',
  itemList:['保存图片','发说说']
})

// 相当于

this.$refs['yt-message'].show({
  type:'action-sheet',
  itemList:[{
    title:'保存图片',type:'default'
  },{
    title:'发说说',type:'default'
  }]
})

// 注意,选择中的type,还有一个特殊类型share,调用分享时使用,比如
this.$refs['yt-message'].show({
  type:'action-sheet',
  itemList:[{
    title:'分享好友',type:'share'
  }{
    title:'保存图片',type:'default'
  }]
})

yt-navbar 自定义导航栏

参数说明类型默认值可选值
background背景颜色String-#F7F7F7
title标题String--
theme主题颜色,变换图标颜色Stringwhiteblack
color标题颜色,16进制色值Stringtheme的值-
root是否首页,代表是否隐藏左上角功能按钮Booleanfalsetrue
prop是否占位,将内容区顶下去Booleanfalsetrue
fixed是否固定在视口上方Booleantruefalse
index是否显示“仅供娱乐”字样Booleanfalsetrue
homePath首页路径Boolean/pages/index/indextid-
homeIcon自定义返回首页图标String--

yt-privacy 隐私协议授权弹框

参数说明类型默认值可选值
protocol协议页地址String/pages/protocol-
root控制协议样式,true是居中大弹窗,否则是底部小弹窗Booleanfalsetrue
required是否必检测授权,只有在产品有input输入时传Booleanfalsetrue
方法说明参数
show通过实例方法唤起弹框,返回一个Promise-

yt-protocol 隐私协议内容

参数说明类型默认值可选值
email邮箱地址Stringzwbbb0102b@163.com-

tips:一般在注册一个/pages/protocol页面,然后在页面中使用本组件

yt-protocol-entry 隐私协议内容

参数说明类型默认值可选值
color文字颜色String#ffffff-
custom-style组件样式String--
protocol协议页地址String/pages/protocol-

tips:如果需要absolute定位时,请包裹一层节点,通过对节点定位实现;

yt-qq-share QQ分享+发说说

参数说明类型默认值可选值
topmargin-topString60rpx-
width组件宽度String710rpx-
btnStyle按钮样式,一般用于配合width控制按钮大小String--
options发说说配置Object--
media发说说资源(图片,视频)Array--
// options 参数示例
{
  desc:'', // 说说默认文案
  title:'', //说说小尾巴文案
  path:'' // 产品路径,注意子产品都需要product_id
}
// media参数示例
[
  {
    type:'photo', // 资源类型,可选 video
    path:'' // 文件路径,必须为本地文件
  }
]

yt-recommend 热门推荐列表

参数说明类型默认值可选值
custom-style列表容器样式String--
top列表margin-topString40rpx-
scrollIndex分页触发器,父页面在onReachBottom回调一直递增即可Number--

yt-transition 动画过度组件

参数说明类型默认值可选值
name动画名Stringfade-
// yt-transition 用法同vue transition组件

// name 动画名可选值
/**
  * 淡入淡出 - fade、fade-up、fade-down、fade-left、fade-right
  * 滑动 - slide-up、slide-down、slide-left、slide-right
  * 弹动 bounce
  * 中部弹出 zoom
  * 中部弹入 punch
  * 飞入 fly
*/

yt-video-share 剪映视频合成(目前基本不可用)

参数说明类型默认值可选值
v-model控制显示隐藏Booleanfalse-
baseUrl合成视频的服务域名Stringhttps://image-to-video.yizhiweixin.com-
productId产品IDString--
imageData合成图片素材,目前仅支持两段Array--
dirName上传时的文件夹名称StringkoreanFace-
merge是否融合Booleantruefalse
1.3.13

2 years ago

1.3.11

2 years ago

1.3.12

2 years ago

1.3.10

2 years ago

1.3.7

3 years ago

1.3.6

3 years ago

1.3.5

3 years ago

1.3.9

2 years ago

1.3.8

3 years ago

1.3.4

3 years ago

1.3.3

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.9

3 years ago

1.2.8

3 years ago

1.2.7

3 years ago

1.2.6

3 years ago

1.2.5

3 years ago

1.2.55

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.0

3 years ago

1.1.9

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.1.8

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.1

3 years ago

1.1.2

3 years ago

1.1.0

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago