ExtDLabel.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <style scoped lang="scss">
  2. .status-label {
  3. display: inline-block;
  4. padding: 3px 6px;
  5. font-size: 11px;
  6. font-weight: 600;
  7. line-height: 1;
  8. height: 20px;
  9. text-align: center;
  10. white-space: nowrap;
  11. vertical-align: baseline;
  12. border-radius: 10px;
  13. margin-top: 3px;
  14. width: auto;
  15. color: #fff;
  16. }
  17. .status-label-color {
  18. &-1 {
  19. border: 1px solid #FFB800;
  20. color: #FFB800;
  21. }
  22. &-2 {
  23. border: 1px solid #009688;
  24. color: #009688;
  25. }
  26. &-3 {
  27. border: 1px solid #1E9FFF;
  28. color: #1E9FFF;
  29. }
  30. &-4 {
  31. border: 1px solid #00C7D2;
  32. color: #00C7D2;
  33. }
  34. &-5 {
  35. border: 1px solid #599CDE;
  36. color: #599CDE;
  37. }
  38. &-6 {
  39. border: 1px solid #FF5722;
  40. color: #FF5722;
  41. }
  42. &-7 {
  43. border: 1px solid #eb2f96;
  44. color: #eb2f96;
  45. }
  46. &-8 {
  47. border: 1px solid #4a5055;
  48. color: #4a5055;
  49. }
  50. }
  51. .status-label-mode {
  52. &-1 {
  53. color: #5FB878;
  54. }
  55. &-2 {
  56. color: #009688;
  57. }
  58. &-3 {
  59. color: #1E9FFF;
  60. }
  61. &-4 {
  62. color: #00C7D2;
  63. }
  64. &-5 {
  65. color: #599CDE;
  66. }
  67. &-6 {
  68. color: #FF5722;
  69. }
  70. &-7 {
  71. color: #eb2f96;
  72. }
  73. &-8 {
  74. color: #4a5055;
  75. }
  76. }
  77. </style>
  78. <template>
  79. <span class="status-label" :style="state.style">{{ state.text }}</span>
  80. </template>
  81. <script setup lang="ts" name="ExtDLabel">
  82. import {onMounted, reactive} from 'vue';
  83. import {Session} from "/@/utils/storage";
  84. import u from "/@/utils/u";
  85. // const emit = defineEmits(['update:value']);
  86. const props = defineProps({
  87. modelValue: {
  88. type: [Number, String]
  89. },
  90. type: {
  91. type: String,
  92. require: true
  93. },
  94. dataRange: {
  95. type: Array<IFieldRange>
  96. }
  97. })
  98. const state = reactive({
  99. text: '' as string,
  100. style: {color: '#000000'},
  101. color:'#fff',
  102. colorList:["#FFB800","#009688","#1E9FFF","#00C7D2","#599CDE","#FF5722","#eb2f96","#4a5055"],
  103. dicts:{
  104. 'User.status':[
  105. {label:'有效',value:1},
  106. {label:'无效',value:0},
  107. ]
  108. }
  109. })
  110. const setupColorStyle = (hex: string = "#000000") => {
  111. let hexToRgb = u.hexToRgb(hex);
  112. let {r, g, b} = hexToRgb;
  113. return {
  114. 'text-shadow': `2px 2px 3px rgba(${r},${g},${b},0.2)`,
  115. // 'background-color': `rgba(${r},${g},${b},0.2)`,
  116. 'color': `rgb(${r},${g},${b})`
  117. }
  118. }
  119. onMounted(() => {
  120. if (!u.isEmptyOrNull(props.dataRange)) {
  121. let data = props.dataRange?.find(k => k.value == props.modelValue);
  122. if (data) {
  123. let {label, color} = data;
  124. state.text = label;
  125. state.style = setupColorStyle(color);
  126. }
  127. } else {
  128. let dicts = [];
  129. const sessionDicts = Session.get("dicts");
  130. if (!u.isEmptyOrNull(sessionDicts)) {
  131. dicts =sessionDicts[`${props.type}`]
  132. if(u.isEmptyOrNull(dicts)){
  133. return "-";
  134. }
  135. }else{
  136. dicts =state.dicts[`${props.type}`]
  137. if(u.isEmptyOrNull(dicts)){
  138. return "-";
  139. }
  140. }
  141. console.log(props.modelValue)
  142. let dict = (<Dicts>dicts).find(k => k.value == props.modelValue);
  143. if (dict) {
  144. state.text = dict.name||dict.label;
  145. state.style = setupColorStyle(state.colorList[dict.value%8]);
  146. }
  147. }
  148. });
  149. </script>