| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- <script setup lang="ts" name="Group">
- import apis from "@a"
- import message from "@@/utils/message"
- import dayjs from "dayjs"
- const tableRef = ref()
- const modalRef = ref()
- const opts = reactive<any>({
- columns: [
- { field: "id", name: "ID", width: 100, visible: false, isSort: false, tooltip: true },
- { field: "parentId", name: "父ID", width: "auto", isSort: false, visible: true },
- { field: "name", name: "分组名称", width: "auto", isSort: true, visible: true },
- { field: "description", name: "分组描述", width: "auto", isSort: false, visible: true },
- { field: "createdAt", name: "创建时间", width: 185, isSort: true, visible: true },
- { field: "actions", name: `操作`, width: 150 }
- ],
- queryParams: {
- name: undefined,
- description: undefined,
- dateRange: []
- },
- searchFormItems: [
- {
- field: "name",
- label: "分组名称",
- class: "w-100",
- component: "I",
- listeners: {
- keyup: (e: any) => {
- if (e.code == "Enter") {
- handleQuery()
- }
- }
- }
- },
- {
- field: "description",
- label: "分组描述",
- class: "w-100",
- component: "I",
- listeners: {
- keyup: (e: any) => {
- if (e.code == "Enter") {
- handleQuery()
- }
- }
- }
- },
- {
- field: "dateRange",
- label: "创建时间",
- class: "w-100",
- component: "D",
- placeholder: "请选择创建时间",
- props: {
- type: "daterange",
- valueFormat: "YYYY-MM-DD",
- rangeSeparator: "-",
- startPlaceholder: "开始日期",
- endPlaceholder: "结束日期"
- },
- listeners: {
- change: (v: any) => {
- queryParams.value.dateRange = v
- }
- }
- }
- ] as any,
- permission: "iot:group",
- handleFuns: {},
- customBtns: [],
- tableListFun: apis.iot.groupApi.listGroup,
- getEntityFun: apis.iot.groupApi.getGroup,
- deleteEntityFun: apis.iot.groupApi.delGroup,
- formItems: [
- {
- field: "parentId",
- label: "父ID",
- class: "w-100",
- component: "I",
- required: true
- },
- {
- field: "name",
- label: "分组名称",
- class: "w-100",
- component: "I",
- required: true
- },
- {
- field: "description",
- label: "分组描述",
- class: "w-100",
- component: "I",
- required: true
- }
- ] as any,
- resetForm: () => {
- form.value = emptyFormData.value
- },
- emptyFormData: {
- id: undefined,
- parentId: undefined,
- name: undefined,
- description: undefined
- }
- })
- const { queryParams, emptyFormData } = toRefs(opts)
- const form = ref<any>(emptyFormData.value)
- /** 修改按钮操作 */
- function handleUpdate(row: any) {
- tableRef.value.defaultHandleFuns.handleUpdate("", row)
- }
- /** 删除按钮操作 */
- function handleDelete(rows: any[]) {
- tableRef.value.defaultHandleFuns.handleDelete("", rows)
- }
- /** 提交按钮 */
- function submitForm() {
- if (form.value.id != undefined) {
- apis.iot.groupApi.updateGroup(form.value).then(() => {
- message.msgSuccess("修改成功")
- handleQuery()
- })
- } else {
- apis.iot.groupApi.addGroup(form.value).then(() => {
- message.msgSuccess("新增成功")
- handleQuery()
- })
- }
- }
- /** 查询按钮 */
- function handleQuery() {
- addDateRange(queryParams.value, queryParams.value.dateRange)
- tableRef.value?.search()
- }
- /** 查询重置按钮 */
- function resetQuery() {
- queryParams.value.dateRange = []
- addDateRange(queryParams.value, queryParams.value.dateRange)
- }
- function init() {}
- onMounted(init)
- </script>
- <template>
- <div class="app-container">
- <VbDataTable
- ref="tableRef"
- :handle-perm="opts.permission"
- :handle-funs="opts.handleFuns"
- :search-form-items="opts.searchFormItems"
- :columns="opts.columns"
- :custom-btns="opts.customBtns"
- :remote-fun="opts.tableListFun"
- :get-entity-fun="opts.getEntityFun"
- :delete-entity-fun="opts.deleteEntityFun"
- sortField="createdAt"
- sort-order="desc"
- :modal="modalRef"
- :reset-form-fun="opts.resetForm"
- v-model:form-data="form"
- :query-params="queryParams"
- :check-multiple="true"
- :has-checkbox="true"
- :reset-search-form-fun="resetQuery"
- :custom-search-fun="handleQuery">
- <template #createdAt="{ row }">
- <span>{{ dayjs(row.createdAt).format("YYYY-MM-DD HH:mm:ss") }}</span>
- </template>
- <template #actions="{ row }">
- <vb-tooltip content="修改" placement="top">
- <el-button
- link
- type="primary"
- @click="handleUpdate(row)"
- v-hasPermission="'iot:group:edit'">
- <template #icon>
- <VbIcon icon-name="notepad-edit" icon-type="duotone" class="fs-3"></VbIcon>
- </template>
- </el-button>
- </vb-tooltip>
- <vb-tooltip content="删除" placement="top">
- <el-button
- link
- type="primary"
- @click="handleDelete([row])"
- v-hasPermission="'iot:group:remove'">
- <template #icon>
- <VbIcon icon-name="trash-square" icon-type="duotone" class="fs-3"></VbIcon>
- </template>
- </el-button>
- </vb-tooltip>
- </template>
- </VbDataTable>
- <VbModal
- v-model:modal="modalRef"
- :title="opts.modalTitle"
- :form-items="opts.formItems as any"
- :form-data="form"
- @confirm="submitForm"
- append-to-body></VbModal>
- </div>
- </template>
|