index.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <script setup lang="ts" name="Group">
  2. import apis from "@a"
  3. import message from "@@/utils/message"
  4. import dayjs from "dayjs"
  5. const tableRef = ref()
  6. const modalRef = ref()
  7. const opts = reactive<any>({
  8. columns: [
  9. { field: "id", name: "ID", width: 100, visible: false, isSort: false, tooltip: true },
  10. { field: "parentId", name: "父ID", width: "auto", isSort: false, visible: true },
  11. { field: "name", name: "分组名称", width: "auto", isSort: true, visible: true },
  12. { field: "description", name: "分组描述", width: "auto", isSort: false, visible: true },
  13. { field: "createdAt", name: "创建时间", width: 185, isSort: true, visible: true },
  14. { field: "actions", name: `操作`, width: 150 }
  15. ],
  16. queryParams: {
  17. name: undefined,
  18. description: undefined,
  19. dateRange: []
  20. },
  21. searchFormItems: [
  22. {
  23. field: "name",
  24. label: "分组名称",
  25. class: "w-100",
  26. component: "I",
  27. listeners: {
  28. keyup: (e: any) => {
  29. if (e.code == "Enter") {
  30. handleQuery()
  31. }
  32. }
  33. }
  34. },
  35. {
  36. field: "description",
  37. label: "分组描述",
  38. class: "w-100",
  39. component: "I",
  40. listeners: {
  41. keyup: (e: any) => {
  42. if (e.code == "Enter") {
  43. handleQuery()
  44. }
  45. }
  46. }
  47. },
  48. {
  49. field: "dateRange",
  50. label: "创建时间",
  51. class: "w-100",
  52. component: "D",
  53. placeholder: "请选择创建时间",
  54. props: {
  55. type: "daterange",
  56. valueFormat: "YYYY-MM-DD",
  57. rangeSeparator: "-",
  58. startPlaceholder: "开始日期",
  59. endPlaceholder: "结束日期"
  60. },
  61. listeners: {
  62. change: (v: any) => {
  63. queryParams.value.dateRange = v
  64. }
  65. }
  66. }
  67. ] as any,
  68. permission: "iot:group",
  69. handleFuns: {},
  70. customBtns: [],
  71. tableListFun: apis.iot.groupApi.listGroup,
  72. getEntityFun: apis.iot.groupApi.getGroup,
  73. deleteEntityFun: apis.iot.groupApi.delGroup,
  74. formItems: [
  75. {
  76. field: "parentId",
  77. label: "父ID",
  78. class: "w-100",
  79. component: "I",
  80. required: true
  81. },
  82. {
  83. field: "name",
  84. label: "分组名称",
  85. class: "w-100",
  86. component: "I",
  87. required: true
  88. },
  89. {
  90. field: "description",
  91. label: "分组描述",
  92. class: "w-100",
  93. component: "I",
  94. required: true
  95. }
  96. ] as any,
  97. resetForm: () => {
  98. form.value = emptyFormData.value
  99. },
  100. emptyFormData: {
  101. id: undefined,
  102. parentId: undefined,
  103. name: undefined,
  104. description: undefined
  105. }
  106. })
  107. const { queryParams, emptyFormData } = toRefs(opts)
  108. const form = ref<any>(emptyFormData.value)
  109. /** 修改按钮操作 */
  110. function handleUpdate(row: any) {
  111. tableRef.value.defaultHandleFuns.handleUpdate("", row)
  112. }
  113. /** 删除按钮操作 */
  114. function handleDelete(rows: any[]) {
  115. tableRef.value.defaultHandleFuns.handleDelete("", rows)
  116. }
  117. /** 提交按钮 */
  118. function submitForm() {
  119. if (form.value.id != undefined) {
  120. apis.iot.groupApi.updateGroup(form.value).then(() => {
  121. message.msgSuccess("修改成功")
  122. handleQuery()
  123. })
  124. } else {
  125. apis.iot.groupApi.addGroup(form.value).then(() => {
  126. message.msgSuccess("新增成功")
  127. handleQuery()
  128. })
  129. }
  130. }
  131. /** 查询按钮 */
  132. function handleQuery() {
  133. addDateRange(queryParams.value, queryParams.value.dateRange)
  134. tableRef.value?.search()
  135. }
  136. /** 查询重置按钮 */
  137. function resetQuery() {
  138. queryParams.value.dateRange = []
  139. addDateRange(queryParams.value, queryParams.value.dateRange)
  140. }
  141. function init() {}
  142. onMounted(init)
  143. </script>
  144. <template>
  145. <div class="app-container">
  146. <VbDataTable
  147. ref="tableRef"
  148. :handle-perm="opts.permission"
  149. :handle-funs="opts.handleFuns"
  150. :search-form-items="opts.searchFormItems"
  151. :columns="opts.columns"
  152. :custom-btns="opts.customBtns"
  153. :remote-fun="opts.tableListFun"
  154. :get-entity-fun="opts.getEntityFun"
  155. :delete-entity-fun="opts.deleteEntityFun"
  156. sortField="createdAt"
  157. sort-order="desc"
  158. :modal="modalRef"
  159. :reset-form-fun="opts.resetForm"
  160. v-model:form-data="form"
  161. :query-params="queryParams"
  162. :check-multiple="true"
  163. :has-checkbox="true"
  164. :reset-search-form-fun="resetQuery"
  165. :custom-search-fun="handleQuery">
  166. <template #createdAt="{ row }">
  167. <span>{{ dayjs(row.createdAt).format("YYYY-MM-DD HH:mm:ss") }}</span>
  168. </template>
  169. <template #actions="{ row }">
  170. <vb-tooltip content="修改" placement="top">
  171. <el-button
  172. link
  173. type="primary"
  174. @click="handleUpdate(row)"
  175. v-hasPermission="'iot:group:edit'">
  176. <template #icon>
  177. <VbIcon icon-name="notepad-edit" icon-type="duotone" class="fs-3"></VbIcon>
  178. </template>
  179. </el-button>
  180. </vb-tooltip>
  181. <vb-tooltip content="删除" placement="top">
  182. <el-button
  183. link
  184. type="primary"
  185. @click="handleDelete([row])"
  186. v-hasPermission="'iot:group:remove'">
  187. <template #icon>
  188. <VbIcon icon-name="trash-square" icon-type="duotone" class="fs-3"></VbIcon>
  189. </template>
  190. </el-button>
  191. </vb-tooltip>
  192. </template>
  193. </VbDataTable>
  194. <VbModal
  195. v-model:modal="modalRef"
  196. :title="opts.modalTitle"
  197. :form-items="opts.formItems as any"
  198. :form-data="form"
  199. @confirm="submitForm"
  200. append-to-body></VbModal>
  201. </div>
  202. </template>