dynamicAddRadar.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <div>
  3. <el-button
  4. type="primary"
  5. size="small"
  6. icon="el-icon-plus"
  7. plain
  8. @click="handleAddClick"
  9. >新增</el-button
  10. >
  11. <el-table :data="formData" style="width: 100%">
  12. <el-table-column prop="name" label="名称" width="90" />
  13. <el-table-column prop="key" label="key值" width="90" />
  14. <el-table-column prop="max" label="最大值" width="70" />
  15. <el-table-column label="操作" width="90">
  16. <template slot-scope="scope">
  17. <div class="button-group">
  18. <el-button
  19. @click="handleEditorClick(scope.$index, scope.row)"
  20. type="text"
  21. size="small"
  22. >编辑</el-button
  23. >
  24. <el-button
  25. type="text"
  26. size="small"
  27. @click="handleDeleteClick(scope.$index, scope.row)"
  28. >删除</el-button
  29. >
  30. </div>
  31. </template>
  32. </el-table-column>
  33. </el-table>
  34. <el-dialog
  35. title="新增"
  36. :visible.sync="dialogVisible"
  37. width="30%"
  38. :before-close="handleClose"
  39. >
  40. <el-form :model="rowFormData" label-width="60px">
  41. <el-form-item label="名称:">
  42. <el-input
  43. v-model.trim="rowFormData['name']"
  44. placeholder="请输入名称"
  45. size="mini"
  46. >
  47. </el-input>
  48. </el-form-item>
  49. <el-form-item label="key值:">
  50. <el-input
  51. v-model.trim="rowFormData['key']"
  52. placeholder="请输入key值"
  53. size="mini"
  54. >
  55. </el-input>
  56. </el-form-item>
  57. <el-form-item label="最大值:">
  58. <el-input
  59. v-model.trim="rowFormData['max']"
  60. placeholder="请输入最大值"
  61. size="mini"
  62. >
  63. </el-input>
  64. </el-form-item>
  65. </el-form>
  66. <span slot="footer" class="dialog-footer">
  67. <el-button size="mini" @click="dialogVisible = false">取 消</el-button>
  68. <el-button size="mini" type="primary" @click="handleSaveClick"
  69. >确 定</el-button
  70. >
  71. </span>
  72. </el-dialog>
  73. </div>
  74. </template>
  75. <script>
  76. export default {
  77. model: {
  78. prop: "formData",
  79. event: "input"
  80. },
  81. props: {
  82. formData: Array
  83. },
  84. data() {
  85. return {
  86. dialogVisible: false,
  87. rowFormData: {
  88. name: "",
  89. key: "",
  90. max: ""
  91. },
  92. flag: true, // true 新增, false 编辑
  93. indexEditor: -1, // 编辑第几个数据
  94. tableData: []
  95. };
  96. },
  97. methods: {
  98. // 新增
  99. handleAddClick() {
  100. this.rowFormData = {};
  101. this.flag = true;
  102. this.dialogVisible = true;
  103. },
  104. // 编辑
  105. handleEditorClick(index, row) {
  106. this.flag = false;
  107. this.rowFormData = this.deepClone(row);
  108. this.indexEditor = index;
  109. this.dialogVisible = true;
  110. },
  111. // 关闭
  112. handleClose() {
  113. this.dialogVisible = false;
  114. },
  115. // 保存
  116. handleSaveClick() {
  117. if (this.flag) {
  118. // 新增
  119. this.formData.push(this.rowFormData);
  120. this.dialogVisible = false;
  121. } else {
  122. // 编辑
  123. this.formData[this.indexEditor] = this.rowFormData;
  124. this.$set(this.formData, this.indexEditor, this.rowFormData);
  125. this.dialogVisible = false;
  126. }
  127. this.$emit("input", this.formData);
  128. this.$emit("change", this.formData);
  129. },
  130. // 删除
  131. handleDeleteClick(index) {
  132. this.formData.splice(index, 1);
  133. this.$emit("input", this.formData);
  134. this.$emit("change", this.formData);
  135. }
  136. }
  137. };
  138. </script>
  139. <style lang="scss" scoped>
  140. :deep()::-webkit-scrollbar-track-piece {
  141. background-color: transparent;
  142. }
  143. :deep() .el-table__body-wrapper::-webkit-scrollbar {
  144. width: 0; // 横向滚动条
  145. height: 8px; // 纵向滚动条 必写
  146. }
  147. // 滚动条的滑块
  148. :deep() .el-table__body-wrapper::-webkit-scrollbar-thumb {
  149. border-radius: 5px;
  150. background-color: rgba(144, 146, 152, 0.3);
  151. }
  152. :deep().el-table,
  153. :deep().el-table__expanded-cell,
  154. :deep().el-table th,
  155. :deep().el-table tr {
  156. background-color: transparent !important;
  157. color: #859094 !important;
  158. font-size: 12px !important;
  159. }
  160. :deep().el-table td,
  161. :deep().el-table th.is-leaf {
  162. border-bottom: none;
  163. line-height: 26px;
  164. }
  165. :deep().el-table tbody tr:hover {
  166. background-color: #263445 !important;
  167. }
  168. :deep().el-table tbody tr:hover > td {
  169. background-color: #263445 !important;
  170. }
  171. :deep().el-table::before {
  172. height: 0;
  173. }
  174. .button-group .el-button {
  175. padding: 0;
  176. }
  177. </style>