table.vue.tpl 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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 @click="update{{.StructName}}(scope.row)" size="small" type="primary">变更</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/data";
  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. this.multipleSelection &&
  209. this.multipleSelection.map(item => {
  210. ids.push(item.ID)
  211. })
  212. const res = await delete{{.StructName}}ByIds({ ids })
  213. if (res.code == 0) {
  214. this.$message({
  215. type: 'success',
  216. message: '删除成功'
  217. })
  218. this.deleteVisible = false
  219. this.getTableData()
  220. }
  221. },
  222. async update{{.StructName}}(row) {
  223. const res = await find{{.StructName}}({ ID: row.ID });
  224. this.type = "update";
  225. if (res.code == 0) {
  226. this.formData = res.data.re{{.Abbreviation}};
  227. this.dialogFormVisible = true;
  228. }
  229. },
  230. closeDialog() {
  231. this.dialogFormVisible = false;
  232. this.formData = {
  233. {{range .Fields}}
  234. {{- if eq .FieldType "bool" -}}
  235. {{.FieldJson}}:false,
  236. {{ end -}}
  237. {{- if eq .FieldType "string" -}}
  238. {{.FieldJson}}:"",
  239. {{ end -}}
  240. {{- if eq .FieldType "int" -}}
  241. {{.FieldJson}}:0,
  242. {{ end -}}
  243. {{- if eq .FieldType "time.Time" -}}
  244. {{.FieldJson}}:new Date(),
  245. {{ end -}}
  246. {{- if eq .FieldType "float64" -}}
  247. {{.FieldJson}}:0,
  248. {{ end -}}
  249. {{ end }}
  250. };
  251. },
  252. async delete{{.StructName}}(row) {
  253. this.visible = false;
  254. const res = await delete{{.StructName}}({ ID: row.ID });
  255. if (res.code == 0) {
  256. this.$message({
  257. type: "success",
  258. message: "删除成功"
  259. });
  260. this.getTableData();
  261. }
  262. },
  263. async enterDialog() {
  264. let res;
  265. switch (this.type) {
  266. case "create":
  267. res = await create{{.StructName}}(this.formData);
  268. break;
  269. case "update":
  270. res = await update{{.StructName}}(this.formData);
  271. break;
  272. default:
  273. res = await create{{.StructName}}(this.formData);
  274. break;
  275. }
  276. if (res.code == 0) {
  277. this.$message({
  278. type:"success",
  279. message:"创建/更改成功"
  280. })
  281. this.closeDialog();
  282. this.getTableData();
  283. }
  284. },
  285. openDialog() {
  286. this.type = "create";
  287. this.dialogFormVisible = true;
  288. }
  289. },
  290. async created() {
  291. await this.getTableData();
  292. {{ range .Fields -}}
  293. {{- if .DictType }}
  294. await this.getDict("{{.DictType}}");
  295. {{ end -}}
  296. {{- end }}
  297. }
  298. };
  299. </script>
  300. <style>
  301. </style>