htui-yllkbz 1.2.39 → 1.2.43

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.
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "htui-yllkbz",
3
- "version": "1.2.39",
3
+ "version": "1.2.43",
4
4
  "typings": "types/index.d.ts",
5
5
  "main": "lib/htui.common.js",
6
6
  "style": "lib/htui.css",
@@ -24,7 +24,6 @@
24
24
  "element-ui": "^2.14.1",
25
25
  "html2canvas": "1.0.0-rc.1",
26
26
  "htui-yllkbz": "^1.2.35",
27
- "jspdf": "^1.5.3",
28
27
  "mavon-editor": "^2.10.4",
29
28
  "moment": "^2.29.1",
30
29
  "vue": "^2.6.11",
@@ -5,10 +5,11 @@
5
5
  * @Author: hutao
6
6
  * @Date: 2021-11-11 11:23:24
7
7
  * @LastEditors: hutao
8
- * @LastEditTime: 2022-01-04 09:30:09
8
+ * @LastEditTime: 2022-01-10 13:40:53
9
9
  -->
10
10
  <template>
11
11
  <div v-loading="state.loading">
12
+
12
13
  <article>
13
14
  <el-table ref="comTable"
14
15
  :height="height"
@@ -42,28 +43,39 @@
42
43
  @cell-click="(row, column, cell, event)=>$emit('cell-click',row, column, cell, event)"
43
44
  @cell-dblclick="(row, column, cell, event)=>$emit('cell-dblclick',row, column, cell, event)">
44
45
  <el-table-column width="55"
46
+ :resizable="false"
45
47
  v-if="checked"
46
48
  :reserve-selection="reserveSelection"
47
49
  :selectable="selectable"
48
50
  type='selection'>
49
51
  </el-table-column>
50
52
  <el-table-column v-if="!hideOrder"
53
+ :resizable="false"
51
54
  :label="keyName===undefined?'序号':keyName"
52
55
  :align="'center'"
53
56
  width="55">
54
57
  <template slot="header">
55
- <slot :name="'header_order'"></slot>
58
+ <slot :name="'header_order'">
59
+ <div @click="showFilterModel"
60
+ v-if="showFilter"
61
+ title="筛选排序">
62
+ <el-button type="text"><i class="el-icon-s-grid"></i></el-button>
63
+ </div>
64
+ <span v-else>{{keyName||'序号'}}</span>
65
+
66
+ </slot>
56
67
  </template>
57
68
  <template slot-scope="scope">
58
69
  {{(state.pageInfo.currentPage-1)*state.pageInfo.pageSize+(scope.$index+1)}}
59
70
  </template>
60
71
  </el-table-column>
61
- <template v-for="item in columns">
72
+ <template v-for="item in showColumns">
62
73
  <el-table-column :label="item.title"
63
74
  :key='item.key'
64
75
  :fixed="item.fixed"
65
76
  :align="item.align"
66
77
  v-if="!item.hide"
78
+ :resizable="item.resizable"
67
79
  :header-align="item.headerAlign"
68
80
  :column-key="item.columnKey"
69
81
  :class-name="item.className"
@@ -160,6 +172,39 @@
160
172
 
161
173
  </el-row>
162
174
  </footer>
