first commit

This commit is contained in:
@jyuhsin
2026-01-14 14:49:41 +08:00
commit 105c955abd
4752 changed files with 911871 additions and 0 deletions
@@ -0,0 +1,118 @@
<template>
<div>
<template v-for="item in options">
<component :key="item[value_key]" v-if="item[value_key] === value" v-bind="$attrs"
:is="isMobile ? 'van-tag' : 'el-tag'" :type="item.type"
>{{ item[label_key] }}
</component>
</template>
</div>
</template>
<script>
// 全局缓存和请求Promise缓存
const enumCache = {}
const requestPromises = {}
module.exports = {
name: "DictTag",
props: {
value: { type: String | Number },
name: { type: String },
value_key: {
type: String,
default: "code"
},
label_key: {
type: String,
default: "name"
},
},
data() {
return {
options: [],
isMobile: true,
}
},
watch: {
code: {
handler(val) {
this.getEnumOptions()
},
immediate: true
}
},
methods: {
isMobileDevice() {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
navigator.userAgent
);
},
getEnumOptions() {
// // 检查数据缓存
// if (enumCache[this.name]) {
// this.options = enumCache[this.name]
// return
// }
//
// // 检查是否已有相同请求在进行中
// if (requestPromises[this.name]) {
// requestPromises[this.name].then(data => {
// this.options = data
// })
// return
// }
// 创建请求Promise并缓存
requestPromises[this.name] = $.get("/open/common/dictEnumOptions", { name: this.name })
.then(res => {
if (res.code === 0) {
// 存入数据缓存
enumCache[this.name] = res.data
// 清除请求Promise缓存
delete requestPromises[this.name]
return res.data
}
})
requestPromises[this.name].then(data => {
this.options = data
})
}
},
created() {
this.isMobile = this.isMobileDevice()
}
}
</script>
<style scoped>
.el-tag + .el-tag {
margin-left: 10px;
}
.van-tag {
height: 24px;
padding: 0 8px;
line-height: 22px;
}
.van-tag--success {
background-color: #f0f9eb;
border-color: #e1f3d8;
color: #67c23a;
}
.van-tag--primary {
color: var(--color-primary);
background-color: #ecf5ff;
border-color: #d9ecff;
}
.van-tag--danger{
background-color: #fef0f0;
border-color: #fde2e2;
color: #f56c6c;
}
.van-tag--warning{
background-color: #fdf6ec;
border-color: #faecd8;
color: #e6a23c;
}
</style>