index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <div class="system-plugin-container">
  3. <el-card shadow="hover">
  4. <div class="system-user-search mb15">
  5. <el-form :model="params" ref="queryRef" :inline="true" label-width="68px">
  6. <el-form-item label="关键字" prop="keyWord">
  7. <el-input v-model="params.keyWord" placeholder="请输入关键字" clearable style="width: 180px" size="default" @keyup.enter="getList" />
  8. </el-form-item>
  9. <el-form-item>
  10. <el-button size="default" type="primary" class="ml10" @click="getList">
  11. <el-icon>
  12. <ele-Search />
  13. </el-icon>
  14. 查询
  15. </el-button>
  16. <el-button size="default" @click="resetQuery()">
  17. <el-icon>
  18. <ele-Refresh />
  19. </el-icon>
  20. 重置
  21. </el-button>
  22. <el-button size="default" type="success" @click="addOrEdit()">
  23. <el-icon>
  24. <ele-Plus />
  25. </el-icon>
  26. 上传插件ZIP
  27. </el-button>
  28. </el-form-item>
  29. </el-form>
  30. </div>
  31. <el-table :data="tableData" style="width: 100%" v-loading="loading">
  32. <el-table-column label="序号" align="center" width="80">
  33. <template #default="{ $index }">{{ params.pageSize * (params.pageNum - 1) + ($index + 1) }} </template>
  34. </el-table-column>
  35. <el-table-column label="名称" v-col="'name'" align="center" prop="name" />
  36. <el-table-column label="通信方式" v-col="'types'" align="center" prop="types" />
  37. <el-table-column label="功能类型" v-col="'handleType'" align="center" prop="handleType" />
  38. <el-table-column label="说明" v-col="'description'" show-overflow-tooltip align="left" prop="description" />
  39. <el-table-column label="作者" v-col="'author'" align="center" prop="author" />
  40. <el-table-column label="状态" v-col="'status'" align="center" prop="status" width="80">
  41. <template #default="scope">
  42. <el-tag type="success" size="small" v-if="scope.row.status === 1">正常</el-tag>
  43. <el-tag type="error" size="small" v-else-if="scope.row.status === 0">停用</el-tag>
  44. <el-tag type="info" size="small" v-else-if="scope.row.status === -1">全部</el-tag>
  45. <el-tag type="info" size="small" v-else>-</el-tag>
  46. </template>
  47. </el-table-column>
  48. <el-table-column label="操作" width="180" align="center" fixed="right" v-col="'handle'">
  49. <template #default="scope">
  50. <el-button :disabled="scope.row.status == 0" type="warning" size="small" link @click="changeStatus(scope.row, 0)" v-auth="'stop'"
  51. >停用</el-button
  52. >
  53. <el-button :disabled="scope.row.status == 1" size="small" type="success" link @click="changeStatus(scope.row, 1)" v-auth="'start'"
  54. >启用</el-button
  55. >
  56. <el-button :disabled="scope.row.status == 1" size="small" type="danger" link @click="onDel(scope.row)" v-auth="'del'">删除</el-button>
  57. <el-button size="small" type="plain" link @click="addOrEdit(scope.row)">编辑</el-button>
  58. </template>
  59. </el-table-column>
  60. </el-table>
  61. <pagination :total="params.total" v-model:page="params.pageNum" v-model:limit="params.pageSize" @pagination="getList" />
  62. </el-card>
  63. <EditForm ref="editFormRef" @getList="getList()"></EditForm>
  64. </div>
  65. </template>
  66. <script lang="ts" setup>
  67. import { ref, h } from 'vue'
  68. import { ElMessage, ElMessageBox, ElUpload } from 'element-plus'
  69. import api from '/@/api/system'
  70. import { useSearch } from '/@/hooks/useCommon'
  71. import EditForm from './edit.vue'
  72. const queryRef = ref()
  73. const editFormRef = ref()
  74. let uploadFile: File | null = null
  75. const { params, tableData, getList, loading } = useSearch(api.plugin.getList, 'list', { keyWord: '' })
  76. getList()
  77. // 添加插件主要是上传编译好插件包,进行上传。
  78. // 在添加窗口中显示:
  79. // 插件名称、插件类型、上传插件包、说明
  80. // 注:按统一的文件目录格式,进行插件文件压缩。并上传到平台后,自动解压的指定的插件目录。
  81. const addOrEdit = (row?: any) => {
  82. // edit
  83. if (row) {
  84. editFormRef.value.open(row)
  85. } else {
  86. // add
  87. ElMessageBox({
  88. title: '上传插件',
  89. message: h('input', {
  90. type: 'file',
  91. accept: '.zip',
  92. onchange: (file: any) => {
  93. uploadFile = file.target.files[0]
  94. // console.log(uploadFile)
  95. },
  96. }),
  97. showCancelButton: true,
  98. confirmButtonText: '上传',
  99. cancelButtonText: '取消',
  100. beforeClose: (action, instance, done) => {
  101. if (action === 'confirm') {
  102. if (!uploadFile) return ElMessage('请先上传插件!')
  103. instance.confirmButtonLoading = true
  104. instance.confirmButtonText = '上传中...'
  105. const formData = new FormData()
  106. formData.append('file', uploadFile)
  107. api.plugin
  108. .addPluginFile(formData)
  109. .then(() => {
  110. ElMessage.success('上传成功')
  111. getList(1)
  112. done()
  113. })
  114. .finally(() => {
  115. instance.confirmButtonLoading = false
  116. })
  117. } else {
  118. done()
  119. }
  120. uploadFile = null
  121. },
  122. })
  123. }
  124. }
  125. const changeStatus = (row: any, status: number) => {
  126. api.plugin.changeStatus({ id: row.id, status: status }).then((res: any) => {
  127. ElMessage.success('操作成功')
  128. getList()
  129. })
  130. }
  131. // 重置表单
  132. const resetQuery = () => {
  133. queryRef.value.resetFields()
  134. getList(1)
  135. }
  136. const onDel = (row: any) => {
  137. ElMessageBox.confirm(`此操作将删除接口:“${row.name}”,是否继续?`, '提示', {
  138. confirmButtonText: '确认',
  139. cancelButtonText: '取消',
  140. type: 'warning',
  141. }).then(async () => {
  142. await api.plugin.del([row.id])
  143. ElMessage.success('删除成功')
  144. getList(1)
  145. })
  146. }
  147. </script>