sysDictionary.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <template>
  2. <div>
  3. <div class="search-term">
  4. <el-form :inline="true" :model="searchInfo" class="demo-form-inline">
  5. <el-form-item label="字典名(中)">
  6. <el-input placeholder="搜索条件" v-model="searchInfo.name"></el-input>
  7. </el-form-item>
  8. <el-form-item label="字典名(英)">
  9. <el-input placeholder="搜索条件" v-model="searchInfo.type"></el-input>
  10. </el-form-item>
  11. <el-form-item label="状态" prop="status">
  12. <el-select v-model="searchInfo.status" clear placeholder="请选择">
  13. <el-option
  14. key="true"
  15. label="是"
  16. value="true">
  17. </el-option>
  18. <el-option
  19. key="false"
  20. label="否"
  21. value="false">
  22. </el-option>
  23. </el-select>
  24. </el-form-item>
  25. <el-form-item label="描述">
  26. <el-input placeholder="搜索条件" v-model="searchInfo.desc"></el-input>
  27. </el-form-item>
  28. <el-form-item>
  29. <el-button @click="onSubmit" type="primary">查询</el-button>
  30. </el-form-item>
  31. <el-form-item>
  32. <el-button @click="openDialog" type="primary">新增字典</el-button>
  33. </el-form-item>
  34. </el-form>
  35. </div>
  36. <el-table
  37. :data="tableData"
  38. border
  39. ref="multipleTable"
  40. stripe
  41. style="width: 100%"
  42. tooltip-effect="dark"
  43. >
  44. <el-table-column type="selection" width="55"></el-table-column>
  45. <el-table-column label="日期" width="180">
  46. <template slot-scope="scope">{{scope.row.CreatedAt|formatDate}}</template>
  47. </el-table-column>
  48. <el-table-column label="字典名(中)" prop="name" width="120"></el-table-column>
  49. <el-table-column label="字典名(英)" prop="type" width="120"></el-table-column>
  50. <el-table-column label="状态" prop="status" width="120">
  51. <template slot-scope="scope">{{scope.row.status|formatBoolean}}</template>
  52. </el-table-column>
  53. <el-table-column label="描述" prop="desc" width="280"></el-table-column>
  54. <el-table-column label="按钮组">
  55. <template slot-scope="scope">
  56. <el-button @click="toDetile(scope.row)" size="small" type="success">详情</el-button>
  57. <el-button @click="updateSysDictionary(scope.row)" size="small" type="primary">变更</el-button>
  58. <el-popover placement="top" width="160" v-model="scope.row.visible">
  59. <p>确定要删除吗?</p>
  60. <div style="text-align: right; margin: 0">
  61. <el-button size="mini" type="text" @click="scope.row.visible = false">取消</el-button>
  62. <el-button type="primary" size="mini" @click="deleteSysDictionary(scope.row)">确定</el-button>
  63. </div>
  64. <el-button type="danger" icon="el-icon-delete" size="mini" slot="reference">删除</el-button>
  65. </el-popover>
  66. </template>
  67. </el-table-column>
  68. </el-table>
  69. <el-pagination
  70. :current-page="page"
  71. :page-size="pageSize"
  72. :page-sizes="[10, 30, 50, 100]"
  73. :style="{float:'right',padding:'20px'}"
  74. :total="total"
  75. @current-change="handleCurrentChange"
  76. @size-change="handleSizeChange"
  77. layout="total, sizes, prev, pager, next, jumper"
  78. ></el-pagination>
  79. <el-dialog :before-close="closeDialog" :visible.sync="dialogFormVisible" title="弹窗操作">
  80. <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="110px">
  81. <el-form-item label="字典名(中)" prop="name">
  82. <el-input v-model="formData.name" placeholder="请输入字典名(中)" clearable :style="{width: '100%'}"></el-input>
  83. </el-form-item>
  84. <el-form-item label="字典名(英)" prop="type">
  85. <el-input v-model="formData.type" placeholder="请输入字典名(英)" clearable :style="{width: '100%'}"></el-input>
  86. </el-form-item>
  87. <el-form-item label="状态" prop="status" required>
  88. <el-switch v-model="formData.status" active-text="开启" inactive-text="停用"></el-switch>
  89. </el-form-item>
  90. <el-form-item label="描述" prop="desc">
  91. <el-input v-model="formData.desc" placeholder="请输入描述" clearable :style="{width: '100%'}"></el-input>
  92. </el-form-item>
  93. </el-form>
  94. <div class="dialog-footer" slot="footer">
  95. <el-button @click="closeDialog">取 消</el-button>
  96. <el-button @click="enterDialog" type="primary">确 定</el-button>
  97. </div>
  98. </el-dialog>
  99. <div style="margin-top:40px;color:red">获取字典且缓存方法已在前端utils/dictionary 已经封装完成 不必自己书写 使用方法查看文件内注释</div>
  100. </div>
  101. </template>
  102. <script>
  103. import {
  104. createSysDictionary,
  105. deleteSysDictionary,
  106. updateSysDictionary,
  107. findSysDictionary,
  108. getSysDictionaryList
  109. } from "@/api/sysDictionary"; // 此处请自行替换地址
  110. import { formatTimeToStr } from "@/utils/date";
  111. import infoList from "@/mixins/infoList";
  112. export default {
  113. name: "SysDictionary",
  114. mixins: [infoList],
  115. data() {
  116. return {
  117. listApi: getSysDictionaryList,
  118. dialogFormVisible: false,
  119. visible: false,
  120. type: "",
  121. formData: {
  122. name:null,type:null,status:true,desc:null
  123. },
  124. rules: {
  125. name: [{
  126. required: true,
  127. message: '请输入字典名(中)',
  128. trigger: 'blur'
  129. }],
  130. type: [{
  131. required: true,
  132. message: '请输入字典名(英)',
  133. trigger: 'blur'
  134. }],
  135. desc: [{
  136. required: true,
  137. message: '请输入描述',
  138. trigger: 'blur'
  139. }],
  140. },
  141. };
  142. },
  143. filters: {
  144. formatDate: function(time) {
  145. if (time != null && time != "") {
  146. var date = new Date(time);
  147. return formatTimeToStr(date, "yyyy-MM-dd hh:mm:ss");
  148. } else {
  149. return "";
  150. }
  151. },
  152. formatBoolean: function(bool) {
  153. if (bool != null) {
  154. return bool ? "是" :"否";
  155. } else {
  156. return "";
  157. }
  158. }
  159. },
  160. methods: {
  161. toDetile(row){
  162. this.$router.push({
  163. name:"dictionaryDetail",
  164. params:{
  165. id:row.ID
  166. }
  167. })
  168. },
  169. //条件搜索前端看此方法
  170. onSubmit() {
  171. this.page = 1
  172. this.pageSize = 10
  173. if (this.searchInfo.status==""){
  174. this.searchInfo.status=null
  175. }
  176. this.getTableData()
  177. },
  178. async updateSysDictionary(row) {
  179. const res = await findSysDictionary({ ID: row.ID });
  180. this.type = "update";
  181. if (res.code == 0) {
  182. this.formData = res.data.resysDictionary;
  183. this.dialogFormVisible = true;
  184. }
  185. },
  186. closeDialog() {
  187. this.dialogFormVisible = false;
  188. this.formData = {
  189. name:null,
  190. type:null,
  191. status:true,
  192. desc:null,
  193. };
  194. },
  195. async deleteSysDictionary(row) {
  196. this.visible = false;
  197. const res = await deleteSysDictionary({ ID: row.ID });
  198. if (res.code == 0) {
  199. this.$message({
  200. type: "success",
  201. message: "删除成功"
  202. });
  203. this.getTableData();
  204. }
  205. },
  206. async enterDialog() {
  207. this.$refs['elForm'].validate(async valid => {
  208. if (!valid) return
  209. let res;
  210. switch (this.type) {
  211. case "create":
  212. res = await createSysDictionary(this.formData);
  213. break;
  214. case "update":
  215. res = await updateSysDictionary(this.formData);
  216. break;
  217. default:
  218. res = await createSysDictionary(this.formData);
  219. break;
  220. }
  221. if (res.code == 0) {
  222. this.closeDialog();
  223. this.getTableData();
  224. }
  225. })
  226. },
  227. openDialog() {
  228. this.type = "create";
  229. this.dialogFormVisible = true;
  230. }
  231. },
  232. async created() {
  233. this.getTableData();
  234. }
  235. };
  236. </script>
  237. <style>
  238. </style>