index.vue 11 KB

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