index.vue 11 KB

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