schangxiang@126.com
2024-08-16 65bd2dc1d4c1fb136af853c7ede93a338431be29
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
<template>
  <a-modal
    title="编辑代码生成配置"
    :width="900"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item v-show="false">
          <a-input v-decorator="['id']" />
        </a-form-item>
         <a-row :gutter="24">
          <a-col :md="12" :sm="24">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="生成库" has-feedback>
              <a-select
                style="width: 100%"
                placeholder="请选择数据库"
                v-decorator="['databaseName', {rules: [{ required: true, message: '请选择数据库!' }]}]">
                <a-select-option
                  v-for="(item,index) in databaseNameData"
                  :key="index"
                  :value="item.databaseName"
                  @click="databaseNameSele(item)">{{ item.databaseName }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :md="12" :sm="24">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="生成表" has-feedback>
              <a-select
                style="width: 100%"
                placeholder="请选择数据库表"
                v-decorator="['tableName', {rules: [{ required: true, message: '请选择数据库表!' }]}]">
                <a-select-option
                  v-for="(item,index) in tableNameData"
                  :key="index"
                  :value="item.tableName"
                  @click="tableNameSele(item)">{{ item.tableName }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item label="业务名" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
              <a-input
                placeholder="请输入业务名"
                v-decorator="['busName', {rules: [{required: true, message: '请输入业务名!'}]}]" />
            </a-form-item>
          </a-col>
          <!--          <a-col :md="12" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="移除前缀"
            >
              <a-radio-group v-decorator="['tablePrefix',{rules: [{ required: true, message: '请选择是否移除前缀!' }]}]" >
                <a-radio v-for="(item,index) in tablePrefixData" :key="index" :value="item.code" @click="tablePrefixRadio(item.code)">{{ item.name }}</a-radio>
              </a-radio-group>
            </a-form-item>
          </a-col> -->
        </a-row>
        <a-row :gutter="24">
          <a-col :md="12" :sm="24">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="菜单分类" has-feedback>
              <a-select
                style="width: 100%"
                placeholder="请选择应用分类"
                v-decorator="['menuApplication', {rules: [{ required: true, message: '请选择应用分类!' }]}]">
                <a-select-option
                  v-for="(item,index) in appData"
                  :key="index"
                  :value="item.code"
                  @click="changeApplication(item.code)">{{ item.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <div>
              <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="父级菜单" has-feedback>
                <a-tree-select
                  v-decorator="['menuPid', {rules: [{ required: true, message: '请选择父级菜单!' }]}]"
                  style="width: 100%"
                  :dropdownStyle="{ maxHeight: '300px', overflow: 'auto' }"
                  :treeData="menuTreeData"
                  placeholder="请选择父级菜单"
                  treeDefaultExpandAll>
                  <span slot="title" slot-scope="{ id }">{{ id }}
                  </span>
                </a-tree-select>
              </a-form-item>
            </div>
          </a-col>
        </a-row>
        <!--        <a-row :gutter="24">
          <a-col :md="12" :sm="24">
            <a-form-item
              label="功能名"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              has-feedback
            >
              <a-input placeholder="请输入功能名" v-decorator="['tableComment', {rules: [{required: true, message: '请输入功能名!'}]}]" />
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="类名"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              has-feedback
            >
              <a-input placeholder="请输入类名" v-decorator="['className', {rules: [{required: true, message: '请输入类名!'}]}]" />
            </a-form-item>
          </a-col>
        </a-row> -->
        <a-row :gutter="24">
          <a-col :md="12" :sm="24">
            <a-form-item label="命名空间" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
              <a-input
                placeholder="请输入命名空间"
                v-decorator="['nameSpace', {rules: [{required: true, message: '请输入命名空间!'}]}]" />
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item label="作者姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
              <a-input
                placeholder="请输入作者姓名"
                v-decorator="['authorName', {rules: [{required: true, message: '请输入作者姓名!'}]}]" />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :md="12" :sm="24">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="生成方式">
              <a-radio-group v-decorator="['generateType',{rules: [{ required: true, message: '请选择生成方式!' }]}]">
                <a-radio
                  v-for="(item,index) in generateTypeData"
                  :key="index"
                  :value="item.code"
                  @click="generateTypeRadio(item.code)">{{ item.name }}</a-radio>
              </a-radio-group>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-spin>
  </a-modal>
</template>
 
<script>
  import {
    getAppList
  } from '@/api/modular/system/appManage'
  import {
    getMenuTree
  } from '@/api/modular/system/menuManage'
  import {
    codeGenerateDatabaseList,
    codeGenerateInformationList,
    codeGenerateEdit
  } from '@/api/modular/gen/codeGenerateManage'
  export default {
    data() {
      return {
        labelCol: {
          xs: {
            span: 24
          },
          sm: {
            span: 5
          }
        },
        wrapperCol: {
          xs: {
            span: 24
          },
          sm: {
            span: 15
          }
        },
        visible: false,
        databaseNameData:[],
        tableNameData: [],
        appData: [],
        menuTreeData: [],
        // tablePrefixData: [],
        generateTypeData: [],
        confirmLoading: false,
        // tablePrefixValue: 'N',
        databaseNameValue:'',
        tableNameValue: '',
        // packageNameShow: true,
        form: this.$form.createForm(this)
      }
    },
    methods: {
      // 初始化方法
      edit(record) {
        this.visible = true
        this.codeGenerateDatabaseList()
        this.codeGenerateInformationList()
        this.dataTypeItem()
        setTimeout(() => {
          this.form.setFieldsValue({
            id: record.id,
            databaseName:record.databaseName,
            tableName: record.tableName,
            // tablePrefix: record.tablePrefix,
            // tableComment: record.tableComment,
            // className: record.className,
            busName: record.busName,
            generateType: record.generateType,
            authorName: record.authorName,
            nameSpace: record.nameSpace,
            menuApplication: record.menuApplication,
            menuPid: record.menuPid
          })
        }, 100)
        this.databaseNameValue = record.databaseName
        this.tableNameValue = record.tableName
        // this.tablePrefixValue = record.tablePrefix
 
        // 获取系统应用列表
        this.getSysApplist()
        this.changeApplication(record.menuApplication)
      },
      /**
       * 获得菜单所属应用
       */
      getSysApplist() {
        return getAppList().then((res) => {
          if (res.success) {
            this.appData = res.data
          } else {
            this.$message.warning(res.message)
          }
        })
      },
        /**
       * 获得所有数据库
       */
      codeGenerateDatabaseList() {
        codeGenerateDatabaseList().then((res) => {
          this.databaseNameData = res.data
        })
      },
      /**
       * 获得所有数据库的表
       */
      codeGenerateInformationList(parameter) {
        codeGenerateInformationList(parameter).then((res) => {
          this.tableNameData = res.data
        })
      },
      /**
       * 获取字典数据
       */
      dataTypeItem() {
        this.tablePrefixData = this.$options.filters['dictData']('yes_or_no')
        this.generateTypeData = this.$options.filters['dictData']('code_gen_create_type')
        this.generateTypeData.splice(0, 1) // 默认去掉从压缩包下载
      },
      /**
       * 提交表单
       */
      handleSubmit() {
        const {
          form: {
            validateFields
          }
        } = this
        validateFields((errors, values) => {
          if (!errors) {
            this.confirmLoading = true
            codeGenerateEdit(values).then((res) => {
              if (res.success) {
                this.$message.success('编辑成功')
                this.$emit('ok', values)
                this.handleCancel()
              } else {
                this.$message.error('编辑失败' + res.message)
              }
            }).finally((res) => {
              this.confirmLoading = false
            })
          }
        })
      },
      handleCancel() {
        this.form.resetFields()
        this.visible = false
      },
        /**
       * 选择数据库
       */
      databaseNameSele(item) {
        this.databaseNameValue = item.databaseName
        // this.form.getFieldDecorator('tableComment', { initialValue: item.tableComment })
        //this.form.getFieldDecorator('busName', {
        //  initialValue: item.databaseComment
        //})
        this.form.setFieldsValue({'tableName':''}); //这个OK
        this.codeGenerateInformationList({ dbContextLocatorName:this.databaseNameValue});
        //this.settingDefaultValue()
      },
      /**
       * 选择数据库列表
       */
      tableNameSele(item) {
        this.tableNameValue = item.tableName
        this.form.setFieldsValue({
          className: item.tableComment
        })
        this.settingDefaultValue()
      },
      /**
       * 菜单所属应用change事件
       */
      changeApplication(value) {
        getMenuTree({
          'application': value
        }).then((res) => {
          if (res.success) {
            this.menuTreeData = [{
              'id': '-1',
              'parentId': '0',
              'title': '顶级',
              'value': '0',
              'pid': '0',
              'children': res.data
            }]
          } else {
            this.$message.warning(res.message)
          }
        })
      },
      // /**
      //  * 选择是否移除前缀触发
      //  */
      // tablePrefixRadio (tablePrefixType) {
      //   this.tablePrefixValue = tablePrefixType
      //   this.settingDefaultValue()
      // },
      // /**
      //  * 设置默认值
      //  */
       settingDefaultValue () {
      //  const tableName = this.classNameToHump()
      //   this.form.setFieldsValue(
      //     {
      //       className: tableName,
      //       busName: tableName.toLowerCase()
      //     }
      //   )
       },
      // /**
      //  * 设置类名为数据库表的驼峰命名
      //  */
      // classNameToHump () {
      //   const arr = this.tableNameValue.toLowerCase().split('_')
      //   if (this.tablePrefixValue === 'Y') {
      //     arr.splice(0, 1)
      //   }
      //   for (let i = 0; i < arr.length; i++) {
      //     // charAt()方法得到第一个字母,slice()得到第二个字母以后的字符串
      //     arr[i] = arr[i].charAt(0).toUpperCase() + arr[i].slice(1)
      //   }
      //   return arr.join('')
      // },
      /**
       * 选择生成方式
       */
      generateTypeRadio(generateType) {
        // if (generateType === '1') {
        //   this.packageNameShow = true
        // } else {
        //   this.packageNameShow = false
        //   this.form.setFieldsValue({ packageName: 'com.cn.xiaonuo' })
        // }
      }
    }
  }
</script>