index.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <el-card shadow="nover" class="page">
  3. <div class="search">
  4. <el-form :model="params" inline ref="queryRef">
  5. <el-form-item label="应用名称:" prop="keyWord" @submit.prevent>
  6. <el-input v-model="params.keyWord" placeholder="请输入应用名称" clearable style="width: 240px" @keyup.enter.native="getList(1)" />
  7. </el-form-item>
  8. <el-form-item>
  9. <el-button type="primary" class="ml10" @click="getList(1)">
  10. <el-icon>
  11. <ele-Search />
  12. </el-icon>
  13. 查询
  14. </el-button>
  15. <el-button @click="resetQuery(queryRef)">
  16. <el-icon>
  17. <ele-Refresh />
  18. </el-icon>
  19. 重置
  20. </el-button>
  21. <el-button type="primary" v-auth="'add'" @click="addOrEdit()">
  22. <el-icon>
  23. <ele-FolderAdd />
  24. </el-icon>
  25. 添加应用
  26. </el-button>
  27. </el-form-item>
  28. </el-form>
  29. </div>
  30. <el-table :data="tableData" style="width: 100%" row-key="id" v-loading="loading">
  31. <el-table-column prop="id" label="ID" width="100" show-overflow-tooltip v-col="'id'"></el-table-column>
  32. <el-table-column prop="appId" label="应用标识" show-overflow-tooltip v-col="'appId'"></el-table-column>
  33. <el-table-column prop="name" label="应用名称" show-overflow-tooltip v-col="'name'"></el-table-column>
  34. <el-table-column prop="desc" label="描述" show-overflow-tooltip v-col="'desc'"></el-table-column>
  35. <el-table-column prop="status" label="应用状态" width="80" align="center" v-col="'status'">
  36. <template #default="scope">
  37. <el-tag size="small" type="success" v-if="scope.row.status == 1">启用</el-tag>
  38. <el-tag size="small" type="info" v-if="scope.row.status == 0">未启用</el-tag>
  39. </template>
  40. </el-table-column>
  41. <el-table-column prop="createdAt" label="创建时间" width="160" align="center" v-col="'createdAt'"></el-table-column>
  42. <el-table-column label="操作" width="200" align="center">
  43. <template #default="scope">
  44. <el-button size="small" text type="success" @click="onActionStatus(scope.row)" v-if="scope.row.status == 0" v-auth="'startOrStop'">启用</el-button>
  45. <el-button size="small" text type="primary" @click="onActionStatus(scope.row)" v-if="scope.row.status > 0" v-auth="'startOrStop'">停用</el-button>
  46. <el-button size="small" text type="warning" v-auth="'edit'" @click="addOrEdit(scope.row)">编辑</el-button>
  47. <el-button size="small" text type="danger" v-auth="'del'" @click="del(scope.row)">删除</el-button>
  48. </template>
  49. </el-table-column>
  50. </el-table>
  51. <pagination v-if="params.total" :total="params.total" v-model:page="params.pageNum" v-model:limit="params.pageSize" @pagination="getList()" />
  52. <EditForm ref="editFormRef" :deptData="deptData" @getList="getList(1)"></EditForm>
  53. </el-card>
  54. </template>
  55. <script lang="ts" setup>
  56. import { ElMessageBox, ElMessage } from 'element-plus'
  57. import EditForm from './edit.vue'
  58. import { ref } from 'vue'
  59. import api from '/@/api/application'
  60. import user from '/@/api/system';
  61. import { useSearch } from '/@/hooks/useCommon'
  62. const queryRef = ref()
  63. const deptData = ref([])
  64. const editFormRef = ref()
  65. const { params, tableData, getList, loading } = useSearch<any[]>(api.getList, 'Data', { keyWord: '' })
  66. getList()
  67. /** 重置按钮操作 */
  68. const resetQuery = (formEl: any) => {
  69. if (!formEl) return;
  70. formEl.resetFields();
  71. getList(1);
  72. };
  73. const initTableData = () => {
  74. user.dept.getList({ status: 1 }).then((res: any) => {
  75. deptData.value = res;
  76. });
  77. };
  78. initTableData();
  79. const onActionStatus = (item: any) => {
  80. if (item.status == 0) {
  81. api.status({ id: item.id, status: 1 }).then((res: any) => {
  82. getList();
  83. ElMessage.success(res.message || '操作成功');
  84. });
  85. } else {
  86. api.status({ id: item.id, status: 0 }).then((res: any) => {
  87. getList();
  88. ElMessage.success(res.message || '操作成功');
  89. });
  90. }
  91. }
  92. const addOrEdit = async (row?: any) => {
  93. if (row) {
  94. editFormRef.value.open(row)
  95. return
  96. } else {
  97. editFormRef.value.open()
  98. }
  99. }
  100. const del = (row: any) => {
  101. ElMessageBox.confirm(`此操作将删除应用:“${row.name}”,是否继续?`, '提示', {
  102. confirmButtonText: '确认',
  103. cancelButtonText: '取消',
  104. type: 'warning',
  105. }).then(async () => {
  106. await api.del(row.id)
  107. ElMessage.success('删除成功')
  108. getList()
  109. })
  110. }
  111. </script>