index.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="字典名称" prop="name">
  5. <el-input v-model="queryParams.name" placeholder="请输入字典名称" clearable style="width: 240px" @keyup.enter.native="handleQuery"/>
  6. </el-form-item>
  7. <el-form-item label="字典类型" prop="type">
  8. <el-input v-model="queryParams.type" placeholder="请输入字典类型" clearable style="width: 240px" @keyup.enter.native="handleQuery"/>
  9. </el-form-item>
  10. <el-form-item label="状态" prop="status">
  11. <el-select v-model="queryParams.status" placeholder="字典状态" clearable style="width: 240px">
  12. <el-option v-for="dict in statusDictDatas" :key="parseInt(dict.value)" :label="dict.label" :value="parseInt(dict.value)"/>
  13. </el-select>
  14. </el-form-item>
  15. <el-form-item label="创建时间" prop="createTime">
  16. <el-date-picker v-model="queryParams.createTime" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss" type="daterange"
  17. range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']" />
  18. </el-form-item>
  19. <el-form-item>
  20. <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
  21. <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
  22. </el-form-item>
  23. </el-form>
  24. <el-row :gutter="10" class="mb8">
  25. <el-col :span="1.5">
  26. <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
  27. v-hasPermi="['system:dict:create']">新增</el-button>
  28. </el-col>
  29. <el-col :span="1.5">
  30. <el-button type="warning" icon="el-icon-download" size="mini" @click="handleExport" :loading="exportLoading"
  31. v-hasPermi="['system:dict:export']">导出</el-button>
  32. </el-col>
  33. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  34. </el-row>
  35. <el-table v-loading="loading" :data="typeList">
  36. <el-table-column label="字典编号" align="center" prop="id" />
  37. <el-table-column label="字典名称" align="center" prop="name" :show-overflow-tooltip="true" />
  38. <el-table-column label="字典类型" align="center" :show-overflow-tooltip="true">
  39. <template slot-scope="scope">
  40. <router-link :to="'/dict/type/data/' + scope.row.id" class="link-type">
  41. <span>{{ scope.row.type }}</span>
  42. </router-link>
  43. </template>
  44. </el-table-column>
  45. <el-table-column label="状态" align="center" prop="status">
  46. <template slot-scope="scope">
  47. <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status"/>
  48. </template>
  49. </el-table-column>
  50. <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />
  51. <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  52. <template slot-scope="scope">
  53. <span>{{ parseTime(scope.row.createTime) }}</span>
  54. </template>
  55. </el-table-column>
  56. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  57. <template slot-scope="scope">
  58. <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
  59. v-hasPermi="['system:dict:update']">修改</el-button>
  60. <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
  61. v-hasPermi="['system:dict:delete']">删除</el-button>
  62. </template>
  63. </el-table-column>
  64. </el-table>
  65. <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
  66. @pagination="getList"/>
  67. <!-- 添加或修改参数配置对话框 -->
  68. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  69. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  70. <el-form-item label="字典名称" prop="name">
  71. <el-input v-model="form.name" placeholder="请输入字典名称" />
  72. </el-form-item>
  73. <el-form-item label="字典类型" prop="type">
  74. <el-input :disabled="typeof form.id !== 'undefined'" v-model="form.type" placeholder="请输入字典类型" />
  75. </el-form-item>
  76. <el-form-item label="状态" prop="status">
  77. <el-radio-group v-model="form.status">
  78. <el-radio v-for="dict in statusDictDatas" :key="parseInt(dict.value)" :label="parseInt(dict.value)">{{dict.label}}</el-radio>
  79. </el-radio-group>
  80. </el-form-item>
  81. <el-form-item label="备注" prop="remark">
  82. <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
  83. </el-form-item>
  84. </el-form>
  85. <div slot="footer" class="dialog-footer">
  86. <el-button type="primary" @click="submitForm">确 定</el-button>
  87. <el-button @click="cancel">取 消</el-button>
  88. </div>
  89. </el-dialog>
  90. </div>
  91. </template>
  92. <script>
  93. import { listType, getType, delType, addType, updateType, exportType } from "@/api/system/dict/type";
  94. import { CommonStatusEnum } from '@/utils/constants'
  95. import { getDictDatas, DICT_TYPE } from '@/utils/dict'
  96. export default {
  97. name: "Dict",
  98. data() {
  99. return {
  100. // 遮罩层
  101. loading: true,
  102. // 导出遮罩层
  103. exportLoading: false,
  104. // 显示搜索条件
  105. showSearch: true,
  106. // 总条数
  107. total: 0,
  108. // 字典表格数据
  109. typeList: [],
  110. // 弹出层标题
  111. title: "",
  112. // 是否显示弹出层
  113. open: false,
  114. // 状态数据字典
  115. statusOptions: [],
  116. // 查询参数
  117. queryParams: {
  118. pageNo: 1,
  119. pageSize: 10,
  120. name: undefined,
  121. type: undefined,
  122. status: undefined,
  123. createTime: []
  124. },
  125. // 表单参数
  126. form: {},
  127. // 表单校验
  128. rules: {
  129. name: [
  130. { required: true, message: "字典名称不能为空", trigger: "blur" }
  131. ],
  132. type: [
  133. { required: true, message: "字典类型不能为空", trigger: "blur" }
  134. ]
  135. },
  136. // 枚举
  137. CommonStatusEnum: CommonStatusEnum,
  138. // 数据字典
  139. statusDictDatas: getDictDatas(DICT_TYPE.COMMON_STATUS)
  140. };
  141. },
  142. created() {
  143. this.getList();
  144. },
  145. methods: {
  146. /** 查询字典类型列表 */
  147. getList() {
  148. this.loading = true;
  149. // 执行查询
  150. listType(this.queryParams).then(response => {
  151. this.typeList = response.data.list;
  152. this.total = response.data.total;
  153. this.loading = false;
  154. });
  155. },
  156. // 取消按钮
  157. cancel() {
  158. this.open = false;
  159. this.reset();
  160. },
  161. // 表单重置
  162. reset() {
  163. this.form = {
  164. id: undefined,
  165. name: undefined,
  166. type: undefined,
  167. status: CommonStatusEnum.ENABLE,
  168. remark: undefined
  169. };
  170. this.resetForm("form");
  171. },
  172. /** 搜索按钮操作 */
  173. handleQuery() {
  174. this.queryParams.pageNo = 1;
  175. this.getList();
  176. },
  177. /** 重置按钮操作 */
  178. resetQuery() {
  179. this.resetForm("queryForm");
  180. this.handleQuery();
  181. },
  182. /** 新增按钮操作 */
  183. handleAdd() {
  184. this.reset();
  185. this.open = true;
  186. this.title = "添加字典类型";
  187. },
  188. /** 修改按钮操作 */
  189. handleUpdate(row) {
  190. this.reset();
  191. const id = row.id;
  192. getType(id).then(response => {
  193. this.form = response.data;
  194. this.open = true;
  195. this.title = "修改字典类型";
  196. });
  197. },
  198. /** 提交按钮 */
  199. submitForm: function() {
  200. this.$refs["form"].validate(valid => {
  201. if (valid) {
  202. if (this.form.id !== undefined) {
  203. updateType(this.form).then(response => {
  204. this.$modal.msgSuccess("修改成功");
  205. this.open = false;
  206. this.getList();
  207. });
  208. } else {
  209. addType(this.form).then(response => {
  210. this.$modal.msgSuccess("新增成功");
  211. this.open = false;
  212. this.getList();
  213. });
  214. }
  215. }
  216. });
  217. },
  218. /** 删除按钮操作 */
  219. handleDelete(row) {
  220. const ids = row.id || this.ids;
  221. this.$modal.confirm('是否确认删除字典编号为"' + ids + '"的数据项?').then(function() {
  222. return delType(ids);
  223. }).then(() => {
  224. this.getList();
  225. this.$modal.msgSuccess("删除成功");
  226. }).catch(() => {});
  227. },
  228. /** 导出按钮操作 */
  229. handleExport() {
  230. // 处理查询参数
  231. let params = {...this.queryParams};
  232. params.pageNo = undefined;
  233. params.pageSize = undefined;
  234. // 执行导出
  235. this.$modal.confirm('是否确认导出所有字典类型数据项?').then(() => {
  236. this.exportLoading = true;
  237. return exportType(params);
  238. }).then(response => {
  239. this.$download.excel(response, '字典类型.xls');
  240. this.exportLoading = false;
  241. }).catch(() => {});
  242. }
  243. }
  244. };
  245. </script>