Rap 原分销系统代码Web
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

326 líneas
13KB

  1. <template>
  2. <div class="app-container">
  3. <el-row :gutter="15">
  4. <el-col style="margin-bottom: 10px">
  5. <el-card class="box-card" shadow="never">
  6. <div slot="header" class="clearfix">
  7. <span class="role-span">字段配置:{{ tableName }}</span>
  8. <el-button
  9. :loading="genLoading"
  10. icon="el-icon-s-promotion"
  11. size="mini"
  12. style="float: right; padding: 6px 9px;"
  13. type="success"
  14. @click="toGen"
  15. >保存&生成</el-button>
  16. <el-button
  17. :loading="columnLoading"
  18. icon="el-icon-check"
  19. size="mini"
  20. style="float: right; padding: 6px 9px;margin-right: 9px"
  21. type="primary"
  22. @click="saveColumnConfig"
  23. >保存</el-button>
  24. <el-tooltip class="item" effect="dark" content="数据库中表字段变动时使用该功能" placement="top-start">
  25. <el-button
  26. :loading="syncLoading"
  27. icon="el-icon-refresh"
  28. size="mini"
  29. style="float: right; padding: 6px 9px;"
  30. type="info"
  31. @click="sync"
  32. >同步</el-button>
  33. </el-tooltip>
  34. </div>
  35. <el-form size="small" label-width="90px">
  36. <el-table v-loading="loading" :data="data" :max-height="tableHeight" size="small" style="width: 100%;margin-bottom: 15px">
  37. <el-table-column prop="columnName" label="字段名称" />
  38. <el-table-column prop="columnType" label="字段类型" />
  39. <el-table-column prop="remark" label="字段描述">
  40. <template slot-scope="scope">
  41. <el-input v-model="data[scope.$index].remark" size="mini" class="edit-input" />
  42. </template>
  43. </el-table-column>
  44. <el-table-column align="center" label="必填" width="70px">
  45. <template slot-scope="scope">
  46. <el-checkbox v-model="data[scope.$index].notNull" />
  47. </template>
  48. </el-table-column>
  49. <el-table-column align="center" label="列表" width="70px">
  50. <template slot-scope="scope">
  51. <el-checkbox v-model="data[scope.$index].listShow" />
  52. </template>
  53. </el-table-column>
  54. <el-table-column align="center" label="表单" width="70px">
  55. <template slot-scope="scope">
  56. <el-checkbox v-model="data[scope.$index].formShow" />
  57. </template>
  58. </el-table-column>
  59. <el-table-column label="表单类型">
  60. <template slot-scope="scope">
  61. <el-select v-model="data[scope.$index].formType" filterable class="edit-input" clearable size="mini" placeholder="请选择">
  62. <el-option
  63. label="文本框"
  64. value="Input"
  65. />
  66. <el-option
  67. label="文本域"
  68. value="Textarea"
  69. />
  70. <el-option
  71. label="单选框"
  72. value="Radio"
  73. />
  74. <el-option
  75. label="下拉框"
  76. value="Select"
  77. />
  78. <el-option
  79. label="日期框"
  80. value="Date"
  81. />
  82. </el-select>
  83. </template>
  84. </el-table-column>
  85. <el-table-column label="查询方式">
  86. <template slot-scope="scope">
  87. <el-select v-model="data[scope.$index].queryType" filterable class="edit-input" clearable size="mini" placeholder="请选择">
  88. <el-option
  89. label="="
  90. value="="
  91. />
  92. <el-option
  93. label="!="
  94. value="!="
  95. />
  96. <el-option
  97. label=">="
  98. value=">="
  99. />
  100. <el-option
  101. label="<="
  102. value="<="
  103. />
  104. <el-option
  105. label="Like"
  106. value="Like"
  107. />
  108. <el-option
  109. label="NotNull"
  110. value="NotNull"
  111. />
  112. <el-option
  113. label="BetWeen"
  114. value="BetWeen"
  115. />
  116. </el-select>
  117. </template>
  118. </el-table-column>
  119. <el-table-column label="日期注解">
  120. <template slot-scope="scope">
  121. <el-select v-model="data[scope.$index].dateAnnotation" filterable class="edit-input" clearable size="mini" placeholder="请选择">
  122. <el-option
  123. label="自动创建时间"
  124. value="CreationTimestamp"
  125. />
  126. <el-option
  127. label="自动更新时间"
  128. value="UpdateTimestamp"
  129. />
  130. </el-select>
  131. </template>
  132. </el-table-column>
  133. <el-table-column label="关联字典">
  134. <template slot-scope="scope">
  135. <el-select v-model="data[scope.$index].dictName" filterable class="edit-input" clearable size="mini" placeholder="请选择">
  136. <el-option v-for="item in dicts" :key="item.id" :label="item.remark === '' ? item.name : item.remark" :value="item.name" />
  137. </el-select>
  138. </template>
  139. </el-table-column>
  140. </el-table>
  141. </el-form>
  142. </el-card>
  143. </el-col>
  144. <el-col>
  145. <el-card class="box-card" shadow="never">
  146. <div slot="header" class="clearfix">
  147. <span class="role-span">生成配置</span>
  148. <el-button
  149. :loading="configLoading"
  150. icon="el-icon-check"
  151. size="mini"
  152. style="float: right; padding: 6px 9px"
  153. type="primary"
  154. @click="doSubmit"
  155. >保存</el-button>
  156. </div>
  157. <el-form ref="form" :model="form" :rules="rules" size="small" label-width="78px">
  158. <el-form-item label="作者名称" prop="author">
  159. <el-input v-model="form.author" style="width: 40%" />
  160. <span style="color: #C0C0C0;margin-left: 10px;">类上面的作者名称</span>
  161. </el-form-item>
  162. <el-form-item label="模块名称" prop="moduleName">
  163. <el-input v-model="form.moduleName" style="width: 40%" />
  164. <span style="color: #C0C0C0;margin-left: 10px;">模块的名称,请选择项目中已存在的模块</span>
  165. </el-form-item>
  166. <el-form-item label="至于包下" prop="pack">
  167. <el-input v-model="form.pack" style="width: 40%" />
  168. <span style="color: #C0C0C0;margin-left: 10px;">项目包的名称,生成的代码放到哪个包里面</span>
  169. </el-form-item>
  170. <el-form-item label="接口名称" prop="apiAlias">
  171. <el-input v-model="form.apiAlias" style="width: 40%" />
  172. <span style="color: #C0C0C0;margin-left: 10px;">接口的名称,用于控制器与接口文档中</span>
  173. </el-form-item>
  174. <el-form-item label="前端路径" prop="path">
  175. <el-input v-model="form.path" style="width: 40%" />
  176. <span style="color: #C0C0C0;margin-left: 10px;">输入views文件夹下的目录,不存在即创建</span>
  177. </el-form-item>
  178. <!-- <el-form-item label="接口目录">-->
  179. <!-- <el-input v-model="form.apiPath" style="width: 40%" />-->
  180. <!-- <span style="color: #C0C0C0;margin-left: 10px;">Api存放路径[src/api],为空则自动生成路径</span>-->
  181. <!-- </el-form-item>-->
  182. <el-form-item label="去表前缀" prop="prefix">
  183. <el-input v-model="form.prefix" placeholder="默认不去除表前缀" style="width: 40%" />
  184. <span style="color: #C0C0C0;margin-left: 10px;">默认不去除表前缀,可自定义</span>
  185. </el-form-item>
  186. <el-form-item label="是否覆盖" prop="cover">
  187. <el-radio-group v-model="form.cover" size="mini" style="width: 40%">
  188. <el-radio-button label="true">是</el-radio-button>
  189. <el-radio-button label="false">否</el-radio-button>
  190. </el-radio-group>
  191. <span style="color: #C0C0C0;margin-left: 10px;">谨防误操作,请慎重选择</span>
  192. </el-form-item>
  193. </el-form>
  194. </el-card>
  195. </el-col>
  196. </el-row>
  197. </div>
  198. </template>
  199. <script>
  200. import crud from '@/mixins/crud'
  201. import { update, get } from '@/api/generator/genConfig'
  202. import { save, sync, generator } from '@/api/generator/generator'
  203. import { getDicts } from '@/api/system/dict'
  204. export default {
  205. name: 'GeneratorConfig',
  206. components: {},
  207. mixins: [crud],
  208. data() {
  209. return {
  210. activeName: 'first', tableName: '', tableHeight: 550, columnLoading: false, configLoading: false, dicts: [], syncLoading: false, genLoading: false,
  211. form: { id: null, tableName: '', author: '', pack: '', path: '', moduleName: '', cover: 'false', apiPath: '', prefix: '', apiAlias: null },
  212. rules: {
  213. author: [
  214. { required: true, message: '作者不能为空', trigger: 'blur' }
  215. ],
  216. pack: [
  217. { required: true, message: '包路径不能为空', trigger: 'blur' }
  218. ],
  219. moduleName: [
  220. { required: true, message: '包路径不能为空', trigger: 'blur' }
  221. ],
  222. path: [
  223. { required: true, message: '前端路径不能为空', trigger: 'blur' }
  224. ],
  225. apiAlias: [
  226. { required: true, message: '接口名称不能为空', trigger: 'blur' }
  227. ],
  228. cover: [
  229. { required: true, message: '不能为空', trigger: 'blur' }
  230. ]
  231. }
  232. }
  233. },
  234. created() {
  235. this.tableHeight = document.documentElement.clientHeight - 385
  236. this.tableName = this.$route.params.tableName
  237. this.$nextTick(() => {
  238. this.init()
  239. get(this.tableName).then(data => {
  240. this.form = data
  241. this.form.cover = this.form.cover.toString()
  242. })
  243. getDicts().then(data => {
  244. this.dicts = data
  245. })
  246. })
  247. },
  248. methods: {
  249. beforeInit() {
  250. this.url = 'api/generator/columns'
  251. const tableName = this.tableName
  252. this.params = { tableName }
  253. return true
  254. },
  255. saveColumnConfig() {
  256. this.columnLoading = true
  257. save(this.data).then(res => {
  258. this.notify('保存成功', 'success')
  259. this.columnLoading = false
  260. }).catch(err => {
  261. this.columnLoading = false
  262. console.log(err.response.data.message)
  263. })
  264. },
  265. doSubmit() {
  266. this.$refs['form'].validate((valid) => {
  267. if (valid) {
  268. this.configLoading = true
  269. update(this.form).then(res => {
  270. this.notify('保存成功', 'success')
  271. this.form = res
  272. this.form.cover = this.form.cover.toString()
  273. this.configLoading = false
  274. }).catch(err => {
  275. this.configLoading = false
  276. console.log(err.response.data.message)
  277. })
  278. }
  279. })
  280. },
  281. sync() {
  282. this.syncLoading = true
  283. sync([this.tableName]).then(() => {
  284. this.init()
  285. this.notify('同步成功', 'success')
  286. this.syncLoading = false
  287. }).then(() => {
  288. this.syncLoading = false
  289. })
  290. },
  291. toGen() {
  292. this.genLoading = true
  293. save(this.data).then(res => {
  294. this.notify('保存成功', 'success')
  295. // 生成代码
  296. generator(this.tableName, 0).then(data => {
  297. this.genLoading = false
  298. this.notify('生成成功', 'success')
  299. }).catch(err => {
  300. this.genLoading = false
  301. console.log(err.response.data.message)
  302. })
  303. }).catch(err => {
  304. this.genLoading = false
  305. console.log(err.response.data.message)
  306. })
  307. }
  308. }
  309. }
  310. </script>
  311. <style rel="stylesheet/scss" lang="scss">
  312. .edit-input {
  313. .el-input__inner {
  314. border: 1px solid #e5e6e7;
  315. }
  316. }
  317. </style>
  318. <style scoped>
  319. ::v-deep .input-with-select .el-input-group__prepend {
  320. background-color: #fff;
  321. }
  322. </style>