@xjw_/vue2-npm-system 1.0.0

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.
@@ -0,0 +1,286 @@
1
+ <template>
2
+ <div class="jc-table-wrapper">
3
+ <el-table
4
+ v-bind="$attrs"
5
+ :data="tableData"
6
+ :size="size"
7
+ :border="border"
8
+ :stripe="stripe"
9
+ :highlight-current-row="highlightCurrentRow"
10
+ :loading="loading"
11
+ :row-key="rowKey"
12
+ @selection-change="handleSelectionChange"
13
+ @sort-change="handleSortChange"
14
+ @current-change="handleCurrentChange"
15
+ >
16
+ <!-- 选择列 -->
17
+ <el-table-column
18
+ v-if="showSelection"
19
+ type="selection"
20
+ :width="selectionWidth"
21
+ :fixed="selectionFixed"
22
+ >
23
+ </el-table-column>
24
+
25
+ <!-- 序号列 -->
26
+ <el-table-column
27
+ v-if="showIndex"
28
+ type="index"
29
+ :label="indexLabel"
30
+ :width="indexWidth"
31
+ :fixed="indexFixed"
32
+ >
33
+ </el-table-column>
34
+
35
+ <!-- 动态列 -->
36
+ <el-table-column
37
+ v-for="(column, colIndex) in columns"
38
+ :key="column.prop || colIndex"
39
+ :prop="column.prop"
40
+ :label="column.label"
41
+ :width="column.width"
42
+ :min-width="column.minWidth"
43
+ :fixed="column.fixed"
44
+ :sortable="column.sortable"
45
+ :align="column.align || 'center'"
46
+ :header-align="column.headerAlign || 'center'"
47
+ :show-overflow-tooltip="column.showOverflowTooltip !== false"
48
+ >
49
+ <template slot-scope="scope">
50
+ <!-- 自定义渲染插槽 -->
51
+ <slot
52
+ :name="`column-${column.prop}`"
53
+ :row="scope.row"
54
+ :column="column"
55
+ :$index="scope.$index"
56
+ >
57
+ {{ getCellValue(scope.row, column.prop) }}
58
+ </slot>
59
+ </template>
60
+ </el-table-column>
61
+
62
+ <!-- 操作列 -->
63
+ <el-table-column
64
+ v-if="showOperation"
65
+ :label="operationLabel"
66
+ :width="operationWidth"
67
+ :fixed="operationFixed"
68
+ :align="operationAlign"
69
+ >
70
+ <template slot-scope="scope">
71
+ <slot name="operation" :row="scope.row" :$index="scope.$index">
72
+ </slot>
73
+ </template>
74
+ </el-table-column>
75
+ </el-table>
76
+
77
+ <!-- 分页 -->
78
+ <div v-if="showPagination" class="jc-table-pagination">
79
+ <el-pagination
80
+ :current-page="currentPage"
81
+ :page-size="pageSize"
82
+ :total="total"
83
+ :page-sizes="pageSizes"
84
+ :layout="paginationLayout"
85
+ @size-change="handleSizeChange"
86
+ @current-change="handleCurrentPageChange"
87
+ />
88
+ </div>
89
+ </div>
90
+ </template>
91
+
92
+ <script>
93
+ export default {
94
+ name: 'JcTable',
95
+ inheritAttrs: false,
96
+ props: {
97
+ // 表格数据
98
+ data: {
99
+ type: Array,
100
+ default: () => []
101
+ },
102
+ // 尺寸
103
+ size: {
104
+ type: String,
105
+ default: 'medium'
106
+ },
107
+ // 是否带有纵向边框
108
+ border: {
109
+ type: Boolean,
110
+ default: true
111
+ },
112
+ // 是否为斑马纹表格
113
+ stripe: {
114
+ type: Boolean,
115
+ default: false
116
+ },
117
+ // 是否高亮当前行
118
+ highlightCurrentRow: {
119
+ type: Boolean,
120
+ default: false
121
+ },
122
+ // 是否显示加载状态
123
+ loading: {
124
+ type: Boolean,
125
+ default: false
126
+ },
127
+ // 行数据的 Key
128
+ rowKey: {
129
+ type: [String, Function],
130
+ default: 'id'
131
+ },
132
+ // 列配置
133
+ columns: {
134
+ type: Array,
135
+ default: () => []
136
+ },
137
+ // 是否显示选择列
138
+ showSelection: {
139
+ type: Boolean,
140
+ default: false
141
+ },
142
+ // 选择列宽度
143
+ selectionWidth: {
144
+ type: [String, Number],
145
+ default: 55
146
+ },
147
+ // 选择列固定位置
148
+ selectionFixed: {
149
+ type: [Boolean, String],
150
+ default: false
151
+ },
152
+ // 是否显示序号列
153
+ showIndex: {
154
+ type: Boolean,
155
+ default: false
156
+ },
157
+ // 序号列标签
158
+ indexLabel: {
159
+ type: String,
160
+ default: '序号'
161
+ },
162
+ // 序号列宽度
163
+ indexWidth: {
164
+ type: [String, Number],
165
+ default: 60
166
+ },
167
+ // 序号列固定位置
168
+ indexFixed: {
169
+ type: [Boolean, String],
170
+ default: 'left'
171
+ },
172
+ // 是否显示操作列
173
+ showOperation: {
174
+ type: Boolean,
175
+ default: false
176
+ },
177
+ // 操作列标签
178
+ operationLabel: {
179
+ type: String,
180
+ default: '操作'
181
+ },
182
+ // 操作列宽度
183
+ operationWidth: {
184
+ type: [String, Number],
185
+ default: 150
186
+ },
187
+ // 操作列固定位置
188
+ operationFixed: {
189
+ type: [Boolean, String],
190
+ default: 'right'
191
+ },
192
+ // 操作列对齐方式
193
+ operationAlign: {
194
+ type: String,
195
+ default: 'center'
196
+ },
197
+ // 是否显示分页
198
+ showPagination: {
199
+ type: Boolean,
200
+ default: false
201
+ },
202
+ // 当前页码
203
+ currentPage: {
204
+ type: Number,
205
+ default: 1
206
+ },
207
+ // 每页条数
208
+ pageSize: {
209
+ type: Number,
210
+ default: 20
211
+ },
212
+ // 总条数
213
+ total: {
214
+ type: Number,
215
+ default: 0
216
+ },
217
+ // 每页条数选项
218
+ pageSizes: {
219
+ type: Array,
220
+ default: () => [10, 20, 50, 100]
221
+ },
222
+ // 分页布局
223
+ paginationLayout: {
224
+ type: String,
225
+ default: 'total, sizes, prev, pager, next, jumper'
226
+ }
227
+ },
228
+ computed: {
229
+ tableData() {
230
+ return this.data || []
231
+ }
232
+ },
233
+ methods: {
234
+ // 获取单元格值
235
+ getCellValue(row, prop) {
236
+ if (!prop) return ''
237
+ return prop.split('.').reduce((prev, curr) => {
238
+ return prev ? prev[curr] : ''
239
+ }, row)
240
+ },
241
+ // 选择变化
242
+ handleSelectionChange(selection) {
243
+ this.$emit('selection-change', selection)
244
+ },
245
+ // 排序变化
246
+ handleSortChange({ column, prop, order }) {
247
+ this.$emit('sort-change', { column, prop, order })
248
+ },
249
+ // 当前行变化
250
+ handleCurrentChange(val) {
251
+ this.$emit('current-change', val)
252
+ },
253
+ // 每页条数变化
254
+ handleSizeChange(size) {
255
+ this.$emit('size-change', size)
256
+ },
257
+ // 页码变化
258
+ handleCurrentPageChange(page) {
259
+ this.$emit('current-change-page', page)
260
+ },
261
+ // 清除选中
262
+ clearSelection() {
263
+ if (this.$refs.table) {
264
+ this.$refs.table.clearSelection()
265
+ }
266
+ },
267
+ // 切换排序
268
+ toggleAllSelection() {
269
+ if (this.$refs.table) {
270
+ this.$refs.table.toggleAllSelection()
271
+ }
272
+ }
273
+ }
274
+ }
275
+ </script>
276
+
277
+ <style scoped>
278
+ .jc-table-wrapper {
279
+ width: 100%;
280
+ }
281
+
282
+ .jc-table-pagination {
283
+ margin-top: 16px;
284
+ text-align: right;
285
+ }
286
+ </style>
package/es/index.js ADDED
@@ -0,0 +1,31 @@
1
+ // 导入所有组件
2
+ import JcButton from './components/JcButton';
3
+ import JcInput from './components/JcInput';
4
+ import JcTable from './components/JcTable';
5
+ import JcDialog from './components/JcDialog';
6
+ import JcSelect from './components/JcSelect';
7
+
8
+ // 存储组件列表
9
+ var components = [JcButton, JcInput, JcTable, JcDialog, JcSelect];
10
+
11
+ // 安装方法
12
+ var install = function install(Vue) {
13
+ // 注册所有组件
14
+ components.forEach(function (component) {
15
+ Vue.component(component.name, component);
16
+ });
17
+ };
18
+
19
+ // 导出的对象
20
+ export default {
21
+ version: '1.0.0',
22
+ install: install,
23
+ JcButton: JcButton,
24
+ JcInput: JcInput,
25
+ JcTable: JcTable,
26
+ JcDialog: JcDialog,
27
+ JcSelect: JcSelect
28
+ };
29
+
30
+ // 单独导出各个组件
31
+ export { JcButton, JcInput, JcTable, JcDialog, JcSelect };
@@ -0,0 +1,76 @@
1
+ <template>
2
+ <el-button
3
+ v-bind="$attrs"
4
+ :type="jcType"
5
+ :size="size"
6
+ :disabled="disabled || loading"
7
+ :loading="loading"
8
+ @click="handleClick"
9
+ >
10
+ <slot></slot>
11
+ </el-button>
12
+ </template>
13
+
14
+ <script>
15
+ export default {
16
+ name: 'JcButton',
17
+ inheritAttrs: false,
18
+ props: {
19
+ // 扩展类型,支持业务场景
20
+ jcType: {
21
+ type: String,
22
+ default: 'primary'
23
+ },
24
+ // 按钮大小
25
+ size: {
26
+ type: String,
27
+ default: 'medium'
28
+ },
29
+ // 是否禁用
30
+ disabled: {
31
+ type: Boolean,
32
+ default: false
33
+ },
34
+ // 是否加载中
35
+ loading: {
36
+ type: Boolean,
37
+ default: false
38
+ },
39
+ // 防抖时间(毫秒)
40
+ debounce: {
41
+ type: Number,
42
+ default: 0
43
+ }
44
+ },
45
+ data() {
46
+ return {
47
+ isDebouncing: false
48
+ }
49
+ },
50
+ methods: {
51
+ handleClick(event) {
52
+ if (this.disabled || this.loading) {
53
+ return
54
+ }
55
+
56
+ // 防抖处理
57
+ if (this.debounce > 0 && this.isDebouncing) {
58
+ return
59
+ }
60
+
61
+ if (this.debounce > 0) {
62
+ this.isDebouncing = true
63
+ setTimeout(() => {
64
+ this.isDebouncing = false
65
+ }, this.debounce)
66
+ }
67
+
68
+ this.$emit('click', event)
69
+ }
70
+ }
71
+ }
72
+ </script>
73
+
74
+ <style scoped>
75
+ /* 可以在这里添加自定义样式 */
76
+ </style>
@@ -0,0 +1,199 @@
1
+ <template>
2
+ <el-dialog
3
+ v-bind="$attrs"
4
+ :visible.sync="internalVisible"
5
+ :title="title"
6
+ :width="width"
7
+ :size="size"
8
+ :top="top"
9
+ :modal="modal"
10
+ :custom-class="customClass"
11
+ :close-on-click-modal="closeOnClickModal"
12
+ :close-on-press-escape="closeOnPressEscape"
13
+ :show-close="showClose"
14
+ @open="handleOpen"
15
+ @opened="handleOpened"
16
+ @close="handleClose"
17
+ @closed="handleClosed"
18
+ >
19
+ <!-- 标题插槽 -->
20
+ <template v-if="$slots.title" slot="title">
21
+ <slot name="title"></slot>
22
+ </template>
23
+
24
+ <!-- 默认内容 -->
25
+ <slot></slot>
26
+
27
+ <!-- 底部插槽 -->
28
+ <template v-if="$slots.footer" slot="footer">
29
+ <slot name="footer"></slot>
30
+ </template>
31
+
32
+ <!-- 默认底部按钮 -->
33
+ <div v-else-if="showFooter" class="jc-dialog-footer">
34
+ <el-button
35
+ v-if="showCancelButton"
36
+ :size="buttonSize"
37
+ @click="handleCancel"
38
+ >
39
+ {{ cancelText }}
40
+ </el-button>
41
+ <el-button
42
+ v-if="showConfirmButton"
43
+ :type="confirmButtonType"
44
+ :size="buttonSize"
45
+ :loading="confirmLoading"
46
+ @click="handleConfirm"
47
+ >
48
+ {{ confirmText }}
49
+ </el-button>
50
+ </div>
51
+ </el-dialog>
52
+ </template>
53
+
54
+ <script>
55
+ export default {
56
+ name: 'JcDialog',
57
+ inheritAttrs: false,
58
+ props: {
59
+ // 是否显示
60
+ visible: {
61
+ type: Boolean,
62
+ default: false
63
+ },
64
+ // 标题
65
+ title: {
66
+ type: String,
67
+ default: ''
68
+ },
69
+ // 宽度
70
+ width: {
71
+ type: String,
72
+ default: '50%'
73
+ },
74
+ // 尺寸
75
+ size: {
76
+ type: String,
77
+ default: 'small'
78
+ },
79
+ // Dialog CSS Margin Top
80
+ top: {
81
+ type: String,
82
+ default: '15vh'
83
+ },
84
+ // 是否需要遮罩层
85
+ modal: {
86
+ type: Boolean,
87
+ default: true
88
+ },
89
+ // 自定义类名
90
+ customClass: {
91
+ type: String,
92
+ default: ''
93
+ },
94
+ // 是否点击遮罩关闭 Dialog
95
+ closeOnClickModal: {
96
+ type: Boolean,
97
+ default: false
98
+ },
99
+ // 是否按 ESC 关闭 Dialog
100
+ closeOnPressEscape: {
101
+ type: Boolean,
102
+ default: true
103
+ },
104
+ // 是否显示关闭按钮
105
+ showClose: {
106
+ type: Boolean,
107
+ default: true
108
+ },
109
+ // 是否显示底部
110
+ showFooter: {
111
+ type: Boolean,
112
+ default: true
113
+ },
114
+ // 是否显示取消按钮
115
+ showCancelButton: {
116
+ type: Boolean,
117
+ default: true
118
+ },
119
+ // 是否显示确认按钮
120
+ showConfirmButton: {
121
+ type: Boolean,
122
+ default: true
123
+ },
124
+ // 取消按钮文本
125
+ cancelText: {
126
+ type: String,
127
+ default: '取消'
128
+ },
129
+ // 确认按钮文本
130
+ confirmText: {
131
+ type: String,
132
+ default: '确定'
133
+ },
134
+ // 确认按钮类型
135
+ confirmButtonType: {
136
+ type: String,
137
+ default: 'primary'
138
+ },
139
+ // 按钮尺寸
140
+ buttonSize: {
141
+ type: String,
142
+ default: 'medium'
143
+ },
144
+ // 确认按钮加载中
145
+ confirmLoading: {
146
+ type: Boolean,
147
+ default: false
148
+ }
149
+ },
150
+ data() {
151
+ return {
152
+ internalVisible: this.visible
153
+ }
154
+ },
155
+ watch: {
156
+ visible(val) {
157
+ this.internalVisible = val
158
+ },
159
+ internalVisible(val) {
160
+ this.$emit('update:visible', val)
161
+ }
162
+ },
163
+ methods: {
164
+ handleOpen() {
165
+ this.$emit('open')
166
+ },
167
+ handleOpened() {
168
+ this.$emit('opened')
169
+ },
170
+ handleClose() {
171
+ this.$emit('close')
172
+ },
173
+ handleClosed() {
174
+ this.$emit('closed')
175
+ },
176
+ handleCancel() {
177
+ this.$emit('cancel')
178
+ this.internalVisible = false
179
+ },
180
+ handleConfirm() {
181
+ this.$emit('confirm')
182
+ if (!this.confirmLoading) {
183
+ this.internalVisible = false
184
+ }
185
+ }
186
+ }
187
+ }
188
+ </script>
189
+
190
+ <style scoped>
191
+ .jc-dialog-footer {
192
+ text-align: right;
193
+ padding-top: 16px;
194
+ }
195
+
196
+ .jc-dialog-footer .el-button {
197
+ margin-left: 8px;
198
+ }
199
+ </style>
@@ -0,0 +1,136 @@
1
+ <template>
2
+ <div class="jc-input-wrapper">
3
+ <el-input
4
+ v-model="internalValue"
5
+ v-bind="$attrs"
6
+ :type="type"
7
+ :size="size"
8
+ :disabled="disabled"
9
+ :placeholder="placeholder"
10
+ :clearable="clearable"
11
+ :show-password="showPassword"
12
+ :maxlength="maxlength"
13
+ :prefix-icon="prefixIcon"
14
+ :suffix-icon="suffixIcon"
15
+ @input="handleInput"
16
+ @blur="handleBlur"
17
+ @focus="handleFocus"
18
+ >
19
+ <template v-for="(_, name) in $slots" v-slot:[name]>
20
+ <slot :name="name"></slot>
21
+ </template>
22
+ </el-input>
23
+ <span
24
+ v-if="maxLength && internalValue"
25
+ class="jc-input-count"
26
+ >
27
+ {{ internalValue.length }}/{{ maxLength }}
28
+ </span>
29
+ </div>
30
+ </template>
31
+
32
+ <script>
33
+ export default {
34
+ name: 'JcInput',
35
+ inheritAttrs: false,
36
+ props: {
37
+ value: {
38
+ type: [String, Number],
39
+ default: ''
40
+ },
41
+ // 输入框类型
42
+ type: {
43
+ type: String,
44
+ default: 'text'
45
+ },
46
+ // 尺寸
47
+ size: {
48
+ type: String,
49
+ default: 'medium'
50
+ },
51
+ // 是否禁用
52
+ disabled: {
53
+ type: Boolean,
54
+ default: false
55
+ },
56
+ // 占位符
57
+ placeholder: {
58
+ type: String,
59
+ default: '请输入'
60
+ },
61
+ // 是否可清空
62
+ clearable: {
63
+ type: Boolean,
64
+ default: true
65
+ },
66
+ // 是否显示切换密码图标
67
+ showPassword: {
68
+ type: Boolean,
69
+ default: false
70
+ },
71
+ // 最大长度
72
+ maxlength: {
73
+ type: Number,
74
+ default: null
75
+ },
76
+ // 前缀图标
77
+ prefixIcon: {
78
+ type: String,
79
+ default: ''
80
+ },
81
+ // 后缀图标
82
+ suffixIcon: {
83
+ type: String,
84
+ default: ''
85
+ },
86
+ // 是否显示字数统计
87
+ showCount: {
88
+ type: Boolean,
89
+ default: false
90
+ }
91
+ },
92
+ data() {
93
+ return {
94
+ internalValue: this.value
95
+ }
96
+ },
97
+ computed: {
98
+ maxLength() {
99
+ return this.showCount ? (this.maxlength || 999) : null
100
+ }
101
+ },
102
+ watch: {
103
+ value(val) {
104
+ this.internalValue = val
105
+ }
106
+ },
107
+ methods: {
108
+ handleInput(val) {
109
+ this.$emit('input', val)
110
+ this.$emit('change', val)
111
+ },
112
+ handleBlur(event) {
113
+ this.$emit('blur', event)
114
+ },
115
+ handleFocus(event) {
116
+ this.$emit('focus', event)
117
+ }
118
+ }
119
+ }
120
+ </script>
121
+
122
+ <style scoped>
123
+ .jc-input-wrapper {
124
+ position: relative;
125
+ display: inline-block;
126
+ width: 100%;
127
+ }
128
+
129
+ .jc-input-count {
130
+ position: absolute;
131
+ right: 12px;
132
+ bottom: 8px;
133
+ font-size: 12px;
134
+ color: #909399;
135
+ }
136
+ </style>