1.0.8 • Published 3 years ago

@mg_zero/test1 v1.0.8

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

安装说明

1、安装npm包

npm install @mg_zero/test1 --save

2、在main.js导入使用

import mg from '@mg_zero/test1'
Vue.use(mg)

分类

——基本工具类库 mg_base

platform(获取当前运行平台)
const res = this.$mg_base.platform;
console.log(res,'platform')
changeIosDate(IOS时间转化兼容)
const res = this.$mg_base.changeIosDate('2022-12-12');
console.log(res,'changeIosDate')
setItem(添加localStorage项)
this.$mg_base.setItem('aa','aaa')
getItem(获取localStorage项)
this.$mg_base.setItem('aa','aaa')
removeItem(移除localStorage项)
this.$mg_base.removeItem('aa');
omitString(文本超出省略)
const res = this.$mg_base.omitString('一二三四五六七八九十一二三四五六七八九十',10);
console.log(res,'omitString');
debounce(防抖)
 this.$mg_base.debounce(()=>{
   console.log('debounce ===>')
 },3000,false);
initHtmlFontSize(根据屏幕大小算出对应字体大小)
this.$mg_base.initHtmlFontSize();
formatDate(日期转化)
const res = this.$mg_base.formatDate(new Date(),'YYYY/MM/DD');
console.log(res,'formatDate')
getWeekDay(获取当前星期几)
const res =this.$mg_base.getWeekDay(new Date())
console.log(res,'getWeekDay')
getParameter(获取地址栏某个参数)
 const res = this.$mg_base.getParameter('test')
 console.log(res,'getParameter')
paramsToObj(地址栏参数转成对象)
const res = this.$mg_base.paramsToObj();
console.log(res,'paramsToObj')
richTextParse(过滤html为字符串)
const res = this.$mg_base.richTextParse("<h2>test<span>222</span></h2>");
console.log(res,'richTextParse')
regex(正则匹配)
const res = this.$mg_base.regex(13312345678,'mobile');
console.log(res,'regex')
pagination(前端本地分页)
const res = this.$mg_base.pagination(2,1,[1,2,3,4,5,6,7]);
console.log(res,'pagination')
replaceLineBreak(替换多行文本框中的换行符)
const str = '<div>aaa\nbbb\nccc</div>'
const res = this.$mg_base.replaceLineBreak(str);
console.log(res,'replaceLineBreak',str)
deepClone(深拷贝)
// 支持基本数值类型
const res = this.$mg_base.deepClone({aa:11,bb:22})
console.log(res,'deepClone')
formatNumber(数字转换k/w)
const res = this.$mg_base.formatNumber(12345222)
console.log(res,'formatNumber')
formatMoney(数字转换成元万元亿元)
const res = this.$mg_base.formatMoney(12345222)
console.log(res,'formatMoney')
thousandNum(数字千分位)
const res = this.$mg_base.thousandNum(12345222)
console.log(res,'thousandNum')
formatTime(时间换算成距离现在还还有xx小时xx天)
const res = this.$mg_base.formatTime(new Date()-300000)
console.log(res,'formatTime')
iosInputHandle(ios输入处理)
this.$mg_base.iosInputHandle()
changeByte(字节B转化为其它单位)
const res = this.$mg_base.changeByte(6000)
console.log(res,'changeByte')

——企业微信工具类库 mg_qw

api调用统一格式:

 this.$mg_qw.xxx(params,successFun,errorFun,completeFun,cancelFun,triggerFun)
参数名称参数含义必选示例
params入参(同企微)N{}
successFun接口调用成功时执行的回调函数N(Res)=>{}
completeFun接口调用完成时执行的回调函数N(Res)=>{}
errorFun接口调用失败时执行的回调函数N(Res)=>{}
cancelFun用户点击取消时的回调函数N(Res)=>{}
triggerFun监听Menu中的按钮点击时触发的方法N(Res)=>{}
initParams(企业微信参数初始化)
// main.js 引入
const qwParams ={
  corpId:'wwe5d4c8db028f9be7', // 必填
  getJsApiConfigParams:(data) => get('/web/isales-wxwork/jsApi/config', data), // 必填
  jsApiList:[], // 可选
  agentJsApiList:[] // 可选
}

Vue.prototype.$mg_qw.initParams(qwParams)



initConfig(配置初始化)
// 页面中调用api前使用
await this.$mg_qw.initConfig();

