You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

169 lines
3.4 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. <template>
  2. <div class="field-box">
  3. <el-avatar class="avater" :icon="getMyIcon(currentItem)" :style="{backgroundColor:getMyColor(currentItem)}">{{getMyAvaterInfo(currentItem)}}</el-avatar>
  4. <div class="field-info">
  5. <slot name="field-info" :dict="dict" :item="currentItem">
  6. <span class="field-value">{{currentItem?currentItem.name:''}} </span>
  7. <slot name="label" :dict="dict" :item="currentItem">
  8. <span class="field-label">{{label}}</span>
  9. </slot>
  10. </slot>
  11. </div>
  12. <slot class="my-select" name="select" :dict="dict" :value="myVal">
  13. <dict-select :dict="dict" v-model="myVal" @change="onChange"></dict-select>
  14. </slot>
  15. </div>
  16. </template>
  17. <script>
  18. export default {
  19. name: 'dict-field',
  20. components: { },
  21. computed: {
  22. currentItem(){
  23. if(this.dict){
  24. return this.dict.find(k=>k.id==this.myVal)
  25. }else{
  26. return null;
  27. }
  28. }
  29. },
  30. data(){
  31. return {
  32. myVal:'',
  33. }
  34. },
  35. watch:{
  36. value:{
  37. deep:true,
  38. handler(){
  39. this.initData();
  40. }
  41. },
  42. myVal(){
  43. this.$emit('input',this.myVal)
  44. }
  45. },
  46. props: {
  47. label:{
  48. type:String,
  49. default:''
  50. },
  51. clearable:{
  52. type:Boolean,
  53. default:false,
  54. },
  55. dict:{
  56. type:Array,
  57. default:function(){return []}
  58. },
  59. value: {
  60. },
  61. getIcon:{
  62. type:Function
  63. },
  64. getColor:{
  65. type:Function
  66. } ,
  67. },
  68. methods: {
  69. getMyAvaterInfo(item){
  70. if(!item){
  71. return ""
  72. }else{
  73. return item.icon?"":item.name
  74. }
  75. },
  76. getMyColor(item){
  77. if(!item){
  78. return ""
  79. }
  80. if(this.getColor){
  81. return this.getColor(item.id)
  82. }
  83. if(item.color){
  84. return item.color
  85. }
  86. return ""
  87. },
  88. getMyIcon(item){
  89. if(!item){
  90. return ""
  91. }
  92. if(this.getIcon){
  93. return this.getIcon(item.id)
  94. }
  95. if(item.icon){
  96. return item.icon
  97. }
  98. return "";
  99. },
  100. initData(){
  101. this.myVal=this.value
  102. },
  103. onChange(data){
  104. this.$emit('change',data)
  105. }
  106. },
  107. mounted(){
  108. this.initData();
  109. }
  110. }
  111. </script>
  112. <style lang="scss" scoped>
  113. .field-box {
  114. display: flex;
  115. margin-right:5px;
  116. align-items: center;
  117. cursor: pointer;
  118. .avater {
  119. background-color:#FF9F73;
  120. }
  121. .field-info {
  122. margin-left: 10px;
  123. display: flex;
  124. flex-direction: column;
  125. .field-value {
  126. font-size: 16px;
  127. }
  128. .field-label{
  129. font-size: 14px;
  130. color: #C0C4CC;
  131. }
  132. }
  133. .my-select{
  134. margin-left: 5px;
  135. margin-right:5px;
  136. max-width: 120px;
  137. visibility:hidden;
  138. }
  139. .btn{
  140. margin-top: 0px;
  141. visibility:hidden;
  142. }
  143. }
  144. .field-box:hover .btn{
  145. visibility: visible !important;
  146. }
  147. .field-box:hover .my-select{
  148. margin-left: 5px;
  149. visibility: visible !important;
  150. }
  151. </style>