You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

320 lines
10 KiB

  1. <template>
  2. <div>
  3. <div class="search-term">
  4. <el-form :inline="true" :model="searchInfo" class="demo-form-inline">
  5. {{- range .Fields}} {{- if .FieldSearchType}} {{- if eq .FieldType "bool" }}
  6. <el-form-item label="{{.FieldDesc}}" prop="{{.FieldJson}}">
  7. <el-select v-model="searchInfo.{{.FieldJson}}" clear placeholder="请选择">
  8. <el-option
  9. key="true"
  10. label="是"
  11. value="true">
  12. </el-option>
  13. <el-option
  14. key="false"
  15. label="否"
  16. value="false">
  17. </el-option>
  18. </el-select>
  19. </el-form-item>
  20. {{- else }}
  21. <el-form-item label="{{.FieldDesc}}">
  22. <el-input placeholder="搜索条件" v-model="searchInfo.{{.FieldJson}}"></el-input>
  23. </el-form-item> {{ end }} {{ end }} {{ end }}
  24. <el-form-item>
  25. <el-button @click="onSubmit" type="primary">查询</el-button>
  26. </el-form-item>
  27. <el-form-item>
  28. <el-button @click="openDialog" type="primary">新增{{.Description}}</el-button>
  29. </el-form-item>
  30. <el-form-item>
  31. <el-popover placement="top" v-model="deleteVisible" width="160">
  32. <p>确定要删除吗?</p>
  33. <div style="text-align: right; margin: 0">
  34. <el-button @click="deleteVisible = false" size="mini" type="text">取消</el-button>
  35. <el-button @click="onDelete" size="mini" type="primary">确定</el-button>
  36. </div>
  37. <el-button icon="el-icon-delete" size="mini" slot="reference" type="danger">批量删除</el-button>
  38. </el-popover>
  39. </el-form-item>
  40. </el-form>
  41. </div>
  42. <el-table
  43. :data="tableData"
  44. @selection-change="handleSelectionChange"
  45. border
  46. ref="multipleTable"
  47. stripe
  48. style="width: 100%"
  49. tooltip-effect="dark"
  50. >
  51. <el-table-column type="selection" width="55"></el-table-column>
  52. <el-table-column label="日期" width="180">
  53. <template slot-scope="scope">{{ "{{scope.row.CreatedAt|formatDate}}" }}</template>
  54. </el-table-column>
  55. {{range .Fields}}
  56. {{- if .DictType}}
  57. <el-table-column label="{{.FieldDesc}}" prop="{{.FieldJson}}" width="120">
  58. <template slot-scope="scope">
  59. {{"{{"}}filterDict(scope.row.{{.FieldJson}},"{{.DictType}}"){{"}}"}}
  60. </template>
  61. </el-table-column>
  62. {{- else if eq .FieldType "bool" }}
  63. <el-table-column label="{{.FieldDesc}}" prop="{{.FieldJson}}" width="120">
  64. <template slot-scope="scope">{{ "{{scope.row."}}{{.FieldJson}}{{"|formatBoolean}}" }}</template>
  65. </el-table-column> {{- else }}
  66. <el-table-column label="{{.FieldDesc}}" prop="{{.FieldJson}}" width="120"></el-table-column> {{ end }}
  67. {{ end }}
  68. <el-table-column label="按钮组">
  69. <template slot-scope="scope">
  70. <el-button class="table-button" @click="update{{.StructName}}(scope.row)" size="small" type="primary" icon="el-icon-edit">变更</el-button>
  71. <el-button type="danger" icon="el-icon-delete" size="mini" @click="deleteRow(scope.row)">删除</el-button>
  72. </template>
  73. </el-table-column>
  74. </el-table>
  75. <el-pagination
  76. :current-page="page"
  77. :page-size="pageSize"
  78. :page-sizes="[10, 30, 50, 100]"
  79. :style="{float:'right',padding:'20px'}"
  80. :total="total"
  81. @current-change="handleCurrentChange"
  82. @size-change="handleSizeChange"
  83. layout="total, sizes, prev, pager, next, jumper"
  84. ></el-pagination>
  85. <el-dialog :before-close="closeDialog" :visible.sync="dialogFormVisible" title="弹窗操作">
  86. <el-form :model="formData" label-position="right" label-width="80px">
  87. {{- range .Fields}}
  88. <el-form-item label="{{.FieldDesc}}:">
  89. {{- if eq .FieldType "bool" }}
  90. <el-switch active-color="#13ce66" inactive-color="#ff4949" active-text="是" inactive-text="否" v-model="formData.{{.FieldJson}}" clearable ></el-switch>
  91. {{ end -}}
  92. {{- if eq .FieldType "string" }}
  93. <el-input v-model="formData.{{.FieldJson}}" clearable placeholder="请输入" ></el-input>
  94. {{ end -}}
  95. {{- if eq .FieldType "int" }}
  96. {{- if .DictType}}
  97. <el-select v-model="formData.{{ .FieldJson }}" placeholder="请选择" clearable>
  98. <el-option v-for="(item,key) in {{ .DictType }}Options" :key="key" :label="item.label" :value="item.value"></el-option>
  99. </el-select>
  100. {{ else -}}
  101. <el-input v-model.number="formData.{{ .FieldJson }}" clearable placeholder="请输入"></el-input>
  102. {{ end -}}
  103. {{ end -}}
  104. {{- if eq .FieldType "time.Time" }}
  105. <el-date-picker type="date" placeholder="选择日期" v-model="formData.{{ .FieldJson }}" clearable></el-date-picker>
  106. {{ end -}}
  107. {{- if eq .FieldType "float64" }}
  108. <el-input-number v-model="formData.{{ .FieldJson }}" :precision="2" clearable></el-input-number>
  109. {{ end -}}
  110. </el-form-item>
  111. {{ end -}}
  112. </el-form>
  113. <div class="dialog-footer" slot="footer">
  114. <el-button @click="closeDialog">取 消</el-button>
  115. <el-button @click="enterDialog" type="primary">确 定</el-button>
  116. </div>
  117. </el-dialog>
  118. </div>
  119. </template>
  120. <script>
  121. import {
  122. create{{.StructName}},
  123. delete{{.StructName}},
  124. delete{{.StructName}}ByIds,
  125. update{{.StructName}},
  126. find{{.StructName}},
  127. get{{.StructName}}List
  128. } from "@/api/{{.PackageName}}"; // 此处请自行替换地址
  129. import { formatTimeToStr } from "@/utils/date";
  130. import infoList from "@/mixins/infoList";
  131. export default {
  132. name: "{{.StructName}}",
  133. mixins: [infoList],
  134. data() {
  135. return {
  136. listApi: get{{ .StructName }}List,
  137. dialogFormVisible: false,
  138. type: "",
  139. deleteVisible: false,
  140. multipleSelection: [],
  141. {{- range .Fields}}
  142. {{- if .DictType }}
  143. {{ .DictType }}Options:[],
  144. {{ end -}}
  145. {{end -}}
  146. formData: {
  147. {{range .Fields}}
  148. {{- if eq .FieldType "bool" -}}
  149. {{.FieldJson}}:false,
  150. {{ end -}}
  151. {{- if eq .FieldType "string" -}}
  152. {{.FieldJson}}:"",
  153. {{ end -}}
  154. {{- if eq .FieldType "int" -}}
  155. {{.FieldJson}}:0,
  156. {{ end -}}
  157. {{- if eq .FieldType "time.Time" -}}
  158. {{.FieldJson}}:new Date(),
  159. {{ end -}}
  160. {{- if eq .FieldType "float64" -}}
  161. {{.FieldJson}}:0,
  162. {{ end -}}
  163. {{ end }}
  164. }
  165. };
  166. },
  167. filters: {
  168. formatDate: function(time) {
  169. if (time != null && time != "") {
  170. var date = new Date(time);
  171. return formatTimeToStr(date, "yyyy-MM-dd hh:mm:ss");
  172. } else {
  173. return "";
  174. }
  175. },
  176. formatBoolean: function(bool) {
  177. if (bool != null) {
  178. return bool ? "是" :"否";
  179. } else {
  180. return "";
  181. }
  182. }
  183. },
  184. methods: {
  185. //条件搜索前端看此方法
  186. onSubmit() {
  187. this.page = 1
  188. this.pageSize = 10
  189. {{- range .Fields}} {{- if eq .FieldType "bool" }}
  190. if (this.searchInfo.{{.FieldJson}}==""){
  191. this.searchInfo.{{.FieldJson}}=null
  192. } {{ end }} {{ end }}
  193. this.getTableData()
  194. },
  195. handleSelectionChange(val) {
  196. this.multipleSelection = val
  197. },
  198. deleteRow(row){
  199. this.$confirm('确定要删除吗?', '提示', {
  200. confirmButtonText: '确定',
  201. cancelButtonText: '取消',
  202. type: 'warning'
  203. }).then(() => {
  204. this.delete{{.StructName}}(row);
  205. });
  206. },
  207. async onDelete() {
  208. const ids = []
  209. if(this.multipleSelection.length == 0){
  210. this.$message({
  211. type: 'warning',
  212. message: '请选择要删除的数据'
  213. })
  214. return
  215. }
  216. this.multipleSelection &&
  217. this.multipleSelection.map(item => {
  218. ids.push(item.ID)
  219. })
  220. const res = await delete{{.StructName}}ByIds({ ids })
  221. if (res.code == 0) {
  222. this.$message({
  223. type: 'success',
  224. message: '删除成功'
  225. })
  226. if (this.tableData.length == ids.length && this.page > 1) {
  227. this.page--;
  228. }
  229. this.deleteVisible = false
  230. this.getTableData()
  231. }
  232. },
  233. async update{{.StructName}}(row) {
  234. const res = await find{{.StructName}}({ ID: row.ID });
  235. this.type = "update";
  236. if (res.code == 0) {
  237. this.formData = res.data.re{{.Abbreviation}};
  238. this.dialogFormVisible = true;
  239. }
  240. },
  241. closeDialog() {
  242. this.dialogFormVisible = false;
  243. this.formData = {
  244. {{range .Fields}}
  245. {{- if eq .FieldType "bool" -}}
  246. {{.FieldJson}}:false,
  247. {{ end -}}
  248. {{- if eq .FieldType "string" -}}
  249. {{.FieldJson}}:"",
  250. {{ end -}}
  251. {{- if eq .FieldType "int" -}}
  252. {{.FieldJson}}:0,
  253. {{ end -}}
  254. {{- if eq .FieldType "time.Time" -}}
  255. {{.FieldJson}}:new Date(),
  256. {{ end -}}
  257. {{- if eq .FieldType "float64" -}}
  258. {{.FieldJson}}:0,
  259. {{ end -}}
  260. {{ end }}
  261. };
  262. },
  263. async delete{{.StructName}}(row) {
  264. const res = await delete{{.StructName}}({ ID: row.ID });
  265. if (res.code == 0) {
  266. this.$message({
  267. type: "success",
  268. message: "删除成功"
  269. });
  270. if (this.tableData.length == 1 && this.page > 1 ) {
  271. this.page--;
  272. }
  273. this.getTableData();
  274. }
  275. },
  276. async enterDialog() {
  277. let res;
  278. switch (this.type) {
  279. case "create":
  280. res = await create{{.StructName}}(this.formData);
  281. break;
  282. case "update":
  283. res = await update{{.StructName}}(this.formData);
  284. break;
  285. default:
  286. res = await create{{.StructName}}(this.formData);
  287. break;
  288. }
  289. if (res.code == 0) {
  290. this.$message({
  291. type:"success",
  292. message:"创建/更改成功"
  293. })
  294. this.closeDialog();
  295. this.getTableData();
  296. }
  297. },
  298. openDialog() {
  299. this.type = "create";
  300. this.dialogFormVisible = true;
  301. }
  302. },
  303. async created() {
  304. await this.getTableData();
  305. {{ range .Fields -}}
  306. {{- if .DictType }}
  307. await this.getDict("{{.DictType}}");
  308. {{ end -}}
  309. {{- end }}
  310. }
  311. };
  312. </script>
  313. <style>
  314. </style>