dict.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" size="mini" :inline="true">
  4. <el-form-item label="字典名称" prop="dictName">
  5. <el-input
  6. v-model="queryParams.dictName"
  7. placeholder="请输入字典名称"
  8. clearable
  9. style="width: 200px"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item label="字典类型" prop="dictType">
  14. <el-input
  15. v-model="queryParams.dictType"
  16. placeholder="请输入字典类型"
  17. clearable
  18. style="width: 200px"
  19. @keyup.enter.native="handleQuery"
  20. />
  21. </el-form-item>
  22. <el-form-item label="状态" prop="status">
  23. <el-select
  24. v-model="queryParams.status"
  25. placeholder="字典状态"
  26. clearable
  27. style="width: 200px">
  28. <el-option
  29. v-for="dict in sysStatusDicts"
  30. :key="dict.dictValue"
  31. :label="dict.dictLabel"
  32. :value="dict.dictValue"/>
  33. <!-- <el-option :key="0" label="正常" :value="0"/>-->
  34. <!-- <el-option :key="1" label="停用" :value="1"/>-->
  35. </el-select>
  36. </el-form-item>
  37. <el-form-item>
  38. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  39. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  40. </el-form-item>
  41. </el-form>
  42. <el-row :gutter="10" class="mb8">
  43. <el-col :span="1.5">
  44. <el-button
  45. type="primary"
  46. plain
  47. icon="el-icon-plus"
  48. size="mini"
  49. @click="handleAdd"
  50. v-hasPermi="['system:dict:add']"
  51. >新增
  52. </el-button>
  53. </el-col>
  54. <el-col :span="1.5">
  55. <el-button
  56. type="primary"
  57. plain
  58. icon="el-icon-refresh"
  59. size="mini"
  60. @click="handleRefresh"
  61. v-hasPermi="['system:dict:list']"
  62. >刷新缓存
  63. </el-button>
  64. </el-col>
  65. </el-row>
  66. <el-table :data="dictList" size="mini">
  67. <el-table-column type="expand">
  68. <template slot-scope="props">
  69. <el-descriptions v-for="(dictData,index) in props.row.dictDataList" :key="index" :column="4" size="mini">
  70. <el-descriptions-item label="标签">{{ dictData.dictLabel }}</el-descriptions-item>
  71. <el-descriptions-item label="键值">{{ dictData.dictValue }}</el-descriptions-item>
  72. <el-descriptions-item label="排序">{{ dictData.dictSort }}</el-descriptions-item>
  73. <el-descriptions-item label="备注">{{ dictData.remark }}</el-descriptions-item>
  74. </el-descriptions>
  75. </template>
  76. </el-table-column>
  77. <el-table-column label="字典编号" prop="id" width="100"/>
  78. <el-table-column label="字典名称" prop="dictName"/>
  79. <el-table-column label="字典类型" prop="dictType"/>
  80. <el-table-column label="状态" align="center">
  81. <template slot-scope="scope">
  82. <el-switch
  83. v-model="scope.row.status"
  84. active-value="0"
  85. inactive-value="1"
  86. @change="handleStatusChange(scope.row)"
  87. ></el-switch>
  88. </template>
  89. </el-table-column>
  90. <el-table-column label="备注" align="center" prop="remark" width="180"></el-table-column>
  91. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  92. <template slot-scope="scope">
  93. <el-button
  94. size="mini"
  95. type="text"
  96. icon="el-icon-edit"
  97. @click="handleUpdate(scope.row)"
  98. v-hasPermi="['system:dict:edit']"
  99. >修改
  100. </el-button>
  101. <el-button
  102. size="mini"
  103. type="text"
  104. icon="el-icon-delete"
  105. @click="handleDelete(scope.row)"
  106. v-hasPermi="['system:dict:delete']"
  107. >删除
  108. </el-button>
  109. </template>
  110. </el-table-column>
  111. </el-table>
  112. <div style="margin-top: 10px;text-align: center">
  113. <el-pagination
  114. background
  115. @size-change="handleSizeChange"
  116. @current-change="handleCurrentChange"
  117. :current-page="queryParams.pageNum"
  118. :page-sizes="[10, 20, 50]"
  119. :page-size="queryParams.pageSize"
  120. layout="total, sizes, prev, pager, next, jumper"
  121. :total="total">
  122. </el-pagination>
  123. </div>
  124. <!-- 添加或修改字典配置对话框 -->
  125. <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body :close-on-click-modal="false">
  126. <el-form ref="form" :model="form" :rules="rules" size="mini" label-width="80px">
  127. <el-row>
  128. <el-col :span="12">
  129. <el-form-item label="字典名称" prop="dictName">
  130. <el-input v-model="form.dictName" placeholder="请输入字典名称" style="width: 180px"/>
  131. </el-form-item>
  132. </el-col>
  133. <el-col :span="12">
  134. <el-form-item label="字典类型" prop="dictType">
  135. <el-input v-model="form.dictType" placeholder="请输入字典类型" style="width: 180px"/>
  136. </el-form-item>
  137. </el-col>
  138. </el-row>
  139. <el-row>
  140. <el-col :span="12">
  141. <el-form-item label="状态" prop="status">
  142. <el-radio-group v-model="form.status">
  143. <el-radio label="0">正常</el-radio>
  144. <el-radio label="1">停用</el-radio>
  145. </el-radio-group>
  146. </el-form-item>
  147. </el-col>
  148. </el-row>
  149. <el-row>
  150. <el-col :span="22">
  151. <el-form-item label="备注" prop="remark">
  152. <el-input v-model="form.remark" placeholder="请输入内容"></el-input>
  153. </el-form-item>
  154. </el-col>
  155. <el-col :span="2">
  156. <el-button type="text" icon="el-icon-circle-plus-outline"
  157. style="float: right;font-size: 22px; margin-top: -8px" @click="addDictData"></el-button>
  158. </el-col>
  159. </el-row>
  160. <el-row :gutter="10">
  161. <el-col :span="12" v-for="(dictData,index) in form.dictDataList" :key="index">
  162. <el-card shadow="always" class="item-card">
  163. <div slot="header" class="clearfix">
  164. <span>字典数据{{ index + 1 }}</span>
  165. <el-button type="text" icon="el-icon-delete" @click="delDictData(index)"
  166. style="float: right;color: red; padding: 3px 0"></el-button>
  167. </div>
  168. <el-form ref="dictDataForm" :model="dictData" :rules="rules" size="mini" label-width="50px">
  169. <el-form-item label="标签" prop="dictLabel">
  170. <el-input v-model="dictData.dictLabel"/>
  171. </el-form-item>
  172. <el-form-item label="键值" prop="dictValue">
  173. <el-input v-model="dictData.dictValue"/>
  174. </el-form-item>
  175. <el-form-item label="备注" prop="remark">
  176. <el-input v-model="dictData.remark"/>
  177. </el-form-item>
  178. </el-form>
  179. </el-card>
  180. </el-col>
  181. </el-row>
  182. </el-form>
  183. <div slot="footer" class="dialog-footer">
  184. <el-button type="primary" size="mini" @click="submitForm">确 定</el-button>
  185. <el-button size="mini" @click="cancel">取 消</el-button>
  186. </div>
  187. </el-dialog>
  188. </div>
  189. </template>
  190. <script>
  191. import {
  192. listDict,
  193. getDict,
  194. delDict,
  195. addDict,
  196. updateDict, refreshDictCache, getDictData,
  197. } from "@/api/system/dict";
  198. export default {
  199. name: "dict",
  200. data() {
  201. return {
  202. sysStatusDicts:[],
  203. // 总条数
  204. total: 0,
  205. // 字典表格数据
  206. dictList: [],
  207. // 弹出层标题
  208. title: "",
  209. // 是否显示弹出层
  210. open: false,
  211. // 是否显示弹出层(数据权限)
  212. openDataScope: false,
  213. menuExpand: false,
  214. menuNodeAll: false,
  215. deptExpand: true,
  216. deptNodeAll: false,
  217. // 日期范围
  218. dateRange: [],
  219. // 菜单列表
  220. menuOptions: [],
  221. // 部门列表
  222. deptOptions: [],
  223. // 查询参数
  224. queryParams: {
  225. pageNum: 1,
  226. pageSize: 10,
  227. dictName: undefined,
  228. dictType: undefined,
  229. status: undefined
  230. },
  231. // 表单参数
  232. form: {},
  233. defaultProps: {
  234. dictDataList: "dictDataList",
  235. label: "menuName"
  236. },
  237. // 表单校验
  238. rules: {
  239. dictName: [
  240. {required: true, message: "字典名称不能为空", trigger: "blur"}
  241. ],
  242. dictType: [
  243. {required: true, message: "字典类型不能为空", trigger: "blur"}
  244. ],
  245. dictSort: [
  246. {required: true, message: "字典顺序不能为空", trigger: "blur"}
  247. ]
  248. }
  249. };
  250. },
  251. created() {
  252. this.initData();
  253. },
  254. methods: {
  255. initData(){
  256. this.getList();
  257. getDictData('sys_status').then(res => {
  258. this.sysStatusDicts=res.data
  259. })
  260. },
  261. /** 查询字典列表 */
  262. getList() {
  263. listDict(this.queryParams).then(response => {
  264. this.dictList = response.data.records;
  265. this.total = response.data.total;
  266. }
  267. );
  268. },
  269. // 字典状态修改
  270. handleStatusChange(row) {
  271. let text = row.status === "0" ? "启用" : "停用";
  272. this.$confirm('确认要"' + text + '""' + row.dictName + '"字典吗?').then(function () {
  273. return changeCStatus(row.id, row.status);
  274. }).then(() => {
  275. this.$message.success(text + "成功");
  276. }).catch(function () {
  277. row.status = row.status === "0" ? "1" : "0";
  278. });
  279. },
  280. // 取消按钮
  281. cancel() {
  282. this.open = false;
  283. this.reset();
  284. },
  285. // 取消按钮(数据权限)
  286. cancelDataScope() {
  287. this.openDataScope = false;
  288. this.reset();
  289. },
  290. // 表单重置
  291. reset() {
  292. this.form = {
  293. id: undefined,
  294. dictName: undefined,
  295. dictType: undefined,
  296. dictSort: 0,
  297. status: "0",
  298. remark: undefined,
  299. dictDataList: []
  300. };
  301. this.resetForm("form");
  302. },
  303. /** 搜索按钮操作 */
  304. handleQuery() {
  305. this.queryParams.pageNum = 1;
  306. this.getList();
  307. },
  308. /** 重置按钮操作 */
  309. resetQuery() {
  310. this.dateRange = [];
  311. this.resetForm("queryForm");
  312. this.handleQuery();
  313. },
  314. handleSizeChange(val) {
  315. this.queryParams.pageSize = val;
  316. this.getList();
  317. },
  318. handleCurrentChange(val) {
  319. this.queryParams.pageNum = val;
  320. this.getList();
  321. },
  322. /** 新增按钮操作 */
  323. handleAdd() {
  324. this.reset();
  325. this.open = true;
  326. this.title = "添加字典";
  327. },
  328. /** 刷新字典缓存操作 */
  329. handleRefresh() {
  330. refreshDictCache().then(res => {
  331. if (res.success) {
  332. this.$message({
  333. message: '操作成功!',
  334. type: 'success'
  335. });
  336. }
  337. })
  338. },
  339. /** 修改按钮操作 */
  340. handleUpdate(row) {
  341. this.reset();
  342. const id = row.id || this.ids
  343. getDict(id).then(response => {
  344. this.form = response.data;
  345. this.open = true;
  346. this.title = "修改字典";
  347. });
  348. },
  349. addDictData() {
  350. let child = {
  351. dictLabel: undefined,
  352. dictValue: undefined,
  353. remark: undefined
  354. }
  355. this.form.dictDataList.push(child)
  356. },
  357. /** 提交按钮 */
  358. submitForm() {
  359. this.$refs["form"].validate(valid => {
  360. if (valid) {
  361. if (this.form.id != undefined) {
  362. updateDict(this.form).then(response => {
  363. this.$message.success("修改成功");
  364. this.open = false;
  365. this.getList();
  366. });
  367. } else {
  368. addDict(this.form).then(response => {
  369. this.$message.success("新增成功");
  370. this.open = false;
  371. this.getList();
  372. });
  373. }
  374. }
  375. });
  376. },
  377. /** 删除按钮操作 */
  378. handleDelete(row) {
  379. const ids = row.id || this.ids;
  380. this.$confirm('是否确认删除字典编号为"' + ids + '"的数据项?').then(() => {
  381. return delDict(ids);
  382. }).then(() => {
  383. this.getList();
  384. this.$message.success("删除成功");
  385. }).catch(() => {
  386. });
  387. },
  388. }
  389. };
  390. </script>
  391. <style scoped lang="scss">
  392. .el-form-item--mini.el-form-item, .el-form-item--small.el-form-item {
  393. margin-bottom: 10px;
  394. }
  395. .item-card ::v-deep {
  396. margin-bottom: 10px;
  397. .el-card__header {
  398. padding: 10px 10px 0px 10px;
  399. }
  400. .el-card__body {
  401. padding: 10px;
  402. }
  403. }
  404. </style>