starai-ui 0.1.22 → 0.1.24

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