@zhaoren118/youyu-button 0.0.1
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/LICENSE +21 -0
- package/README.md +172 -0
- package/dist/App.vue.d.ts +3 -0
- package/dist/components/HelloWorld.vue.d.ts +6 -0
- package/dist/components/TheWelcome.vue.d.ts +3 -0
- package/dist/components/WelcomeItem.vue.d.ts +17 -0
- package/dist/components/YouyuButton.vue.d.ts +44 -0
- package/dist/components/icons/IconCommunity.vue.d.ts +3 -0
- package/dist/components/icons/IconDocumentation.vue.d.ts +3 -0
- package/dist/components/icons/IconEcosystem.vue.d.ts +3 -0
- package/dist/components/icons/IconSupport.vue.d.ts +3 -0
- package/dist/components/icons/IconTooling.vue.d.ts +3 -0
- package/dist/favicon.ico +0 -0
- package/dist/main.css +1 -0
- package/dist/main.d.ts +76 -0
- package/dist/types.d.ts +18 -0
- package/dist/youyu-button.es.js +197 -0
- package/dist/youyu-button.es.js.map +1 -0
- package/dist/youyu-button.umd.js +39 -0
- package/dist/youyu-button.umd.js.map +1 -0
- package/package.json +44 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 youyu-button
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# youyu-button
|
|
2
|
+
|
|
3
|
+
一个基于 Vue 3 的自定义按钮组件插件,提供丰富的样式和交互功能。
|
|
4
|
+
|
|
5
|
+
## 功能特性
|
|
6
|
+
|
|
7
|
+
- 支持多种按钮类型:默认、主要、次要、成功、警告、危险、信息
|
|
8
|
+
- 支持多种按钮尺寸:迷你(MINI)、小(S)、中(M)、大(L)、特大(XL)
|
|
9
|
+
- 支持圆角样式
|
|
10
|
+
- 支持激活和禁用状态
|
|
11
|
+
- 内置消息提示功能
|
|
12
|
+
- 内置确认对话框功能
|
|
13
|
+
- 内置弹窗功能
|
|
14
|
+
- 响应式设计
|
|
15
|
+
|
|
16
|
+
## 安装
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
# 使用 npm
|
|
20
|
+
npm install youyu-button
|
|
21
|
+
|
|
22
|
+
# 使用 yarn
|
|
23
|
+
yarn add youyu-button
|
|
24
|
+
|
|
25
|
+
# 使用 pnpm
|
|
26
|
+
pnpm add youyu-button
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## 使用
|
|
30
|
+
|
|
31
|
+
### 全局安装
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
// main.ts
|
|
35
|
+
import { createApp } from "vue";
|
|
36
|
+
import YouyuButtonPlugin from "youyu-button";
|
|
37
|
+
import "youyu-button/dist/style.css";
|
|
38
|
+
|
|
39
|
+
const app = createApp(App);
|
|
40
|
+
app.use(YouyuButtonPlugin);
|
|
41
|
+
app.mount("#app");
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### 局部使用
|
|
45
|
+
|
|
46
|
+
```vue
|
|
47
|
+
<script setup lang="ts">
|
|
48
|
+
import { YouyuButton } from "youyu-button";
|
|
49
|
+
import "youyu-button/dist/style.css";
|
|
50
|
+
</script>
|
|
51
|
+
|
|
52
|
+
<template>
|
|
53
|
+
<YouyuButton type="primary">主要按钮</YouyuButton>
|
|
54
|
+
</template>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## 组件属性
|
|
58
|
+
|
|
59
|
+
| 属性名 | 类型 | 默认值 | 说明 |
|
|
60
|
+
| -------------------- | ------- | -------------------- | --------------------------------------------------------------------- |
|
|
61
|
+
| type | string | default | 按钮类型:default, primary, secondary, success, warning, danger, info |
|
|
62
|
+
| size | string | M | 按钮尺寸:MINI, S, M, L, XL |
|
|
63
|
+
| rounded | boolean | false | 是否显示圆角 |
|
|
64
|
+
| active | boolean | false | 是否激活状态 |
|
|
65
|
+
| disabled | boolean | false | 是否禁用状态 |
|
|
66
|
+
| className | string | | 自定义类名 |
|
|
67
|
+
| data-toggle | string | | 交互类型:message, confirm, layer |
|
|
68
|
+
| data-message | string | 操作成功 | 提示消息内容 |
|
|
69
|
+
| data-type | string | success | 消息类型:success, error, warning, info |
|
|
70
|
+
| data-confirm-message | string | 确定要执行此操作吗? | 确认对话框消息 |
|
|
71
|
+
| data-layer-title | string | 弹窗 | 弹窗标题 |
|
|
72
|
+
| data-layer-url | string | # | 弹窗内容 URL |
|
|
73
|
+
|
|
74
|
+
## 事件
|
|
75
|
+
|
|
76
|
+
| 事件名 | 说明 | 参数 |
|
|
77
|
+
| ------ | -------- | ---------- |
|
|
78
|
+
| click | 点击事件 | MouseEvent |
|
|
79
|
+
|
|
80
|
+
## 示例
|
|
81
|
+
|
|
82
|
+
### 基础按钮
|
|
83
|
+
|
|
84
|
+
```vue
|
|
85
|
+
<YouyuButton type="default">默认按钮</YouyuButton>
|
|
86
|
+
<YouyuButton type="primary">主要按钮</YouyuButton>
|
|
87
|
+
<YouyuButton type="success">成功按钮</YouyuButton>
|
|
88
|
+
<YouyuButton type="warning">警告按钮</YouyuButton>
|
|
89
|
+
<YouyuButton type="danger">危险按钮</YouyuButton>
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### 不同尺寸
|
|
93
|
+
|
|
94
|
+
```vue
|
|
95
|
+
<YouyuButton type="primary" size="MINI">迷你按钮</YouyuButton>
|
|
96
|
+
<YouyuButton type="primary" size="S">小按钮</YouyuButton>
|
|
97
|
+
<YouyuButton type="primary" size="M">中按钮</YouyuButton>
|
|
98
|
+
<YouyuButton type="primary" size="L">大按钮</YouyuButton>
|
|
99
|
+
<YouyuButton type="primary" size="XL">特大按钮</YouyuButton>
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### 圆角按钮
|
|
103
|
+
|
|
104
|
+
```vue
|
|
105
|
+
<YouyuButton type="primary" rounded>圆角按钮</YouyuButton>
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### 消息提示
|
|
109
|
+
|
|
110
|
+
```vue
|
|
111
|
+
<YouyuButton
|
|
112
|
+
type="primary"
|
|
113
|
+
rounded
|
|
114
|
+
data-toggle="message"
|
|
115
|
+
data-message="操作成功!"
|
|
116
|
+
data-type="success"
|
|
117
|
+
>
|
|
118
|
+
显示成功提示
|
|
119
|
+
</YouyuButton>
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### 确认对话框
|
|
123
|
+
|
|
124
|
+
```vue
|
|
125
|
+
<YouyuButton
|
|
126
|
+
type="primary"
|
|
127
|
+
rounded
|
|
128
|
+
data-toggle="confirm"
|
|
129
|
+
data-confirm-message="确定要删除这个项目吗?"
|
|
130
|
+
data-message="删除成功!"
|
|
131
|
+
>
|
|
132
|
+
确认删除
|
|
133
|
+
</YouyuButton>
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### 弹窗
|
|
137
|
+
|
|
138
|
+
```vue
|
|
139
|
+
<YouyuButton
|
|
140
|
+
type="primary"
|
|
141
|
+
rounded
|
|
142
|
+
data-toggle="layer"
|
|
143
|
+
data-layer-title="示例弹窗"
|
|
144
|
+
data-layer-url="#"
|
|
145
|
+
>
|
|
146
|
+
打开弹窗
|
|
147
|
+
</YouyuButton>
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## 项目开发
|
|
151
|
+
|
|
152
|
+
### 安装依赖
|
|
153
|
+
|
|
154
|
+
```sh
|
|
155
|
+
pnpm install
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### 开发模式
|
|
159
|
+
|
|
160
|
+
```sh
|
|
161
|
+
pnpm dev
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### 构建生产版本
|
|
165
|
+
|
|
166
|
+
```sh
|
|
167
|
+
pnpm build
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## 许可证
|
|
171
|
+
|
|
172
|
+
MIT
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
2
|
+
declare const _default: typeof __VLS_export;
|
|
3
|
+
export default _default;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
msg: string;
|
|
3
|
+
};
|
|
4
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
5
|
+
declare const _default: typeof __VLS_export;
|
|
6
|
+
export default _default;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
2
|
+
declare const _default: typeof __VLS_export;
|
|
3
|
+
export default _default;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare var __VLS_1: {}, __VLS_3: {}, __VLS_5: {};
|
|
2
|
+
type __VLS_Slots = {} & {
|
|
3
|
+
icon?: (props: typeof __VLS_1) => any;
|
|
4
|
+
} & {
|
|
5
|
+
heading?: (props: typeof __VLS_3) => any;
|
|
6
|
+
} & {
|
|
7
|
+
default?: (props: typeof __VLS_5) => any;
|
|
8
|
+
};
|
|
9
|
+
declare const __VLS_base: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
10
|
+
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
11
|
+
declare const _default: typeof __VLS_export;
|
|
12
|
+
export default _default;
|
|
13
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
14
|
+
new (): {
|
|
15
|
+
$slots: S;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import "../youyu-button/css/button.css";
|
|
2
|
+
import type { Props } from "../types";
|
|
3
|
+
declare global {
|
|
4
|
+
interface Window {
|
|
5
|
+
MyUI?: {
|
|
6
|
+
Button?: {
|
|
7
|
+
showMessage: (message: string, type?: string) => void;
|
|
8
|
+
showConfirm: (message: string, onConfirm?: () => void, onCancel?: () => void) => void;
|
|
9
|
+
openLayer: (title: string, url: string, id?: string, width?: string) => void;
|
|
10
|
+
init: () => void;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
declare var __VLS_1: {};
|
|
16
|
+
type __VLS_Slots = {} & {
|
|
17
|
+
default?: (props: typeof __VLS_1) => any;
|
|
18
|
+
};
|
|
19
|
+
declare const __VLS_base: import("vue").DefineComponent<Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
|
|
20
|
+
click: (event: MouseEvent) => any;
|
|
21
|
+
}, string, import("vue").PublicProps, Readonly<Props> & Readonly<{
|
|
22
|
+
onClick?: ((event: MouseEvent) => any) | undefined;
|
|
23
|
+
}>, {
|
|
24
|
+
type: import("../types").ButtonType;
|
|
25
|
+
size: import("../types").ButtonSize;
|
|
26
|
+
rounded: boolean;
|
|
27
|
+
active: boolean;
|
|
28
|
+
disabled: boolean;
|
|
29
|
+
className: string;
|
|
30
|
+
dataToggle: string;
|
|
31
|
+
dataMessage: string;
|
|
32
|
+
dataType: string;
|
|
33
|
+
dataConfirmMessage: string;
|
|
34
|
+
dataLayerTitle: string;
|
|
35
|
+
dataLayerUrl: string;
|
|
36
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
37
|
+
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
38
|
+
declare const _default: typeof __VLS_export;
|
|
39
|
+
export default _default;
|
|
40
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
41
|
+
new (): {
|
|
42
|
+
$slots: S;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
2
|
+
declare const _default: typeof __VLS_export;
|
|
3
|
+
export default _default;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
2
|
+
declare const _default: typeof __VLS_export;
|
|
3
|
+
export default _default;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
2
|
+
declare const _default: typeof __VLS_export;
|
|
3
|
+
export default _default;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
2
|
+
declare const _default: typeof __VLS_export;
|
|
3
|
+
export default _default;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
2
|
+
declare const _default: typeof __VLS_export;
|
|
3
|
+
export default _default;
|
package/dist/favicon.ico
ADDED
|
Binary file
|
package/dist/main.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.container{max-width:1200px;margin:0 auto;padding:20px;font-family:Arial,Microsoft YaHei,sans-serif}.button-group{margin-bottom:30px;display:flex;gap:10px;flex-wrap:wrap}h1{color:#333;border-bottom:1px solid #eee;padding-bottom:10px;margin-bottom:30px}h2{color:#666;margin-top:40px;margin-bottom:20px;font-size:18px}.btn{display:inline-block;box-sizing:border-box;cursor:pointer;text-align:center;font-weight:400;white-space:nowrap;vertical-align:middle;border:solid 1px #ddd;background-color:#fff;width:auto;text-decoration:none;transition:background-color .1s linear,border-color .1s linear}.btn{font-size:14px;height:31px;line-height:1.42857;padding:4px 12px}a.btn{line-height:21px}.btn.size-MINI{font-size:12px;height:23px;padding:1px 4px;line-height:1.42857}a.btn.size-MINI{line-height:21px}.btn.size-S{font-size:12px;height:27px;padding:3px 8px;line-height:1.42857}a.btn.size-S{line-height:19px}.btn.size-L{font-size:16px;height:41px;padding:8px 16px;line-height:1.42857}a.btn.size-L{line-height:23px}.btn.size-XL{font-size:18px;height:48px;padding:10px 24px;line-height:1.42857}a.btn.size-XL{line-height:26px}.btn-default{background-color:#e6e6e6;border-color:#e6e6e6;color:#333}.btn-default:hover,.btn-default:focus,.btn-default:active,.btn-default.active{background-color:#c7c7c7;border-color:#c7c7c7;color:#333}.btn-primary{background-color:#5a98de;border-color:#5a98de;color:#fff}.btn-primary:hover,.btn-primary:focus,.btn-primary:active,.btn-primary.active{background-color:#0a6999;border-color:#0a6999;color:#fff}.btn-secondary{background-color:#3bb4f2;border-color:#3bb4f2;color:#fff}.btn-secondary:hover,.btn-secondary:focus,.btn-secondary:active,.btn-secondary.active{background-color:#0f9ae0;border-color:#0f9ae0;color:#fff}.btn-success{background-color:#5eb95e;border-color:#5eb95e;color:#fff}.btn-success:hover,.btn-success:focus,.btn-success:active,.btn-success.active{background-color:#429842;border-color:#429842;color:#fff}.btn-warning{background-color:#f37b1d;border-color:#f37b1d;color:#fff}.btn-warning:hover,.btn-warning:focus,.btn-warning:active,.btn-warning.active{background-color:#c85e0b;border-color:#c85e0b;color:#fff}.btn-danger{background-color:#dd514c;border-color:#dd514c;color:#fff}.btn-danger:hover,.btn-danger:focus,.btn-danger:active,.btn-danger.active{background-color:#c62b26;border-color:#c62b26;color:#fff}.btn-info{background-color:#4990e2;border-color:#4990e2;color:#fff}.btn-info:hover,.btn-info:focus,.btn-info:active,.btn-info.active{background-color:#2873cc;border-color:#2873cc;color:#fff}.btn.radius{border-radius:4px}.btn.size-MINI.radius{border-radius:3px}.btn.size-L.radius{border-radius:5px}.btn.size-XL.radius{border-radius:6px}.btn:active,.btn.active{background-color:#ccc}.btn.active,.btn:active{box-shadow:0 1px 8px #00000020 inset}.btn.disabled,.btn[disabled]{cursor:not-allowed;opacity:.65;filter:alpha(opacity=65);pointer-events:none}.my-iconfont{margin-right:5px;font-style:normal}@media(max-width:767px){.button-group{flex-direction:column;gap:8px}.btn{width:100%;text-align:center}}
|
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import "./youyu-button/css/button.css";
|
|
2
|
+
import YouyuButton from "./components/YouyuButton.vue";
|
|
3
|
+
import type { App } from "vue";
|
|
4
|
+
import * as types from "./types";
|
|
5
|
+
declare const plugin: {
|
|
6
|
+
install(app: App): void;
|
|
7
|
+
YouyuButton: {
|
|
8
|
+
new (...args: any[]): import("vue").CreateComponentPublicInstanceWithMixins<Readonly<types.Props> & Readonly<{
|
|
9
|
+
onClick?: ((event: MouseEvent) => any) | undefined;
|
|
10
|
+
}>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
|
|
11
|
+
click: (event: MouseEvent) => any;
|
|
12
|
+
}, import("vue").PublicProps, {
|
|
13
|
+
type: types.ButtonType;
|
|
14
|
+
size: types.ButtonSize;
|
|
15
|
+
rounded: boolean;
|
|
16
|
+
active: boolean;
|
|
17
|
+
disabled: boolean;
|
|
18
|
+
className: string;
|
|
19
|
+
dataToggle: string;
|
|
20
|
+
dataMessage: string;
|
|
21
|
+
dataType: string;
|
|
22
|
+
dataConfirmMessage: string;
|
|
23
|
+
dataLayerTitle: string;
|
|
24
|
+
dataLayerUrl: string;
|
|
25
|
+
}, false, {}, {}, import("vue").GlobalComponents, import("vue").GlobalDirectives, string, {}, any, import("vue").ComponentProvideOptions, {
|
|
26
|
+
P: {};
|
|
27
|
+
B: {};
|
|
28
|
+
D: {};
|
|
29
|
+
C: {};
|
|
30
|
+
M: {};
|
|
31
|
+
Defaults: {};
|
|
32
|
+
}, Readonly<types.Props> & Readonly<{
|
|
33
|
+
onClick?: ((event: MouseEvent) => any) | undefined;
|
|
34
|
+
}>, {}, {}, {}, {}, {
|
|
35
|
+
type: types.ButtonType;
|
|
36
|
+
size: types.ButtonSize;
|
|
37
|
+
rounded: boolean;
|
|
38
|
+
active: boolean;
|
|
39
|
+
disabled: boolean;
|
|
40
|
+
className: string;
|
|
41
|
+
dataToggle: string;
|
|
42
|
+
dataMessage: string;
|
|
43
|
+
dataType: string;
|
|
44
|
+
dataConfirmMessage: string;
|
|
45
|
+
dataLayerTitle: string;
|
|
46
|
+
dataLayerUrl: string;
|
|
47
|
+
}>;
|
|
48
|
+
__isFragment?: never;
|
|
49
|
+
__isTeleport?: never;
|
|
50
|
+
__isSuspense?: never;
|
|
51
|
+
} & import("vue").ComponentOptionsBase<Readonly<types.Props> & Readonly<{
|
|
52
|
+
onClick?: ((event: MouseEvent) => any) | undefined;
|
|
53
|
+
}>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
|
|
54
|
+
click: (event: MouseEvent) => any;
|
|
55
|
+
}, string, {
|
|
56
|
+
type: types.ButtonType;
|
|
57
|
+
size: types.ButtonSize;
|
|
58
|
+
rounded: boolean;
|
|
59
|
+
active: boolean;
|
|
60
|
+
disabled: boolean;
|
|
61
|
+
className: string;
|
|
62
|
+
dataToggle: string;
|
|
63
|
+
dataMessage: string;
|
|
64
|
+
dataType: string;
|
|
65
|
+
dataConfirmMessage: string;
|
|
66
|
+
dataLayerTitle: string;
|
|
67
|
+
dataLayerUrl: string;
|
|
68
|
+
}, {}, string, {}, import("vue").GlobalComponents, import("vue").GlobalDirectives, string, import("vue").ComponentProvideOptions> & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & (new () => {
|
|
69
|
+
$slots: {
|
|
70
|
+
default?: (props: {}) => any;
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
export default plugin;
|
|
75
|
+
export { YouyuButton };
|
|
76
|
+
export * from "./types";
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const ButtonType: readonly ["default", "primary", "secondary", "success", "warning", "danger", "info"];
|
|
2
|
+
export type ButtonType = (typeof ButtonType)[number];
|
|
3
|
+
export declare const ButtonSize: readonly ["MINI", "S", "M", "L", "XL"];
|
|
4
|
+
export type ButtonSize = (typeof ButtonSize)[number];
|
|
5
|
+
export interface Props {
|
|
6
|
+
type?: ButtonType;
|
|
7
|
+
size?: ButtonSize;
|
|
8
|
+
rounded?: boolean;
|
|
9
|
+
active?: boolean;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
className?: string;
|
|
12
|
+
dataToggle?: string;
|
|
13
|
+
dataMessage?: string;
|
|
14
|
+
dataType?: string;
|
|
15
|
+
dataConfirmMessage?: string;
|
|
16
|
+
dataLayerTitle?: string;
|
|
17
|
+
dataLayerUrl?: string;
|
|
18
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { defineComponent as b, createElementBlock as h, openBlock as p, normalizeClass as x, renderSlot as v } from "vue";
|
|
2
|
+
const w = ["disabled", "data-toggle", "data-message", "data-type", "data-confirm-message", "data-layer-title", "data-layer-url"], B = /* @__PURE__ */ b({
|
|
3
|
+
__name: "YouyuButton",
|
|
4
|
+
props: {
|
|
5
|
+
type: { default: "default" },
|
|
6
|
+
size: { default: "M" },
|
|
7
|
+
rounded: { type: Boolean, default: !1 },
|
|
8
|
+
active: { type: Boolean, default: !1 },
|
|
9
|
+
disabled: { type: Boolean, default: !1 },
|
|
10
|
+
className: { default: "" },
|
|
11
|
+
dataToggle: { default: "" },
|
|
12
|
+
dataMessage: { default: "" },
|
|
13
|
+
dataType: { default: "" },
|
|
14
|
+
dataConfirmMessage: { default: "" },
|
|
15
|
+
dataLayerTitle: { default: "" },
|
|
16
|
+
dataLayerUrl: { default: "" }
|
|
17
|
+
},
|
|
18
|
+
emits: ["click"],
|
|
19
|
+
setup(t, { emit: r }) {
|
|
20
|
+
const i = t, l = r, u = (o) => {
|
|
21
|
+
i.disabled || l("click", o);
|
|
22
|
+
}, n = window.MyUI || {};
|
|
23
|
+
return n.Button = n.Button || {
|
|
24
|
+
/**
|
|
25
|
+
* 弹出提示信息
|
|
26
|
+
* @param message - 提示消息内容
|
|
27
|
+
* @param type - 提示类型 (success, error, warning, info)
|
|
28
|
+
*/
|
|
29
|
+
showMessage: function(o, d = "info") {
|
|
30
|
+
const e = document.createElement("div");
|
|
31
|
+
e.className = `my-message my-message-${d}`, e.textContent = o, e.style.cssText = `
|
|
32
|
+
position: fixed;
|
|
33
|
+
top: 20px;
|
|
34
|
+
right: 20px;
|
|
35
|
+
padding: 10px 20px;
|
|
36
|
+
border-radius: 4px;
|
|
37
|
+
color: white;
|
|
38
|
+
z-index: 9999;
|
|
39
|
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
|
|
40
|
+
transition: all 0.3s ease;
|
|
41
|
+
max-width: 300px;
|
|
42
|
+
word-wrap: break-word;
|
|
43
|
+
`;
|
|
44
|
+
const a = {
|
|
45
|
+
success: "#5eb95e",
|
|
46
|
+
error: "#dd514c",
|
|
47
|
+
warning: "#f37b1d",
|
|
48
|
+
info: "#5a98de"
|
|
49
|
+
}, s = a[d] || a.info;
|
|
50
|
+
e.style.backgroundColor = s, document.body.appendChild(e), setTimeout(() => {
|
|
51
|
+
e.style.opacity = "0", e.style.transform = "translateX(100%)", setTimeout(() => {
|
|
52
|
+
document.body.contains(e) && document.body.removeChild(e);
|
|
53
|
+
}, 300);
|
|
54
|
+
}, 3e3);
|
|
55
|
+
},
|
|
56
|
+
/**
|
|
57
|
+
* 弹出确认对话框
|
|
58
|
+
* @param {string} message - 确认消息内容
|
|
59
|
+
* @param {function} onConfirm - 确认回调函数
|
|
60
|
+
* @param {function} onCancel - 取消回调函数
|
|
61
|
+
*/
|
|
62
|
+
showConfirm: function(o, d, e) {
|
|
63
|
+
const a = document.createElement("div");
|
|
64
|
+
a.className = "my-confirm-overlay", a.style.cssText = `
|
|
65
|
+
position: fixed;
|
|
66
|
+
top: 0;
|
|
67
|
+
left: 0;
|
|
68
|
+
width: 100%;
|
|
69
|
+
height: 100%;
|
|
70
|
+
background-color: rgba(0, 0, 0, 0.5);
|
|
71
|
+
z-index: 9998;
|
|
72
|
+
display: flex;
|
|
73
|
+
justify-content: center;
|
|
74
|
+
align-items: center;
|
|
75
|
+
`;
|
|
76
|
+
const s = document.createElement("div");
|
|
77
|
+
s.className = "my-confirm-box", s.style.cssText = `
|
|
78
|
+
background-color: white;
|
|
79
|
+
border-radius: 4px;
|
|
80
|
+
padding: 20px;
|
|
81
|
+
width: 400px;
|
|
82
|
+
max-width: 90%;
|
|
83
|
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
|
84
|
+
`, s.innerHTML = `
|
|
85
|
+
<div class="my-confirm-content">${o}</div>
|
|
86
|
+
<div class="my-confirm-buttons" style="text-align: right; margin-top: 20px;">
|
|
87
|
+
<button class="btn btn-default radius" style="margin-right: 10px;">取消</button>
|
|
88
|
+
<button class="btn btn-primary radius">确认</button>
|
|
89
|
+
</div>
|
|
90
|
+
`, a.appendChild(s), document.body.appendChild(a);
|
|
91
|
+
const m = s.querySelector(
|
|
92
|
+
".btn-default"
|
|
93
|
+
), y = s.querySelector(
|
|
94
|
+
".btn-primary"
|
|
95
|
+
);
|
|
96
|
+
m.addEventListener("click", () => {
|
|
97
|
+
document.body.removeChild(a), e && e();
|
|
98
|
+
}), y.addEventListener("click", () => {
|
|
99
|
+
document.body.removeChild(a), d && d();
|
|
100
|
+
}), a.addEventListener("click", (f) => {
|
|
101
|
+
f.target === a && (document.body.removeChild(a), e && e());
|
|
102
|
+
});
|
|
103
|
+
const c = (f) => {
|
|
104
|
+
f.key === "Escape" && (document.body.contains(a) && (document.body.removeChild(a), e && e()), document.removeEventListener("keydown", c));
|
|
105
|
+
};
|
|
106
|
+
document.addEventListener("keydown", c);
|
|
107
|
+
},
|
|
108
|
+
/**
|
|
109
|
+
* 模拟打开弹窗功能
|
|
110
|
+
* @param {string} title - 弹窗标题
|
|
111
|
+
* @param {string} url - 弹窗内容URL
|
|
112
|
+
* @param {string} id - 弹窗ID
|
|
113
|
+
* @param {string} width - 弹窗宽度
|
|
114
|
+
*/
|
|
115
|
+
openLayer: function(o, d, e, a) {
|
|
116
|
+
this.showMessage("打开弹窗:" + o, "info"), console.log("打开弹窗参数:", { title: o, url: d, id: e, width: a });
|
|
117
|
+
},
|
|
118
|
+
/**
|
|
119
|
+
* 初始化按钮组件
|
|
120
|
+
*/
|
|
121
|
+
init: function() {
|
|
122
|
+
document.querySelectorAll(
|
|
123
|
+
"button[data-toggle], a.btn[data-toggle]"
|
|
124
|
+
).forEach((d) => {
|
|
125
|
+
d.addEventListener("click", function() {
|
|
126
|
+
const e = this.getAttribute("data-toggle"), a = this.getAttribute("data-message") || "操作成功", s = this.getAttribute("data-type") || "success";
|
|
127
|
+
if (n.Button)
|
|
128
|
+
switch (e) {
|
|
129
|
+
case "message":
|
|
130
|
+
n.Button.showMessage(a, s);
|
|
131
|
+
break;
|
|
132
|
+
case "confirm":
|
|
133
|
+
const m = this.getAttribute("data-confirm-message") || "确定要执行此操作吗?";
|
|
134
|
+
n.Button.showConfirm(m, () => {
|
|
135
|
+
n.Button && n.Button.showMessage(a, s);
|
|
136
|
+
});
|
|
137
|
+
break;
|
|
138
|
+
case "layer":
|
|
139
|
+
const y = this.getAttribute("data-layer-title") || "弹窗", c = this.getAttribute("data-layer-url") || "#";
|
|
140
|
+
n.Button.openLayer(y, c);
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}, window.MyUI = n, typeof window < "u" && n && n.Button && (document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", () => {
|
|
147
|
+
n.Button.init();
|
|
148
|
+
}) : n.Button.init()), (o, d) => (p(), h("button", {
|
|
149
|
+
class: x([
|
|
150
|
+
"btn",
|
|
151
|
+
`btn-${t.type}`,
|
|
152
|
+
t.size ? `size-${t.size}` : "",
|
|
153
|
+
{ radius: t.rounded },
|
|
154
|
+
{ active: t.active },
|
|
155
|
+
{ disabled: t.disabled },
|
|
156
|
+
t.className
|
|
157
|
+
]),
|
|
158
|
+
disabled: t.disabled,
|
|
159
|
+
onClick: u,
|
|
160
|
+
"data-toggle": t.dataToggle,
|
|
161
|
+
"data-message": t.dataMessage,
|
|
162
|
+
"data-type": t.dataType,
|
|
163
|
+
"data-confirm-message": t.dataConfirmMessage,
|
|
164
|
+
"data-layer-title": t.dataLayerTitle,
|
|
165
|
+
"data-layer-url": t.dataLayerUrl
|
|
166
|
+
}, [
|
|
167
|
+
v(o.$slots, "default", {}, void 0, !0)
|
|
168
|
+
], 10, w));
|
|
169
|
+
}
|
|
170
|
+
}), k = (t, r) => {
|
|
171
|
+
const i = t.__vccOpts || t;
|
|
172
|
+
for (const [l, u] of r)
|
|
173
|
+
i[l] = u;
|
|
174
|
+
return i;
|
|
175
|
+
}, g = /* @__PURE__ */ k(B, [["__scopeId", "data-v-fcc077ad"]]), M = [
|
|
176
|
+
"default",
|
|
177
|
+
"primary",
|
|
178
|
+
"secondary",
|
|
179
|
+
"success",
|
|
180
|
+
"warning",
|
|
181
|
+
"danger",
|
|
182
|
+
"info"
|
|
183
|
+
], E = ["MINI", "S", "M", "L", "XL"], T = {
|
|
184
|
+
// 安装方法
|
|
185
|
+
install(t) {
|
|
186
|
+
t.component("YouyuButton", g);
|
|
187
|
+
},
|
|
188
|
+
// 导出组件
|
|
189
|
+
YouyuButton: g
|
|
190
|
+
};
|
|
191
|
+
export {
|
|
192
|
+
E as ButtonSize,
|
|
193
|
+
M as ButtonType,
|
|
194
|
+
g as YouyuButton,
|
|
195
|
+
T as default
|
|
196
|
+
};
|
|
197
|
+
//# sourceMappingURL=youyu-button.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"youyu-button.es.js","sources":["../src/components/YouyuButton.vue","../src/types.ts","../src/main.ts"],"sourcesContent":["<template>\n <button\n :class=\"[\n 'btn',\n `btn-${type}`,\n size ? `size-${size}` : '',\n { radius: rounded },\n { active },\n { disabled },\n className,\n ]\"\n :disabled=\"disabled\"\n @click=\"handleClick\"\n :data-toggle=\"dataToggle\"\n :data-message=\"dataMessage\"\n :data-type=\"dataType\"\n :data-confirm-message=\"dataConfirmMessage\"\n :data-layer-title=\"dataLayerTitle\"\n :data-layer-url=\"dataLayerUrl\"\n >\n <slot></slot>\n </button>\n</template>\n\n<script setup lang=\"ts\">\nimport \"../youyu-button/css/button.css\";\nimport type { Props } from \"../types\";\n\n// 定义组件属性\nconst props = withDefaults(defineProps<Props>(), {\n type: \"default\",\n size: \"M\",\n rounded: false,\n active: false,\n disabled: false,\n className: \"\",\n dataToggle: \"\",\n dataMessage: \"\",\n dataType: \"\",\n dataConfirmMessage: \"\",\n dataLayerTitle: \"\",\n dataLayerUrl: \"\",\n});\n\n// 定义组件事件\nconst emit = defineEmits<{\n (e: \"click\", event: MouseEvent): void;\n}>();\n\n// 处理点击事件\nconst handleClick = (event: MouseEvent) => {\n if (props.disabled) return;\n emit(\"click\", event);\n};\n\n// 扩展Window接口\ndeclare global {\n interface Window {\n MyUI?: {\n Button?: {\n showMessage: (message: string, type?: string) => void;\n showConfirm: (\n message: string,\n onConfirm?: () => void,\n onCancel?: () => void\n ) => void;\n openLayer: (\n title: string,\n url: string,\n id?: string,\n width?: string\n ) => void;\n init: () => void;\n };\n };\n }\n}\n\n// 按钮命名空间\nconst MyUI = window.MyUI || {};\n\n// 确保MyUI.Button存在\nMyUI.Button = MyUI.Button || {\n /**\n * 弹出提示信息\n * @param message - 提示消息内容\n * @param type - 提示类型 (success, error, warning, info)\n */\n showMessage: function (message: string, type: string = \"info\") {\n // 创建提示元素\n const messageElement = document.createElement(\"div\");\n messageElement.className = `my-message my-message-${type}`;\n messageElement.textContent = message;\n messageElement.style.cssText = `\n position: fixed;\n top: 20px;\n right: 20px;\n padding: 10px 20px;\n border-radius: 4px;\n color: white;\n z-index: 9999;\n box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);\n transition: all 0.3s ease;\n max-width: 300px;\n word-wrap: break-word;\n `;\n\n // 根据类型设置背景色\n const colors: Record<string, string> = {\n success: \"#5eb95e\",\n error: \"#dd514c\",\n warning: \"#f37b1d\",\n info: \"#5a98de\",\n };\n const bgColor = colors[type] || colors.info;\n messageElement.style.backgroundColor = bgColor as string;\n\n // 添加到页面\n document.body.appendChild(messageElement);\n\n // 3秒后自动移除\n setTimeout(() => {\n messageElement.style.opacity = \"0\";\n messageElement.style.transform = \"translateX(100%)\";\n setTimeout(() => {\n if (document.body.contains(messageElement)) {\n document.body.removeChild(messageElement);\n }\n }, 300);\n }, 3000);\n },\n\n /**\n * 弹出确认对话框\n * @param {string} message - 确认消息内容\n * @param {function} onConfirm - 确认回调函数\n * @param {function} onCancel - 取消回调函数\n */\n showConfirm: function (\n message: string,\n onConfirm?: () => void,\n onCancel?: () => void\n ) {\n // 创建遮罩层\n const overlay = document.createElement(\"div\");\n overlay.className = \"my-confirm-overlay\";\n overlay.style.cssText = `\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background-color: rgba(0, 0, 0, 0.5);\n z-index: 9998;\n display: flex;\n justify-content: center;\n align-items: center;\n `;\n\n // 创建确认框\n const confirmBox = document.createElement(\"div\");\n confirmBox.className = \"my-confirm-box\";\n confirmBox.style.cssText = `\n background-color: white;\n border-radius: 4px;\n padding: 20px;\n width: 400px;\n max-width: 90%;\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);\n `;\n\n // 确认框内容\n confirmBox.innerHTML = `\n <div class=\"my-confirm-content\">${message}</div>\n <div class=\"my-confirm-buttons\" style=\"text-align: right; margin-top: 20px;\">\n <button class=\"btn btn-default radius\" style=\"margin-right: 10px;\">取消</button>\n <button class=\"btn btn-primary radius\">确认</button>\n </div>\n `;\n\n // 添加到页面\n overlay.appendChild(confirmBox);\n document.body.appendChild(overlay);\n\n // 绑定事件\n const cancelBtn = confirmBox.querySelector(\n \".btn-default\"\n ) as HTMLButtonElement;\n const confirmBtn = confirmBox.querySelector(\n \".btn-primary\"\n ) as HTMLButtonElement;\n\n // 取消按钮事件\n cancelBtn.addEventListener(\"click\", () => {\n document.body.removeChild(overlay);\n if (onCancel) {\n onCancel();\n }\n });\n\n // 确认按钮事件\n confirmBtn.addEventListener(\"click\", () => {\n document.body.removeChild(overlay);\n if (onConfirm) {\n onConfirm();\n }\n });\n\n // 点击遮罩层关闭\n overlay.addEventListener(\"click\", (e) => {\n if (e.target === overlay) {\n document.body.removeChild(overlay);\n if (onCancel) {\n onCancel();\n }\n }\n });\n\n // ESC键关闭\n const handleEscKey = (e: KeyboardEvent) => {\n if (e.key === \"Escape\") {\n if (document.body.contains(overlay)) {\n document.body.removeChild(overlay);\n if (onCancel) {\n onCancel();\n }\n }\n document.removeEventListener(\"keydown\", handleEscKey);\n }\n };\n document.addEventListener(\"keydown\", handleEscKey);\n },\n\n /**\n * 模拟打开弹窗功能\n * @param {string} title - 弹窗标题\n * @param {string} url - 弹窗内容URL\n * @param {string} id - 弹窗ID\n * @param {string} width - 弹窗宽度\n */\n openLayer: function (\n title: string,\n url: string,\n id?: string,\n width?: string\n ) {\n // 这里只是简单的模拟,实际项目中可能需要更复杂的实现\n this.showMessage(\"打开弹窗:\" + title, \"info\");\n console.log(\"打开弹窗参数:\", { title, url, id, width });\n },\n\n /**\n * 初始化按钮组件\n */\n init: function () {\n // 为所有带有data-toggle属性的按钮添加事件监听\n const buttons = document.querySelectorAll(\n \"button[data-toggle], a.btn[data-toggle]\"\n );\n\n buttons.forEach((button) => {\n button.addEventListener(\"click\", function (this: any) {\n const toggleType = this.getAttribute(\"data-toggle\");\n const message = this.getAttribute(\"data-message\") || \"操作成功\";\n const type = this.getAttribute(\"data-type\") || \"success\";\n\n if (!MyUI.Button) return;\n\n switch (toggleType) {\n case \"message\":\n MyUI.Button.showMessage(message, type);\n break;\n case \"confirm\":\n const confirmMessage =\n this.getAttribute(\"data-confirm-message\") ||\n \"确定要执行此操作吗?\";\n MyUI.Button.showConfirm(confirmMessage, () => {\n if (MyUI.Button) {\n MyUI.Button.showMessage(message, type);\n }\n });\n break;\n case \"layer\":\n const layerTitle = this.getAttribute(\"data-layer-title\") || \"弹窗\";\n const layerUrl = this.getAttribute(\"data-layer-url\") || \"#\";\n MyUI.Button.openLayer(layerTitle, layerUrl);\n break;\n }\n });\n });\n },\n};\n\n// 挂载到全局\nwindow.MyUI = MyUI;\n\n// 页面加载完成后初始化按钮组件\nif (typeof window !== \"undefined\" && MyUI && MyUI.Button) {\n if (document.readyState === \"loading\") {\n document.addEventListener(\"DOMContentLoaded\", () => {\n MyUI.Button!.init();\n });\n } else {\n MyUI.Button.init();\n }\n}\n</script>\n\n<style scoped>\n/* 组件特定样式可以在这里添加 */\n</style>\n","// 按钮类型\nexport const ButtonType = [\n \"default\",\n \"primary\",\n \"secondary\",\n \"success\",\n \"warning\",\n \"danger\",\n \"info\",\n] as const;\nexport type ButtonType = (typeof ButtonType)[number];\n\n// 按钮尺寸\nexport const ButtonSize = [\"MINI\", \"S\", \"M\", \"L\", \"XL\"] as const;\nexport type ButtonSize = (typeof ButtonSize)[number];\n\n// 按钮属性定义\nexport interface Props {\n type?: ButtonType;\n size?: ButtonSize;\n rounded?: boolean;\n active?: boolean;\n disabled?: boolean;\n className?: string;\n dataToggle?: string;\n dataMessage?: string;\n dataType?: string;\n dataConfirmMessage?: string;\n dataLayerTitle?: string;\n dataLayerUrl?: string;\n}","import \"./youyu-button/css/button.css\";\nimport YouyuButton from \"./components/YouyuButton.vue\";\nimport type { App } from \"vue\";\nimport * as types from \"./types\";\n\n// 定义插件类型\nconst plugin = {\n // 安装方法\n install(app: App) {\n // 全局注册组件\n app.component(\"YouyuButton\", YouyuButton);\n },\n // 导出组件\n YouyuButton,\n};\n\n// 导出插件、组件和类型\nexport default plugin;\nexport { YouyuButton };\nexport * from \"./types\";\n\n// 开发环境下自动挂载(保持原有功能)\nif (import.meta.env.DEV) {\n import(\"./assets/main.css\").then(() => {\n import(\"vue\").then(({ createApp }) => {\n import(\"./App.vue\").then(({ default: App }) => {\n createApp(App).mount(\"#app\");\n });\n });\n });\n}\n"],"names":["props","__props","emit","__emit","handleClick","event","MyUI","message","type","messageElement","colors","bgColor","onConfirm","onCancel","overlay","confirmBox","cancelBtn","confirmBtn","e","handleEscKey","title","url","id","width","button","toggleType","confirmMessage","layerTitle","layerUrl","_createElementBlock","_normalizeClass","_renderSlot","_ctx","ButtonType","ButtonSize","plugin","app","YouyuButton"],"mappings":";;;;;;;;;;;;;;;;;;;AA6BA,UAAMA,IAAQC,GAgBRC,IAAOC,GAKPC,IAAc,CAACC,MAAsB;AACzC,MAAIL,EAAM,YACVE,EAAK,SAASG,CAAK;AAAA,IACrB,GA0BMC,IAAO,OAAO,QAAQ,CAAA;AAG5B,WAAAA,EAAK,SAASA,EAAK,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAM3B,aAAa,SAAUC,GAAiBC,IAAe,QAAQ;AAE7D,cAAMC,IAAiB,SAAS,cAAc,KAAK;AACnD,QAAAA,EAAe,YAAY,yBAAyBD,CAAI,IACxDC,EAAe,cAAcF,GAC7BE,EAAe,MAAM,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAe/B,cAAMC,IAAiC;AAAA,UACrC,SAAS;AAAA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amd?define(["exports","vue"],c):(r=typeof globalThis<"u"?globalThis:r||self,c(r.YouyuButton={},r.Vue))})(this,(function(r,c){"use strict";var h=document.createElement("style");h.textContent=`.container{max-width:1200px;margin:0 auto;padding:20px;font-family:Arial,Microsoft YaHei,sans-serif}.button-group{margin-bottom:30px;display:flex;gap:10px;flex-wrap:wrap}h1{color:#333;border-bottom:1px solid #eee;padding-bottom:10px;margin-bottom:30px}h2{color:#666;margin-top:40px;margin-bottom:20px;font-size:18px}.btn{display:inline-block;box-sizing:border-box;cursor:pointer;text-align:center;font-weight:400;white-space:nowrap;vertical-align:middle;border:solid 1px #ddd;background-color:#fff;width:auto;text-decoration:none;transition:background-color .1s linear,border-color .1s linear}.btn{font-size:14px;height:31px;line-height:1.42857;padding:4px 12px}a.btn{line-height:21px}.btn.size-MINI{font-size:12px;height:23px;padding:1px 4px;line-height:1.42857}a.btn.size-MINI{line-height:21px}.btn.size-S{font-size:12px;height:27px;padding:3px 8px;line-height:1.42857}a.btn.size-S{line-height:19px}.btn.size-L{font-size:16px;height:41px;padding:8px 16px;line-height:1.42857}a.btn.size-L{line-height:23px}.btn.size-XL{font-size:18px;height:48px;padding:10px 24px;line-height:1.42857}a.btn.size-XL{line-height:26px}.btn-default{background-color:#e6e6e6;border-color:#e6e6e6;color:#333}.btn-default:hover,.btn-default:focus,.btn-default:active,.btn-default.active{background-color:#c7c7c7;border-color:#c7c7c7;color:#333}.btn-primary{background-color:#5a98de;border-color:#5a98de;color:#fff}.btn-primary:hover,.btn-primary:focus,.btn-primary:active,.btn-primary.active{background-color:#0a6999;border-color:#0a6999;color:#fff}.btn-secondary{background-color:#3bb4f2;border-color:#3bb4f2;color:#fff}.btn-secondary:hover,.btn-secondary:focus,.btn-secondary:active,.btn-secondary.active{background-color:#0f9ae0;border-color:#0f9ae0;color:#fff}.btn-success{background-color:#5eb95e;border-color:#5eb95e;color:#fff}.btn-success:hover,.btn-success:focus,.btn-success:active,.btn-success.active{background-color:#429842;border-color:#429842;color:#fff}.btn-warning{background-color:#f37b1d;border-color:#f37b1d;color:#fff}.btn-warning:hover,.btn-warning:focus,.btn-warning:active,.btn-warning.active{background-color:#c85e0b;border-color:#c85e0b;color:#fff}.btn-danger{background-color:#dd514c;border-color:#dd514c;color:#fff}.btn-danger:hover,.btn-danger:focus,.btn-danger:active,.btn-danger.active{background-color:#c62b26;border-color:#c62b26;color:#fff}.btn-info{background-color:#4990e2;border-color:#4990e2;color:#fff}.btn-info:hover,.btn-info:focus,.btn-info:active,.btn-info.active{background-color:#2873cc;border-color:#2873cc;color:#fff}.btn.radius{border-radius:4px}.btn.size-MINI.radius{border-radius:3px}.btn.size-L.radius{border-radius:5px}.btn.size-XL.radius{border-radius:6px}.btn:active,.btn.active{background-color:#ccc}.btn.active,.btn:active{box-shadow:0 1px 8px #00000020 inset}.btn.disabled,.btn[disabled]{cursor:not-allowed;opacity:.65;filter:alpha(opacity=65);pointer-events:none}.my-iconfont{margin-right:5px;font-style:normal}@media(max-width:767px){.button-group{flex-direction:column;gap:8px}.btn{width:100%;text-align:center}}
|
|
2
|
+
/*$vite$:1*/`,document.head.appendChild(h);const x=["disabled","data-toggle","data-message","data-type","data-confirm-message","data-layer-title","data-layer-url"],b=((e,u)=>{const s=e.__vccOpts||e;for(const[f,g]of u)s[f]=g;return s})(c.defineComponent({__name:"YouyuButton",props:{type:{default:"default"},size:{default:"M"},rounded:{type:Boolean,default:!1},active:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},className:{default:""},dataToggle:{default:""},dataMessage:{default:""},dataType:{default:""},dataConfirmMessage:{default:""},dataLayerTitle:{default:""},dataLayerUrl:{default:""}},emits:["click"],setup(e,{emit:u}){const s=e,f=u,g=a=>{s.disabled||f("click",a)},n=window.MyUI||{};return n.Button=n.Button||{showMessage:function(a,d="info"){const t=document.createElement("div");t.className=`my-message my-message-${d}`,t.textContent=a,t.style.cssText=`
|
|
3
|
+
position: fixed;
|
|
4
|
+
top: 20px;
|
|
5
|
+
right: 20px;
|
|
6
|
+
padding: 10px 20px;
|
|
7
|
+
border-radius: 4px;
|
|
8
|
+
color: white;
|
|
9
|
+
z-index: 9999;
|
|
10
|
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
|
|
11
|
+
transition: all 0.3s ease;
|
|
12
|
+
max-width: 300px;
|
|
13
|
+
word-wrap: break-word;
|
|
14
|
+
`;const o={success:"#5eb95e",error:"#dd514c",warning:"#f37b1d",info:"#5a98de"},i=o[d]||o.info;t.style.backgroundColor=i,document.body.appendChild(t),setTimeout(()=>{t.style.opacity="0",t.style.transform="translateX(100%)",setTimeout(()=>{document.body.contains(t)&&document.body.removeChild(t)},300)},3e3)},showConfirm:function(a,d,t){const o=document.createElement("div");o.className="my-confirm-overlay",o.style.cssText=`
|
|
15
|
+
position: fixed;
|
|
16
|
+
top: 0;
|
|
17
|
+
left: 0;
|
|
18
|
+
width: 100%;
|
|
19
|
+
height: 100%;
|
|
20
|
+
background-color: rgba(0, 0, 0, 0.5);
|
|
21
|
+
z-index: 9998;
|
|
22
|
+
display: flex;
|
|
23
|
+
justify-content: center;
|
|
24
|
+
align-items: center;
|
|
25
|
+
`;const i=document.createElement("div");i.className="my-confirm-box",i.style.cssText=`
|
|
26
|
+
background-color: white;
|
|
27
|
+
border-radius: 4px;
|
|
28
|
+
padding: 20px;
|
|
29
|
+
width: 400px;
|
|
30
|
+
max-width: 90%;
|
|
31
|
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
|
32
|
+
`,i.innerHTML=`
|
|
33
|
+
<div class="my-confirm-content">${a}</div>
|
|
34
|
+
<div class="my-confirm-buttons" style="text-align: right; margin-top: 20px;">
|
|
35
|
+
<button class="btn btn-default radius" style="margin-right: 10px;">取消</button>
|
|
36
|
+
<button class="btn btn-primary radius">确认</button>
|
|
37
|
+
</div>
|
|
38
|
+
`,o.appendChild(i),document.body.appendChild(o);const p=i.querySelector(".btn-default"),m=i.querySelector(".btn-primary");p.addEventListener("click",()=>{document.body.removeChild(o),t&&t()}),m.addEventListener("click",()=>{document.body.removeChild(o),d&&d()}),o.addEventListener("click",y=>{y.target===o&&(document.body.removeChild(o),t&&t())});const l=y=>{y.key==="Escape"&&(document.body.contains(o)&&(document.body.removeChild(o),t&&t()),document.removeEventListener("keydown",l))};document.addEventListener("keydown",l)},openLayer:function(a,d,t,o){this.showMessage("打开弹窗:"+a,"info"),console.log("打开弹窗参数:",{title:a,url:d,id:t,width:o})},init:function(){document.querySelectorAll("button[data-toggle], a.btn[data-toggle]").forEach(d=>{d.addEventListener("click",function(){const t=this.getAttribute("data-toggle"),o=this.getAttribute("data-message")||"操作成功",i=this.getAttribute("data-type")||"success";if(n.Button)switch(t){case"message":n.Button.showMessage(o,i);break;case"confirm":const p=this.getAttribute("data-confirm-message")||"确定要执行此操作吗?";n.Button.showConfirm(p,()=>{n.Button&&n.Button.showMessage(o,i)});break;case"layer":const m=this.getAttribute("data-layer-title")||"弹窗",l=this.getAttribute("data-layer-url")||"#";n.Button.openLayer(m,l);break}})})}},window.MyUI=n,typeof window<"u"&&n&&n.Button&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{n.Button.init()}):n.Button.init()),(a,d)=>(c.openBlock(),c.createElementBlock("button",{class:c.normalizeClass(["btn",`btn-${e.type}`,e.size?`size-${e.size}`:"",{radius:e.rounded},{active:e.active},{disabled:e.disabled},e.className]),disabled:e.disabled,onClick:g,"data-toggle":e.dataToggle,"data-message":e.dataMessage,"data-type":e.dataType,"data-confirm-message":e.dataConfirmMessage,"data-layer-title":e.dataLayerTitle,"data-layer-url":e.dataLayerUrl},[c.renderSlot(a.$slots,"default",{},void 0,!0)],10,x))}}),[["__scopeId","data-v-fcc077ad"]]),v=["default","primary","secondary","success","warning","danger","info"],w=["MINI","S","M","L","XL"],k={install(e){e.component("YouyuButton",b)},YouyuButton:b};r.ButtonSize=w,r.ButtonType=v,r.YouyuButton=b,r.default=k,Object.defineProperties(r,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
|
|
39
|
+
//# sourceMappingURL=youyu-button.umd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"youyu-button.umd.js","sources":["../src/components/YouyuButton.vue","../src/types.ts","../src/main.ts"],"sourcesContent":["<template>\n <button\n :class=\"[\n 'btn',\n `btn-${type}`,\n size ? `size-${size}` : '',\n { radius: rounded },\n { active },\n { disabled },\n className,\n ]\"\n :disabled=\"disabled\"\n @click=\"handleClick\"\n :data-toggle=\"dataToggle\"\n :data-message=\"dataMessage\"\n :data-type=\"dataType\"\n :data-confirm-message=\"dataConfirmMessage\"\n :data-layer-title=\"dataLayerTitle\"\n :data-layer-url=\"dataLayerUrl\"\n >\n <slot></slot>\n </button>\n</template>\n\n<script setup lang=\"ts\">\nimport \"../youyu-button/css/button.css\";\nimport type { Props } from \"../types\";\n\n// 定义组件属性\nconst props = withDefaults(defineProps<Props>(), {\n type: \"default\",\n size: \"M\",\n rounded: false,\n active: false,\n disabled: false,\n className: \"\",\n dataToggle: \"\",\n dataMessage: \"\",\n dataType: \"\",\n dataConfirmMessage: \"\",\n dataLayerTitle: \"\",\n dataLayerUrl: \"\",\n});\n\n// 定义组件事件\nconst emit = defineEmits<{\n (e: \"click\", event: MouseEvent): void;\n}>();\n\n// 处理点击事件\nconst handleClick = (event: MouseEvent) => {\n if (props.disabled) return;\n emit(\"click\", event);\n};\n\n// 扩展Window接口\ndeclare global {\n interface Window {\n MyUI?: {\n Button?: {\n showMessage: (message: string, type?: string) => void;\n showConfirm: (\n message: string,\n onConfirm?: () => void,\n onCancel?: () => void\n ) => void;\n openLayer: (\n title: string,\n url: string,\n id?: string,\n width?: string\n ) => void;\n init: () => void;\n };\n };\n }\n}\n\n// 按钮命名空间\nconst MyUI = window.MyUI || {};\n\n// 确保MyUI.Button存在\nMyUI.Button = MyUI.Button || {\n /**\n * 弹出提示信息\n * @param message - 提示消息内容\n * @param type - 提示类型 (success, error, warning, info)\n */\n showMessage: function (message: string, type: string = \"info\") {\n // 创建提示元素\n const messageElement = document.createElement(\"div\");\n messageElement.className = `my-message my-message-${type}`;\n messageElement.textContent = message;\n messageElement.style.cssText = `\n position: fixed;\n top: 20px;\n right: 20px;\n padding: 10px 20px;\n border-radius: 4px;\n color: white;\n z-index: 9999;\n box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);\n transition: all 0.3s ease;\n max-width: 300px;\n word-wrap: break-word;\n `;\n\n // 根据类型设置背景色\n const colors: Record<string, string> = {\n success: \"#5eb95e\",\n error: \"#dd514c\",\n warning: \"#f37b1d\",\n info: \"#5a98de\",\n };\n const bgColor = colors[type] || colors.info;\n messageElement.style.backgroundColor = bgColor as string;\n\n // 添加到页面\n document.body.appendChild(messageElement);\n\n // 3秒后自动移除\n setTimeout(() => {\n messageElement.style.opacity = \"0\";\n messageElement.style.transform = \"translateX(100%)\";\n setTimeout(() => {\n if (document.body.contains(messageElement)) {\n document.body.removeChild(messageElement);\n }\n }, 300);\n }, 3000);\n },\n\n /**\n * 弹出确认对话框\n * @param {string} message - 确认消息内容\n * @param {function} onConfirm - 确认回调函数\n * @param {function} onCancel - 取消回调函数\n */\n showConfirm: function (\n message: string,\n onConfirm?: () => void,\n onCancel?: () => void\n ) {\n // 创建遮罩层\n const overlay = document.createElement(\"div\");\n overlay.className = \"my-confirm-overlay\";\n overlay.style.cssText = `\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background-color: rgba(0, 0, 0, 0.5);\n z-index: 9998;\n display: flex;\n justify-content: center;\n align-items: center;\n `;\n\n // 创建确认框\n const confirmBox = document.createElement(\"div\");\n confirmBox.className = \"my-confirm-box\";\n confirmBox.style.cssText = `\n background-color: white;\n border-radius: 4px;\n padding: 20px;\n width: 400px;\n max-width: 90%;\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);\n `;\n\n // 确认框内容\n confirmBox.innerHTML = `\n <div class=\"my-confirm-content\">${message}</div>\n <div class=\"my-confirm-buttons\" style=\"text-align: right; margin-top: 20px;\">\n <button class=\"btn btn-default radius\" style=\"margin-right: 10px;\">取消</button>\n <button class=\"btn btn-primary radius\">确认</button>\n </div>\n `;\n\n // 添加到页面\n overlay.appendChild(confirmBox);\n document.body.appendChild(overlay);\n\n // 绑定事件\n const cancelBtn = confirmBox.querySelector(\n \".btn-default\"\n ) as HTMLButtonElement;\n const confirmBtn = confirmBox.querySelector(\n \".btn-primary\"\n ) as HTMLButtonElement;\n\n // 取消按钮事件\n cancelBtn.addEventListener(\"click\", () => {\n document.body.removeChild(overlay);\n if (onCancel) {\n onCancel();\n }\n });\n\n // 确认按钮事件\n confirmBtn.addEventListener(\"click\", () => {\n document.body.removeChild(overlay);\n if (onConfirm) {\n onConfirm();\n }\n });\n\n // 点击遮罩层关闭\n overlay.addEventListener(\"click\", (e) => {\n if (e.target === overlay) {\n document.body.removeChild(overlay);\n if (onCancel) {\n onCancel();\n }\n }\n });\n\n // ESC键关闭\n const handleEscKey = (e: KeyboardEvent) => {\n if (e.key === \"Escape\") {\n if (document.body.contains(overlay)) {\n document.body.removeChild(overlay);\n if (onCancel) {\n onCancel();\n }\n }\n document.removeEventListener(\"keydown\", handleEscKey);\n }\n };\n document.addEventListener(\"keydown\", handleEscKey);\n },\n\n /**\n * 模拟打开弹窗功能\n * @param {string} title - 弹窗标题\n * @param {string} url - 弹窗内容URL\n * @param {string} id - 弹窗ID\n * @param {string} width - 弹窗宽度\n */\n openLayer: function (\n title: string,\n url: string,\n id?: string,\n width?: string\n ) {\n // 这里只是简单的模拟,实际项目中可能需要更复杂的实现\n this.showMessage(\"打开弹窗:\" + title, \"info\");\n console.log(\"打开弹窗参数:\", { title, url, id, width });\n },\n\n /**\n * 初始化按钮组件\n */\n init: function () {\n // 为所有带有data-toggle属性的按钮添加事件监听\n const buttons = document.querySelectorAll(\n \"button[data-toggle], a.btn[data-toggle]\"\n );\n\n buttons.forEach((button) => {\n button.addEventListener(\"click\", function (this: any) {\n const toggleType = this.getAttribute(\"data-toggle\");\n const message = this.getAttribute(\"data-message\") || \"操作成功\";\n const type = this.getAttribute(\"data-type\") || \"success\";\n\n if (!MyUI.Button) return;\n\n switch (toggleType) {\n case \"message\":\n MyUI.Button.showMessage(message, type);\n break;\n case \"confirm\":\n const confirmMessage =\n this.getAttribute(\"data-confirm-message\") ||\n \"确定要执行此操作吗?\";\n MyUI.Button.showConfirm(confirmMessage, () => {\n if (MyUI.Button) {\n MyUI.Button.showMessage(message, type);\n }\n });\n break;\n case \"layer\":\n const layerTitle = this.getAttribute(\"data-layer-title\") || \"弹窗\";\n const layerUrl = this.getAttribute(\"data-layer-url\") || \"#\";\n MyUI.Button.openLayer(layerTitle, layerUrl);\n break;\n }\n });\n });\n },\n};\n\n// 挂载到全局\nwindow.MyUI = MyUI;\n\n// 页面加载完成后初始化按钮组件\nif (typeof window !== \"undefined\" && MyUI && MyUI.Button) {\n if (document.readyState === \"loading\") {\n document.addEventListener(\"DOMContentLoaded\", () => {\n MyUI.Button!.init();\n });\n } else {\n MyUI.Button.init();\n }\n}\n</script>\n\n<style scoped>\n/* 组件特定样式可以在这里添加 */\n</style>\n","// 按钮类型\nexport const ButtonType = [\n \"default\",\n \"primary\",\n \"secondary\",\n \"success\",\n \"warning\",\n \"danger\",\n \"info\",\n] as const;\nexport type ButtonType = (typeof ButtonType)[number];\n\n// 按钮尺寸\nexport const ButtonSize = [\"MINI\", \"S\", \"M\", \"L\", \"XL\"] as const;\nexport type ButtonSize = (typeof ButtonSize)[number];\n\n// 按钮属性定义\nexport interface Props {\n type?: ButtonType;\n size?: ButtonSize;\n rounded?: boolean;\n active?: boolean;\n disabled?: boolean;\n className?: string;\n dataToggle?: string;\n dataMessage?: string;\n dataType?: string;\n dataConfirmMessage?: string;\n dataLayerTitle?: string;\n dataLayerUrl?: string;\n}","import \"./youyu-button/css/button.css\";\nimport YouyuButton from \"./components/YouyuButton.vue\";\nimport type { App } from \"vue\";\nimport * as types from \"./types\";\n\n// 定义插件类型\nconst plugin = {\n // 安装方法\n install(app: App) {\n // 全局注册组件\n app.component(\"YouyuButton\", YouyuButton);\n },\n // 导出组件\n YouyuButton,\n};\n\n// 导出插件、组件和类型\nexport default plugin;\nexport { YouyuButton };\nexport * from \"./types\";\n\n// 开发环境下自动挂载(保持原有功能)\nif (import.meta.env.DEV) {\n import(\"./assets/main.css\").then(() => {\n import(\"vue\").then(({ createApp }) => {\n import(\"./App.vue\").then(({ default: App }) => {\n createApp(App).mount(\"#app\");\n });\n });\n });\n}\n"],"names":["props","__props","emit","__emit","handleClick","event","MyUI","message","type","messageElement","colors","bgColor","onConfirm","onCancel","overlay","confirmBox","cancelBtn","confirmBtn","e","handleEscKey","title","url","id","width","button","toggleType","confirmMessage","layerTitle","layerUrl","_createElementBlock","_normalizeClass","_renderSlot","_ctx","ButtonType","ButtonSize","plugin","app","YouyuButton"],"mappings":";moBA6BA,MAAMA,EAAQC,EAgBRC,EAAOC,EAKPC,EAAeC,GAAsB,CACrCL,EAAM,UACVE,EAAK,QAASG,CAAK,CACrB,EA0BMC,EAAO,OAAO,MAAQ,CAAA,EAG5B,OAAAA,EAAK,OAASA,EAAK,QAAU,CAM3B,YAAa,SAAUC,EAAiBC,EAAe,OAAQ,CAE7D,MAAMC,EAAiB,SAAS,cAAc,KAAK,EACnDA,EAAe,UAAY,yBAAyBD,CAAI,GACxDC,EAAe,YAAcF,EAC7BE,EAAe,MAAM,QAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAe/B,MAAMC,EAAiC,CACrC,QAAS,UACT,MAAO,UACP,QAAS,UACT,KAAM,SAAA,EAEFC,EAAUD,EAAOF,CAAI,GAAKE,EAAO,KACvCD,EAAe,MAAM,gBAAkBE,EAGvC,SAAS,KAAK,YAAYF,CAAc,EAGxC,WAAW,IAAM,CACfA,EAAe,MAAM,QAAU,IAC/BA,EAAe,MAAM,UAAY,mBACjC,WAAW,IAAM,CACX,SAAS,KAAK,SAASA,CAAc,GACvC,SA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BA,EAAA,YAAA,GAEjB8B,EAAAA,WAAaC,EAAA,OAAA,UAAA,CAAA,EAAA,OAAA,EAAA,CAAA,+CCnBJC,EAAa,CACxB,UACA,UACA,YACA,UACA,UACA,SACA,MACF,EAIaC,EAAa,CAAC,OAAQ,IAAK,IAAK,IAAK,IAAI,ECPhDC,EAAS,CAEb,QAAQC,EAAU,CAEhBA,EAAI,UAAU,cAAeC,CAAW,CAC1C,EAEA,YAAAA,CACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zhaoren118/youyu-button",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "A custom button component for Vue 3",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"main": "dist/youyu-button.umd.js",
|
|
9
|
+
"module": "dist/youyu-button.es.js",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": "./dist/youyu-button.es.js",
|
|
13
|
+
"require": "./dist/youyu-button.umd.js"
|
|
14
|
+
},
|
|
15
|
+
"./dist/main.css": "./dist/main.css"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"vue": "^3.5.26"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@tsconfig/node24": "^24.0.3",
|
|
28
|
+
"@types/node": "^24.10.4",
|
|
29
|
+
"@vitejs/plugin-vue": "^6.0.3",
|
|
30
|
+
"@vue/tsconfig": "^0.8.1",
|
|
31
|
+
"npm-run-all2": "^8.0.4",
|
|
32
|
+
"typescript": "~5.9.3",
|
|
33
|
+
"vite": "^7.3.0",
|
|
34
|
+
"vite-plugin-vue-devtools": "^8.0.5",
|
|
35
|
+
"vue-tsc": "^3.2.1"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"dev": "vite",
|
|
39
|
+
"build": "run-p type-check \"build-only {@}\" --",
|
|
40
|
+
"preview": "vite preview",
|
|
41
|
+
"build-only": "vite build",
|
|
42
|
+
"type-check": "vue-tsc --build"
|
|
43
|
+
}
|
|
44
|
+
}
|