haiwei-module-admin 1.0.6 → 1.0.8

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
@@ -2,7 +2,7 @@
2
2
  "id": 0,
3
3
  "name": "haiwei-module-admin",
4
4
  "code": "admin",
5
- "version": "1.0.6",
5
+ "version": "1.0.8",
6
6
  "description": "haiwei前端Admin模块组件",
7
7
  "author": "Eric",
8
8
  "license": "ISC",
@@ -24,10 +24,8 @@ export default {
24
24
  required: true
25
25
  },
26
26
  /** 所在库 */
27
- libName: {
28
- type: String,
29
- default: ''
30
- },
27
+ /**所在库 */
28
+ libName: String,
31
29
  /** 空值显示文本 */
32
30
  emptyText: {
33
31
  type: String,
@@ -38,9 +36,9 @@ export default {
38
36
  type: Boolean,
39
37
  default: true
40
38
  },
41
- /** tag类型:primary/success/info/warning/danger */
39
+ /** tag类型映射:{0: 'primary', 1: 'success'} 或直接指定类型字符串 */
42
40
  tagType: {
43
- type: String,
41
+ type: [String, Object],
44
42
  default: ''
45
43
  },
46
44
  /** tag效果:dark/light/plain */
@@ -52,17 +50,11 @@ export default {
52
50
  tagSize: {
53
51
  type: String,
54
52
  default: 'small'
55
- },
56
- /** 颜色映射配置 */
57
- colorMap: {
58
- type: Object,
59
- default: () => ({})
60
53
  }
61
54
  },
62
55
  data() {
63
56
  return {
64
- enumList: [],
65
- loading: false
57
+ enumList: []
66
58
  }
67
59
  },
68
60
  computed: {
@@ -71,7 +63,6 @@ export default {
71
63
  return this.emptyText
72
64
  }
73
65
 
74
- // 查找对应的枚举项
75
66
  const enumItem = this.enumList.find(item => item.value == this.value)
76
67
  return enumItem ? enumItem.label : this.value
77
68
  },
@@ -80,104 +71,61 @@ export default {
80
71
  return this.useTag && this.value !== null && this.value !== undefined && this.value !== ''
81
72
  },
82
73
 
83
- // 根据枚举值自动计算tag类型
74
+ // 计算tag颜色类型
84
75
  computedTagType() {
76
+ // 如果用户指定了tagType
85
77
  if (this.tagType) {
86
- return this.tagType
78
+ // 如果是字符串,直接使用
79
+ if (typeof this.tagType === 'string') {
80
+ return this.tagType
81
+ }
82
+
83
+ // 如果是对象,根据枚举值查找对应的颜色
84
+ if (typeof this.tagType === 'object' && this.tagType !== null) {
85
+ // 首先尝试精确匹配
86
+ if (this.tagType[this.value] !== undefined) {
87
+ return this.tagType[this.value]
88
+ }
89
+
90
+ // 尝试数字匹配
91
+ const numValue = Number(this.value)
92
+ if (this.tagType[numValue] !== undefined) {
93
+ return this.tagType[numValue]
94
+ }
95
+ }
87
96
  }
88
97
 
89
- // 如果没有指定tagType,根据枚举值自动计算
98
+ // 如果没有指定或未找到匹配,根据枚举值自动计算
90
99
  if (this.value === null || this.value === undefined || this.value === '') {
91
100
  return 'info'
92
101
  }
93
102
 
94
- // 将枚举值转换为数字
103
+ // 将值转换为数字
95
104
  const numValue = Number(this.value)
96
105
 
97
- // 合并默认颜色映射和用户自定义颜色映射
98
- const defaultColorMap = {
99
- // 状态类枚举
100
- 0: 'primary', // 默认/初始/待处理
101
- 1: 'success', // 成功/完成/已确认
102
- 2: 'warning', // 警告/进行中
103
- 3: 'danger', // 失败/错误/已取消
104
- 4: 'info', // 信息/其他
105
-
106
- // 布尔类枚举
107
- true: 'success',
108
- false: 'danger',
109
-
110
- // 字符串值映射
111
- 'active': 'success',
112
- 'inactive': 'info',
113
- 'pending': 'warning',
114
- 'rejected': 'danger',
115
- 'approved': 'success',
116
- 'draft': 'info'
117
- }
118
-
119
- // 合并颜色映射,用户自定义的优先级更高
120
- const mergedColorMap = { ...defaultColorMap, ...this.colorMap }
121
-
122
- // 首先检查用户自定义的精确匹配
123
- if (mergedColorMap[this.value] !== undefined) {
124
- return mergedColorMap[this.value]
125
- }
126
-
127
- // 检查数字映射
128
- if (mergedColorMap[numValue] !== undefined) {
129
- return mergedColorMap[numValue]
130
- }
131
-
132
- // 根据枚举文本内容智能判断
133
- const foundEnumItem = this.enumList.find(item => item.value == this.value)
134
- if (foundEnumItem && foundEnumItem.label) {
135
- const label = foundEnumItem.label.toLowerCase()
136
-
137
- // 根据标签文本判断颜色
138
- if (label.includes('成功') || label.includes('完成') || label.includes('通过') || label.includes('确认') || label.includes('出仓')) {
139
- return 'success'
140
- }
141
- if (label.includes('失败') || label.includes('错误') || label.includes('拒绝') || label.includes('取消') || label.includes('入仓')) {
142
- return 'danger'
143
- }
144
- if (label.includes('警告') || label.includes('注意') || label.includes('进行中') || label.includes('处理中')) {
145
- return 'warning'
146
- }
147
- if (label.includes('默认') || label.includes('初始') || label.includes('待处理') || label.includes('未开始')) {
148
- return 'primary'
149
- }
150
- }
106
+ // 简单的颜色映射
107
+ if (numValue === 0) return 'primary' // 默认/初始状态
108
+ if (numValue === 1) return 'success' // 成功/确认状态
109
+ if (numValue === 2) return 'warning' // 警告状态
110
+ if (numValue === 3) return 'danger' // 失败/错误状态
151
111
 
152
- // 其他值使用哈希算法生成稳定颜色
112
+ // 其他值使用循环颜色
153
113
  const colors = ['primary', 'success', 'warning', 'danger', 'info']
154
- let hash = 0
155
- const strValue = String(this.value)
156
- for (let i = 0; i < strValue.length; i++) {
157
- hash = strValue.charCodeAt(i) + ((hash << 5) - hash)
158
- }
159
- hash = Math.abs(hash)
160
- return colors[hash % colors.length] || 'info'
114
+ return colors[numValue % colors.length] || 'info'
161
115
  }
162
116
  },
