py-test-components 1.0.1 → 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.
@@ -4,12 +4,6 @@
4
4
  * Released under the MIT License.
5
5
  */
6
6
 
7
- /**
8
- * vue-custom-element v3.3.0
9
- * (c) 2021 Karol Fabjańczuk
10
- * @license MIT
11
- */
12
-
13
7
  /**
14
8
  * @license
15
9
  * Lodash <https://lodash.com/>
package/package.json CHANGED
@@ -1,60 +1,29 @@
1
- {
2
- "name": "py-test-components",
3
- "version": "1.0.1",
4
- "description": "跨框架组件库 - Vue 2 组件可被 React 使用",
5
- "main": "dist/py-component.js",
6
- "module": "dist/py-component.esm.js",
7
- "exports": {
8
- ".": {
9
- "import": "./dist/py-component.esm.js",
10
- "require": "./dist/py-component.js",
11
- "default": "./dist/py-component.esm.js"
12
- },
13
- "./vue": {
14
- "import": "./dist/vue.js",
15
- "require": "./dist/vue.js",
16
- "default": "./dist/vue.js"
17
- },
18
- "./react": {
19
- "import": "./dist/react.js",
20
- "require": "./dist/react.js",
21
- "default": "./dist/react.js"
22
- },
23
- "./package.json": "./package.json"
24
- },
25
- "files": [
26
- "dist",
27
- "src"
28
- ],
29
- "scripts": {
30
- "build": "webpack --mode=production",
31
- "dev": "webpack --mode=development --watch",
32
- "clean": "rimraf dist"
33
- },
34
- "dependencies": {
35
- "element-ui": "^2.15.14",
36
- "vue": "^2.7.16",
37
- "vue-custom-element": "^3.3.0"
38
- },
39
- "devDependencies": {
40
- "@babel/core": "^7.23.0",
41
- "@babel/preset-env": "^7.23.0",
42
- "babel-loader": "^9.1.3",
43
- "css-loader": "^6.8.1",
44
- "rimraf": "^5.0.5",
45
- "style-loader": "^3.3.3",
46
- "vue-loader": "^15.10.1",
47
- "vue-template-compiler": "^2.7.16",
48
- "webpack": "^5.89.0",
49
- "webpack-cli": "^5.1.4"
50
- },
51
- "keywords": [
52
- "vue",
53
- "react",
54
- "web-components",
55
- "component-library",
56
- "element-ui"
57
- ],
58
- "author": "",
59
- "license": "MIT"
60
- }
1
+ {
2
+ "name": "py-test-components",
3
+ "version": "1.0.2",
4
+ "description": "Vue2 + ElementUI component library for Vue and React",
5
+ "main": "dist/py-component.js",
6
+ "module": "dist/py-component.esm.js",
7
+ "scripts": {
8
+ "dev": "webpack --mode development --watch",
9
+ "build": "webpack --mode production"
10
+ },
11
+ "keywords": ["vue", "elementui", "component", "library"],
12
+ "author": "",
13
+ "license": "MIT",
14
+ "dependencies": {
15
+ "vue": "^2.7.0",
16
+ "element-ui": "^2.15.0",
17
+ "vue-custom-element": "^3.3.0"
18
+ },
19
+ "devDependencies": {
20
+ "webpack": "^5.0.0",
21
+ "webpack-cli": "^5.0.0",
22
+ "vue-loader": "^15.10.0",
23
+ "vue-template-compiler": "^2.7.0",
24
+ "css-loader": "^6.0.0",
25
+ "style-loader": "^3.0.0",
26
+ "file-loader": "^6.0.0",
27
+ "url-loader": "^4.0.0"
28
+ }
29
+ }
@@ -1,280 +1,40 @@
1
- <template>
2
- <div class="py-table">
3
- <el-card class="table-card">
4
- <div slot="header" class="card-header">
5
- <span class="title">{{ config.title || '数据表格' }}</span>
6
- <div class="actions">
7
- <el-button
8
- v-if="config.showRefresh !== false"
9
- type="text"
10
- @click="refreshData"
11
- icon="el-icon-refresh"
12
- >
13
- 刷新
14
- </el-button>
15
- </div>
16
- </div>
17
-
18
- <el-table
19
- :data="tableData"
20
- :stripe="config.stripe !== false"
21
- :border="config.border === true"
22
- :height="config.height"
23
- v-loading="loading"
24
- @selection-change="handleSelectionChange"
25
- >
26
- <!-- 选择列 -->
27
- <el-table-column
28
- v-if="config.showSelection"
29
- type="selection"
30
- width="55"
31
- />
32
-
33
- <!-- 序号列 -->
34
- <el-table-column
35
- v-if="config.showIndex !== false"
36
- type="index"
37
- label="序号"
38
- width="60"
39
- />
40
-
41
- <!-- 动态列 -->
42
- <el-table-column
43
- v-for="column in columns"
44
- :key="column.prop"
45
- :prop="column.prop"
46
- :label="column.label"
47
- :width="column.width"
48
- :min-width="column.minWidth"
49
- :sortable="column.sortable"
50
- >
51
- <template slot-scope="scope">
52
- <!-- 自定义渲染 -->
53
- <span v-if="column.formatter">
54
- {{ column.formatter(scope.row[column.prop], scope.row) }}
55
- </span>
56
- <span v-else-if="column.type === 'date'">
57
- {{ formatDate(scope.row[column.prop]) }}
58
- </span>
59
- <span v-else-if="column.type === 'status'">
60
- <el-tag :type="getStatusType(scope.row[column.prop])">
61
- {{ scope.row[column.prop] }}
62
- </el-tag>
63
- </span>
64
- <span v-else>
65
- {{ scope.row[column.prop] }}
66
- </span>
67
- </template>
68
- </el-table-column>
69
-
70
- <!-- 操作列 -->
71
- <el-table-column
72
- v-if="config.showActions !== false"
73
- label="操作"
74
- width="150"
75
- fixed="right"
76
- >
77
- <template slot-scope="scope">
78
- <el-button
79
- type="text"
80
- size="small"
81
- @click="handleEdit(scope.row)"
82
- >
83
- 编辑
84
- </el-button>
85
- <el-button
86
- type="text"
87
- size="small"
88
- @click="handleDelete(scope.row)"
89
- >
90
- 删除
91
- </el-button>
92
- </template>
93
- </el-table-column>
94
- </el-table>
95
-
96
- <!-- 分页 -->
97
- <div v-if="config.pagination !== false" class="pagination-wrapper">
98
- <el-pagination
99
- :current-page="currentPage"
100
- :page-size="pageSize"
101
- :page-sizes="[10, 20, 50, 100]"
102
- :total="total"
103
- layout="total, sizes, prev, pager, next, jumper"
104
- @size-change="handleSizeChange"
105
- @current-change="handlePageChange"
106
- />
107
- </div>
108
- </el-card>
109
- </div>
110
- </template>
111
-
112
- <script>
113
- import store from '../store';
114
- import { tableApi } from '../utils/api';
115
-
116
- export default {
117
- name: 'PyTable',
118
-
119
- props: {
120
- propData: {
121
- default: null
122
- }
123
- },
124
-
125
- data() {
126
- return {
127
- tableData: [],
128
- loading: false,
129
- currentPage: 1,
130
- pageSize: 10,
131
- total: 0,
132
- selectedRows: []
133
- };
134
- },
135
-
136
- computed: {
137
- config() {
138
- return this.propData || {};
139
- },
140
-
141
- columns() {
142
- return this.config.columns || [];
143
- }
144
- },
145
-
146
- mounted() {
147
- this.loadData();
148
-
149
- // 监听 store 变化(如果需要)
150
- const baseUrl = store.get('baseUrl');
151
- if (baseUrl) {
152
- console.log('[PyTable] baseUrl from store:', baseUrl);
153
- }
154
- },
155
-
156
- methods: {
157
- // 加载数据
158
- async loadData() {
159
- if (this.config.data) {
160
- // 使用传入的数据
161
- this.tableData = this.config.data;
162
- this.total = this.tableData.length;
163
- return;
164
- }
165
-
166
- // 通过 API 获取数据
167
- if (this.config.api !== false) {
168
- try {
169
- this.loading = true;
170
- const params = {
171
- page: this.currentPage,
172
- size: this.pageSize,
173
- ...this.config.params
174
- };
175
-
176
- const res = await tableApi.getData(params);
177
-
178
- // 支持自定义数据路径
179
- const dataPath = this.config.dataPath || 'data';
180
- const totalPath = this.config.totalPath || 'total';
181
-
182
- this.tableData = this.getPathValue(res, dataPath) || [];
183
- this.total = this.getPathValue(res, totalPath) || 0;
184
- } catch (error) {
185
- console.error('[PyTable] 加载数据失败:', error);
186
- this.$message.error('加载数据失败');
187
- } finally {
188
- this.loading = false;
189
- }
190
- }
191
- },
192
-
193
- // 获取对象路径值
194
- getPathValue(obj, path) {
195
- return path.split('.').reduce((o, p) => o && o[p], obj);
196
- },
197
-
198
- // 刷新数据
199
- refreshData() {
200
- this.currentPage = 1;
201
- this.loadData();
202
- this.$emit('refresh');
203
- },
204
-
205
- // 分页大小变化
206
- handleSizeChange(size) {
207
- this.pageSize = size;
208
- this.loadData();
209
- this.$emit('size-change', size);
210
- },
211
-
212
- // 页码变化
213
- handlePageChange(page) {
214
- this.currentPage = page;
215
- this.loadData();
216
- this.$emit('page-change', page);
217
- },
218
-
219
- // 选择变化
220
- handleSelectionChange(rows) {
221
- this.selectedRows = rows;
222
- this.$emit('selection-change', rows);
223
- },
224
-
225
- // 编辑
226
- handleEdit(row) {
227
- this.$emit('edit', row);
228
- },
229
-
230
- // 删除
231
- handleDelete(row) {
232
- this.$emit('delete', row);
233
- },
234
-
235
- // 格式化日期
236
- formatDate(value) {
237
- if (!value) return '';
238
- const date = new Date(value);
239
- return date.toLocaleDateString('zh-CN');
240
- },
241
-
242
- // 获取状态类型
243
- getStatusType(status) {
244
- const statusMap = {
245
- 'active': 'success',
246
- 'pending': 'warning',
247
- 'disabled': 'info',
248
- 'error': 'danger'
249
- };
250
- return statusMap[status] || '';
251
- }
252
- }
253
- };
254
- </script>
255
-
256
- <style scoped>
257
- .py-table {
258
- width: 100%;
259
- }
260
-
261
- .table-card {
262
- margin-bottom: 20px;
263
- }
264
-
265
- .card-header {
266
- display: flex;
267
- justify-content: space-between;
268
- align-items: center;
269
- }
270
-
271
- .title {
272
- font-size: 16px;
273
- font-weight: 500;
274
- }
275
-
276
- .pagination-wrapper {
277
- margin-top: 20px;
278
- text-align: right;
279
- }
280
- </style>
1
+ <template>
2
+ <div class="py-table">
3
+ <el-table :data="tableData" v-bind="config">
4
+ <el-table-column
5
+ v-for="(col, index) in columns"
6
+ :key="index"
7
+ :prop="col.prop"
8
+ :label="col.label"
9
+ />
10
+ </el-table>
11
+ </div>
12
+ </template>
13
+
14
+ <script>
15
+ export default {
16
+ name: 'PyTable',
17
+ props: {
18
+ propData: {
19
+ default: null,
20
+ },
21
+ },
22
+ computed: {
23
+ tableData() {
24
+ return this.propData?.data || [];
25
+ },
26
+ columns() {
27
+ return this.propData?.columns || [];
28
+ },
29
+ config() {
30
+ return this.propData?.config || {};
31
+ },
32
+ },
33
+ };
34
+ </script>
35
+
36
+ <style scoped>
37
+ .py-table {
38
+ width: 100%;
39
+ }
40
+ </style>