api-edit.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <template>
  2. <div v-loading="loading">
  3. <div class="white-box">
  4. <el-form ref="form" :model="form" label-width="250px" class="form-page">
  5. <el-form-item label="接口类型">{{apiType}}</el-form-item>
  6. <template v-for="item in configData">
  7. <el-form-item :label="item.TITLE" :key="item.CONFIG_NAME">
  8. <template v-if="item.INPUT_TYPE==='2'">
  9. <el-select v-model="item.VALUE" placeholder="请选择">
  10. <el-option v-for="optionItem in item.OPTIONS" :label="optionItem.label" :value="optionItem.value"
  11. :key="optionItem.label"></el-option>
  12. </el-select>
  13. </template>
  14. <template v-else-if="item.INPUT_TYPE==='3'">
  15. <el-checkbox-group v-model="item.VALUE">
  16. <el-checkbox v-for="optionItem in item.OPTIONS" :label="optionItem.label" :value="optionItem.value"
  17. :key="optionItem.label"></el-checkbox>
  18. </el-checkbox-group>
  19. </template>
  20. <template v-else-if="item.INPUT_TYPE==='4'">
  21. <el-date-picker v-model="item.VALUE" type="year" placeholder="选择年">
  22. </el-date-picker>
  23. </template>
  24. <template v-else-if="item.INPUT_TYPE==='5'">
  25. <el-date-picker
  26. v-model="item.VALUE"
  27. type="datetime"
  28. placeholder="Select date">
  29. </el-date-picker>
  30. </template>
  31. <template v-else-if="item.INPUT_TYPE==='6'">
  32. <el-date-picker
  33. v-model="item.VALUE"
  34. type="date"
  35. placeholder="Select date">
  36. </el-date-picker>
  37. </template>
  38. <template v-else-if="item.INPUT_TYPE==='7'">
  39. <el-time-select v-model="item.VALUE"
  40. :picker-options="{start: item.OPTIONS.start, end: item.OPTIONS.end, step: item.OPTIONS.step}"
  41. placeholder="选择时间">
  42. </el-time-select>
  43. </template>
  44. <template v-else-if="item.INPUT_TYPE==='8'">
  45. <el-switch v-model="item.VALUE">
  46. </el-switch>
  47. </template>
  48. <template v-else>
  49. <el-input v-model="item.VALUE" placeholder="请输入内容">
  50. <template v-if="!!item.UNIT" slot="append">{{item.UNIT}}</template>
  51. </el-input>
  52. </template>
  53. </el-form-item>
  54. </template>
  55. <el-form-item>
  56. <el-button type="primary" @click="onSubmit" :loading="submitButtonStat">更新</el-button>
  57. </el-form-item>
  58. </el-form>
  59. </div>
  60. </div>
  61. </template>
  62. <script>
  63. import network from './../../utils/network'
  64. export default {
  65. name: 'config_api-edit',
  66. mounted () {
  67. this.getData()
  68. },
  69. data () {
  70. return {
  71. loading: true,
  72. submitButtonStat: false,
  73. configData: null,
  74. apiType: '',
  75. }
  76. },
  77. computed: {
  78. form: function () {
  79. let result = {}
  80. for (let i in this.configData) {
  81. result[i] = this.configData[i].VALUE
  82. }
  83. return result
  84. }
  85. },
  86. methods: {
  87. onSubmit () {
  88. this.submitButtonStat = true
  89. let requestPath = ``
  90. if(this.$route.params.type === 'ocr'){
  91. requestPath = `config/ocr-api-edit/${this.$route.params.id}`
  92. } else if(this.$route.params.type === 'sms') {
  93. requestPath = `config/sms-api-edit/${this.$route.params.id}`
  94. }
  95. network.postData(requestPath, {config: this.form}).then(response => {
  96. this.$message({
  97. message: response,
  98. type: 'success'
  99. })
  100. this.submitButtonStat = false
  101. this.getData()
  102. this.$router.go(-1)
  103. }).catch(response => {
  104. this.submitButtonStat = false
  105. this.getData()
  106. })
  107. },
  108. getData () {
  109. if(this.$route.params.type === 'ocr'){
  110. network.getData(`config/ocr-api-edit/${this.$route.params.id}`).then(response => {
  111. this.configData = response.CONFIGS
  112. this.apiType = response.apiType
  113. this.loading = false
  114. })
  115. } else if(this.$route.params.type === 'sms') {
  116. network.getData(`config/sms-api-edit/${this.$route.params.id}`).then(response => {
  117. this.configData = response.CONFIGS
  118. this.apiType = response.apiType
  119. this.loading = false
  120. })
  121. } else {
  122. this.loading = false
  123. }
  124. },
  125. }
  126. }
  127. </script>
  128. <style scoped>
  129. </style>