index.vue 12 KB

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