工业互联网平台脚手架前端代码
houzhongjian
2024-09-18 23db5e5c6bfcbd7030a4003cd4ea18fbb920024f
提交 | 用户 | 时间
23db5e 1 <template>
H 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="code">
12         <el-input
13           v-model="queryParams.code"
14           placeholder="请输入编号"
15           clearable
16           @keyup.enter="handleQuery"
17           class="!w-240px"
18         />
19       </el-form-item>
20       <el-form-item label="名称" prop="name">
21         <el-input
22           v-model="queryParams.name"
23           placeholder="请输入名称"
24           clearable
25           @keyup.enter="handleQuery"
26           class="!w-240px"
27         />
28       </el-form-item>
29       <el-form-item label="状态" prop="status">
30         <el-select
31           v-model="queryParams.status"
32           placeholder="请选择状态"
33           clearable
34           class="!w-240px"
35         >
36           <el-option
37             v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
38             :key="dict.value"
39             :label="dict.label"
40             :value="dict.value"
41           />
42         </el-select>
43       </el-form-item>
44       <el-form-item>
45         <el-button @click="handleQuery">
46           <Icon icon="ep:search" class="mr-5px" />
47           搜索
48         </el-button>
49         <el-button @click="resetQuery">
50           <Icon icon="ep:refresh" class="mr-5px" />
51           重置
52         </el-button>
53         <el-button
54           type="primary"
55           plain
56           @click="openForm('create')"
57           v-hasPermi="['fast:demo:create']"
58         >
59           <Icon icon="ep:plus" class="mr-5px" />
60           新增
61         </el-button>
62         <el-button
63           type="success"
64           plain
65           @click="handleExport"
66           :loading="exportLoading"
67           v-hasPermi="['fast:demo:export']"
68         >
69           <Icon icon="ep:download" class="mr-5px" />
70           导出
71         </el-button>
72       </el-form-item>
73     </el-form>
74   </ContentWrap>
75
76   <!-- 列表 -->
77   <ContentWrap>
78     <el-table v-loading="loading" :data="list">
79       <el-table-column label="应用编号" align="center" prop="code" />
80       <el-table-column label="应用名称" align="center" prop="name" />
81       <el-table-column label="应用图标" align="center" prop="icon" />
82       <el-table-column label="备注" align="center" prop="remark" width="200" />
83       <el-table-column
84         label="创建时间"
85         align="center"
86         prop="createTime"
87         width="180"
88         :formatter="dateFormatter"
89       />
90       <el-table-column label="操作" align="center" min-width="110" fixed="right">
91         <template #default="scope">
92           <el-button
93             link
94             type="primary"
95             @click="openForm('update', scope.row.id)"
96             v-hasPermi="['fast:demo:update']"
97           >
98             编辑
99           </el-button>
100           <el-button
101             link
102             type="danger"
103             @click="handleDelete(scope.row.id)"
104             v-hasPermi="['fast:demo:delete']"
105           >
106             删除
107           </el-button>
108         </template>
109       </el-table-column>
110     </el-table>
111     <!-- 分页 -->
112     <Pagination
113       :total="total"
114       v-model:page="queryParams.pageNo"
115       v-model:limit="queryParams.pageSize"
116       @pagination="getList"
117     />
118   </ContentWrap>
119
120   <!-- 表单弹窗:添加/修改 -->
121   <DemoForm ref="formRef" @success="getList" />
122
123 </template>
124 <script lang="ts" setup>
125   import {DICT_TYPE, getIntDictOptions} from '@/utils/dict'
126   import {dateFormatter} from '@/utils/formatTime'
127   import download from '@/utils/download'
128   import * as DemoApi from '@/api/demo'
129   import DemoForm from './DemoForm.vue'
130
131   defineOptions({name: 'Demo'})
132
133   const message = useMessage() // 消息弹窗
134   const {t} = useI18n() // 国际化
135
136   const loading = ref(true) // 列表的加载中
137   const total = ref(0) // 列表的总页数
138   const list = ref([]) // 列表的数据
139   const queryParams = reactive({
140     pageNo: 1,
141     pageSize: 10,
142     code: undefined,
143     name: undefined,
144     status: undefined,
145     createTime: []
146   })
147   const queryFormRef = ref() // 搜索的表单
148   const exportLoading = ref(false) // 导出的加载中
149
150   /** 查询列表 */
151   const getList = async () => {
152     loading.value = true
153     try {
154       const data = await DemoApi.getDemoPage(queryParams)
155       list.value = data.list
156       total.value = data.total
157     } finally {
158       loading.value = false
159     }
160   }
161
162   /** 搜索按钮操作 */
163   const handleQuery = () => {
164     queryParams.pageNo = 1
165     getList()
166   }
167
168   /** 重置按钮操作 */
169   const resetQuery = () => {
170     queryFormRef.value.resetFields()
171     handleQuery()
172   }
173
174   /** 添加/修改操作 */
175   const formRef = ref()
176   const openForm = (type: string, id?: number) => {
177     formRef.value.open(type, id)
178   }
179
180   /** 删除按钮操作 */
181   const handleDelete = async (id: number) => {
182     try {
183       // 删除的二次确认
184       await message.delConfirm()
185       // 发起删除
186       await DemoApi.deleteDemo(id)
187       message.success(t('common.delSuccess'))
188       // 刷新列表
189       await getList()
190     } catch {
191     }
192   }
193
194   /** 导出按钮操作 */
195   const handleExport = async () => {
196     try {
197       // 导出的二次确认
198       await message.exportConfirm()
199       // 发起导出
200       exportLoading.value = true
201       const data = await DemoApi.exportDemo(queryParams)
202       download.excel(data, '租户列表.xls')
203     } catch {
204     } finally {
205       exportLoading.value = false
206     }
207   }
208
209   /** 初始化 **/
210   onMounted(async () => {
211     await getList()
212   })
213 </script>