generate.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <template>
  2. <div>
  3. <el-form ref="form" v-loading="loading" style="width: 100%;padding: 5px">
  4. <el-row class="handle-box" style="margin-bottom: 10px">
  5. <el-col :span="24">
  6. <span class="card_title">基本信息</span>
  7. <el-card shadow="always" style="padding: 15px 5px 5px 15px">
  8. <el-row>
  9. <el-col :span="3" class="col-txt"><span>生成的文件名</span></el-col>
  10. <el-col :span="8" class="col-input">
  11. <el-form-item>
  12. <el-input v-model="fileName" />
  13. </el-form-item>
  14. </el-col>
  15. <el-col :span="4" class="col-txt"><span>控制器名称</span></el-col>
  16. <el-col :span="8" class="col-input">
  17. <el-form-item>
  18. <el-input v-model="controller" />
  19. </el-form-item>
  20. </el-col>
  21. </el-row>
  22. <el-row>
  23. <el-col :span="3" class="col-txt"><span>文件夹地址</span></el-col>
  24. <el-col :span="20" class="col-input">
  25. <el-form-item>
  26. <el-input v-model="filePath" />
  27. </el-form-item>
  28. </el-col>
  29. </el-row>
  30. </el-card>
  31. </el-col>
  32. </el-row>
  33. <el-row class="handle-box" style="margin-bottom: 10px">
  34. <el-col :span="24">
  35. <span class="card_title">字段信息</span>
  36. <el-card shadow="always" style="padding: 15px 5px 5px 15px">
  37. <el-row>
  38. <el-col :span="24">
  39. <el-table
  40. :data="FieldData"
  41. header-row-class-name="g_table_header"
  42. height="300"
  43. row-class-name="g_table_row"
  44. stripe
  45. >
  46. <el-table-column type="index" width="40" />
  47. <el-table-column align="center" header-align="center" label="字段">
  48. <template scope="scope">
  49. <el-input v-model="scope.row.key" class="f-small" size="small" />
  50. </template>
  51. </el-table-column>
  52. <el-table-column align="center" header-align="center" label="字段显示名">
  53. <template scope="scope">
  54. <el-input v-model="scope.row.value" class="f-small" size="small" />
  55. </template>
  56. </el-table-column>
  57. <el-table-column align="center" header-align="center" label="导出宽度">
  58. <template scope="scope">
  59. <el-input v-model="scope.row.opWidth" class="f-small" size="small" />
  60. </template>
  61. </el-table-column>
  62. <el-table-column align="center" header-align="center" label="是否字典项">
  63. <template scope="scope">
  64. <el-checkbox v-model="scope.row.isDict" @change="checkSearchField(scope.row.id)" />
  65. </template>
  66. </el-table-column>
  67. <el-table-column align="center" header-align="center" label="字典KEY">
  68. <template scope="scope">
  69. <el-input v-model="scope.row.dictKey" class="f-small" size="small" />
  70. </template>
  71. </el-table-column>
  72. <el-table-column align="center" header-align="center" label="是否搜索">
  73. <template scope="scope">
  74. <el-checkbox v-model="scope.row.isSearch" @change="checkSearchField(scope.row.id)" />
  75. </template>
  76. </el-table-column>
  77. <el-table-column align="center" header-align="center" label="类型">
  78. <template scope="scope">
  79. <el-input v-model="scope.row.type" class="f-small" size="small" />
  80. </template>
  81. </el-table-column>
  82. <el-table-column align="right" width="120">
  83. <template slot="header">
  84. <el-button
  85. size="mini"
  86. type="primary"
  87. @click="keepAddLine()"
  88. >添加</el-button>
  89. </template>
  90. <template scope="scope">
  91. <el-button
  92. size="mini"
  93. type="danger"
  94. @click="deleteLine(scope.$index, FieldData) "
  95. >删除</el-button>
  96. </template>
  97. </el-table-column>
  98. </el-table>
  99. </el-col>
  100. </el-row>
  101. </el-card>
  102. </el-col>
  103. </el-row>
  104. </el-form>
  105. <el-row class="handle-box" style="margin-bottom: 10px">
  106. <el-col :span="24">
  107. <span class="card_title">生成历史</span>
  108. <el-card shadow="always" style="padding: 15px 5px 5px 15px">
  109. <el-row>
  110. <el-col :span="24">
  111. <el-table
  112. :data="HisData"
  113. header-row-class-name="g_table_header"
  114. height="300"
  115. row-class-name="g_table_row"
  116. stripe
  117. >
  118. <el-table-column type="index" width="40" />
  119. <el-table-column align="center" header-align="center" label="id" prop="id" />
  120. <el-table-column align="center" header-align="center" label="fileName" prop="fileName" />
  121. <el-table-column align="center" header-align="center" label="创建时间" prop="createdAt" />
  122. <el-table-column align="right" width="80">
  123. <template scope="scope">
  124. <el-button
  125. size="mini"
  126. type="primary"
  127. @click="fill(scope.row)"
  128. >回填</el-button>
  129. </template>
  130. </el-table-column>
  131. </el-table>
  132. </el-col>
  133. </el-row>
  134. </el-card>
  135. </el-col>
  136. </el-row>
  137. <div slot="footer" style="float: right">
  138. <el-button @click="">重 置</el-button>
  139. <el-button type="primary" @click="confirmSubmit()">生成代码</el-button>
  140. </div>
  141. </div>
  142. </template>
  143. <script>
  144. export default {
  145. name: 'GenerateCode',
  146. data() {
  147. return {
  148. loading: false,
  149. fileName: '',
  150. filePath: '',
  151. controller: '',
  152. FieldData: [],
  153. HisData: []
  154. }
  155. },
  156. mounted() {
  157. this.initHis()
  158. },
  159. methods: {
  160. initHis: function() {
  161. const genHis = this.$common.castEval(localStorage.getItem('genHis'))
  162. if (genHis && this.$common.isArrayFn(genHis)) {
  163. this.HisData = genHis
  164. //console.log('his', this.HisData)
  165. }
  166. },
  167. fill: function(val) {
  168. //console.log(val)
  169. const his = this.$common.castEval(val.his)
  170. if (his) {
  171. //console.log('fill select s', his)
  172. this.fileName = his.fileName
  173. this.filePath = his.filePath
  174. this.controller = his.controller
  175. this.FieldData = this.$common.castEval(his.fieldData)
  176. }
  177. },
  178. keepAddLine: function() {
  179. const newcont = {
  180. id: new Date().getTime(),
  181. key: '',
  182. value: '',
  183. opWidth: '', // 导出宽度
  184. isDict: false,
  185. dictKey: '', // 字典key
  186. isSearch: false,
  187. type: 'input'
  188. }
  189. this.FieldData.push(newcont)
  190. },
  191. checkSearchField: function(val) {
  192. //console.log(this.FieldData)
  193. },
  194. deleteLine: function(index, rows) {
  195. rows.splice(index, 1)
  196. },
  197. reset: function() {
  198. this.fileName = ''
  199. this.controller = ''
  200. this.filePath = ''
  201. this.HisData = []
  202. },
  203. confirmSubmit: function() {
  204. const _this = this
  205. const fields = {}
  206. const searchs = {}
  207. this.FieldData.forEach(function(item) {
  208. fields[item.key] = item.value
  209. if (item.isSearch) {
  210. searchs[item.key] = item.value
  211. }
  212. })
  213. const postData = {
  214. fileName: this.fileName,
  215. controller: this.controller,
  216. filePath: this.filePath,
  217. fieldData: JSON.stringify(this.FieldData),
  218. createdAt: this.$common.transServDate(new Date())
  219. // fields: JSON.stringify(fields),
  220. // seachFields: JSON.stringify(searchs),
  221. }
  222. this.loading = true
  223. // //console.log(postData)
  224. this.$axios({
  225. headers: {
  226. 'MVVM-Key': String(new Date().getTime()),
  227. 'xx': 'anything'
  228. },
  229. method: 'post',
  230. url: this.$constant.BASE_URI + '/VueGenController/code',
  231. data: this.$qs.stringify(postData)
  232. }).then((res) => {
  233. //console.log('Gen ', res)
  234. const his = {
  235. id: String(new Date().getTime()),
  236. fileName: postData.fileName,
  237. createdAt: postData.createdAt,
  238. his: _this.$common.castString(postData)
  239. }
  240. let genHis = _this.$common.castEval(localStorage.getItem('genHis'))
  241. if (!genHis || !_this.$common.isArrayFn(genHis)) {
  242. genHis = []
  243. }
  244. // genHis.push(his)
  245. genHis.unshift(his)
  246. localStorage.setItem('genHis', _this.$common.castString(genHis))
  247. _this.initHis()
  248. _this.$common.checkLoginStatus(res.data.statusCode)
  249. _this.loading = false
  250. _this.$notify({
  251. title: '生成完成',
  252. type: 'info'
  253. })
  254. }).catch((err, x) => {
  255. //console.log('biz user list error', err, x)
  256. })
  257. }
  258. }
  259. }
  260. </script>
  261. <style scoped>
  262. .ch-input .el-input__inner {
  263. border-radius: 0px;
  264. border-color: #32323A;
  265. }
  266. .ch-input-size {
  267. width: 200px;
  268. /*margin-right: 10px;*/
  269. }
  270. .ch-button {
  271. border-radius: 0px;
  272. border-color: #32323A;
  273. background-color: #32323A;
  274. color: #fff;
  275. }
  276. </style>