175
+ <!-- 详情弹框 -->
176
+ <el-dialog :visible.sync="state.visibleFilter"
177
+ title="属性设置"
178
+ :close-on-click-modal="true"
179
+ width="400px"
180
+ :center="true">
181
+ <div style='overflow:hidden;height:500px'>
182
+ <el-scrollbar style='height: calc(100% + 17px)'>
183
+ <el-tree :data="columns"
184
+ ref="tree"
185
+ show-checkbox
186
+ node-key="key"
187
+ :check-on-click-node="false"
188
+ @node-drag-start="handleDragStart"
189
+ @node-drag-enter="handleDragEnter"
190
+ @node-drag-leave="handleDragLeave"
191
+ @node-drag-over="handleDragOver"
192
+ @node-drag-end="handleDragEnd"
193
+ @node-drop="handleDrop"
194
+ :default-checked-keys="state.showColumnKeys"
195
+ @check-change="changeColumns"
196
+ :allow-drag="allowDrag"
197
+ draggable
198
+ :allow-drop="allowDrop">
199
+ <span class="custom-tree-node"
200
+ slot-scope="{ node, data }">
201
+ <slot :name="'header_'+data.key"
202
+ :column="data">{{data.title}}</slot>
203
+ </span>
204
+ </el-tree>
205
+ </el-scrollbar>
206
+ </div>
207
+ </el-dialog>
163
208
  </div>
164
209
  </template>
165
210
  <script lang='ts'>
@@ -169,6 +214,13 @@ import PageInfo from "@/packages/PageInfo/index.vue";
169
214
  interface State {
170
215
  pageInfo: PageInfoType;
171
216
  loading: boolean;
217
+ /** 展示出来的列表名 */
218
+ showColumns: Column[];
219
+ showColumnKeys: string[];
220
+ /** 是否展示筛选框 */
221
+ visibleFilter: boolean;
222
+ /** 当前拖动的数据 */
223
+ currentColumn?: Column;
172
224
  }
