index.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <template>
  2. <!-- 搜索工作栏 -->
  3. <ContentWrap>
  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" label-width="100px">
  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" label-width="100px">
  21. <el-select
  22. v-model="queryParams.status"
  23. placeholder="请选择编码分类状态"
  24. clearable
  25. class="!w-240px"
  26. >
  27. <el-option
  28. v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
  29. :key="dict.value"
  30. :label="dict.label"
  31. :value="dict.value"
  32. />
  33. </el-select>
  34. </el-form-item>
  35. <el-form-item>
  36. <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
  37. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  38. <el-button
  39. type="primary"
  40. plain
  41. @click="openForm('create')"
  42. v-hasPermi="['iot:product-classify:create']"
  43. >
  44. <Icon icon="ep:plus" class="mr-5px" /> 新增
  45. </el-button>
  46. <el-button type="danger" plain @click="toggleExpandAll">
  47. <Icon icon="ep:sort" class="mr-5px" /> 展开/折叠
  48. </el-button>
  49. </el-form-item>
  50. </el-form>
  51. </ContentWrap>
  52. <!-- 列表 -->
  53. <ContentWrap>
  54. <el-table
  55. v-loading="loading"
  56. :data="list"
  57. row-key="id"
  58. :default-expand-all="isExpandAll"
  59. v-if="refreshTable"
  60. @row-click="handleClick"
  61. >
  62. <el-table-column prop="name" label="编码分类名称" />
  63. <el-table-column prop="code" label="编码分类编码" />
  64. <el-table-column prop="sort" label="排序" />
  65. <el-table-column prop="status" label="状态">
  66. <template #default="scope">
  67. <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
  68. </template>
  69. </el-table-column>
  70. <el-table-column prop="remark" label="备注" />
  71. <el-table-column
  72. label="创建时间"
  73. align="center"
  74. prop="createTime"
  75. width="180"
  76. :formatter="dateFormatter"
  77. />
  78. <el-table-column label="操作" align="center">
  79. <template #default="scope">
  80. <el-button
  81. link
  82. type="primary"
  83. @click="openForm('update', scope.row.id)"
  84. v-hasPermi="['iot:product-classify:update']"
  85. >
  86. 修改
  87. </el-button>
  88. <el-button
  89. link
  90. type="danger"
  91. @click="handleDelete(scope.row.id)"
  92. v-hasPermi="['iot:product-classify:delete']"
  93. >
  94. 删除
  95. </el-button>
  96. </template>
  97. </el-table-column>
  98. </el-table>
  99. </ContentWrap>
  100. <!-- 表单弹窗:添加/修改 -->
  101. <YfClassifyForm ref="formRef" @success="getList" />
  102. </template>
  103. <script lang="ts" setup>
  104. import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  105. import { dateFormatter } from '@/utils/formatTime'
  106. import { handleTree } from '@/utils/tree'
  107. import * as YfClassifyApi from '@/api/pms/yfclass'
  108. import YfClassifyForm from './YfClassifyForm.vue'
  109. import {IotYfClassifyApi} from "@/api/pms/yfclass";
  110. defineOptions({ name: 'IotProductClassify' })
  111. const message = useMessage() // 消息弹窗
  112. const { t } = useI18n() // 国际化
  113. const loading = ref(true) // 列表的加载中
  114. const list = ref() // 列表的数据
  115. const queryParams = reactive({
  116. pageNo: 1,
  117. pageSize: 100,
  118. name: undefined,
  119. status: undefined
  120. })
  121. const queryFormRef = ref() // 搜索的表单
  122. const isExpandAll = ref(true) // 是否展开,默认全部展开
  123. const refreshTable = ref(true) // 重新渲染表格状态
  124. const parentId = ref('')
  125. const handleClick = (node: {}) => {
  126. parentId.value = node.id
  127. }
  128. /** 查询编码分类列表 */
  129. const getList = async () => {
  130. loading.value = true
  131. try {
  132. const data = await YfClassifyApi.IotYfClassifyApi.getIotYfClassifyPage(queryParams)
  133. list.value = handleTree(data)
  134. } finally {
  135. loading.value = false
  136. }
  137. }
  138. /** 展开/折叠操作 */
  139. const toggleExpandAll = () => {
  140. refreshTable.value = false
  141. isExpandAll.value = !isExpandAll.value
  142. nextTick(() => {
  143. refreshTable.value = true
  144. })
  145. }
  146. /** 搜索按钮操作 */
  147. const handleQuery = () => {
  148. getList()
  149. }
  150. /** 重置按钮操作 */
  151. const resetQuery = () => {
  152. queryParams.pageNo = 1
  153. queryFormRef.value.resetFields()
  154. handleQuery()
  155. }
  156. /** 添加/修改操作 */
  157. const formRef = ref()
  158. const openForm = (type: string, id?: number, parent: number) => {
  159. parent = parentId.value
  160. formRef.value.open(type, id, parent)
  161. }
  162. /** 删除按钮操作 */
  163. const handleDelete = async (id: number) => {
  164. try {
  165. // 删除的二次确认
  166. await message.delConfirm()
  167. // 发起删除
  168. await IotYfClassifyApi.deleteIotYfClassify(id)
  169. message.success(t('common.delSuccess'))
  170. // 刷新列表
  171. await getList()
  172. } catch {}
  173. }
  174. /** 初始化 **/
  175. onMounted(async () => {
  176. await getList()
  177. // 获取用户列表
  178. //userList.value = await UserApi.getSimpleUserList()
  179. })
  180. </script>
  181. <style scoped>
  182. /* 全局样式或 scoped 穿透 */
  183. :deep(.el-table__body tr) {
  184. cursor: pointer; /* 手型光标 */
  185. }
  186. :deep(.el-table__body tr:hover) {
  187. cursor: pointer;
  188. }
  189. </style>