@ebiz/designer-components 0.0.18-beta.34 → 0.0.18-beta.38

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ebiz/designer-components",
3
- "version": "0.0.18-beta.34",
3
+ "version": "0.0.18-beta.38",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -1,9 +1,9 @@
1
1
  <template>
2
- <tiny-tooltip :content="!isNormal && !apiConfig.apiId ? tooltipText : ''" placement="top">
3
-
4
- 123456
5
-
6
- </tiny-tooltip>
2
+ <t-tooltip :content="!isNormal && !apiConfig.apiId ? tooltipText : ''" placement="top">
3
+ <t-button :disabled="disabled || loading" :theme="type" :size="size" :variant="variant" @click="click">
4
+ <slot>{{ text }}</slot>
5
+ </t-button>
6
+ </t-tooltip>
7
7
  </template>
8
8
 
9
9
 
@@ -14,12 +14,10 @@ export default {
14
14
  </script>
15
15
 
16
16
  <script lang='js' setup>
17
-
18
- import { ref, reactive, computed, toRef, toRefs } from 'vue';
19
- import { TinyButton, TinyTooltip, TinyNotify } from '@opentiny/vue';
17
+ import { ref, toRefs, defineProps, defineEmits } from 'vue';
18
+ import { Button as TButton, Tooltip as TTooltip } from 'tdesign-vue-next';
20
19
  import dataService from '../apiService/simpleDataService';
21
20
 
22
-
23
21
  const props = defineProps({
24
22
  text: {
25
23
  type: String,
@@ -33,25 +31,29 @@ const props = defineProps({
33
31
  type: Boolean,
34
32
  default: false
35
33
  },
36
- type: {//'default' | 'primary' | 'success' | 'warning' | 'danger' | 'info' | 'text'
34
+ type: {//'default' | 'primary' | 'success' | 'warning' | 'danger' | 'info'
37
35
  type: String,
38
- default: 'primary'
36
+ default: 'default'
39
37
  },
40
- size: {//'large' | 'medium' | 'small' | 'mini'
38
+ size: {//'large' | 'medium' | 'small'
41
39
  type: String,
42
40
  default: 'medium'
43
41
  },
42
+ variant: {//'base' | 'outline' | 'dashed' | 'text'
43
+ type: String,
44
+ default: 'base'
45
+ },
44
46
  apiConfig: {//接口配置
45
47
  type: Object,
46
- default: {
48
+ default: () => ({
47
49
  key: null,
48
50
  apiId: null,
49
51
  apiType: ''
50
- }
52
+ })
51
53
  },
52
54
  data: {
53
55
  type: Object,
54
- default: {}
56
+ default: () => ({})
55
57
  },
56
58
  onClick: {
57
59
  type: Function,
@@ -59,11 +61,15 @@ const props = defineProps({
59
61
  },
60
62
  onPrepare: {//调用接口前置事件
61
63
  type: Function,
62
- default: () => { }
64
+ default: () => true // 默认返回true,允许继续执行
63
65
  },
64
66
  onFinish: {//调用接口后置事件
65
67
  type: Function,
66
68
  default: () => { }
69
+ },
70
+ onError: {
71
+ type: Function,
72
+ default: () => { }
67
73
  }
68
74
  })
69
75
 
@@ -80,23 +86,72 @@ const apiMap = [
80
86
  'MULTIPLE_DATA_LINK_SEARCH'
81
87
  ];
82
88
 
83
- const emit = defineEmits(['click'])
89
+ const emit = defineEmits(['click', 'success', 'error', 'loading', 'prepare'])
84
90
 
85
- const { text, isNormal, disabled, type, size, apiConfig, data, isUseMethod } = toRefs(props)
91
+ const { text, isNormal, disabled, type, size, variant, apiConfig, data } = toRefs(props)
86
92
 
87
93
  const tooltipText = ref('请先设置接口配置')
94
+ const loading = ref(false)
88
95
 
89
- const click = () => {
96
+ // 检查API配置是否有效
97
+ const isValidApiConfig = () => {
98
+ return apiConfig.value && apiConfig.value.apiId &&
99
+ typeof apiConfig.value.apiType === 'number' &&
100
+ apiConfig.value.apiType >= 0 &&
101
+ apiConfig.value.apiType < apiMap.length;
102
+ }
103
+
104
+ const click = async () => {
105
+ // 总是调用onClick回调
90
106
  props.onClick()
91
- if (!isNormal.value && apiConfig.value.apiId) {
92
- props.onPrepare()
93
- dataService.fetch(data.value, { key: apiConfig.value.key, apiId: apiConfig.value.apiId, apiType: apiMap[apiConfig.value.apiType] }).then((res) => {
94
- emit('click', res)
95
- props.onFinish()
107
+
108
+ // 如果是普通按钮或API配置无效,不调用接口
109
+ if (isNormal.value || !isValidApiConfig()) {
110
+ emit('click', null)
111
+ return
112
+ }
113
+
114
+ try {
115
+ // 设置加载状态
116
+ loading.value = true
117
+ emit('loading', true)
118
+
119
+ // 调用前置处理并获取返回值
120
+ const shouldContinue = props.onPrepare()
121
+ emit('prepare', shouldContinue)
122
+
123
+ // 只有当返回值明确为false时才中断,undefined或其他值都继续执行
124
+ if (shouldContinue === false) {
125
+ emit('click', null)
126
+ return null
127
+ }
128
+
129
+ // 调用接口
130
+ const apiType = apiMap[apiConfig.value.apiType]
131
+ const res = await dataService.fetch(data.value, {
132
+ key: apiConfig.value.key,
133
+ apiId: apiConfig.value.apiId,
134
+ apiType
96
135
  })
136
+
137
+ // 成功处理
138
+ emit('click', res)
139
+ emit('success', res)
140
+ props.onFinish(res)
141
+
142
+ return res
143
+ } catch (error) {
144
+ // 错误处理
145
+ emit('error', error)
146
+ props.onError(error)
147
+
148
+ return null
149
+ } finally {
150
+ // 清除加载状态
151
+ loading.value = false
152
+ emit('loading', false)
97
153
  }
98
154
  }
99
-
100
155
  </script>
101
156
 
102
157
  <style lang='less' scoped></style>