table.vue.tpl 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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-popover placement="top" width="160" v-model="scope.row.visible">
  72. <p>确定要删除吗?</p>
  73. <div style="text-align: right; margin: 0">
  74. <el-button size="mini" type="text" @click="scope.row.visible = false">取消</el-button>
  75. <el-button type="primary" size="mini" @click="delete{{.StructName}}(scope.row)">确定</el-button>
  76. </div>
  77. <el-button type="danger" icon="el-icon-delete" size="mini" slot="reference">删除</el-button>
  78. </el-popover>
  79. </template>
  80. </el-table-column>
  81. </el-table>
  82. <el-pagination
  83. :current-page="page"
  84. :page-size="pageSize"
  85. :page-sizes="[10, 30, 50, 100]"
  86. :style="{float:'right',padding:'20px'}"
  87. :total="total"
  88. @current-change="handleCurrentChange"
  89. @size-change="handleSizeChange"
  90. layout="total, sizes, prev, pager, next, jumper"
  91. ></el-pagination>
  92. <el-dialog :before-close="closeDialog" :visible.sync="dialogFormVisible" title="弹窗操作">
  93. <el-form :model="formData" label-position="right" label-width="80px">
  94. {{- range .Fields}}
  95. <el-form-item label="{{.FieldDesc}}:">
  96. {{- if eq .FieldType "bool" }}
  97. <el-switch active-color="#13ce66" inactive-color="#ff4949" active-text="是" inactive-text="否" v-model="formData.{{.FieldJson}}" clearable ></el-switch>
  98. {{ end -}}
  99. {{- if eq .FieldType "string" }}
  100. <el-input v-model="formData.{{.FieldJson}}" clearable placeholder="请输入" ></el-input>
  101. {{ end -}}
  102. {{- if eq .FieldType "int" }}
  103. {{- if .DictType}}
  104. <el-select v-model="formData.{{ .FieldJson }}" placeholder="请选择" clearable>
  105. <el-option v-for="(item,key) in {{ .DictType }}Options" :key="key" :label="item.label" :value="item.value"></el-option>
  106. </el-select>
  107. {{ else -}}
  108. <el-input v-model.number="formData.{{ .FieldJson }}" clearable placeholder="请输入"></el-input>
  109. {{ end -}}
  110. {{ end -}}
  111. {{- if eq .FieldType "time.Time" }}
  112. <el-date-picker type="date" placeholder="选择日期" v-model="formData.{{ .FieldJson }}" clearable></el-date-picker>
  113. {{ end -}}
  114. {{- if eq .FieldType "float64" }}
  115. <el-input-number v-model="formData.{{ .FieldJson }}" :precision="2" clearable></el-input-number>
  116. {{ end -}}
  117. </el-form-item>
  118. {{ end -}}
  119. </el-form>
  120. <div class="dialog-footer" slot="footer">
  121. <el-button @click="closeDialog">取 消</el-button>
  122. <el-button @click="enterDialog" type="primary">确 定</el-button>
  123. </div>
  124. </el-dialog>
  125. </div>
  126. </template>
  127. <script>
  128. import {
  129. create{{.StructName}},
  130. delete{{.StructName}},
  131. delete{{.StructName}}ByIds,
  132. update{{.StructName}},
  133. find{{.StructName}},
  134. get{{.StructName}}List
  135. } from "@/api/{{.PackageName}}"; // 此处请自行替换地址
  136. import { formatTimeToStr } from "@/utils/date";
  137. import infoList from "@/mixins/infoList";
  138. export default {
  139. name: "{{.StructName}}",
  140. mixins: [infoList],
  141. data() {
  142. return {
  143. listApi: get{{ .StructName }}List,
  144. dialogFormVisible: false,
  145. visible: false,
  146. type: "",
  147. deleteVisible: false,
  148. multipleSelection: [],
  149. {{- range .Fields}}
  150. {{- if .DictType }}
  151. {{ .DictType }}Options:[],
  152. {{ end -}}
  153. {{end -}}
  154. formData: {
  155. {{range .Fields}}
  156. {{- if eq .FieldType "bool" -}}
  157. {{.FieldJson}}:false,
  158. {{ end -}}
  159. {{- if eq .FieldType "string" -}}
  160. {{.FieldJson}}:"",
  161. {{ end -}}
  162. {{- if eq .FieldType "int" -}}
  163. {{.FieldJson}}:0,
  164. {{ end -}}
  165. {{- if eq .FieldType "time.Time" -}}
  166. {{.FieldJson}}:new Date(),
  167. {{ end -}}
  168. {{- if eq .FieldType "float64" -}}
  169. {{.FieldJson}}:0,
  170. {{ end -}}
  171. {{ end }}
  172. }
  173. };
  174. },
  175. filters: {
  176. formatDate: function(time) {
  177. if (time != null && time != "") {
  178. var date = new Date(time);
  179. return formatTimeToStr(date, "yyyy-MM-dd hh:mm:ss");
  180. } else {
  181. return "";
  182. }
  183. },
  184. formatBoolean: function(bool) {
  185. if (bool != null) {
  186. return bool ? "是" :"否";
  187. } else {
  188. return "";
  189. }
  190. }
  191. },
  192. methods: {
  193. //条件搜索前端看此方法
  194. onSubmit() {
  195. this.page = 1
  196. this.pageSize = 10
  197. {{- range .Fields}} {{- if eq .FieldType "bool" }}
  198. if (this.searchInfo.{{.FieldJson}}==""){
  199. this.searchInfo.{{.FieldJson}}=null
  200. } {{ end }} {{ end }}
  201. this.getTableData()
  202. },
  203. handleSelectionChange(val) {
  204. this.multipleSelection = val
  205. },
  206. async onDelete() {
  207. const ids = []
  208. if(this.multipleSelection.length == 0){
  209. this.$message({
  210. type: 'warning',
  211. message: '请选择要删除的数据'
  212. })
  213. return
  214. }
  215. this.multipleSelection &&
  216. this.multipleSelection.map(item => {
  217. ids.push(item.ID)
  218. })
  219. const res = await delete{{.StructName}}ByIds({ ids })
  220. if (res.code == 0) {
  221. this.$message({
  222. type: 'success',
  223. message: '删除成功'
  224. })
  225. if (this.tableData.length == ids.length) {
  226. this.page--;
  227. }
  228. this.deleteVisible = false
  229. this.getTableData()
  230. }
  231. },
  232. async update{{.StructName}}(row) {
  233. const res = await find{{.StructName}}({ ID: row.ID });
  234. this.type = "update";
  235. if (res.code == 0) {
  236. this.formData = res.data.re{{.Abbreviation}};
  237. this.dialogFormVisible = true;
  238. }
  239. },
  240. closeDialog() {
  241. this.dialogFormVisible = false;
  242. this.formData = {
  243. {{range .Fields}}
  244. {{- if eq .FieldType "bool" -}}
  245. {{.FieldJson}}:false,
  246. {{ end -}}
  247. {{- if eq .FieldType "string" -}}
  248. {{.FieldJson}}:"",
  249. {{ end -}}
  250. {{- if eq .FieldType "int" -}}
  251. {{.FieldJson}}:0,
  252. {{ end -}}
  253. {{- if eq .FieldType "time.Time" -}}
  254. {{.FieldJson}}:new Date(),
  255. {{ end -}}
  256. {{- if eq .FieldType "float64" -}}
  257. {{.FieldJson}}:0,
  258. {{ end -}}
  259. {{ end }}
  260. };
  261. },
  262. async delete{{.StructName}}(row) {
  263. this.visible = false;
  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) {
  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>