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.

159 lines
3.8 KiB

2 years ago
  1. import util from "../js/util.js"
  2. export const MdpFieldMixin = {
  3. computed: {
  4. avaterCpd(){
  5. var isEmpty=this.isEmpty(this.myVal)
  6. var obj={isNull:isEmpty,icon:this.icon?this.icon:'el-icon-full-screen',color:this.color?this.color:'#E4E7ED',innerText:''}
  7. if(isEmpty){
  8. return obj;
  9. }else{
  10. if(this.color){
  11. obj.color=this.color
  12. }else{
  13. obj.color= util.getColorById(this.myVal)
  14. }
  15. if(this.icon){
  16. obj.icon=this.icon
  17. }else{
  18. obj.icon=''
  19. }
  20. obj.innerText=this.myVal
  21. }
  22. return obj;
  23. },
  24. },
  25. data(){
  26. return {
  27. myVal:null,
  28. }
  29. },
  30. watch:{
  31. showAvater:{
  32. type:Boolean,
  33. default:true,
  34. },
  35. value(val){
  36. if(val==this.myVal){
  37. return;
  38. }
  39. this.myVal=val
  40. },
  41. myVal(val){
  42. if(val==this.value){
  43. return;
  44. }
  45. this.$emit('input',this.myVal)
  46. }
  47. },
  48. props: {
  49. disabled:{
  50. type:Boolean,
  51. default:false,
  52. },
  53. closable:{
  54. type:Boolean,
  55. default:false,
  56. },
  57. effect:{
  58. type:String,
  59. default:'dark'//dark / light / plain
  60. },
  61. value: {
  62. type:[String,Number],
  63. default:''
  64. },
  65. clearable:{
  66. type:Boolean,
  67. default:true,
  68. },
  69. styleObj:{
  70. type:Object,
  71. default:function(){return { marginTop:'5px' }}
  72. },
  73. /**
  74. * 输入域的名字
  75. */
  76. label: {
  77. type: String,
  78. default: "",
  79. },
  80. /**
  81. * 空值时显示的内容
  82. */
  83. placeholder:{
  84. type: String,
  85. default:''
  86. },
  87. /**
  88. * 直接指定颜色
  89. */
  90. color:String,
  91. /**
  92. * 直接指定图标
  93. */
  94. icon:String,
  95. /**
  96. * 控制组件的布局
  97. * origin 原始方式保持element-ui原组件样式
  98. * tag 未编辑前以tag显示鼠标放入后显示原生组件模样
  99. * x 综合布局适合于表单追求美观的样式将颜色+图标+布局进行柔和组成新的组件
  100. */
  101. showStyle:{
  102. type:String,
  103. default:'origin'
  104. },
  105. /**
  106. * medium/small/mini
  107. */
  108. size:{
  109. type: String,
  110. default:'small'
  111. }
  112. },
  113. methods: {
  114. showSelect(){
  115. if(this.disabled){
  116. return;
  117. }
  118. if(this.$refs["operRef"]){
  119. if(this.$refs["operRef"].onFieldClick){
  120. this.$refs["operRef"].onFieldClick();
  121. }
  122. }
  123. },
  124. initData(){
  125. if(this.value==this.myVal){
  126. return;
  127. }
  128. this.myVal=this.value
  129. },
  130. onChange(currentVal,oldVal){
  131. this.$emit('change',currentVal,oldVal)
  132. },
  133. isEmpty(v) {
  134. switch (typeof v) {
  135. case 'undefined':
  136. return true;
  137. case 'string':
  138. if(v.length == 0) return true;
  139. break;
  140. case 'object':
  141. if (null === v || v.length === 0) return true;
  142. for (var i in v) {
  143. return false;
  144. }
  145. return true;
  146. }
  147. return false;
  148. },
  149. },
  150. mounted(){
  151. this.initData();
  152. }
  153. }