common-utils-kit 1.1.4 → 1.1.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.editorconfig ADDED
@@ -0,0 +1,7 @@
1
+ [*.{js,jsx,ts,tsx,vue}]
2
+ indent_style = space
3
+ indent_size = 2
4
+ end_of_line = lf
5
+ trim_trailing_whitespace = true
6
+ insert_final_newline = true
7
+ max_line_length = 400
package/.eslintrc.js ADDED
@@ -0,0 +1,42 @@
1
+ module.exports = {
2
+ root: true,
3
+ env: {
4
+ node: true,
5
+ },
6
+ extends: ['eslint:recommended', 'plugin:vue/recommended'],
7
+ parserOptions: {
8
+ parser: "@babel/eslint-parser",
9
+ requireConfigFile: false
10
+ },
11
+ rules: {
12
+ 'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
13
+ 'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
14
+ 'import/prefer-default-export': 'off',
15
+ 'no-param-reassign': 'off',
16
+ 'vue/no-template-shadow': 'off',
17
+ 'global-require': 0,
18
+ 'linebreak-style': ['off'],
19
+ 'vue/max-attributes-per-line': 'off',
20
+ 'max-len': ['error', { code: 400, ignoreUrls: true, ignorePattern: '^\\s*xlink:href="*?' }],
21
+ 'no-bitwise': 'off',
22
+ 'guard-for-in': 'off',
23
+ 'no-restricted-syntax': 'off',
24
+ 'prefer-destructuring': 'off',
25
+ 'no-underscore-dangle': 'off',
26
+ 'new-cap': 'off',
27
+ 'no-plusplus': 'off',
28
+ 'vue/multi-word-component-names':'off',
29
+ 'vue/first-attribute-linebreak':'off',
30
+ 'vue/component-definition-name-casing':'off',
31
+ 'vue/attributes-order':'off'
32
+ },
33
+ overrides: [
34
+ {
35
+ files: ['**/__tests__/*.{j,t}s?(x)', '**/tests/unit/**/*.spec.{j,t}s?(x)'],
36
+ env: {
37
+ mocha: true,
38
+ },
39
+ },
40
+ ],
41
+ ignorePatterns: ['src/assets/*'],
42
+ };
@@ -0,0 +1,14 @@
1
+ {
2
+ "recommendations": [
3
+ "vue.volar",
4
+ "vue.vscode-typescript-vue-plugin",
5
+ "hollowtree.vue-snippets",
6
+ "dbaeumer.vscode-eslint",
7
+ "stylelint.vscode-stylelint",
8
+ "esbenp.prettier-vscode",
9
+ "editorconfig.editorconfig",
10
+ "streetsidesoftware.code-spell-checker",
11
+ "syler.sass-indented",
12
+ "mikestead.dotenv"
13
+ ]
14
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "files.exclude": {
3
+ // "**/lib": true,
4
+ // "**/public": true
5
+ }
6
+ }
package/README.md CHANGED
@@ -1,34 +1,116 @@
1
-
2
- ## Common Utils Kit
3
-
1
+ # Vue2 Utils Kit
4
2
  `common-utils-kit`是一个包含常用函数的npm包,提供了一系列验证、防抖节流、数据格式化等功能
5
-
6
- ## 使用
3
+ ## 安装
4
+ ```
5
+ npm install common-utils-kit
7
6
  ```
8
- # 安装
9
- npm i common-utils-kit
10
7
 
11
- # 使用方式一(局部引入)
8
+ ### 全局引入
9
+ 新建 vue.prototype.js 文件
10
+ ```
11
+ import Vue from 'vue';
12
+ import commonUtilsKit from 'common-utils-kit';
13
+ Vue.prototype.$files = commonUtilsKit.files;
14
+ Vue.prototype.$format = commonUtilsKit.format;
15
+ Vue.prototype.$test = commonUtilsKit.test;
16
+ Vue.prototype.$tool = commonUtilsKit.tool;
17
+ Vue.use(commonUtilsKit.directive); // 注册自定义指令
18
+ ```
19
+ 在main文件中引入vue.prototype.js
20
+ ```
21
+ import './vue.prototype.js'; // 引入 vue.prototype.js
22
+ ```
23
+ ### 局部引入
24
+ ```
12
25
  import commonUtilsKit from "common-utils-kit";
13
26
  例:验证是否为数字 commonUtilsKit.test.number(1)
27
+ ```
28
+ #### 使用方式
29
+ ```
30
+ this.$test.email("200") //false
31
+ ```
14
32
 
