# h-vue-utils

Latest version **1.0.3** (published 2019-01-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install h-vue-utils
pnpm add h-vue-utils
yarn add h-vue-utils
bun add h-vue-utils
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2019-01-29 |
| First published | 2019-01-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 214.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | hevin 21553925@qq.com |
| Maintainers | hevin |
| Keywords | javascript vue 工具类 utils |

## Links

- npm: https://www.npmjs.com/package/h-vue-utils
- Repository: https://github.com/hevin-lee
- npm.io page: https://npm.io/package/h-vue-utils

## Recent versions

- 1.0.3 (latest) — 2019-01-29
- 1.0.2 — 2019-01-29
- 1.0.1 — 2019-01-28
- 1.0.0 — 2019-01-28

## README

# vue js 工具类


> 时间类、字符串等工具类集合，会不断更新
 
## Install
```shell
npm install h-vue-utils -S
```

## 如何使用

``` javascript
//main.js
import Vue from 'vue'
import H from 'h-vue-utils'
Vue.use(H)
```
## 工具类介绍

vue统一前缀 this.$H.


**字符串**
|作用 | 事件名 | 参数 | 类型 | 描述  
|------------- | -------------| -------------| -------------| -------------| -------------| -------------
|判断字符串为空 | strUtil.isEmpty |  str | string | 返回boolean  
|前后空格过滤 | strUtil.trim |  str |  string | 返回过滤后的值 
|判断是否超过限定字数 | strUtil.isOverLimit |  str<br>lenNum | string<br>string/number |   返回boolean  
|截取字符串 | strUtil.subStr |  str<br>lenNum | string<br>string/number |   结果string
|剩余可输入字数 | strUtil.remainChar |  str<br>total | string =>输入字符串<br>string/number =>总个数 |   结果 11/100
|手机、身份证等号码<br>位数值替换为星号 | strUtil.strTransStar |  (str,startIndex,endIndex) | (string,number,number) |   结果 135****2356
|纯数字校验 | strUtil.isNumber |  (str) | (string) |   结果 boolean
|判断数字,并保留2位小数 | strUtil.isDecimal |  (str) | (string) |   结果 boolean
|忽略大小写判断字符串是否相同 | strUtil.isCharEqual |  (str) | (string) |   结果 boolean
|数字转为千分位 | strUtil.parseToQFW |  (str,point=2) | (string/number,string/number) |   结果 100,000.02
|中文校验 | strUtil.isChinese |  (str) | (string) |   结果 boolean
<br><br>
**时间相关**
|作用 | 事件名 | 参数 | 类型 | 描述  
|------------- | -------------| -------------| -------------| -------------| -------------| -------------
|时间格式化 | dateUtil.format |  (date, pattern)| (string/Date,string) |   date=> 2018-03-03长短时间、时间戳、new Date()<br>pattern=>yyyy-MM-dd hh:mm:ss 组合式，不填默认yyyy-MM-dd
|获取当前时间 某天之前的时间 | dateUtil.getPreDate |  (day, curDate, pattern)| (string/number,string,string) |   day=> 天数，必填<br>curDate=>格式2018-01-03 传空，默认当天，pattern=>yyyy-MM-dd hh:mm:ss 组合式
|距离当前日期的天数 | dateUtil.getDay |  (t) | (string) |   t=>时间戳 或时间
|毫秒转时分秒 | dateUtil.formatSeconds |  (t, isEn = true) | (string/number,boolean) |   t=> 毫秒数<br>isEn 默认01:22:03, false为 1小时22分钟3秒
|判断时间跨度是否超过设定的天数 | dateUtil.isMaxDays |  (sTime, eTime, max = 31) | (string,string,string/number) |    结果boolean
开始时间不能大于结束时间 | dateUtil.dateCompare |  (sTime, eTime) | (string,string) |    结果boolean
<br><br>
**url相关**
|作用 | 事件名 | 参数 | 类型 | 描述  
|------------- | -------------| -------------| -------------| -------------| -------------| -------------
|获取url参数 | urlUtil.getQueryStringByName |  (name) | (string) |   1.html?tt=234234  ， ('tt') => 234234
url参数转为对象 | urlUtil.urlToObj |  (url) | (string) |   结果为一个对象 key：value
<br><br>
** 对象、数组相关**
|作用 | 事件名 | 参数 | 类型 | 描述  
|------------- | -------------| -------------| -------------| -------------| -------------| -------------
|根据子节点ID 找到所有父节点ID   | getTreeAllParent |  (treeItems, queryId, queryField = 'id', childKey = 'children', callback, treeTempArray = []) | (array,string/number,string,string,function,array) |  this.$H.getTreeAllParent(a,33,'id','children',function(items){console.log(items);})
<br><br>
**【发送消息】参数说明**
|参数 | 描述
|------------- | -------------
|moduleName  | string类型，对应模块名称，唯一性，on和emit必须对应，必须
|message  | object类型，要发送的数据，必须
|ifmId  | string类型，当前iframe的ID名称，isParent为true时（即top window发送消息时），必须传
|isParent  | boolean类型，true =》top window  发送给 子window ； false =》 子window 发送给 top window（即父级页面），默认false 

**【接收消息】参数说明**
|参数 | 描述
|------------- | -------------
|moduleName  | 对应模块名称，唯一性，on和emit必须对应，必须
|callback    |  回调函数，参数msg为接收到的数据，function(msg){  console.log(msg);  }

``` vue
  <!-- app.vue -->
  <template>
     <iframe src="http://localhost:8005/iframeTest.html" width="100%" height="600" id="ifr1"></iframe>
     <button @click="doClick">写入iframe</button>
  </template>
```
``` javascript
  <script>
    export default {
    data() {
        return {
        }
    },
    methods:{
       doClick() {
            //*********发送消息*********
            //top window父级发送消息  emit(发送的消息json,iframeId,true父级发送)
            this.$H.msg.emit({
                moduleName:"checkLogin",
                message:{name:'hello,小子~'},
                ifmId:'ifr1',
                isParent:true
            });
           
            //iframe页面发送消息调用方法
            this.$H.msg.emit({
                moduleName:"checkLogin",
                message:{name:'hello,小子~'}
            });
          

            //*********接收消息*********
            this.$H.msg.on({
              moduleName:"checkLogin", //和emit保持一致
              callback:function(msg){
                console.log(msg);
              }
            });
       }
    }
}
  </script>
```



## options
 
#######
有问题，请联系

21553925@qq.com

喜欢就加个star吧, thanks very much!

---
_Source: https://npm.io/package/h-vue-utils · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
