index.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <div class="app-container">
  3. <el-button type="primary" size="mini" icon="el-icon-plus" style="margin-bottom: 10px;" @click="onTableAdd">新增模板组</el-button>
  4. <el-table
  5. :data="tableData"
  6. border
  7. highlight-current-row
  8. >
  9. <el-table-column
  10. prop="groupName"
  11. label="模板组名称"
  12. />
  13. <el-table-column
  14. label="操作"
  15. >
  16. <template slot-scope="scope">
  17. <el-button type="text" size="mini" @click="onSelectTemplate(scope.row)">查看模板</el-button>
  18. <el-button type="text" size="mini" @click="onTableUpdate(scope.row)">修改</el-button>
  19. <el-button type="text" size="mini" @click="onTableDelete(scope.row)">删除</el-button>
  20. </template>
  21. </el-table-column>
  22. </el-table>
  23. <el-dialog
  24. :title="groupTitle"
  25. :visible.sync="groupDlgShow"
  26. >
  27. <el-form
  28. ref="dialogForm"
  29. :model="formData"
  30. :rules="formRules"
  31. size="mini"
  32. label-width="120px"
  33. >
  34. <el-form-item prop="name" label="模板组名称">
  35. <el-input v-model="formData.groupName" show-word-limit maxlength="100" />
  36. </el-form-item>
  37. <el-form-item>
  38. <el-button type="primary" @click="onSave">保 存</el-button>
  39. </el-form-item>
  40. </el-form>
  41. </el-dialog>
  42. </div>
  43. </template>
  44. <script>
  45. export default {
  46. data() {
  47. return {
  48. tableData: [],
  49. groupTitle: '',
  50. groupDlgShow: false,
  51. formData: {
  52. id: 0,
  53. groupName: ''
  54. },
  55. formRules: {
  56. groupName: [
  57. { required: true, message: '不能为空', trigger: 'blur' }
  58. ]
  59. }
  60. }
  61. },
  62. created() {
  63. this.loadTable()
  64. },
  65. methods: {
  66. loadTable: function() {
  67. this.post('/group/list', {}, function(resp) {
  68. this.tableData = resp.data
  69. })
  70. },
  71. onTableAdd: function(row) {
  72. this.groupTitle = '增加模板组'
  73. this.formData = {
  74. id: 0,
  75. groupName: ''
  76. }
  77. this.groupDlgShow = true
  78. },
  79. onTableUpdate: function(row) {
  80. this.groupTitle = '修改模板组'
  81. this.post(`/group/get/${row.id}`, {}, function(resp) {
  82. this.formData = resp.data
  83. })
  84. this.groupDlgShow = true
  85. },
  86. onTableDelete: function(row) {
  87. this.confirm(`确认要删除【${row.groupName}】吗?`, function(done) {
  88. this.post('/group/del', row, function() {
  89. done()
  90. this.tip('删除成功')
  91. this.loadTable()
  92. })
  93. })
  94. },
  95. onAdd: function() {
  96. this.goRoute('edit/0')
  97. },
  98. onSelectTemplate: function (row){
  99. this.goRoute(`/template/list?groupId=${row.id}`)
  100. },
  101. onSave() {
  102. this.$refs.dialogForm.validate((valid) => {
  103. if (valid) {
  104. console.log(this.formData.id)
  105. const opt = this.formData.id ? 'update' : 'add'
  106. console.log(opt)
  107. const uri = `/group/${opt}`
  108. this.post(uri, this.formData, resp => {
  109. if (opt === 'add') {
  110. this.formData.id = resp.data.id
  111. }
  112. this.tip('保存成功')
  113. this.loadTable()
  114. this.groupDlgShow = false
  115. })
  116. }
  117. })
  118. }
  119. }
  120. }
  121. </script>