dict.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <template>
  2. <div class="app-container">
  3. <div class="head-container" style="margin: 10px 0 10px 0;">
  4. <!-- 搜索 -->
  5. <el-input
  6. v-model="query.value"
  7. clearable
  8. placeholder="输入搜索内容"
  9. style="width: 200px;"
  10. size="small"
  11. class="filter-item"
  12. />
  13. <el-select v-model="query.type" clearable placeholder="类型" class="filter-item" size="small" style="width: 130px">
  14. <el-option v-for="item in queryTypeOptions" :key="item.key" :label="item.display_name" :value="item.key" />
  15. </el-select>
  16. <el-button class="filter-item" size="small" type="primary" icon="el-icon-search" plain>搜索</el-button>
  17. <el-button
  18. class="filter-item"
  19. size="small"
  20. type="primary"
  21. icon="el-icon-plus"
  22. @click="handleAdd"
  23. >新增
  24. </el-button>
  25. </div>
  26. <!--表格渲染-->
  27. <el-table v-loading="loading" :data="data" style="width: 100%;">
  28. <el-table-column label="序号" width="60" align="center">
  29. <template slot-scope="scope">
  30. <span>{{ scope.$index + 1 }}</span>
  31. </template>
  32. </el-table-column>
  33. <el-table-column prop="dictName" label="字典名称" />
  34. <el-table-column prop="dictCode" label="字典编码" />
  35. <el-table-column prop="description" :show-overflow-tooltip="true" label="描述" />
  36. <el-table-column prop="remark" label="备注" />
  37. <el-table-column prop="createTime" label="创建时间" />
  38. <el-table-column label="操作" width="250" align="center">
  39. <template slot-scope="scope">
  40. <el-button slot="reference" type="text" icon="el-icon-edit" @click="handleEdit(scope.row)">编辑</el-button>
  41. <el-popover
  42. :ref="scope.row.dictName"
  43. placement="top"
  44. width="180"
  45. >
  46. <p>此操作将删除字典与对应的字典详情,确定要删除吗?</p>
  47. <div style="text-align: right; margin: 0">
  48. <el-button size="mini" type="text" @click="$refs[scope.row.dictName].doClose()">取消</el-button>
  49. <el-button :loading="delLoading" type="primary" size="mini" @click="subDelete(scope.row.id)">确定
  50. </el-button>
  51. </div>
  52. <el-button slot="reference" icon="el-icon-delete" type="text">删除</el-button>
  53. </el-popover>
  54. <el-button slot="reference" icon="el-icon-s-grid" type="text" @click="a(scope.row.id)">字典值</el-button>
  55. </template>
  56. </el-table-column>
  57. </el-table>
  58. <!--分页-->
  59. <div class="pagination">
  60. <el-pagination
  61. :current-page.sync="currentPage"
  62. :page-size="pageSize"
  63. layout="total, prev, pager, next, jumper"
  64. :total="total"
  65. background
  66. @current-change="handleCurrentChange"
  67. />
  68. </div>
  69. <!--新增-->
  70. <el-dialog :append-to-body="true" :visible.sync="dialog" :title="isAdd ? '新增字典' : '编辑字典'" width="500px">
  71. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  72. <el-form-item label="字典名称" prop="dictName">
  73. <el-input v-model="form.dictName" style="width: 370px;" placeholder="请输入字典名称" />
  74. </el-form-item>
  75. <el-form-item label="字典编码" prop="dictCode">
  76. <el-input v-model="form.dictCode" style="width: 370px;" placeholder="请输入字典编码" />
  77. </el-form-item>
  78. <el-form-item label="描述" prop="description">
  79. <el-input v-model="form.description" style="width: 370px;" placeholder="请输入描述" />
  80. </el-form-item>
  81. <el-form-item label="备注">
  82. <el-input v-model="form.remark" style="width: 370px;" placeholder="请输入备注" />
  83. </el-form-item>
  84. </el-form>
  85. <div slot="footer" class="dialog-footer">
  86. <el-button type="text" @click="dialog = false">取消</el-button>
  87. <el-button :loading="loading" type="primary" @click="doSubmit">确认</el-button>
  88. </div>
  89. </el-dialog>
  90. <dictItem ref="dictItem" />
  91. </div>
  92. </template>
  93. <script>
  94. import { saveDict, getDict, updateDict, deleteDict } from '@/api/dict'
  95. import dictItem from './dictItem'
  96. export default {
  97. components: { dictItem },
  98. data() {
  99. return {
  100. data: [],
  101. dictDetailData: [],
  102. loading: false,
  103. dloading: false,
  104. qqdialog: false,
  105. dialog: false,
  106. ddialog: false,
  107. isAdd: false,
  108. isValueAdd: false,
  109. visible: false,
  110. form: {
  111. id: '',
  112. dictName: '',
  113. dictCode: '',
  114. description: '',
  115. remark: ''
  116. },
  117. currentPage: 1,
  118. pageSize: 10,
  119. total: 0, // 总数量
  120. // 名称
  121. dictName: '',
  122. delLoading: false,
  123. rules: {
  124. dictName: [
  125. { required: true, message: '字典名称不为空', trigger: 'blur' }
  126. ],
  127. dictCode: [
  128. { required: true, message: '字典编码不为空', trigger: 'blur' }
  129. ],
  130. description: [
  131. { required: true, message: '描述不为空', trigger: 'blur' }
  132. ]
  133. },
  134. queryTypeOptions: [
  135. { key: 'name', display_name: '字典名称' },
  136. { key: 'remark', display_name: '描述' }
  137. ],
  138. query: {
  139. type: '',
  140. value: ''
  141. }
  142. }
  143. },
  144. created() {
  145. this.getDictData()
  146. },
  147. methods: {
  148. a: function(val) {
  149. this.$refs.dictItem.doSubmit(val)
  150. },
  151. // 获取字典详情
  152. getDictData: function() {
  153. this.loading = true
  154. const params = new URLSearchParams()
  155. params.append('current', this.currentPage)
  156. params.append('size', this.pageSize)
  157. getDict(params).then(res => {
  158. console.log(res)
  159. this.data = res.data.data.records
  160. this.total = res.data.data.total
  161. this.loading = false
  162. })
  163. },
  164. // 字典名称提交动作
  165. doSubmit() {
  166. this.$refs['form'].validate((valid) => {
  167. if (valid) {
  168. if (this.isAdd) {
  169. // 新增字典
  170. saveDict(this.form).then((res) => {
  171. if (res.data.code === 200) {
  172. this.$message({ message: '操作成功', type: 'success' })
  173. } else {
  174. this.$message({ message: res.data.msg, type: 'error' })
  175. }
  176. this.dialog = false
  177. this.getDictData()
  178. this.$refs['form'].resetFields()
  179. })
  180. } else {
  181. // 更新字典
  182. updateDict(this.form).then((res) => {
  183. if (res.data.code === 200) {
  184. this.$message({ message: '操作成功', type: 'success' })
  185. } else {
  186. this.$message({ message: res.data.msg, type: 'error' })
  187. }
  188. this.dialog = false
  189. this.getDictData()
  190. })
  191. }
  192. }
  193. })
  194. },
  195. // 添加字典
  196. handleAdd: function() {
  197. this.dialog = true
  198. this.isAdd = true
  199. this.form = {}
  200. },
  201. // 编辑字典
  202. handleEdit: function(row) {
  203. this.dialog = true
  204. this.isAdd = false
  205. this.form = row
  206. },
  207. // 删除操作
  208. subDelete(val) {
  209. deleteDict(val).then(res => {
  210. if (res.data.code === 200) {
  211. this.delLoading = false
  212. this.$message({ message: '删除成功', type: 'success' })
  213. this.getDictData()
  214. }
  215. }).catch(err => {
  216. this.delLoading = false
  217. console.log(err.response.data.message)
  218. })
  219. },
  220. // 换页
  221. handleCurrentChange: function(val) {
  222. this.currentPage = val
  223. this.getDictData()
  224. }
  225. }
  226. }
  227. </script>
  228. <style scoped>
  229. </style>