configForm.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * 新增数据源时,根据不同的连接类型,渲染扩展输入字段drivreConfig表单
  3. * @property dictname ENABLE_FLAG
  4. * @property placeholder
  5. * @property style
  6. */
  7. <template>
  8. <span>
  9. <span class="grid-content" v-for="(item, index) in formItemsArr" :key="index" style="">
  10. <EachForm :item="item" v-model="ConfigData" @eachChange='eachChange'></EachForm>
  11. </span>
  12. </span>
  13. </template>
  14. <script>
  15. import EachForm from "./eachForm"
  16. export default {
  17. props: {
  18. value: {
  19. type: [Object,String],
  20. default:()=>{}
  21. },
  22. formItems: {
  23. type: Array,
  24. default:()=>[]
  25. }
  26. },
  27. components:{
  28. EachForm
  29. },
  30. data () {
  31. return {
  32. // inputVals:[],
  33. ConfigData:{
  34. payType: []
  35. }, // 要传递出去的数据
  36. formItemsArr: []
  37. }
  38. },
  39. watch: {
  40. value(newValue, oldValue) {
  41. if ( typeof newValue == "string") {
  42. // 传string进来 表示编辑进来 重新赋值给
  43. setTimeout(()=>{ //保证动态select 渲染完成再赋值
  44. this.ConfigData = JSON.parse(newValue || "{}")
  45. },10)
  46. }else{
  47. this.ConfigData = newValue || {};
  48. }
  49. },
  50. formItems(val){
  51. console.log(val, 'formItems1');
  52. this.formItemsArr = val
  53. console.log(this.formItemsArr)
  54. }
  55. },
  56. computed: {},
  57. methods: {
  58. eachChange(val){
  59. console.log(val, '回传的值');
  60. this.$emit('myChanged', val)
  61. },
  62. // 无论哪个输入框改变 都需要触发事件 将值回传
  63. drivreConfigChange(val,key){
  64. const {ConfigData} = this
  65. // console.log(val,key,"方法方法付付");
  66. // 针对type是下拉框的处理
  67. if (val.extend) {
  68. this.$set(ConfigData,key,val.value);
  69. }else{
  70. this.$set(ConfigData,key,val);
  71. }
  72. this.$emit('input', ConfigData)
  73. this.$emit('myChanged', ConfigData)
  74. },
  75. //重新选择了 数据连接类型 就重置输入框的值
  76. clearInput(){
  77. // this.inputVals.forEach((item,index,arr) => this.$set(arr,index,''));
  78. // 清空 对象
  79. let obj = this.ConfigData
  80. Object.keys(obj).forEach(key => {
  81. if (obj[key]) obj[key] = "";
  82. });
  83. }
  84. }
  85. }
  86. </script>