sysDictionary.vue 7.9 KB

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