index.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <template>
  2. <div class="sy-content">
  3. <el-row>
  4. <el-col :span="24">
  5. <!-- 表单查询 -->
  6. <el-form ref="queryForm" :model="queryParams" :inline="true" size="small">
  7. <el-form-item label="字典描述" prop="description">
  8. <el-input v-model="queryParams.description" placeholder="请输入字典描述" clear />
  9. </el-form-item>
  10. <el-form-item label="字典类型" prop="dictKeyType">
  11. <el-input v-model="queryParams.dictKeyType" placeholder="请输入字典类型" clear />
  12. </el-form-item>
  13. <el-form-item>
  14. <el-button type="primary" icon="el-icon-search" size="mini" @click="handelSearch">搜索</el-button>
  15. <el-button icon="el-icon-refresh" size="mini" @click="handelReset">重置</el-button>
  16. </el-form-item>
  17. </el-form>
  18. <el-row class="czBtns">
  19. <el-col>
  20. <el-button size="mini" icon="el-icon-plus" type="primary" plain @click="handelAdd">新增</el-button>
  21. <el-button
  22. type="danger"
  23. plain
  24. icon="el-icon-delete-solid"
  25. size="mini"
  26. :disabled="multiple"
  27. @click="handelDelAll"
  28. >批量删除</el-button>
  29. </el-col>
  30. </el-row>
  31. <!-- 表格数据信息 -->
  32. <el-table
  33. ref="dictTable"
  34. v-loading="loading"
  35. :data="dictList"
  36. row-key="id"
  37. border
  38. stripe
  39. header-row-class-name="headBackground"
  40. @selection-change="handleSelectionChange"
  41. >
  42. <el-table-column type="selection" width="50" align="center" />
  43. <el-table-column key="description" label="字典描述" align="center" prop="description" />
  44. <el-table-column key="dictKeyType" label="字典类型" align="center" prop="dictKeyType" />
  45. <el-table-column key="dictKeyValue" label="字典值" align="center" prop="dictKeyValue">
  46. <template slot-scope="scope">
  47. <el-link type="primary" @click="hendelTo(scope.row)">{{ scope.row.dictKeyValue }}</el-link>
  48. </template>
  49. </el-table-column>
  50. <el-table-column key="sortNum" label="排序号" align="center" prop="sortNum" />
  51. <el-table-column label="操作" align="center" width="250" class-name="small-padding fixed-width">
  52. <template slot-scope="scope">
  53. <el-button size="mini" type="text" icon="el-icon-edit" @click="handelEdit(scope.row)">修改
  54. </el-button>
  55. <el-button
  56. size="mini"
  57. type="text"
  58. icon="el-icon-delete"
  59. :disabled="!multiple"
  60. @click="handelDel(scope.row.id)"
  61. >删除
  62. </el-button>
  63. </template>
  64. </el-table-column>
  65. </el-table>
  66. <!-- 分页信息 -->
  67. <pagination
  68. v-show="total > 0"
  69. :total="total"
  70. :page.sync="queryParams.page"
  71. :limit.sync="queryParams.num"
  72. align="right"
  73. @pagination="getAllDictType"
  74. />
  75. </el-col>
  76. </el-row>
  77. <!-- 弹出框 -->
  78. <el-dialog :title="title" :visible.sync="dialogVisible" width="600px" append-to-body :close-on-click-modal="false">
  79. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  80. <el-form-item label="字典描述" prop="description">
  81. <el-input v-model.trim="form.description" clearable placeholder="请输入字典描述" />
  82. </el-form-item>
  83. <el-form-item label="字典类型" prop="dictKeyType">
  84. <el-input v-model.trim="form.dictKeyType" clearable placeholder="请输入字典类型" />
  85. </el-form-item>
  86. <el-form-item label="字典值" prop="dictKeyValue">
  87. <el-input v-model.trim="form.dictKeyValue" clearable placeholder="请输入字典值" />
  88. </el-form-item>
  89. <el-form-item label="排序号" prop="sortNum">
  90. <el-input
  91. v-model.trim="form.sortNum"
  92. placeholder="请输入排序号"
  93. controls-position="right"
  94. :minlengh="1"
  95. :maxlength="5"
  96. />
  97. </el-form-item>
  98. </el-form>
  99. <span slot="footer" class="dialog-footer">
  100. <el-button size="mini" type="primary" @click="handelSubmit('form')">确定</el-button>
  101. <el-button size="mini" @click="handelCancel('form')">取消</el-button>
  102. </span>
  103. </el-dialog>
  104. </div>
  105. </template>
  106. <script>
  107. import { getAllDictType, editDictType, addDictType, delDictType } from '@/api/system/dictType.js'
  108. export default {
  109. data() {
  110. const sortNumRule = (rule, value, callback) => {
  111. var reg = /^[1-9][0-9]*$/
  112. if (!value) {
  113. callback(new Error('排序号不能为空'))
  114. }
  115. if (!(reg.test(value))) {
  116. callback(new Error('只能输入正整数'))
  117. }
  118. callback()
  119. }
  120. return {
  121. // 遮罩层
  122. loading: true,
  123. // 查询参数
  124. queryParams: {
  125. page: 1,
  126. num: 10,
  127. description: null,
  128. dictKeyType: null
  129. },
  130. // 总条数
  131. total: 0,
  132. // 表格数据
  133. dictList: [],
  134. // 弹出框
  135. dialogVisible: false,
  136. // 弹出框标题
  137. title: '',
  138. // 弹出框表单
  139. form: {},
  140. // 字典树数据
  141. options: [],
  142. // 表单验证
  143. rules: {
  144. description: [
  145. { required: true, message: '字典描述不能为空', trigger: 'blur' }
  146. ],
  147. dictKeyType: [
  148. { required: true, message: '字典类型不能为空', trigger: 'blur' }
  149. ],
  150. dictKeyValue: [
  151. { required: true, message: '字典值不能为空', trigger: 'blur' }
  152. ],
  153. sortNum: [
  154. { required: true, validator: sortNumRule, trigger: 'blur' }
  155. ]
  156. },
  157. // 控制批量删除按钮
  158. multiple: true,
  159. // 删除字典id集合
  160. ids: [],
  161. // 自定义treeselect键名
  162. keyName: null,
  163. // 当前分页数据条数
  164. dictTotal: null
  165. }
  166. },
  167. created() {
  168. this.getAllDictType()
  169. },
  170. methods: {
  171. /** 查询所有字典类型 */
  172. getAllDictType() {
  173. getAllDictType(this.queryParams).then(res => {
  174. if (res.code === 200 & res.data === null) {
  175. this.dictList = []
  176. this.total = 0
  177. return
  178. }
  179. const data = res.data
  180. this.dictList = data.dictTypes
  181. this.total = data.count
  182. this.loading = false
  183. })
  184. },
  185. /** 搜索 */
  186. handelSearch(event) {
  187. this.$resetBtn(event)
  188. this.queryParams.page = 1
  189. this.getAllDictType()
  190. },
  191. /** 重置按钮操作 */
  192. handelReset(event) {
  193. this.$refs['queryForm'].resetFields()
  194. this.handelSearch(event)
  195. },
  196. /** 新增按钮 */
  197. handelAdd() {
  198. this.dialogVisible = true
  199. this.title = '添加字典'
  200. },
  201. /** 修改按钮 */
  202. handelEdit(row) {
  203. this.form = JSON.parse(JSON.stringify(row))
  204. this.dialogVisible = true
  205. this.title = '修改字典'
  206. },
  207. /** 表格多选 */
  208. handleSelectionChange(val) {
  209. this.ids = val.map(item => item.id)
  210. this.multiple = !val.length
  211. },
  212. /** 删除按钮 */
  213. handelDel(id) {
  214. this.$confirm('您确定要删除该字典吗?', '提示', {
  215. confirmButtonText: '确定',
  216. cancelButtonText: '取消',
  217. cancelButtonClass: 'btn_custom_cancel',
  218. closeOnClickModal: false,
  219. type: 'warning'
  220. }).then(() => {
  221. if (this.dictList.length === 1) {
  222. this.queryParams.page -= 1
  223. }
  224. this.ids.push(id)
  225. this.delDictType()
  226. }).catch(() => {
  227. this.$message({
  228. type: 'info',
  229. message: '已取消删除'
  230. })
  231. })
  232. },
  233. /** 批量删除 */
  234. handelDelAll() {
  235. this.$confirm('您确定要批量删除选中的字典吗?', '提示', {
  236. confirmButtonText: '确定',
  237. cancelButtonText: '取消',
  238. cancelButtonClass: 'btn_custom_cancel',
  239. closeOnClickModal: false,
  240. type: 'warning'
  241. }).then(() => {
  242. if (this.ids.length === this.dictList.length) {
  243. this.queryParams.page -= 1
  244. }
  245. this.delDictType()
  246. }).catch(() => {
  247. this.$refs.dictTable.clearSelection()
  248. this.$message({
  249. type: 'info',
  250. message: '已取消删除'
  251. })
  252. })
  253. },
  254. /** 删除接口 */
  255. delDictType() {
  256. delDictType(this.ids).then(res => {
  257. if (res.code === 200) {
  258. this.$message({
  259. type: 'success',
  260. message: '删除成功'
  261. })
  262. this.getAllDictType()
  263. }
  264. })
  265. },
  266. /** 表单提交 */
  267. handelSubmit(formName) {
  268. this.$refs[formName].validate((valid) => {
  269. if (valid) {
  270. if (this.title === '添加字典') {
  271. addDictType(this.form).then(res => {
  272. if (res.code === 200) {
  273. this.$message({
  274. message: res.data,
  275. type: 'success'
  276. })
  277. this.getAllDictType()
  278. this.dialogVisible = false
  279. }
  280. })
  281. } else {
  282. editDictType(this.form).then(res => {
  283. if (res.code === 200) {
  284. this.$message({
  285. message: '修改成功',
  286. type: 'success'
  287. })
  288. this.getAllDictType()
  289. this.dialogVisible = false
  290. }
  291. })
  292. }
  293. }
  294. })
  295. },
  296. /** 表单取消 */
  297. handelCancel() {
  298. this.dialogVisible = false
  299. this.reset()
  300. },
  301. /** 表单重置 */
  302. reset() {
  303. this.form = {}
  304. if (this.$refs['form']) {
  305. this.$refs['form'].resetFields()
  306. }
  307. },
  308. /** 选择字典类型跳转 */
  309. hendelTo(row) {
  310. this.$router.push({
  311. path: '/system/dict/dict-detail/role/',
  312. query: row
  313. })
  314. }
  315. }
  316. }
  317. </script>
  318. <style lang="scss" rel="stylesheet/scss" scoped>
  319. </style>