inleft
2022-03-02 34223b096cf6ad9d92c3702bb9529e764f523b11
commit | author | age
9bcb19 1 <template>
I 2   <div>
3     <a-card :bordered="false" v-show="indexOpenShow" :bodyStyle="tstyle">
4       <a-spin :spinning="Loading">
5         <div class="table-page-search-wrapper" v-if="hasPerm('codeGenerate:page')">
6           <a-form layout="inline">
7             <a-row :gutter="48">
8               <a-col :md="8" :sm="24">
9                 <a-form-item label="表名称" >
10                   <a-input v-model="queryParam.tableName" allow-clear placeholder="请输入表名称"/>
11                 </a-form-item>
12               </a-col>
13               <a-col :md="8" :sm="24">
14                 <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
15                 <a-button style="margin-left: 8px" @click="() => queryParam = {}">重置</a-button>
16               </a-col>
17             </a-row>
18           </a-form>
19         </div>
20       </a-spin>
21     </a-card>
22     <a-card :bordered="false" v-show="indexOpenShow">
23       <a-spin :spinning="Loading">
24         <s-table
25           ref="table"
26           :columns="columns"
27           :data="loadData"
28           :alert="true"
29           :rowKey="(record) => record.id"
30           :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
31         >
32           <div slot="operator" v-if="hasPerm('codeGenerate:add')" >
33             <a-button type="primary" v-if="hasPerm('codeGenerate:add')" icon="plus" @click="$refs.addForm.add()">新增</a-button>
34           </div>
35           <span slot="tableName" slot-scope="text">
36             <ellipsis :length="10" tooltip>{{ text }}</ellipsis>
37           </span>
38           <span slot="packageName" slot-scope="text">
39             <ellipsis :length="10" tooltip>{{ text }}</ellipsis>
40           </span>
41           <span slot="busName" slot-scope="text">
42             <ellipsis :length="10" tooltip>{{ text }}</ellipsis>
43           </span>
44           <span slot="className" slot-scope="text">
45             <ellipsis :length="10" tooltip>{{ text }}</ellipsis>
46           </span>
47           <span slot="tableComment" slot-scope="text">
48             <ellipsis :length="10" tooltip>{{ text }}</ellipsis>
49           </span>
50           <span slot="tablePrefix" slot-scope="text">
51             <ellipsis :length="10" tooltip>{{ 'yes_or_no' | dictType(text) }}</ellipsis>
52           </span>
53           <span slot="generateType" slot-scope="text">
54             <ellipsis :length="10" tooltip>{{ 'code_gen_create_type' | dictType(text) }}</ellipsis>
55           </span>
56           <span slot="action" slot-scope="text, record">
57             <span v-if="record.generateType === '1'">
58               <a v-if="hasPerm('codeGenerate:runDown')" @click="runDownCodeGenerate(record)">开始生成</a>
59             </span>
60             <span v-else>
61               <a-popconfirm v-if="hasPerm('codeGenerate:runLocal')" placement="topRight" title="确定生成代码到本项目?" @confirm="() => runLocalCodeGenerate(record)">
62                 <a>开始生成</a>
63               </a-popconfirm>
64             </span>
65             <a-divider type="vertical" v-if="hasPerm('codeGenerate:config') & hasPerm('codeGenerate:runLocal') || hasPerm('codeGenerate:runDown') "/>
66             <a v-if="hasPerm('codeGenerate:config')" @click="indexConfigOpen(record)">配置</a>
67             <a-divider type="vertical" v-if="hasPerm('codeGenerate:config') & hasPerm('codeGenerate:edit')"/>
68             <a v-if="hasPerm('codeGenerate:edit')" @click="$refs.editForm.edit(record)">编辑</a>
69             <a-divider type="vertical" v-if="hasPerm('codeGenerate:edit') & hasPerm('codeGenerate:delete')"/>
70             <a-popconfirm v-if="hasPerm('codeGenerate:delete')" placement="topRight" title="确认删除?" @confirm="() => codeGenerateDelete(record)">
71               <a>删除</a>
72             </a-popconfirm>
73           </span>
74         </s-table>
75         <add-form ref="addForm" @ok="handleOk" v-if="hasPerm('codeGenerate:add')"/>
76         <edit-form ref="editForm" @ok="handleOk" v-if="hasPerm('codeGenerate:edit')"/>
77       </a-spin>
78     </a-card>
79     <index-config ref="indexConfig" @ok="handleResetOpen" v-if="hasPerm('codeGenerate:config')"/>
80   </div>
81 </template>
82 <script>
83   import { STable, Ellipsis } from '@/components'
84   import { codeGeneratePage, codeGenerateDelete, codeGenerateRunDown, codeGenerateRunLocal } from '@/api/modular/gen/codeGenerateManage'
85   import addForm from './addForm'
86   import editForm from './editForm'
87   import indexConfig from './indexConfig'
88
89   export default {
90     components: {
91       indexConfig,
92       STable,
93       Ellipsis,
94       addForm,
95       editForm
96     },
97     data () {
98       return {
99         // 查询参数
100         queryParam: {},
101         // 表头
102         columns: [
103           {
104             title: '表名称',
105             dataIndex: 'tableName',
106             scopedSlots: { customRender: 'tableName' }
107           },
108           {
109             title: '代码包名',
110             dataIndex: 'packageName',
111             scopedSlots: { customRender: 'packageName' }
112           },
113           {
114             title: '业务名',
115             dataIndex: 'busName',
116             scopedSlots: { customRender: 'busName' }
117           },
118           {
119             title: '类名',
120             dataIndex: 'className',
121             scopedSlots: { customRender: 'className' }
122           },
123           {
124             title: '功能名',
125             dataIndex: 'tableComment',
126             scopedSlots: { customRender: 'tableComment' }
127           },
128           {
129             title: '作者姓名',
130             dataIndex: 'authorName'
131           },
132           {
133             title: '表前缀移除',
134             dataIndex: 'tablePrefix',
135             scopedSlots: { customRender: 'tablePrefix' }
136           },
137           {
138             title: '生成方式',
139             dataIndex: 'generateType',
140             scopedSlots: { customRender: 'generateType' }
141           }
142         ],
143         tstyle: { 'padding-bottom': '0px', 'margin-bottom': '10px' },
144         loadData: parameter => {
145           return codeGeneratePage(Object.assign(parameter, this.queryParam)).then((res) => {
146             return res.data
147           })
148         },
149         selectedRowKeys: [],
150         selectedRows: [],
151         Loading: false,
152         jdbcDriverList: [],
153         indexOpenShow: true
154       }
155     },
156     created () {
157       if (this.hasPerm('codeGenerate:edit') || this.hasPerm('codeGenerate:delete')) {
158         this.columns.push({
159           title: '操作',
160           width: '230px',
161           dataIndex: 'action',
162           scopedSlots: { customRender: 'action' }
163         })
164       }
165     },
166     methods: {
167       /**
168        * 开始生成代码(生成压缩包)
169        */
170       runDownCodeGenerate (record) {
171         this.Loading = true
172         codeGenerateRunDown({ id: record.id }).then((res) => {
173           this.Loading = false
174           this.downloadfile(res)
175           // eslint-disable-next-line handle-callback-err
176         }).catch((err) => {
177           this.Loading = false
178           this.$message.error('下载错误:获取文件流错误')
179         })
180       },
181       downloadfile (res) {
182         var blob = new Blob([res.data], { type: 'application/octet-stream;charset=UTF-8' })
183         var contentDisposition = res.headers['content-disposition']
184         var patt = new RegExp('filename=([^;]+\\.[^\\.;]+);*')
185         var result = patt.exec(contentDisposition)
186         var filename = result[1]
187         var downloadElement = document.createElement('a')
188         var href = window.URL.createObjectURL(blob) // 创建下载的链接
189         var reg = /^["](.*)["]$/g
190         downloadElement.style.display = 'none'
191         downloadElement.href = href
192         downloadElement.download = decodeURI(filename.replace(reg, '$1')) // 下载后文件名
193         document.body.appendChild(downloadElement)
194         downloadElement.click() // 点击下载
195         document.body.removeChild(downloadElement) // 下载完成移除元素
196         window.URL.revokeObjectURL(href)
197       },
198       /**
199        * 开始生成代码(本地项目)
200        */
201       runLocalCodeGenerate (record) {
202         codeGenerateRunLocal(record).then((res) => {
203           if (res.success) {
204             this.$message.success('生成成功')
205             this.$refs.table.refresh()
206           } else {
207             this.$message.error('生成失败:' + res.message)
208           }
209         })
210       },
211       /**
212        * 删除
213        */
214       codeGenerateDelete (record) {
215         this.Loading = true
216         codeGenerateDelete([{ id: record.id }]).then((res) => {
217           if (res.success) {
218             this.$message.success('删除成功')
219             this.$refs.table.refresh()
220           } else {
221             this.$message.error('删除失败:' + res.message)
222           }
223         }).catch((err) => {
224           this.$message.error('删除错误:' + err.message)
225         }).finally((res) => {
226           this.Loading = false
227         })
228       },
229       /**
230        * 打开配置界面
231        */
232       indexConfigOpen (record) {
233         this.indexOpenShow = false
234         this.$refs.indexConfig.open(record)
235       },
236       /**
237        * 详细配置界面返回
238        */
239       handleResetOpen () {
240         this.indexOpenShow = true
241         this.$refs.table.refresh()
242       },
243       /**
244        * 其他界面返回
245        */
246       handleOk () {
247         this.$refs.table.refresh()
248       },
249       onSelectChange (selectedRowKeys, selectedRows) {
250         this.selectedRowKeys = selectedRowKeys
251         this.selectedRows = selectedRows
252       }
253     }
254   }
255 </script>
256 <style lang="less">
257   .table-operator {
258     margin-bottom: 18px;
259   }
260   button {
261     margin-right: 8px;
262   }
263 </style>