data.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. <template>
  2. <div class="app-container">
  3. <el-form
  4. :model="queryParams"
  5. ref="queryForm"
  6. size="small"
  7. :inline="true"
  8. v-show="showSearch"
  9. label-width="68px"
  10. >
  11. <el-form-item label="字典名称" prop="dictType">
  12. <el-select v-model="queryParams.dictType">
  13. <el-option
  14. v-for="item in typeOptions"
  15. :key="item.dictId"
  16. :label="item.dictName"
  17. :value="item.dictType"
  18. />
  19. </el-select>
  20. </el-form-item>
  21. <el-form-item label="字典标签" prop="dictLabel">
  22. <el-input
  23. v-model="queryParams.dictLabel"
  24. placeholder="请输入字典标签"
  25. clearable
  26. @keyup.enter.native="handleQuery"
  27. />
  28. </el-form-item>
  29. <el-form-item label="状态" prop="status">
  30. <el-select
  31. v-model="queryParams.status"
  32. placeholder="数据状态"
  33. clearable
  34. >
  35. <el-option
  36. v-for="dict in dict.type.sys_normal_disable"
  37. :key="dict.value"
  38. :label="dict.label"
  39. :value="dict.value"
  40. />
  41. </el-select>
  42. </el-form-item>
  43. <el-form-item>
  44. <el-button
  45. type="primary"
  46. icon="el-icon-search"
  47. size="mini"
  48. @click="handleQuery"
  49. >搜索</el-button
  50. >
  51. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
  52. >重置</el-button
  53. >
  54. </el-form-item>
  55. </el-form>
  56. <el-row :gutter="10" class="mb8">
  57. <el-col :span="1.5">
  58. <el-button
  59. type="primary"
  60. icon="el-icon-plus"
  61. size="mini"
  62. @click="handleAdd"
  63. v-hasPermi="['system:dict:add']"
  64. >新增</el-button
  65. >
  66. </el-col>
  67. <!-- <el-col :span="1.5">
  68. <el-button
  69. type="success"
  70. plain
  71. icon="el-icon-edit-outline"
  72. size="mini"
  73. :disabled="single"
  74. @click="handleUpdate"
  75. v-hasPermi="['system:dict:edit']"
  76. >修改</el-button>
  77. </el-col>
  78. <el-col :span="1.5">
  79. <el-button
  80. type="danger"
  81. plain
  82. icon="el-icon-delete"
  83. size="mini"
  84. :disabled="multiple"
  85. @click="handleDelete"
  86. v-hasPermi="['system:dict:remove']"
  87. >删除</el-button>
  88. </el-col>
  89. <el-col :span="1.5">
  90. <el-button
  91. type="warning"
  92. plain
  93. icon="el-icon-download"
  94. size="mini"
  95. @click="handleExport"
  96. v-hasPermi="['system:dict:export']"
  97. >导出</el-button>
  98. </el-col> -->
  99. <el-col :span="1.5">
  100. <el-button
  101. type="warning"
  102. plain
  103. icon="el-icon-close"
  104. size="mini"
  105. @click="handleClose"
  106. >关闭</el-button
  107. >
  108. </el-col>
  109. <right-toolbar
  110. :showSearch.sync="showSearch"
  111. @queryTable="getList"
  112. ></right-toolbar>
  113. </el-row>
  114. <el-table
  115. border
  116. height="700"
  117. size="small"
  118. v-loading="loading"
  119. :data="dataList"
  120. @selection-change="handleSelectionChange"
  121. >
  122. <!-- <el-table-column type="selection" width="55" align="center" /> -->
  123. <el-table-column label="字典编码" align="center" prop="dictCode" />
  124. <el-table-column label="字典标签" align="center" prop="dictLabel">
  125. <template slot-scope="scope">
  126. <span
  127. v-if="scope.row.listClass == '' || scope.row.listClass == 'default'"
  128. >{{ scope.row.dictLabel }}</span
  129. >
  130. <el-tag
  131. v-else
  132. :type="scope.row.listClass == 'primary' ? '' : scope.row.listClass"
  133. >{{ scope.row.dictLabel }}</el-tag
  134. >
  135. </template>
  136. </el-table-column>
  137. <el-table-column label="字典键值" align="center" prop="dictValue" />
  138. <el-table-column label="字典排序" align="center" prop="dictSort" />
  139. <el-table-column label="状态" align="center" prop="status">
  140. <template slot-scope="scope">
  141. <dict-tag
  142. :options="dict.type.sys_normal_disable"
  143. :value="scope.row.status"
  144. />
  145. </template>
  146. </el-table-column>
  147. <el-table-column
  148. label="备注"
  149. align="center"
  150. prop="remark"
  151. :show-overflow-tooltip="true"
  152. >
  153. </el-table-column>
  154. <el-table-column
  155. label="创建时间"
  156. align="center"
  157. prop="createTime"
  158. width="180"
  159. >
  160. <template slot-scope="scope">
  161. <span>{{ parseTime(scope.row.createTime) }}</span>
  162. </template>
  163. </el-table-column>
  164. <el-table-column
  165. label="操作"
  166. align="center"
  167. class-name="small-padding fixed-width"
  168. >
  169. <template slot-scope="scope">
  170. <el-button
  171. size="mini"
  172. type="text"
  173. icon="el-icon-edit-outline"
  174. @click="handleUpdate(scope.row)"
  175. v-hasPermi="['system:dict:edit']"
  176. >编辑</el-button
  177. >
  178. <el-button
  179. size="mini"
  180. type="text"
  181. icon="el-icon-delete"
  182. @click="handleDelete(scope.row)"
  183. v-hasPermi="['system:dict:remove']"
  184. >删除</el-button
  185. >
  186. </template>
  187. </el-table-column>
  188. </el-table>
  189. <pagination
  190. v-show="total > 0"
  191. :total="total"
  192. :page.sync="queryParams.pageNum"
  193. :limit.sync="queryParams.pageSize"
  194. @pagination="getList"
  195. />
  196. <!-- 添加或修改参数配置对话框 -->
  197. <DialogCom :title="title" :visible.sync="open" width="700px" append-to-body>
  198. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  199. <el-row>
  200. <el-col :span="12">
  201. <el-form-item label="字典类型">
  202. <el-input v-model="form.dictType" :disabled="true" />
  203. </el-form-item>
  204. </el-col>
  205. <el-col :span="12">
  206. <el-form-item label="数据标签" prop="dictLabel">
  207. <el-input v-model="form.dictLabel" placeholder="请输入数据标签" />
  208. </el-form-item>
  209. </el-col>
  210. </el-row>
  211. <el-row>
  212. <el-col :span="12">
  213. <el-form-item label="数据键值" prop="dictValue">
  214. <el-input v-model="form.dictValue" placeholder="请输入数据键值" />
  215. </el-form-item>
  216. </el-col>
  217. <el-col :span="12">
  218. <el-form-item label="样式属性" prop="cssClass">
  219. <el-input v-model="form.cssClass" placeholder="请输入样式属性" />
  220. </el-form-item>
  221. </el-col>
  222. </el-row>
  223. <el-row>
  224. <el-col :span="12">
  225. <el-form-item label="显示排序" prop="dictSort">
  226. <el-input-number
  227. style="width: 100%"
  228. v-model="form.dictSort"
  229. controls-position="right"
  230. :min="0"
  231. />
  232. </el-form-item>
  233. </el-col>
  234. <el-col :span="12">
  235. <el-form-item label="回显样式" prop="listClass">
  236. <el-select style="width: 100%" v-model="form.listClass">
  237. <el-option
  238. v-for="item in listClassOptions"
  239. :key="item.value"
  240. :label="item.label + '(' + item.value + ')'"
  241. :value="item.value"
  242. ></el-option>
  243. </el-select>
  244. </el-form-item>
  245. </el-col>
  246. </el-row>
  247. <el-row>
  248. <el-col :span="12">
  249. <el-form-item label="状态" prop="status">
  250. <el-radio-group v-model="form.status">
  251. <el-radio
  252. v-for="dict in dict.type.sys_normal_disable"
  253. :key="dict.value"
  254. :label="dict.value"
  255. >{{ dict.label }}</el-radio
  256. >
  257. </el-radio-group>
  258. </el-form-item>
  259. </el-col>
  260. </el-row>
  261. <el-form-item label="备注" prop="remark">
  262. <el-input
  263. v-model="form.remark"
  264. type="textarea"
  265. placeholder="请输入内容"
  266. ></el-input>
  267. </el-form-item>
  268. </el-form>
  269. <div slot="footer" class="dialog-footer">
  270. <el-button type="primary" @click="submitForm">确 定</el-button>
  271. <el-button @click="cancel">取 消</el-button>
  272. </div>
  273. </DialogCom>
  274. </div>
  275. </template>
  276. <script>
  277. import {
  278. listData,
  279. getData,
  280. delData,
  281. addData,
  282. updateData,
  283. } from "@/api/system/dict/data";
  284. import {
  285. optionselect as getDictOptionselect,
  286. getType,
  287. } from "@/api/system/dict/type";
  288. export default {
  289. name: "Data",
  290. dicts: ["sys_normal_disable"],
  291. data() {
  292. return {
  293. // 遮罩层
  294. loading: true,
  295. // 选中数组
  296. ids: [],
  297. // 非单个禁用
  298. single: true,
  299. // 非多个禁用
  300. multiple: true,
  301. // 显示搜索条件
  302. showSearch: true,
  303. // 总条数
  304. total: 0,
  305. // 字典表格数据
  306. dataList: [],
  307. // 默认字典类型
  308. defaultDictType: "",
  309. // 弹出层标题
  310. title: "",
  311. // 是否显示弹出层
  312. open: false,
  313. // 数据标签回显样式
  314. listClassOptions: [
  315. {
  316. value: "default",
  317. label: "默认",
  318. },
  319. {
  320. value: "primary",
  321. label: "主要",
  322. },
  323. {
  324. value: "success",
  325. label: "成功",
  326. },
  327. {
  328. value: "info",
  329. label: "信息",
  330. },
  331. {
  332. value: "warning",
  333. label: "警告",
  334. },
  335. {
  336. value: "danger",
  337. label: "危险",
  338. },
  339. ],
  340. // 类型数据字典
  341. typeOptions: [],
  342. // 查询参数
  343. queryParams: {
  344. pageNum: 1,
  345. pageSize: 10,
  346. dictName: undefined,
  347. dictType: undefined,
  348. status: undefined,
  349. },
  350. // 表单参数
  351. form: {},
  352. // 表单校验
  353. rules: {
  354. dictLabel: [
  355. { required: true, message: "数据标签不能为空", trigger: "blur" },
  356. ],
  357. dictValue: [
  358. { required: true, message: "数据键值不能为空", trigger: "blur" },
  359. ],
  360. dictSort: [
  361. { required: true, message: "数据顺序不能为空", trigger: "blur" },
  362. ],
  363. },
  364. };
  365. },
  366. created() {
  367. const dictId = this.$route.params && this.$route.params.dictId;
  368. this.getType(dictId);
  369. this.getTypeList();
  370. },
  371. methods: {
  372. /** 查询字典类型详细 */
  373. getType(dictId) {
  374. getType(dictId).then((response) => {
  375. this.queryParams.dictType = response.data.dictType;
  376. this.defaultDictType = response.data.dictType;
  377. this.getList();
  378. });
  379. },
  380. /** 查询字典类型列表 */
  381. getTypeList() {
  382. getDictOptionselect().then((response) => {
  383. this.typeOptions = response.data;
  384. });
  385. },
  386. /** 查询字典数据列表 */
  387. getList() {
  388. this.loading = true;
  389. listData(this.queryParams).then((response) => {
  390. this.dataList = response.rows;
  391. this.total = response.total;
  392. this.loading = false;
  393. });
  394. },
  395. // 取消按钮
  396. cancel() {
  397. this.open = false;
  398. this.reset();
  399. },
  400. // 表单重置
  401. reset() {
  402. this.form = {
  403. dictCode: undefined,
  404. dictLabel: undefined,
  405. dictValue: undefined,
  406. cssClass: undefined,
  407. listClass: "default",
  408. dictSort: 0,
  409. status: "0",
  410. remark: undefined,
  411. };
  412. this.resetForm("form");
  413. },
  414. /** 搜索按钮操作 */
  415. handleQuery() {
  416. this.queryParams.pageNum = 1;
  417. this.getList();
  418. },
  419. /** 返回按钮操作 */
  420. handleClose() {
  421. const obj = { path: "/system/dict" };
  422. this.$tab.closeOpenPage(obj);
  423. },
  424. /** 重置按钮操作 */
  425. resetQuery() {
  426. this.resetForm("queryForm");
  427. this.queryParams.dictType = this.defaultDictType;
  428. this.handleQuery();
  429. },
  430. /** 新增按钮操作 */
  431. handleAdd() {
  432. this.reset();
  433. this.open = true;
  434. this.title = "新增";
  435. this.form.dictType = this.queryParams.dictType;
  436. },
  437. // 多选框选中数据
  438. handleSelectionChange(selection) {
  439. this.ids = selection.map((item) => item.dictCode);
  440. this.single = selection.length != 1;
  441. this.multiple = !selection.length;
  442. },
  443. /** 修改按钮操作 */
  444. handleUpdate(row) {
  445. this.reset();
  446. const dictCode = row.dictCode || this.ids;
  447. getData(dictCode).then((response) => {
  448. this.form = response.data;
  449. this.open = true;
  450. this.title = "编辑";
  451. });
  452. },
  453. /** 提交按钮 */
  454. submitForm: function () {
  455. this.$refs["form"].validate((valid) => {
  456. if (valid) {
  457. if (this.form.dictCode != undefined) {
  458. updateData(this.form).then((response) => {
  459. this.$store.dispatch(
  460. "dict/removeDict",
  461. this.queryParams.dictType
  462. );
  463. this.$modal.msgSuccess("处理成功");
  464. this.open = false;
  465. this.getList();
  466. });
  467. } else {
  468. addData(this.form).then((response) => {
  469. this.$store.dispatch(
  470. "dict/removeDict",
  471. this.queryParams.dictType
  472. );
  473. this.$modal.msgSuccess("处理成功");
  474. this.open = false;
  475. this.getList();
  476. });
  477. }
  478. }
  479. });
  480. },
  481. /** 删除按钮操作 */
  482. handleDelete(row) {
  483. const dictCodes = row.dictCode || this.ids;
  484. this.$modal
  485. .confirm('是否确认删除字典编码为"' + dictCodes + '"的数据项?')
  486. .then(function () {
  487. return delData(dictCodes);
  488. })
  489. .then(() => {
  490. this.getList();
  491. this.$modal.msgSuccess("删除成功");
  492. this.$store.dispatch("dict/removeDict", this.queryParams.dictType);
  493. })
  494. .catch(() => {});
  495. },
  496. /** 导出按钮操作 */
  497. handleExport() {
  498. this.download(
  499. "system/dict/data/export",
  500. {
  501. ...this.queryParams,
  502. },
  503. `data_${new Date().getTime()}.xlsx`
  504. );
  505. },
  506. },
  507. };
  508. </script>
  509. <style lang="scss" scoped>
  510. .tooltipClass {
  511. width: 300px;
  512. }
  513. </style>
  514. <style >
  515. .el-tooltip__popper {
  516. max-width: 200px;
  517. overflow: hidden;
  518. }
  519. </style>