// 或者在路由中
router.beforeEach(async(to, from, next) => {
  await Vue.prototype.$mg_qw.initConfig();
  next()
})
config(注入企微企业的身份与权限)
await this.$mg_qw.config()
agentConfig(注入应用的身份与权限)
await this.$mg_qw.agentConfig();
checkJsApi(检测是否支持js接口)
this.$mg_qw.checkJsApi();
getContext(获取进入H5页面的入口环境)
this.$mg_qw.getContext((res)=>{
	console.log(res,'获取进入H5页面的入口环境')
});
selectEnterpriseContact(选人接口)
this.$mg_qw.selectEnterpriseContact(params,(res)=>{
   console.log(res)
},(err)=>{
   console.log(err)
});
openUserProfile(打开企业微信个人信息页)
this.$mg_qw.openUserProfile({type:1,userid:'WangZhiHao'});
selectCorpGroupContact(企业互联/上下游选人接口)
this.$mg_qw.selectCorpGroupContact();
claimClassAdmin(认领老师班级)
this.$mg_qw.claimClassAdmin();
openEnterpriseChat(打开会话)
this.$mg_qw.openEnterpriseChat({
  userIds:"CaiHeQiang;ZhouYiFang",
  groupName:'test',
  chatId:'wrgeD7BgAAdGIkxydGWFaEc2_cdC7N0g'
},(res)=>{
  var chatId = res.chatId; //返回当前群聊ID,
});
updateEnterpriseChat(变更群成员)
this.$mg_qw.updateEnterpriseChat({
  chatId:'wrgeD7BgAAdGIkxydGWFaEc2_cdC7N0g',
  userIdsToAdd:'WangZhiHao'
},(res)=>{
  console.log("变更群成员成功",res)
})
openExistedChatWithMsg(打开已有群聊并发送消息)
this.$mg_qw.openExistedChatWithMsg(
  {
    chatId:'wrgeD7BgAAdGIkxydGWFaEc2_cdC7N0g',
    msg: {
      msgtype: "link",
      link: {
        title: "title1",
        desc: "desc1",
        url: "link1",
        imgUrl: "imgurl1"
      }
    }
  },
  (res)=>{
    console.log("打开已有群聊并发送消息",res)
  })
hideChatAttachmentMenu(隐藏聊天附件栏的发送按钮)
this.$mg_qw.hideChatAttachmentMenu();
sendChatMessage(分享消息到当前会话)
this.$mg_qw.sendChatMessage();
selectExternalContact(外部联系人选人接口)
this.$mg_qw.selectExternalContact();
getCurExternalContact(获取当前外部联系人userid)
this.$mg_qw.getCurExternalContact();
getVersion(获取企业微信版本号)
this.$mg_qw.getVersion();
hideOptionMenu(隐藏右上角菜单)
this.$mg_qw.hideOptionMenu();
setClipBoardData(设置系统剪贴板的内容)
this.$mg_qw.setClipBoardData();
getClipboardData(获取系统剪贴板内容)
this.$mg_qw.getClipboardData();
navigateToAddCustomer(打开客户添加页面)
this.$mg_qw.navigateToAddCustomer();
hideAllNonBaseMenuItem(隐藏所有非基础按钮接口)
this.$mg_qw.hideAllNonBaseMenuItem();
versionToNum(版本号转化)
this.$mg_qw.versionToNum();
compareVersion(获取当前版本是大于输入的版本号)
this.$mg_qw.compareVersion('1.1.2');
hideMenuItems(保留部分分享菜单)
this.$mg_qw.hideMenuItems();
share(分享)
const shareParams:{
  content:'content111',
  title:'title',
  desc:'desc',
  link:'https://www.baidu.com',
  imgUrl:'https://search-operate.cdn.bcebos.com/d054b8892a7ab572cb296d62ec7f97b6.png',
} 
this.$mg_qw.share({type:'qywx',shareParams},()=>{
   console.log('success 没回调')
 },(err)=>{
   console.log(err)
 })
shareToExternalContact(群发消息给客户)
this.$mg_qw.shareToExternalContact(shareParams,()=>{
  console.log('success');
});
closeWindow(关闭窗口)
this.$mg_qw.closeWindow();

问题探讨

  1. ts智能提示;
  2. 命名$mg_qw、$mg_base
  3. 回调还是promise

自动生成ts文件

1、安装dtsmake包

文档地址:https://github.com/ConquestArrow/dtsmake

npm i dtsmake -g
npm i tern --save-dev 

2、执行转化

dtsmake -s ./path/to/sourcefile.js
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