From f26f29d84e0a68831a6af14dab3eec5500496d2e Mon Sep 17 00:00:00 2001 From: spring <2396852758@qq.com> Date: 星期三, 28 五月 2025 16:48:52 +0800 Subject: [PATCH] 初始化项目 --- components/dict-tag/dict-tag.vue | 75 +++++++++++++++++++++++++++++++++++++ 1 files changed, 75 insertions(+), 0 deletions(-) diff --git a/components/dict-tag/dict-tag.vue b/components/dict-tag/dict-tag.vue new file mode 100644 index 0000000..a8bb29b --- /dev/null +++ b/components/dict-tag/dict-tag.vue @@ -0,0 +1,75 @@ +<template> + <span> + <u-tag :text="item.label" mode="plain" v-for="(item, idx) in options.items" :key="idx" + v-if="item.value === value"/> + </span> +</template> +<script> + +export default { + props: { + value: { + type: String, + default: '' + }, + dictType: { + type: String, + default: '' + }, + items: { + type: Array, + default() { + return []; + } + }, + itemLabel: { + type: String, + default: 'name' + }, + itemValue: { + type: String, + default: 'value' + } + }, + data() { + return { + options: { + value: this.value, + items: this.items + } + }; + }, + watch: { + value(val, oldVal) { + this.options.value = val; + }, + items(val, oldVal) { + this.options.items = val; + } + }, + created() { + this.loadData(); + }, + methods: { + loadData() { + console.log("==", this.value) + if (this.dictType != '') { + this.$u.api.dictData({dictType: this.dictType}).then(res => { + if (typeof res === 'object' && res.result === 'login') { + return; + } + this.options.items = res.data; + }); + } else { + this.options.items = this.items; + } + }, + change(val) { + this.$emit('input', val); + } + } +} +</script> +<style lang="scss" scoped> + +</style> -- Gitblit v1.9.3