emacroh5lib 1.0.0 → 1.0.1

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/README.md CHANGED
@@ -1,6 +1,11 @@
1
- ## 添加npm账号
2
- npm adduser --registry https://registry.npmjs.org/
3
1
 
4
- ## 发布npm包
5
- npm publish --registry https://registry.npmjs.org/
6
2
 
3
+ ## 读取excel表格数据
4
+
5
+ ``` JavaScript
6
+ EMacro.File.readLocalExcel((file, workbook) => {
7
+ console.log("file", file);
8
+ console.log("workbook", workbook);
9
+ console.log("数据", workbook.Sheets["工作表1"]["G32"].h);
10
+ });
11
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emacroh5lib",
3
- "version": "1.0.0",
3
+ "version": "1.0.001",
4
4
  "description": "EMacro前端组件库",
5
5
  "main": "./dist/emacroh5lib.min.js",
6
6
  "types": "./dist/types/index.d.ts",
@@ -10,6 +10,7 @@
10
10
  "build:prod": "webpack --mode=production --node-env=production",
11
11
  "test:unit": "vue-cli-service test:unit",
12
12
  "test:e2e": "vue-cli-service test:e2e",
13
+ "e2e": "vue-cli-service test:e2e",
13
14
  "watch": "webpack --watch",
14
15
  "serve": "webpack serve",
15
16
  "dev": "webpack serve",
@@ -89,6 +90,9 @@
89
90
  "vue-echarts": "^6.0.2",
90
91
  "vue-property-decorator": "^9.1.2",
91
92
  "vue-router": "^3.5.1",
92
- "vuex": "^3.6.2"
93
+ "vuex": "^3.6.2",
94
+ "xlsx": "^0.18.5",
95
+ "query-string": "^7.0.1",
96
+ "deep-eql": "^4.0.0"
93
97
  }
94
98
  }
@@ -0,0 +1,116 @@
1
+
2
+ // 输入框支持搜索
3
+ //
4
+ export default {
5
+ data() {
6
+ return {
7
+ msg: "default",
8
+ };
9
+ },
10
+ props: {
11
+ data: { type: Array, default: [] },
12
+ placeholder: {
13
+ type: String,
14
+ default: ''
15
+ },
16
+ defaultValue: {
17
+ type: String,
18
+ default: ''
19
+ },
20
+ css: {
21
+ type: String,
22
+ default: 'width: 300px;'
23
+ },
24
+ // 失去焦点时回调
25
+ focus: {
26
+ type: Function,
27
+ default: () => {
28
+ console.log('focus');
29
+ }
30
+ },
31
+ blur: {
32
+ type: Function,
33
+ default: () => {
34
+ console.log('blur');
35
+ }
36
+ },
37
+ // 选中 option,或 input 的 value 变化(combobox 模式下)时,调用此函数
38
+ change: {
39
+ type: Function,
40
+ default: (value, option) => {
41
+ console.log('change');
42
+ }
43
+ },
44
+ // 键盘按下时回调
45
+ inputKeydown: {
46
+ type: Function,
47
+ default: (event) => {
48
+ console.log('inputKeydown', event);
49
+ }
50
+ },
51
+ // 鼠标移入时回调
52
+ mouseenter: {
53
+ type: Function,
54
+ default: (event) => {
55
+ console.log('mouseenter', event);
56
+ }
57
+ },
58
+ // 鼠标移出时回调
59
+ mouseleave: {
60
+ type: Function,
61
+ default: (event) => {
62
+ console.log('mouseleave', event);
63
+ }
64
+ },
65
+ // 下拉列表滚动时的回调
66
+ popupScroll: {
67
+ type: Function,
68
+ default: (event) => {
69
+ console.log('popupScroll', event);
70
+ }
71
+ },
72
+ // 文本框值变化时回调
73
+ search: {
74
+ type: Function,
75
+ default: (value) => {
76
+ console.log('search', value);
77
+ }
78
+ },
79
+ // 被选中时调用,参数为选中项的 value (或 key) 值
80
+ select: {
81
+ type: Function,
82
+ default: (value, option) => {
83
+ console.log('select', value, option);
84
+ }
85
+ },
86
+ // 展开下拉菜单的回调
87
+ dropdownVisibleChange: {
88
+ type: Function,
89
+ default: (open) => {
90
+ console.log('dropdownVisibleChange', open);
91
+ }
92
+ },
93
+ },
94
+ methods: {
95
+ click(msg) {
96
+ // 子组件 input的事件回调
97
+ // 实现 改变msg值
98
+ // this.user = '123';
99
+ console.log(msg);
100
+ }
101
+ },
102
+ render() {
103
+ return (
104
+ <div>
105
+ <a-select show-search placeholder={this.placeholder} option-filter-prop="children" style={this.css}
106
+ onfocus={this.focus} onblur={this.blur} onchange={this.change} oninputKeydown={this.inputKeydown} defaultValue={this.defaultValue}>
107
+ {
108
+ this.data.map(item => {
109
+ return <a-select-option value={item}>{item}</a-select-option>
110
+ })
111
+ }
112
+ </a-select>
113
+ </div>
114
+ );
115
+ }
116
+ };
@@ -17,7 +17,12 @@ const routes: Array<RouteConfig> = [
17
17
  // this generates a separate chunk (about.[hash].js) for this route
18
18
  // which is lazy-loaded when the route is visited.
19
19
  component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
20
- }
20
+ },
21
+ {
22
+ path: '/file',
23
+ name: 'file',
24
+ component: () => import('../views/File/index.vue')
25
+ },
21
26
  ]
22
27
 
23
28
  const router = new VueRouter({
@@ -1,22 +1,50 @@
1
+ import * as XLSX from "xlsx";
1
2
 
3
+ namespace EMacro {
2
4
 
3
- const selectFile = (_options: any = { multiple: true }) => {
4
- return new Promise((res, rej) => {
5
- let options = {
6
- accept: "*/*",
7
- multiple: true,
8
- };
9
- if (_options) {
10
- options.accept = _options.accept;
11
- options.multiple = _options.multiple;
5
+ export class File {
6
+
7
+ private static selectFile(options: any = { multiple: true, accept: "*/*" }) {
8
+ return new Promise((res: (value: FileList) => void, rej) => {
9
+ const el = document.createElement("input");
10
+ el.type = "file";
11
+ el.accept = options.accept;
12
+ el.multiple = options.multiple;
13
+ el.addEventListener("change", (_) => {
14
+ try {
15
+ if (el.files === null) {
16
+ rej(null)
17
+ } else {
18
+ res(el.files);
19
+ }
20
+ } catch (error) {
21
+ rej(error)
22
+ }
23
+ });
24
+ el.click();
25
+ });
26
+ }
27
+
28
+ public static readLocalExcel(onloadend: (file, workbook) => void, options: any = { multiple: true, accept: "*/*" }) {
29
+
30
+ this.selectFile(options).then((files: FileList) => {
31
+ for (let i = 0; i < files.length; i++) {
32
+ const file = files[i];
33
+ let reader = new FileReader();
34
+ reader.readAsArrayBuffer(file);
35
+ reader.onloadend = async function (e: any) {
36
+ let workbook = XLSX.read(e.target.result, { type: "binary" });
37
+ onloadend(file, workbook);
38
+ }
39
+ }
40
+ }).catch(e => {
41
+ throw e;
42
+ })
12
43
  }
13
- const el = document.createElement("input");
14
- el.type = "file";
15
- el.accept = options.accept;
16
- el.multiple = options.multiple;
17
- el.addEventListener("change", (_) => {
18
- res(el.files);
19
- });
20
- el.click();
21
- });
22
- }
44
+
45
+ }
46
+
47
+ }
48
+
49
+
50
+ export default EMacro;
@@ -0,0 +1,15 @@
1
+ .app-container {
2
+ height: 100%;
3
+ width: 100%;
4
+ margin: 0;
5
+ padding: 0;
6
+ }
7
+
8
+
9
+ .click-button {
10
+ padding: 10px;
11
+ font-size: 16px;
12
+ color: white;
13
+ border-radius: 15px;
14
+ background-color: blue;
15
+ }
@@ -0,0 +1,74 @@
1
+ <template>
2
+ <div class="app-container">
3
+ <button class="click-button" @click="test1">读取excel</button>
4
+ </div>
5
+ </template>
6
+
7
+ <script lang="ts">
8
+ import { Component, Prop, Vue } from "vue-property-decorator";
9
+
10
+ import $ from "jquery";
11
+
12
+ import * as echarts from "echarts";
13
+ import EMacro from "../../utilities/File";
14
+
15
+ /// <reference path = "../../utilities/File.ts" />
16
+
17
+ @Component({
18
+ components: {},
19
+ })
20
+ @Component
21
+ export default class Page extends Vue {
22
+ @Prop(Number) readonly msg!: number | undefined;
23
+ @Prop() private name!: string;
24
+
25
+ private currentTime = "";
26
+
27
+ public data_0 = {
28
+ page_index: 0,
29
+ page_size: 3,
30
+ data: [
31
+ { a: "面料类", b: "16500", c: "12063", d: "45.5%" },
32
+ { a: "面料类", b: "26500", c: "12063", d: "45.5%" },
33
+ { a: "面料类", b: "36500", c: "12063", d: "45.5%" },
34
+ { a: "面料类", b: "46500", c: "12063", d: "45.5%" },
35
+ { a: "面料类", b: "56500", c: "12063", d: "45.5%" },
36
+ ],
37
+ };
38
+
39
+ // 计算属性
40
+ private get reversedMessage(): string {
41
+ return this.currentTime;
42
+ }
43
+
44
+ public test1(): void {
45
+ EMacro.File.readLocalExcel((file, workbook) => {
46
+ console.log("file", file);
47
+ console.log("workbook", workbook);
48
+ console.log("数据", workbook.Sheets["工作表1"]["G32"].h);
49
+ });
50
+ }
51
+
52
+ // 生命周期
53
+ private created(): void {}
54
+ private mounted(): void {
55
+ this.$nextTick(() => {
56
+ console.log("调用", EMacro);
57
+ });
58
+ }
59
+ private updated(): void {}
60
+ private destroyed(): void {}
61
+ }
62
+ </script>
63
+
64
+ <style lang="less" scoped>
65
+ @import "index.less";
66
+
67
+ .app-container /deep/ .el-table .unchecked {
68
+ background: rgba(255, 192, 203, 0.35) !important;
69
+
70
+ td {
71
+ color: #fff !important;
72
+ }
73
+ }
74
+ </style>
package/tsconfig.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "outDir": "./dist/", // 打包到的目录
5
5
  "sourceMap": true, // 是否生成sourceMap(用于浏览器调试)
6
6
  "noImplicitAny": false,
7
- "noUnusedLocals": true,
7
+ "noUnusedLocals": false,
8
8
  "noUnusedParameters": true,
9
9
  "declaration": true, // 是否生成声明文件
10
10
  "declarationDir": "./dist/types/", // 声明文件打包的位置
package/webpack.config.js CHANGED
@@ -3,9 +3,14 @@
3
3
  const path = require("path");
4
4
  // const HtmlWebpackPlugin = require("html-webpack-plugin");
5
5
  const MiniCssExtractPlugin = require("mini-css-extract-plugin");
6
+ const webpack = require('webpack');
6
7
 
7
8
  const isProduction = process.env.NODE_ENV == "production";
8
9
 
10
+ function resolve(dir) {
11
+ return path.join(__dirname, dir)
12
+ }
13
+
9
14
  const stylesHandler = isProduction
10
15
  ? MiniCssExtractPlugin.loader
11
16
  : "style-loader";
@@ -16,7 +21,7 @@ const config = {
16
21
  outputModule: true,
17
22
  },
18
23
  output: {
19
- filename:'emacroh5lib.min.js',
24
+ filename: 'emacroh5lib.min.js',
20
25
  path: path.resolve(__dirname, "dist"),
21
26
  library: {
22
27
  // do not specify a `name` here
@@ -31,6 +36,12 @@ const config = {
31
36
  // new HtmlWebpackPlugin({
32
37
  // template: "index.html",
33
38
  // }),
39
+ new webpack.ProvidePlugin({
40
+ echarts: 'echarts',
41
+ THREE: 'three',
42
+ jQuery: "jquery",
43
+ $: "jquery"
44
+ })
34
45
 
35
46
  // Add your plugins here
36
47
  // Learn more about plugins from https://webpack.js.org/configuration/plugins/
@@ -55,13 +66,17 @@ const config = {
55
66
  type: "asset/inline"
56
67
  },
57
68
 
69
+
58
70
  // Add your rules for custom modules here
59
71
  // Learn more about loaders from https://webpack.js.org/loaders/
60
72
  ],
61
73
  },
62
74
  resolve: {
75
+ alias: {
76
+ '@': resolve('src')
77
+ },
63
78
  extensions: [".tsx", ".ts", ".js"],
64
- },
79
+ }
65
80
  };
66
81
 
67
82
  module.exports = () => {
@@ -72,5 +87,12 @@ module.exports = () => {
72
87
  } else {
73
88
  config.mode = "development";
74
89
  }
90
+
91
+ // 打包文件大小配置
92
+ config.performance = {
93
+ maxEntrypointSize: 10 * 1024 * 1024,
94
+ maxAssetSize: 10 * 1024 * 1024
95
+ }
96
+
75
97
  return config;
76
98
  };