提交 | 用户 | 时间
|
820397
|
1 |
<template> |
H |
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="createTime"> |
|
21 |
<el-date-picker |
|
22 |
v-model="queryParams.createTime" |
|
23 |
value-format="YYYY-MM-DD HH:mm:ss" |
|
24 |
type="daterange" |
|
25 |
start-placeholder="开始日期" |
|
26 |
end-placeholder="结束日期" |
|
27 |
:default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]" |
|
28 |
class="!w-240px" |
|
29 |
/> |
|
30 |
</el-form-item> |
|
31 |
<el-form-item> |
|
32 |
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button> |
|
33 |
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button> |
|
34 |
<el-button |
|
35 |
type="primary" |
|
36 |
plain |
|
37 |
@click="openForm('create')" |
|
38 |
v-hasPermi="['infra:demo02-category:create']" |
|
39 |
> |
|
40 |
<Icon icon="ep:plus" class="mr-5px" /> 新增 |
|
41 |
</el-button> |
|
42 |
<el-button |
|
43 |
type="success" |
|
44 |
plain |
|
45 |
@click="handleExport" |
|
46 |
:loading="exportLoading" |
|
47 |
v-hasPermi="['infra:demo02-category:export']" |
|
48 |
> |
|
49 |
<Icon icon="ep:download" class="mr-5px" /> 导出 |
|
50 |
</el-button> |
|
51 |
<el-button type="danger" plain @click="toggleExpandAll"> |
|
52 |
<Icon icon="ep:sort" class="mr-5px" /> 展开/折叠 |
|
53 |
</el-button> |
|
54 |
</el-form-item> |
|
55 |
</el-form> |
|
56 |
</ContentWrap> |
|
57 |
|
|
58 |
<!-- 列表 --> |
|
59 |
<ContentWrap> |
|
60 |
<el-table |
|
61 |
v-loading="loading" |
|
62 |
:data="list" |
|
63 |
:stripe="true" |
|
64 |
:show-overflow-tooltip="true" |
|
65 |
row-key="id" |
|
66 |
:default-expand-all="isExpandAll" |
|
67 |
v-if="refreshTable" |
|
68 |
> |
|
69 |
<el-table-column label="编号" align="center" prop="id" /> |
|
70 |
<el-table-column label="名字" align="center" prop="name" /> |
|
71 |
<el-table-column |
|
72 |
label="创建时间" |
|
73 |
align="center" |
|
74 |
prop="createTime" |
|
75 |
:formatter="dateFormatter" |
|
76 |
width="180px" |
|
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="['infra:demo02-category:update']" |
|
85 |
> |
|
86 |
编辑 |
|
87 |
</el-button> |
|
88 |
<el-button |
|
89 |
link |
|
90 |
type="danger" |
|
91 |
@click="handleDelete(scope.row.id)" |
|
92 |
v-hasPermi="['infra:demo02-category:delete']" |
|
93 |
> |
|
94 |
删除 |
|
95 |
</el-button> |
|
96 |
</template> |
|
97 |
</el-table-column> |
|
98 |
</el-table> |
|
99 |
<!-- 分页 --> |
|
100 |
<Pagination |
|
101 |
:total="total" |
|
102 |
v-model:page="queryParams.pageNo" |
|
103 |
v-model:limit="queryParams.pageSize" |
|
104 |
@pagination="getList" |
|
105 |
/> |
|
106 |
</ContentWrap> |
|
107 |
|
|
108 |
<!-- 表单弹窗:添加/修改 --> |
|
109 |
<Demo02CategoryForm ref="formRef" @success="getList" /> |
|
110 |
</template> |
|
111 |
|
|
112 |
<script setup lang="ts"> |
|
113 |
import { dateFormatter } from '@/utils/formatTime' |
|
114 |
import { handleTree } from '@/utils/tree' |
|
115 |
import download from '@/utils/download' |
|
116 |
import * as Demo02CategoryApi from '@/api/infra/demo/demo02' |
|
117 |
import Demo02CategoryForm from './Demo02CategoryForm.vue' |
|
118 |
|
|
119 |
defineOptions({ name: 'Demo02Category' }) |
|
120 |
|
|
121 |
const message = useMessage() // 消息弹窗 |
|
122 |
const { t } = useI18n() // 国际化 |
|
123 |
|
|
124 |
const loading = ref(true) // 列表的加载中 |
|
125 |
const list = ref([]) // 列表的数据 |
|
126 |
const queryParams = reactive({ |
|
127 |
name: null, |
|
128 |
parentId: null, |
|
129 |
createTime: [] |
|
130 |
}) |
|
131 |
const queryFormRef = ref() // 搜索的表单 |
|
132 |
const exportLoading = ref(false) // 导出的加载中 |
|
133 |
|
|
134 |
/** 查询列表 */ |
|
135 |
const getList = async () => { |
|
136 |
loading.value = true |
|
137 |
try { |
|
138 |
const data = await Demo02CategoryApi.getDemo02CategoryList(queryParams) |
|
139 |
list.value = handleTree(data, 'id', 'parentId') |
|
140 |
} finally { |
|
141 |
loading.value = false |
|
142 |
} |
|
143 |
} |
|
144 |
|
|
145 |
/** 搜索按钮操作 */ |
|
146 |
const handleQuery = () => { |
|
147 |
queryParams.pageNo = 1 |
|
148 |
getList() |
|
149 |
} |
|
150 |
|
|
151 |
/** 重置按钮操作 */ |
|
152 |
const resetQuery = () => { |
|
153 |
queryFormRef.value.resetFields() |
|
154 |
handleQuery() |
|
155 |
} |
|
156 |
|
|
157 |
/** 添加/修改操作 */ |
|
158 |
const formRef = ref() |
|
159 |
const openForm = (type: string, id?: number) => { |
|
160 |
formRef.value.open(type, id) |
|
161 |
} |
|
162 |
|
|
163 |
/** 删除按钮操作 */ |
|
164 |
const handleDelete = async (id: number) => { |
|
165 |
try { |
|
166 |
// 删除的二次确认 |
|
167 |
await message.delConfirm() |
|
168 |
// 发起删除 |
|
169 |
await Demo02CategoryApi.deleteDemo02Category(id) |
|
170 |
message.success(t('common.delSuccess')) |
|
171 |
// 刷新列表 |
|
172 |
await getList() |
|
173 |
} catch {} |
|
174 |
} |
|
175 |
|
|
176 |
/** 导出按钮操作 */ |
|
177 |
const handleExport = async () => { |
|
178 |
try { |
|
179 |
// 导出的二次确认 |
|
180 |
await message.exportConfirm() |
|
181 |
// 发起导出 |
|
182 |
exportLoading.value = true |
|
183 |
const data = await Demo02CategoryApi.exportDemo02Category(queryParams) |
|
184 |
download.excel(data, '示例分类.xls') |
|
185 |
} catch { |
|
186 |
} finally { |
|
187 |
exportLoading.value = false |
|
188 |
} |
|
189 |
} |
|
190 |
|
|
191 |
/** 展开/折叠操作 */ |
|
192 |
const isExpandAll = ref(true) // 是否展开,默认全部展开 |
|
193 |
const refreshTable = ref(true) // 重新渲染表格状态 |
|
194 |
const toggleExpandAll = async () => { |
|
195 |
refreshTable.value = false |
|
196 |
isExpandAll.value = !isExpandAll.value |
|
197 |
await nextTick() |
|
198 |
refreshTable.value = true |
|
199 |
} |
|
200 |
|
|
201 |
/** 初始化 **/ |
|
202 |
onMounted(() => { |
|
203 |
getList() |
|
204 |
}) |
|
205 |
</script> |