潘志宝
2024-12-11 8ca7ee27830b807fbb20268b4b90c9dfae7648f6
提交 | 用户 | 时间
9ec4bd 1 <template>
1e8d99 2   <el-row :gutter="20">
3     <!-- 左侧树 -->
4     <el-col :span="4" :xs="24">
5       <ContentWrap class="h-1/1">
6         <el-tree
7           style="max-width: 600px"
8           :data="treeData"
9           :props="treeProps"
10           default-expand-all
11           highlight-current
12           @node-click="handleNodeClick"
9ec4bd 13         />
1e8d99 14       </ContentWrap>
15     </el-col>
16     <el-col :span="20" :xs="24">
17       <!-- 搜索工作栏 -->
18       <ContentWrap>
19         <el-form
20           class="-mb-15px"
21           :model="queryParams"
22           ref="queryFormRef"
23           :inline="true"
24           label-width="68px"
ec54c9 25           @submit.prevent
1e8d99 26         >
8ca7ee 27           <el-form-item label="模型名称" prop="pyChineseName">
28             <el-input
29               v-model="queryParams.pyChineseName"
30               placeholder="请输入模型名称"
31               clearable
32               class="!w-240px"
33             />
34           </el-form-item>
35           <el-form-item label="模型文件" prop="pyName">
1e8d99 36             <el-input
37               v-model="queryParams.pyName"
8ca7ee 38               placeholder="请输入模型文件名称"
1e8d99 39               clearable
40               class="!w-240px"
41             />
42           </el-form-item>
43           <el-form-item>
44             <el-button @click="handleQuery">
45               <Icon icon="ep:search" class="mr-5px"/>
46               搜索
9ec4bd 47             </el-button>
1e8d99 48             <el-button @click="resetQuery">
49               <Icon icon="ep:refresh" class="mr-5px"/>
50               重置
51             </el-button>
52             <div class="ml-12px">
53               <router-link :to="'/file/form'">
54                 <el-button type="primary" plain v-hasPermi="['mpk:file:create']">
55                   <Icon icon="ep:plus" class="mr-5px"/>新增</el-button>
56               </router-link>
9ec4bd 57             </div>
58
1e8d99 59           </el-form-item>
60         </el-form>
61       </ContentWrap>
62
63       <!-- 列表 -->
64       <ContentWrap>
65         <el-table
66           v-loading="loading"
67           :data="list"
68           row-key="id"
69         >
8ca7ee 70           <el-table-column prop="pyChineseName" label="模型名称" header-align="center" align="left" min-width="100" />
71           <el-table-column prop="pyName" label="模型文件" header-align="center" align="left" min-width="300"/>
1e8d99 72           <el-table-column prop="pyType" label="模型类型" :formatter="(r,c,v) => getDictLabel(DICT_TYPE.MODEL_TYPE,v)"/>
73           <el-table-column prop="menuName" label="所属菜单" min-width="120px"/>
74           <el-table-column prop="groupName" label="所属组" min-width="120px"/>
75           <el-table-column prop="remark" label="备注" min-width="100px"/>
76           <el-table-column prop="createDate" label="创建时间" :formatter="dateFormatter" width="180px"/>
77           <el-table-column label="操作" align="center" width="200px">
78             <template #default="scope">
79               <div class="flex items-center justify-center">
80                 <router-link :to="'/file/form/' + scope.row.id">
81                   <el-button type="primary" link v-hasPermi="['mpk:file:update']">
82                     <Icon icon="ep:edit"/>修改
83                   </el-button>
84                 </router-link>
85                 <el-button link type="danger" @click="handleDelete(scope.row.id)" v-hasPermi="['mpk:file:delete']">
86                   <Icon icon="ep:delete"/>删除
87                 </el-button>
88                 <div class="pl-12px">
89                   <el-dropdown @command="(command) => handleCommand(command, scope.row)" trigger="click">
90                     <el-button type="primary" link>
91                       <Icon icon="ep:d-arrow-right" /> 更多
92                     </el-button>
93                     <template #dropdown>
94                       <el-dropdown-menu>
95                         <el-dropdown-item
96                           command="generatorCode"
97                         >
98                           生成代码
99                         </el-dropdown-item>
100                         <el-dropdown-item
101                           command="generatorHistory"
102                         >
103                           生成历史
104                         </el-dropdown-item>
105                         <el-dropdown-item
106                           command="mpkRunDialog"
107                         >
108                           运行
109                         </el-dropdown-item>
110                       </el-dropdown-menu>
111                     </template>
112                   </el-dropdown>
113                 </div>
114               </div>
115             </template>
116           </el-table-column>
117         </el-table>
118         <!-- 分页 -->
119         <Pagination
b45bad 120           v-model:limit="queryParams.limit"
1e8d99 121           v-model:page="queryParams.page"
122           :total="total"
123           @pagination="getList"
124         />
125       </ContentWrap>
126
127       <MpkGenerator ref="mpkGenerator"/>
128       <GeneratorCodeHistory ref="generatorCodeHistory"/>
129       <MpkRun ref="mpkRun"/>
130     </el-col>
131   </el-row>
9ec4bd 132 </template>
133 <script lang="ts" setup>
134   import {dateFormatter} from '@/utils/formatTime'
aff5c9 135   import * as MpkApi from '@/api/model/mpk/mpk'
1e8d99 136   import * as MpkMenuApi from '@/api/model/mpk/menu'
9ec4bd 137   import MpkGenerator from './MpkGenerator.vue'
138   import GeneratorCodeHistory from './MpkGeneratorHistory.vue'
139   import MpkRun from './MpkRun.vue'
140   import { DICT_TYPE, getDictLabel } from '@/utils/dict'
1e8d99 141   import {ElTree} from "element-plus";
9ec4bd 142
143   defineOptions({name: 'MpkFile'})
144
145   const message = useMessage() // 消息弹窗
146   const {t} = useI18n() // 国际化
1e8d99 147
148   const treeProps = {
149     children: 'children',
150     label: 'label',
151   }
9ec4bd 152
153   const loading = ref(true) // 列表的加载中
154   const total = ref(0) // 列表的总页数
155   const list = ref([]) // 字典表格数据
156   const queryParams = reactive({
157     page: 1,
b45bad 158     limit: 10,
8ca7ee 159     pyChineseName: '',
1e8d99 160     pyName: '',
161     label: ''
9ec4bd 162   })
163   const queryFormRef = ref() // 搜索的表单
1e8d99 164   const treeData = ref([])
9ec4bd 165
166   const getList = async () => {
167     loading.value = true
168     try {
169       const data = await MpkApi.getPage(queryParams)
170       list.value = data.list
171       total.value = data.total
172     } finally {
173       loading.value = false
174     }
1e8d99 175   }
176
177   const getTree = async () => {
178     const data = await MpkMenuApi.getTree()
179     treeData.value = data
9ec4bd 180   }
181
182   /** 操作分发 */
183   const handleCommand = (command: string, row) => {
184     switch (command) {
185       case 'generatorCode':
186         generatorCode(row.id,row.pyName)
187         break
188       case 'generatorHistory':
189         generatorHistory(row.id)
190         break
191       case 'mpkRunDialog':
192         mpkRunDialog(row)
193         break
194       default:
195         break
196     }
197   }
198
199   const mpkGenerator = ref();
200   const generatorCode = (id,pyName) => {
201     mpkGenerator.value.open(id,pyName);
202   }
203
204   const generatorCodeHistory = ref();
205   const generatorHistory = (id) => {
206     generatorCodeHistory.value.open(id);
207   }
208
209   const mpkRun = ref();
210   const mpkRunDialog = (row) => {
211     mpkRun.value.open(row);
212   }
213
214   /** 搜索按钮操作 */
215   const handleQuery = () => {
216     getList()
217   }
218
219   /** 重置按钮操作 */
220   const resetQuery = () => {
221     queryParams.page = 1
222     queryFormRef.value.resetFields()
223     handleQuery()
224   }
225
226   /** 删除按钮操作 */
227   const handleDelete = async (id: number) => {
228     try {
229       // 删除的二次确认
230       await message.delConfirm()
231       // 发起删除
232       await MpkApi.deleteMpk(id)
233       message.success(t('common.delSuccess'))
234       // 刷新列表
235       await getList()
236     } catch {
237     }
238   }
239
1e8d99 240   const handleNodeClick = (data: Tree) => {
241     queryParams.label = data.label
242     getList()
243   }
244
9ec4bd 245   onActivated((to) => {
246     getList()
1e8d99 247     getTree()
9ec4bd 248   })
249
250   /** 初始化 **/
251   onMounted(async () => {
252     await getList()
1e8d99 253     await getTree()
9ec4bd 254   })
255 </script>