163
117
  watch: {
164
118
  moduleCode: {
165
119
  immediate: true,
166
- handler() {
167
- this.loadEnumList()
168
- }
120
+ handler: 'loadEnumList'
169
121
  },
170
122
  enumName: {
171
123
  immediate: true,
172
- handler() {
173
- this.loadEnumList()
174
- }
124
+ handler: 'loadEnumList'
175
125
  },
176
126
  libName: {
177
127
  immediate: true,
178
- handler() {
179
- this.loadEnumList()
180
- }
128
+ handler: 'loadEnumList'
181
129
  }
182
130
  },
183
131
  methods: {
@@ -188,16 +136,7 @@ export default {
188
136
  }
189
137
 
190
138
  try {
191
- this.loading = true
192
139
  const { moduleCode, enumName, libName } = this
193
-
194
- // 确保$api存在
195
- if (typeof $api === 'undefined' || !$api.admin || !$api.admin.tool || !$api.admin.tool.enumSelect) {
196
- console.warn('API未定义,无法加载枚举列表')
197
- this.enumList = []
198
- return
199
- }
200
-
201
140
  const result = await $api.admin.tool.enumSelect({ moduleCode, enumName, libName })
202
141
 
203
142
  if (result && result.data) {
@@ -208,8 +147,6 @@ export default {
208
147
  } catch (error) {
209
148
  console.error('加载枚举列表失败:', error)
210
149
  this.enumList = []
211
- } finally {
212
- this.loading = false
213
150
  }
214
151
  }
215
152
  },