haiwei-module-admin 1.0.6 → 1.0.7
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
|
@@ -38,9 +38,9 @@ export default {
|
|
|
38
38
|
type: Boolean,
|
|
39
39
|
default: true
|
|
40
40
|
},
|
|
41
|
-
/** tag
|
|
41
|
+
/** tag类型映射:{0: 'primary', 1: 'success'} 或直接指定类型字符串 */
|
|
42
42
|
tagType: {
|
|
43
|
-
type: String,
|
|
43
|
+
type: [String, Object],
|
|
44
44
|
default: ''
|
|
45
45
|
},
|
|
46
46
|
/** tag效果:dark/light/plain */
|
|
@@ -52,17 +52,11 @@ export default {
|
|
|
52
52
|
tagSize: {
|
|
53
53
|
type: String,
|
|
54
54
|
default: 'small'
|
|
55
|
-
},
|
|
56
|
-
/** 颜色映射配置 */
|
|
57
|
-
colorMap: {
|
|
58
|
-
type: Object,
|
|
59
|
-
default: () => ({})
|
|
60
55
|
}
|
|
61
56
|
},
|
|
62
57
|
data() {
|
|
63
58
|
return {
|
|
64
|
-
enumList: []
|
|
65
|
-
loading: false
|
|
59
|
+
enumList: []
|
|
66
60
|
}
|
|
67
61
|
},
|
|
68
62
|
computed: {
|
|
@@ -71,7 +65,6 @@ export default {
|
|
|
71
65
|
return this.emptyText
|
|
72
66
|
}
|
|
73
67
|
|
|
74
|
-
// 查找对应的枚举项
|
|
75
68
|
const enumItem = this.enumList.find(item => item.value == this.value)
|
|
76
69
|
return enumItem ? enumItem.label : this.value
|
|
77
70
|
},
|
|
@@ -80,104 +73,61 @@ export default {
|
|
|
80
73
|
return this.useTag && this.value !== null && this.value !== undefined && this.value !== ''
|
|
81
74
|
},
|
|
82
75
|
|
|
83
|
-
//
|
|
76
|
+
// 计算tag颜色类型
|
|
84
77
|
computedTagType() {
|
|
78
|
+
// 如果用户指定了tagType
|
|
85
79
|
if (this.tagType) {
|
|
86
|
-
|
|
80
|
+
// 如果是字符串,直接使用
|
|
81
|
+
if (typeof this.tagType === 'string') {
|
|
82
|
+
return this.tagType
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// 如果是对象,根据枚举值查找对应的颜色
|
|
86
|
+
if (typeof this.tagType === 'object' && this.tagType !== null) {
|
|
87
|
+
// 首先尝试精确匹配
|
|
88
|
+
if (this.tagType[this.value] !== undefined) {
|
|
89
|
+
return this.tagType[this.value]
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// 尝试数字匹配
|
|
93
|
+
const numValue = Number(this.value)
|
|
94
|
+
if (this.tagType[numValue] !== undefined) {
|
|
95
|
+
return this.tagType[numValue]
|
|
96
|
+
}
|
|
97
|
+
}
|
|
87
98
|
}
|
|
88
99
|
|
|
89
|
-
//
|
|
100
|
+
// 如果没有指定或未找到匹配,根据枚举值自动计算
|
|
90
101
|
if (this.value === null || this.value === undefined || this.value === '') {
|
|
91
102
|
return 'info'
|
|
92
103
|
}
|
|
93
104
|
|
|
94
|
-
//
|
|
105
|
+
// 将值转换为数字
|
|
95
106
|
const numValue = Number(this.value)
|
|
96
107
|
|
|
97
|
-
//
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
}
|
|
108
|
+
// 简单的颜色映射
|
|
109
|
+
if (numValue === 0) return 'primary' // 默认/初始状态
|
|
110
|
+
if (numValue === 1) return 'success' // 成功/确认状态
|
|
111
|
+
if (numValue === 2) return 'warning' // 警告状态
|
|
112
|
+
if (numValue === 3) return 'danger' // 失败/错误状态
|
|
151
113
|
|
|
152
|
-
//
|
|
114
|
+
// 其他值使用循环颜色
|
|
153
115
|
const colors = ['primary', 'success', 'warning', 'danger', 'info']
|
|
154
|
-
|
|
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'
|
|
116
|
+
return colors[numValue % colors.length] || 'info'
|
|
161
117
|
}
|
|
162
118
|
},
|
|
163
119
|
watch: {
|
|
164
120
|
moduleCode: {
|
|
165
121
|
immediate: true,
|
|
166
|
-
handler
|
|
167
|
-
this.loadEnumList()
|
|
168
|
-
}
|
|
122
|
+
handler: 'loadEnumList'
|
|
169
123
|
},
|
|
170
124
|
enumName: {
|
|
171
125
|
immediate: true,
|
|
172
|
-
handler
|
|
173
|
-
this.loadEnumList()
|
|
174
|
-
}
|
|
126
|
+
handler: 'loadEnumList'
|
|
175
127
|
},
|
|
176
128
|
libName: {
|
|
177
129
|
immediate: true,
|
|
178
|
-
handler
|
|
179
|
-
this.loadEnumList()
|
|
180
|
-
}
|
|
130
|
+
handler: 'loadEnumList'
|
|
181
131
|
}
|
|
182
132
|
},
|
|
183
133
|
methods: {
|
|
@@ -188,16 +138,7 @@ export default {
|
|
|
188
138
|
}
|
|
189
139
|
|
|
190
140
|
try {
|
|
191
|
-
this.loading = true
|
|
192
141
|
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
142
|
const result = await $api.admin.tool.enumSelect({ moduleCode, enumName, libName })
|
|
202
143
|
|
|
203
144
|
if (result && result.data) {
|
|
@@ -208,8 +149,6 @@ export default {
|
|
|
208
149
|
} catch (error) {
|
|
209
150
|
console.error('加载枚举列表失败:', error)
|
|
210
151
|
this.enumList = []
|
|
211
|
-
} finally {
|
|
212
|
-
this.loading = false
|
|
213
152
|
}
|
|
214
153
|
}
|
|
215
154
|
},
|