index.vue 11 KB

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