TableBox.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <template>
  2. <div>
  3. <div class="btn-box">
  4. <el-button type="primary" icon="el-icon-plus" @click="onCreate">新增</el-button>
  5. </div>
  6. <el-table
  7. v-loading="loading"
  8. :data="data"
  9. border
  10. style="width: 100%"
  11. >
  12. <el-table-column
  13. type="index"
  14. label="序号"
  15. width="80"
  16. fixed="left"
  17. align="center"
  18. />
  19. <el-table-column
  20. prop="parent_field"
  21. label="数据库表"
  22. align="center"
  23. />
  24. <el-table-column
  25. prop="parent_fildname"
  26. label="数据库表名称"
  27. align="center"
  28. />
  29. <el-table-column
  30. prop="field"
  31. label="数据字段"
  32. align="center"
  33. />
  34. <el-table-column
  35. prop="field_name"
  36. label="字段含义"
  37. align="center"
  38. />
  39. <el-table-column
  40. prop=""
  41. label="数据字典"
  42. width="130"
  43. align="center"
  44. >
  45. <template slot-scope="scope">
  46. <el-button type="text" style="color: #E6A23C;" @click="onShowDict(scope.row)">查看</el-button>
  47. </template>
  48. </el-table-column>
  49. <el-table-column key="status" label="状态" width="130" align="center">
  50. <template slot-scope="scope">
  51. <el-switch
  52. v-model="scope.row.status"
  53. active-color="#13ce66"
  54. :active-value="1"
  55. :inactive-value="2"
  56. @change="handleStatusChange(scope.row)"
  57. />
  58. </template>
  59. </el-table-column>
  60. <el-table-column
  61. prop="remark"
  62. label="备注"
  63. align="center"
  64. />
  65. <el-table-column
  66. prop=""
  67. label="操作"
  68. align="center"
  69. fixed="right"
  70. >
  71. <template slot-scope="scope">
  72. <el-button type="text" @click="onEdit(scope.row)">修改</el-button>
  73. <el-button type="text" style="color: #F56C6C;" @click="onDel(scope.row)">删除</el-button>
  74. </template>
  75. </el-table-column>
  76. </el-table>
  77. <!-- 新增、编辑 -->
  78. <CreateDialog v-if="createData.bSwitch" :data="createData" @refresh="handleRefresh" />
  79. <!-- 查看数据字典 -->
  80. <DictDialog v-if="dictData.bSwitch" :data="dictData" @refresh="handleRefresh" />
  81. </div>
  82. </template>
  83. <script>
  84. import CreateDialog from './CreateDialog.vue'
  85. import DictDialog from './DictDialog.vue'
  86. import { edit_dict_status, del_dict } from '@/api/dict'
  87. export default {
  88. components: {
  89. CreateDialog,
  90. DictDialog
  91. },
  92. props: {
  93. data: {
  94. type: Array,
  95. default() {
  96. return []
  97. }
  98. },
  99. loading: {
  100. type: Boolean,
  101. default() {
  102. return false
  103. }
  104. }
  105. },
  106. data() {
  107. return {
  108. statusArr: [
  109. { 'id': 1, 'name': '启用' },
  110. { 'id': 2, 'name': '停用' }
  111. ],
  112. createData: {
  113. bSwitch: false,
  114. row: {}
  115. },
  116. dictData: {
  117. bSwitch: false,
  118. row: {}
  119. }
  120. }
  121. },
  122. methods: {
  123. onCreate() {
  124. this.createData.row = {}
  125. this.createData.bSwitch = true
  126. },
  127. onEdit(row) {
  128. this.createData.row = row
  129. this.createData.bSwitch = true
  130. },
  131. onDel(row) {
  132. this.$confirm('是否确认删除该数据?', '提示', {
  133. confirmButtonText: '确定',
  134. cancelButtonText: '取消',
  135. type: 'warning'
  136. }).then(() => {
  137. del_dict({ id: row.id }).then((res) => {
  138. this.$message.success(res.m || '操作成功')
  139. })
  140. })
  141. },
  142. handleRefresh() {
  143. this.$emit('refresh')
  144. },
  145. handleStatusChange(row) {
  146. const statusIndex = this.statusArr.findIndex((value) => parseInt(value.id) === parseInt(row.status))
  147. this.$confirm('确认要更改为 <strong>' + this.statusArr[statusIndex].name + '</strong> 状态吗?', '提示', {
  148. dangerouslyUseHTMLString: true,
  149. confirmButtonText: '确定',
  150. cancelButtonText: '取消',
  151. type: 'warning'
  152. }).then(() => {
  153. edit_dict_status({ id: row.id, status: row.status }).then((res) => {
  154. this.$message.success(res.m || '操作成功')
  155. }).catch(function() {
  156. row.status = row.status === 2 ? 1 : 2
  157. })
  158. }).catch(function() {
  159. row.status = row.status === 2 ? 1 : 2
  160. })
  161. },
  162. onShowDict(row) {
  163. this.dictData.row = row
  164. this.dictData.bSwitch = true
  165. }
  166. }
  167. }
  168. </script>
  169. <style lang="scss" scoped>
  170. .btn-box {
  171. text-align: right;
  172. margin-bottom: 15px;
  173. }
  174. </style>