npmapps 1.0.4 → 1.0.5

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/README.md CHANGED
@@ -2,4 +2,5 @@
2
2
  1.0.1 HeidiSQL_12.10.0.7000_Setup.7z
3
3
  1.0.2 v-fullScreen.browser.text
4
4
  1.0.3 ehcarts-3dpie
5
- 1.0.4 EllTable
5
+ 1.0.4 EllTable
6
+ 1.0.5 dialogFnJsx
@@ -0,0 +1,51 @@
1
+ <template>
2
+ <el-form ref="form" :model="formData" label-width="80px">
3
+ <el-form-item label="名称" prop="name">
4
+ <el-input
5
+ v-model="formData.name"
6
+ placeholder="请输入名称"
7
+ />
8
+ </el-form-item>
9
+ <el-form-item label="邮箱" prop="email">
10
+ <el-input
11
+ v-model="formData.email"
12
+ placeholder="请输入邮箱"
13
+ />
14
+ </el-form-item>
15
+ <el-form-item label="描述" prop="description">
16
+ <el-input
17
+ type="textarea"
18
+ v-model="formData.description"
19
+ placeholder="请输入描述"
20
+ :rows="3"
21
+ />
22
+ </el-form-item>
23
+ </el-form>
24
+ </template>
25
+
26
+ <script>
27
+ export default {
28
+ name: 'DialogForm',
29
+ data() {
30
+ return {
31
+ formData: {
32
+ name: '',
33
+ email: '',
34
+ description: ''
35
+ }
36
+ }
37
+ },
38
+ methods: {
39
+ getFormData() {
40
+ return this.formData
41
+ },
42
+ resetForm() {
43
+ this.formData = {
44
+ name: '',
45
+ email: '',
46
+ description: ''
47
+ }
48
+ }
49
+ }
50
+ }
51
+ </script>
@@ -0,0 +1,98 @@
1
+ # dialogFnJsx 组件文档
2
+
3
+ ## 组件介绍
4
+
5
+ `dialogFnJsx` 是一个基于 Element UI 的 Dialog 组件封装的函数式对话框组件,使用 JSX 语法实现。它提供了一种更灵活的方式来创建和管理对话框,支持动态内容渲染和自定义插槽。
6
+
7
+ ## 特性
8
+
9
+ - 函数式调用,无需在模板中声明
10
+ - 支持 JSX 语法
11
+ - 支持多个插槽(默认内容、标题、底部)
12
+ - 自动管理对话框的生命周期
13
+ - 支持所有 Element UI Dialog 的原生属性和事件
14
+
15
+ ## 基本用法
16
+
17
+ ```javascript
18
+ import { dialogFn } from './dialogFnJsx';
19
+
20
+ // 基础用法
21
+ const { dialog, close } = dialogFn({
22
+ slots: {
23
+ default: <div>对话框内容</div>,
24
+ title: <h3>标题</h3>,
25
+ footer: (
26
+ <div>
27
+ <el-button onClick={() => close()}>取消</el-button>
28
+ <el-button type="primary" onClick={() => {}}>确定</el-button>
29
+ </div>
30
+ )
31
+ },
32
+ props: {
33
+ title: '标题',
34
+ width: '500px',
35
+ destroyOnClose: true
36
+ },
37
+ on: {
38
+ close: () => {
39
+ console.log('关闭');
40
+ }
41
+ }
42
+ });
43
+ ```
44
+
45
+ ## 参数说明
46
+
47
+ ### options 配置对象
48
+
49
+ | 参数 | 类型 | 必填 | 说明 |
50
+ |------|------|------|------|
51
+ | slots | Object | 否 | 插槽内容配置对象 |
52
+ | props | Object | 否 | Dialog 组件的 props 配置 |
53
+ | on | Object | 否 | Dialog 组件的事件监听配置 |
54
+
55
+ ### slots 配置对象
56
+
57
+ | 属性 | 类型 | 说明 |
58
+ |------|------|------|
59
+ | default | JSX.Element | 默认插槽内容 |
60
+ | title | JSX.Element | 标题插槽内容 |
61
+ | footer | JSX.Element | 底部插槽内容 |
62
+
63
+ ### props 配置对象
64
+
65
+ 支持所有 Element UI Dialog 组件的 props 配置,常用的有:
66
+
67
+ | 属性 | 类型 | 说明 |
68
+ |------|------|------|
69
+ | title | String | 对话框标题 |
70
+ | width | String | 对话框宽度 |
71
+ | top | String | 对话框距离顶部的距离 |
72
+ | destroyOnClose | Boolean | 关闭时是否销毁内容 |
73
+ | beforeClose | Function | 关闭前的回调函数 |
74
+
75
+ ### on 配置对象
76
+
77
+ 支持所有 Element UI Dialog 组件的事件监听配置,常用的有:
78
+
79
+ | 事件名 | 说明 |
80
+ |--------|------|
81
+ | close | 对话框关闭时的回调函数 |
82
+ | open | 对话框打开时的回调函数 |
83
+
84
+ ## 注意事项
85
+
86
+ 1. 组件使用 JSX 语法,确保项目已配置好相关的 Babel 插件支持。
87
+ 2. 关闭对话框时会自动销毁组件实例,无需手动处理。
88
+ 3. 所有的 Element UI Dialog 原生属性都可以通过 props 传入。
89
+ 4. 事件监听器通过 on 对象进行配置。
90
+ 5. 返回的 close 方法可以用于手动关闭对话框。
91
+
92
+ ## 与普通 Vue 组件的区别
93
+
94
+ 1. 采用函数式调用而非组件式声明
95
+ 2. 使用 JSX 语法替代模板语法
96
+ 3. 自动管理组件的挂载和销毁
97
+ 4. 更灵活的插槽内容配置
98
+ 5. 无需在父组件中注册即可使用
@@ -0,0 +1,74 @@
1
+ <template>
2
+ <div>
3
+ {{ nameProps }}
4
+
5
+ <el-button type="primary" v-if="showBtn" @click="show">打开新弹窗</el-button>
6
+ <el-button v-if="showBtn" @click="close">关闭</el-button>
7
+ <el-button v-if="showBtn" @click="obj.a++">{{ obj.a }}</el-button>
8
+ <slot />
9
+ </div>
10
+ </template>
11
+ <script>
12
+ import { dialogFn } from "./index";
13
+ import com11 from "./com11.vue";
14
+ export default {
15
+ props: {
16
+ nameProps: {
17
+ type: String,
18
+ default: "111",
19
+ },
20
+ closeDialog: {
21
+ type: Function,
22
+ default: () => {
23
+ },
24
+ },
25
+ showBtn: {
26
+ type: Boolean,
27
+ default: false,
28
+ },
29
+ obj: {
30
+ type: Object,
31
+ default: () => {
32
+ return {};
33
+ },
34
+ },
35
+ },
36
+ created() {
37
+ console.log(this.nameProps, "nameProps");
38
+ },
39
+ methods: {
40
+ close() {
41
+ console.log(this.closeDialog, "dialog");
42
+ this.closeDialog();
43
+ },
44
+ beforeClose(d) {
45
+ d();
46
+ },
47
+ show() {
48
+
49
+ const { close } = dialogFn({
50
+ slots: {
51
+ default: (
52
+ <com11
53
+ nameProps="内部defaultSlot"
54
+ closeDialog={() => close()}
55
+ />
56
+ ),
57
+ },
58
+ props: {
59
+ title: "内部弹窗标题",
60
+ width: "300px",
61
+ top: "100px",
62
+ beforeClose: this.beforeClose,
63
+ appendToBody: true,
64
+ },
65
+ on: {
66
+ close: () => {
67
+ console.log("内部关闭");
68
+ },
69
+ },
70
+ });
71
+ },
72
+ },
73
+ };
74
+ </script>
@@ -0,0 +1,31 @@
1
+ <template>
2
+ <div>
3
+ {{ nameProps }}
4
+ <el-button type="" @click="close">关闭</el-button>
5
+ </div>
6
+ </template>
7
+ <script>
8
+ export default {
9
+ props: {
10
+ nameProps: {
11
+ type: String,
12
+ default: "111",
13
+ },
14
+ closeDialog: {
15
+ type: Function,
16
+ default: () => {
17
+ },
18
+ },
19
+ },
20
+ created() {
21
+ console.log(this.nameProps, "nameProps");
22
+ },
23
+ methods: {
24
+ close() {
25
+ console.log(this.closeDialog, "dialog");
26
+
27
+ this.closeDialog();
28
+ },
29
+ },
30
+ };
31
+ </script>
@@ -0,0 +1,205 @@
1
+ <template>
2
+ <div class="dialog-examples">
3
+ <!-- 基础用法示例 -->
4
+ <el-button @click="showBasicDialog">基础对话框</el-button>
5
+
6
+ <!-- 自定义标题和内容示例 -->
7
+ <el-button @click="showCustomDialog" type="primary">自定义对话框</el-button>
8
+
9
+ <!-- 表单验证示例 -->
10
+ <el-button @click="showFormDialog" type="success">表单对话框</el-button>
11
+
12
+ <!-- 复杂功能示例 -->
13
+ <el-button @click="showComplexDialog" type="warning">复杂对话框</el-button>
14
+ </div>
15
+ </template>
16
+
17
+ <script>
18
+ import DialogForm from './DialogForm.vue'
19
+
20
+ export default {
21
+ components: {
22
+ DialogForm
23
+ },
24
+ name: 'DialogExamples',
25
+ data() {
26
+ return {
27
+ formData: {
28
+ name: '',
29
+ email: '',
30
+ description: ''
31
+ }
32
+ }
33
+ },
34
+ methods: {
35
+ // 基础对话框示例
36
+ showBasicDialog() {
37
+ this.$dialogFnByJsx({
38
+ props: {
39
+ title: '基础对话框',
40
+ width: '30%'
41
+ },
42
+ slots: {
43
+ default: '这是一个基础的对话框示例,展示最简单的用法。'
44
+ },
45
+ on: {
46
+ open: () => console.log('对话框打开了'),
47
+ close: () => console.log('对话框关闭了')
48
+ }
49
+ })
50
+ },
51
+
52
+ // 自定义对话框示例
53
+ showCustomDialog() {
54
+ this.$dialogFnByJsx({
55
+ props: {
56
+ width: '40%',
57
+ 'custom-class': 'custom-dialog'
58
+ },
59
+ slots: {
60
+ title: <div style="color: #409EFF">自定义标题样式</div>,
61
+ default: (
62
+ <div class="custom-content">
63
+ <el-alert
64
+ title="自定义内容示例"
65
+ type="success"
66
+ description="这里展示了如何使用JSX语法自定义对话框内容"
67
+ show-icon
68
+ />
69
+ <div style="margin-top: 20px">
70
+ 可以在这里放置任何自定义的内容组件
71
+ </div>
72
+ </div>
73
+ ),
74
+ footer: (
75
+ <div class="custom-footer">
76
+ <el-button>取消</el-button>
77
+ <el-button type="primary">确定</el-button>
78
+ </div>
79
+ )
80
+ }
81
+ })
82
+ },
83
+
84
+ // 表单对话框示例
85
+ showFormDialog() {
86
+ let formRef = null
87
+ const config = {
88
+ props: {
89
+ title: '表单对话框',
90
+ width: '50%'
91
+ },
92
+ slots: {
93
+ default: (
94
+ <DialogForm ref={ref => formRef = ref} />
95
+ ),
96
+ footer: (
97
+ <div>
98
+ <el-button onClick={() => close()}>取消</el-button>
99
+ <el-button
100
+ type="primary"
101
+ onClick={() => {
102
+ const formData = formRef.getFormData()
103
+ console.log('表单数据:', formData)
104
+ close()
105
+ }}
106
+ >
107
+ 提交
108
+ </el-button>
109
+ </div>
110
+ )
111
+ }
112
+ }
113
+ let { close } = this.$dialogFnByJsx(config)
114
+ },
115
+
116
+ // 复杂功能示例
117
+ showComplexDialog() {
118
+ const config={
119
+ props: {
120
+ title: '复杂功能示例',
121
+ width: '60%',
122
+ 'close-on-click-modal': false,
123
+ 'custom-class': 'complex-dialog'
124
+ },
125
+ slots: {
126
+ default: (
127
+ <div class="complex-content">
128
+ <el-tabs type="border-card">
129
+ <el-tab-pane label="基本信息">
130
+ <el-descriptions title="用户信息" border>
131
+ <el-descriptions-item label="用户名">张三</el-descriptions-item>
132
+ <el-descriptions-item label="手机号">18100000000</el-descriptions-item>
133
+ <el-descriptions-item label="居住地">苏州市</el-descriptions-item>
134
+ <el-descriptions-item label="备注">
135
+ <el-tag size="small">学校</el-tag>
136
+ </el-descriptions-item>
137
+ <el-descriptions-item label="联系地址">
138
+ 江苏省苏州市吴中区吴中大道 1188 号
139
+ </el-descriptions-item>
140
+ </el-descriptions>
141
+ </el-tab-pane>
142
+ <el-tab-pane label="操作记录">
143
+ <el-timeline>
144
+ <el-timeline-item
145
+ timestamp="2023/4/12"
146
+ placement="top"
147
+ >
148
+ <el-card>
149
+ <h4>更新 Github 模板</h4>
150
+ <p>王小虎 提交于 2023/4/12 20:46</p>
151
+ </el-card>
152
+ </el-timeline-item>
153
+ <el-timeline-item
154
+ timestamp="2023/4/3"
155
+ placement="top"
156
+ >
157
+ <el-card>
158
+ <h4>更新 Github 模板</h4>
159
+ <p>王小虎 提交于 2023/4/3 20:46</p>
160
+ </el-card>
161
+ </el-timeline-item>
162
+ </el-timeline>
163
+ </el-tab-pane>
164
+ </el-tabs>
165
+ </div>
166
+ ),
167
+ footer: (
168
+ <div class="complex-footer">
169
+ <el-button onClick={() => close()}>取消</el-button>
170
+ <el-button type="primary" onClick={() => close()}>确定</el-button>
171
+ </div>
172
+ )
173
+ },
174
+ on: {
175
+ open: () => console.log('复杂对话框打开'),
176
+ close: () => console.log('复杂对话框关闭')
177
+ }
178
+ }
179
+ const { close } = this.$dialogFnByJsx(config)
180
+ }
181
+ }
182
+ }
183
+ </script>
184
+
185
+ <style scoped>
186
+ .dialog-examples {
187
+ padding: 20px;
188
+ }
189
+
190
+ .dialog-examples .el-button {
191
+ margin-right: 10px;
192
+ }
193
+
194
+ .custom-content {
195
+ padding: 20px 0;
196
+ }
197
+
198
+ .complex-content {
199
+ padding: 20px 0;
200
+ }
201
+
202
+ :global(.complex-dialog) {
203
+ min-height: 400px;
204
+ }
205
+ </style>
@@ -0,0 +1,59 @@
1
+ import { Dialog } from "element-ui";
2
+ import Vue from "vue";
3
+
4
+ const DialogConstructor = Vue.extend(Dialog);
5
+
6
+ export function dialogFn(options = {}) {
7
+ const {
8
+ slots = {},
9
+ props = {},
10
+ on = {},
11
+ } = options;
12
+
13
+ const dialog = new DialogConstructor({
14
+ el: document.createElement("div"),
15
+ render() {
16
+ const dialogProps = {
17
+ props: {
18
+ visible: true,
19
+ ...props,
20
+ },
21
+ on: {
22
+ "update:visible": (val) => {
23
+ dialog.visible = val;
24
+ if (!val) {
25
+ close();
26
+ }
27
+ },
28
+ ...on,
29
+ },
30
+ };
31
+
32
+ return (
33
+ <Dialog {...dialogProps}>
34
+ {slots.default && <template slot="default">{slots.default}</template>}
35
+ {slots.title && <template slot="title">{slots.title}</template>}
36
+ {slots.footer && <template slot="footer">{slots.footer}</template>}
37
+ </Dialog>
38
+ );
39
+ },
40
+ });
41
+
42
+ const close = () => {
43
+ on.close && on.close();
44
+ if (dialog && dialog.$el && dialog.$el.parentNode) {
45
+ dialog.$el.parentNode.removeChild(dialog.$el);
46
+ dialog.$destroy();
47
+
48
+ }
49
+ };
50
+
51
+ Vue.nextTick(() => {
52
+ document.body.appendChild(dialog.$el);
53
+ on.open && on.open();
54
+ });
55
+
56
+ return { dialog, close };
57
+ }
58
+
59
+ Vue.prototype.$dialogFnByJsx = dialogFn;
@@ -0,0 +1,91 @@
1
+ <template>
2
+ <div>
3
+ <el-button @click="show">案例1jsx</el-button>
4
+ <el-button @click="show1">案例2jsx</el-button>
5
+ <span>{{ obj.a }}</span>
6
+ </div>
7
+ </template>
8
+
9
+ <script>
10
+ import com from "./com.vue";
11
+
12
+ export default {
13
+ name: "DialogFn",
14
+ components: {
15
+ com,
16
+ },
17
+ data() {
18
+ return {
19
+ obj: {
20
+ a: 1,
21
+ }
22
+ };
23
+ },
24
+ methods: {
25
+ beforeClose(done) {
26
+ console.log("beforeClose");
27
+ done();
28
+ },
29
+ show() {
30
+ // 确保在打开新对话框前关闭旧的
31
+ const dialogConfig = {
32
+ slots: {
33
+ default: (
34
+ <com
35
+ nameProps="defaultSlot"
36
+ closeDialog={() => close()}
37
+ obj={this.obj}
38
+ showBtn={true}
39
+ > <el-button type='text'>anniu</el-button></com>
40
+ ),
41
+ title: <com nameProps="标题titleSlot" />,
42
+ footer: (
43
+ <div>
44
+ <el-button onClick={() => close()}>取消</el-button>
45
+ <el-button type="primary" onClick={() => {}}>
46
+ 确定
47
+ </el-button>
48
+ </div>
49
+ ),
50
+ },
51
+
52
+ props: {
53
+ title: "标题",
54
+ width: "500px",
55
+ top: "100px",
56
+ beforeClose: this.beforeClose,
57
+ destroyOnClose: true, // 关闭时销毁内容
58
+ },
59
+ on: {
60
+ close: () => {
61
+ console.log("关闭close");
62
+ },
63
+ open: () => {
64
+ console.log("打开opened");
65
+ }
66
+ },
67
+ };
68
+
69
+ const { close } = this.$dialogFnByJsx(dialogConfig);
70
+ },
71
+ show1() {
72
+ const dialogConfig = {
73
+ slots: {
74
+ default: (
75
+ <com
76
+ nameProps="简单案例"
77
+ closeDialog={() => close()}
78
+ showBtn={true}
79
+ > </com>
80
+ ),
81
+ },
82
+ props: {
83
+ title: "标题",
84
+ },
85
+ }
86
+ const { close } = this.$dialogFnByJsx(dialogConfig);
87
+
88
+ }
89
+ },
90
+ };
91
+ </script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npmapps",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -1,70 +0,0 @@
1
- # EllTable 组件
2
-
3
- 基于 Element UI Table 组件扩展的表格组件,支持鼠标横向滚动和提示功能。
4
-
5
- ## 功能特点
6
-
7
- - 支持鼠标横向滚动(按住 Alt 键)
8
- - 自动检测表格是否需要横向滚动
9
- - 可配置的提示信息和位置
10
- - 继承 Element UI Table 的所有功能和属性
11
-
12
- ## 属性配置
13
-
14
- | 属性名 | 类型 | 默认值 | 说明 |
15
- |--------|------|---------|------|
16
- | disableMouseHorizontalWheel | Boolean | false | 是否禁用鼠标横向滚动功能 |
17
- | hiddenMouseWheel | Boolean | false | 是否隐藏鼠标滚动提示 |
18
- | showTooltip | Boolean | false | 是否显示提示信息 |
19
- | tooltipContent | String/Array | [] | 提示信息内容,可以是字符串或字符串数组 |
20
- | tooltipPosition | Object | { top: "10px", left: "10px" } | 提示信息位置,支持 top、left、bottom、right |
21
-
22
- ## 使用示例
23
-
24
- ```vue
25
- <template>
26
- <ell-table
27
- :data="tableData"
28
- border
29
- style="width: 100%"
30
- height="300"
31
- :tooltip-content="['按住Alt键可以横向滚动表格', '自定义提示信息']"
32
- :show-tooltip="true"
33
- :tooltip-position="{ top: '20px', right: '20px' }"
34
- >
35
- <el-table-column prop="date" label="日期" width="180" fixed="left"></el-table-column>
36
- <el-table-column prop="name" label="姓名" width="180"></el-table-column>
37
- <el-table-column prop="address" label="地址" width="300"></el-table-column>
38
- <!-- 更多列... -->
39
- </ell-table>
40
- </template>
41
-
42
- <script>
43
- export default {
44
- data() {
45
- return {
46
- tableData: [{
47
- date: '2023-01-01',
48
- name: '张三',
49
- address: '北京市朝阳区'
50
- }]
51
- }
52
- }
53
- }
54
- </script>
55
- ```
56
-
57
- ## 注意事项
58
-
59
- 1. 组件会自动检测表格是否同时存在横向和纵向滚动条,如果存在则显示提示信息
60
- 2. 可以通过 `disableMouseHorizontalWheel` 属性禁用鼠标横向滚动功能
61
- 3. 提示信息位置可以通过 `tooltipPosition` 属性灵活配置
62
- 4. 组件完全兼容 Element UI Table 的所有功能,可以正常使用 Table 组件的所有属性和方法
63
-
64
- ## 建议功能扩展
65
-
66
- 1. 支持自定义滚动速度
67
- 2. 添加滚动方向锁定功能
68
- 3. 提供滚动事件回调
69
- 4. 支持 tooltip 主题定制
70
- 5. 添加更多交互效果(如双击切换滚动方向、滚动到边缘时的视觉反馈等)
@@ -1,218 +0,0 @@
1
- import { Table } from "element-ui";
2
-
3
- /**
4
- * @description 扩展Element UI Table组件,支持鼠标横向滚动和提示功能
5
- * @extends {Table}
6
- */
7
- export const tableMouseHorizontalWheel = {
8
- extends: Table,
9
- data() {
10
- return {
11
- tooltipContentList: [],
12
- tooltipVisible: this.showTooltip,
13
- scrollDirection: 'vertical', // 默认为垂直滚动
14
- isScrollingToEdge: false, // 是否滚动到边缘
15
- };
16
- },
17
- props: {
18
- /** @prop {Boolean} [disableMouseHorizontalWheel=false] - 是否禁用鼠标横向滚动功能 */
19
- disableMouseHorizontalWheel: {
20
- type: Boolean,
21
- default: false,
22
- },
23
- /** @prop {Boolean} [hiddenMouseWheel=false] - 是否隐藏鼠标滚动提示 */
24
- hiddenMouseWheel: {
25
- type: Boolean,
26
- default: false,
27
- },
28
- /** @prop {Boolean} [showTooltip=false] - 是否显示提示信息 */
29
- showTooltip: {
30
- type: Boolean,
31
- default: false,
32
- },
33
- /** @prop {String|Array} [tooltipContent=[]] - 提示信息内容 */
34
- tooltipContent: {
35
- type: [String, Array],
36
- default: () => [],
37
- },
38
- /** @prop {Object} [tooltipPosition={ top: "10px", left: "10px" }] - 提示信息位置 */
39
- tooltipPosition: {
40
- type: Object,
41
- default: () => ({
42
- top: "10px",
43
- left: "10px",
44
- })
45
- },
46
- },
47
- created() {
48
- // 初始化提示信息列表
49
- if (Array.isArray(this.tooltipContent)) {
50
- this.tooltipContentList.push(...this.tooltipContent);
51
- } else {
52
- this.tooltipContentList.push(this.tooltipContent);
53
- }
54
- },
55
-
56
- mounted() {
57
- const newHasScrollbarByMff = _.debounce(this.hasScrollbarByMff, 10);
58
- // 监听this.$el元素变化
59
- const observer = new MutationObserver((mutations) => {
60
- mutations.forEach((mutation) => {
61
- if (mutation.type === "childList") {
62
- newHasScrollbarByMff();
63
- }
64
- });
65
- });
66
- observer.observe(this.$el, {
67
- childList: true,
68
- subtree: true,
69
- });
70
-
71
- if (!this.disableMouseHorizontalWheel) {
72
- this.$el.addEventListener("wheel", this.handleWheel);
73
-
74
- }
75
- },
76
- beforeDestroy() {
77
- if (!this.disableMouseHorizontalWheel) {
78
- this.$el.removeEventListener("wheel", this.handleWheel);
79
- }
80
- },
81
- methods: {
82
- /**
83
- * @description 处理鼠标滚轮事件,实现横向滚动
84
- * @param {WheelEvent} event - 鼠标滚轮事件对象
85
- */
86
- handleWheel(event) {
87
- const tableBody = this.$el.querySelector(".el-table__body-wrapper");
88
-
89
- if (this.scrollDirection === 'horizontal' || event.altKey) {
90
- event.preventDefault();
91
- tableBody.scrollLeft += event.deltaY;
92
-
93
- // 检查是否滚动到边缘
94
- if (tableBody.scrollLeft <= 0 || tableBody.scrollLeft >= (tableBody.scrollWidth - tableBody.clientWidth)) {
95
- this.showEdgeFeedback(tableBody);
96
- }
97
- } else {
98
- // 检查垂直滚动是否到达边缘
99
- if (tableBody.scrollTop <= 0 || tableBody.scrollTop >= (tableBody.scrollHeight - tableBody.clientHeight)) {
100
- this.showEdgeFeedback(tableBody);
101
- }
102
- }
103
- },
104
- /**
105
- * @description 检测表格是否同时存在横向和纵向滚动条,并显示提示信息
106
- */
107
- /**
108
- * @description 切换滚动方向
109
- */
110
- toggleScrollDirection() {
111
- this.scrollDirection = this.scrollDirection === 'vertical' ? 'horizontal' : 'vertical';
112
- this.tooltipContentList = this.tooltipContentList.filter(item => !item.includes('当前滚动方向'));
113
- this.tooltipContentList.push(`当前滚动方向: ${this.scrollDirection === 'vertical' ? '垂直' : '水平'}`);
114
- // 消息提醒
115
- this.$message({
116
- message: `当前表格滚动方向已切换为: ${this.scrollDirection ==='vertical'? '垂直' : '水平'}`,
117
- type: 'info',
118
- duration: 1000,
119
- })
120
- },
121
-
122
- /**
123
- * @description 显示边缘视觉反馈
124
- * @param {HTMLElement} element - 需要添加视觉反馈的元素
125
- */
126
- showEdgeFeedback(element) {
127
- if (!this.isScrollingToEdge) {
128
- this.isScrollingToEdge = true;
129
- element.style.transition = 'background-color 0.3s';
130
- element.style.backgroundColor = 'rgba(0, 0, 0, 0.1)';
131
-
132
- setTimeout(() => {
133
- element.style.backgroundColor = '';
134
- setTimeout(() => {
135
- element.style.transition = '';
136
- this.isScrollingToEdge = false;
137
- }, 300);
138
- }, 300);
139
- }
140
- },
141
-
142
- hasScrollbarByMff() {
143
- console.log(123);
144
-
145
- const tableBody = this.$el.querySelector(".el-table__body-wrapper");
146
- // 是否有竖向滚动条
147
- const verticalScrollbarWidth =
148
- tableBody.scrollHeight - tableBody.clientHeight;
149
- console.log(tableBody.scrollHeight, tableBody.clientHeight,'1231321321',verticalScrollbarWidth);
150
-
151
- // 是否有横向滚动条
152
- const horizontalScrollbarHeight =
153
- tableBody.scrollWidth - tableBody.clientWidth;
154
- console.log(tableBody.scrollWidth, tableBody.clientWidth,'1231321321',horizontalScrollbarHeight);
155
-
156
-
157
-
158
- // 如果有横向滚动条和竖向滚动条 hiddenMouseWheel 为false时 tooltipVisible 为true
159
- if (
160
- verticalScrollbarWidth > 0 &&
161
- horizontalScrollbarHeight > 0 &&
162
- !this.hiddenMouseWheel
163
- ) {
164
- this.tooltipContentList.push("按住Alt键可以横向滚动表格");
165
- this.tooltipVisible = true;
166
- this.$el.addEventListener("dblclick", this.toggleScrollDirection);
167
- this.tooltipContentList.push('双击表格任意位置可切换滚动方向')
168
- }else{
169
- this.tooltipContentList = this.tooltipContentList.filter(item =>!item.includes('按住Alt键可以横向滚动表格'));
170
- this.tooltipContentList = this.tooltipContentList.filter(item =>!item.includes('双击表格任意位置可切换滚动方向'));
171
- this.tooltipVisible = false;
172
- console.log(1231321);
173
- }
174
-
175
- },
176
- },
177
- render(h) {
178
- const table = this.$options.extends.render.call(this, h);
179
- return (
180
- <div
181
- style={{
182
- position: "relative",
183
- }}
184
- >
185
- <el-tooltip
186
- placement="top"
187
- style={{
188
- position: "absolute",
189
- ...(this.tooltipPosition.top && { top: this.tooltipPosition.top }),
190
- ...(this.tooltipPosition.left && { left: this.tooltipPosition.left }),
191
- ...(this.tooltipPosition.bottom && { bottom: this.tooltipPosition.bottom }),
192
- ...(this.tooltipPosition.right && { right: this.tooltipPosition.right }),
193
- zIndex: 11,
194
- display: this.tooltipVisible ? "block" : "none",
195
- }}
196
- >
197
- <div slot="content">
198
- {this.tooltipContentList.map((item, index) => {
199
- return (
200
- <div key={index} style={{ marginBottom: "4px" }}>
201
- <span>{index + 1}.</span> {item}
202
- </div>
203
- );
204
- })}
205
- </div>
206
- <i
207
- class="el-icon-info"
208
- style={{
209
- cursor: "pointer",
210
- display: this.tooltipVisible ? "block" : "none",
211
- }}
212
- ></i>
213
- </el-tooltip>
214
- {table}
215
- </div>
216
- );
217
- },
218
- }