173
225
  @Component({
174
226
  name: "HtTable",
@@ -182,6 +234,10 @@ export default class HtTable extends Vue {
182
234
  @Prop() data!: any[];
183
235
  /** 序号对应的名称 */
184
236
  @Prop() keyName?: string;
237
+ /** 是否增加筛选功能 */
238
+ @Prop() showFilter?: boolean;
239
+ /** table的唯一值用于table数据筛选 */
240
+ @Prop() uuId?: string;
185
241
  /** 是否隐藏分页 */
186
242
  @Prop() hidePage!: boolean;
187
243
  /** 是否启用复选框 */
@@ -215,9 +271,84 @@ export default class HtTable extends Vue {
215
271
  skipCount: 0,
216
272
  totalCount: 0,
217
273
  },
274
+ showColumns: [],
275
+ currentColumn: undefined,
276
+ visibleFilter: false,
277
+ showColumnKeys: [],
218
278
  };
219
279
  created() {
220
280
  this.setPageInfo(this.pageInfo);
281
+ this.state.showColumns = this.columns;
282
+ if (this.uuId) {
283
+ //通过uuid获取缓存起来的header显示信息
284
+ const showKeys: string | null = window.localStorage.getItem(
285
+ "table_" + this.uuId
286
+ );
287
+ if (showKeys) {
288
+ this.state.showColumnKeys = JSON.parse(showKeys);
289
+ } else {
290
+ this.creatInitColumnKey();
291
+ }
292
+ } else {
293
+ this.creatInitColumnKey();
294
+ }
295
+ }
296
+ creatInitColumnKey() {
297
+ this.state.showColumnKeys = this.columns.reduce((arr: string[], item) => {
298
+ arr.push(item.key);
299
+ return arr;
300
+ }, []);
301
+ }
302
+ changeColumns(node: any, checked: boolean) {
303
+ let { showColumnKeys } = this.state;
304
+ if (checked) {
305
+ showColumnKeys.push(node.key);
306
+ } else {
307
+ showColumnKeys = showColumnKeys.filter((item) => item !== node.key);
308
+ }
309
+ this.state.showColumnKeys = showColumnKeys;
310
+ }
311
+ handleDragStart(node: any) {
312
+ this.state.currentColumn = node.data;
313
+ }
314
+ handleDragEnter() {
315
+ // console.log("tree drag enter: ", dropNode.label);
316
+ }
317
+ handleDragLeave() {
318
+ //console.log("tree drag leave: ", dropNode.label);
319
+ }
320
+ handleDragOver() {
321
+ // console.log("tree drag over: ", dropNode.label);
322
+ }
323
+ handleDragEnd(draggingNode: any, dropNode: any, dropType: string) {
324
+ const { showColumns, currentColumn, showColumnKeys } = this.state;
325
+ // if ((dropType === "before" || dropType === "after") && currentColumn) {
326
+ // const data = showColumns.filter(
327
+ // (item) => item.key !== currentColumn?.key
328
+ // );
329
+ // const index = data.findIndex((item) => item.key === dropNode.data.key);
330
+ // dropType === "before"
331
+ // ? data.splice(index, 0, currentColumn)
332
+ // : data.splice(index + 1, 0, currentColumn);
333
+ // console.log("tree drag end: ", currentColumn, showColumnKeys);
334
+ if (currentColumn && showColumnKeys.includes(currentColumn.key)) {
335
+ setTimeout(() => {
336
+ (this.$refs.tree as any).setChecked(currentColumn, true);
337
+ }, 0);
338
+ }
339
+
340
+ // }
341
+ }
342
+ handleDrop() {
343
+ // console.log("tree drop: ", dropNode, dropType);
344
+ }
345
+ /** 节点是否被插入 */
346
+ allowDrop(draggingNode: any, dropNode: any, type: string) {
347
+ return type !== "inner";
348
+ }
349
+ /** 节点是否允许拖动 */
350
+ allowDrag(draggingNode: any) {
351
+ return !draggingNode.data.disabled;
221
352
  }
222
353
  /** 处理table里面根据字段获取对应的值 */
223
354
  getPropByPath(obj: any, path: string, strict = true) {
@@ -246,6 +377,9 @@ export default class HtTable extends Vue {
246
377
  // };
247
378
  return tempObj ? tempObj[keyArr[i]] : null;
248
379
  }
380
+ showFilterModel() {
381
+ this.state.visibleFilter = true;
382
+ }
249
383
  /** 遍历循环展示row数据 */
250
384
  showValue(row: any, key: string) {
251
385
  if (key) {
@@ -270,6 +404,25 @@ export default class HtTable extends Vue {
270
404
  return "";
271
405
  }
272
406
  }
407
+ /** 获取显示出来的table头信息 */
408
+ get showColumns() {
409
+ const { showColumnKeys, showColumns } = this.state;
410
+ let obj: any = {};
411
+ for (const key in showColumnKeys) {
412
+ obj = { ...obj, [showColumnKeys[key]]: true };
413
+ }
414
+ /** 缓存起来下次使用 --todo只做了显示没有做排序缓存 */
415
+ if (this.uuId) {
416
+ window.localStorage.setItem(
417
+ "table_" + this.uuId,
418
+ JSON.stringify(showColumnKeys)
419
+ );
420
+ }
421
+
422
+ const data = showColumns.filter((item) => obj[item.key as string]);
423
+ return data;
424
+ }
425
+
273
426
  /** 监听 */
274
427
  @Watch("pageInfo")
275
428
  setPageInfo(val?: PageInfoType) {
@@ -283,6 +436,10 @@ export default class HtTable extends Vue {
283
436
  };
284
437
  }
285
438
  }
439
+ @Watch("columns")
440
+ setColumns(columns?: Column[]) {
441
+ this.state.showColumns = columns || [];
442
+ }
286
443
  }
287
444
  </script>
288
445
  <style lang='scss' scoped></style>
@@ -4,7 +4,7 @@
4
4
  * @Author: hutao
5
5
  * @Date: 2021-10-21 10:08:41
6
6
  * @LastEditors: hutao
7
- * @LastEditTime: 2021-12-29 09:55:45
7
+ * @LastEditTime: 2022-01-04 09:47:12
8
8
  */
9
9
 
10
10
  // 导入组件
@@ -18,10 +18,10 @@ import HtExport from './HtExport/index'
18
18
  import HtUpload from './HtUpload/index'
19
19
  import HtMd from './HtMd/index'
20
20
  import HtCountDown from './HtCountDown/index'
21
- import HtExportPdf from './HtExportPdf/index'
21
+
22
22
 
23
23
  // 存储组件列表
24
- const components = [HtSelectTable, HtPagination, HtTable, HtExport, HtUpload, HtMd, HtCountDown, HtExportPdf]
24
+ const components = [HtSelectTable, HtPagination, HtTable, HtExport, HtUpload, HtMd, HtCountDown]
25
25
  // 定义 install 方法,接收 Vue 作为参数。如果使用 use 注册插件,则所有的组件都将被注册
26
26
  const install = function (Vue: any) {
27
27
  // 判断是否安装
@@ -37,6 +37,6 @@ export default {
37
37
  // 导出的对象必须具有 install,才能被 Vue.use() 方法安装
38
38
  install,
39
39
  // 以下是具体的组件列表
40
- HtSelectTable, HtPagination, HtTable, HtExport, HtUpload, HtMd, HtCountDown, HtExportPdf
40
+ HtSelectTable, HtPagination, HtTable, HtExport, HtUpload, HtMd, HtCountDown
41
41
  }
42
42
 
@@ -4,7 +4,7 @@
4
4
  * @Author: hutao
5
5
  * @Date: 2021-10-25 17:05:17
6
6
  * @LastEditors: hutao
7
- * @LastEditTime: 2021-12-23 11:33:43
7
+ * @LastEditTime: 2022-01-10 09:32:46
8
8
  */
9
9
  /** 初始的默认条数 */
10
10
  export const defalutPageSize = 10
@@ -53,6 +53,7 @@ export interface Column {
53
53
 
54
54
  key: string;
55
55
  title: string;
56
+
56
57
  width?: number | string;
57
58
  minWidth?: number | string;
58
59
  fixed?: 'left' | 'rigth' | boolean;
@@ -68,11 +69,13 @@ export interface Column {
68
69
  hide?: boolean;
69
70
  /** 时间是否跨行展示 */
70
71
  spread?: boolean;
71
- /** 通过type展示相应的数据 用户id|部门id|时间格式化*/
72
- type?: 'userId' | 'org' | 'time' | 'common',
72
+ /** 通过type展示相应的数据 用户id|部门id|时间格式化|是否布尔值*/
73
+ type?: 'userId' | 'org' | 'time' | 'common' | 'boolean',
73
74
  /** 只有当type='common'时候有效 数据类型个ca common里面的一样但不包括时间 时间使用time */
74
75
  commonType?: 'userId' | 'departmentId' | 'baseDataId' | 'roleId' | 'baseDataName' | 'baseDataValue',
75
76
  showOverflowTooltip?: boolean,
77
+ /** 筛选时候是否禁用 */
78
+ disabled?: boolean;
76
79
  }
77
80
  export interface PageInfoType {
78
81
  currentPage: number;
@@ -4,13 +4,11 @@
4
4
  * @Author: hutao
5
5
  * @Date: 2021-11-15 14:41:40
6
6
  * @LastEditors: hutao
7
- * @LastEditTime: 2022-01-04 09:31:44
7
+ * @LastEditTime: 2022-01-10 09:32:22
8
8
  -->
9
9
  <template>
10
10
  <div>
11
- <HtExportPdf selector="f"
12
- ref="pdf"
13
- :title="'测试'"></HtExportPdf>
11
+
14
12
  <el-button type=""
15
13
  @click="test">test</el-button>
16
14
  <!-- <ht-count-down :stopwatch="true"
@@ -62,7 +60,6 @@
62
60
  import { Component, Vue } from "vue-property-decorator";
63
61
  import HtTable from "@/packages/HtTable/index.vue";
64
62
  import HtCountDown from "@/packages/HtCountDown/index.vue";
65
- import HtExportPdf from "@/packages/HtExportPdf/index.vue";
66
63
  import HtUi from "htui-yllkbz";
67
64
  import "htui-yllkbz/lib/htui.css";
68
65
  Vue.use(HtUi);
@@ -78,7 +75,6 @@ interface State {
78
75
  components: {
79
76
  HtTable,
80
77
  HtCountDown,
81
- HtExportPdf,
82
78
  },
83
79
  })
84
80
  export default class Index extends Vue {
@@ -93,6 +89,7 @@ export default class Index extends Vue {
93
89
  age: 12,
94
90
  sex: 0,
95
91
  id: 1,
92
+
96
93
  test: { title: "测试" },
97
94
  time: "2022-01-20T00:00:00+08:00",
98
95
  },
@@ -134,6 +131,7 @@ export default class Index extends Vue {
134
131
  title: "姓名",
135
132
  key: "test.title",
136
133
  width: "300px",
134
+ disabled: true,
137
135
  },
138
136
  {
139
137
  title: "姓额外名",
@@ -1,16 +0,0 @@
1
- /*
2
- * @Descripttion:导出PDF
3
- * @version:
4
- * @Author: hutao
5
- * @Date: 2021-11-15 15:00:57
6
- * @LastEditors: hutao
7
- * @LastEditTime: 2021-12-29 09:53:53
8
- */
9
- import HtExportPdf from "./index.vue";
10
-
11
- (HtExportPdf as any).install = function (Vue: any) {
12
-
13
- Vue.component("HtExportPdf", HtExportPdf);
14
- };
15
-
16
- export default HtExportPdf;
@@ -1,46 +0,0 @@
1
- <!--
2
- * @Descripttion: 导出PDF
3
- * @version:
4
- * @Author: hutao
5
- * @Date: 2021-09-02 09:03:43
6
- * @LastEditors: hutao
7
- * @LastEditTime: 2021-12-29 14:25:39
8
- -->
9
- <template>
10
- <div @click="exportPdf">
11
- <slot>
12
- <el-button type="primary">
13
- 导出PDF
14
- </el-button>
15
- </slot>
16
- <div ref="demo">dsdsdsdsdsds</div>
17
- </div>
18
- </template>
19
- <script lang='ts'>
20
- import { Component, Prop, Vue } from "vue-property-decorator";
21
- import htmlToPdf from "@/unit/htmlToPdf.js";
22
- /** 设置axios返回类型 */
23
- Vue.config.productionTip = false;
24
- interface State {
25
- /** 数据状态 */
26
- loading: boolean;
27
- }
28
- @Component
29
- export default class HtExportPdf extends Vue {
30
- /** 导出文件对应的id */
31
- @Prop() selector!: string;
32
- /** 文件导出名 */
33
- @Prop() title!: string;
34
- exportPdf(t: any) {
35
- console.log("this.selector", this.selector, t);
36
- if (!this.selector) {
37
- this.$notify.error("请用selector传入需要导出的内容id");
38
- return;
39
- }
40
- console.log('document.querySelector("#ht-pdf")', this.$refs.demo);
41
- htmlToPdf.downloadPDF(t, this.title);
42
- }
43
- }
44
- </script>
45
-
46
- <style lang='scss' scoped></style>
@@ -1,108 +0,0 @@
1
- /*
2
- * @Descripttion:
3
- * @version:
4
- * @Author: hutao
5
- * @Date: 2021-12-29 09:52:58
6
- * @LastEditors: hutao
7
- * @LastEditTime: 2021-12-29 14:15:53
8
- */
9
- //不使用JQuery版的
10
-
11
- import html2canvas from 'html2canvas';
12
- import JsPDF from 'jspdf';
13
- /**
14
- * @param ele 要生成 pdf 的DOM元素(容器)
15
- * @param padfName PDF文件生成后的文件名字
16
- * */
17
-
18
- function downloadPDF(ele, pdfName){
19
-
20
- const eleW = ele.offsetWidth;// 获得该容器的宽
21
- const eleH = ele.offsetHeight;// 获得该容器的高
22
-
23
-
24
- const eleOffsetTop = ele.offsetTop; // 获得该容器到文档顶部的距离
25
- const eleOffsetLeft = ele.offsetLeft; // 获得该容器到文档最左的距离
26
-
27
- const canvas = document.createElement("canvas");
28
- let abs = 0;
29
-
30
- const winIn = document.documentElement.clientWidth || document.body.clientWidth; // 获得当前可视窗口的宽度(不包含滚动条)
31
- const winOut = window.innerWidth; // 获得当前窗口的宽度(包含滚动条)
32
-
33
- if(winOut>winIn){
34
- // abs = (win_o - win_i)/2; // 获得滚动条长度的一半
35
- abs = (winOut - winIn)/2; // 获得滚动条宽度的一半
36
- // console.log(a, '新abs');
37
- }
38
-
39
- canvas.width = eleW * 2; // 将画布宽&&高放大两倍
40
- canvas.height = eleH * 2;
41
-
42
-
43
-
44
-
45
- const context = canvas.getContext("2d");
46
-
47
- context.scale(2, 2);
48
-
49
- context.translate(-eleOffsetLeft -abs, -eleOffsetTop);
50
- // 这里默认横向没有滚动条的情况,因为offset.left(),有无滚动条的时候存在差值,因此
51
- // translate的时候,要把这个差值去掉
52
-
53
- // html2canvas(element).then( (canvas)=>{ //报错
54
- // html2canvas(element[0]).then( (canvas)=>{
55
- console.log('baocuo',);
56
- html2canvas( ele, {
57
- dpi: 300,
58
- // allowTaint: true, //允许 canvas 污染, allowTaint参数要去掉,否则是无法通过toDataURL导出canvas数据的
59
- useCORS:true //允许canvas画布内 可以跨域请求外部链接图片, 允许跨域请求。
60
- }).then((canvas) => {
61
- console.log('baocuo-------1',);
62
- setTimeout(() => {
63
- const contentWidth = canvas.width;
64
- const contentHeight = canvas.height;
65
- //一页pdf显示html页面生成的canvas高度;
66
- const pageHeight = contentWidth / 592.28 * 841.89;
67
- //未生成pdf的html页面高度
68
- let leftHeight = contentHeight;
69
- //页面偏移
70
- let position = 0;
71
- //a4纸的尺寸[595.28,841.89],html页面生成的canvas在pdf中图片的宽高
72
- const imgWidth = 595.28;
73
- const imgHeight = 595.28/contentWidth * contentHeight;
74
-
75
- const pageData = canvas.toDataURL('image/jpeg', 1.0);
76
- const pdf = new JsPDF('', 'pt', 'a4');
77
-
78
- //有两个高度需要区分,一个是html页面的实际高度,和生成pdf的页面高度(841.89)
79
- //当内容未超过pdf一页显示的范围,无需分页
80
- if (leftHeight < pageHeight) {
81
- //在pdf.addImage(pageData, 'JPEG', 左,上,宽度,高度)设置在pdf中显示;
82
- pdf.addImage(pageData, 'JPEG', 0, 0, imgWidth, imgHeight);
83
- // pdf.addImage(pageData, 'JPEG', 20, 40, imgWidth, imgHeight);
84
- } else { // 分页
85
- while(leftHeight > 0) {
86
- pdf.addImage(pageData, 'JPEG', 0, position, imgWidth, imgHeight);
87
- leftHeight -= pageHeight;
88
- position -= 841.89;
89
- //避免添加空白页
90
- if(leftHeight > 0) {
91
- pdf.addPage();
92
- }
93
- }
94
- }
95
-
96
- //可动态生成
97
- pdf.save(pdfName);
98
- },1000)
99
-
100
- })
101
-
102
-
103
- }
104
-
105
-
106
- export default {
107
- downloadPDF
108
- }