@star-ai/star-ui 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,117 @@
1
1
 
2
- // Button 组件入口文件
3
- import StarButton from './Button.vue'
4
-
5
- StarButton.install = function(Vue) {
6
- Vue.component(StarButton.name, StarButton)
2
+ // Button 组件入口文件
3
+ const StarButton = {
4
+ name: 'StarButton',
5
+
6
+ // 组件属性定义
7
+ props: {
8
+ // 按钮类型
9
+ type: {
10
+ type: String,
11
+ default: 'default',
12
+ validator: (value) => {
13
+ return ['default', 'primary', 'success', 'warning', 'error', 'info'].includes(value)
14
+ }
15
+ },
16
+
17
+ // 按钮大小
18
+ size: {
19
+ type: String,
20
+ default: 'medium',
21
+ validator: (value) => {
22
+ return ['mini', 'small', 'medium', 'large'].includes(value)
23
+ }
24
+ },
25
+
26
+ // 是否禁用
27
+ disabled: {
28
+ type: Boolean,
29
+ default: false
30
+ },
31
+
32
+ // 是否加载中
33
+ loading: {
34
+ type: Boolean,
35
+ default: false
36
+ },
37
+
38
+ // 是否为朴素按钮
39
+ plain: {
40
+ type: Boolean,
41
+ default: false
42
+ },
43
+
44
+ // 是否为块级按钮
45
+ block: {
46
+ type: Boolean,
47
+ default: false
48
+ },
49
+
50
+ // 左侧图标
51
+ icon: {
52
+ type: String,
53
+ default: ''
54
+ },
55
+
56
+ // 右侧图标
57
+ rightIcon: {
58
+ type: String,
59
+ default: ''
60
+ },
61
+
62
+ // 自定义样式
63
+ customStyle: {
64
+ type: Object,
65
+ default: () => ({})
66
+ },
67
+
68
+ // 点击防抖时间(毫秒)
69
+ debounce: {
70
+ type: Number,
71
+ default: 0
72
+ }
73
+ },
74
+
75
+ data() {
76
+ return {
77
+ canClick: true
78
+ }
79
+ },
80
+
81
+ methods: {
82
+ handleClick(event) {
83
+ // 防抖处理
84
+ if (!this.canClick) return
85
+
86
+ if (this.debounce > 0) {
87
+ this.canClick = false
88
+ setTimeout(() => {
89
+ this.canClick = true
90
+ }, this.debounce)
91
+ }
92
+
93
+ // 触发点击事件
94
+ if (!this.disabled && !this.loading) {
95
+ this.$emit('click', event)
96
+ }
97
+ }
98
+ }
7
99
  }
8
-
9
- export default StarButton
10
- export { StarButton }
100
+
101
+ // 添加模板
102
+ StarButton.template = '<view \n class="star-button"\n :class="[\n \`star-button--${type}\`,\n \`star-button--${size}\`,\n {\n \'star-button--disabled\': disabled,\n \'star-button--loading\': loading,\n \'star-button--block\': block,\n \'star-button--plain\': plain\n }\n ]"\n :style="[customStyle]"\n @click="handleClick"\n >\n <!-- 加载状态 -->\n <view v-if="loading" class="star-button__loading">\n <view class="star-button__loading-spinner"></view>\n </view>\n \n <!-- 图标 -->\n <text \n v-if="icon && !loading" \n class="star-button__icon" \n :class="icon"\n ></text>\n \n <!-- 文字内容 -->\n <text class="star-button__text">\n <slot></slot>\n </text>\n \n <!-- 右侧图标 -->\n <text \n v-if="rightIcon && !loading" \n class="star-button__right-icon" \n :class="rightIcon"\n ></text>\n </view>'
103
+
104
+ StarButton.install = function(Vue) {
105
+ Vue.component(StarButton.name, StarButton)
106
+ }
107
+
108
+ // CommonJS 导出(仅在支持module的环境中)
109
+ if (typeof module !== 'undefined' && module.exports) {
110
+ module.exports = StarButton
111
+ module.exports.default = StarButton
112
+ }
113
+
114
+ // 浏览器全局变量导出
115
+ if (typeof window !== 'undefined') {
116
+ window.StarButton = StarButton
117
+ }
@@ -1,10 +1,195 @@
1
1
 
2
- // Input 组件入口文件
3
- import StarInput from './Input.vue'
4
-
5
- StarInput.install = function(Vue) {
6
- Vue.component(StarInput.name, StarInput)
2
+ // Input 组件入口文件
3
+ const StarInput = {
4
+ name: 'StarInput',
5
+
6
+ props: {
7
+ // 输入框类型
8
+ type: {
9
+ type: String,
10
+ default: 'text'
11
+ },
12
+
13
+ // 绑定值
14
+ value: {
15
+ type: [String, Number],
16
+ default: ''
17
+ },
18
+
19
+ // 原生属性
20
+ placeholder: {
21
+ type: String,
22
+ default: ''
23
+ },
24
+
25
+ disabled: {
26
+ type: Boolean,
27
+ default: false
28
+ },
29
+
30
+ maxlength: {
31
+ type: [String, Number],
32
+ default: 140
33
+ },
34
+
35
+ focus: {
36
+ type: Boolean,
37
+ default: false
38
+ },
39
+
40
+ confirmType: {
41
+ type: String,
42
+ default: 'done'
43
+ },
44
+
45
+ placeholderStyle: {
46
+ type: String,
47
+ default: ''
48
+ },
49
+
50
+ placeholderClass: {
51
+ type: String,
52
+ default: ''
53
+ },
54
+
55
+ cursorSpacing: {
56
+ type: [String, Number],
57
+ default: 0
58
+ },
59
+
60
+ // 自定义属性
61
+ size: {
62
+ type: String,
63
+ default: 'medium',
64
+ validator: (value) => ['mini', 'small', 'medium', 'large'].includes(value)
65
+ },
66
+
67
+ clearable: {
68
+ type: Boolean,
69
+ default: false
70
+ },
71
+
72
+ showPassword: {
73
+ type: Boolean,
74
+ default: false
75
+ },
76
+
77
+ prefixIcon: {
78
+ type: String,
79
+ default: ''
80
+ },
81
+
82
+ suffixIcon: {
83
+ type: String,
84
+ default: ''
85
+ },
86
+
87
+ prepend: {
88
+ type: String,
89
+ default: ''
90
+ },
91
+
92
+ append: {
93
+ type: String,
94
+ default: ''
95
+ },
96
+
97
+ readonly: {
98
+ type: Boolean,
99
+ default: false
100
+ }
101
+ },
102
+
103
+ data() {
104
+ return {
105
+ currentValue: this.value,
106
+ isFocused: false,
107
+ passwordVisible: false
108
+ }
109
+ },
110
+
111
+ computed: {
112
+ inputClasses() {
113
+ return [
114
+ `star-input--${this.size}`,
115
+ {
116
+ 'star-input--disabled': this.disabled,
117
+ 'star-input--focused': this.isFocused,
118
+ 'star-input--with-prepend': this.prepend || this.$slots.prepend,
119
+ 'star-input--with-append': this.append || this.$slots.append,
120
+ 'star-input--readonly': this.readonly
121
+ }
122
+ ]
123
+ }
124
+ },
125
+
126
+ watch: {
127
+ value(newVal) {
128
+ this.currentValue = newVal
129
+ }
130
+ },
131
+
132
+ methods: {
133
+ handleInput(event) {
134
+ const value = event.detail.value
135
+ this.currentValue = value
136
+ this.$emit('input', value)
137
+ this.$emit('change', value)
138
+ },
139
+
140
+ handleFocus(event) {
141
+ this.isFocused = true
142
+ this.$emit('focus', event)
143
+ },
144
+
145
+ handleBlur(event) {
146
+ this.isFocused = false
147
+ this.$emit('blur', event)
148
+ },
149
+
150
+ handleConfirm(event) {
151
+ this.$emit('confirm', event)
152
+ },
153
+
154
+ handleKeyboardHeightChange(event) {
155
+ this.$emit('keyboardheightchange', event)
156
+ },
157
+
158
+ handleClear() {
159
+ this.currentValue = ''
160
+ this.$emit('input', '')
161
+ this.$emit('change', '')
162
+ this.$emit('clear')
163
+ },
164
+
165
+ togglePasswordVisible() {
166
+ this.passwordVisible = !this.passwordVisible
167
+ },
168
+
169
+ handlePrefixIconClick() {
170
+ this.$emit('click-prefix')
171
+ },
172
+
173
+ handleSuffixIconClick() {
174
+ this.$emit('click-suffix')
175
+ }
176
+ }
7
177
  }
8
-
9
- export default StarInput
10
- export { StarInput }
178
+
179
+ // 添加模板
180
+ StarInput.template = '<view class="star-input" :class="inputClasses">\n <!-- 前置内容 -->\n <view v-if="$slots.prepend || prepend" class="star-input__prepend">\n <slot name="prepend">\n <text v-if="prepend" class="star-input__prepend-text">{{ prepend }}</text>\n </slot>\n </view>\n \n <!-- 输入框主体 -->\n <view class="star-input__wrapper">\n <!-- 前置图标 -->\n <text \n v-if="prefixIcon" \n class="star-input__prefix-icon" \n :class="prefixIcon"\n @click="handlePrefixIconClick"\n ></text>\n \n <!-- 输入框 -->\n <input\n class="star-input__inner"\n :type="showPassword ? (passwordVisible ? \'text\' : \'password\') : type"\n :value="currentValue"\n :placeholder="placeholder"\n :disabled="disabled"\n :maxlength="maxlength"\n :focus="focus"\n :confirm-type="confirmType"\n :placeholder-style="placeholderStyle"\n :placeholder-class="placeholderClass"\n :cursor-spacing="cursorSpacing"\n @input="handleInput"\n @focus="handleFocus"\n @blur="handleBlur"\n @confirm="handleConfirm"\n @keyboardheightchange="handleKeyboardHeightChange"\n />\n \n <!-- 清除按钮 -->\n <view \n v-if="clearable && currentValue && !disabled" \n class="star-input__clear"\n @click="handleClear"\n >\n <text class="star-icon-close"></text>\n </view>\n \n <!-- 密码可见切换按钮 -->\n <view \n v-if="showPassword && currentValue" \n class="star-input__password-toggle"\n @click="togglePasswordVisible"\n >\n <text :class="passwordVisible ? \'star-icon-eye-open\' : \'star-icon-eye-close\'"></text>\n </view>\n \n <!-- 后置图标 -->\n <text \n v-if="suffixIcon" \n class="star-input__suffix-icon" \n :class="suffixIcon"\n @click="handleSuffixIconClick"\n ></text>\n </view>\n \n <!-- 后置内容 -->\n <view v-if="$slots.append || append" class="star-input__append">\n <slot name="append">\n <text v-if="append" class="star-input__append-text">{{ append }}</text>\n </slot>\n </view>\n </view>'
181
+
182
+ StarInput.install = function(Vue) {
183
+ Vue.component(StarInput.name, StarInput)
184
+ }
185
+
186
+ // CommonJS 导出(仅在支持module的环境中)
187
+ if (typeof module !== 'undefined' && module.exports) {
188
+ module.exports = StarInput
189
+ module.exports.default = StarInput
190
+ }
191
+
192
+ // 浏览器全局变量导出
193
+ if (typeof window !== 'undefined') {
194
+ window.StarInput = StarInput
195
+ }
package/lib/index.js CHANGED
@@ -1,70 +1,53 @@
1
-
2
- // star-ui 组件库主入口文件
3
- import packageJson from '../package.json'
4
-
5
- // 导入所有组件
6
- import StarButton from './components/Button/index.js'
7
- import StarInput from './components/Input/index.js'
8
-
9
- // 组件列表
10
- const components = [
11
- StarButton,
12
- StarInput
13
- ]
14
-
15
- // 安装函数
16
- const install = function(Vue, opts = {}) {
17
- components.forEach(component => {
18
- // 如果组件有install方法,使用install方法注册
19
- if (component.install) {
20
- Vue.use(component)
21
- }
22
- // 如果组件是Vue组件对象,直接注册
23
- else if (component.name) {
24
- Vue.component(component.name, component)
25
- }
26
- })
27
-
28
- // 挂载全局方法
29
- Vue.prototype.$MY_UI = {
30
- size: opts.size || '',
31
- zIndex: opts.zIndex || 2000
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3
+ typeof define === 'function' && define.amd ? define(factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.StarUI = factory());
5
+ }(this, (function () {
6
+ 'use strict';
7
+
8
+ // 导入组件
9
+ const StarButton = require('./components/Button/index.js');
10
+ const StarInput = require('./components/Input/index.js');
11
+
12
+ // 组件列表
13
+ const components = [
14
+ StarButton,
15
+ StarInput
16
+ ];
17
+
18
+ // 安装函数
19
+ const install = function(Vue, opts = {}) {
20
+ components.forEach(component => {
21
+ // 如果组件有install方法,使用install方法注册
22
+ if (component.install) {
23
+ Vue.use(component);
24
+ }
25
+ // 如果组件是Vue组件对象,直接注册
26
+ else if (component.name) {
27
+ Vue.component(component.name, component);
28
+ }
29
+ });
30
+
31
+ // 挂载全局方法
32
+ Vue.prototype.$MY_UI = {
33
+ size: opts.size || '',
34
+ zIndex: opts.zIndex || 2000
35
+ };
36
+ };
37
+
38
+ // 如果是浏览器环境且已引入Vue,则自动安装
39
+ if (typeof window !== 'undefined' && window.Vue) {
40
+ install(window.Vue);
32
41
  }
33
- }
34
-
35
- // 如果是浏览器环境且已引入Vue,则自动安装
36
- if (typeof window !== 'undefined' && window.Vue) {
37
- install(window.Vue)
38
- }
39
-
40
- // 创建导出对象
41
- const StarUI = {
42
- version: packageJson.version,
43
- install,
44
- // 导出所有组件
45
- StarButton,
46
- StarInput
47
- }
48
-
49
- // 导出模块
50
- if (typeof module !== 'undefined' && module.exports) {
51
- // CommonJS 导出
52
- module.exports = StarUI
53
- module.exports.default = StarUI
54
- // 为每个组件添加单独的导出(支持按需导入)
55
- components.forEach(component => {
56
- if (component.name) {
57
- module.exports[component.name] = component
58
- }
59
- })
60
- } else if (typeof define === 'function' && define.amd) {
61
- // AMD 导出
62
- define(() => StarUI)
63
- } else if (typeof window !== 'undefined') {
64
- // 浏览器全局变量导出
65
- window.StarUI = StarUI
66
- }
67
42
 
68
- // ES模块导出
69
- export default StarUI
70
- export { StarButton, StarInput }
43
+ // 创建导出对象
44
+ const StarUI = {
45
+ version: '0.0.5',
46
+ install,
47
+ // 导出所有组件
48
+ StarButton,
49
+ StarInput
50
+ };
51
+
52
+ return StarUI;
53
+ })));
package/lib/package.json CHANGED
@@ -1,13 +1,10 @@
1
1
  {
2
2
  "name": "@star-ai/star-ui",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "基于Uniapp的Vue2组件库",
5
5
  "main": "index.js",
6
- "files": [
7
- "components",
8
- "styles",
9
- "index.js"
10
- ],
6
+ "module": "index.js",
7
+ "browser": "star-ui.umd.js",
11
8
  "dependencies": {
12
9
  "@vue/shared": "^3.0.0",
13
10
  "core-js": "^3.8.3"
@@ -0,0 +1,64 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3
+ typeof define === 'function' && define.amd ? define(factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.StarUI = factory());
5
+ }(this, (function () {
6
+ 'use strict';
7
+
8
+ // 组件定义
9
+
10
+ // Button 组件
11
+ const StarButton = window.StarButton || {};
12
+
13
+
14
+ // Input 组件
15
+ const StarInput = window.StarInput || {};
16
+
17
+
18
+ // 组件列表
19
+ const components = [
20
+ StarButton,
21
+ StarInput
22
+ ];
23
+
24
+ // 安装函数
25
+ const install = function(Vue, opts = {}) {
26
+ components.forEach(component => {
27
+ // 如果组件有install方法,使用install方法注册
28
+ if (component.install) {
29
+ Vue.use(component);
30
+ }
31
+ // 如果组件是Vue组件对象,直接注册
32
+ else if (component.name) {
33
+ Vue.component(component.name, component);
34
+ }
35
+ });
36
+
37
+ // 挂载全局方法
38
+ Vue.prototype.$MY_UI = {
39
+ size: opts.size || '',
40
+ zIndex: opts.zIndex || 2000
41
+ };
42
+ };
43
+
44
+ // 如果是浏览器环境且已引入Vue,则自动安装
45
+ if (typeof window !== 'undefined' && window.Vue) {
46
+ install(window.Vue);
47
+ }
48
+
49
+ // 创建导出对象
50
+ const StarUI = {
51
+ version: '0.0.5',
52
+ install,
53
+ // 导出所有组件
54
+ StarButton,
55
+ StarInput
56
+ };
57
+
58
+ // 浏览器全局变量导出
59
+ if (typeof window !== 'undefined') {
60
+ window.StarUI = StarUI;
61
+ }
62
+
63
+ return StarUI;
64
+ })));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@star-ai/star-ui",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "基于Uniapp的Vue2组件库",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.js",
@@ -1,325 +0,0 @@
1
- <template>
2
- <view
3
- class="star-button"
4
- :class="[
5
- `star-button--${type}`,
6
- `star-button--${size}`,
7
- {
8
- 'star-button--disabled': disabled,
9
- 'star-button--loading': loading,
10
- 'star-button--block': block,
11
- 'star-button--plain': plain
12
- }
13
- ]"
14
- :style="[customStyle]"
15
- @click="handleClick"
16
- >
17
- <!-- 加载状态 -->
18
- <view v-if="loading" class="star-button__loading">
19
- <view class="star-button__loading-spinner"></view>
20
- </view>
21
-
22
- <!-- 图标 -->
23
- <text
24
- v-if="icon && !loading"
25
- class="star-button__icon"
26
- :class="icon"
27
- ></text>
28
-
29
- <!-- 文字内容 -->
30
- <text class="star-button__text">
31
- <slot></slot>
32
- </text>
33
-
34
- <!-- 右侧图标 -->
35
- <text
36
- v-if="rightIcon && !loading"
37
- class="star-button__right-icon"
38
- :class="rightIcon"
39
- ></text>
40
- </view>
41
- </template>
42
-
43
- <script>
44
- export default {
45
- name: 'StarButton',
46
-
47
- // 组件属性定义
48
- props: {
49
- // 按钮类型
50
- type: {
51
- type: String,
52
- default: 'default',
53
- validator: (value) => {
54
- return ['default', 'primary', 'success', 'warning', 'error', 'info'].includes(value)
55
- }
56
- },
57
-
58
- // 按钮大小
59
- size: {
60
- type: String,
61
- default: 'medium',
62
- validator: (value) => {
63
- return ['mini', 'small', 'medium', 'large'].includes(value)
64
- }
65
- },
66
-
67
- // 是否禁用
68
- disabled: {
69
- type: Boolean,
70
- default: false
71
- },
72
-
73
- // 是否加载中
74
- loading: {
75
- type: Boolean,
76
- default: false
77
- },
78
-
79
- // 是否为朴素按钮
80
- plain: {
81
- type: Boolean,
82
- default: false
83
- },
84
-
85
- // 是否为块级按钮
86
- block: {
87
- type: Boolean,
88
- default: false
89
- },
90
-
91
- // 左侧图标
92
- icon: {
93
- type: String,
94
- default: ''
95
- },
96
-
97
- // 右侧图标
98
- rightIcon: {
99
- type: String,
100
- default: ''
101
- },
102
-
103
- // 自定义样式
104
- customStyle: {
105
- type: Object,
106
- default: () => ({})
107
- },
108
-
109
- // 点击防抖时间(毫秒)
110
- debounce: {
111
- type: Number,
112
- default: 0
113
- }
114
- },
115
-
116
- data() {
117
- return {
118
- canClick: true
119
- }
120
- },
121
-
122
- methods: {
123
- handleClick(event) {
124
- // 防抖处理
125
- if (!this.canClick) return
126
-
127
- if (this.debounce > 0) {
128
- this.canClick = false
129
- setTimeout(() => {
130
- this.canClick = true
131
- }, this.debounce)
132
- }
133
-
134
- // 触发点击事件
135
- if (!this.disabled && !this.loading) {
136
- this.$emit('click', event)
137
- }
138
- }
139
- }
140
- }
141
- </script>
142
-
143
- <style lang="scss" scoped>
144
- // 引入样式变量
145
- @import "../../styles/variables.scss";
146
-
147
- .star-button {
148
- display: inline-flex;
149
- align-items: center;
150
- justify-content: center;
151
- position: relative;
152
- box-sizing: border-box;
153
- padding: 0 16px;
154
- height: 44px;
155
- line-height: 44px;
156
- border-radius: $border-radius-base;
157
- font-size: $font-size-base;
158
- font-weight: 500;
159
- text-align: center;
160
- vertical-align: middle;
161
- transition: all 0.3s;
162
- cursor: pointer;
163
- user-select: none;
164
-
165
- // 块级按钮
166
- &--block {
167
- display: flex;
168
- width: 100%;
169
- }
170
-
171
- // 禁用状态
172
- &--disabled {
173
- opacity: 0.6;
174
- cursor: not-allowed;
175
- }
176
-
177
- // 大小
178
- &--mini {
179
- padding: 0 8px;
180
- height: 24px;
181
- line-height: 24px;
182
- font-size: $font-size-sm;
183
- border-radius: $border-radius-sm;
184
- }
185
-
186
- &--small {
187
- padding: 0 12px;
188
- height: 32px;
189
- line-height: 32px;
190
- font-size: $font-size-sm;
191
- border-radius: $border-radius-sm;
192
- }
193
-
194
- &--large {
195
- padding: 0 20px;
196
- height: 48px;
197
- line-height: 48px;
198
- font-size: $font-size-lg;
199
- border-radius: $border-radius-lg;
200
- }
201
-
202
- // 类型 - 默认
203
- &--default {
204
- color: $text-color;
205
- background-color: $bg-color;
206
- border: 1px solid $border-color;
207
-
208
- &:not(.star-button--disabled):not(.star-button--loading):active {
209
- background-color: darken($bg-color, 5%);
210
- }
211
- }
212
-
213
- // 类型 - 主要
214
- &--primary {
215
- color: $white;
216
- background-color: $primary-color;
217
- border: 1px solid $primary-color;
218
-
219
- &.star-button--plain {
220
- color: $primary-color;
221
- background-color: transparent;
222
- }
223
-
224
- &:not(.star-button--disabled):not(.star-button--loading):active {
225
- background-color: darken($primary-color, 10%);
226
- border-color: darken($primary-color, 10%);
227
- }
228
- }
229
-
230
- // 类型 - 成功
231
- &--success {
232
- color: $white;
233
- background-color: $success-color;
234
- border: 1px solid $success-color;
235
-
236
- &.star-button--plain {
237
- color: $success-color;
238
- background-color: transparent;
239
- }
240
- }
241
-
242
- // 类型 - 警告
243
- &--warning {
244
- color: $white;
245
- background-color: $warning-color;
246
- border: 1px solid $warning-color;
247
-
248
- &.star-button--plain {
249
- color: $warning-color;
250
- background-color: transparent;
251
- }
252
- }
253
-
254
- // 类型 - 错误
255
- &--error {
256
- color: $white;
257
- background-color: $error-color;
258
- border: 1px solid $error-color;
259
-
260
- &.star-button--plain {
261
- color: $error-color;
262
- background-color: transparent;
263
- }
264
- }
265
-
266
- // 类型 - 信息
267
- &--info {
268
- color: $white;
269
- background-color: $info-color;
270
- border: 1px solid $info-color;
271
-
272
- &.star-button--plain {
273
- color: $info-color;
274
- background-color: transparent;
275
- }
276
- }
277
-
278
- // 加载中
279
- &--loading {
280
- cursor: not-allowed;
281
- }
282
-
283
- // 图标
284
- &__icon,
285
- &__right-icon {
286
- font-family: "star-icon-font" !important; // 使用你自己的图标字体
287
- margin-right: 4px;
288
- font-size: inherit;
289
- }
290
-
291
- &__right-icon {
292
- margin-right: 0;
293
- margin-left: 4px;
294
- }
295
-
296
- &__text {
297
- display: inline-block;
298
- vertical-align: middle;
299
- }
300
-
301
- // 加载动画
302
- &__loading {
303
- margin-right: 4px;
304
- }
305
-
306
- &__loading-spinner {
307
- display: inline-block;
308
- width: 14px;
309
- height: 14px;
310
- border: 2px solid;
311
- border-color: currentColor transparent transparent transparent;
312
- border-radius: 50%;
313
- animation: star-button-spin 1s linear infinite;
314
- }
315
- }
316
-
317
- @keyframes star-button-spin {
318
- 0% {
319
- transform: rotate(0deg);
320
- }
321
- 100% {
322
- transform: rotate(360deg);
323
- }
324
- }
325
- </style>
@@ -1,404 +0,0 @@
1
- <template>
2
- <view class="star-input" :class="inputClasses">
3
- <!-- 前置内容 -->
4
- <view v-if="$slots.prepend || prepend" class="star-input__prepend">
5
- <slot name="prepend">
6
- <text v-if="prepend" class="star-input__prepend-text">{{ prepend }}</text>
7
- </slot>
8
- </view>
9
-
10
- <!-- 输入框主体 -->
11
- <view class="star-input__wrapper">
12
- <!-- 前置图标 -->
13
- <text
14
- v-if="prefixIcon"
15
- class="star-input__prefix-icon"
16
- :class="prefixIcon"
17
- @click="handlePrefixIconClick"
18
- ></text>
19
-
20
- <!-- 输入框 -->
21
- <input
22
- class="star-input__inner"
23
- :type="showPassword ? (passwordVisible ? 'text' : 'password') : type"
24
- :value="currentValue"
25
- :placeholder="placeholder"
26
- :disabled="disabled"
27
- :maxlength="maxlength"
28
- :focus="focus"
29
- :confirm-type="confirmType"
30
- :placeholder-style="placeholderStyle"
31
- :placeholder-class="placeholderClass"
32
- :cursor-spacing="cursorSpacing"
33
- @input="handleInput"
34
- @focus="handleFocus"
35
- @blur="handleBlur"
36
- @confirm="handleConfirm"
37
- @keyboardheightchange="handleKeyboardHeightChange"
38
- />
39
-
40
- <!-- 清除按钮 -->
41
- <view
42
- v-if="clearable && currentValue && !disabled"
43
- class="star-input__clear"
44
- @click="handleClear"
45
- >
46
- <text class="star-icon-close"></text>
47
- </view>
48
-
49
- <!-- 密码可见切换按钮 -->
50
- <view
51
- v-if="showPassword && currentValue"
52
- class="star-input__password-toggle"
53
- @click="togglePasswordVisible"
54
- >
55
- <text :class="passwordVisible ? 'star-icon-eye-open' : 'star-icon-eye-close'"></text>
56
- </view>
57
-
58
- <!-- 后置图标 -->
59
- <text
60
- v-if="suffixIcon"
61
- class="star-input__suffix-icon"
62
- :class="suffixIcon"
63
- @click="handleSuffixIconClick"
64
- ></text>
65
- </view>
66
-
67
- <!-- 后置内容 -->
68
- <view v-if="$slots.append || append" class="star-input__append">
69
- <slot name="append">
70
- <text v-if="append" class="star-input__append-text">{{ append }}</text>
71
- </slot>
72
- </view>
73
- </view>
74
- </template>
75
-
76
- <script>
77
- export default {
78
- name: 'StarInput',
79
-
80
- props: {
81
- // 输入框类型
82
- type: {
83
- type: String,
84
- default: 'text'
85
- },
86
-
87
- // 绑定值
88
- value: {
89
- type: [String, Number],
90
- default: ''
91
- },
92
-
93
- // 原生属性
94
- placeholder: {
95
- type: String,
96
- default: ''
97
- },
98
-
99
- disabled: {
100
- type: Boolean,
101
- default: false
102
- },
103
-
104
- maxlength: {
105
- type: [String, Number],
106
- default: 140
107
- },
108
-
109
- focus: {
110
- type: Boolean,
111
- default: false
112
- },
113
-
114
- confirmType: {
115
- type: String,
116
- default: 'done'
117
- },
118
-
119
- placeholderStyle: {
120
- type: String,
121
- default: ''
122
- },
123
-
124
- placeholderClass: {
125
- type: String,
126
- default: ''
127
- },
128
-
129
- cursorSpacing: {
130
- type: [String, Number],
131
- default: 0
132
- },
133
-
134
- // 自定义属性
135
- size: {
136
- type: String,
137
- default: 'medium',
138
- validator: (value) => ['mini', 'small', 'medium', 'large'].includes(value)
139
- },
140
-
141
- clearable: {
142
- type: Boolean,
143
- default: false
144
- },
145
-
146
- showPassword: {
147
- type: Boolean,
148
- default: false
149
- },
150
-
151
- prefixIcon: {
152
- type: String,
153
- default: ''
154
- },
155
-
156
- suffixIcon: {
157
- type: String,
158
- default: ''
159
- },
160
-
161
- prepend: {
162
- type: String,
163
- default: ''
164
- },
165
-
166
- append: {
167
- type: String,
168
- default: ''
169
- },
170
-
171
- readonly: {
172
- type: Boolean,
173
- default: false
174
- }
175
- },
176
-
177
- data() {
178
- return {
179
- currentValue: this.value,
180
- isFocused: false,
181
- passwordVisible: false
182
- }
183
- },
184
-
185
- computed: {
186
- inputClasses() {
187
- return [
188
- `star-input--${this.size}`,
189
- {
190
- 'star-input--disabled': this.disabled,
191
- 'star-input--focused': this.isFocused,
192
- 'star-input--with-prepend': this.prepend || this.$slots.prepend,
193
- 'star-input--with-append': this.append || this.$slots.append,
194
- 'star-input--readonly': this.readonly
195
- }
196
- ]
197
- }
198
- },
199
-
200
- watch: {
201
- value(newVal) {
202
- this.currentValue = newVal
203
- }
204
- },
205
-
206
- methods: {
207
- handleInput(event) {
208
- const value = event.detail.value
209
- this.currentValue = value
210
- this.$emit('input', value)
211
- this.$emit('change', value)
212
- },
213
-
214
- handleFocus(event) {
215
- this.isFocused = true
216
- this.$emit('focus', event)
217
- },
218
-
219
- handleBlur(event) {
220
- this.isFocused = false
221
- this.$emit('blur', event)
222
- },
223
-
224
- handleConfirm(event) {
225
- this.$emit('confirm', event)
226
- },
227
-
228
- handleKeyboardHeightChange(event) {
229
- this.$emit('keyboardheightchange', event)
230
- },
231
-
232
- handleClear() {
233
- this.currentValue = ''
234
- this.$emit('input', '')
235
- this.$emit('change', '')
236
- this.$emit('clear')
237
- },
238
-
239
- togglePasswordVisible() {
240
- this.passwordVisible = !this.passwordVisible
241
- },
242
-
243
- handlePrefixIconClick() {
244
- this.$emit('click-prefix')
245
- },
246
-
247
- handleSuffixIconClick() {
248
- this.$emit('click-suffix')
249
- }
250
- }
251
- }
252
- </script>
253
-
254
- <style lang="scss" scoped>
255
- @import "../../styles/variables.scss";
256
-
257
- .star-input {
258
- display: inline-flex;
259
- width: 100%;
260
- font-size: $font-size-base;
261
- line-height: normal;
262
-
263
- &__prepend,
264
- &__append {
265
- display: flex;
266
- align-items: center;
267
- justify-content: center;
268
- padding: 0 12px;
269
- background-color: $bg-color-grey;
270
- border: 1px solid $border-color;
271
- white-space: nowrap;
272
-
273
- &-text {
274
- color: $text-color-secondary;
275
- }
276
- }
277
-
278
- &__prepend {
279
- border-right: 0;
280
- border-radius: $border-radius-base 0 0 $border-radius-base;
281
- }
282
-
283
- &__append {
284
- border-left: 0;
285
- border-radius: 0 $border-radius-base $border-radius-base 0;
286
- }
287
-
288
- &__wrapper {
289
- display: flex;
290
- align-items: center;
291
- flex: 1;
292
- position: relative;
293
- padding: 0 12px;
294
- border: 1px solid $border-color;
295
- border-radius: $border-radius-base;
296
- background-color: $bg-color;
297
- transition: border-color 0.3s;
298
-
299
- .star-input--with-prepend & {
300
- border-top-left-radius: 0;
301
- border-bottom-left-radius: 0;
302
- border-left: 0;
303
- }
304
-
305
- .star-input--with-append & {
306
- border-top-right-radius: 0;
307
- border-bottom-right-radius: 0;
308
- border-right: 0;
309
- }
310
- }
311
-
312
- &--focused &__wrapper {
313
- border-color: $primary-color;
314
- }
315
-
316
- &--disabled &__wrapper {
317
- background-color: $bg-color-grey;
318
- cursor: not-allowed;
319
- }
320
-
321
- &__inner {
322
- flex: 1;
323
- width: 100%;
324
- height: 100%;
325
- padding: 0;
326
- border: none;
327
- outline: none;
328
- background: transparent;
329
- font-size: inherit;
330
- color: $text-color;
331
-
332
- .star-input--disabled & {
333
- color: $text-color-disabled;
334
- cursor: not-allowed;
335
- }
336
-
337
- &::placeholder {
338
- color: $text-color-light;
339
- }
340
- }
341
-
342
- &__prefix-icon,
343
- &__suffix-icon {
344
- font-family: "star-icon-font" !important;
345
- color: $text-color-light;
346
- font-size: 18px;
347
- cursor: pointer;
348
- transition: color 0.3s;
349
-
350
- &:hover {
351
- color: $text-color;
352
- }
353
- }
354
-
355
- &__prefix-icon {
356
- margin-right: 8px;
357
- }
358
-
359
- &__suffix-icon {
360
- margin-left: 8px;
361
- }
362
-
363
- &__clear,
364
- &__password-toggle {
365
- display: flex;
366
- align-items: center;
367
- justify-content: center;
368
- width: 20px;
369
- height: 20px;
370
- margin-left: 8px;
371
- color: $text-color-light;
372
- cursor: pointer;
373
- transition: color 0.3s;
374
-
375
- &:hover {
376
- color: $text-color;
377
- }
378
-
379
- .star-icon-close,
380
- .star-icon-eye-open,
381
- .star-icon-eye-close {
382
- font-family: "star-icon-font" !important;
383
- font-size: 16px;
384
- }
385
- }
386
-
387
- // 尺寸
388
- &--mini &__wrapper {
389
- height: 24px;
390
- }
391
-
392
- &--small &__wrapper {
393
- height: 32px;
394
- }
395
-
396
- &--medium &__wrapper {
397
- height: 40px;
398
- }
399
-
400
- &--large &__wrapper {
401
- height: 48px;
402
- }
403
- }
404
- </style>