index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  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="dictName">
  12. <el-input
  13. v-model="queryParams.dictName"
  14. placeholder="请输入字典名称"
  15. clearable
  16. style="width: 240px"
  17. @keyup.enter.native="handleQuery"
  18. />
  19. </el-form-item>
  20. <el-form-item label="字典类型" prop="dictType">
  21. <el-input
  22. v-model="queryParams.dictType"
  23. placeholder="请输入字典类型"
  24. clearable
  25. style="width: 240px"
  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. style="width: 240px"
  35. >
  36. <el-option
  37. v-for="dict in dict.type.sys_normal_disable"
  38. :key="dict.value"
  39. :label="dict.label"
  40. :value="dict.value"
  41. />
  42. </el-select>
  43. </el-form-item>
  44. <el-form-item label="创建时间">
  45. <el-date-picker
  46. v-model="dateRange"
  47. style="width: 240px"
  48. value-format="yyyy-MM-dd"
  49. type="daterange"
  50. range-separator="-"
  51. start-placeholder="开始日期"
  52. end-placeholder="结束日期"
  53. ></el-date-picker>
  54. </el-form-item>
  55. <el-form-item>
  56. <el-button
  57. type="primary"
  58. icon="el-icon-search"
  59. size="mini"
  60. @click="handleQuery"
  61. >搜索</el-button
  62. >
  63. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
  64. >重置</el-button
  65. >
  66. </el-form-item>
  67. </el-form>
  68. <el-row :gutter="10" class="mb8">
  69. <el-col :span="1.5">
  70. <el-button
  71. type="primary"
  72. plain
  73. icon="el-icon-plus"
  74. size="mini"
  75. @click="handleAdd"
  76. v-hasPermi="['system:dict:add']"
  77. >新增</el-button
  78. >
  79. </el-col>
  80. <!-- <el-col :span="1.5">
  81. <el-button
  82. type="success"
  83. plain
  84. icon="el-icon-edit"
  85. size="mini"
  86. :disabled="single"
  87. @click="handleUpdate"
  88. v-hasPermi="['system:dict:edit']"
  89. >修改</el-button
  90. >
  91. </el-col> -->
  92. <el-col :span="1.5">
  93. <el-button
  94. type="danger"
  95. plain
  96. icon="el-icon-delete"
  97. size="mini"
  98. :disabled="multiple"
  99. @click="handleDelete"
  100. v-hasPermi="['system:dict:remove']"
  101. >删除</el-button
  102. >
  103. </el-col>
  104. <el-col :span="1.5">
  105. <el-button
  106. v-if="selection.length == 0"
  107. type="warning"
  108. plain
  109. icon="el-icon-download"
  110. size="mini"
  111. @click="handleExport"
  112. v-hasPermi="['system:dict:export']"
  113. >导出</el-button
  114. >
  115. <ExcelDownLoad
  116. v-else
  117. :headerList="headerList"
  118. :fieldList="selection"
  119. :excelTitle="excelTitle"
  120. ></ExcelDownLoad>
  121. </el-col>
  122. <el-col :span="1.5">
  123. <el-button
  124. type="danger"
  125. plain
  126. icon="el-icon-refresh"
  127. size="mini"
  128. @click="handleRefreshCache"
  129. v-hasPermi="['system:dict:remove']"
  130. >刷新缓存</el-button
  131. >
  132. </el-col>
  133. <right-toolbar
  134. :showSearch.sync="showSearch"
  135. @queryTable="getList"
  136. ></right-toolbar>
  137. </el-row>
  138. <el-table
  139. v-loading="loading"
  140. :data="typeList"
  141. @selection-change="handleSelectionChange"
  142. >
  143. <el-table-column type="selection" width="55" align="center" />
  144. <el-table-column label="字典编号" align="center" prop="dictId" />
  145. <el-table-column
  146. label="字典名称"
  147. align="center"
  148. prop="dictName"
  149. :show-overflow-tooltip="true"
  150. />
  151. <el-table-column
  152. label="字典类型"
  153. align="center"
  154. :show-overflow-tooltip="true"
  155. >
  156. <template slot-scope="scope">
  157. <router-link
  158. :to="'/system/dict-data/index/' + scope.row.dictId"
  159. class="link-type"
  160. >
  161. <span>{{ scope.row.dictType }}</span>
  162. </router-link>
  163. </template>
  164. </el-table-column>
  165. <el-table-column label="状态" align="center" prop="status">
  166. <template slot-scope="scope">
  167. <dict-tag
  168. :options="dict.type.sys_normal_disable"
  169. :value="scope.row.status"
  170. />
  171. </template>
  172. </el-table-column>
  173. <el-table-column
  174. label="备注"
  175. align="center"
  176. prop="remark"
  177. :show-overflow-tooltip="true"
  178. />
  179. <el-table-column
  180. label="创建时间"
  181. align="center"
  182. prop="createTime"
  183. width="180"
  184. >
  185. <template slot-scope="scope">
  186. <span>{{ parseTime(scope.row.createTime) }}</span>
  187. </template>
  188. </el-table-column>
  189. <el-table-column
  190. label="操作"
  191. align="center"
  192. class-name="small-padding fixed-width"
  193. >
  194. <template slot-scope="scope">
  195. <el-dropdown>
  196. <el-button type="warning" plain size="small">
  197. 处理<i class="el-icon-arrow-down el-icon--right"></i>
  198. </el-button>
  199. <el-dropdown-menu slot="dropdown">
  200. <el-dropdown-item
  201. ><el-button
  202. size="mini"
  203. type="text"
  204. icon="el-icon-edit"
  205. @click="handleUpdate(scope.row)"
  206. v-hasPermi="['system:dict:edit']"
  207. >修改</el-button
  208. ></el-dropdown-item
  209. >
  210. <el-dropdown-item
  211. ><el-button
  212. size="mini"
  213. type="text"
  214. icon="el-icon-delete"
  215. @click="handleDelete(scope.row)"
  216. v-hasPermi="['system:dict:remove']"
  217. >删除</el-button
  218. >
  219. </el-dropdown-item>
  220. </el-dropdown-menu>
  221. </el-dropdown>
  222. <!-- <el-button
  223. size="mini"
  224. type="text"
  225. icon="el-icon-edit"
  226. @click="handleUpdate(scope.row)"
  227. v-hasPermi="['system:dict:edit']"
  228. >修改</el-button>
  229. <el-button
  230. size="mini"
  231. type="text"
  232. icon="el-icon-delete"
  233. @click="handleDelete(scope.row)"
  234. v-hasPermi="['system:dict:remove']"
  235. >删除</el-button> -->
  236. </template>
  237. </el-table-column>
  238. </el-table>
  239. <pagination
  240. v-show="total > 0"
  241. :total="total"
  242. :page.sync="queryParams.pageNum"
  243. :limit.sync="queryParams.pageSize"
  244. @pagination="getList"
  245. />
  246. <!-- 添加或修改参数配置对话框 -->
  247. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  248. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  249. <el-form-item label="字典名称" prop="dictName">
  250. <el-input v-model="form.dictName" placeholder="请输入字典名称" />
  251. </el-form-item>
  252. <el-form-item label="字典类型" prop="dictType">
  253. <el-input v-model="form.dictType" placeholder="请输入字典类型" />
  254. </el-form-item>
  255. <el-form-item label="状态" prop="status">
  256. <el-radio-group v-model="form.status">
  257. <el-radio
  258. v-for="dict in dict.type.sys_normal_disable"
  259. :key="dict.value"
  260. :label="dict.value"
  261. >{{ dict.label }}</el-radio
  262. >
  263. </el-radio-group>
  264. </el-form-item>
  265. <el-form-item label="备注" prop="remark">
  266. <el-input
  267. v-model="form.remark"
  268. type="textarea"
  269. placeholder="请输入内容"
  270. ></el-input>
  271. </el-form-item>
  272. </el-form>
  273. <div slot="footer" class="dialog-footer">
  274. <el-button type="primary" @click="submitForm">确 定</el-button>
  275. <el-button @click="cancel">取 消</el-button>
  276. </div>
  277. </el-dialog>
  278. </div>
  279. </template>
  280. <script>
  281. import {
  282. listType,
  283. getType,
  284. delType,
  285. addType,
  286. updateType,
  287. refreshCache,
  288. } from "@/api/system/dict/type";
  289. import ExcelDownLoad from "@/components/ExcelDownLoad/index.vue";
  290. export default {
  291. name: "Dict",
  292. dicts: ["sys_normal_disable"],
  293. components: {
  294. ExcelDownLoad,
  295. },
  296. data() {
  297. return {
  298. // 前端导出数据
  299. selection: [],
  300. headerList: {
  301. 字典主键: "dictId",
  302. 字典名称: "dictName",
  303. 字典类型: "dictType",
  304. 状态: "status",
  305. },
  306. excelTitle: "type",
  307. // 遮罩层
  308. loading: true,
  309. // 选中数组
  310. ids: [],
  311. // 非单个禁用
  312. single: true,
  313. // 非多个禁用
  314. multiple: true,
  315. // 显示搜索条件
  316. showSearch: true,
  317. // 总条数
  318. total: 0,
  319. // 字典表格数据
  320. typeList: [],
  321. // 弹出层标题
  322. title: "",
  323. // 是否显示弹出层
  324. open: false,
  325. // 日期范围
  326. dateRange: [],
  327. // 查询参数
  328. queryParams: {
  329. pageNum: 1,
  330. pageSize: 10,
  331. dictName: undefined,
  332. dictType: undefined,
  333. status: undefined,
  334. },
  335. // 表单参数
  336. form: {},
  337. // 表单校验
  338. rules: {
  339. dictName: [
  340. { required: true, message: "字典名称不能为空", trigger: "blur" },
  341. ],
  342. dictType: [
  343. { required: true, message: "字典类型不能为空", trigger: "blur" },
  344. ],
  345. },
  346. };
  347. },
  348. created() {
  349. this.getList();
  350. },
  351. methods: {
  352. /** 查询字典类型列表 */
  353. getList() {
  354. this.loading = true;
  355. listType(this.addDateRange(this.queryParams, this.dateRange)).then(
  356. (response) => {
  357. this.typeList = response.rows;
  358. this.total = response.total;
  359. this.loading = false;
  360. }
  361. );
  362. },
  363. // 取消按钮
  364. cancel() {
  365. this.open = false;
  366. this.reset();
  367. },
  368. // 表单重置
  369. reset() {
  370. this.form = {
  371. dictId: undefined,
  372. dictName: undefined,
  373. dictType: undefined,
  374. status: "0",
  375. remark: undefined,
  376. };
  377. this.resetForm("form");
  378. },
  379. /** 搜索按钮操作 */
  380. handleQuery() {
  381. this.queryParams.pageNum = 1;
  382. this.getList();
  383. },
  384. /** 重置按钮操作 */
  385. resetQuery() {
  386. this.dateRange = [];
  387. this.resetForm("queryForm");
  388. this.handleQuery();
  389. },
  390. /** 新增按钮操作 */
  391. handleAdd() {
  392. this.reset();
  393. this.open = true;
  394. this.title = "添加字典类型";
  395. },
  396. // 多选框选中数据
  397. handleSelectionChange(selection) {
  398. this.ids = selection.map((item) => item.dictId);
  399. this.single = selection.length != 1;
  400. this.multiple = !selection.length;
  401. this.selection = selection;
  402. },
  403. /** 修改按钮操作 */
  404. handleUpdate(row) {
  405. this.reset();
  406. const dictId = row.dictId || this.ids;
  407. getType(dictId).then((response) => {
  408. this.form = response.data;
  409. this.open = true;
  410. this.title = "修改字典类型";
  411. });
  412. },
  413. /** 提交按钮 */
  414. submitForm: function () {
  415. this.$refs["form"].validate((valid) => {
  416. if (valid) {
  417. if (this.form.dictId != undefined) {
  418. updateType(this.form).then((response) => {
  419. this.$modal.msgSuccess("修改成功");
  420. this.open = false;
  421. this.getList();
  422. });
  423. } else {
  424. addType(this.form).then((response) => {
  425. this.$modal.msgSuccess("新增成功");
  426. this.open = false;
  427. this.getList();
  428. });
  429. }
  430. }
  431. });
  432. },
  433. /** 删除按钮操作 */
  434. handleDelete(row) {
  435. const dictIds = row.dictId || this.ids;
  436. this.$modal
  437. .confirm('是否确认删除字典编号为"' + dictIds + '"的数据项?')
  438. .then(function () {
  439. return delType(dictIds);
  440. })
  441. .then(() => {
  442. this.getList();
  443. this.$modal.msgSuccess("删除成功");
  444. })
  445. .catch(() => {});
  446. },
  447. /** 导出按钮操作 */
  448. handleExport() {
  449. this.download(
  450. "system/dict/type/export",
  451. {
  452. ...this.queryParams,
  453. },
  454. `type_${new Date().getTime()}.xlsx`
  455. );
  456. },
  457. /** 刷新缓存按钮操作 */
  458. handleRefreshCache() {
  459. refreshCache().then(() => {
  460. this.$modal.msgSuccess("刷新成功");
  461. this.$store.dispatch("dict/cleanDict");
  462. });
  463. },
  464. },
  465. };
  466. </script>