ExtDLabel.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <style scoped lang="scss">
  2. .status-label {
  3. display: inline-block;
  4. padding: 5px 6px 1px 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: 2px;
  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,watch} 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,Boolean]
  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:{} as any
  104. })
  105. const setupColorStyle = (hex: string = "#000000") => {
  106. let hexToRgb = u.hexToRgb(hex);
  107. let {r, g, b} = hexToRgb;
  108. return {
  109. // 'text-shadow': `2px 2px 3px rgba(${r},${g},${b},0.2)`,
  110. 'background-color': `rgba(${r},${g},${b},0.2)`,
  111. 'color': `rgb(${r},${g},${b})`
  112. }
  113. }
  114. watch(()=>props.modelValue,(oldVal,newVal)=>{
  115. setupLabel();
  116. })
  117. onMounted(() => {
  118. setupLabel()
  119. });
  120. const setupLabel = ()=>{
  121. if (!u.isEmptyOrNull(props.dataRange)) {
  122. let data = props.dataRange?.find(k => k.value == props.modelValue);
  123. if (data) {
  124. let {label, color} = data;
  125. state.text = label;
  126. state.style = setupColorStyle(color);
  127. }
  128. } else {
  129. let dicts = [];
  130. const sessionDicts = Session.get("dicts");
  131. if (!u.isEmptyOrNull(sessionDicts)) {
  132. dicts =sessionDicts[`${props.type}`]
  133. if(u.isEmptyOrNull(dicts)){
  134. return "-";
  135. }
  136. }else{
  137. dicts =state.dicts[`${props.type}`]
  138. if(u.isEmptyOrNull(dicts)){
  139. return "-";
  140. }
  141. }
  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||dict.value.length%8]);
  146. }else{
  147. return "-"
  148. }
  149. }
  150. }
  151. </script>