p-pc-ui 1.3.5 → 1.3.6
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.
|
@@ -2,33 +2,36 @@
|
|
|
2
2
|
// import "viewerjs/dist/viewer.css";
|
|
3
3
|
import { api as viewerApi } from "v-viewer";
|
|
4
4
|
import PForm from "../p-form/p-form.vue";
|
|
5
|
-
import { h, ref, reactive, onMounted, toRaw
|
|
5
|
+
import { h, ref, reactive, onMounted, toRaw } from "vue";
|
|
6
6
|
import * as _ from "../../utils/dataUtils";
|
|
7
7
|
import dayjs from "dayjs";
|
|
8
|
-
import { Table as ATable, Button as AButton,Textarea as ATextarea
|
|
8
|
+
import { Table as ATable, Button as AButton, Textarea as ATextarea } from "ant-design-vue";
|
|
9
9
|
import type { FormDataItem } from "../p-form/index.d";
|
|
10
10
|
import type { TableColumn } from "./index.d";
|
|
11
11
|
import { useSlots } from "vue";
|
|
12
12
|
const SearchFormRef = ref();
|
|
13
13
|
|
|
14
|
-
const uSlots
|
|
14
|
+
const uSlots = useSlots();
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
interface Props{
|
|
16
|
+
interface Props {
|
|
18
17
|
tableColumns: TableColumn[];
|
|
19
18
|
height?: number;
|
|
20
|
-
editColumns?:string[]
|
|
21
|
-
getData?: (
|
|
19
|
+
editColumns?: string[];
|
|
20
|
+
getData?: (query: object) => Promise<{ data: any[]; count: number; pages: { total: number; now: number } }>;
|
|
22
21
|
searchRenderData?: FormDataItem[];
|
|
23
22
|
initSearchFormData?: any;
|
|
24
|
-
data?:any[]
|
|
23
|
+
data?: any[];
|
|
25
24
|
}
|
|
26
25
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
const {
|
|
27
|
+
getData = null,
|
|
28
|
+
data = [],
|
|
29
|
+
height = 1000,
|
|
30
|
+
searchRenderData = [],
|
|
31
|
+
editColumns = [],
|
|
32
|
+
tableColumns = [],
|
|
33
|
+
initSearchFormData = [],
|
|
34
|
+
} = defineProps<Props>();
|
|
32
35
|
|
|
33
36
|
const pageQuery = reactive({
|
|
34
37
|
p: 1,
|
|
@@ -55,14 +58,13 @@ const rowSelection = {
|
|
|
55
58
|
|
|
56
59
|
const editableData = reactive({});
|
|
57
60
|
|
|
58
|
-
|
|
59
61
|
const loading = ref(false);
|
|
60
62
|
|
|
61
63
|
let searchQuery = {};
|
|
62
64
|
|
|
63
65
|
const renderTableColumns = (tableColumns: TableColumn[]) => {
|
|
64
66
|
const returnColumns: any = [];
|
|
65
|
-
for (const [index,renderItem] of tableColumns.entries()) {
|
|
67
|
+
for (const [index, renderItem] of tableColumns.entries()) {
|
|
66
68
|
if (renderItem.type == "operate") {
|
|
67
69
|
// renderItem.customRender = ({ text, record }) => {
|
|
68
70
|
// const buttons: any = [];
|
|
@@ -83,15 +85,14 @@ const renderTableColumns = (tableColumns: TableColumn[]) => {
|
|
|
83
85
|
// return h("div", { style: { display: "flex", justifyContent: "space-around" } }, buttons);
|
|
84
86
|
// };
|
|
85
87
|
|
|
86
|
-
if(!renderItem.width){
|
|
88
|
+
if (!renderItem.width) {
|
|
87
89
|
renderItem.width = renderItem.operateButtons.length * 60;
|
|
88
90
|
}
|
|
89
91
|
|
|
90
|
-
if(editColumns.length > 0){
|
|
91
|
-
renderItem.width +=110
|
|
92
|
+
if (editColumns.length > 0) {
|
|
93
|
+
renderItem.width += 110;
|
|
92
94
|
}
|
|
93
95
|
renderItem.align = "center";
|
|
94
|
-
|
|
95
96
|
}
|
|
96
97
|
|
|
97
98
|
// 处理默认字段
|
|
@@ -137,7 +138,7 @@ const renderTableColumns = (tableColumns: TableColumn[]) => {
|
|
|
137
138
|
height: (renderItem.picHeight || 60) + "px",
|
|
138
139
|
marginLeft: "10px",
|
|
139
140
|
},
|
|
140
|
-
})
|
|
141
|
+
}),
|
|
141
142
|
);
|
|
142
143
|
};
|
|
143
144
|
}
|
|
@@ -160,12 +161,8 @@ const renderTableColumns = (tableColumns: TableColumn[]) => {
|
|
|
160
161
|
|
|
161
162
|
renderItem["dataIndex"] = renderItem["key"];
|
|
162
163
|
returnColumns.push(renderItem);
|
|
163
|
-
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
166
|
return returnColumns;
|
|
170
167
|
};
|
|
171
168
|
|
|
@@ -173,24 +170,21 @@ const columns = renderTableColumns(tableColumns);
|
|
|
173
170
|
|
|
174
171
|
const renderTableData = async () => {
|
|
175
172
|
loading.value = true;
|
|
176
|
-
if(getData){
|
|
173
|
+
if (getData) {
|
|
177
174
|
const _searchInitFormData = initSearchFormData ? JSON.parse(JSON.stringify(initSearchFormData)) : {};
|
|
178
175
|
const _pageQuery = JSON.parse(JSON.stringify(pageQuery));
|
|
179
176
|
const _tableData = await getData({ ..._searchInitFormData, ..._pageQuery, ..._.cloneDeep(searchQuery) });
|
|
180
177
|
tableData.data = _tableData.data;
|
|
181
178
|
tableData.count = _tableData.count;
|
|
182
179
|
tableData.pages = _tableData.pages;
|
|
180
|
+
} else if (data) {
|
|
181
|
+
tableData.data = data;
|
|
183
182
|
}
|
|
184
183
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}
|
|
188
|
-
|
|
184
|
+
tableData.data.forEach((item, index) => {
|
|
185
|
+
item["index"] = index;
|
|
186
|
+
});
|
|
189
187
|
|
|
190
|
-
tableData.data.forEach((item,index)=>{
|
|
191
|
-
item["index"] = index
|
|
192
|
-
})
|
|
193
|
-
|
|
194
188
|
loading.value = false;
|
|
195
189
|
};
|
|
196
190
|
|
|
@@ -249,15 +243,11 @@ const getTableData = () => {
|
|
|
249
243
|
return toRaw(tableData)["data"];
|
|
250
244
|
};
|
|
251
245
|
|
|
252
|
-
|
|
253
|
-
|
|
254
246
|
const edit = (index: string) => {
|
|
255
247
|
editableData[index] = _.cloneDeep(tableData.data[index]);
|
|
256
|
-
|
|
257
|
-
|
|
258
248
|
};
|
|
259
249
|
const save = (key: string) => {
|
|
260
|
-
Object.assign(tableData.data.filter(item => key === item.key)[0], editableData[key]);
|
|
250
|
+
Object.assign(tableData.data.filter((item) => key === item.key)[0], editableData[key]);
|
|
261
251
|
delete editableData[key];
|
|
262
252
|
};
|
|
263
253
|
|
|
@@ -292,7 +282,7 @@ defineExpose({
|
|
|
292
282
|
</PForm>
|
|
293
283
|
</div>
|
|
294
284
|
|
|
295
|
-
<div v-if="uSlots.button"
|
|
285
|
+
<div v-if="uSlots.button" style="display: flex; justify-content: flex-end; margin-bottom: 10px; padding: 20px">
|
|
296
286
|
<slot name="button"></slot>
|
|
297
287
|
</div>
|
|
298
288
|
|
|
@@ -300,21 +290,25 @@ defineExpose({
|
|
|
300
290
|
rowKey="id"
|
|
301
291
|
:row-selection="rowSelection"
|
|
302
292
|
:columns="columns"
|
|
303
|
-
:data-source="data && data.length >0 ? data :
|
|
293
|
+
:data-source="data && data.length > 0 ? data : tableData.data || []"
|
|
304
294
|
:loading="loading"
|
|
305
|
-
:pagination="
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
295
|
+
:pagination="
|
|
296
|
+
data.length > 0
|
|
297
|
+
? false
|
|
298
|
+
: {
|
|
299
|
+
current: pageQuery.p,
|
|
300
|
+
defaultPageSize: pageQuery.pc,
|
|
301
|
+
showSizeChanger: true,
|
|
302
|
+
pageSizeOptions: ['10', '20', '50', '100', '200'],
|
|
303
|
+
total: tableData.count,
|
|
304
|
+
onChange: onPageChange,
|
|
305
|
+
onShowSizeChange: onPageSizeChange,
|
|
306
|
+
}
|
|
307
|
+
"
|
|
314
308
|
bordered
|
|
315
309
|
@change="onchange"
|
|
316
310
|
>
|
|
317
|
-
<template #bodyCell="{ column, text, record,index }">
|
|
311
|
+
<template #bodyCell="{ column, text, record, index }">
|
|
318
312
|
<template v-if="editColumns.includes(column.key as string)">
|
|
319
313
|
<div>
|
|
320
314
|
<a-textarea
|
|
@@ -324,22 +318,25 @@ defineExpose({
|
|
|
324
318
|
:auto-size="true"
|
|
325
319
|
/>
|
|
326
320
|
<template v-else>
|
|
327
|
-
|
|
321
|
+
{{ text }}
|
|
328
322
|
</template>
|
|
329
323
|
</div>
|
|
330
324
|
</template>
|
|
331
325
|
|
|
332
326
|
<template v-else-if="column['type'] === 'operate'">
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
327
|
+
<div style="display: flex; gap: 10px; justify-content: center">
|
|
328
|
+
<span v-for="item in column['operateButtons']">
|
|
329
|
+
<a v-if="item.visibleFunc && item.visibleFunc(record)" class="operate-a" @click="item.click(record)">
|
|
330
|
+
{{ item.label }}</a
|
|
331
|
+
>
|
|
332
|
+
</span>
|
|
336
333
|
<a class="operate-a" v-if="editableData[record.index]" @click="save(record.index)">保存</a>
|
|
337
|
-
|
|
338
|
-
|
|
334
|
+
<a class="operate-a" v-if="editableData[record.index]" @click="cancel(record.index)">退出</a>
|
|
335
|
+
<a v-if="editColumns.length > 0" class="operate-a" @click="edit(record.index)">编辑</a>
|
|
339
336
|
</div>
|
|
340
337
|
</template>
|
|
341
338
|
|
|
342
|
-
<slot name="bodyCell" v-bind="{column, text, record,index}" />
|
|
339
|
+
<slot name="bodyCell" v-bind="{ column, text, record, index }" />
|
|
343
340
|
</template>
|
|
344
341
|
</a-table>
|
|
345
342
|
</template>
|
|
@@ -365,8 +362,7 @@ defineExpose({
|
|
|
365
362
|
border-bottom: 10px solid #f5f5f5;
|
|
366
363
|
}
|
|
367
364
|
|
|
368
|
-
|
|
369
|
-
.operate-a{
|
|
365
|
+
.operate-a {
|
|
370
366
|
color: #126cff;
|
|
371
367
|
}
|
|
372
368
|
</style>
|