adtec-core-package 1.0.0 → 1.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adtec-core-package",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "scripts": {
@@ -31,7 +31,9 @@
31
31
  "vue-focus-lock": "^3.0.0",
32
32
  "vue-img-viewr": "2.0.11",
33
33
  "vue-router": "^4.5.0",
34
- "wujie-vue3": "^1.0.24"
34
+ "wujie-vue3": "^1.0.24",
35
+ "xlsx-js-style": "^1.2.0",
36
+ "linq-to-ts": "^1.3.0"
35
37
  },
36
38
  "devDependencies": {
37
39
  "@tsconfig/node22": "^22.0.0",
@@ -135,7 +135,7 @@ const getStyleComp = computed(() => {
135
135
  height: heightComp.value,
136
136
  width: widthComp.value,
137
137
  flex: getFlex(),
138
- overflow: 'auto',
138
+ overflow: 'initial',
139
139
  boxSizing: 'border-box',
140
140
  minWidth: props.minWidth ? props.minWidth : '',
141
141
  flexShrink: flexShrinkComp.value,
@@ -1,58 +1,28 @@
1
1
  <!--创建人 丁盼-->
2
- <!--说明: ElTable动态列-->
2
+ <!--说明: ElTableDynamicColumn-->
3
3
  <!--创建时间: 2025/3/19 14:25-->
4
4
  <!--修改时间: 2025/3/19 14:25-->
5
5
  <template>
6
6
  <el-table-column :key="getItemKey(column)" v-bind="column">
7
7
  <template #default v-if="column.children && column.children.length > 0">
8
- <el-table-column-dynamic
9
- v-for="item in column.children"
10
- :key="getItemKey(item)"
11
- :column="item">
12
- <template v-slot:[getSlotNameDefault(item.prop)]="scope">
13
- <slot
14
- :name="getSlotNameDefault(item.prop)"
15
- :row="scope.row"
16
- :column="scope.column"
17
- :$index="scope.$index"></slot>
18
- </template>
19
- <template v-slot:[getSlotNameHeader(item.prop)]="scope">
20
- <slot
21
- :name="getSlotNameHeader(item.prop)"
22
- :column="scope.column"
23
- :$index="scope.$index"></slot>
24
- </template>
25
-
26
- </el-table-column-dynamic>
8
+ <template v-for="item in column.children" :key="getItemKey(item)">
9
+ <el-table-column-dynamic :column="item">
10
+ <template #default="scope">
11
+ <slot :row="scope.row" :column="scope.column" :$index="scope.$index"></slot>
12
+ </template>
13
+ </el-table-column-dynamic>
14
+ </template>
27
15
  </template>
28
- <template #default="scope" v-if="slots[getSlotNameDefault(column.prop)]">
29
- <slot
30
- :name="getSlotNameDefault(column.prop)"
31
- :row="scope.row"
32
- :column="scope.column"
33
- :$index="scope.$index"></slot>
34
- </template>
35
- <template #header="scope" v-if="slots[getSlotNameHeader(column.prop)]">
36
- <slot
37
- :name="getSlotNameHeader(column.prop)"
38
- :column="scope.column"
39
- :$index="scope.$index"></slot>
16
+ <template #default="scope">
17
+ <slot :row="scope.row" :column="scope.column" :$index="scope.$index"></slot>
40
18
  </template>
41
19
  </el-table-column>
42
20
  </template>
43
21
  <script setup lang="ts">
44
22
  import type { TableColumnCtx } from 'element-plus/es/components/table/src/table-column/defaults'
45
- import { useSlots } from 'vue'
46
23
  defineProps<{
47
24
  column: TableColumnCtx<any> // 列配置数据
48
25
  }>()
49
- const getSlotNameDefault=(name:any)=>{
50
- return name
51
- }
52
- const getSlotNameHeader=(name:any)=>{
53
- return name+'H'
54
- }
55
- const slots = useSlots()
56
26
  // 假设每一项都有一个唯一的 id 属性
57
27
  function getItemKey(item: TableColumnCtx<any>): string {
58
28
  return item?.prop || String(Math.random()) // 如果没有 id,使用随机字符串作为 key
@@ -1,66 +1,335 @@
1
- import elTableTool from '../components/Table/ElTableTool.ts'
2
- import { ElMessage } from 'element-plus'
3
- /**
4
- * Create by丁盼
5
- * 说明: FrameworkUtils
6
- * 创建时间: 2025/3/12 09:24
7
- * 修改时间: 2025/3/12 09:24
8
- */
9
- export default {
10
- /**
11
- * 校验表格数据是否为空
12
- * @param table 表格对象
13
- * @param rules 校验规则
14
- */
15
- validateTableData(table: any, rules: any): Boolean {
16
- return elTableTool.validateTableData(table, rules)
17
- },
18
- /**
19
- * 获取系统分页数
20
- */
21
- getPageSize(): number {
22
- try {
23
- const systemConfig = JSON.parse(localStorage.getItem('systemConfig') + '')
24
- if (systemConfig && systemConfig['pageSize'] + '') {
25
- return Number(systemConfig['pageSize'] + '')
26
- } else {
27
- return 50
28
- }
29
- } catch {
30
- return 50
31
- }
32
- },
33
- /**
34
- * 提示错误信息
35
- * @param err
36
- */
37
- messageError(err: any) {
38
- if (err.code) {
39
- if (err.code === '500') {
40
- ElMessage.error('系统错误,请与管理员联系!')
41
- } else if (
42
- err.code === '10402' ||
43
- err.code === '10403' ||
44
- err.code === '10404' ||
45
- err.code === '10500' ||
46
- err.code === '10505' ||
47
- err.code === '10506' ||
48
- err.code === '10507'
49
- ) {
50
- ElMessage.error(err.msg)
51
- } else if (err.code === '10504') {
52
- ElMessage.warning(err.msg)
53
- }
54
- } else {
55
- ElMessage.error(err.message)
56
- }
57
- },
58
- // /**
59
- // * 判断是否有操作权限
60
- // * @param operCode
61
- // * @constructor
62
- // */
63
- // IsOperationAuth(operCode:string): Boolean {
64
- // return permission.IsOperationAuth(operCode)
65
- // }
66
- }
1
+ import elTableTool from '../components/Table/ElTableTool.ts'
2
+ import { ElMessage } from 'element-plus'
3
+ import * as XLSX from 'xlsx-js-style'
4
+ import { Linq } from 'linq-to-ts'
5
+ /**
6
+ * Create by丁盼
7
+ * 说明: FrameworkUtils
8
+ * 创建时间: 2025/3/12 09:24
9
+ * 修改时间: 2025/3/12 09:24
10
+ */
11
+ export default {
12
+ /**
13
+ * 校验表格数据是否为空
14
+ * @param table 表格对象
15
+ * @param rules 校验规则
16
+ */
17
+ validateTableData(table: any, rules: any): Boolean {
18
+ return elTableTool.validateTableData(table, rules)
19
+ },
20
+ /**
21
+ * 获取系统分页数
22
+ */
23
+ getPageSize(): number {
24
+ try {
25
+ const systemConfig = JSON.parse(localStorage.getItem('systemConfig') + '')
26
+ if (systemConfig && systemConfig['pageSize'] + '') {
27
+ return Number(systemConfig['pageSize'] + '')
28
+ } else {
29
+ return 50
30
+ }
31
+ } catch {
32
+ return 50
33
+ }
34
+ },
35
+ /**
36
+ * 提示错误信息
37
+ * @param err
38
+ */
39
+ messageError(err: any) {
40
+ if (err.code) {
41
+ if (err.code === '500') {
42
+ ElMessage.error('系统错误,请与管理员联系!')
43
+ } else if (
44
+ err.code === '10402' ||
45
+ err.code === '10403' ||
46
+ err.code === '10404' ||
47
+ err.code === '10500' ||
48
+ err.code === '10505' ||
49
+ err.code === '10506' ||
50
+ err.code === '10507'
51
+ ) {
52
+ ElMessage.error(err.msg)
53
+ } else if (err.code === '10504') {
54
+ ElMessage.warning(err.msg)
55
+ }
56
+ } else {
57
+ ElMessage.error(err.message)
58
+ }
59
+ },
60
+ /**
61
+ * 导出excel
62
+ * @param title 标题
63
+ * @param fileName 文件名
64
+ * @param sheetName 工作表名
65
+ * @param columns 表头,参考ElTable列属性{property:'',width:'',label:'',colSpan:'',colSpan:'',level:'',children:[]}
66
+ * @param data 数据
67
+ * @param rowMerges 行合并配置
68
+ * [{
69
+ * conditions: ['groupNo'],//条件
70
+ * fields: ['groupNo', 'seMeetingSampleName'],//需要合并的列
71
+ * }]
72
+ * @param colMerges 列合并配置
73
+ * [
74
+ * {
75
+ * conditions: ['groupNo', 'seMeetingSampleName']//条件
76
+ * },
77
+ * ]
78
+ * @param customHeaderCallback 自定义标题回调函数
79
+ * rows: any[], 当前行对象
80
+ * dataColumns: any[],列对象
81
+ * merges: any[] 合并对象
82
+ * @param customFooterCallback 自定义页脚回调函数
83
+ * @constructor
84
+ */
85
+ exportExcel(
86
+ title: string,
87
+ fileName: string,
88
+ sheetName: string,
89
+ columns: any,
90
+ data: any,
91
+ rowMerges?: any[],
92
+ colMerges?: any[],
93
+ customHeaderCallback?: any,
94
+ customFooterCallback?: any,
95
+ ) {
96
+ const cl = columns
97
+ let rows: any[] = []
98
+ const cols: any[] = []
99
+ const dataColumns: any[] = []
100
+ const merges: any = []
101
+ this.generateColumns(cl, dataColumns)
102
+ //设置表头
103
+ if (customHeaderCallback) {
104
+ customHeaderCallback(rows, dataColumns, merges)
105
+ } else {
106
+ rows.push([
107
+ {
108
+ v: title,
109
+ t: 's',
110
+ s: {
111
+ font: { bold: true },
112
+ alignment: {
113
+ vertical: 'center', // 垂直居中
114
+ horizontal: 'center', // 水平居中
115
+ },
116
+ // border 边框属性
117
+ border: {
118
+ top: { style: 'thin' },
119
+ bottom: { style: 'thin' },
120
+ left: { style: 'thin' },
121
+ right: { style: 'thin' },
122
+ },
123
+ },
124
+ },
125
+ ])
126
+ //表头合并
127
+ merges.push({
128
+ s: { c: 0, r: 0 },
129
+ e: { c: dataColumns.length - 1, r: 0 },
130
+ })
131
+ }
132
+ //@ts-ignore
133
+ this.generateHeader(cl, rows, 0, merges)
134
+ //设置缺失单元格对象
135
+ let max = 0
136
+ rows.forEach((r: any) => {
137
+ if (max < r.length) {
138
+ max = r.length
139
+ }
140
+ })
141
+ const rowsS = [{ hpx: 30 }]
142
+ rows.forEach((r: any, index: number) => {
143
+ if (index > 0) {
144
+ rowsS.push({ hpx: 20 })
145
+ }
146
+ for (let i = 0; i < max; i++) {
147
+ if (!r[i]) {
148
+ r[i] = {
149
+ v: '',
150
+ t: 's',
151
+ s: {
152
+ font: { bold: true },
153
+ alignment: {
154
+ vertical: 'center', // 垂直居中
155
+ horizontal: 'center', // 水平居中
156
+ },
157
+ // border 边框属性
158
+ border: {
159
+ top: { style: 'thin' },
160
+ bottom: { style: 'thin' },
161
+ left: { style: 'thin' },
162
+ right: { style: 'thin' },
163
+ },
164
+ },
165
+ }
166
+ }
167
+ }
168
+ })
169
+ const data1 = JSON.parse(JSON.stringify(data))
170
+ data1.forEach((r: any, index: any) => {
171
+ r._orderNum = index + rows.length
172
+ })
173
+ //col单元格合并
174
+ if (colMerges) {
175
+ colMerges.forEach((m: any) => {
176
+ data1.forEach((r: any) => {
177
+ const set = new Set()
178
+ m.conditions.forEach((c: any) => {
179
+ set.add(r[c])
180
+ })
181
+ if (set.size === 1) {
182
+ const sIndes = dataColumns.indexOf(
183
+ dataColumns.find((c) => c.property === m.conditions[0]),
184
+ )
185
+ const eIndes = dataColumns.indexOf(
186
+ dataColumns.find((c) => c.property === m.conditions[m.conditions.length - 1]),
187
+ )
188
+ merges.push({
189
+ s: { c: sIndes, r: r._orderNum },
190
+ e: { c: eIndes, r: r._orderNum },
191
+ })
192
+ }
193
+ })
194
+ })
195
+ }
196
+ //row单元格合并
197
+ if (rowMerges) {
198
+ rowMerges.forEach((m: any) => {
199
+ const groupList = new Linq(data1).groupBy((r: any) => {
200
+ const obj: any = {}
201
+ m.conditions.forEach((c: any) => {
202
+ obj[c] = r[c]
203
+ })
204
+ return obj
205
+ })
206
+ //@ts-ignore
207
+ groupList.forEach((c: any) => {
208
+ m.fields.forEach((m1: any) => {
209
+ const cIndex = dataColumns.indexOf(dataColumns.find((c) => c.property === m1))
210
+ let minOrderNum = 0
211
+ let maxOrderNum = 0
212
+ minOrderNum = new Linq(c.elements).min((c: any) => c._orderNum)
213
+ maxOrderNum = new Linq(c.elements).max((c: any) => c._orderNum)
214
+ merges.push({
215
+ s: { c: cIndex, r: minOrderNum },
216
+ e: { c: cIndex, r: maxOrderNum },
217
+ })
218
+ })
219
+ })
220
+ })
221
+ }
222
+ data1?.forEach((r: any) => {
223
+ const row: any = []
224
+ dataColumns.forEach((c) => {
225
+ row.push({
226
+ v: r[c.property] ? r[c.property] : '',
227
+ t: 's',
228
+ s: {
229
+ alignment: {
230
+ vertical: 'center', // 垂直居中
231
+ horizontal: 'center', // 水平居中
232
+ },
233
+ // border 边框属性
234
+ border: {
235
+ top: { style: 'thin' },
236
+ bottom: { style: 'thin' },
237
+ left: { style: 'thin' },
238
+ right: { style: 'thin' },
239
+ },
240
+ },
241
+ })
242
+ })
243
+ rows.push(row)
244
+ })
245
+ //设置行高
246
+ rows.forEach((r: any, index: number) => {
247
+ if (index > 0) {
248
+ rowsS.push({ hpx: 20 })
249
+ }
250
+ })
251
+ //设置列宽
252
+ dataColumns.forEach((c) => {
253
+ cols.push({ wpx: c.width })
254
+ })
255
+ if (customFooterCallback) {
256
+ customFooterCallback(rows, dataColumns, merges)
257
+ }
258
+ const wb = XLSX.utils.book_new()
259
+ const ws = XLSX.utils.aoa_to_sheet(rows)
260
+ ws['!cols'] = cols
261
+ ws['!merges'] = merges
262
+ ws['!rows'] = rowsS
263
+ XLSX.utils.book_append_sheet(wb, ws, sheetName)
264
+ // STEP 4: Write Excel file to browser
265
+ XLSX.writeFile(wb, fileName+'.xlsx')
266
+ },
267
+ generateHeader(
268
+ columns: any[],
269
+ rows: any[],
270
+ columnIndex: number,
271
+ merges: any,
272
+ ){
273
+ //@ts-ignore
274
+ columns.forEach((c: any) => {
275
+ let row: any = []
276
+ if (rows[c.level]) {
277
+ row = rows[c.level]
278
+ } else {
279
+ row = []
280
+ rows.push(row)
281
+ }
282
+ row[columnIndex] = {
283
+ v: c.label,
284
+ t: 's',
285
+ s: {
286
+ font: { bold: true },
287
+ alignment: {
288
+ vertical: 'center', // 垂直居中
289
+ horizontal: 'center', // 水平居中
290
+ },
291
+ // border 边框属性
292
+ border: {
293
+ top: { style: 'thin' },
294
+ bottom: { style: 'thin' },
295
+ left: { style: 'thin' },
296
+ right: { style: 'thin' },
297
+ },
298
+ },
299
+ }
300
+ if (c.children) {
301
+ merges.push({
302
+ s: { c: columnIndex, r: c.level },
303
+ e: { c: columnIndex + c.colSpan - 1, r: c.level },
304
+ })
305
+ this.generateHeader(c.children, rows, columnIndex, merges)
306
+ } else {
307
+ if (c.rowSpan > 1) {
308
+ merges.push({
309
+ s: { c: columnIndex, r: c.level },
310
+ e: { c: columnIndex, r: c.level + c.rowSpan - 1 },
311
+ })
312
+ }
313
+ }
314
+ columnIndex = columnIndex + c.colSpan
315
+ })
316
+ },
317
+ generateColumns(columns: any[], dataColumns: any[]){
318
+ //@ts-ignore
319
+ columns.forEach((c: any) => {
320
+ if (c.children) {
321
+ this.generateColumns(c.children, dataColumns)
322
+ } else {
323
+ dataColumns.push({ property: c.property, width: c.width ? c.width : c.minWidth })
324
+ }
325
+ })
326
+ }
327
+ // /**
328
+ // * 判断是否有操作权限
329
+ // * @param operCode
330
+ // * @constructor
331
+ // */
332
+ // IsOperationAuth(operCode:string): Boolean {
333
+ // return permission.IsOperationAuth(operCode)
334
+ // }
335
+ }