index.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <template>
  2. <div class="app-container">
  3. <!-- 搜索表单 -->
  4. <el-form inline label-width="100px" size="mini" @submit.native.prevent>
  5. <el-form-item label="设备名称:">
  6. <el-input v-model="form.name" placeholder="请输入设备名称" clearable />
  7. </el-form-item>
  8. <el-form-item>
  9. <el-button type="primary" icon="el-icon-search" @click="getSearch">搜索</el-button>
  10. <el-button icon="el-icon-refresh" @click="getRefresh">重置</el-button>
  11. <el-button type="primary" icon="el-icon-plus" plain @click="getChange()">新增</el-button>
  12. </el-form-item>
  13. </el-form>
  14. <!-- 表格 -->
  15. <el-table :data="tableData" v-loading="loading">
  16. <el-table-column label="设备ID" prop="id" align="center" />
  17. <el-table-column label="设备型号" prop="clientType" align="center" />
  18. <el-table-column label="设备名称" prop="name" align="center" />
  19. <el-table-column label="设备图片" prop="img" align="center" width="100">
  20. <template slot-scope="scope">
  21. <el-image :src="scope.row.img" :preview-src-list="[scope.row.img]" />
  22. </template>
  23. </el-table-column>
  24. <el-table-column label="使用分类" prop="deviceType" align="center" :formatter="deviceTypeFormatter" />
  25. <el-table-column label="升级方式" prop="upgradeTypeText" align="center" />
  26. <el-table-column label="创建时间" prop="createTimeText" align="center" />
  27. <el-table-column label="操作" align="center">
  28. <template slot-scope="scope">
  29. <el-button type="text" @click="getChange(scope.row.id, '查看')">查看</el-button>
  30. <el-button type="text" @click="getChange(scope.row.id)">编辑</el-button>
  31. <el-button type="delete" @click="getDelete(scope.row.id)">删除</el-button>
  32. </template>
  33. </el-table-column>
  34. </el-table>
  35. <pagination v-show="total>0" :total="total" :page.sync="form.pageNum" :limit.sync="form.pageSize"
  36. @pagination="getList" />
  37. </div>
  38. </template>
  39. <script>
  40. import { listPage, deviceDelete } from '@/api/device/list'
  41. import mixin from './mixin/index'
  42. export default {
  43. mixins: [mixin],
  44. data() {
  45. return {
  46. // 遮罩层
  47. loading: true,
  48. // 表格
  49. tableData: [],
  50. // 总数据
  51. total: 0,
  52. // 表单
  53. form: {
  54. name: '',
  55. pageNum: 1,
  56. pageSize: 10
  57. }
  58. }
  59. },
  60. mounted() {
  61. this.getList()
  62. },
  63. methods: {
  64. // 列表
  65. getList() {
  66. this.loading = true
  67. listPage(this.form).then(res => {
  68. this.tableData = res.data.records
  69. this.total = res.data.total
  70. this.loading = false
  71. })
  72. },
  73. // 搜索
  74. getSearch() {
  75. this.form.pageNum = 1
  76. this.form.pageSize = 10
  77. this.getList()
  78. },
  79. // 重置
  80. getRefresh() {
  81. this.form = {
  82. name: '',
  83. pageNum: 1,
  84. pageSize: 10
  85. }
  86. this.getList()
  87. },
  88. // 新增 / 编辑 / 查看
  89. getChange(id, key) {
  90. this.$router.push({
  91. path: `/device/list/detail`,
  92. query: {
  93. id: id,
  94. key: key
  95. }
  96. })
  97. },
  98. // 删除
  99. getDelete(id) {
  100. this.$confirm('确定要删除?', {
  101. type: 'warning'
  102. }).then(() => {
  103. deviceDelete(id).then(res => {
  104. if (res.data.code === 0) {
  105. this.getList()
  106. this.$message.success('删除成功!')
  107. }
  108. })
  109. }).catch(() => { })
  110. },
  111. // 字典翻译
  112. deviceTypeFormatter(row) {
  113. return this.selectDictLabel(this.deviceTypeOptions, row.deviceType);
  114. }
  115. }
  116. }
  117. </script>
  118. <style lang="scss" scoped>
  119. </style>