index.vue 11 KB

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