index.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <template>
  2. <ContentWrap>
  3. <!-- 搜索工作栏 -->
  4. <el-form
  5. class="-mb-15px"
  6. :model="queryParams"
  7. ref="queryFormRef"
  8. :inline="true"
  9. label-width="68px"
  10. >
  11. <el-form-item label="工具名称" prop="name">
  12. <el-input
  13. v-model="queryParams.name"
  14. placeholder="请输入工具名称"
  15. clearable
  16. @keyup.enter="handleQuery"
  17. class="!w-240px"
  18. />
  19. </el-form-item>
  20. <el-form-item label="状态" prop="status">
  21. <el-select v-model="queryParams.status" placeholder="请选择状态" clearable class="!w-240px">
  22. <el-option
  23. v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
  24. :key="dict.value"
  25. :label="dict.label"
  26. :value="dict.value"
  27. />
  28. </el-select>
  29. </el-form-item>
  30. <el-form-item label="创建时间" prop="createTime">
  31. <el-date-picker
  32. v-model="queryParams.createTime"
  33. value-format="YYYY-MM-DD HH:mm:ss"
  34. type="daterange"
  35. start-placeholder="开始日期"
  36. end-placeholder="结束日期"
  37. :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
  38. class="!w-220px"
  39. />
  40. </el-form-item>
  41. <el-form-item>
  42. <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
  43. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  44. <el-button type="primary" plain @click="openForm('create')" v-hasPermi="['ai:tool:create']">
  45. <Icon icon="ep:plus" class="mr-5px" /> 新增
  46. </el-button>
  47. </el-form-item>
  48. </el-form>
  49. </ContentWrap>
  50. <!-- 列表 -->
  51. <ContentWrap>
  52. <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
  53. <el-table-column label="工具编号" align="center" prop="id" />
  54. <el-table-column label="工具名称" align="center" prop="name" />
  55. <el-table-column label="工具描述" align="center" prop="description" />
  56. <el-table-column label="状态" align="center" prop="status">
  57. <template #default="scope">
  58. <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
  59. </template>
  60. </el-table-column>
  61. <el-table-column
  62. label="创建时间"
  63. align="center"
  64. prop="createTime"
  65. :formatter="dateFormatter"
  66. width="180px"
  67. />
  68. <el-table-column label="操作" align="center" min-width="120px">
  69. <template #default="scope">
  70. <el-button
  71. link
  72. type="primary"
  73. v-if="scope.row.tenantId == getTenantId()"
  74. @click="openForm('update', scope.row.id)"
  75. v-hasPermi="['ai:tool:update']"
  76. >
  77. 编辑
  78. </el-button>
  79. <el-button
  80. link
  81. type="danger"
  82. v-if="scope.row.tenantId == getTenantId()"
  83. @click="handleDelete(scope.row.id)"
  84. v-hasPermi="['ai:tool:delete']"
  85. >
  86. 删除
  87. </el-button>
  88. </template>
  89. </el-table-column>
  90. </el-table>
  91. <!-- 分页 -->
  92. <Pagination
  93. :total="total"
  94. v-model:page="queryParams.pageNo"
  95. v-model:limit="queryParams.pageSize"
  96. @pagination="getList"
  97. />
  98. </ContentWrap>
  99. <!-- 表单弹窗:添加/修改 -->
  100. <ToolForm ref="formRef" @success="getList" />
  101. </template>
  102. <script setup lang="ts">
  103. import { getIntDictOptions, DICT_TYPE } from '@/utils/dict'
  104. import { dateFormatter } from '@/utils/formatTime'
  105. import { ToolApi, ToolVO } from '@/api/ai/model/tool'
  106. import ToolForm from './ToolForm.vue'
  107. import { getTenantId } from '@/utils/auth'
  108. import { ElButton } from 'element-plus'
  109. /** AI 工具 列表 */
  110. defineOptions({ name: 'AiTool' })
  111. const message = useMessage() // 消息弹窗
  112. const { t } = useI18n() // 国际化
  113. const loading = ref(true) // 列表的加载中
  114. const list = ref<ToolVO[]>([]) // 列表的数据
  115. const total = ref(0) // 列表的总页数
  116. const queryParams = reactive({
  117. pageNo: 1,
  118. pageSize: 10,
  119. name: undefined,
  120. description: undefined,
  121. status: undefined,
  122. createTime: []
  123. })
  124. const queryFormRef = ref() // 搜索的表单
  125. const exportLoading = ref(false) // 导出的加载中
  126. /** 查询列表 */
  127. const getList = async () => {
  128. loading.value = true
  129. try {
  130. const data = await ToolApi.getToolPage(queryParams)
  131. list.value = data.list
  132. total.value = data.total
  133. } finally {
  134. loading.value = false
  135. }
  136. }
  137. /** 搜索按钮操作 */
  138. const handleQuery = () => {
  139. queryParams.pageNo = 1
  140. getList()
  141. }
  142. /** 重置按钮操作 */
  143. const resetQuery = () => {
  144. queryFormRef.value.resetFields()
  145. handleQuery()
  146. }
  147. /** 添加/修改操作 */
  148. const formRef = ref()
  149. const openForm = (type: string, id?: number) => {
  150. formRef.value.open(type, id)
  151. }
  152. /** 删除按钮操作 */
  153. const handleDelete = async (id: number) => {
  154. try {
  155. // 删除的二次确认
  156. await message.delConfirm()
  157. // 发起删除
  158. await ToolApi.deleteTool(id)
  159. message.success(t('common.delSuccess'))
  160. // 刷新列表
  161. await getList()
  162. } catch {}
  163. }
  164. /** 初始化 **/
  165. onMounted(() => {
  166. getList()
  167. })
  168. </script>