index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="字典名称" prop="dictName">
  5. <el-input
  6. v-model="queryParams.dictName"
  7. placeholder="请输入字典名称"
  8. clearable
  9. size="small"
  10. style="width: 240px"
  11. @keyup.enter.native="handleQuery"
  12. />
  13. </el-form-item>
  14. <el-form-item label="字典类型" prop="dictType">
  15. <el-input
  16. v-model="queryParams.dictType"
  17. placeholder="请输入字典类型"
  18. clearable
  19. size="small"
  20. style="width: 240px"
  21. @keyup.enter.native="handleQuery"
  22. />
  23. </el-form-item>
  24. <el-form-item label="状态" prop="status">
  25. <el-select
  26. v-model="queryParams.status"
  27. placeholder="字典状态"
  28. clearable
  29. size="small"
  30. style="width: 240px"
  31. >
  32. <el-option
  33. v-for="dict in dict.type.sys_normal_disable"
  34. :key="dict.value"
  35. :label="dict.label"
  36. :value="dict.value"
  37. />
  38. </el-select>
  39. </el-form-item>
  40. <el-form-item label="创建时间">
  41. <el-date-picker
  42. v-model="dateRange"
  43. size="small"
  44. style="width: 240px"
  45. value-format="yyyy-MM-dd"
  46. type="daterange"
  47. range-separator="-"
  48. start-placeholder="开始日期"
  49. end-placeholder="结束日期"
  50. ></el-date-picker>
  51. </el-form-item>
  52. <el-form-item>
  53. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  54. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  55. </el-form-item>
  56. </el-form>
  57. <el-row :gutter="10" class="mb8">
  58. <el-col :span="1.5">
  59. <el-button
  60. type="primary"
  61. plain
  62. icon="el-icon-plus"
  63. size="mini"
  64. @click="handleAdd"
  65. v-hasPermi="['system:dict:add']"
  66. >新增</el-button>
  67. </el-col>
  68. <el-col :span="1.5">
  69. <el-button
  70. type="success"
  71. plain
  72. icon="el-icon-edit"
  73. size="mini"
  74. :disabled="single"
  75. @click="handleUpdate"
  76. v-hasPermi="['system:dict:edit']"
  77. >修改</el-button>
  78. </el-col>
  79. <el-col :span="1.5">
  80. <el-button
  81. type="danger"
  82. plain
  83. icon="el-icon-delete"
  84. size="mini"
  85. :disabled="multiple"
  86. @click="handleDelete"
  87. v-hasPermi="['system:dict:remove']"
  88. >删除</el-button>
  89. </el-col>
  90. <el-col :span="1.5">
  91. <el-button
  92. type="warning"
  93. plain
  94. icon="el-icon-download"
  95. size="mini"
  96. :loading="exportLoading"
  97. @click="handleExport"
  98. v-hasPermi="['system:dict:export']"
  99. >导出</el-button>
  100. </el-col>
  101. <el-col :span="1.5">
  102. <el-button
  103. type="danger"
  104. plain
  105. icon="el-icon-refresh"
  106. size="mini"
  107. @click="handleRefreshCache"
  108. v-hasPermi="['system:dict:remove']"
  109. >刷新缓存</el-button>
  110. </el-col>
  111. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  112. </el-row>
  113. <el-table v-loading="loading" :data="typeList" @selection-change="handleSelectionChange">
  114. <el-table-column type="selection" width="55" align="center" />
  115. <el-table-column label="字典编号" align="center" prop="dictId" />
  116. <el-table-column label="字典名称" align="center" prop="dictName" :show-overflow-tooltip="true" />
  117. <el-table-column label="字典类型" align="center" :show-overflow-tooltip="true">
  118. <template slot-scope="scope">
  119. <router-link :to="'/system/dict-data/index/' + scope.row.dictId" class="link-type">
  120. <span>{{ scope.row.dictType }}</span>
  121. </router-link>
  122. </template>
  123. </el-table-column>
  124. <el-table-column label="状态" align="center" prop="status">
  125. <template slot-scope="scope">
  126. <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status"/>
  127. </template>
  128. </el-table-column>
  129. <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />
  130. <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  131. <template slot-scope="scope">
  132. <span>{{ parseTime(scope.row.createTime) }}</span>
  133. </template>
  134. </el-table-column>
  135. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  136. <template slot-scope="scope">
  137. <el-button
  138. size="mini"
  139. type="text"
  140. icon="el-icon-edit"
  141. @click="handleUpdate(scope.row)"
  142. v-hasPermi="['system:dict:edit']"
  143. >修改</el-button>
  144. <el-button
  145. size="mini"
  146. type="text"
  147. icon="el-icon-delete"
  148. @click="handleDelete(scope.row)"
  149. v-hasPermi="['system:dict:remove']"
  150. >删除</el-button>
  151. </template>
  152. </el-table-column>
  153. </el-table>
  154. <pagination
  155. v-show="total>0"
  156. :total="total"
  157. :page.sync="queryParams.pageNum"
  158. :limit.sync="queryParams.pageSize"
  159. @pagination="getList"
  160. />
  161. <!-- 添加或修改参数配置对话框 -->
  162. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  163. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  164. <el-form-item label="字典名称" prop="dictName">
  165. <el-input v-model="form.dictName" placeholder="请输入字典名称" />
  166. </el-form-item>
  167. <el-form-item label="字典类型" prop="dictType">
  168. <el-input v-model="form.dictType" placeholder="请输入字典类型" />
  169. </el-form-item>
  170. <el-form-item label="状态" prop="status">
  171. <el-radio-group v-model="form.status">
  172. <el-radio
  173. v-for="dict in dict.type.sys_normal_disable"
  174. :key="dict.value"
  175. :label="dict.value"
  176. >{{dict.label}}</el-radio>
  177. </el-radio-group>
  178. </el-form-item>
  179. <el-form-item label="备注" prop="remark">
  180. <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
  181. </el-form-item>
  182. </el-form>
  183. <div slot="footer" class="dialog-footer">
  184. <el-button type="primary" @click="submitForm">确 定</el-button>
  185. <el-button @click="cancel">取 消</el-button>
  186. </div>
  187. </el-dialog>
  188. </div>
  189. </template>
  190. <script>
  191. import { listType, getType, delType, addType, updateType, exportType, refreshCache } from "@/api/system/dict/type";
  192. export default {
  193. name: "Dict",
  194. dicts: ['sys_normal_disable'],
  195. data() {
  196. return {
  197. // 遮罩层
  198. loading: true,
  199. // 导出遮罩层
  200. exportLoading: false,
  201. // 选中数组
  202. ids: [],
  203. // 非单个禁用
  204. single: true,
  205. // 非多个禁用
  206. multiple: true,
  207. // 显示搜索条件
  208. showSearch: true,
  209. // 总条数
  210. total: 0,
  211. // 字典表格数据
  212. typeList: [],
  213. // 弹出层标题
  214. title: "",
  215. // 是否显示弹出层
  216. open: false,
  217. // 日期范围
  218. dateRange: [],
  219. // 查询参数
  220. queryParams: {
  221. pageNum: 1,
  222. pageSize: 10,
  223. dictName: undefined,
  224. dictType: undefined,
  225. status: undefined
  226. },
  227. // 表单参数
  228. form: {},
  229. // 表单校验
  230. rules: {
  231. dictName: [
  232. { required: true, message: "字典名称不能为空", trigger: "blur" }
  233. ],
  234. dictType: [
  235. { required: true, message: "字典类型不能为空", trigger: "blur" }
  236. ]
  237. }
  238. };
  239. },
  240. created() {
  241. this.getList();
  242. },
  243. methods: {
  244. /** 查询字典类型列表 */
  245. getList() {
  246. this.loading = true;
  247. listType(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
  248. this.typeList = response.rows;
  249. this.total = response.total;
  250. this.loading = false;
  251. }
  252. );
  253. },
  254. // 取消按钮
  255. cancel() {
  256. this.open = false;
  257. this.reset();
  258. },
  259. // 表单重置
  260. reset() {
  261. this.form = {
  262. dictId: undefined,
  263. dictName: undefined,
  264. dictType: undefined,
  265. status: "0",
  266. remark: undefined
  267. };
  268. this.resetForm("form");
  269. },
  270. /** 搜索按钮操作 */
  271. handleQuery() {
  272. this.queryParams.pageNum = 1;
  273. this.getList();
  274. },
  275. /** 重置按钮操作 */
  276. resetQuery() {
  277. this.dateRange = [];
  278. this.resetForm("queryForm");
  279. this.handleQuery();
  280. },
  281. /** 新增按钮操作 */
  282. handleAdd() {
  283. this.reset();
  284. this.open = true;
  285. this.title = "添加字典类型";
  286. },
  287. // 多选框选中数据
  288. handleSelectionChange(selection) {
  289. this.ids = selection.map(item => item.dictId)
  290. this.single = selection.length!=1
  291. this.multiple = !selection.length
  292. },
  293. /** 修改按钮操作 */
  294. handleUpdate(row) {
  295. this.reset();
  296. const dictId = row.dictId || this.ids
  297. getType(dictId).then(response => {
  298. this.form = response.data;
  299. this.open = true;
  300. this.title = "修改字典类型";
  301. });
  302. },
  303. /** 提交按钮 */
  304. submitForm: function() {
  305. this.$refs["form"].validate(valid => {
  306. if (valid) {
  307. if (this.form.dictId != undefined) {
  308. updateType(this.form).then(response => {
  309. this.$modal.msgSuccess("修改成功");
  310. this.open = false;
  311. this.getList();
  312. });
  313. } else {
  314. addType(this.form).then(response => {
  315. this.$modal.msgSuccess("新增成功");
  316. this.open = false;
  317. this.getList();
  318. });
  319. }
  320. }
  321. });
  322. },
  323. /** 删除按钮操作 */
  324. handleDelete(row) {
  325. const dictIds = row.dictId || this.ids;
  326. this.$modal.confirm('是否确认删除字典编号为"' + dictIds + '"的数据项?').then(function() {
  327. return delType(dictIds);
  328. }).then(() => {
  329. this.getList();
  330. this.$modal.msgSuccess("删除成功");
  331. }).catch(() => {});
  332. },
  333. /** 导出按钮操作 */
  334. handleExport() {
  335. const queryParams = this.queryParams;
  336. this.$modal.confirm('是否确认导出所有类型数据项?').then(() => {
  337. this.exportLoading = true;
  338. return exportType(queryParams);
  339. }).then(response => {
  340. this.$download.name(response.msg);
  341. this.exportLoading = false;
  342. }).catch(() => {});
  343. },
  344. /** 刷新缓存按钮操作 */
  345. handleRefreshCache() {
  346. refreshCache().then(() => {
  347. this.$modal.msgSuccess("刷新成功");
  348. });
  349. }
  350. }
  351. };
  352. </script>