export-config.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <template>
  2. <div id="export-config">
  3. <el-tabs type="card" class="demo-tabs" @tab-click="handleClick">
  4. <el-tab-pane v-for="i in tableList" :key="i.table" :label="i.label" :name="i.table">
  5. <el-row justify="space-between" style="padding: 10px">
  6. <el-col :span="4">
  7. <el-button type="success" @click="toSave">保存当前数据设置</el-button>
  8. </el-col>
  9. <el-col :span="4">
  10. <el-button type="primary" @click="addColumn">添加字段</el-button>
  11. </el-col>
  12. </el-row>
  13. <el-table :data="config" v-loading="loading" height="60vh">
  14. <el-table-column align="center" label="是否使用" prop="is_use" width="150px">
  15. <template #default="{ row }">
  16. <el-switch v-model="row.is_use" class="mb-2" style="--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949" active-text="使用" inactive-text="禁用" active-value="0" inactive-value="1" />
  17. </template>
  18. </el-table-column>
  19. <el-table-column align="center" label="字段" prop="column" width="150px">
  20. <template #default="{ row }">
  21. <el-input v-model="row.column"></el-input>
  22. </template>
  23. </el-table-column>
  24. <el-table-column align="center" label="中文" prop="zh" width="150px">
  25. <template #default="{ row }">
  26. <el-input v-model="row.zh"></el-input>
  27. </template>
  28. </el-table-column>
  29. <el-table-column align="center" label="数据类型" prop="type" width="150px">
  30. <template #default="{ row }">
  31. <el-select v-model="row.type">
  32. <el-option v-for="i in typeList" :key="i.value" :label="i.label" :value="i.value"></el-option>
  33. </el-select>
  34. </template>
  35. </el-table-column>
  36. <el-table-column align="center" label="数据来源" prop="source" width="150px">
  37. <template #default="{ row }">
  38. <el-select v-model="row.source">
  39. <el-option v-for="i in sourceList" :key="i.value" :label="i.label" :value="i.value"></el-option>
  40. </el-select>
  41. </template>
  42. </el-table-column>
  43. <el-table-column align="center" label="字典类型(code)/关联表名(小驼峰)">
  44. <template #default="{ row }">
  45. <template v-if="row.source && row.source !== 'write'">
  46. <el-input v-model="row.from"></el-input>
  47. </template>
  48. </template>
  49. </el-table-column>
  50. <el-table-column align="center" label="导出字典/关联表使用字段">
  51. <template #default="{ row }">
  52. <template v-if="row.source !== 'write'">
  53. <el-input v-model="row.from_column"></el-input>
  54. </template>
  55. </template>
  56. </el-table-column>
  57. <el-table-column align="center" label="操作">
  58. <template #default="{ $index }">
  59. <el-button type="danger" @click="deleteColumn($index)">删除</el-button>
  60. </template>
  61. </el-table-column>
  62. </el-table>
  63. </el-tab-pane>
  64. </el-tabs>
  65. </div>
  66. </template>
  67. <script setup>
  68. import { ExportConfigStore } from '@/store/api/exportConfig'
  69. import { get, cloneDeep } from 'lodash-es'
  70. const store = ExportConfigStore()
  71. const $checkRes = inject('$checkRes')
  72. // 表
  73. const tableList = ref([])
  74. // 数据类型
  75. const typeList = ref([])
  76. // 数据来源
  77. const sourceList = ref([])
  78. const table = ref()
  79. const config = ref([])
  80. const configs = {
  81. demand: [
  82. { column: 'user', zh: '平台用户', type: 'string', source: 'write', is_use: '0' },
  83. { column: 'name', zh: '需求名称', type: 'string', source: 'write', is_use: '0' }
  84. ]
  85. }
  86. const addColumn = () => {
  87. config.value.push({})
  88. }
  89. const deleteColumn = (index) => {
  90. config.value.splice(index, 1)
  91. }
  92. const loading = ref(false)
  93. const handleClick = async (tab, e) => {
  94. const nowView = get(tab, 'props.name')
  95. if (!nowView) return
  96. loading.value = true
  97. try {
  98. // 请求表设置
  99. const result = await store.fetch(nowView)
  100. if ($checkRes(result)) {
  101. console.log('get data')
  102. const data = get(result, 'data.config', [])
  103. table.value = nowView
  104. config.value = data
  105. }
  106. } catch (error) {}
  107. finally{
  108. loading.value = false
  109. }
  110. }
  111. const toSave = async () => {
  112. const table = table.value
  113. const config = config.value
  114. const obj = { table, config }
  115. const result = await store.update(obj)
  116. $checkRes(result, true, result.errmsg)
  117. }
  118. onMounted(() => {
  119. searchOthers()
  120. })
  121. const searchOthers = async () => {
  122. const result = await store.dict()
  123. if ($checkRes(result)) {
  124. const tl = get(result, 'data.typeList', [])
  125. const sl = get(result, 'data.sourceList', [])
  126. const tabl = get(result, 'data.tableList', [])
  127. typeList.value = tl
  128. sourceList.value = sl
  129. tableList.value = tabl
  130. }
  131. }
  132. </script>
  133. <style scoped></style>