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