haiwei-module-admin 1.0.2 → 1.0.5
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.
|
|
5
|
+
"version": "1.0.5",
|
|
6
6
|
"description": "haiwei前端Admin模块组件",
|
|
7
7
|
"author": "Eric",
|
|
8
8
|
"license": "ISC",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"haiwei-skins-classics": "^1.0.2",
|
|
22
|
-
"haiwei-ui": "^1.0.
|
|
22
|
+
"haiwei-ui": "^1.0.7"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@vue/cli-plugin-babel": "^4.4.4",
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<el-tag v-if="showTag" :type="computedTagType" :effect="tagEffect" :size="tagSize">
|
|
3
|
+
{{ displayText }}
|
|
4
|
+
</el-tag>
|
|
5
|
+
<span v-else>{{ displayText }}</span>
|
|
6
|
+
</template>
|
|
7
|
+
|
|
8
|
+
<script>
|
|
9
|
+
export default {
|
|
10
|
+
props: {
|
|
11
|
+
/** 枚举值 */
|
|
12
|
+
value: {
|
|
13
|
+
type: [Number, String],
|
|
14
|
+
default: null
|
|
15
|
+
},
|
|
16
|
+
/** 模块编码 */
|
|
17
|
+
moduleCode: {
|
|
18
|
+
type: String,
|
|
19
|
+
required: true
|
|
20
|
+
},
|
|
21
|
+
/** 枚举名称 */
|
|
22
|
+
enumName: {
|
|
23
|
+
type: String,
|
|
24
|
+
required: true
|
|
25
|
+
},
|
|
26
|
+
/** 所在库 */
|
|
27
|
+
libName: {
|
|
28
|
+
type: String,
|
|
29
|
+
default: ''
|
|
30
|
+
},
|
|
31
|
+
/** 空值显示文本 */
|
|
32
|
+
emptyText: {
|
|
33
|
+
type: String,
|
|
34
|
+
default: ''
|
|
35
|
+
},
|
|
36
|
+
/** 是否使用tag标签显示 */
|
|
37
|
+
useTag: {
|
|
38
|
+
type: Boolean,
|
|
39
|
+
default: true
|
|
40
|
+
},
|
|
41
|
+
/** tag类型:primary/success/info/warning/danger */
|
|
42
|
+
tagType: {
|
|
43
|
+
type: String,
|
|
44
|
+
default: ''
|
|
45
|
+
},
|
|
46
|
+
/** tag效果:dark/light/plain */
|
|
47
|
+
tagEffect: {
|
|
48
|
+
type: String,
|
|
49
|
+
default: 'light'
|
|
50
|
+
},
|
|
51
|
+
/** tag尺寸:medium/small/mini */
|
|
52
|
+
tagSize: {
|
|
53
|
+
type: String,
|
|
54
|
+
default: 'small'
|
|
55
|
+
},
|
|
56
|
+
/** 颜色映射配置 */
|
|
57
|
+
colorMap: {
|
|
58
|
+
type: Object,
|
|
59
|
+
default: () => ({})
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
data() {
|
|
63
|
+
return {
|
|
64
|
+
enumList: [],
|
|
65
|
+
loading: false
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
computed: {
|
|
69
|
+
displayText() {
|
|
70
|
+
if (this.value === null || this.value === undefined || this.value === '') {
|
|
71
|
+
return this.emptyText
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// 查找对应的枚举项
|
|
75
|
+
const enumItem = this.enumList.find(item => item.value == this.value)
|
|
76
|
+
return enumItem ? enumItem.label : this.value
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
showTag() {
|
|
80
|
+
return this.useTag && this.value !== null && this.value !== undefined && this.value !== ''
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
// 根据枚举值自动计算tag类型
|
|
84
|
+
computedTagType() {
|
|
85
|
+
if (this.tagType) {
|
|
86
|
+
return this.tagType
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// 如果没有指定tagType,根据枚举值自动计算
|
|
90
|
+
if (this.value === null || this.value === undefined || this.value === '') {
|
|
91
|
+
return 'info'
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// 将枚举值转换为数字
|
|
95
|
+
const numValue = Number(this.value)
|
|
96
|
+
|
|
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 enumItem = this.enumList.find(item => item.value == this.value)
|
|
134
|
+
if (enumItem && enumItem.label) {
|
|
135
|
+
const label = enumItem.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
|
+
}
|
|
151
|
+
|
|
152
|
+
// 其他值使用哈希算法生成稳定颜色
|
|
153
|
+
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'
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
watch: {
|
|
164
|
+
moduleCode: {
|
|
165
|
+
immediate: true,
|
|
166
|
+
handler() {
|
|
167
|
+
this.loadEnumList()
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
enumName: {
|
|
171
|
+
immediate: true,
|
|
172
|
+
handler() {
|
|
173
|
+
this.loadEnumList()
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
libName: {
|
|
177
|
+
immediate: true,
|
|
178
|
+
handler() {
|
|
179
|
+
this.loadEnumList()
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
methods: {
|
|
184
|
+
async loadEnumList() {
|
|
185
|
+
if (!this.moduleCode || !this.enumName) {
|
|
186
|
+
this.enumList = []
|
|
187
|
+
return
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
try {
|
|
191
|
+
this.loading = true
|
|
192
|
+
const { moduleCode, enumName, libName } = this
|
|
193
|
+
const result = await $api.admin.tool.enumSelect({ moduleCode, enumName, libName })
|
|
194
|
+
|
|
195
|
+
if (result && result.data) {
|
|
196
|
+
this.enumList = result.data
|
|
197
|
+
} else {
|
|
198
|
+
this.enumList = []
|
|
199
|
+
}
|
|
200
|
+
} catch (error) {
|
|
201
|
+
console.error('加载枚举列表失败:', error)
|
|
202
|
+
this.enumList = []
|
|
203
|
+
} finally {
|
|
204
|
+
this.loading = false
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
mounted() {
|
|
209
|
+
this.loadEnumList()
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
</script>
|
|
213
|
+
|
|
214
|
+
<style scoped>
|
|
215
|
+
.el-tag {
|
|
216
|
+
margin: 2px;
|
|
217
|
+
}
|
|
218
|
+
span {
|
|
219
|
+
display: inline-block;
|
|
220
|
+
}
|
|
221
|
+
</style>
|