15
- # 使用方式二(全局引入)
16
- import commonUtilsKit from "common-utils-kit";
17
- Vue.prototype.$test = commonUtilsKit.test;
18
- 例:验证是否为数字 this.$test.number(1)
19
- ```
20
- ### directives(指令)
21
- 1. debounce(按钮或输入框防抖)
22
- 2. inputDebounce(输入框防抖)
23
- 3. btnDebounce(按钮防抖)
24
- 4. btnThrottle(按钮节流)
25
- 5. relativeTime(相对时间)
26
- 6. replace(输入框字符串替换)
27
- 7. elDragDialog(拖拽dialog)
28
- ### files(文件)
33
+ # 使用文档
34
+
35
+ ## 指令列表(directives)
36
+
37
+ ### 1. `v-debounce`
38
+ **描述**: 按钮或输入框防抖。
39
+ ```html
40
+ <el-input v-model="aa" v-debounce="[reset, 'input', 1000]" placeholder="输入框数组防抖" />
41
+ <el-button v-debounce="[reset, 'click', 1000]">刷新</el-button>
42
+ ```
43
+ **参数说明**:
44
+ - `v-debounce` - 指令接受一个数组,包含以下参数。
45
+ - **方法**: 要执行的函数(如 `reset`)。
46
+ - **事件类型**:要监听的事件类型(如 `'click'`)。
47
+ - **延迟时间**:防抖延迟的时间,以毫秒为单位(如 `1000`)。
48
+
49
+ ### 2. `v-input-debounce`
50
+ **描述**: 输入框防抖。
51
+ ```html
52
+ <el-input v-input-debounce:1000="reset" placeholder="输入框防抖" />
53
+ ```
54
+ **参数说明**:
55
+ - `v-input-debounce` - 指令接受以下参数:
56
+ - **延迟时间**:以毫秒为单位的防抖延迟时间(如 `1000`),默认为 500 毫秒。
57
+ - **方法**:要执行的函数(如 `reset`)。
58
+
59
+ ### 3. `v-btn-debounce`
60
+ **描述**: 按钮防抖。
61
+ ```html
62
+ <el-button v-btn-debounce="500">防抖按钮</el-button>
63
+ ```
64
+ **参数说明**:
65
+ - `v-btn-debounce` - 指令接受以下参数:
66
+ - **延迟时间**:以毫秒为单位的防抖延迟时间(如 `500`),默认为 1000 毫秒。
67
+
68
+ ### 4. `v-btn-throttle`
69
+ **描述**: 按钮节流。
70
+ ```html
71
+ <el-button v-btn-throttle="500">节流按钮</el-button>
72
+ ```
73
+ **参数说明**:
74
+ - `v-btn-throttle` - 指令接受以下参数:
75
+ - **间隔时间**:以毫秒为单位的防抖延迟时间(如 `500`),默认为 1000 毫秒。
76
+
77
+ ### 5. `v-relative-time`
78
+
79
+ **描述**: 时间转换,展示距离当前时间的相对时间。(刚刚,xx分钟前,xx小时前,xx天前,年/月/日)
80
+ ```html
81
+ <div v-relative-time="1699795200000"></div>
82
+ ```
83
+ **参数说明**:
84
+ - `v-relative-time` - 指令接受以下参数:
85
+ - **过去时间戳**:过去的时间戳(如 `1699795200000`)
86
+
87
+ ### 6. `v-replace`
88
+ **描述**: 限制输入框的输入内容。
89
+ ```html
90
+ <el-input v-replace:price="inputValue" />
91
+ ```
92
+ **参数说明**:
93
+ - `v-relative-time` - 指令接受以下参数:
94
+ - **限制类型**:允许两位小数的金额`price`(如 price)
95
+ - **限制类型**仅允许正数`plusPrice`(如 price)。
96
+ - **限制类型**仅允许正整数`num`(如 price)。
97
+ - **限制类型**仅允许自然数`natural`(如 price)。
98
+ - **输入内容**限制输入的内容(如 inputValue)
99
+
100
+
101
+ ### 7. `v-el-drag-dialog`
102
+ **描述**: 可拖拽的对话框(仅用于element-ui)。
103
+ ```html
104
+ <el-dialog v-el-drag-dialog>
105
+ <div class="el-dialog__header">拖拽我</div>
106
+ <div>对话框内容</div>
107
+ </el-dialog>
108
+ ```
109
+
110
+ ## 文件插件(files)
29
111
  1. downloadBase64File(base64文件下载)
30
112
  2. downloadFiles(文件http地址下载)
31
- ### format(格式化数据)
113
+ ## 格式化数据(format)
32
114
  1. unrepeated(数组对象去重)
33
115
  2. treeToFlat(树形结构拍平为一维数组)
34
116
  3. flatToTree(一维数组递归成为树形结构)
@@ -37,7 +119,7 @@ Vue.prototype.$test = commonUtilsKit.test;
37
119
  6. dateDiff(计算日期差值(单位:天))
38
120
  7. getNowDate(获取当前日期)
39
121
  8. setFormColumnsData(设置自定义表单列数据)
40
- ### test(验证)
122
+ ## 数据验证(test)
41
123
  1. hasValue(是否有值,可验证指定类型)
42
124
  2. valueType(返回数据类型)
43
125
  3. emai(是否为邮箱)
@@ -49,7 +131,12 @@ Vue.prototype.$test = commonUtilsKit.test;
49
131
  9. letter(是否为字母)
50
132
  10. landline(是否为座机)
51
133
  11. code(是否为6位数短信验证码)
52
- ### tool(工具函数)
134
+ ## 通用工具(tool)
53
135
  1. debounce(防抖)
54
136
  2. throttle(节流)
55
137
  3. sleep(睡眠阻塞延时)
138
+ ## 组件使用
139
+ ### 文件预览(preview)
140
+ 需要安装 npm i docx-preview --save 预览docx
141
+ 需要安装 npm i axios --save 预览docx
142
+
package/lib/demo.html ADDED
@@ -0,0 +1 @@
1
+ <!doctype html><meta charset="utf-8"><title>utils-kit demo</title><script src="./utils-kit.umd.js"></script><script>console.log(utils-kit)</script>