stellar-ui-plus 1.17.0 → 1.17.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -33,7 +33,7 @@
33
33
  ## 安装
34
34
 
35
35
  ```bash [pnpm]
36
- pnpm install stellar-ui-plus -S
36
+ npm install stellar-ui-plus -S
37
37
  ```
38
38
 
39
39
  ## 快速上手
@@ -149,7 +149,7 @@ async function click() {
149
149
  type PropsKeyTypee = keyof typeof props;
150
150
  function getDefaultData(key: PropsKeyTypee, value: any) {
151
151
  try {
152
- if (Object.hasOwn(props, key)) {
152
+ if (Object.prototype.hasOwnProperty.call(props, key)) {
153
153
  if (props[key]) {
154
154
  return props[key];
155
155
  } else {
@@ -1,25 +1,31 @@
1
1
  export const ICON_OBJ = {
2
- info: '',
3
- success: '',
4
- error: '',
5
- }
6
- export const DURATION = 200
7
- export const ANIMATION_PROP: UniApp.CreateAnimationOptions = { duration: DURATION, timingFunction: 'ease-out' }
2
+ info: '',
3
+ success: '',
4
+ error: '',
5
+ };
6
+ export const DURATION = 200;
7
+ export const ANIMATION_PROP: UniApp.CreateAnimationOptions = { duration: DURATION, timingFunction: 'ease-out' };
8
+
9
+ export type MessageBoxIcon = 'info' | 'success' | 'error';
8
10
 
9
- export type MessageBoxIcon = 'info' | 'success' | 'error'
11
+ export interface MessageBoxOptions {
12
+ show?: boolean;
13
+ title?: string;
14
+ content?: string;
15
+ icon?: MessageBoxIcon;
16
+ cancelText?: string;
17
+ confirmText?: string;
18
+ confirmColor?: string;
19
+ showCancel?: boolean;
20
+ showClose?: boolean;
21
+ cancelColor?: string;
22
+ editable?: boolean;
23
+ placeholderText?: string;
24
+ confirm?: (value?: string) => void;
25
+ cancel?: (value?: string) => void;
26
+ complete?: (value?: string) => void;
10
27
 
11
- export const DEFAULT_CONFIG = {
12
- title: '',
13
- content: '',
14
- showCancel: true,
15
- icon: '',
16
- cancelText: '取消',
17
- cancelColor: '#333333',
18
- confirmText: '确认',
19
- confirmColor: '',
20
- editable: false,
21
- placeholderText: '',
22
- success: null,
23
- fail: null,
24
- complete: null,
28
+ closeOnClickOverlay?: boolean;
29
+ closeOnPressEscape?: boolean;
30
+ closeOnBackdropClick?: boolean;
25
31
  }
@@ -1,14 +1,10 @@
1
1
  <script lang="ts" setup>
2
- import { watch, computed, useSlots, defineOptions } from 'vue';
2
+ import { inject, watch, ref, computed, useSlots, defineOptions } from 'vue';
3
+ import { messageBoxDefaultOptionsKey } from './ste-message-box';
3
4
  import useData from './useData';
4
5
  import type { BaseEvent } from '../../types/event';
5
6
  import utils from '../../utils/utils';
6
- import { ICON_OBJ, ANIMATION_PROP, DURATION } from './constants';
7
- import type { MessageBoxOptions } from '../../types';
8
- import { STE_MESSAGE_BOX_KEY } from './use-message-box';
9
- import { useMsgBoxStore } from '../../store';
10
- import { useColorStore } from '../../store/color';
11
- let { getColor } = useColorStore();
7
+ import { ICON_OBJ, ANIMATION_PROP, DURATION, type MessageBoxOptions } from './constants';
12
8
 
13
9
  defineOptions({
14
10
  name: 'ste-message-box',
@@ -19,9 +15,6 @@ const slots = useSlots();
19
15
  const props = defineProps<{
20
16
  selector: string;
21
17
  }>();
22
- const customKey = props.selector || STE_MESSAGE_BOX_KEY;
23
- const { getMessageBox, resetMessageBox } = useMsgBoxStore();
24
- const messageBoxOption = getMessageBox(customKey);
25
18
 
26
19
  const {
27
20
  animationData,
@@ -44,6 +37,9 @@ const {
44
37
  showInputPlaceholder,
45
38
  } = useData();
46
39
 
40
+ const injectKey = props.selector ? props.selector : messageBoxDefaultOptionsKey;
41
+ const injectMessageBoxOption = ref<MessageBoxOptions>(inject(injectKey) || {});
42
+
47
43
  // 用input自带占位符时,由于动画原因导致最终显示会有一个下降的效果
48
44
  function handleInputFocus() {
49
45
  showInputPlaceholder.value = false;
@@ -59,7 +55,7 @@ const cmpRootStyle = computed(() => {
59
55
  return {
60
56
  opacity: 0,
61
57
  '--cancel-color': cancelColor.value,
62
- '--confirm-color': confirmColor.value ? confirmColor.value : getColor().steThemeColor,
58
+ '--confirm-color': confirmColor.value,
63
59
  };
64
60
  });
65
61
 
@@ -112,7 +108,6 @@ function closeBox() {
112
108
  maskAnimationData.value = maskAnimation.export();
113
109
  setTimeout(() => {
114
110
  show.value = false;
115
- resetMessageBox(customKey);
116
111
  }, DURATION);
117
112
  }
118
113
  function handleInput(e: Event) {
@@ -149,18 +144,14 @@ function loadMessageBoxParams(options: MessageBoxOptions) {
149
144
  complete.value = options.complete || complete.value;
150
145
  }
151
146
 
152
- watch(
153
- () => messageBoxOption,
154
- val => {
155
- if (val.show) {
156
- loadMessageBoxParams(val);
157
- showBox();
158
- } else {
159
- closeBox();
160
- }
161
- },
162
- { deep: true }
163
- );
147
+ watch(injectMessageBoxOption, val => {
148
+ if (val.show) {
149
+ loadMessageBoxParams(val);
150
+ showBox();
151
+ } else {
152
+ closeBox();
153
+ }
154
+ });
164
155
 
165
156
  function showMsgBox(options: MessageBoxOptions) {
166
157
  loadMessageBoxParams(options);
@@ -197,10 +188,10 @@ defineExpose({
197
188
  </view>
198
189
  </view>
199
190
  <view class="footer">
200
- <view class="footer-btn cancel text" v-if="showCancel" @click="handleCancel">
191
+ <view class="cancel text" v-if="showCancel" @click="handleCancel">
201
192
  {{ cancelText }}
202
193
  </view>
203
- <view class="footer-btn confirm text" @click="handleConfirm">
194
+ <view class="confirm text" @click="handleConfirm">
204
195
  {{ confirmText }}
205
196
  </view>
206
197
  </view>
@@ -244,7 +235,6 @@ defineExpose({
244
235
  .ste-message-title {
245
236
  padding-bottom: 48rpx !important;
246
237
  }
247
-
248
238
  .msg {
249
239
  padding: 0 !important;
250
240
  }
@@ -259,7 +249,6 @@ defineExpose({
259
249
  display: inline-flex;
260
250
  flex-direction: column;
261
251
  transform: scale(0);
262
-
263
252
  .content-box {
264
253
  .icon-box {
265
254
  padding-top: 4rpx;
@@ -273,7 +262,6 @@ defineExpose({
273
262
  align-items: center;
274
263
  justify-content: center;
275
264
  }
276
-
277
265
  .ste-message-title {
278
266
  width: 100%;
279
267
  padding-top: 48rpx;
@@ -286,7 +274,6 @@ defineExpose({
286
274
  .msg {
287
275
  padding: 0 32rpx 48rpx 32rpx;
288
276
  text-align: center;
289
-
290
277
  .text {
291
278
  width: 100%;
292
279
  font-size: var(--font-size-28, 28rpx);
@@ -317,12 +304,10 @@ defineExpose({
317
304
  }
318
305
  }
319
306
  }
320
-
321
307
  .footer {
322
308
  display: flex;
323
309
  height: 96rpx;
324
-
325
- .footer-btn {
310
+ > view {
326
311
  height: 100%;
327
312
  border-top: 2rpx solid #eeeeee;
328
313
  border-right: 2rpx solid #eeeeee;
@@ -346,7 +331,7 @@ defineExpose({
346
331
  color: var(--confirm-color);
347
332
  }
348
333
 
349
- & + .footer-btn {
334
+ &:nth-last-child(1) {
350
335
  border-right: none;
351
336
  }
352
337
  }
@@ -1,26 +1,29 @@
1
- import type { MessageBoxOptions } from '../../types'
2
- import { useMsgBoxStore } from '../../store'
1
+ import { provide, ref } from 'vue';
2
+ import { messageBoxDefaultOptionsKey } from './ste-message-box';
3
+ import type { MessageBoxOptions } from './constants';
3
4
 
4
- export const STE_MESSAGE_BOX_KEY = '$steMsgBoxKey'
5
- export function useMessageBox(key: string = STE_MESSAGE_BOX_KEY) {
6
- const store = useMsgBoxStore()
5
+ export function useMessageBox(customKey?: string) {
6
+ const provideKey = customKey || messageBoxDefaultOptionsKey;
7
+ const MsgOptions = ref<MessageBoxOptions>({});
8
+ provide(provideKey, MsgOptions);
7
9
 
8
- // 初始化
9
- store.initializeState(key)
10
-
11
- return {
12
- showMsgBox(params: MessageBoxOptions) {
13
- store.setMessageBox({
14
- key,
15
- params: {
16
- ...params,
17
- show: true,
18
- },
19
- })
20
- },
21
-
22
- hideMsgBox() {
23
- store.resetMessageBox(key)
24
- },
25
- }
10
+ // 打开弹窗
11
+ function showMsgBox(options: MessageBoxOptions) {
12
+ MsgOptions.value = Object.assign(
13
+ {
14
+ show: true,
15
+ },
16
+ options
17
+ );
18
+ }
19
+ /** 关闭弹窗 */
20
+ function hideMsgBox() {
21
+ MsgOptions.value = {
22
+ show: false,
23
+ };
24
+ }
25
+ return {
26
+ showMsgBox,
27
+ hideMsgBox,
28
+ };
26
29
  }
@@ -1,56 +1,56 @@
1
- import { ref } from 'vue'
2
- import { DEFAULT_CONFIG, type MessageBoxIcon } from './constants'
1
+ import { ref } from 'vue';
2
+ import type { MessageBoxIcon } from './constants';
3
3
 
4
4
  export default function useData() {
5
- const title = ref(DEFAULT_CONFIG.title)
6
- const content = ref('')
7
- const icon = ref<MessageBoxIcon | ''>('')
8
- const cancelText = ref(DEFAULT_CONFIG.cancelText)
9
- const cancelColor = ref(DEFAULT_CONFIG.cancelColor)
10
- const confirmText = ref(DEFAULT_CONFIG.confirmText)
11
- const confirmColor = ref(DEFAULT_CONFIG.confirmColor)
12
- const showCancel = ref(DEFAULT_CONFIG.showCancel)
13
- const editable = ref(DEFAULT_CONFIG.editable)
14
- const placeholderText = ref('')
15
- const inputType = ref('')
16
- const confirm = ref((_value?: string) => {})
17
- const cancel = ref((_value?: string) => {})
18
- const complete = ref((_value?: string) => {})
5
+ const title = ref('确认删除订单?');
6
+ const content = ref('');
7
+ const icon = ref<MessageBoxIcon | ''>('');
8
+ const cancelText = ref('取消');
9
+ const cancelColor = ref('#333333');
10
+ const confirmText = ref('确认');
11
+ const confirmColor = ref('#0090ff');
12
+ const showCancel = ref(true);
13
+ const editable = ref(false);
14
+ const placeholderText = ref('');
15
+ const inputType = ref('');
16
+ const confirm = ref((_value?: string) => {});
17
+ const cancel = ref((_value?: string) => {});
18
+ const complete = ref((_value?: string) => {});
19
19
 
20
- // 内部值
21
- const pageShow = ref(true)
22
- const show = ref(false)
23
- const inputValue = ref('')
24
- const animationData = ref(null)
25
- const maskAnimationData = ref(null)
20
+ // 内部值
21
+ const pageShow = ref(true);
22
+ const show = ref(false);
23
+ const inputValue = ref('');
24
+ const animationData = ref(null);
25
+ const maskAnimationData = ref(null);
26
26
 
27
- const open = ref(false)
28
- const tmpMsg = ref(null)
27
+ const open = ref(false);
28
+ const tmpMsg = ref(null);
29
29
 
30
- const showInputPlaceholder = ref(true)
30
+ const showInputPlaceholder = ref(true);
31
31
 
32
- return {
33
- title,
34
- content,
35
- icon,
36
- cancelText,
37
- cancelColor,
38
- confirmText,
39
- confirmColor,
40
- showCancel,
41
- editable,
42
- placeholderText,
43
- inputType,
44
- confirm,
45
- cancel,
46
- complete,
47
- pageShow,
48
- show,
49
- inputValue,
50
- animationData,
51
- maskAnimationData,
52
- open,
53
- tmpMsg,
54
- showInputPlaceholder,
55
- }
32
+ return {
33
+ title,
34
+ content,
35
+ icon,
36
+ cancelText,
37
+ cancelColor,
38
+ confirmText,
39
+ confirmColor,
40
+ showCancel,
41
+ editable,
42
+ placeholderText,
43
+ inputType,
44
+ confirm,
45
+ cancel,
46
+ complete,
47
+ pageShow,
48
+ show,
49
+ inputValue,
50
+ animationData,
51
+ maskAnimationData,
52
+ open,
53
+ tmpMsg,
54
+ showInputPlaceholder,
55
+ };
56
56
  }
@@ -1,132 +1,144 @@
1
- import { computed, ref, watch } from 'vue';
2
- import utils from '../../utils/utils';
3
- import { useColorStore } from '../../store/color';
4
- let { getColor } = useColorStore();
5
- import type { NumberKeyboardProps } from './props';
1
+ import { computed, ref, watch } from 'vue'
2
+ import utils from '../../utils/utils'
3
+ import { useColorStore } from '../../store/color'
4
+ import type { NumberKeyboardProps } from './props'
5
+
6
+ const { getColor } = useColorStore()
6
7
  export default function useData({
7
- props,
8
- emits,
8
+ props,
9
+ emits,
9
10
  }: {
10
- props: NumberKeyboardProps;
11
- emits: {
12
- (e: 'change', value: string): void;
13
- (e: 'input', value: string): void;
14
- (e: 'update:modelValue', value: string): void;
15
- (e: 'clear'): void;
16
- (e: 'backspace'): void;
17
- (e: 'confirm', value: string): void;
18
- (e: 'click', key: string): void;
19
- (e: 'beforeinput', key: string, suspend: () => void, next: () => void, stop: () => void): void;
20
- (e: 'close'): void;
21
- (e: 'update:show', show: boolean): void;
22
- (e: 'open'): void;
23
- };
11
+ props: NumberKeyboardProps
12
+ emits: {
13
+ (e: 'change', value: string): void
14
+ (e: 'input', value: string): void
15
+ (e: 'update:modelValue', value: string): void
16
+ (e: 'clear'): void
17
+ (e: 'backspace'): void
18
+ (e: 'confirm', value: string): void
19
+ (e: 'click', key: string): void
20
+ (e: 'beforeinput', key: string, suspend: () => void, next: () => void, stop: () => void): void
21
+ (e: 'close'): void
22
+ (e: 'update:show', show: boolean): void
23
+ (e: 'open'): void
24
+ }
24
25
  }) {
25
- const dataValue = ref('');
26
- const setDataValue = (value: string) => {
27
- if (value === dataValue.value) return;
28
- if (value === null || value === undefined) dataValue.value = '';
29
- else if (typeof value === 'string') dataValue.value = value;
30
- else dataValue.value = String(value);
31
- };
26
+ const dataValue = ref('')
27
+ const setDataValue = (value: string) => {
28
+ if (value === dataValue.value)
29
+ return
30
+ if (value === null || value === undefined)
31
+ dataValue.value = ''
32
+ else if (typeof value === 'string')
33
+ dataValue.value = value
34
+ else dataValue.value = String(value)
35
+ }
32
36
 
33
- const dataShow = ref(false);
34
- const setDataShow = (value: boolean) => {
35
- if (value === dataShow.value) return;
36
- dataShow.value = value;
37
- };
37
+ const dataShow = ref(false)
38
+ const setDataShow = (value: boolean) => {
39
+ if (value === dataShow.value)
40
+ return
41
+ dataShow.value = value
42
+ }
38
43
 
39
- const cmpNumbers = computed(() => {
40
- let keys = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'];
41
- if (props.randomKeys) keys = utils.randomArray(keys);
44
+ const cmpNumbers = computed(() => {
45
+ let keys = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']
46
+ if (props.randomKeys)
47
+ keys = utils.randomArray(keys)
42
48
 
43
- if (Array.isArray(props.customKeys)) keys.push(...props.customKeys);
49
+ if (Array.isArray(props.customKeys))
50
+ keys.push(...props.customKeys)
44
51
 
45
- if (!props.rightKeys) {
46
- if (!props.showClear) {
47
- keys.push('backspace');
48
- return;
49
- }
50
- const d = keys.length % 3;
51
- if (d === 1) {
52
- const end = keys.pop();
53
- keys.push('clear', end || '', 'backspace');
54
- } else {
55
- keys.push('clear', 'backspace');
56
- }
57
- }
58
- return keys;
59
- });
52
+ if (!props.rightKeys) {
53
+ if (!props.showClear) {
54
+ keys.push('backspace')
55
+ return
56
+ }
57
+ const d = keys.length % 3
58
+ if (d === 1) {
59
+ const end = keys.pop()
60
+ keys.push('clear', end || '', 'backspace')
61
+ }
62
+ else {
63
+ keys.push('clear', 'backspace')
64
+ }
65
+ }
66
+ return keys
67
+ })
60
68
 
61
- const cmpRootStyle = computed(() => {
62
- return {
63
- '--ste-number-keyboard-text-color': props.textColor,
64
- '--ste-number-keyboard-text-size': `var(--font-size-${props.textSize},${utils.formatPx(props.textSize)})`,
65
- '--ste-number-keyboard-clear-text-size': `var(--font-size-${props.textSize},${utils.formatPx(Number(props.textSize) - 8)})`,
66
- '--ste-number-keyboard-confirm-text-size': `var(--font-size-${props.textSize},${utils.formatPx(Number(props.textSize) - 3)})`,
67
- '--ste-number-keyboard-confirm-bg': props.confirmBg ? props.confirmBg : getColor().steThemeColor,
68
- '--ste-number-keyboard-confirm-bg-active': utils.Color.formatColor(props.confirmBg, 0.8),
69
- '--ste-number-keyboard-confirm-color': props.confirmColor,
70
- };
71
- });
69
+ const cmpRootStyle = computed(() => {
70
+ return {
71
+ '--ste-number-keyboard-text-color': props.textColor,
72
+ '--ste-number-keyboard-text-size': `var(--font-size-${props.textSize},${utils.formatPx(props.textSize)})`,
73
+ '--ste-number-keyboard-clear-text-size': `var(--font-size-${props.textSize},${utils.formatPx(Number(props.textSize) - 8)})`,
74
+ '--ste-number-keyboard-confirm-text-size': `var(--font-size-${props.textSize},${utils.formatPx(Number(props.textSize) - 3)})`,
75
+ '--ste-number-keyboard-confirm-bg': props.confirmBg ? props.confirmBg : getColor().steThemeColor,
76
+ '--ste-number-keyboard-confirm-bg-active': utils.Color.formatColor(props.confirmBg, 0.8),
77
+ '--ste-number-keyboard-confirm-color': props.confirmColor,
78
+ }
79
+ })
72
80
 
73
- watch(() => props.modelValue, setDataValue, { immediate: true });
74
- watch(() => props.show, setDataShow, { immediate: true });
81
+ watch(() => props.modelValue, setDataValue, { immediate: true })
82
+ watch(() => props.show, setDataShow, { immediate: true })
75
83
 
76
- const onClose = () => {
77
- setDataShow(false);
78
- emits('update:show', false);
79
- emits('close');
80
- };
84
+ const onClose = () => {
85
+ setDataShow(false)
86
+ emits('update:show', false)
87
+ emits('close')
88
+ }
81
89
 
82
- const beforInput = async (value: string) => {
83
- let next = true;
84
- const stop = new Promise((resolve, reject) => {
85
- emits(
86
- 'beforeinput',
87
- value,
88
- () => (next = false),
89
- () => resolve('next'),
90
- () => reject(new Error('beforInput stop'))
91
- );
92
- });
93
- if (!next) await stop;
90
+ const beforInput = async (value: string) => {
91
+ let next = true
92
+ const stop = new Promise((resolve, reject) => {
93
+ emits(
94
+ 'beforeinput',
95
+ value,
96
+ () => (next = false),
97
+ () => resolve('next'),
98
+ () => reject(new Error('beforInput stop')),
99
+ )
100
+ })
101
+ if (!next)
102
+ await stop
94
103
 
95
- /* eslint prefer-promise-reject-errors: "error" */
96
- };
104
+ /* eslint prefer-promise-reject-errors: "error" */
105
+ }
97
106
 
98
- const onChange = async (value: string) => {
99
- try {
100
- if (value === 'confirm') {
101
- emits('confirm', dataValue.value);
102
- onClose();
103
- return;
104
- }
105
- switch (value) {
106
- case 'backspace':
107
- setDataValue(dataValue.value.slice(0, dataValue.value.length - 1));
108
- emits('backspace');
109
- break;
110
- case 'clear':
111
- setDataValue('');
112
- emits('clear');
113
- break;
114
- default:
115
- await beforInput(value);
116
- emits('click', value);
117
- if (props.maxlength && dataValue.value.length >= Number(props.maxlength)) return;
118
- dataValue.value += value;
119
- break;
120
- }
121
- emits('input', dataValue.value);
122
- emits('change', dataValue.value);
123
- emits('update:modelValue', dataValue.value);
124
- } catch (e) {
125
- if (e) console.error(e);
126
- }
127
- };
107
+ const onChange = async (value: string) => {
108
+ try {
109
+ if (value === 'confirm') {
110
+ emits('confirm', dataValue.value)
111
+ onClose()
112
+ return
113
+ }
114
+ switch (value) {
115
+ case 'backspace':
116
+ setDataValue(dataValue.value.slice(0, dataValue.value.length - 1))
117
+ emits('backspace')
118
+ break
119
+ case 'clear':
120
+ setDataValue('')
121
+ emits('clear')
122
+ break
123
+ default:
124
+ await beforInput(value)
125
+ emits('click', value)
126
+ if (props.maxlength && dataValue.value.length >= Number(props.maxlength))
127
+ return
128
+ dataValue.value += value
129
+ break
130
+ }
131
+ emits('input', dataValue.value)
132
+ emits('change', dataValue.value)
133
+ emits('update:modelValue', dataValue.value)
134
+ }
135
+ catch (e) {
136
+ if (e)
137
+ console.error(e)
138
+ }
139
+ }
128
140
 
129
- const onOpen = () => emits('open');
141
+ const onOpen = () => emits('open')
130
142
 
131
- return { cmpNumbers, cmpRootStyle, dataShow, onClose, onChange, onOpen };
143
+ return { cmpNumbers, cmpRootStyle, dataShow, onClose, onChange, onOpen }
132
144
  }
@@ -131,7 +131,7 @@ async function click() {
131
131
  type PropsKeyTypee = keyof typeof props;
132
132
  function getDefaultData(key: PropsKeyTypee, value: any) {
133
133
  try {
134
- if (Object.hasOwn(props, key)) {
134
+ if (Object.prototype.hasOwnProperty.call(props, key)) {
135
135
  if (props[key]) {
136
136
  return props[key];
137
137
  } else {